@@ -298,6 +298,43 @@ typedef struct pj_turn_session_cb
298298 pj_turn_state_t old_state ,
299299 pj_turn_state_t new_state );
300300
301+ /**
302+ * Notification when TURN client received a ConnectionAttempt Indication
303+ * from the TURN server, which indicates that peer initiates a TCP
304+ * connection to allocated slot in the TURN server. Application must
305+ * implement this callback if it uses RFC 6062 (TURN TCP allocations).
306+ *
307+ * After receiving this callback, application should establish a new TCP
308+ * connection to the TURN server and send ConnectionBind request (using
309+ * pj_turn_session_connection_bind()). After the connection binding
310+ * succeeds, this new connection will become a data only connection.
311+ *
312+ * @param sess The TURN session.
313+ * @param conn_id The connection ID assigned by TURN server.
314+ * @param peer_addr Peer address that tried to connect to the TURN server.
315+ * @param addr_len Length of the peer address.
316+ */
317+ void (* on_connection_attempt )(pj_turn_session * sess ,
318+ pj_uint32_t conn_id ,
319+ const pj_sockaddr_t * peer_addr ,
320+ unsigned addr_len );
321+
322+ /**
323+ * Notification for ConnectionBind request sent using
324+ * pj_turn_session_connection_bind().
325+ *
326+ * @param sess The TURN session.
327+ * @param status The status code.
328+ * @param conn_id The connection ID.
329+ * @param peer_addr Peer address.
330+ * @param addr_len Length of the peer address.
331+ */
332+ void (* on_connection_bind_status )(pj_turn_session * sess ,
333+ pj_status_t status ,
334+ pj_uint32_t conn_id ,
335+ const pj_sockaddr_t * peer_addr ,
336+ unsigned addr_len );
337+
301338} pj_turn_session_cb ;
302339
303340
@@ -339,6 +376,13 @@ typedef struct pj_turn_alloc_param
339376 */
340377 int af ;
341378
379+ /**
380+ * Type of connection to from TURN server to peer. Supported values are
381+ * PJ_TURN_TP_UDP (RFC 5766) and PJ_TURN_TP_TCP (RFC 6062)
382+ *
383+ * Default is PJ_TURN_TP_UDP.
384+ */
385+ pj_turn_tp_type peer_conn_type ;
342386
343387} pj_turn_alloc_param ;
344388
@@ -386,6 +430,40 @@ typedef struct pj_turn_session_info
386430} pj_turn_session_info ;
387431
388432
433+ /**
434+ * Parameters for function pj_turn_session_on_rx_pkt2().
435+ */
436+ typedef struct pj_turn_session_on_rx_pkt_param
437+ {
438+ /**
439+ * The packet as received from the TURN server. This should contain
440+ * either STUN encapsulated message or a ChannelData packet.
441+ */
442+ void * pkt ;
443+
444+ /**
445+ * The length of the packet.
446+ */
447+ pj_size_t pkt_len ;
448+
449+ /**
450+ * The number of parsed or processed data from the packet.
451+ */
452+ pj_size_t parsed_len ;
453+
454+ /**
455+ * Source address where the packet is received from.
456+ */
457+ const pj_sockaddr_t * src_addr ;
458+
459+ /**
460+ * Length of the source address.
461+ */
462+ unsigned src_addr_len ;
463+
464+ } pj_turn_session_on_rx_pkt_param ;
465+
466+
389467/**
390468 * Initialize pj_turn_alloc_param with the default values.
391469 *
@@ -741,6 +819,56 @@ PJ_DECL(pj_status_t) pj_turn_session_on_rx_pkt(pj_turn_session *sess,
741819 pj_size_t pkt_len ,
742820 pj_size_t * parsed_len );
743821
822+ /**
823+ * Notify TURN client session upon receiving a packet from server. Since
824+ * the TURN session is transport independent, it does not read packet from
825+ * any sockets, and rather relies on application giving it packets that
826+ * are received from the TURN server. The session then processes this packet
827+ * and decides whether it is part of TURN protocol exchange or if it is a
828+ * data to be reported back to user, which in this case it will call the
829+ * \a on_rx_data() callback.
830+ *
831+ * This function is variant of pj_turn_session_on_rx_pkt() with additional
832+ * parameters such as source address. Source address will allow STUN/TURN
833+ * session to resend the request (e.g: with updated authentication) to the
834+ * provided source address which may be different to the initial connection,
835+ * for example in RFC 6062 scenario that there can be some data connection
836+ * and a control connection.
837+ *
838+ * @param sess The TURN client session.
839+ * @param prm The function parameters, e.g: packet, source address.
840+ *
841+ * @return The function may return non-PJ_SUCCESS if it receives
842+ * non-STUN and non-ChannelData packet, or if the
843+ * \a on_rx_data() returns non-PJ_SUCCESS;
844+ */
845+ PJ_DECL (pj_status_t ) pj_turn_session_on_rx_pkt2 (
846+ pj_turn_session * sess ,
847+ pj_turn_session_on_rx_pkt_param * prm );
848+
849+ /**
850+ * Initiate connection binding to the specified peer using ConnectionBind
851+ * request. Application must call this function when it uses RFC 6062
852+ * (TURN TCP allocations) to establish a data connection with peer after
853+ * opening/accepting connection to/from peer. The connection binding status
854+ * will be notified via on_connection_bind_status callback.
855+ *
856+ * @param sess The TURN session.
857+ * @param pool The memory pool.
858+ * @param conn_id The connection ID assigned by TURN server.
859+ * @param peer_addr Peer address.
860+ * @param addr_len Length of the peer address.
861+ *
862+ * @return PJ_SUCCESS if the operation has been successfully
863+ * issued, or the appropriate error code. Note that
864+ * the operation itself will complete asynchronously.
865+ */
866+ PJ_DECL (pj_status_t ) pj_turn_session_connection_bind (
867+ pj_turn_session * sess ,
868+ pj_pool_t * pool ,
869+ pj_uint32_t conn_id ,
870+ const pj_sockaddr_t * peer_addr ,
871+ unsigned addr_len );
744872
745873/**
746874 * @}
0 commit comments