From 7386662164c0339ae4bf0bd307f34f2260a4f27c Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 22 Aug 2011 10:59:33 -0500 Subject: [PATCH] rework session timers to try to have us not be the refresher whenever possible --- src/mod/endpoints/mod_sofia/mod_sofia.c | 52 ++++++++++++++++-------- src/mod/endpoints/mod_sofia/mod_sofia.h | 4 +- src/mod/endpoints/mod_sofia/sofia.c | 1 + src/mod/endpoints/mod_sofia/sofia_glue.c | 17 ++++---- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 2774e7135a..930a4a6f3f 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -741,13 +741,6 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) } } - if ((val = switch_channel_get_variable(channel, SOFIA_SESSION_TIMEOUT))) { - int v_session_timeout = atoi(val); - if (v_session_timeout >= 0) { - session_timeout = v_session_timeout; - } - } - if (sofia_test_flag(tech_pvt, TFLAG_NAT) || (val = switch_channel_get_variable(channel, "sip-force-contact")) || ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) { @@ -756,6 +749,13 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) switch_channel_set_variable(channel, "sip_nat_detected", "true"); } + if ((val = switch_channel_get_variable(channel, SOFIA_SESSION_TIMEOUT))) { + int v_session_timeout = atoi(val); + if (v_session_timeout >= 0) { + session_timeout = v_session_timeout; + } + } + if (!sofia_test_flag(tech_pvt, TFLAG_BYE)) { char *extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX); char *cid = NULL; @@ -780,19 +780,27 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) } } + if ((tech_pvt->session_timeout = session_timeout)) { + tech_pvt->session_refresher = switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? nua_local_refresher : nua_remote_refresher; + } else { + tech_pvt->session_refresher = nua_no_refresher; + } + + + if (sofia_use_soa(tech_pvt)) { nua_respond(tech_pvt->nh, SIP_200_OK, NUTAG_AUTOANSWER(0), TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)), TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)), TAG_IF(cid, SIPTAG_HEADER_STR(cid)), - NUTAG_SESSION_TIMER(session_timeout), - NUTAG_SESSION_REFRESHER(session_timeout ? nua_local_refresher : nua_no_refresher), + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), SOATAG_AUDIO_AUX("cn telephone-event"), NUTAG_INCLUDE_EXTRA_SDP(1), - TAG_IF(is_proxy, SOATAG_RTP_SELECT(1)), + TAG_IF(is_proxy, SOATAG_RTP_SELECT(1)), TAG_IF(!zstr(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_IF(switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote), SIPTAG_HEADER_STR("X-FS-Support: " FREESWITCH_SUPPORT)), TAG_END()); @@ -803,8 +811,8 @@ static switch_status_t sofia_answer_channel(switch_core_session_t *session) TAG_IF(call_info, SIPTAG_CALL_INFO_STR(call_info)), TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)), TAG_IF(cid, SIPTAG_HEADER_STR(cid)), - NUTAG_SESSION_TIMER(session_timeout), - NUTAG_SESSION_REFRESHER(session_timeout ? nua_local_refresher : nua_no_refresher), + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), SIPTAG_CONTACT_STR(tech_pvt->reply_contact), SIPTAG_CALL_INFO_STR(switch_channel_get_variable(tech_pvt->channel, SOFIA_SIP_HEADER_PREFIX "call_info")), SIPTAG_CONTENT_TYPE_STR("application/sdp"), @@ -2001,6 +2009,8 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <%s>", name, number); sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY); nua_update(tech_pvt->nh, + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), TAG_IF(!zstr(tech_pvt->route_uri), NUTAG_PROXY(tech_pvt->route_uri)), TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)), TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END()); @@ -2009,17 +2019,21 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY); nua_update(tech_pvt->nh, + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), TAG_IF(!zstr(tech_pvt->route_uri), NUTAG_PROXY(tech_pvt->route_uri)), TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)), TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END()); } else if ((ua && (switch_stristr("cisco/spa50", ua) || switch_stristr("cisco/spa525", ua)))) { - snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" ", name, number, tech_pvt->profile->sipip); + snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" ", name, number, tech_pvt->profile->sipip); - sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY); - nua_update(tech_pvt->nh, - TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)), - TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END()); - } + sofia_set_flag_locked(tech_pvt, TFLAG_UPDATING_DISPLAY); + nua_update(tech_pvt->nh, + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), + TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)), + TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END()); + } tech_pvt->last_sent_callee_id_name = switch_core_session_strdup(tech_pvt->session, name); tech_pvt->last_sent_callee_id_number = switch_core_session_strdup(tech_pvt->session, number); @@ -2071,6 +2085,8 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } else if (ua && switch_stristr("polycom", ua)) { snprintf(message, sizeof(message), "P-Asserted-Identity: \"%s\" <%s>", msg->string_arg, tech_pvt->caller_profile->destination_number); nua_update(tech_pvt->nh, + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), TAG_IF(!zstr(tech_pvt->route_uri), NUTAG_PROXY(tech_pvt->route_uri)), TAG_IF(!zstr_buf(message), SIPTAG_HEADER_STR(message)), TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)), TAG_END()); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 8c50a9059d..b6df8170f3 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -45,7 +45,7 @@ #define HAVE_APR #include #include -#define SOFIA_NAT_SESSION_TIMEOUT 1800 +#define SOFIA_NAT_SESSION_TIMEOUT 90 #define SOFIA_MAX_ACL 100 #ifdef _MSC_VER #define HAVE_FUNCTION 1 @@ -767,6 +767,8 @@ struct private_object { sofia_cid_type_t cid_type; switch_payload_t payload_space; switch_payload_t ianacodes[SWITCH_MAX_CODECS]; + uint32_t session_timeout; + enum nua_session_refresher session_refresher; }; struct callback_t { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 96df565ee3..5733193743 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -7454,6 +7454,7 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { tech_pvt->user_via = sofia_glue_create_external_via(session, profile, tech_pvt->transport); + nua_set_hparams(tech_pvt->nh, SIPTAG_VIA_STR(tech_pvt->user_via), TAG_END()); } if (sip->sip_contact && sip->sip_contact->m_url) { diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 9876e9b64b..c225b4e6a3 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2366,6 +2366,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) extra_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_HEADER_PREFIX); session_timeout = tech_pvt->profile->session_timeout; + if ((val = switch_channel_get_variable(channel, SOFIA_SESSION_TIMEOUT))) { int v_session_timeout = atoi(val); if (v_session_timeout >= 0) { @@ -2420,10 +2421,12 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA); } - if (sofia_test_flag(tech_pvt, TFLAG_RECOVERED)) { - session_timeout = 0; + if ((tech_pvt->session_timeout = session_timeout)) { + tech_pvt->session_refresher = switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? nua_local_refresher : nua_remote_refresher; + } else { + tech_pvt->session_refresher = nua_no_refresher; } - + if (sofia_use_soa(tech_pvt)) { nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), @@ -2431,8 +2434,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) //TAG_IF(!zstr(tech_pvt->local_sdp_str), NUTAG_AUTOACK(1)), // The code above is breaking things...... grrr WE need this because we handle our own acks and there are 3pcc cases in there too NUTAG_AUTOACK(0), - NUTAG_SESSION_TIMER(session_timeout), - NUTAG_SESSION_REFRESHER(session_timeout ? nua_local_refresher : nua_no_refresher), + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)), TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)), TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)), @@ -2465,8 +2468,8 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_AUTOACK(0), - NUTAG_SESSION_TIMER(session_timeout), - TAG_IF(session_timeout, NUTAG_SESSION_REFRESHER(nua_remote_refresher)), + NUTAG_SESSION_TIMER(tech_pvt->session_timeout), + NUTAG_SESSION_REFRESHER(tech_pvt->session_refresher), TAG_IF(sofia_test_flag(tech_pvt, TFLAG_RECOVERED), NUTAG_INVITE_TIMER(UINT_MAX)), TAG_IF(invite_full_from, SIPTAG_FROM_STR(invite_full_from)), TAG_IF(invite_full_to, SIPTAG_TO_STR(invite_full_to)),