summaryrefslogtreecommitdiff
path: root/pjnath/include/pjnath/turn_session.h
blob: 19260b7711068b57399da65e9ed0702af550e020 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* $Id$ */
/* 
 * Copyright (C) 2003-2007 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 __PJNATH_TURN_SESSION_H__
#define __PJNATH_TURN_SESSION_H__

/**
 * @file turn_session.h
 * @brief Transport independent TURN client session.
 */
#include <pjnath/stun_session.h>
#include <pjlib-util/resolver.h>


PJ_BEGIN_DECL

/* **************************************************************************/
/**
 * @defgroup PJNATH_TURN_SESSION TURN client session
 * @brief Transport independent TURN client session
 * @ingroup PJNATH_STUN
 * @{
 */

/** 
 * Opaque declaration for TURN client session.
 */
typedef struct pj_turn_session pj_turn_session;


#define PJ_TURN_INVALID_CHANNEL	    0xFFFF
#define PJ_TURN_CHANNEL_MIN	    0x4000
#define PJ_TURN_CHANNEL_MAX	    0xFFFE  /* inclusive */
#define PJ_TURN_NO_TIMEOUT	    ((long)0x7FFFFFFF)
#define PJ_TURN_MAX_PKT_LEN	    3000
#define PJ_TURN_PERM_TIMEOUT	    300
#define PJ_TURN_CHANNEL_TIMEOUT	    600


/** Transport types */
enum {
    PJ_TURN_TP_UDP = 16,    /**< UDP.	*/
    PJ_TURN_TP_TCP = 6	    /**< TCP.	*/
};

/* ChannelData header */
typedef struct pj_turn_channel_data
{
    pj_uint16_t ch_number;
    pj_uint16_t length;
} pj_turn_channel_data;



/**
 * Callback to receive events from TURN session.
 */
typedef struct pj_turn_session_cb
{
    /**
     * Callback to send outgoing packet. This callback is mandatory.
     */
    pj_status_t (*on_send_pkt)(pj_turn_session *sess,
			       const pj_uint8_t *pkt,
			       unsigned pkt_len,
			       const pj_sockaddr_t *dst_addr,
			       unsigned dst_addr_len);

    /**
     * Notification when allocation completes, either successfully or
     * with failure.
     */
    void (*on_allocate_complete)(pj_turn_session *sess,
				 pj_status_t status);

    /**
     * Notification when data is received.
     */
    void (*on_rx_data)(pj_turn_session *sess,
		       const pj_uint8_t *pkt,
		       unsigned pkt_len,
		       const pj_sockaddr_t *peer_addr,
		       unsigned addr_len);

    /**
     * Notification when session has been destroyed.
     */
    void (*on_destroyed)(pj_turn_session *sess);

} pj_turn_session_cb;


/**
 * Allocate parameter.
 */
typedef struct pj_turn_alloc_param
{
    int	    bandwidth;
    int	    lifetime;
} pj_turn_alloc_param;


/**
 * TURN session info.
 */
typedef struct pj_turn_session_info
{
    pj_sockaddr	    server;
} pj_turn_session_info;


/**
 * Create TURN client session.
 */
PJ_DECL(pj_status_t) pj_turn_session_create(pj_stun_config *cfg,
					    const pj_turn_session_cb *cb,
					    pj_turn_session **p_sess);


/**
 * Destroy TURN client session.
 */
PJ_DECL(pj_status_t) pj_turn_session_destroy(pj_turn_session *sess);


/**
 * Set the server or domain name of the server.
 */
PJ_DECL(pj_status_t) pj_turn_session_set_server(pj_turn_session *sess,
					        const pj_str_t *domain,
					        const pj_str_t *res_name,
						int default_port,
						pj_dns_resolver *resolver);


/**
 * Set credential to be used by the session.
 */
PJ_DECL(pj_status_t) pj_turn_session_set_cred(pj_turn_session *sess,
					      const pj_stun_auth_cred *cred);


/**
 * Create TURN allocation.
 */
PJ_DECL(pj_status_t) pj_turn_session_alloc(pj_turn_session *sess,
					   const pj_turn_alloc_param *param);


/**
 * Relay data to the specified peer through the session.
 */
PJ_DECL(pj_status_t) pj_turn_session_sendto(pj_turn_session *sess,
					    const pj_uint8_t *pkt,
					    unsigned pkt_len,
					    const pj_sockaddr_t *addr,
					    unsigned addr_len);

/**
 * Bind a peer address to a channel number.
 */
PJ_DECL(pj_status_t) pj_turn_session_bind_channel(pj_turn_session *sess,
						  const pj_sockaddr_t *peer,
						  unsigned addr_len);

/**
 * Notify TURN client session upon receiving a packet from server.
 * The packet maybe a STUN packet or ChannelData packet.
 */
PJ_DECL(pj_status_t) pj_turn_session_on_rx_pkt(pj_turn_session *sess,
					       const pj_uint8_t *pkt,
					       unsigned pkt_len,
					       pj_bool_t is_datagram);


/**
 * @}
 */


PJ_END_DECL


#endif	/* __PJNATH_TURN_SESSION_H__ */