[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "modular-transport-refactor" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Jun 29 06:39:20 CDT 2011


branch "modular-transport-refactor" has been updated
       via  6b1dcf996494c7f590078c51913e9e498280e481 (commit)
      from  6d3ef9e35e467d718a8f616eb2a85fb4b2958af0 (commit)

Summary of changes:
 src/PJSipManager.cpp  |   13 +++++++++++++
 src/PJSipManager.h    |    1 +
 src/STUNModule.cpp    |    5 +++--
 src/STUNTransport.cpp |   34 ++++++++++++++++++----------------
 4 files changed, 35 insertions(+), 18 deletions(-)


- Log -----------------------------------------------------------------
commit 6b1dcf996494c7f590078c51913e9e498280e481
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Jun 29 09:04:16 2011 -0230

    - Modified the STUN transport initialization to use the socket in the
      library callback instead of the stun sock in an effort to work around
      some asserts happening in the pjproject library. The assert's themselves
      seem to be firing incorrectly, so may be the result of a race condition.
    - Re-added addition of adding the stun module to the PJSipManager that
      was lost in merging.
    - Fix STUN module pool initialization.

diff --git a/src/PJSipManager.cpp b/src/PJSipManager.cpp
index e9dde6b..859b35b 100644
--- a/src/PJSipManager.cpp
+++ b/src/PJSipManager.cpp
@@ -64,6 +64,8 @@ PJSipManagerPtr AsteriskSCF::SipSessionManager::PJSipManager::create(const Ice::
 {
     PJSipManagerPtr result(new PJSipManager);
     result->initializeDefaultTransports(properties);
+    STUNModulePtr stunModule = STUNModule::create(result, properties, logger);
+    result->addModule("STUN", stunModule);
     return result;
 }
 
@@ -152,6 +154,17 @@ TransportPtr PJSipManager::getTransport(const string& id)
     return TransportPtr();
 }
 
+void PJSipManager::addModule(const string& moduleName, const SipModulePtr& module)
+{
+    boost::unique_lock<boost::shared_mutex> lock(mLock);
+    SipModuleMap::const_iterator i = mModules.find(moduleName);
+    if (i != mModules.end())
+    {
+        mModules.erase(i);
+    }
+    mModules.insert(make_pair(moduleName, module));
+}
+
 SipModulePtr PJSipManager::getModule(const string& moduleName)
 {
     boost::shared_lock<boost::shared_mutex> lock(mLock);
diff --git a/src/PJSipManager.h b/src/PJSipManager.h
index 9544bb2..7975fad 100644
--- a/src/PJSipManager.h
+++ b/src/PJSipManager.h
@@ -104,6 +104,7 @@ public:
     void addTransport(const std::string& id, const TransportPtr& transport);
     TransportPtr getTransport(const std::string& id);
 
+    void addModule(const std::string& id, const SipModulePtr& module);
     SipModulePtr getModule(const std::string& moduleName);
 
     void handleEvents();
diff --git a/src/STUNModule.cpp b/src/STUNModule.cpp
index 687de6f..3678e5e 100644
--- a/src/STUNModule.cpp
+++ b/src/STUNModule.cpp
@@ -137,7 +137,8 @@ boost::shared_ptr<STUNModule> STUNModule::create(const PJSipManagerPtr& sipManag
  **/
 STUNModule::STUNModule(const boost::shared_ptr<pj_stun_config>& config) :
     mConfig(config),
-    mTimeout(new pj_time_val(DEFAULT_PROCESSING_TIMEOUT))
+    mTimeout(new pj_time_val(DEFAULT_PROCESSING_TIMEOUT)),
+    mPool(pj_pool_create(mConfig->pf, "STUNMEMPL", 16 * 1024, 1024, 0))
 {
 }
 
@@ -149,7 +150,7 @@ void STUNModule::destroyImpl()
     boost::unique_lock<boost::shared_mutex> lock(mLock);
     pj_ioqueue_destroy(mConfig->ioqueue);
     pj_timer_heap_destroy(mConfig->timer_heap);
-
+    pj_pool_release(mPool);
     mConfig.reset();
 }
 }
diff --git a/src/STUNTransport.cpp b/src/STUNTransport.cpp
index a560a40..b0942fd 100644
--- a/src/STUNTransport.cpp
+++ b/src/STUNTransport.cpp
@@ -74,7 +74,7 @@ private:
         // TODO: We should allow this to change over time, so we need to have some thread
         // safety around initTransport.
         //
-        if (operation == PJ_STUN_SOCK_BINDING_OP)
+        if (operation == PJ_STUN_SOCK_BINDING_OP || operation == PJ_STUN_SOCK_MAPPED_ADDR_CHANGE)
         {
             //
             // NOTE: If you watch the PJNATH tracing, you will see binding requests occurring periodically, but 
@@ -84,7 +84,12 @@ private:
             STUNTransport* t = reinterpret_cast<STUNTransport*>(pj_stun_sock_get_user_data(stunSock));
             if (t)
             {
-                t->updateBinding();
+                pj_stun_sock_info socketInfo;
+                pj_status_t result = pj_stun_sock_get_info(stunSock, &socketInfo);
+                if (success(result))
+                {
+                    t->updateBinding(socketInfo);
+                }
             }
         }
         return PJ_TRUE;
@@ -149,12 +154,17 @@ public:
         pj_str_t pjT;
         if (address)
         {
-            pj_sockaddr_init(pj_AF_UNSPEC(), &udpAddr, pj_cstr(&pjT, address->address().c_str()), 
+            int af = pj_AF_INET();
+            if (address->isIPV6())
+            {
+                af = pj_AF_INET6();
+            }
+            pj_sockaddr_init(af, &udpAddr, pj_cstr(&pjT, address->address().c_str()), 
                 static_cast<pj_uint16_t>(address->port()));
         }
         else
         {
-            pj_sockaddr_init(pj_AF_UNSPEC(), &udpAddr, pj_cstr(&pjT, "0.0.0.0"), 5060);
+            pj_sockaddr_init(pj_AF_INET(), &udpAddr, pj_cstr(&pjT, "0.0.0.0"), 5060);
         }
 
         pj_status_t result = pj_stun_sock_create(mModule->getConfig(), 0, udpAddr.addr.sa_family, &stunSockCB, 
@@ -182,7 +192,7 @@ public:
         }
         if (pj_sockaddr_has_addr(&socketInfo.mapped_addr))
         {
-            updateBinding();
+            updateBinding(socketInfo);
         }
     };
 
@@ -267,10 +277,10 @@ private:
         return current;
     }
 
