From d61fe35f48364cd7964542dc74ea4950b93edf51 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 4 Feb 2016 16:52:59 +0100 Subject: [PATCH] Add API to force the use of relay when using ICE (for tests purpose) + add test that does just that. --- coreapi/misc.c | 6 ++++++ coreapi/private.h | 4 +++- mediastreamer2 | 2 +- tester/call_tester.c | 36 ++++++++++++++++++++++++++---------- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/coreapi/misc.c b/coreapi/misc.c index 996d3d867..d2fd020f7 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -624,6 +624,10 @@ const struct addrinfo *linphone_core_get_stun_server_addrinfo(LinphoneCore *lc){ return lc->net_conf.stun_addrinfo; } +void linphone_core_enable_forced_ice_relay(LinphoneCore *lc, bool_t enable) { + lc->forced_ice_relay = enable; +} + int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call) { char local_addr[64]; @@ -650,6 +654,8 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call) } linphone_core_notify_display_status(lc, _("ICE local candidates gathering in progress...")); + ice_session_enable_forced_relay(call->ice_session, lc->forced_ice_relay); + /* Gather local host candidates. */ if (linphone_core_get_local_ip_for(AF_INET, NULL, local_addr) < 0) { ms_error("Fail to get local ip"); diff --git a/coreapi/private.h b/coreapi/private.h index 92e9999d3..715378e82 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -486,6 +486,7 @@ void linphone_core_resolve_stun_server(LinphoneCore *lc); LINPHONE_PUBLIC const struct addrinfo *linphone_core_get_stun_server_addrinfo(LinphoneCore *lc); void linphone_core_adapt_to_network(LinphoneCore *lc, int ping_time_ms, LinphoneCallParams *params); int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call); +LINPHONE_PUBLIC void linphone_core_enable_forced_ice_relay(LinphoneCore *lc, bool_t enable); void linphone_core_update_ice_state_in_call_stats(LinphoneCall *call); void linphone_call_stats_fill(LinphoneCallStats *stats, MediaStream *ms, OrtpEvent *ev); void linphone_call_stop_ice_for_inactive_streams(LinphoneCall *call, SalMediaDescription *result); @@ -937,7 +938,8 @@ struct _LinphoneCore bool_t vtables_running; bool_t send_call_stats_periodical_updates; - bool_t pad[2]; + bool_t forced_ice_relay; + bool_t pad; char localip[LINPHONE_IPADDR_SIZE]; int device_rotation; int max_calls; diff --git a/mediastreamer2 b/mediastreamer2 index dd5ad1b73..bc6574e8c 160000 --- a/mediastreamer2 +++ b/mediastreamer2 @@ -1 +1 @@ -Subproject commit dd5ad1b738989bc6964f889e17f275eea85e11c0 +Subproject commit bc6574e8c7d5a385d89c2cb807e4fb9a6c20f612 diff --git a/tester/call_tester.c b/tester/call_tester.c index c1a267e36..deb1f0c88 100644 --- a/tester/call_tester.c +++ b/tester/call_tester.c @@ -1110,7 +1110,10 @@ static void check_nb_media_starts(LinphoneCoreManager *caller, LinphoneCoreManag } } -static void _call_with_ice_base(LinphoneCoreManager* pauline,LinphoneCoreManager* marie, bool_t caller_with_ice, bool_t callee_with_ice, bool_t random_ports) { +static void _call_with_ice_base(LinphoneCoreManager* pauline,LinphoneCoreManager* marie, bool_t caller_with_ice, bool_t callee_with_ice, bool_t random_ports, bool_t forced_relay) { + linphone_core_set_user_agent(pauline->lc, "Natted Linphone", NULL); + linphone_core_set_user_agent(marie->lc, "Natted Linphone", NULL); + if (callee_with_ice){ linphone_core_set_firewall_policy(marie->lc,LinphonePolicyUseIce); } @@ -1127,6 +1130,10 @@ static void _call_with_ice_base(LinphoneCoreManager* pauline,LinphoneCoreManager linphone_core_set_text_port(pauline->lc, -1); } + if (forced_relay == TRUE) { + linphone_core_enable_forced_ice_relay(marie->lc, TRUE); + linphone_core_enable_forced_ice_relay(pauline->lc, TRUE); + } if (!BC_ASSERT_TRUE(call(pauline,marie))) return; @@ -1136,24 +1143,28 @@ static void _call_with_ice_base(LinphoneCoreManager* pauline,LinphoneCoreManager BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,2)); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&marie->stat.number_of_LinphoneCallStreamsRunning,2)); - BC_ASSERT_TRUE(check_ice(pauline,marie,LinphoneIceStateHostConnection)); + if (forced_relay == TRUE) { + BC_ASSERT_TRUE(check_ice(pauline, marie, LinphoneIceStateRelayConnection)); + } else { + BC_ASSERT_TRUE(check_ice(pauline,marie,LinphoneIceStateHostConnection)); + } check_nb_media_starts(pauline, marie, 1, 1); } liblinphone_tester_check_rtcp(marie,pauline); /*then close the call*/ end_call(pauline, marie); - } -static void _call_with_ice(bool_t caller_with_ice, bool_t callee_with_ice, bool_t random_ports) { + +static void _call_with_ice(bool_t caller_with_ice, bool_t callee_with_ice, bool_t random_ports, bool_t forced_relay) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); - _call_with_ice_base(pauline,marie,caller_with_ice,callee_with_ice,random_ports); + _call_with_ice_base(pauline,marie,caller_with_ice,callee_with_ice,random_ports,forced_relay); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } static void call_with_ice(void){ - _call_with_ice(TRUE,TRUE,FALSE); + _call_with_ice(TRUE,TRUE,FALSE,FALSE); } /*ICE is not expected to work in this case, however this should not crash*/ @@ -1177,15 +1188,19 @@ static void call_with_ice_no_sdp(void){ } static void call_with_ice_random_ports(void){ - _call_with_ice(TRUE,TRUE,TRUE); + _call_with_ice(TRUE,TRUE,TRUE,FALSE); +} + +static void call_with_ice_forced_relay(void) { + _call_with_ice(TRUE, TRUE, TRUE, TRUE); } static void ice_to_not_ice(void){ - _call_with_ice(TRUE,FALSE,FALSE); + _call_with_ice(TRUE,FALSE,FALSE,FALSE); } static void not_ice_to_ice(void){ - _call_with_ice(FALSE,TRUE,FALSE); + _call_with_ice(FALSE,TRUE,FALSE,FALSE); } static void call_with_custom_headers(void) { @@ -2426,7 +2441,7 @@ static void call_with_ice_video_to_novideo(void) { linphone_core_set_video_policy(pauline->lc,&vpol); vpol.automatically_initiate=FALSE; linphone_core_set_video_policy(marie->lc,&vpol); - _call_with_ice_base(pauline,marie,TRUE,TRUE,TRUE); + _call_with_ice_base(pauline,marie,TRUE,TRUE,TRUE,FALSE); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } @@ -6072,6 +6087,7 @@ test_t call_tests[] = { TEST_ONE_TAG("Call with ICE", call_with_ice, "ICE"), TEST_ONE_TAG("Call with ICE without SDP", call_with_ice_no_sdp, "ICE"), TEST_ONE_TAG("Call with ICE (random ports)", call_with_ice_random_ports, "ICE"), + TEST_ONE_TAG("Call with ICE (forced relay)", call_with_ice_forced_relay, "ICE"), TEST_ONE_TAG("Call from ICE to not ICE", ice_to_not_ice, "ICE"), TEST_ONE_TAG("Call from not ICE to ICE", not_ice_to_ice, "ICE"), TEST_NO_TAG("Call with custom headers", call_with_custom_headers),