]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix long delay in nat detection
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 2 Jun 2009 22:46:38 +0000 (22:46 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 2 Jun 2009 22:46:38 +0000 (22:46 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13557 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_nat.c

index d8add7f18b663437e169ff9678cfce2a4d4081d4..68b897e6e09b0947e6b828e76605fbe9f7ef5a71 100644 (file)
@@ -101,11 +101,11 @@ static int init_upnp (void)
 
 static int init_pmp(void)
 {
-       int r = 0;
+       int r = 0, i = 0, max = 5;
        natpmpresp_t response;
        char *pubaddr = NULL;
        fd_set fds;
-       struct timeval timeout;
+
 
        initnatpmp(&nat_globals.natpmp);
        r = sendpublicaddressrequest(&nat_globals.natpmp);
@@ -115,12 +115,16 @@ static int init_pmp(void)
        }
 
        do {
+               struct timeval timeout = { 1, 0};
+               i++;
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for PMP %d/%d\n", i, max);
+
                FD_ZERO(&fds);
                FD_SET(nat_globals.natpmp.s, &fds);
                getnatpmprequesttimeout(&nat_globals.natpmp, &timeout);
                select(FD_SETSIZE, &fds, NULL, NULL, &timeout);
                r = readnatpmpresponseorretry(&nat_globals.natpmp, &response);
-       } while(r == NATPMP_TRYAGAIN);
+       } while(r == NATPMP_TRYAGAIN && i < max);
 
        if (r < 0) {
                goto end;
@@ -147,13 +151,12 @@ SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool)
        switch_find_local_ip(nat_globals.pvt_addr, sizeof(nat_globals.pvt_addr), NULL, AF_INET);
 
 
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Detecting NAT\n");
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Scanning for NAT\n");
 
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for PMP\n");
        init_pmp();
 
-       if (nat_globals.nat_type) {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPNP\n");
+       if (!nat_globals.nat_type) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Checking for UPnP\n");
                init_upnp();
        }
        
@@ -163,7 +166,7 @@ SWITCH_DECLARE(void) switch_nat_init(switch_memory_pool_t *pool)
                switch_core_set_variable("nat_type", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "NAT detected type: %s\n", nat_globals.nat_type == SWITCH_NAT_TYPE_PMP ? "pmp" : "upnp");
        } else {
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No PMP or uPNP NAT device detected!\n");
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "No PMP or UPnP NAT detected!\n");
        }
 }