-    void updateBinding()
+    void updateBinding(const pj_stun_sock_info& socketInfo)
     {
         boost::shared_ptr<pjsip_transport> newTransport(new pjsip_transport);
-        initTransport(newTransport);
+        initTransport(newTransport, socketInfo);
         pj_status_t result = pjsip_transport_register(newTransport->tpmgr, newTransport.get());
         if (fail(result))
         {
@@ -288,7 +298,7 @@ private:
         }
     }
 
-    void initTransport(const boost::shared_ptr<pjsip_transport>& transport)
+    void initTransport(const boost::shared_ptr<pjsip_transport>& transport, const pj_stun_sock_info& socketInfo)
     {
         assert(transport != 0);
         memset(transport.get(), 0, sizeof *transport);
@@ -320,14 +330,6 @@ private:
         transport->remote_name.host = pj_str((char*)"0.0.0.0");
         transport->remote_name.port = 0;
         
-        pj_stun_sock_info socketInfo;
-        result = pj_stun_sock_get_info(mSocket, &socketInfo);
-        if (fail(result))
-        {
-            logger(Error) << "Unable to get socket info for STUN transport";
-            return;
-        }
-
         char buf[PJ_INET6_ADDRSTRLEN];
         pj_strdup2(mModule->getPool(), &transport->local_name.host,
                 pj_sockaddr_print(&socketInfo.mapped_addr, buf, sizeof buf, 0));

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/sip.git



More information about the asterisk-scf-commits mailing list