]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
improve sofia recover in some nat cases
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 8 Sep 2010 20:32:34 +0000 (15:32 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 8 Sep 2010 20:32:34 +0000 (15:32 -0500)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c

index 19a44f43e126935eb9cfb005e29f982b657dd2f0..799cf4f2af2a906c32cc0ed0d00e6c0d5be2b26a 100644 (file)
@@ -85,6 +85,10 @@ static switch_status_t sofia_on_init(switch_core_session_t *session)
                sofia_glue_tech_absorb_sdp(tech_pvt);
        }
 
+       if (sofia_test_flag(tech_pvt, TFLAG_RECOVERING) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING_BRIDGE)) {
+               sofia_set_flag(tech_pvt, TFLAG_RECOVERED);
+       }
+
        if (sofia_test_flag(tech_pvt, TFLAG_OUTBOUND) || sofia_test_flag(tech_pvt, TFLAG_RECOVERING)) {
                const char *var;
 
index aa2149503aaa5335d1de36183259ed5aaa75c3d3..4cdb1a29121dd7f9398a4305f2eb3c9e9c493e2d 100644 (file)
@@ -275,6 +275,7 @@ typedef enum {
        TFLAG_RECOVERING,
        TFLAG_RECOVERING_BRIDGE,
        TFLAG_T38_PASSTHRU,
+       TFLAG_RECOVERED,
        /* No new flags below this line */
        TFLAG_MAX
 } TFLAGS;
index 14d05fd97792b796e03cd3d9665d544feaec2fac..258be0ed59ca5b7f3cd031b34beb99408cfbedb3 100644 (file)
@@ -1225,7 +1225,7 @@ static void sofia_perform_profile_start_failure(sofia_profile_t *profile, char *
 #define sofia_profile_start_failure(p, xp) sofia_perform_profile_start_failure(p, xp, __FILE__, __LINE__)
 
 
-#define SQLLEN 1024 * 64
+#define SQLLEN 1024 * 32
 void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread, void *obj)
 {
        sofia_profile_t *profile = (sofia_profile_t *) obj;
@@ -1236,7 +1236,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
        void *pop;
        int loop_count = 0;
        switch_size_t sql_len = SQLLEN;
-       char *tmp, *sqlbuf = NULL;
+       char *sqlbuf = NULL;
+       char *sql = NULL;
 
        if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) {
                sqlbuf = (char *) malloc(sql_len);
@@ -1253,7 +1254,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
 
        while ((mod_sofia_globals.running == 1 && sofia_test_pflag(profile, PFLAG_RUNNING)) || qsize) {
                if (sofia_test_pflag(profile, PFLAG_SQL_IN_TRANS)) {
-                       if (qsize > 0 && (qsize >= 1024 || ++loop_count >= profile->trans_timeout)) {
+                       if ((qsize > 0 && (qsize >= 1024 || ++loop_count >= profile->trans_timeout)) || sql) {
                                switch_size_t newlen;
                                uint32_t itterations = 0;
                                switch_size_t len = 0;
@@ -1262,28 +1263,24 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
                                
                                //sofia_glue_actually_execute_sql(profile, "begin;\n", NULL);
 
-                               while (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
-                                       char *sql = (char *) pop;
-
+                               while (sql || (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop)) {
+                                       
+                                       if (!sql) {
+                                               sql = (char *) pop;
+                                       }
+                                       
                                        newlen = strlen(sql) + 2;
-
-                                       if (newlen + 10 < SQLLEN) {
-                                               itterations++;
-                                               if (len + newlen + 10 > sql_len) {
-                                                       sql_len = len + 10 + SQLLEN;
-                                                       if (!(tmp = realloc(sqlbuf, sql_len))) {
-                                                               abort();
-                                                               break;
-                                                       }
-                                                       sqlbuf = tmp;
-                                               }
+                                       itterations++;
+                                       
+                                       if (len + newlen + 10 < sql_len) {
                                                sprintf(sqlbuf + len, "%s;\n", sql);
                                                len += newlen;
+                                               switch_safe_free(sql);
+                                       } else {
+                                               break;
                                        }
-
-                                       free(pop);
                                }
-
+                               
                                //printf("TRANS:\n%s\n", sqlbuf);
                                sofia_glue_actually_execute_sql_trans(profile, sqlbuf, NULL);
                                //sofia_glue_actually_execute_sql(profile, "commit;\n", NULL);
@@ -2860,7 +2857,7 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                        goto done;
                                }
 
-                               profile->trans_timeout = 500;
+                               profile->trans_timeout = 100;
 
                                profile->auto_rtp_bugs = RTP_BUG_CISCO_SKIP_MARK_BIT_2833;// | RTP_BUG_SONUS_SEND_INVALID_TIMESTAMP_2833;
 
index 82b933c981861d559d31d936439a908f7156ce29..45364cdac23aa8af8d5c13b336ce131c44597cad 100644 (file)
@@ -2059,6 +2059,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                nua_invite(tech_pvt->nh,
                                   NUTAG_AUTOANSWER(0),
                                   NUTAG_SESSION_TIMER(session_timeout),
+                                  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)),
                                   TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)),
@@ -2087,6 +2088,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                nua_invite(tech_pvt->nh,
                                   NUTAG_AUTOANSWER(0),
                                   NUTAG_SESSION_TIMER(session_timeout),
+                                  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)),
                                   TAG_IF(tech_pvt->redirected, NUTAG_URL(tech_pvt->redirected)),
@@ -4644,7 +4646,7 @@ void sofia_glue_tech_untrack(sofia_profile_t *profile, switch_core_session_t *se
                        }
                }
                
-               sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+               sofia_glue_execute_sql(profile, &sql, SWITCH_TRUE);
                sofia_clear_flag(tech_pvt, TFLAG_TRACKED);
                
                switch_safe_free(sql);