turn_sock.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJNATH_TURN_SOCK_H__
  20. #define __PJNATH_TURN_SOCK_H__
  21. /**
  22. * @file turn_sock.h
  23. * @brief TURN relay using UDP client as transport protocol
  24. */
  25. #include <pjnath/turn_session.h>
  26. #include <pj/sock_qos.h>
  27. #include <pj/ssl_sock.h>
  28. PJ_BEGIN_DECL
  29. /* **************************************************************************/
  30. /**
  31. @addtogroup PJNATH_TURN_SOCK
  32. @{
  33. This is a ready to use object for relaying application data via a TURN server,
  34. by managing all the operations in \ref turn_op_sec.
  35. \section turnsock_using_sec Using TURN transport
  36. This object provides a thin wrapper to the \ref PJNATH_TURN_SESSION, hence the
  37. API is very much the same (apart from the obvious difference in the names).
  38. Please see \ref PJNATH_TURN_SESSION for the documentation on how to use the
  39. session.
  40. \section turnsock_samples_sec Samples
  41. The \ref turn_client_sample is a sample application to use the
  42. \ref PJNATH_TURN_SOCK.
  43. Also see <b>\ref samples_page</b> for other samples.
  44. */
  45. /**
  46. * Opaque declaration for TURN client.
  47. */
  48. typedef struct pj_turn_sock pj_turn_sock;
  49. /**
  50. * This structure contains callbacks that will be called by the TURN
  51. * transport.
  52. */
  53. typedef struct pj_turn_sock_cb
  54. {
  55. /**
  56. * Notification when incoming data has been received from the remote
  57. * peer via the TURN server. The data reported in this callback will
  58. * be the exact data as sent by the peer (e.g. the TURN encapsulation
  59. * such as Data Indication or ChannelData will be removed before this
  60. * function is called).
  61. *
  62. * @param turn_sock The TURN client transport.
  63. * @param data The data as received from the peer.
  64. * @param data_len Length of the data.
  65. * @param peer_addr The peer address.
  66. * @param addr_len The length of the peer address.
  67. */
  68. void (*on_rx_data)(pj_turn_sock *turn_sock,
  69. void *pkt,
  70. unsigned pkt_len,
  71. const pj_sockaddr_t *peer_addr,
  72. unsigned addr_len);
  73. /**
  74. * Notifification when asynchronous send operation has completed.
  75. *
  76. * @param turn_sock The TURN transport.
  77. * @param sent If value is positive non-zero it indicates the
  78. * number of data sent. When the value is negative,
  79. * it contains the error code which can be retrieved
  80. * by negating the value (i.e. status=-sent).
  81. *
  82. * @return Application should normally return PJ_TRUE to let
  83. * the TURN transport continue its operation. However
  84. * it must return PJ_FALSE if it has destroyed the
  85. * TURN transport in this callback.
  86. */
  87. pj_bool_t (*on_data_sent)(pj_turn_sock *sock,
  88. pj_ssize_t sent);
  89. /**
  90. * Notification when TURN session state has changed. Application should
  91. * implement this callback to monitor the progress of the TURN session.
  92. *
  93. * @param turn_sock The TURN client transport.
  94. * @param old_state Previous state.
  95. * @param new_state Current state.
  96. */
  97. void (*on_state)(pj_turn_sock *turn_sock,
  98. pj_turn_state_t old_state,
  99. pj_turn_state_t new_state);
  100. /**
  101. * Notification when TURN client received a ConnectionAttempt Indication
  102. * from the TURN server, which indicates that peer initiates a TCP
  103. * connection to allocated slot in the TURN server. Application should
  104. * implement this callback if it uses RFC 6062 (TURN TCP allocations),
  105. * otherwise TURN client will automatically accept it.
  106. *
  107. * If application accepts the peer connection attempt (i.e: by returning
  108. * PJ_SUCCESS or not implementing this callback), the TURN socket will
  109. * initiate a new connection to the TURN server and send ConnectionBind
  110. * request, and eventually will notify application via
  111. * on_connection_status callback, if implemented.
  112. *
  113. * @param turn_sock The TURN client transport.
  114. * @param conn_id The connection ID assigned by TURN server.
  115. * @param peer_addr Peer address that tried to connect to the
  116. * TURN server.
  117. * @param addr_len Length of the peer address.
  118. *
  119. * @return The callback must return PJ_SUCCESS to accept
  120. * the connection attempt.
  121. */
  122. pj_status_t (*on_connection_attempt)(pj_turn_sock *turn_sock,
  123. pj_uint32_t conn_id,
  124. const pj_sockaddr_t *peer_addr,
  125. unsigned addr_len);
  126. /**
  127. * Notification for initiated TCP data connection to peer (RFC 6062),
  128. * for example after peer connection attempt is accepted.
  129. *
  130. * @param turn_sock The TURN client transport.
  131. * @param status The status code.
  132. * @param conn_id The connection ID.
  133. * @param peer_addr Peer address.
  134. * @param addr_len Length of the peer address.
  135. */
  136. void (*on_connection_status)(pj_turn_sock *turn_sock,
  137. pj_status_t status,
  138. pj_uint32_t conn_id,
  139. const pj_sockaddr_t *peer_addr,
  140. unsigned addr_len);
  141. } pj_turn_sock_cb;
  142. /**
  143. * The default enabled SSL proto to be used.
  144. * Default is all protocol above TLSv1 (TLSv1 & TLS v1.1 & TLS v1.2).
  145. */
  146. #ifndef PJ_TURN_TLS_DEFAULT_PROTO
  147. # define PJ_TURN_TLS_DEFAULT_PROTO (PJ_SSL_SOCK_PROTO_TLS1 | \
  148. PJ_SSL_SOCK_PROTO_TLS1_1 | \
  149. PJ_SSL_SOCK_PROTO_TLS1_2)
  150. #endif
  151. /**
  152. * TLS transport settings.
  153. */
  154. typedef struct pj_turn_sock_tls_cfg
  155. {
  156. /**
  157. * Certificate of Authority (CA) list file.
  158. */
  159. pj_str_t ca_list_file;
  160. /**
  161. * Certificate of Authority (CA) list directory path.
  162. */
  163. pj_str_t ca_list_path;
  164. /**
  165. * Public endpoint certificate file, which will be used as client-
  166. * side certificate for outgoing TLS connection.
  167. */
  168. pj_str_t cert_file;
  169. /**
  170. * Optional private key of the endpoint certificate to be used.
  171. */
  172. pj_str_t privkey_file;
  173. /**
  174. * Certificate of Authority (CA) buffer. If ca_list_file, ca_list_path,
  175. * cert_file or privkey_file are set, this setting will be ignored.
  176. */
  177. pj_ssl_cert_buffer ca_buf;
  178. /**
  179. * Public endpoint certificate buffer, which will be used as client-
  180. * side certificate for outgoing TLS connection, and server-side
  181. * certificate for incoming TLS connection. If ca_list_file, ca_list_path,
  182. * cert_file or privkey_file are set, this setting will be ignored.
  183. */
  184. pj_ssl_cert_buffer cert_buf;
  185. /**
  186. * Optional private key buffer of the endpoint certificate to be used.
  187. * If ca_list_file, ca_list_path, cert_file or privkey_file are set,
  188. * this setting will be ignored.
  189. */
  190. pj_ssl_cert_buffer privkey_buf;
  191. /**
  192. * Password to open private key.
  193. */
  194. pj_str_t password;
  195. /**
  196. * Lookup certificate from OS certificate store with specified criteria.
  197. *
  198. * Currently only used by TLS backend Windows Schannel, please check
  199. * pj_ssl_cert_load_from_store() for more info.
  200. */
  201. pj_ssl_cert_lookup_criteria cert_lookup;
  202. /**
  203. * The ssl socket parameter.
  204. * These fields are used by TURN TLS:
  205. * - proto
  206. * - ciphers_num
  207. * - ciphers
  208. * - curves_num
  209. * - curves
  210. * - sigalgs
  211. * - entropy_type
  212. * - entropy_path
  213. * - timeout
  214. * - sockopt_params
  215. * - sockopt_ignore_error
  216. * - enable_renegotiation
  217. */
  218. pj_ssl_sock_param ssock_param;
  219. } pj_turn_sock_tls_cfg;
  220. /**
  221. * Initialize TLS setting with default values.
  222. *
  223. * @param tls_cfg The TLS setting to be initialized.
  224. */
  225. PJ_DECL(void) pj_turn_sock_tls_cfg_default(pj_turn_sock_tls_cfg *tls_cfg);
  226. /**
  227. * Duplicate TLS setting.
  228. *
  229. * @param pool The pool to duplicate strings etc.
  230. * @param dst Destination structure.
  231. * @param src Source structure.
  232. */
  233. PJ_DECL(void) pj_turn_sock_tls_cfg_dup(pj_pool_t *pool,
  234. pj_turn_sock_tls_cfg *dst,
  235. const pj_turn_sock_tls_cfg *src);
  236. /**
  237. * Wipe out certificates and keys in the TLS setting.
  238. *
  239. * @param tls_cfg The TLS setting.
  240. */
  241. PJ_DECL(void) pj_turn_sock_tls_cfg_wipe_keys(pj_turn_sock_tls_cfg *tls_cfg);
  242. /**
  243. * This structure describes options that can be specified when creating
  244. * the TURN socket. Application should call #pj_turn_sock_cfg_default()
  245. * to initialize this structure with its default values before using it.
  246. */
  247. typedef struct pj_turn_sock_cfg
  248. {
  249. /**
  250. * The group lock to be used by the STUN socket. If NULL, the STUN socket
  251. * will create one internally.
  252. *
  253. * Default: NULL
  254. */
  255. pj_grp_lock_t *grp_lock;
  256. /**
  257. * Packet buffer size.
  258. *
  259. * Default value is PJ_TURN_MAX_PKT_LEN.
  260. */
  261. unsigned max_pkt_size;
  262. /**
  263. * QoS traffic type to be set on this transport. When application wants
  264. * to apply QoS tagging to the transport, it's preferable to set this
  265. * field rather than \a qos_param fields since this is more portable.
  266. *
  267. * Default value is PJ_QOS_TYPE_BEST_EFFORT.
  268. */
  269. pj_qos_type qos_type;
  270. /**
  271. * Set the low level QoS parameters to the transport. This is a lower
  272. * level operation than setting the \a qos_type field and may not be
  273. * supported on all platforms.
  274. *
  275. * By default all settings in this structure are not set.
  276. */
  277. pj_qos_params qos_params;
  278. /**
  279. * Specify if STUN socket should ignore any errors when setting the QoS
  280. * traffic type/parameters.
  281. *
  282. * Default: PJ_TRUE
  283. */
  284. pj_bool_t qos_ignore_error;
  285. /**
  286. * Specify the interface where the socket should be bound to. If the
  287. * address is zero, socket will be bound to INADDR_ANY. If the address
  288. * is non-zero, socket will be bound to this address only. If the port is
  289. * set to zero, the socket will bind at any port (chosen by the OS).
  290. */
  291. pj_sockaddr bound_addr;
  292. /**
  293. * Specify the port range for TURN socket binding, relative to the start
  294. * port number specified in \a bound_addr. Note that this setting is only
  295. * applicable when the start port number is non zero.
  296. *
  297. * Default value is zero.
  298. */
  299. pj_uint16_t port_range;
  300. /**
  301. * Specify target value for socket receive buffer size. It will be
  302. * applied using setsockopt(). When it fails to set the specified size,
  303. * it will try with lower value until the highest possible has been
  304. * successfully set.
  305. *
  306. * Default: 0 (OS default)
  307. */
  308. unsigned so_rcvbuf_size;
  309. /**
  310. * Specify target value for socket send buffer size. It will be
  311. * applied using setsockopt(). When it fails to set the specified size,
  312. * it will try with lower value until the highest possible has been
  313. * successfully set.
  314. *
  315. * Default: 0 (OS default)
  316. */
  317. unsigned so_sndbuf_size;
  318. /**
  319. * This specifies TLS settings for TLS transport. It's only applicable when
  320. * TLS is used to connect to the TURN server.
  321. */
  322. pj_turn_sock_tls_cfg tls_cfg;
  323. } pj_turn_sock_cfg;
  324. /**
  325. * Initialize pj_turn_sock_cfg structure with default values.
  326. */
  327. PJ_DECL(void) pj_turn_sock_cfg_default(pj_turn_sock_cfg *cfg);
  328. /**
  329. * Create a TURN transport instance with the specified address family and
  330. * connection type. Once TURN transport instance is created, application
  331. * must call pj_turn_sock_alloc() to allocate a relay address in the TURN
  332. * server.
  333. *
  334. * @param cfg The STUN configuration which contains among other
  335. * things the ioqueue and timer heap instance for
  336. * the operation of this transport.
  337. * @param af Address family of the client connection. Currently
  338. * pj_AF_INET() and pj_AF_INET6() are supported.
  339. * @param conn_type Connection type to the TURN server. Both TCP and
  340. * UDP are supported.
  341. * @param cb Callback to receive events from the TURN transport.
  342. * @param setting Optional settings to be specified to the transport.
  343. * If this parameter is NULL, default values will be
  344. * used.
  345. * @param user_data Arbitrary application data to be associated with
  346. * this transport.
  347. * @param p_turn_sock Pointer to receive the created instance of the
  348. * TURN transport.
  349. *
  350. * @return PJ_SUCCESS if the operation has been successful,
  351. * or the appropriate error code on failure.
  352. */
  353. PJ_DECL(pj_status_t) pj_turn_sock_create(pj_stun_config *cfg,
  354. int af,
  355. pj_turn_tp_type conn_type,
  356. const pj_turn_sock_cb *cb,
  357. const pj_turn_sock_cfg *setting,
  358. void *user_data,
  359. pj_turn_sock **p_turn_sock);
  360. /**
  361. * Destroy the TURN transport instance. This will gracefully close the
  362. * connection between the client and the TURN server. Although this
  363. * function will return immediately, the TURN socket deletion may continue
  364. * in the background and the application may still get state changes
  365. * notifications from this transport.
  366. *
  367. * @param turn_sock The TURN transport instance.
  368. */
  369. PJ_DECL(void) pj_turn_sock_destroy(pj_turn_sock *turn_sock);
  370. /**
  371. * Associate a user data with this TURN transport. The user data may then
  372. * be retrieved later with #pj_turn_sock_get_user_data().
  373. *
  374. * @param turn_sock The TURN transport instance.
  375. * @param user_data Arbitrary data.
  376. *
  377. * @return PJ_SUCCESS if the operation has been successful,
  378. * or the appropriate error code on failure.
  379. */
  380. PJ_DECL(pj_status_t) pj_turn_sock_set_user_data(pj_turn_sock *turn_sock,
  381. void *user_data);
  382. /**
  383. * Retrieve the previously assigned user data associated with this TURN
  384. * transport.
  385. *
  386. * @param turn_sock The TURN transport instance.
  387. *
  388. * @return The user/application data.
  389. */
  390. PJ_DECL(void*) pj_turn_sock_get_user_data(pj_turn_sock *turn_sock);
  391. /**
  392. * Get the group lock for this TURN transport.
  393. *
  394. * @param turn_sock The TURN transport instance.
  395. *
  396. * @return The group lock.
  397. */
  398. PJ_DECL(pj_grp_lock_t *) pj_turn_sock_get_grp_lock(pj_turn_sock *turn_sock);
  399. /**
  400. * Get the TURN transport info. The transport info contains, among other
  401. * things, the allocated relay address.
  402. *
  403. * @param turn_sock The TURN transport instance.
  404. * @param info Pointer to be filled with TURN transport info.
  405. *
  406. * @return PJ_SUCCESS if the operation has been successful,
  407. * or the appropriate error code on failure.
  408. */
  409. PJ_DECL(pj_status_t) pj_turn_sock_get_info(pj_turn_sock *turn_sock,
  410. pj_turn_session_info *info);
  411. /**
  412. * Acquire the internal mutex of the TURN transport. Application may need
  413. * to call this function to synchronize access to other objects alongside
  414. * the TURN transport, to avoid deadlock.
  415. *
  416. * @param turn_sock The TURN transport instance.
  417. *
  418. * @return PJ_SUCCESS if the operation has been successful,
  419. * or the appropriate error code on failure.
  420. */
  421. PJ_DECL(pj_status_t) pj_turn_sock_lock(pj_turn_sock *turn_sock);
  422. /**
  423. * Release the internal mutex previously held with pj_turn_sock_lock().
  424. *
  425. * @param turn_sock The TURN transport instance.
  426. *
  427. * @return PJ_SUCCESS if the operation has been successful,
  428. * or the appropriate error code on failure.
  429. */
  430. PJ_DECL(pj_status_t) pj_turn_sock_unlock(pj_turn_sock *turn_sock);
  431. /**
  432. * Set STUN message logging for this TURN session.
  433. * See #pj_stun_session_set_log().
  434. *
  435. * @param turn_sock The TURN transport instance.
  436. * @param flags Bitmask combination of #pj_stun_sess_msg_log_flag
  437. */
  438. PJ_DECL(void) pj_turn_sock_set_log(pj_turn_sock *turn_sock,
  439. unsigned flags);
  440. /**
  441. * Configure the SOFTWARE name to be sent in all STUN requests by the
  442. * TURN session.
  443. *
  444. * @param turn_sock The TURN transport instance.
  445. * @param sw Software name string. If this argument is NULL or
  446. * empty, the session will not include SOFTWARE attribute
  447. * in STUN requests and responses.
  448. *
  449. * @return PJ_SUCCESS on success, or the appropriate error code.
  450. */
  451. PJ_DECL(pj_status_t) pj_turn_sock_set_software_name(pj_turn_sock *turn_sock,
  452. const pj_str_t *sw);
  453. /**
  454. * Allocate a relay address/resource in the TURN server. This function
  455. * will resolve the TURN server using DNS SRV (if desired) and send TURN
  456. * \a Allocate request using the specified credential to allocate a relay
  457. * address in the server. This function completes asynchronously, and
  458. * application will be notified when the allocation process has been
  459. * successful in the \a on_state() callback when the state is set to
  460. * PJ_TURN_STATE_READY. If the allocation fails, the state will be set
  461. * to PJ_TURN_STATE_DEALLOCATING or greater.
  462. *
  463. * @param turn_sock The TURN transport instance.
  464. * @param domain The domain, hostname, or IP address of the TURN
  465. * server. When this parameter contains domain name,
  466. * the \a resolver parameter must be set to activate
  467. * DNS SRV resolution.
  468. * @param default_port The default TURN port number to use when DNS SRV
  469. * resolution is not used. If DNS SRV resolution is
  470. * used, the server port number will be set from the
  471. * DNS SRV records.
  472. * @param resolver If this parameter is not NULL, then the \a domain
  473. * parameter will be first resolved with DNS SRV and
  474. * then fallback to using DNS A/AAAA resolution when
  475. * DNS SRV resolution fails. If this parameter is
  476. * NULL, the \a domain parameter will be resolved as
  477. * hostname.
  478. * @param cred The STUN credential to be used for the TURN server.
  479. * @param param Optional TURN allocation parameter.
  480. *
  481. * @return PJ_SUCCESS if the operation has been successfully
  482. * queued, or the appropriate error code on failure.
  483. * When this function returns PJ_SUCCESS, the final
  484. * result of the allocation process will be notified
  485. * to application in \a on_state() callback.
  486. *
  487. */
  488. PJ_DECL(pj_status_t) pj_turn_sock_alloc(pj_turn_sock *turn_sock,
  489. const pj_str_t *domain,
  490. int default_port,
  491. pj_dns_resolver *resolver,
  492. const pj_stun_auth_cred *cred,
  493. const pj_turn_alloc_param *param);
  494. /**
  495. * Create or renew permission in the TURN server for the specified peer IP
  496. * addresses. Application must install permission for a particular (peer)
  497. * IP address before it sends any data to that IP address, or otherwise
  498. * the TURN server will drop the data.
  499. *
  500. * @param turn_sock The TURN transport instance.
  501. * @param addr_cnt Number of IP addresses.
  502. * @param addr Array of peer IP addresses. Only the address family
  503. * and IP address portion of the socket address matter.
  504. * @param options Specify 1 to let the TURN client session automatically
  505. * renew the permission later when they are about to
  506. * expire.
  507. *
  508. * @return PJ_SUCCESS if the operation has been successfully
  509. * issued, or the appropriate error code. Note that
  510. * the operation itself will complete asynchronously.
  511. */
  512. PJ_DECL(pj_status_t) pj_turn_sock_set_perm(pj_turn_sock *turn_sock,
  513. unsigned addr_cnt,
  514. const pj_sockaddr addr[],
  515. unsigned options);
  516. /**
  517. * Send a data to the specified peer address via the TURN relay. This
  518. * function will encapsulate the data as STUN Send Indication or TURN
  519. * ChannelData packet and send the message to the TURN server. The TURN
  520. * server then will send the data to the peer.
  521. *
  522. * The allocation (pj_turn_sock_alloc()) must have been successfully
  523. * created before application can relay any data.
  524. *
  525. * @param turn_sock The TURN transport instance.
  526. * @param pkt The data/packet to be sent to peer.
  527. * @param pkt_len Length of the data.
  528. * @param peer_addr The remote peer address (the ultimate destination
  529. * of the data, and not the TURN server address).
  530. * @param addr_len Length of the address.
  531. *
  532. * @return PJ_SUCCESS if data has been sent immediately, or
  533. * PJ_EPENDING if data cannot be sent immediately. In
  534. * this case the \a on_data_sent() callback will be
  535. * called when data is actually sent. Any other return
  536. * value indicates error condition.
  537. */
  538. PJ_DECL(pj_status_t) pj_turn_sock_sendto(pj_turn_sock *turn_sock,
  539. const pj_uint8_t *pkt,
  540. unsigned pkt_len,
  541. const pj_sockaddr_t *peer_addr,
  542. unsigned addr_len);
  543. /**
  544. * Optionally establish channel binding for the specified a peer address.
  545. * This function will assign a unique channel number for the peer address
  546. * and request channel binding to the TURN server for this address. When
  547. * a channel has been bound to a peer, the TURN transport and TURN server
  548. * will exchange data using ChannelData encapsulation format, which has
  549. * lower bandwidth overhead than Send Indication (the default format used
  550. * when peer address is not bound to a channel).
  551. *
  552. * @param turn_sock The TURN transport instance.
  553. * @param peer The remote peer address.
  554. * @param addr_len Length of the address.
  555. *
  556. * @return PJ_SUCCESS if the operation has been successful,
  557. * or the appropriate error code on failure.
  558. */
  559. PJ_DECL(pj_status_t) pj_turn_sock_bind_channel(pj_turn_sock *turn_sock,
  560. const pj_sockaddr_t *peer,
  561. unsigned addr_len);
  562. /**
  563. * Initiate connection to the specified peer using Connect request.
  564. * Application must call this function when it uses RFC 6062 (TURN TCP
  565. * allocations) to initiate a data connection to a peer. The connection status
  566. * will be notified via on_connection_status callback.
  567. *
  568. * According to RFC 6062, the TURN transport instance must be created with
  569. * connection type are set to PJ_TURN_TP_TCP, application must send TCP
  570. * Allocate request (with pj_turn_session_alloc(), set TURN allocation
  571. * parameter peer_conn_type to PJ_TURN_TP_TCP) before calling this function.
  572. *
  573. *
  574. * @param turn_sock The TURN transport instance.
  575. * @param peer The remote peer address.
  576. * @param addr_len Length of the address.
  577. *
  578. * @return PJ_SUCCESS if the operation has been successful,
  579. * or the appropriate error code on failure.
  580. */
  581. PJ_DECL(pj_status_t) pj_turn_sock_connect(pj_turn_sock *turn_sock,
  582. const pj_sockaddr_t *peer,
  583. unsigned addr_len);
  584. /**
  585. * Close previous TCP data connection for the specified peer.
  586. * According to RFC 6062, when the client wishes to terminate its relayed
  587. * connection to the peer, it closes the data connection to the server.
  588. *
  589. * @param turn_sock The TURN transport instance.
  590. * @param peer The remote peer address.
  591. * @param addr_len Length of the address.
  592. *
  593. * @return PJ_SUCCESS if the operation has been successful,
  594. * or the appropriate error code on failure.
  595. */
  596. PJ_DECL(pj_status_t) pj_turn_sock_disconnect(pj_turn_sock *turn_sock,
  597. const pj_sockaddr_t *peer,
  598. unsigned addr_len);
  599. /**
  600. * @}
  601. */
  602. PJ_END_DECL
  603. #endif /* __PJNATH_TURN_SOCK_H__ */