summaryrefslogtreecommitdiff
path: root/pjlib-util/include/pjlib-util/turn_client.h
blob: 83d8d2d69977c80ac31a3e85a571cb1b75a54419 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* $Id$ */
/* 
 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */
#ifndef __PJLIB_UTIL_TURN_CLIENT_H__
#define __PJLIB_UTIL_TURN_CLIENT_H__

/**
 * @file turn_client.h
 * @brief TURN client session.
 */

#include <pjlib-util/stun_msg.h>


PJ_BEGIN_DECL


/**
 * @defgroup PJLIB_UTIL_TURN_CLIENT TURN Client Session
 * @brief Management of STUN/TURN client session
 * @ingroup PJLIB_UTIL_STUN
 * @{
 */

typedef struct pj_turn_client pj_turn_client;

/**
 * This describes TURN client config.
 */
typedef struct pj_turn_client_cb
{
    /**
     * Callback to be called by the TURN session to send outgoing message.
     *
     * @param client	    The TURN client session.
     * @param pkt	    Packet to be sent.
     * @param pkt_size	    Size of the packet to be sent.
     * @param dst_addr	    The destination address.
     * @param addr_len	    Length of destination address.
     *
     * @return		    The callback should return the status of the
     *			    packet sending.
     */
    pj_status_t (*on_send_msg)(pj_turn_client *client,
			       const void *pkt,
			       pj_size_t pkt_size,
			       const pj_sockaddr_t *dst_addr,
			       unsigned addr_len);

    /**
     * Callback to be called by TURN session when its state has changed.
     */
    pj_status_t (*on_state_changed)(pj_turn_client *client);

} pj_turn_client_cb;


/**
 * Options
 */
typedef struct pj_turn_client_config
{
    int	    bandwidth;
    int	    lifetime;
    int	    sock_type;
    int	    port;
} pj_turn_client_config;


PJ_INLINE(void) pj_turn_client_config_default(pj_turn_client_config *cfg)
{
    pj_bzero(cfg, sizeof(*cfg));
    cfg->bandwidth = -1;
    cfg->lifetime = -1;
    cfg->sock_type = -1;
    cfg->port = -1;
}


/**
 * This describes the TURN client session.
 */
struct pj_turn_client
{
    pj_pool_t	    *pool;
    pj_stun_session *session;
    pj_timer_entry   alloc_timer;
    pj_sockaddr_in   mapped_addr;
    pj_sockaddr_in   relay_addr;
};




/**
 * Create the TURN client session.
 */
PJ_DECL(pj_status_t) pj_turn_client_create(pj_stun_endpoint *endpt,
					   const pj_turn_client_config *cfg,
					   const pj_turn_client_cb *cb,
					   pj_turn_client **p_client);

/**
 * Start the TURN client session by sending Allocate request to the server.
 */


/**
 * @}
 */


PJ_END_DECL


#endif	/* __PJLIB_UTIL_TURN_CLIENT_H__ */