Commit ce44112e authored by Mickaël Turnel's avatar Mickaël Turnel
Browse files

Add configuration for turn TCP/TLS

(cherry picked from commit 7bdd070f)
parent 6e926b53
......@@ -291,6 +291,9 @@ LinphoneNatPolicy * linphone_config_create_nat_policy_from_section(const Linphon
const char *server = lp_config_get_string(config, section, "stun_server", NULL);
const char *username = lp_config_get_string(config, section, "stun_server_username", NULL);
bctbx_list_t *l = lp_config_get_string_list(config, section, "protocols", NULL);
bool_t turn_enable_udp = linphone_config_get_bool(config, section, "turn_enable_udp", TRUE);
bool_t turn_enable_tcp = linphone_config_get_bool(config, section, "turn_enable_tcp", FALSE);
bool_t turn_enable_tls = linphone_config_get_bool(config, section, "turn_enable_tls", FALSE);
LinphoneNatPolicy *policy;
if (config_ref)
policy = _linphone_nat_policy_new_with_ref(NULL, config_ref);
......@@ -312,6 +315,9 @@ LinphoneNatPolicy * linphone_config_create_nat_policy_from_section(const Linphon
if (upnp_enabled) linphone_nat_policy_enable_upnp(policy, TRUE);
bctbx_list_free_with_data(l, (bctbx_list_free_func)ms_free);
}
linphone_nat_policy_enable_udp_turn_transport(policy, turn_enable_udp);
linphone_nat_policy_enable_tcp_turn_transport(policy, turn_enable_tcp);
linphone_nat_policy_enable_tls_turn_transport(policy, turn_enable_tls);
return policy;
}
LinphoneNatPolicy * linphone_core_create_nat_policy_from_config(LinphoneCore *lc, const char *ref) {
......@@ -336,6 +342,30 @@ LinphoneNatPolicy * linphone_core_create_nat_policy_from_config(LinphoneCore *lc
return policy;
}
void linphone_nat_policy_enable_udp_turn_transport(LinphoneNatPolicy *policy, bool_t enable) {
policy->turn_udp_enabled = enable;
}
bool_t linphone_nat_policy_udp_turn_transport_enabled(LinphoneNatPolicy *policy) {
return policy->turn_udp_enabled;
}
void linphone_nat_policy_enable_tcp_turn_transport(LinphoneNatPolicy *policy, bool_t enable) {
policy->turn_tcp_enabled = enable;
}
bool_t linphone_nat_policy_tcp_turn_transport_enabled(LinphoneNatPolicy *policy) {
return policy->turn_tcp_enabled;
}
void linphone_nat_policy_enable_tls_turn_transport(LinphoneNatPolicy *policy, bool_t enable) {
policy->turn_tls_enabled = enable;
}
bool_t linphone_nat_policy_tls_turn_transport_enabled(LinphoneNatPolicy *policy) {
return policy->turn_tls_enabled;
}
LinphoneCore *linphone_nat_policy_get_core(const LinphoneNatPolicy *policy) {
return policy->lc;
}
......@@ -486,6 +486,9 @@ struct _LinphoneNatPolicy {
bool_t turn_enabled;
bool_t ice_enabled;
bool_t upnp_enabled;
bool_t turn_udp_enabled;
bool_t turn_tcp_enabled;
bool_t turn_tls_enabled;
};
BELLE_SIP_DECLARE_VPTR_NO_EXPORT(LinphoneNatPolicy);
......
......@@ -176,6 +176,54 @@ LINPHONE_PUBLIC void linphone_nat_policy_resolve_stun_server(LinphoneNatPolicy *
*/
LINPHONE_PUBLIC const struct addrinfo * linphone_nat_policy_get_stun_server_addrinfo(LinphoneNatPolicy *policy);
/**
* Enable UDP TURN transport.
* Used when TURN is enabled.
* @param[in] policy #LinphoneNatPolicy object
* @param[in] enable Boolean value telling whether to enable UDP TURN transport.
*/
LINPHONE_PUBLIC void linphone_nat_policy_enable_udp_turn_transport(LinphoneNatPolicy *policy, bool_t enable);
/**
* Tells whether UDP TURN transport is enabled.
* Used when TURN is enabled.
* @param[in] policy #LinphoneNatPolicy object
* @return Boolean value telling whether UDP TURN transport is enabled.
*/
LINPHONE_PUBLIC bool_t linphone_nat_policy_udp_turn_transport_enabled(LinphoneNatPolicy *policy);
/**
* Enable TCP TURN transport.
* Used when TURN is enabled.
* @param[in] policy #LinphoneNatPolicy object
* @param[in] enable Boolean value telling whether to enable TCP TURN transport.
*/
LINPHONE_PUBLIC void linphone_nat_policy_enable_tcp_turn_transport(LinphoneNatPolicy *policy, bool_t enable);
/**
* Tells whether TCP TURN transport is enabled.
* Used when TURN is enabled.
* @param[in] policy #LinphoneNatPolicy object
* @return Boolean value telling whether TCP TURN transport is enabled.
*/
LINPHONE_PUBLIC bool_t linphone_nat_policy_tcp_turn_transport_enabled(LinphoneNatPolicy *policy);
/**
* Enable TLS TURN transport.
* Used when TURN is enabled.
* @param[in] policy #LinphoneNatPolicy object
* @param[in] enable Boolean value telling whether to enable TLS TURN transport.
*/
LINPHONE_PUBLIC void linphone_nat_policy_enable_tls_turn_transport(LinphoneNatPolicy *policy, bool_t enable);
/**
* Tells whether TLS TURN transport is enabled.
* Used when TURN is enabled.
* @param[in] policy #LinphoneNatPolicy object
* @return Boolean value telling whether TLS TURN transport is enabled.
*/
LINPHONE_PUBLIC bool_t linphone_nat_policy_tls_turn_transport_enabled(LinphoneNatPolicy *policy);
/**
* Returns the #LinphoneCore object managing this nat policy, if any.
* @param[in] fr #LinphoneNatPolicy object
......
......@@ -228,7 +228,24 @@ int IceService::gatherIceCandidates () {
string server = linphone_nat_policy_get_stun_server(natPolicy);
lInfo() << "ICE: gathering candidates from [" << server << "] using " << (linphone_nat_policy_turn_enabled(natPolicy) ? "TURN" : "STUN");
// Gather local srflx candidates.
ice_session_enable_turn(mIceSession, linphone_nat_policy_turn_enabled(natPolicy));
if (linphone_nat_policy_turn_enabled(natPolicy)) {
ice_session_enable_turn(mIceSession, TRUE);
if (linphone_nat_policy_tls_turn_transport_enabled(natPolicy)) {
ice_session_set_turn_transport(mIceSession, "tls");
} else if (linphone_nat_policy_tcp_turn_transport_enabled(natPolicy)) {
ice_session_set_turn_transport(mIceSession, "tcp");
} else {
ice_session_set_turn_transport(mIceSession, "udp");
}
ice_session_set_turn_root_certificate(mIceSession, linphone_core_get_root_ca(core));
char host[NI_MAXHOST];
int port = 0;
linphone_parse_host_port(linphone_nat_policy_get_stun_server(natPolicy), host, sizeof(host), &port);
ice_session_set_turn_cn(mIceSession, host);
}
ice_session_set_stun_auth_requested_cb(mIceSession, MediaSessionPrivate::stunAuthRequestedCb, &getMediaSessionPrivate());
err = ice_session_gather_candidates(mIceSession, ai->ai_addr, (socklen_t)ai->ai_addrlen) ? 1 : 0;
} else {
......
......@@ -91,7 +91,7 @@ end:
linphone_core_manager_destroy(lc_stun);
}
static void configure_nat_policy(LinphoneCore *lc, bool_t turn_enabled) {
static void configure_nat_policy(LinphoneCore *lc, bool_t turn_enabled, bool_t turn_tcp, bool_t turn_tls) {
const char *username = "liblinphone-tester";
const char *password = "retset-enohpnilbil";
LinphoneAuthInfo *auth_info = linphone_core_create_auth_info(lc, username, NULL, password, NULL, "sip.linphone.org", NULL);
......@@ -102,6 +102,12 @@ static void configure_nat_policy(LinphoneCore *lc, bool_t turn_enabled) {
linphone_nat_policy_set_stun_server(nat_policy, "sip1.linphone.org:3479"); // This is our unofficial turn server.
/* When the turn server is incorporated in flexisip-tester, use turn.example.org . */
linphone_nat_policy_set_stun_server_username(nat_policy, username);
if (turn_tcp) {
linphone_nat_policy_enable_tcp_turn_transport(nat_policy, TRUE);
} else if (turn_tls) {
linphone_nat_policy_set_stun_server(nat_policy, "sip1.linphone.org:5349");
linphone_nat_policy_enable_tls_turn_transport(nat_policy, TRUE);
}
} else {
linphone_nat_policy_enable_stun(nat_policy, TRUE);
/* We intentionnaly do not use stun.example.org. When both liblinphone_tester and flexisip are in the same local network
......@@ -134,7 +140,7 @@ static void check_turn_context_statistics(MSTurnContext *turn_context1, MSTurnCo
}
}
static void ice_turn_call_base(bool_t video_enabled, bool_t forced_relay, bool_t caller_turn_enabled, bool_t callee_turn_enabled, bool_t rtcp_mux_enabled, bool_t ipv6) {
static void ice_turn_call_base(bool_t video_enabled, bool_t forced_relay, bool_t caller_turn_enabled, bool_t callee_turn_enabled, bool_t rtcp_mux_enabled, bool_t ipv6, bool_t turn_tcp, bool_t turn_tls) {
LinphoneCoreManager *marie;
LinphoneCoreManager *pauline;
LinphoneCall *lcall;
......@@ -156,8 +162,8 @@ static void ice_turn_call_base(bool_t video_enabled, bool_t forced_relay, bool_t
linphone_core_enable_ipv6(pauline->lc, FALSE);
}
configure_nat_policy(marie->lc, caller_turn_enabled);
configure_nat_policy(pauline->lc, callee_turn_enabled);
configure_nat_policy(marie->lc, caller_turn_enabled, turn_tcp, turn_tls);
configure_nat_policy(pauline->lc, callee_turn_enabled, turn_tcp, turn_tls);
if (forced_relay == TRUE) {
linphone_core_enable_forced_ice_relay(marie->lc, TRUE);
linphone_core_enable_forced_ice_relay(pauline->lc, TRUE);
......@@ -232,39 +238,55 @@ static void ice_turn_call_base(bool_t video_enabled, bool_t forced_relay, bool_t
}
static void basic_ice_turn_call(void) {
ice_turn_call_base(FALSE, FALSE, TRUE, TRUE, FALSE, FALSE);
ice_turn_call_base(FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE);
}
static void basic_ipv6_ice_turn_call(void) {
if (liblinphone_tester_ipv6_available()) {
ice_turn_call_base(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE);
ice_turn_call_base(FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE);
} else {
ms_warning("Test skipped, no ipv6 available");
}
}
static void basic_ice_turn_call_tcp(void) {
ice_turn_call_base(FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE);
}
static void basic_ice_turn_call_tls(void) {
ice_turn_call_base(FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE);
}
#ifdef VIDEO_ENABLED
static void video_ice_turn_call(void) {
ice_turn_call_base(TRUE, FALSE, TRUE, TRUE, FALSE, FALSE);
ice_turn_call_base(TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE);
}
#endif
static void relayed_ice_turn_call(void) {
ice_turn_call_base(FALSE, TRUE, TRUE, TRUE, FALSE, FALSE);
ice_turn_call_base(FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE);
}
static void relayed_ice_turn_call_with_tcp(void) {
ice_turn_call_base(FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE);
}
static void relayed_ice_turn_call_with_tls(void) {
ice_turn_call_base(FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE);
}
#ifdef VIDEO_ENABLED
static void relayed_video_ice_turn_call(void) {
ice_turn_call_base(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE);
ice_turn_call_base(TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE);
}
#endif
static void relayed_ice_turn_call_with_rtcp_mux(void) {
ice_turn_call_base(FALSE, TRUE, TRUE, TRUE, TRUE, FALSE);
ice_turn_call_base(FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE);
}
static void relayed_ice_turn_to_ice_stun_call(void) {
ice_turn_call_base(FALSE, TRUE, TRUE, FALSE, FALSE, FALSE);
ice_turn_call_base(FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE);
}
......@@ -273,11 +295,15 @@ test_t stun_tests[] = {
TEST_ONE_TAG("STUN encode", linphone_stun_test_encode, "STUN"),
TEST_TWO_TAGS("Basic ICE+TURN call", basic_ice_turn_call, "ICE", "TURN"),
TEST_TWO_TAGS("Basic IPv6 ICE+TURN call", basic_ipv6_ice_turn_call, "ICE", "TURN"),
TEST_TWO_TAGS("Basic ICE+TURN call with TCP", basic_ice_turn_call_tcp, "ICE", "TURN"),
TEST_TWO_TAGS("Basic ICE+TURN call with TLS", basic_ice_turn_call_tls, "ICE", "TURN"),
#ifdef VIDEO_ENABLED
TEST_TWO_TAGS("Video ICE+TURN call", video_ice_turn_call, "ICE", "TURN"),
TEST_TWO_TAGS("Relayed video ICE+TURN call", relayed_video_ice_turn_call, "ICE", "TURN"),
#endif
TEST_TWO_TAGS("Relayed ICE+TURN call", relayed_ice_turn_call, "ICE", "TURN"),
TEST_TWO_TAGS("Relayed ICE+TURN call with TCP", relayed_ice_turn_call_with_tcp, "ICE", "TURN"),
TEST_TWO_TAGS("Relayed ICE+TURN call with TLS", relayed_ice_turn_call_with_tls, "ICE", "TURN"),
TEST_TWO_TAGS("Relayed ICE+TURN call with rtcp-mux", relayed_ice_turn_call_with_rtcp_mux, "ICE", "TURN"),
TEST_TWO_TAGS("Relayed ICE+TURN to ICE+STUN call", relayed_ice_turn_to_ice_stun_call, "ICE", "TURN")
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment