Enable TURN for the ICE session if the NAT policy tells to do so.

This commit is contained in:
Ghislain MARY 2016-04-27 17:02:25 +02:00
parent e224761160
commit ef66a8e392
4 changed files with 25 additions and 22 deletions

View file

@ -554,7 +554,7 @@ LINPHONE_PUBLIC void linphone_proxy_config_set_ref_key(LinphoneProxyConfig *cfg,
* @return LinphoneNatPolicy object in use.
* @see linphone_core_get_nat_policy()
*/
LINPHONE_PUBLIC const LinphoneNatPolicy * linphone_proxy_config_get_nat_policy(const LinphoneProxyConfig *cfg);
LINPHONE_PUBLIC LinphoneNatPolicy * linphone_proxy_config_get_nat_policy(const LinphoneProxyConfig *cfg);
/**
* Set the policy to use to pass through NATs/firewalls when using this proxy config.

View file

@ -1311,7 +1311,7 @@ static void linphone_call_compute_streams_indexes(LinphoneCall *call, const SalM
LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
LinphoneCall *call = belle_sip_object_new(LinphoneCall);
SalMediaDescription *md;
LinphoneFirewallPolicy fpol;
LinphoneNatPolicy *nat_policy = NULL;
int i;
call->dir=LinphoneCallIncoming;
@ -1386,28 +1386,26 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
}
}
fpol=linphone_core_get_firewall_policy(call->core);
/*create the ice session now if ICE is required*/
if (fpol==LinphonePolicyUseIce){
if (call->dest_proxy != NULL) nat_policy = linphone_proxy_config_get_nat_policy(call->dest_proxy);
if (nat_policy == NULL) nat_policy = linphone_core_get_nat_policy(call->core);
if ((nat_policy != NULL) && linphone_nat_policy_ice_enabled(nat_policy)) {
/* Create the ice session now if ICE is required */
if (md){
linphone_call_create_ice_session(call, IR_Controlled);
}else{
fpol=LinphonePolicyNoFirewall;
nat_policy = NULL;
ms_warning("ICE not supported for incoming INVITE without SDP.");
}
}
/*reserve the sockets immediately*/
linphone_call_init_media_streams(call);
switch (fpol) {
case LinphonePolicyUseIce:
if (nat_policy != NULL) {
if (linphone_nat_policy_ice_enabled(nat_policy)) {
call->defer_notify_incoming = linphone_call_prepare_ice(call,TRUE) == 1;
break;
case LinphonePolicyUseStun:
} else if (linphone_nat_policy_stun_enabled(nat_policy)) {
call->ping_time=linphone_core_run_stun_tests(call->core,call);
/* No break to also destroy ice session in this case. */
break;
case LinphonePolicyUseUpnp:
} else if (linphone_nat_policy_upnp_enabled(nat_policy)) {
#ifdef BUILD_UPNP
if(!lc->rtp_conf.disable_upnp) {
call->upnp_session = linphone_upnp_session_new(call);
@ -1419,9 +1417,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
}
}
#endif //BUILD_UPNP
break;
default:
break;
}
}
discover_mtu(lc,linphone_address_get_domain(from));

View file

@ -641,7 +641,12 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call){
IceCheckList *audio_check_list;
IceCheckList *video_check_list;
IceCheckList *text_check_list;
const char *server = linphone_core_get_stun_server(lc);
LinphoneNatPolicy *nat_policy = NULL;
const char *server = NULL;
if (call->dest_proxy != NULL) nat_policy = linphone_proxy_config_get_nat_policy(call->dest_proxy);
if (nat_policy == NULL) nat_policy = linphone_core_get_nat_policy(lc);
if (nat_policy != NULL) server = linphone_nat_policy_get_stun_server(nat_policy);
if (call->ice_session == NULL) return -1;
audio_check_list = ice_session_check_list(call->ice_session, call->main_audio_stream_index);
@ -653,8 +658,8 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call){
ms_warning("Ice gathering is not implemented for ipv6");
return -1;
}
if (server){
ai=linphone_core_get_stun_server_addrinfo(lc);
if ((nat_policy != NULL) && (server != NULL) && (server[0] != '\0')) {
ai=linphone_nat_policy_get_stun_server_addrinfo(nat_policy);
if (ai==NULL){
ms_warning("Fail to resolve STUN server for ICE gathering, continuing without stun.");
}
@ -687,9 +692,11 @@ int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call){
ice_add_local_candidate(text_check_list, "host", local_addr, call->media_ports[call->main_text_stream_index].rtcp_port, 2, NULL);
call->stats[LINPHONE_CALL_STATS_TEXT].ice_state = LinphoneIceStateInProgress;
}
if (ai){
ms_message("ICE: gathering candidate from [%s]",server);
if ((ai != NULL) && (nat_policy != NULL)
&& (linphone_nat_policy_stun_enabled(nat_policy) || linphone_nat_policy_turn_enabled(nat_policy))) {
ms_message("ICE: gathering candidate from [%s] using %s", server, linphone_nat_policy_turn_enabled(nat_policy) ? "TURN" : "STUN");
/* Gather local srflx candidates. */
ice_session_enable_turn(call->ice_session, linphone_nat_policy_turn_enabled(nat_policy));
ice_session_gather_candidates(call->ice_session, ai->ai_addr, (socklen_t)ai->ai_addrlen);
return 1;
} else {

View file

@ -1689,7 +1689,7 @@ void linphone_proxy_config_set_ref_key(LinphoneProxyConfig *cfg, const char *ref
if (refkey) cfg->refkey=ms_strdup(refkey);
}
const LinphoneNatPolicy * linphone_proxy_config_get_nat_policy(const LinphoneProxyConfig *cfg) {
LinphoneNatPolicy * linphone_proxy_config_get_nat_policy(const LinphoneProxyConfig *cfg) {
return cfg->nat_policy;
}