[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "nat-support" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Jul 18 12:10:13 CDT 2011


branch "nat-support" has been updated
       via  ace9d4b08555bbaef8a36fd7b55782c9122516bd (commit)
      from  7b7c71eca81fad15a1511ead251a09b592f6f6b9 (commit)

Summary of changes:
 src/Helpers/Network.cpp |    7 +-
 src/NAT/Candidates.cpp  |  210 ++++++++++++++++++++++++-----------------------
 2 files changed, 109 insertions(+), 108 deletions(-)


- Log -----------------------------------------------------------------
commit ace9d4b08555bbaef8a36fd7b55782c9122516bd
Author: Brent Eagles <beagles at digium.com>
Date:   Mon Jul 18 14:39:56 2011 -0230

    Review feedback changes.

diff --git a/src/Helpers/Network.cpp b/src/Helpers/Network.cpp
index 53c0b4f..d596c52 100644
--- a/src/Helpers/Network.cpp
+++ b/src/Helpers/Network.cpp
@@ -95,12 +95,11 @@ public:
         //
         // TODO: this can also be made to run asynchronously.
         //
-        tcp::resolver::iterator server = mResolver.resolve(mQuery);
-        tcp::endpoint ep;
         AddressSeq result;
-        while (server != tcp::resolver::iterator())
+        for (tcp::resolver::iterator server = mResolver.resolve(mQuery);
+            server != tcp::resolver::iterator(); ++server)
         {
-            ep = *server++;
+            tcp::endpoint ep = *server;
             result.push_back(AddressPtr(new Address(ep.address().to_string(), ep.port())));
         }
         return result;
diff --git a/src/NAT/Candidates.cpp b/src/NAT/Candidates.cpp
index b76de27..06600e7 100644
--- a/src/NAT/Candidates.cpp
+++ b/src/NAT/Candidates.cpp
@@ -27,132 +27,134 @@ using namespace std;
 std::string toSDP(const AsteriskSCF::System::NAT::V1::CandidatePtr& candidate)
 {
     stringstream os;
-    if (candidate)
+    if (!candidate)
     {
-        os << "candidate:";
-        if (candidate->foundation.empty())
-        {
-            //
-            // Foundation prefix.
-            //
-            switch (candidate->type)
-            {
-            case Host:
-                os << 'H';
-                break;
-
-            case ServerReflexive:
-                os << 'S';
-                break;
-
-            case PeerReflexive:
-                os << 'P';
-                break;
-
-            case Relayed:
-                os << 'R';
-                break;
-
-            default:
-                assert("Unknown candidate type encountered." == 0);
-            }
-            //
-            // Calculate foundation.
-            //
-            string address;
-            unsigned port;
-            if (candidate->mappedAddress.empty())
-            {
-                //
-                // If we do not have a mapped address and the candidate type is not host, then
-                // something is wrong!
-                //
-                assert (candidate->type == Host);
-                address = candidate->baseAddress;
-                port = candidate->basePort;
-            }
-            else
-            {
-                address = candidate->mappedAddress;
-                port = candidate->mappedPort;
-            }
-            AsteriskSCF::Helpers::AddressPtr addr(new AsteriskSCF::Helpers::Address(address, port));
-            //
-            // Now we can be sure we have a numeric ip address.. it would definitely fail in other ways
-            // before we got this far.
-            //
-            string ipaddr = addr->address();
-            if (addr->isIPV6())
-            {
-                boost::asio::ip::address_v6 ip = boost::asio::ip::address_v6::from_string(ipaddr);
-                boost::asio::ip::address_v6::bytes_type ipbytes = ip.to_bytes();
-                size_t seedVal = 0;
-                for (size_t i = 0; i < (sizeof(ipbytes) / sizeof(ipbytes[0])); ++i)
-                {
-                    boost::hash_combine(seedVal, ipbytes[i]);
-                }
-                os << seedVal;
-            }
-            else
-            {
-                boost::asio::ip::address_v4 ip = boost::asio::ip::address_v4::from_string(ipaddr);
-                os << ip.to_ulong();
-            }
-        }
-        else
-        {
-            os << candidate->foundation;
-        }
-        os << ' ';
-        os << candidate->componentId;
-        os << ' ';
-        switch (candidate->transport)
-        {
-        case UDP:
-            os << "UDP";
-            break;
-        case TCP:
-            os << "TCP";
-            break;
-        default:
-            assert("Invalid transport value" == 0);
-        }
+        return "";
+    }
 
+    os << "candidate:";
+    if (candidate->foundation.empty())
+    {
         //
-        // If the candidate is a host candidate then we are almost done.
-        //
-        if (candidate->type == Host)
-        {
-            os << candidate->baseAddress << ' ' << candidate->basePort << " typ host";
-            return os.str();
-        }
-        //
-        // Otherwise, we've got a bit more to do.
+        // Foundation prefix.
         //
-        os << candidate->mappedAddress << ' ' << candidate->mappedPort << "typ ";
         switch (candidate->type)
         {
         case Host:
-            assert("This value isn't valid here" == 0);
+            os << 'H';
             break;
 
         case ServerReflexive:
-            os <<  "srflx ";
+            os << 'S';
             break;
 
         case PeerReflexive:
-            os << "prflx ";
+            os << 'P';
             break;
 
         case Relayed:
-            os << "relay ";
+            os << 'R';
             break;
 
         default:
             assert("Unknown candidate type encountered." == 0);
         }
+        //
+        // Calculate foundation.
+        //
+        string address;
+        unsigned port;
+        if (candidate->mappedAddress.empty())
+        {
+            //
+            // If we do not have a mapped address and the candidate type is not host, then
+            // something is wrong!
+            //
+            assert (candidate->type == Host);
+            address = candidate->baseAddress;
+            port = candidate->basePort;
+        }
+        else
+        {
+            address = candidate->mappedAddress;
+            port = candidate->mappedPort;
+        }
+        AsteriskSCF::Helpers::AddressPtr addr(new AsteriskSCF::Helpers::Address(address, port));
+        //
+        // Now we can be sure we have a numeric ip address.. it would definitely fail in other ways
+        // before we got this far.
+        //
+        string ipaddr = addr->address();
+        if (addr->isIPV6())
+        {
+            boost::asio::ip::address_v6 ip = boost::asio::ip::address_v6::from_string(ipaddr);
+            boost::asio::ip::address_v6::bytes_type ipbytes = ip.to_bytes();
+            size_t seedVal = 0;
+            for (size_t i = 0; i < (sizeof(ipbytes) / sizeof(ipbytes[0])); ++i)
+            {
+                boost::hash_combine(seedVal, ipbytes[i]);
+            }
+            os << seedVal;
+        }
+        else
+        {
+            boost::asio::ip::address_v4 ip = boost::asio::ip::address_v4::from_string(ipaddr);
+            os << ip.to_ulong();
+        }
+    }
+    else
+    {
+        os << candidate->foundation;
+    }
+    os << ' ';
+    os << candidate->componentId;
+    os << ' ';
+    switch (candidate->transport)
+    {
+    case UDP:
+        os << "UDP";
+        break;
+    case TCP:
+        os << "TCP";
+        break;
+    default:
+        assert("Invalid transport value" == 0);
+    }
 
-        os << "raddr " << candidate->baseAddress << " rport " << candidate->basePort;
+    //
+    // If the candidate is a host candidate then we are almost done.
+    //
+    if (candidate->type == Host)
+    {
+        os << candidate->baseAddress << ' ' << candidate->basePort << " typ host";
+        return os.str();
+    }
+    //
+    // Otherwise, we've got a bit more to do.
+    //
+    os << candidate->mappedAddress << ' ' << candidate->mappedPort << "typ ";
+    switch (candidate->type)
+    {
+    case Host:
+        assert("This value isn't valid here" == 0);
+        break;
+
+    case ServerReflexive:
+        os <<  "srflx ";
+        break;
+
+    case PeerReflexive:
+        os << "prflx ";
+        break;
+
+    case Relayed:
+        os << "relay ";
+        break;
+
+    default:
+        assert("Unknown candidate type encountered." == 0);
     }
+
+    os << "raddr " << candidate->baseAddress << " rport " << candidate->basePort;
     return os.str();
 }

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


-- 
asterisk-scf/integration/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list