Skip to content
Snippets Groups Projects
Unverified Commit ebb5e5c1 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

contrib: bump pjproject

Now that RFC6062 is merged upstream, we can remove the patch from
our stack. The API changed a bit, so this patch also updates
turn_transport.cpp to follow changes

Change-Id: If6e0bae8280d586b2e5fcb0babe83df8127789b6
parent 5b6063dc
Branches
No related tags found
No related merge requests found
e203f3846db1a380b2bcb2e18fb73f6296a87c25d5b0b38d44df88a398c597bcb31c85a0e72b476908e4b56fdeb6fc5c586cf595f9723091d6a09659b75d1d5c pjproject-6b9212dcb4b3f781c1e922ae544b063880bc46ac.tar.gz
\ No newline at end of file
a9433b47294434288d61524dea556687fb02137ed56a10e8e2ba85d7888a2ca2a5bea4ae4a9ad008a4c208c5ec53fe364b10ed14481700d6aa8b9b6137e5e9ee pjproject-5dfa75be7d69047387f9b0436dd9492bbbf03fe4.tar.gz
\ No newline at end of file
set BUILD=%SRC%..\build
set PJPROJECT_VERSION=6b9212dcb4b3f781c1e922ae544b063880bc46ac
set PJPROJECT_VERSION=5dfa75be7d69047387f9b0436dd9492bbbf03fe4
set PJPROJECT_URL=https://github.com/pjsip/pjproject/archive/%PJPROJECT_VERSION%.tar.gz
mkdir %BUILD%
......@@ -33,7 +33,6 @@ bash -c "%PATCH_CMD% %UNIXPATH%pjproject/pj_ice_sess.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/fix_turn_fallback.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/fix_ioqueue_ipv6_sendto.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/add_dtls_transport.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/rfc6062.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/rfc6544.patch"
bash -c "%PATCH_CMD% %UNIXPATH%pjproject/ice_config.patch"
......
Copyright (C) 2017-2019 Savoir-faire Linux Inc.
turn: rfc 6062 support
Current implementation of TURN and STUN doesn't support TCP as a valid
peer connection. This connection is defined by the rfc 6062.
This patch is an implementation proposal of this rfc into PJNATH.
Modifications are API backware compatible, not ABI.
Users must rebuild their code.
Written by
Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
on behalf of Savoir-faire Linux.
---
pjnath/include/pjnath/config.h | 8 +
pjnath/include/pjnath/stun_msg.h | 26 ++
pjnath/include/pjnath/stun_session.h | 7 +
pjnath/include/pjnath/turn_session.h | 38 +++
pjnath/include/pjnath/turn_sock.h | 24 ++
pjnath/src/pjnath/stun_msg.c | 13 +-
pjnath/src/pjnath/stun_session.c | 13 +
pjnath/src/pjnath/turn_session.c | 59 +++-
pjnath/src/pjnath/turn_sock.c | 474 ++++++++++++++++++++++++++-
9 files changed, 655 insertions(+), 7 deletions(-)
diff --git a/pjnath/include/pjnath/config.h b/pjnath/include/pjnath/config.h
index 540e32ad1..e157d39ee 100644
--- a/pjnath/include/pjnath/config.h
+++ b/pjnath/include/pjnath/config.h
@@ -220,6 +220,14 @@
# define PJ_TURN_KEEP_ALIVE_SEC 15
#endif
+/**
+ * Maximal number of TCP data connection that a client can open/accept with
+ * peers.
+ */
+#ifndef PJ_TURN_MAX_TCP_CNX
+# define PJ_TURN_MAX_TCP_CNX 32
+#endif
+
/* **************************************************************************
* ICE CONFIGURATION
diff --git a/pjnath/include/pjnath/stun_msg.h b/pjnath/include/pjnath/stun_msg.h
index 7efdf57a2..4d04016ff 100644
--- a/pjnath/include/pjnath/stun_msg.h
+++ b/pjnath/include/pjnath/stun_msg.h
@@ -92,6 +92,21 @@ enum pj_stun_method_e
*/
PJ_STUN_CHANNEL_BIND_METHOD = 9,
+ /*
+ * STUN/TURN Connect as defined by RFC 6062
+ */
+ PJ_STUN_CONNECT_METHOD = 10,
+
+ /*
+ * STUN/TURN ConnectionBind as defined by RFC 6062
+ */
+ PJ_STUN_CONNECTION_BIND_METHOD = 11,
+
+ /*
+ * STUN/TURN ConnectionAttempt as defined by RFC 6062
+ */
+ PJ_STUN_CONNECTION_ATTEMPT_METHOD = 12,
+
/**
* All known methods.
*/
@@ -261,6 +276,16 @@ typedef enum pj_stun_msg_type
*/
PJ_STUN_DATA_INDICATION = 0x0017,
+ /**
+ * STUN/TURN ConnectBind Request
+ */
+ PJ_STUN_CONNECTION_BIND_REQUEST = 0x000b,
+
+ /**
+ * TURN ConnectionAttempt indication
+ */
+ PJ_STUN_CONNECTION_ATTEMPT_INDICATION = 0x001c,
+
/**
* TURN CreatePermission request
@@ -333,6 +358,7 @@ typedef enum pj_stun_attr_type
PJ_STUN_ATTR_XOR_REFLECTED_FROM = 0x0023,/**< XOR-REFLECTED-FROM */
PJ_STUN_ATTR_PRIORITY = 0x0024,/**< PRIORITY */
PJ_STUN_ATTR_USE_CANDIDATE = 0x0025,/**< USE-CANDIDATE */
+ PJ_STUN_ATTR_CONNECTION_ID = 0x002a,/**< CONNECTION-ID */
PJ_STUN_ATTR_ICMP = 0x0030,/**< ICMP (TURN) */
PJ_STUN_ATTR_END_MANDATORY_ATTR,
diff --git a/pjnath/include/pjnath/stun_session.h b/pjnath/include/pjnath/stun_session.h
index f8ea4d1dc..28c5985e8 100644
--- a/pjnath/include/pjnath/stun_session.h
+++ b/pjnath/include/pjnath/stun_session.h
@@ -750,6 +750,13 @@ PJ_DECL(pj_status_t) pj_stun_session_on_rx_pkt(pj_stun_session *sess,
PJ_DECL(void) pj_stun_msg_destroy_tdata(pj_stun_session *sess,
pj_stun_tx_data *tdata);
+PJ_DEF(void)
+pj_stun_session_get_server_cred(pj_stun_session *sess, pj_pool_t *pool,
+ pj_str_t *nonce, pj_str_t *realm);
+
+PJ_DEF(void)
+pj_stun_session_set_server_cred(pj_stun_session *sess, const pj_str_t *nonce,
+ pj_str_t *realm);
/**
* @}
diff --git a/pjnath/include/pjnath/turn_session.h b/pjnath/include/pjnath/turn_session.h
index cc3d5d8d5..3bb073beb 100644
--- a/pjnath/include/pjnath/turn_session.h
+++ b/pjnath/include/pjnath/turn_session.h
@@ -183,6 +183,12 @@ typedef enum pj_turn_state_t
*/
PJ_TURN_STATE_ALLOCATING,
+ /**
+ * TURN session has issued CONNECTION-BIND request and is waiting for response
+ * from the TURN server.
+ */
+ PJ_TURN_STATE_CONNECTION_BINDING,
+
/**
* TURN session has successfully allocated relay resoruce and now is
* ready to be used.
@@ -298,6 +304,21 @@ typedef struct pj_turn_session_cb
pj_turn_state_t old_state,
pj_turn_state_t new_state);
+ /**
+ * Notification when TURN session get a ConnectionAttempt indication.
+ *
+ * @param sess The TURN session.
+ * @param conn_id The connection-id to use for connection binding.
+ * @param peer_addr Peer address that tried to connect on the TURN server.
+ * @param addr_len Length of the peer address.
+
+ */
+ void (*on_peer_connection)(pj_turn_session *sess,
+ pj_uint32_t conn_id,
+ const pj_sockaddr_t *peer_addr,
+ unsigned addr_len,
+ pj_status_t status);
+
} pj_turn_session_cb;
@@ -339,6 +360,14 @@ typedef struct pj_turn_alloc_param
*/
int af;
+ /**
+ * Type of connection to from TURN server to peer.
+ *
+ * Supported values: PJ_TURN_TP_UDP (rfc 5766), PJ_TURN_TP_TLS (rfc 6062)
+ *
+ * Default is PJ_TURN_TP_UDP.
+ */
+ pj_turn_tp_type peer_conn_type;
} pj_turn_alloc_param;
@@ -741,6 +770,15 @@ PJ_DECL(pj_status_t) pj_turn_session_on_rx_pkt(pj_turn_session *sess,
pj_size_t pkt_len,
pj_size_t *parsed_len);
+/**
+ * rfc6062
+ */
+PJ_DEF(void) pj_turn_session_get_server_cred(
+ pj_turn_session *sess,
+ pj_pool_t *pool, pj_str_t *nonce, pj_str_t *realm);
+
+PJ_DEF(void) pj_turn_session_set_server_cred(
+ pj_turn_session *sess, const pj_str_t *nonce, pj_str_t *realm);
/**
* @}
diff --git a/pjnath/include/pjnath/turn_sock.h b/pjnath/include/pjnath/turn_sock.h
index bbff6bf7b..6a4d915c2 100644
--- a/pjnath/include/pjnath/turn_sock.h
+++ b/pjnath/include/pjnath/turn_sock.h
@@ -98,6 +98,23 @@ typedef struct pj_turn_sock_cb
pj_turn_state_t old_state,
pj_turn_state_t new_state);
+ /**
+ * Notification when TURN session get a ConnectionAttempt indication.
+ *
+ * @param turn_sock The TURN client transport.
+ * @param conn_id The connection-id to use for connection binding.
+ * @param peer_addr Peer address that tried to connect on the TURN server.
+ * @param addr_len Length of the peer address.
+ * @param status PJ_SUCCESS when connection is made, or any errors
+ * if the connection has failed (or if the peer has
+ * disconnected after an established connection).
+ */
+ void (*on_peer_connection)(pj_turn_sock *turn_sock,
+ pj_uint32_t conn_id,
+ const pj_sockaddr_t *peer_addr,
+ unsigned addr_len,
+ pj_status_t status);
+
} pj_turn_sock_cb;
@@ -446,6 +463,13 @@ PJ_DECL(pj_status_t) pj_turn_sock_bind_channel(pj_turn_sock *turn_sock,
const pj_sockaddr_t *peer,
unsigned addr_len);
+/**
+ * RFC 6062
+ */
+PJ_DECL(pj_status_t) pj_turn_connect_peer(pj_turn_sock *sock,
+ pj_uint32_t conn_id,
+ const pj_sockaddr_t *peer_addr,
+ unsigned addr_len);
/**
* @}
diff --git a/pjnath/src/pjnath/stun_msg.c b/pjnath/src/pjnath/stun_msg.c
index 896848b7a..acaf3b70f 100644
--- a/pjnath/src/pjnath/stun_msg.c
+++ b/pjnath/src/pjnath/stun_msg.c
@@ -45,6 +45,9 @@ static const char *stun_method_names[PJ_STUN_METHOD_MAX] =
"Data", /* 7 */
"CreatePermission", /* 8 */
"ChannelBind", /* 9 */
+ "Connect", /* 10 */
+ "ConnectionBind", /* 11 */
+ "ConnectionAttempt", /* 12 */
};
static struct
@@ -476,11 +479,11 @@ static struct attr_desc mandatory_attr_desc[] =
NULL
},
{
- /* ID 0x002a is not assigned */
- NULL,
- NULL,
- NULL,
- NULL
+ /* PJ_STUN_ATTR_CONNECTION_ID, */
+ "CONNECTION-ID",
+ &decode_uint_attr,
+ &encode_uint_attr,
+ &clone_uint_attr
},
{
/* ID 0x002b is not assigned */
diff --git a/pjnath/src/pjnath/stun_session.c b/pjnath/src/pjnath/stun_session.c
index d7eb2dbb5..5e2efc35a 100644
--- a/pjnath/src/pjnath/stun_session.c
+++ b/pjnath/src/pjnath/stun_session.c
@@ -1511,3 +1511,16 @@ PJ_DEF(pj_status_t) pj_stun_session_on_rx_pkt(pj_stun_session *sess,
return status;
}
+PJ_DEF(void)
+pj_stun_session_get_server_cred(pj_stun_session *sess, pj_pool_t *pool,
+ pj_str_t *nonce, pj_str_t *realm) {
+ pj_strdup(pool, nonce, &sess->next_nonce);
+ pj_strdup(pool, realm, &sess->server_realm);
+}
+
+PJ_DEF(void)
+pj_stun_session_set_server_cred(pj_stun_session *sess, const pj_str_t *nonce,
+ pj_str_t *realm) {
+ pj_strdup(sess->pool, &sess->next_nonce, nonce);
+ pj_strdup(sess->pool, &sess->server_realm, realm);
+}
diff --git a/pjnath/src/pjnath/turn_session.c b/pjnath/src/pjnath/turn_session.c
index bbea027f3..4fd643be1 100644
--- a/pjnath/src/pjnath/turn_session.c
+++ b/pjnath/src/pjnath/turn_session.c
@@ -42,6 +42,7 @@ static const char *state_names[] =
"Resolving",
"Resolved",
"Allocating",
+ "TcpBinding",
"Ready",
"Deallocating",
"Deallocated",
@@ -208,6 +209,7 @@ static void on_timer_event(pj_timer_heap_t *th, pj_timer_entry *e);
PJ_DEF(void) pj_turn_alloc_param_default(pj_turn_alloc_param *prm)
{
pj_bzero(prm, sizeof(*prm));
+ prm->peer_conn_type = PJ_TURN_TP_UDP;
}
/*
@@ -403,6 +405,11 @@ static void sess_shutdown(pj_turn_session *sess,
sess->pending_destroy = PJ_TRUE;
can_destroy = PJ_FALSE;
break;
+ case PJ_TURN_STATE_CONNECTION_BINDING:
+ /* We need to wait until connection binding complete */
+ sess->pending_destroy = PJ_TRUE;
+ can_destroy = PJ_FALSE;
+ break;
case PJ_TURN_STATE_READY:
/* Send REFRESH with LIFETIME=0 */
can_destroy = PJ_FALSE;
@@ -723,6 +730,9 @@ PJ_DEF(pj_status_t) pj_turn_session_alloc(pj_turn_session *sess,
PJ_ASSERT_RETURN(sess->state>PJ_TURN_STATE_NULL &&
sess->state<=PJ_TURN_STATE_RESOLVED,
PJ_EINVALIDOP);
+ PJ_ASSERT_RETURN(param->peer_conn_type == PJ_TURN_TP_UDP ||
+ param->peer_conn_type == PJ_TURN_TP_TCP,
+ PJ_EINVAL);
/* Verify address family in allocation param */
if (param && param->af) {
@@ -760,7 +770,7 @@ PJ_DEF(pj_status_t) pj_turn_session_alloc(pj_turn_session *sess,
/* MUST include REQUESTED-TRANSPORT attribute */
pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg,
PJ_STUN_ATTR_REQ_TRANSPORT,
- PJ_STUN_SET_RT_PROTO(PJ_TURN_TP_UDP));
+ PJ_STUN_SET_RT_PROTO(param->peer_conn_type));
/* Include BANDWIDTH if requested */
if (sess->alloc_param.bandwidth > 0) {
@@ -998,6 +1008,13 @@ PJ_DEF(pj_status_t) pj_turn_session_sendto( pj_turn_session *sess,
}
}
+ /* rfc6062: direct send if peer connection is TCP */
+ if (sess->alloc_param.peer_conn_type == PJ_TURN_TP_TCP) {
+ status = sess->cb.on_send_pkt(sess, pkt, pkt_len,
+ addr, addr_len);
+ goto on_return;
+ }
+
/* See if the peer is bound to a channel number */
ch = lookup_ch_by_addr(sess, addr, pj_sockaddr_get_len(addr),
PJ_FALSE, PJ_FALSE);
@@ -1674,6 +1691,33 @@ static pj_status_t stun_on_rx_indication(pj_stun_session *stun,
sess = (pj_turn_session*)pj_stun_session_get_user_data(stun);
+ if (msg->hdr.type == PJ_STUN_CONNECTION_ATTEMPT_INDICATION) {
+ pj_stun_uint_attr *connection_id_attr;
+ /* Get CONNECTION-ID attribute */
+ connection_id_attr = (pj_stun_uint_attr*)
+ pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_CONNECTION_ID, 0);
+
+ /* Get XOR-PEER-ADDRESS attribute */
+ peer_attr = (pj_stun_xor_peer_addr_attr*)
+ pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_XOR_PEER_ADDR, 0);
+
+ /* Must have both XOR-PEER-ADDRESS and CONNECTION-ID attributes */
+ if (!peer_attr || !connection_id_attr) {
+ PJ_LOG(4,(sess->obj_name,
+ "Received ConnectionAttempt indication with missing attributes"));
+ return PJ_EINVALIDOP;
+ }
+
+ /* Notify application */
+ if (sess->cb.on_peer_connection) {
+ (*sess->cb.on_peer_connection)(sess, connection_id_attr->value,
+ &peer_attr->sockaddr,
+ pj_sockaddr_get_len(&peer_attr->sockaddr),
+ PJ_SUCCESS);
+ }
+ return PJ_SUCCESS;
+ }
+
/* Expecting Data Indication only */
if (msg->hdr.type != PJ_STUN_DATA_INDICATION) {
PJ_LOG(4,(sess->obj_name, "Unexpected STUN %s indication",
@@ -2096,3 +2140,16 @@ static void on_timer_event(pj_timer_heap_t *th, pj_timer_entry *e)
pj_grp_lock_release(sess->grp_lock);
}
+PJ_DEF(void) pj_turn_session_get_server_cred(pj_turn_session *sess,
+ pj_pool_t *pool, pj_str_t *nonce,
+ pj_str_t *realm)
+{
+ pj_stun_session_get_server_cred(sess->stun, pool, nonce, realm);
+}
+
+PJ_DEF(void) pj_turn_session_set_server_cred(pj_turn_session *sess,
+ const pj_str_t *nonce,
+ pj_str_t *realm)
+{
+ pj_stun_session_set_server_cred(sess->stun, nonce, realm);
+}
diff --git a/pjnath/src/pjnath/turn_sock.c b/pjnath/src/pjnath/turn_sock.c
index a30ab5153..c267871e2 100644
--- a/pjnath/src/pjnath/turn_sock.c
+++ b/pjnath/src/pjnath/turn_sock.c
@@ -35,9 +35,29 @@ enum
enum { MAX_BIND_RETRY = 100 };
+enum { CONNECTION_USED = (1<<0), /* TCP connection slot is used or free */
+ CONNECTION_READY = (1<<1) /* TCP connection bind and ready to use for data transfer */
+};
#define INIT 0x1FFFFFFF
+/**
+ * pj_turn_tcp_data_connection contains information on TCP connection open between
+ * the client and the turn server, conveying data from/to a specific peer.
+ * notes: part of RFC 6062 support
+ */
+typedef struct pj_turn_tcp_data_connection
+{
+ pj_uint32_t id; /* identity of this connection as given by the TURN server */
+ pj_uint32_t flags; /* 0 or CONNECTION_USED */
+ pj_sockaddr peer_addr; /* mapped address of connected peer */
+ unsigned peer_addr_len;
+ pj_activesock_t *active_tcp_sock; /* socket between client and TURN server */
+ pj_ioqueue_op_key_t send_key;
+ pj_stun_session *stun_sess; /* STUN session used to send ConnectBind msg */
+ pj_turn_sock *turn_sock; /* up link */
+} pj_turn_tcp_data_connection;
+
struct pj_turn_sock
{
pj_pool_t *pool;
@@ -59,6 +79,11 @@ struct pj_turn_sock
pj_turn_tp_type conn_type;
pj_activesock_t *active_sock;
pj_ioqueue_op_key_t send_key;
+
+ /* RFC 6062 */
+ pj_stun_auth_cred cred; /* saved from control connection */
+ pj_size_t tcp_cnx_count; /* number of elements in tcp_cnx */
+ pj_turn_tcp_data_connection tcp_cnx[PJ_TURN_MAX_TCP_CNX]; /* peer dedicated data connections throught the TURN server */
};
@@ -82,6 +107,12 @@ static void turn_on_rx_data(pj_turn_session *sess,
static void turn_on_state(pj_turn_session *sess,
pj_turn_state_t old_state,
pj_turn_state_t new_state);
+static void turn_on_peer_connection(pj_turn_session *sess,
+ pj_uint32_t conn_id,
+ const pj_sockaddr_t *peer_addr,
+ unsigned addr_len,
+ pj_status_t status);
+
static pj_bool_t on_data_read(pj_activesock_t *asock,
void *data,
@@ -97,6 +128,26 @@ static void turn_sock_on_destroy(void *comp);
static void destroy(pj_turn_sock *turn_sock);
static void timer_cb(pj_timer_heap_t *th, pj_timer_entry *e);
+static pj_bool_t on_peer_data_read(pj_activesock_t *asock,
+ void *data,
+ pj_size_t size,
+ pj_status_t status,
+ pj_size_t *remainder);
+static pj_bool_t on_peer_connect_complete(pj_activesock_t *asock,
+ pj_status_t status);
+static pj_status_t on_tcp_stun_send_msg(pj_stun_session *sess,
+ void *token,
+ const void *pkt,
+ pj_size_t pkt_size,
+ const pj_sockaddr_t *dst_addr,
+ unsigned addr_len);
+static void on_tcp_stun_request_complete(pj_stun_session *sess,
+ pj_status_t status,
+ void *token,
+ pj_stun_tx_data *tdata,
+ const pj_stun_msg *response,
+ const pj_sockaddr_t *src_addr,
+ unsigned src_addr_len);
/* Init config */
PJ_DEF(void) pj_turn_sock_cfg_default(pj_turn_sock_cfg *cfg)
@@ -193,6 +244,7 @@ PJ_DEF(pj_status_t) pj_turn_sock_create(pj_stun_config *cfg,
sess_cb.on_channel_bound = &turn_on_channel_bound;
sess_cb.on_rx_data = &turn_on_rx_data;
sess_cb.on_state = &turn_on_state;
+ sess_cb.on_peer_connection = &turn_on_peer_connection;
status = pj_turn_session_create(cfg, pool->obj_name, af, conn_type,
turn_sock->grp_lock, &sess_cb, 0,
turn_sock, &turn_sock->sess);
@@ -238,6 +290,9 @@ static void destroy(pj_turn_sock *turn_sock)
pj_turn_session_shutdown(turn_sock->sess);
if (turn_sock->active_sock)
pj_activesock_close(turn_sock->active_sock);
+ for (int i=0; i < turn_sock->tcp_cnx_count; ++i) {
+ pj_activesock_close(turn_sock->tcp_cnx[i].active_tcp_sock);
+ }
pj_grp_lock_dec_ref(turn_sock->grp_lock);
pj_grp_lock_release(turn_sock->grp_lock);
}
@@ -302,6 +357,34 @@ static void sess_fail(pj_turn_sock *turn_sock, const char *title,
}
}
+static void peer_cnx_fail(pj_turn_tcp_data_connection *tcp_cnx,
+ const char *title, pj_status_t status)
+{
+ pj_turn_sock *turn_sock = tcp_cnx->turn_sock;
+
+ show_err(turn_sock, title, status);
+ if (tcp_cnx->stun_sess) {
+ pj_stun_session_destroy(tcp_cnx->stun_sess);
+ tcp_cnx->stun_sess = NULL;
+ }
+ if (tcp_cnx->active_tcp_sock) {
+ for (int i=0; i < turn_sock->tcp_cnx_count; ++i) {
+ if (&turn_sock->tcp_cnx[i] == tcp_cnx) {
+ turn_on_peer_connection(turn_sock->sess, tcp_cnx->id,
+ &tcp_cnx->peer_addr,
+ tcp_cnx->peer_addr_len,
+ PJ_EEOF);
+ pj_activesock_close(tcp_cnx->active_tcp_sock);
+ tcp_cnx->active_tcp_sock = NULL;
+ tcp_cnx->flags = 0;
+ if (i == turn_sock->tcp_cnx_count-1)
+ --turn_sock->tcp_cnx_count;
+ break;
+ }
+ }
+ }
+}
+
/*
* Set user data.
*/
@@ -411,6 +494,9 @@ PJ_DEF(pj_status_t) pj_turn_sock_alloc(pj_turn_sock *turn_sock,
/* Set credental */
if (cred) {
+ // save credentials for peer/TCP connections
+ if (param->peer_conn_type == PJ_TURN_TP_TCP)
+ pj_memcpy(&turn_sock->cred, cred, sizeof(turn_sock->cred));
status = pj_turn_session_set_credential(turn_sock->sess, cred);
if (status != PJ_SUCCESS) {
sess_fail(turn_sock, "Error setting credential", status);
@@ -681,7 +767,32 @@ static pj_status_t turn_on_send_pkt(pj_turn_session *sess,
&turn_sock->send_key, pkt, &len, 0,
dst_addr, dst_addr_len);
} else {
- status = pj_activesock_send(turn_sock->active_sock,
+ /* With TCP peer connection filter by address
+ * if packet is for the server or the peer
+ */
+ pj_activesock_t *asock = NULL;
+ pj_turn_session_info info;
+ pj_turn_session_get_info(turn_sock->sess, &info);
+ if (pj_sockaddr_cmp(&info.server, dst_addr) &&
+ turn_sock->alloc_param.peer_conn_type == PJ_TURN_TP_TCP) {
+ for (int i=0; i < turn_sock->tcp_cnx_count; ++i) {
+ pj_turn_tcp_data_connection *tcp_cnx = &turn_sock->tcp_cnx[i];
+ if ((tcp_cnx->flags & CONNECTION_READY) == 0)
+ continue;
+ if (!pj_sockaddr_cmp(&tcp_cnx->peer_addr, dst_addr)) {
+ asock = tcp_cnx->active_tcp_sock;
+ break;
+ }
+ }
+ if (!asock) {
+ status = PJ_ENOTFOUND;
+ show_err(turn_sock, "socket send()", status);
+ return status;
+ }
+ } else {
+ asock = turn_sock->active_sock;
+ }
+ status = pj_activesock_send(asock,
&turn_sock->send_key, pkt, &len, 0);
}
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
@@ -935,4 +1046,365 @@ static void turn_on_state(pj_turn_session *sess,
}
}
+static void turn_on_peer_connection(pj_turn_session *sess,
+ pj_uint32_t conn_id,
+ const pj_sockaddr_t *peer_addr,
+ unsigned addr_len,
+ pj_status_t status)
+{
+ pj_turn_sock *turn_sock = (pj_turn_sock*) pj_turn_session_get_user_data(sess);
+ if (turn_sock == NULL || turn_sock->is_destroying) {
+ /* We've been destroyed */
+ return;
+ }
+
+ if (turn_sock->cb.on_peer_connection) {
+ (*turn_sock->cb.on_peer_connection)(turn_sock, conn_id,
+ peer_addr, addr_len,
+ status);
+ }
+}
+
+PJ_DECL(pj_status_t) pj_turn_connect_peer(pj_turn_sock *turn_sock,
+ pj_uint32_t conn_id,
+ const pj_sockaddr_t *peer_addr,
+ unsigned addr_len)
+{
+ pj_status_t status;
+ pj_turn_tcp_data_connection *new_tcp_cnx = NULL;
+
+ for (int i=0; i < turn_sock->tcp_cnx_count; ++i) {
+ pj_turn_tcp_data_connection *tcp_cnx = &turn_sock->tcp_cnx[i];
+ if ((tcp_cnx->flags & CONNECTION_USED) == 0) {
+ new_tcp_cnx = tcp_cnx;
+ continue;
+ }
+ if (tcp_cnx->id == conn_id)
+ // TODO: need log
+ return PJ_EINVAL; // TODO: need better error code
+ }
+
+ if (!new_tcp_cnx) {
+ if (turn_sock->tcp_cnx_count == PJ_TURN_MAX_TCP_CNX) {
+ // TODO: need log
+ return PJ_ETOOMANY;
+ }
+ new_tcp_cnx = &turn_sock->tcp_cnx[turn_sock->tcp_cnx_count++];
+ }
+
+ /* Initialize this TCP connection slot */
+ pj_bzero(new_tcp_cnx, sizeof(*new_tcp_cnx));
+ new_tcp_cnx->id = conn_id;
+ new_tcp_cnx->flags = CONNECTION_USED;
+ new_tcp_cnx->turn_sock = turn_sock;
+ pj_sockaddr_cp(&new_tcp_cnx->peer_addr, peer_addr);
+ new_tcp_cnx->peer_addr_len = addr_len;
+
+ pj_ioqueue_op_key_init(&new_tcp_cnx->send_key,
+ sizeof(new_tcp_cnx->send_key));
+
+ /* Initiate a new TCP connection on TURN server
+ * that will become the peer data connection */
+ pj_turn_session_info info;
+ int sock_type;
+ pj_sock_t sock;
+ pj_activesock_cfg asock_cfg;
+ pj_activesock_cb asock_cb;
+ pj_sockaddr bound_addr, *cfg_bind_addr;
+ pj_uint16_t max_bind_retry;
+
+ /* Get server address from session info */
+ pj_turn_session_get_info(turn_sock->sess, &info);
+
+ assert(turn_sock->conn_type == PJ_TURN_TP_TCP);
+ sock_type = pj_SOCK_STREAM();
+
+ /* Init socket */
+ status = pj_sock_socket(turn_sock->af, sock_type, 0, &sock);
+ if (status != PJ_SUCCESS) {
+ pj_turn_sock_destroy(turn_sock);
+ return status;
+ }
+
+ /* Bind socket */
+ cfg_bind_addr = &turn_sock->setting.bound_addr;
+ max_bind_retry = MAX_BIND_RETRY;
+ if (turn_sock->setting.port_range &&
+ turn_sock->setting.port_range < max_bind_retry)
+ {
+ max_bind_retry = turn_sock->setting.port_range;
+ }
+ pj_sockaddr_init(turn_sock->af, &bound_addr, NULL, 0);
+ if (cfg_bind_addr->addr.sa_family == pj_AF_INET() ||
+ cfg_bind_addr->addr.sa_family == pj_AF_INET6())
+ {
+ pj_sockaddr_cp(&bound_addr, cfg_bind_addr);
+ }
+ status = pj_sock_bind_random(sock, &bound_addr,
+ turn_sock->setting.port_range,
+ max_bind_retry);
+ if (status != PJ_SUCCESS) {
+ pj_turn_sock_destroy(turn_sock);
+ return status;
+ }
+
+ /* Apply socket buffer size */
+ if (turn_sock->setting.so_rcvbuf_size > 0) {
+ unsigned sobuf_size = turn_sock->setting.so_rcvbuf_size;
+ status = pj_sock_setsockopt_sobuf(sock, pj_SO_RCVBUF(),
+ PJ_TRUE, &sobuf_size);
+ if (status != PJ_SUCCESS) {
+ pj_perror(3, turn_sock->obj_name, status,
+ "Failed setting SO_RCVBUF");
+ } else {
+ if (sobuf_size < turn_sock->setting.so_rcvbuf_size) {
+ PJ_LOG(4, (turn_sock->obj_name,
+ "Warning! Cannot set SO_RCVBUF as configured,"
+ " now=%d, configured=%d", sobuf_size,
+ turn_sock->setting.so_rcvbuf_size));
+ } else {
+ PJ_LOG(5, (turn_sock->obj_name, "SO_RCVBUF set to %d",
+ sobuf_size));
+ }
+ }
+ }
+ if (turn_sock->setting.so_sndbuf_size > 0) {
+ unsigned sobuf_size = turn_sock->setting.so_sndbuf_size;
+ status = pj_sock_setsockopt_sobuf(sock, pj_SO_SNDBUF(),
+ PJ_TRUE, &sobuf_size);
+ if (status != PJ_SUCCESS) {
+ pj_perror(3, turn_sock->obj_name, status,
+ "Failed setting SO_SNDBUF");
+ } else {
+ if (sobuf_size < turn_sock->setting.so_sndbuf_size) {
+ PJ_LOG(4, (turn_sock->obj_name,
+ "Warning! Cannot set SO_SNDBUF as configured,"
+ " now=%d, configured=%d", sobuf_size,
+ turn_sock->setting.so_sndbuf_size));
+ } else {
+ PJ_LOG(5, (turn_sock->obj_name, "SO_SNDBUF set to %d",
+ sobuf_size));
+ }
+ }
+ }
+
+ /* Create active socket */
+ pj_activesock_cfg_default(&asock_cfg);
+ asock_cfg.grp_lock = turn_sock->grp_lock;
+
+ pj_bzero(&asock_cb, sizeof(asock_cb));
+ asock_cb.on_data_read = &on_peer_data_read;
+ asock_cb.on_connect_complete = &on_peer_connect_complete;
+ status = pj_activesock_create(turn_sock->pool, sock,
+ sock_type, &asock_cfg,
+ turn_sock->cfg.ioqueue, &asock_cb,
+ new_tcp_cnx,
+ &new_tcp_cnx->active_tcp_sock);
+ if (status != PJ_SUCCESS) {
+ pj_turn_sock_destroy(turn_sock);
+ return status;
+ }
+
+ char addrtxt[PJ_INET6_ADDRSTRLEN+8];
+ PJ_LOG(5,(turn_sock->pool->obj_name,
+ "Connecting to %s",
+ pj_sockaddr_print(&info.server, addrtxt,
+ sizeof(addrtxt), 3)));
+
+ status = pj_activesock_start_connect(new_tcp_cnx->active_tcp_sock,
+ turn_sock->pool,
+ &info.server,
+ pj_sockaddr_get_len(&info.server));
+ if (status == PJ_SUCCESS) {
+ on_peer_connect_complete(new_tcp_cnx->active_tcp_sock, PJ_SUCCESS);
+ } else if (status != PJ_EPENDING) {
+ pj_perror(3, turn_sock->pool->obj_name, status,
+ "Failed to connect to %s",
+ pj_sockaddr_print(&info.server, addrtxt,
+ sizeof(addrtxt), 3));
+ pj_turn_sock_destroy(turn_sock);
+ return status;
+ }
+
+ return PJ_SUCCESS;
+}
+
+static pj_bool_t on_peer_data_read(pj_activesock_t *asock,
+ void *data,
+ pj_size_t size,
+ pj_status_t status,
+ pj_size_t *remainder)
+{
+ pj_turn_tcp_data_connection *tcp_cnx;
+ pj_turn_sock *turn_sock;
+
+ tcp_cnx = (pj_turn_tcp_data_connection*) pj_activesock_get_user_data(asock);
+ pj_assert(tcp_cnx && tcp_cnx->turn_sock);
+ turn_sock = tcp_cnx->turn_sock;
+
+ pj_grp_lock_acquire(turn_sock->grp_lock);
+
+ if (status != PJ_SUCCESS) {
+ peer_cnx_fail(tcp_cnx, "Peer connection closed", status);
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return PJ_FALSE;
+ }
+
+ *remainder = size;
+ pj_uint8_t* pkt = data;
+ while (*remainder > 0) {
+ if ((tcp_cnx->flags & CONNECTION_READY) != 0) {
+ if (turn_sock->cb.on_rx_data)
+ turn_sock->cb.on_rx_data(turn_sock, pkt, *remainder,
+ &tcp_cnx->peer_addr,
+ tcp_cnx->peer_addr_len);
+ pj_grp_lock_release(turn_sock->grp_lock);
+ *remainder = 0;
+ return PJ_TRUE;
+ }
+
+ /* STUN session waiting for ConnectBind response */
+ pj_size_t parsed_len;
+ unsigned options = PJ_STUN_CHECK_PACKET | PJ_STUN_NO_FINGERPRINT_CHECK;
+ status = pj_stun_session_on_rx_pkt(tcp_cnx->stun_sess, pkt, size,
+ options, NULL, &parsed_len,
+ &tcp_cnx->peer_addr,
+ tcp_cnx->peer_addr_len);
+
+ if (status != PJ_SUCCESS) {
+ peer_cnx_fail(tcp_cnx, "Peer connection closed", status);
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return PJ_FALSE;
+ }
+
+ PJ_LOG(3, ("rfc6062",
+ "parsed STUN msg (read %zu byte(s) over %zu), status=%u",
+ parsed_len, size, status));
+
+ pkt += parsed_len;
+ *remainder -= parsed_len;
+ }
+
+ pj_grp_lock_release(turn_sock->grp_lock);
+
+ return PJ_TRUE;
+}
+
+static pj_bool_t on_peer_connect_complete(pj_activesock_t *asock,
+ pj_status_t status)
+{
+ pj_turn_tcp_data_connection *tcp_cnx;
+ pj_turn_sock *turn_sock;
+
+ PJ_LOG(1, ("rfc6062", "peer data connection %s", status == PJ_SUCCESS ? "ready" : "failed"));
+
+ tcp_cnx = (pj_turn_tcp_data_connection*) pj_activesock_get_user_data(asock);
+ if (!tcp_cnx)
+ return PJ_FALSE;
+
+ turn_sock = tcp_cnx->turn_sock;
+ pj_assert(turn_sock);
+
+ pj_grp_lock_acquire(turn_sock->grp_lock);
+
+ PJ_LOG(3, ("rfc6062", "peer data connection %s", status == PJ_SUCCESS ? "ready" : "failed"));
+
+ // TODO: handle failures
+ if (status != PJ_SUCCESS) {
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return PJ_FALSE;
+ }
+
+ /* start pending read operation */
+ status = pj_activesock_start_read(asock, turn_sock->pool,
+ turn_sock->setting.max_pkt_size, 0);
+ if (status != PJ_SUCCESS) {
+ // TODO: error handling
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return PJ_FALSE;
+ }
+
+ /* Create a temporary STUN session to send the ConnectBind request */
+ pj_stun_session_cb stun_cb;
+ pj_bzero(&stun_cb, sizeof(stun_cb));
+ stun_cb.on_send_msg = &on_tcp_stun_send_msg;
+ stun_cb.on_request_complete = &on_tcp_stun_request_complete;
+ status = pj_stun_session_create(&turn_sock->cfg, NULL,
+ &stun_cb, PJ_FALSE, NULL,
+ &tcp_cnx->stun_sess);
+ if (status != PJ_SUCCESS) {
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return PJ_FALSE;
+ }
+
+ pj_stun_session_set_user_data(tcp_cnx->stun_sess, tcp_cnx);
+
+ /* Copy credentials from control connection */
+ pj_stun_session_set_credential(tcp_cnx->stun_sess, PJ_STUN_AUTH_LONG_TERM, &turn_sock->cred);
+ pj_str_t server_nonce, server_realm;
+ pj_turn_session_get_server_cred(turn_sock->sess, turn_sock->pool, &server_nonce, &server_realm);
+ pj_stun_session_set_server_cred(tcp_cnx->stun_sess, &server_nonce, &server_realm);
+
+ /* Send ConnectBind request */
+ pj_stun_tx_data *tdata;
+ status = pj_stun_session_create_req(tcp_cnx->stun_sess, PJ_STUN_CONNECTION_BIND_REQUEST,
+ PJ_STUN_MAGIC, NULL, &tdata);
+ if (status != PJ_SUCCESS) {
+ pj_stun_session_destroy(tcp_cnx->stun_sess);
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return PJ_FALSE;
+ }
+
+ /* MUST include REQUESTED-TRANSPORT attribute */
+ pj_stun_msg_add_uint_attr(tdata->pool, tdata->msg, PJ_STUN_ATTR_CONNECTION_ID, tcp_cnx->id);
+
+ PJ_LOG(3, ("rfc6062", "bind TCP connection id=%x", tcp_cnx->id));
+ status = pj_stun_session_send_msg(tcp_cnx->stun_sess, tcp_cnx, PJ_FALSE, PJ_FALSE,
+ &tcp_cnx->peer_addr, tcp_cnx->peer_addr_len,
+ tdata);
+ if (status != PJ_SUCCESS && status != PJ_EPENDING) {
+ pj_stun_session_destroy(tcp_cnx->stun_sess);
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return status;
+ }
+
+ pj_grp_lock_release(turn_sock->grp_lock);
+ return PJ_TRUE;
+}
+
+static pj_status_t on_tcp_stun_send_msg(pj_stun_session *sess,
+ void *token,
+ const void *pkt,
+ pj_size_t pkt_size,
+ const pj_sockaddr_t *dst_addr,
+ unsigned addr_len)
+{
+ pj_status_t status;
+ pj_turn_tcp_data_connection *tcp_cnx = (pj_turn_tcp_data_connection*) token;
+ pj_assert(tcp_cnx != NULL && tcp_cnx->turn_sock != NULL);
+
+ pj_grp_lock_acquire(tcp_cnx->turn_sock->grp_lock);
+ status = pj_activesock_send(tcp_cnx->active_tcp_sock, &tcp_cnx->send_key, pkt, &pkt_size, 0);
+ pj_grp_lock_release(tcp_cnx->turn_sock->grp_lock);
+ return status;
+}
+
+static void on_tcp_stun_request_complete(pj_stun_session *sess,
+ pj_status_t status,
+ void *token,
+ pj_stun_tx_data *tdata,
+ const pj_stun_msg *response,
+ const pj_sockaddr_t *src_addr,
+ unsigned src_addr_len)
+{
+ pj_turn_tcp_data_connection *tcp_cnx = (pj_turn_tcp_data_connection*) token;
+ pj_assert(tcp_cnx != NULL && tcp_cnx->turn_sock != NULL);
+
+ pj_grp_lock_acquire(tcp_cnx->turn_sock->grp_lock);
+ pj_stun_session_destroy(tcp_cnx->stun_sess);
+ tcp_cnx->stun_sess = NULL;
+ tcp_cnx->flags |= CONNECTION_READY;
+ PJ_LOG(3, ("rfc6062", "peer data connection bind %s", status == PJ_SUCCESS ? "succeed" : "failed"));
+ pj_grp_lock_release(tcp_cnx->turn_sock->grp_lock);
+}
......@@ -17,29 +17,28 @@ on behalf of Savoir-faire Linux.
---
pjnath/include/pjnath/config.h | 13 +-
pjnath/include/pjnath/ice_session.h | 118 ++-
pjnath/include/pjnath/ice_strans.h | 61 +-
pjnath/include/pjnath/stun_session.h | 66 +-
pjnath/include/pjnath/stun_sock.h | 84 +-
pjnath/include/pjnath/ice_session.h | 118 ++++++++++++++---
pjnath/include/pjnath/ice_strans.h | 61 ++++++++-
pjnath/include/pjnath/stun_session.h | 66 ++++++++-
pjnath/include/pjnath/stun_sock.h | 84 +++++++++---
pjnath/src/pjnath-test/concur_test.c | 8 +-
pjnath/src/pjnath-test/sess_auth.c | 12 +-
pjnath/src/pjnath-test/stun_sock_test.c | 7 +-
pjnath/src/pjnath/ice_session.c | 388 +++++--
pjnath/src/pjnath/ice_strans.c | 741 ++++++++-----
pjnath/src/pjnath/ice_session.c | 388 +++++++++++++++++++++++++++++++++++++----------------
pjnath/src/pjnath/ice_strans.c | 741 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
pjnath/src/pjnath/nat_detect.c | 12 +-
pjnath/src/pjnath/stun_session.c | 14 +-
pjnath/src/pjnath/stun_sock.c | 1285 ++++++++++++++++-------
pjnath/src/pjnath/stun_session.c | 12 +-
pjnath/src/pjnath/stun_sock.c | 1285 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------
pjnath/src/pjnath/turn_session.c | 3 +-
pjnath/src/pjnath/turn_sock.c | 12 +-
pjnath/src/pjturn-client/client_main.c | 11 +-
pjnath/src/pjturn-srv/allocation.c | 2 +-
pjnath/src/pjturn-srv/server.c | 2 +-
pjsip-apps/src/samples/icedemo.c | 671 ++++++------
pjsip-apps/src/samples/icedemo.c | 671 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------
pjsip/src/pjsua-lib/pjsua_core.c | 8 +-
20 files changed, 2432 insertions(+), 1086 deletions(-)
19 files changed, 2424 insertions(+), 1080 deletions(-)
diff --git a/pjnath/include/pjnath/config.h b/pjnath/include/pjnath/config.h
index e157d39ee..2e09cb816 100644
index fc1e2755..6f17a663 100644
--- a/pjnath/include/pjnath/config.h
+++ b/pjnath/include/pjnath/config.h
@@ -1,5 +1,5 @@
......@@ -49,7 +48,7 @@ index e157d39ee..2e09cb816 100644
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
@@ -249,7 +249,7 @@
@@ -248,7 +248,7 @@
* Default: 8
*/
#ifndef PJ_ICE_ST_MAX_CAND
......@@ -58,7 +57,7 @@ index e157d39ee..2e09cb816 100644
#endif
@@ -257,21 +257,20 @@
@@ -256,21 +256,20 @@
* Maximum number of STUN transports for each ICE stream transport component.
* Valid values are 1 - 64.
*
......@@ -85,7 +84,7 @@ index e157d39ee..2e09cb816 100644
diff --git a/pjnath/include/pjnath/ice_session.h b/pjnath/include/pjnath/ice_session.h
index fa13a3b7c..2e686ea1f 100644
index fa13a3b7..2e686ea1 100644
--- a/pjnath/include/pjnath/ice_session.h
+++ b/pjnath/include/pjnath/ice_session.h
@@ -163,6 +163,51 @@ typedef enum pj_ice_cand_type
......@@ -273,7 +272,7 @@ index fa13a3b7c..2e686ea1f 100644
* @}
*/
diff --git a/pjnath/include/pjnath/ice_strans.h b/pjnath/include/pjnath/ice_strans.h
index b4a83067f..2b491e0d0 100644
index b4a83067..2b491e0d 100644
--- a/pjnath/include/pjnath/ice_strans.h
+++ b/pjnath/include/pjnath/ice_strans.h
@@ -1,5 +1,5 @@
......@@ -378,7 +377,7 @@ index b4a83067f..2b491e0d0 100644
/**
* @}
diff --git a/pjnath/include/pjnath/stun_session.h b/pjnath/include/pjnath/stun_session.h
index 28c5985e8..de52379cf 100644
index f8ea4d1d..1e95a297 100644
--- a/pjnath/include/pjnath/stun_session.h
+++ b/pjnath/include/pjnath/stun_session.h
@@ -1,5 +1,5 @@
......@@ -458,9 +457,9 @@ index 28c5985e8..de52379cf 100644
/**
* Destroy the STUN session and all objects created in the context of
@@ -758,6 +792,24 @@ PJ_DEF(void)
pj_stun_session_set_server_cred(pj_stun_session *sess, const pj_str_t *nonce,
pj_str_t *realm);
@@ -751,6 +785,24 @@ PJ_DECL(void) pj_stun_msg_destroy_tdata(pj_stun_session *sess,
pj_stun_tx_data *tdata);
+/**
+ *
......@@ -484,7 +483,7 @@ index 28c5985e8..de52379cf 100644
* @}
*/
diff --git a/pjnath/include/pjnath/stun_sock.h b/pjnath/include/pjnath/stun_sock.h
index fff4df885..d70300bb3 100644
index fff4df88..d70300bb 100644
--- a/pjnath/include/pjnath/stun_sock.h
+++ b/pjnath/include/pjnath/stun_sock.h
@@ -1,5 +1,5 @@
......@@ -649,7 +648,7 @@ index fff4df885..d70300bb3 100644
/**
* @}
diff --git a/pjnath/src/pjnath-test/concur_test.c b/pjnath/src/pjnath-test/concur_test.c
index c3013d2ab..ebe173922 100644
index c3013d2a..ebe17392 100644
--- a/pjnath/src/pjnath-test/concur_test.c
+++ b/pjnath/src/pjnath-test/concur_test.c
@@ -183,10 +183,10 @@ static int stun_destroy_test_session(struct stun_test_session *test_sess)
......@@ -668,7 +667,7 @@ index c3013d2ab..ebe173922 100644
return -10;
}
diff --git a/pjnath/src/pjnath-test/sess_auth.c b/pjnath/src/pjnath-test/sess_auth.c
index 055eaad61..d1ad137a3 100644
index 055eaad6..d1ad137a 100644
--- a/pjnath/src/pjnath-test/sess_auth.c
+++ b/pjnath/src/pjnath-test/sess_auth.c
@@ -248,7 +248,8 @@ static int create_std_server(pj_stun_auth_type auth_type,
......@@ -705,7 +704,7 @@ index 055eaad61..d1ad137a3 100644
destroy_client_server();
return -270;
diff --git a/pjnath/src/pjnath-test/stun_sock_test.c b/pjnath/src/pjnath-test/stun_sock_test.c
index fff4fad26..a54df74dc 100644
index fff4fad2..a54df74d 100644
--- a/pjnath/src/pjnath-test/stun_sock_test.c
+++ b/pjnath/src/pjnath-test/stun_sock_test.c
@@ -255,8 +255,8 @@ static pj_status_t create_client(pj_stun_config *cfg,
......@@ -732,7 +731,7 @@ index fff4fad26..a54df74dc 100644
app_perror(" error: server sending data", status);
ret = -390;
diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
index c51dba771..b96390613 100644
index c51dba77..b9639061 100644
--- a/pjnath/src/pjnath/ice_session.c
+++ b/pjnath/src/pjnath/ice_session.c
@@ -1,5 +1,5 @@
......@@ -1376,7 +1375,7 @@ index c51dba771..b96390613 100644
c->state == PJ_ICE_SESS_CHECK_STATE_WAITING)
{
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 54ef8ba69..f2d0aa5ed 100644
index ca15a74e..d5877e31 100644
--- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c
@@ -69,6 +69,7 @@ enum tp_type
......@@ -1754,7 +1753,7 @@ index 54ef8ba69..f2d0aa5ed 100644
pj_grp_lock_add_ref(ice_st->grp_lock);
pj_grp_lock_add_handler(ice_st->grp_lock, pool, ice_st,
&ice_st_on_destroy);
@@ -1099,6 +1160,10 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
@@ -1097,6 +1158,10 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
ice_cb.on_ice_complete = &on_ice_complete;
ice_cb.on_rx_data = &ice_rx_data;
ice_cb.on_tx_pkt = &ice_tx_pkt;
......@@ -1765,7 +1764,7 @@ index 54ef8ba69..f2d0aa5ed 100644
/* Create! */
status = pj_ice_sess_create(&ice_st->cfg.stun_cfg, ice_st->obj_name, role,
@@ -1174,7 +1239,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
@@ -1172,7 +1237,7 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
&cand->foundation, &cand->addr,
&cand->base_addr, &cand->rel_addr,
pj_sockaddr_get_len(&cand->addr),
......@@ -1774,7 +1773,7 @@ index 54ef8ba69..f2d0aa5ed 100644
if (status != PJ_SUCCESS)
goto on_error;
}
@@ -1462,110 +1527,162 @@ PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st,
@@ -1460,110 +1525,162 @@ PJ_DEF(pj_status_t) pj_ice_strans_sendto( pj_ice_strans *ice_st,
const pj_sockaddr_t *dst_addr,
int dst_addr_len)
{
......@@ -2033,7 +2032,7 @@ index 54ef8ba69..f2d0aa5ed 100644
}
/*
@@ -1619,7 +1736,15 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status)
@@ -1615,7 +1732,15 @@ static void on_ice_complete(pj_ice_sess *ice, pj_status_t status)
sizeof(lip), 3);
pj_sockaddr_print(&check->rcand->addr, rip,
sizeof(rip), 3);
......@@ -2050,7 +2049,7 @@ index 54ef8ba69..f2d0aa5ed 100644
if (tp_typ == TP_TURN) {
/* Activate channel binding for the remote address
* for more efficient data transfer using TURN.
@@ -1687,12 +1812,16 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
@@ -1683,12 +1808,16 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
PJ_ASSERT_RETURN(comp_id && comp_id <= ice_st->comp_cnt, PJ_EINVAL);
......@@ -2068,7 +2067,7 @@ index 54ef8ba69..f2d0aa5ed 100644
pj_sockaddr_get_port(dst_addr),
tp_typ));
@@ -1728,12 +1857,52 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
@@ -1724,12 +1853,52 @@ static pj_status_t ice_tx_pkt(pj_ice_sess *ice,
dest_addr_len = dst_addr_len;
}
......@@ -2125,7 +2124,7 @@ index 54ef8ba69..f2d0aa5ed 100644
}
return (status==PJ_SUCCESS||status==PJ_EPENDING) ? PJ_SUCCESS : status;
@@ -1759,22 +1928,115 @@ static void ice_rx_data(pj_ice_sess *ice,
@@ -1755,22 +1924,115 @@ static void ice_rx_data(pj_ice_sess *ice,
}
}
......@@ -2254,7 +2253,7 @@ index 54ef8ba69..f2d0aa5ed 100644
/* We have disassociated ourselves from the STUN socket */
return PJ_FALSE;
}
@@ -1818,9 +2080,17 @@ static pj_bool_t stun_on_data_sent(pj_stun_sock *stun_sock,
@@ -1814,9 +2076,17 @@ static pj_bool_t stun_on_data_sent(pj_stun_sock *stun_sock,
pj_ioqueue_op_key_t *send_key,
pj_ssize_t sent)
{
......@@ -2275,7 +2274,7 @@ index 54ef8ba69..f2d0aa5ed 100644
return PJ_TRUE;
}
@@ -2025,6 +2295,10 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
@@ -2021,6 +2291,10 @@ static pj_bool_t stun_on_status(pj_stun_sock *stun_sock,
}
}
break;
......@@ -2286,7 +2285,7 @@ index 54ef8ba69..f2d0aa5ed 100644
}
return pj_grp_lock_dec_ref(ice_st->grp_lock)? PJ_FALSE : PJ_TRUE;
@@ -2256,5 +2530,4 @@ static void turn_on_state(pj_turn_sock *turn_sock, pj_turn_state_t old_state,
@@ -2252,5 +2526,4 @@ static void turn_on_state(pj_turn_sock *turn_sock, pj_turn_state_t old_state,
pj_grp_lock_dec_ref(comp->ice_st->grp_lock);
pj_log_pop_indent();
......@@ -2295,7 +2294,7 @@ index 54ef8ba69..f2d0aa5ed 100644
+}
\ No newline at end of file
diff --git a/pjnath/src/pjnath/nat_detect.c b/pjnath/src/pjnath/nat_detect.c
index 31b06c30c..bb081ad37 100644
index db0de10b..3013eeed 100644
--- a/pjnath/src/pjnath/nat_detect.c
+++ b/pjnath/src/pjnath/nat_detect.c
@@ -329,7 +329,8 @@ PJ_DEF(pj_status_t) pj_stun_detect_nat_type2(const pj_sockaddr *server,
......@@ -2325,7 +2324,7 @@ index 31b06c30c..bb081ad37 100644
goto on_error;
diff --git a/pjnath/src/pjnath/stun_session.c b/pjnath/src/pjnath/stun_session.c
index 5e2efc35a..6ad07e284 100644
index 7b53aba7..2b006d91 100644
--- a/pjnath/src/pjnath/stun_session.c
+++ b/pjnath/src/pjnath/stun_session.c
@@ -49,6 +49,8 @@ struct pj_stun_session
......@@ -2355,20 +2354,18 @@ index 5e2efc35a..6ad07e284 100644
if (grp_lock) {
sess->grp_lock = grp_lock;
@@ -1524,3 +1528,11 @@ pj_stun_session_set_server_cred(pj_stun_session *sess, const pj_str_t *nonce,
pj_strdup(sess->pool, &sess->next_nonce, nonce);
pj_strdup(sess->pool, &sess->server_realm, realm);
@@ -1511,3 +1515,9 @@ on_return:
return status;
}
+
+PJ_DECL(pj_stun_session_cb *) pj_stun_session_callback(pj_stun_session *sess) {
+ return sess ? &sess->cb : NULL;
+}
+
+PJ_DECL(pj_stun_tp_type) pj_stun_session_tp_type(pj_stun_session *sess) {
+ return sess ? sess->conn_type : PJ_STUN_TP_UDP;
+}
diff --git a/pjnath/src/pjnath/stun_sock.c b/pjnath/src/pjnath/stun_sock.c
index 4031bb354..7624cf255 100644
index 7692e6c1..7624cf25 100644
--- a/pjnath/src/pjnath/stun_sock.c
+++ b/pjnath/src/pjnath/stun_sock.c
@@ -1,5 +1,5 @@
......@@ -2842,8 +2839,8 @@ index 4031bb354..7624cf255 100644
- status = pj_sock_setsockopt_sobuf(stun_sock->sock_fd, pj_SO_RCVBUF(),
- PJ_TRUE, &sobuf_size);
- if (status != PJ_SUCCESS) {
- pj_perror(3, stun_sock->obj_name, status,
- "Failed setting SO_RCVBUF");
- PJ_PERROR(3, (stun_sock->obj_name, status,
- "Failed setting SO_RCVBUF"));
- } else {
- if (sobuf_size < cfg->so_rcvbuf_size) {
- PJ_LOG(4, (stun_sock->obj_name,
......@@ -2868,8 +2865,8 @@ index 4031bb354..7624cf255 100644
- status = pj_sock_setsockopt_sobuf(stun_sock->sock_fd, pj_SO_SNDBUF(),
- PJ_TRUE, &sobuf_size);
- if (status != PJ_SUCCESS) {
- pj_perror(3, stun_sock->obj_name, status,
- "Failed setting SO_SNDBUF");
- PJ_PERROR(3, (stun_sock->obj_name, status,
- "Failed setting SO_SNDBUF"));
- } else {
- if (sobuf_size < cfg->so_sndbuf_size) {
- PJ_LOG(4, (stun_sock->obj_name,
......@@ -3344,7 +3341,7 @@ index 4031bb354..7624cf255 100644
if (status != PJ_SUCCESS && status != PJ_EPENDING)
goto on_error;
@@ -637,7 +1032,7 @@ static pj_status_t get_mapped_addr(pj_stun_sock *stun_sock)
@@ -637,7 +1032,7 @@ on_error:
/* Get info */
PJ_DEF(pj_status_t) pj_stun_sock_get_info( pj_stun_sock *stun_sock,
......@@ -3778,7 +3775,7 @@ index 4031bb354..7624cf255 100644
pj_status_t status,
void *token,
pj_stun_tx_data *tdata,
@@ -869,9 +1479,9 @@ static void sess_on_request_complete(pj_stun_session *sess,
@@ -869,9 +1479,9 @@ on_return:
}
/* Schedule keep-alive timer */
......@@ -3900,10 +3897,10 @@ index 4031bb354..7624cf255 100644
+ return stun_sock ? stun_sock->stun_sess : NULL;
+}
diff --git a/pjnath/src/pjnath/turn_session.c b/pjnath/src/pjnath/turn_session.c
index 4fd643be1..1e0cda437 100644
index fcbe703e..1c0430bc 100644
--- a/pjnath/src/pjnath/turn_session.c
+++ b/pjnath/src/pjnath/turn_session.c
@@ -306,7 +306,8 @@ PJ_DEF(pj_status_t) pj_turn_session_create( const pj_stun_config *cfg,
@@ -311,7 +311,8 @@ PJ_DEF(pj_status_t) pj_turn_session_create( const pj_stun_config *cfg,
stun_cb.on_request_complete = &stun_on_request_complete;
stun_cb.on_rx_indication = &stun_on_rx_indication;
status = pj_stun_session_create(&sess->stun_cfg, sess->obj_name, &stun_cb,
......@@ -3913,45 +3910,8 @@ index 4fd643be1..1e0cda437 100644
if (status != PJ_SUCCESS) {
do_destroy(sess);
return status;
diff --git a/pjnath/src/pjnath/turn_sock.c b/pjnath/src/pjnath/turn_sock.c
index c267871e2..0fe2d8037 100644
--- a/pjnath/src/pjnath/turn_sock.c
+++ b/pjnath/src/pjnath/turn_sock.c
@@ -1210,7 +1210,7 @@ PJ_DECL(pj_status_t) pj_turn_connect_peer(pj_turn_sock *turn_sock,
"Connecting to %s",
pj_sockaddr_print(&info.server, addrtxt,
sizeof(addrtxt), 3)));
-
+#if PJ_HAS_TCP
status = pj_activesock_start_connect(new_tcp_cnx->active_tcp_sock,
turn_sock->pool,
&info.server,
@@ -1225,7 +1225,7 @@ PJ_DECL(pj_status_t) pj_turn_connect_peer(pj_turn_sock *turn_sock,
pj_turn_sock_destroy(turn_sock);
return status;
}
-
+#endif
return PJ_SUCCESS;
}
@@ -1329,10 +1329,10 @@ static pj_bool_t on_peer_connect_complete(pj_activesock_t *asock,
pj_bzero(&stun_cb, sizeof(stun_cb));
stun_cb.on_send_msg = &on_tcp_stun_send_msg;
stun_cb.on_request_complete = &on_tcp_stun_request_complete;
- status = pj_stun_session_create(&turn_sock->cfg, NULL,
- &stun_cb, PJ_FALSE, NULL,
- &tcp_cnx->stun_sess);
- if (status != PJ_SUCCESS) {
+ status =
+ pj_stun_session_create(&turn_sock->cfg, NULL, &stun_cb, PJ_FALSE,
+ NULL, &tcp_cnx->stun_sess, PJ_STUN_TP_TCP);
+ if (status != PJ_SUCCESS) {
pj_grp_lock_release(turn_sock->grp_lock);
return PJ_FALSE;
}
diff --git a/pjnath/src/pjturn-client/client_main.c b/pjnath/src/pjturn-client/client_main.c
index 1a8667220..5f013631a 100644
index 1a866722..5f013631 100644
--- a/pjnath/src/pjturn-client/client_main.c
+++ b/pjnath/src/pjturn-client/client_main.c
@@ -154,10 +154,10 @@ static int init()
......@@ -3981,7 +3941,7 @@ index 1a8667220..5f013631a 100644
case 'q':
g.quit = PJ_TRUE;
diff --git a/pjnath/src/pjturn-srv/allocation.c b/pjnath/src/pjturn-srv/allocation.c
index 6c9c9ce11..eea91f01b 100644
index 6c9c9ce1..eea91f01 100644
--- a/pjnath/src/pjturn-srv/allocation.c
+++ b/pjnath/src/pjturn-srv/allocation.c
@@ -338,7 +338,7 @@ PJ_DEF(pj_status_t) pj_turn_allocation_create(pj_turn_transport *transport,
......@@ -3994,7 +3954,7 @@ index 6c9c9ce11..eea91f01b 100644
goto on_error;
}
diff --git a/pjnath/src/pjturn-srv/server.c b/pjnath/src/pjturn-srv/server.c
index 94dda29a3..95ad1793d 100644
index 94dda29a..95ad1793 100644
--- a/pjnath/src/pjturn-srv/server.c
+++ b/pjnath/src/pjturn-srv/server.c
@@ -156,7 +156,7 @@ PJ_DEF(pj_status_t) pj_turn_srv_create(pj_pool_factory *pf,
......@@ -4007,7 +3967,7 @@ index 94dda29a3..95ad1793d 100644
goto on_error;
}
diff --git a/pjsip-apps/src/samples/icedemo.c b/pjsip-apps/src/samples/icedemo.c
index 9d811374a..92826fd8d 100644
index 9d811374..92826fd8 100644
--- a/pjsip-apps/src/samples/icedemo.c
+++ b/pjsip-apps/src/samples/icedemo.c
@@ -43,7 +43,7 @@ static struct app_t
......@@ -4757,7 +4717,7 @@ index 9d811374a..92826fd8d 100644
status = icedemo_init();
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index ea1e72b85..39d05d1ed 100644
index ea1e72b8..39d05d1e 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -1529,10 +1529,10 @@ static void resolve_stun_entry(pjsua_stun_resolve *sess)
......
# PJPROJECT
PJPROJECT_VERSION := 6b9212dcb4b3f781c1e922ae544b063880bc46ac
PJPROJECT_VERSION := 5dfa75be7d69047387f9b0436dd9492bbbf03fe4
PJPROJECT_URL := https://github.com/pjsip/pjproject/archive/$(PJPROJECT_VERSION).tar.gz
PJPROJECT_OPTIONS := --disable-oss \
......@@ -61,7 +61,6 @@ endif
$(APPLY) $(SRC)/pjproject/fix_turn_fallback.patch
$(APPLY) $(SRC)/pjproject/fix_ioqueue_ipv6_sendto.patch
$(APPLY) $(SRC)/pjproject/add_dtls_transport.patch
$(APPLY) $(SRC)/pjproject/rfc6062.patch
$(APPLY) $(SRC)/pjproject/rfc6544.patch
$(APPLY) $(SRC)/pjproject/ice_config.patch
$(APPLY) $(SRC)/pjproject/sip_config.patch
......
......@@ -162,7 +162,7 @@ public:
void onTurnState(pj_turn_state_t old_state, pj_turn_state_t new_state);
void onRxData(const uint8_t* pkt, unsigned pkt_len, const pj_sockaddr_t* peer_addr, unsigned addr_len);
void onPeerConnection(pj_uint32_t conn_id, const pj_sockaddr_t* peer_addr, unsigned addr_len, pj_status_t status);
pj_status_t onPeerConnection(pj_uint32_t conn_id, const pj_sockaddr_t* peer_addr, unsigned addr_len);
void ioJob();
std::mutex apiMutex_;
......@@ -238,25 +238,22 @@ TurnTransportPimpl::onRxData(const uint8_t* pkt, unsigned pkt_len,
(channel_it->second) << std::string(reinterpret_cast<const char*>(pkt), pkt_len);
}
void
pj_status_t
TurnTransportPimpl::onPeerConnection(pj_uint32_t conn_id,
const pj_sockaddr_t* addr, unsigned addr_len,
pj_status_t status)
const pj_sockaddr_t* addr, unsigned addr_len)
{
IpAddr peer_addr (*static_cast<const pj_sockaddr*>(addr), addr_len);
if (status == PJ_SUCCESS) {
JAMI_DBG() << "Received connection attempt from " << peer_addr.toString(true, true)
<< ", id=" << std::hex << conn_id;
pj_turn_connect_peer(relay, conn_id, addr, addr_len);
JAMI_DBG() << "Received connection attempt from "
<< peer_addr.toString(true, true) << ", id=" << std::hex
<< conn_id;
{
MutexGuard lk {apiMutex_};
peerChannels_.emplace(peer_addr, PeerChannel {});
}
}
if (settings.onPeerConnection)
settings.onPeerConnection(conn_id, peer_addr, status == PJ_SUCCESS);
settings.onPeerConnection(conn_id, peer_addr, true);
return PJ_SUCCESS;
}
void
......@@ -317,11 +314,12 @@ TurnTransport::TurnTransport(const TurnTransportParams& params)
auto pimpl = static_cast<TurnTransportPimpl*>(pj_turn_sock_get_user_data(relay));
pimpl->onTurnState(old_state, new_state);
};
relay_cb.on_peer_connection = [](pj_turn_sock* relay, pj_uint32_t conn_id,
const pj_sockaddr_t* peer_addr, unsigned addr_len,
pj_status_t status) {
relay_cb.on_connection_attempt = [](pj_turn_sock *relay,
pj_uint32_t conn_id,
const pj_sockaddr_t *peer_addr,
unsigned addr_len) {
auto pimpl = static_cast<TurnTransportPimpl *>(pj_turn_sock_get_user_data(relay));
pimpl->onPeerConnection(conn_id, peer_addr, addr_len, status);
return pimpl->onPeerConnection(conn_id, peer_addr, addr_len);
};
// TURN socket config
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment