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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Jun 21 09:55:05 CDT 2011


branch "nat-traversal" has been updated
       via  bb74153265ff2f3a19b0cc6a23458cadb758722f (commit)
       via  8a326029d644f89920c24f9d89c798c63a1b0376 (commit)
      from  a12a3505915e4663768beee0617fedaa886ed77c (commit)

Summary of changes:
 .../AsteriskSCF/NAT/Candidates.h                   |   23 ++--
 src/CMakeLists.txt                                 |    3 +
 src/Helpers/Network.cpp                            |    2 +-
 src/NAT/Candidates.cpp                             |  158 ++++++++++++++++++++
 4 files changed, 173 insertions(+), 13 deletions(-)
 copy test/PropertyHelper/PropertyHelperTest.h => include/AsteriskSCF/NAT/Candidates.h (61%)
 create mode 100644 src/NAT/Candidates.cpp


- Log -----------------------------------------------------------------
commit bb74153265ff2f3a19b0cc6a23458cadb758722f
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Jun 21 12:24:46 2011 -0230

    Changed a field in the slice so had to update the helper functions

diff --git a/include/AsteriskSCF/NAT/Candidates.h b/include/AsteriskSCF/NAT/Candidates.h
index 4e40c23..00f33d6 100644
--- a/include/AsteriskSCF/NAT/Candidates.h
+++ b/include/AsteriskSCF/NAT/Candidates.h
@@ -24,6 +24,11 @@ namespace AsteriskSCF
 namespace NAT
 {
 
+/**
+ * 
+ * toSDP() creates an SDP compliant attribute line for the provided candidate.
+ *
+ **/
 std::string ASTERISK_SCF_ICEBOX_EXPORT toSDP(const AsteriskSCF::System::NAT::V1::CandidatePtr& candidate);
 
 } /* End of namespace NAT */
diff --git a/src/NAT/Candidates.cpp b/src/NAT/Candidates.cpp
index 941bd1f..28cf170 100644
--- a/src/NAT/Candidates.cpp
+++ b/src/NAT/Candidates.cpp
@@ -30,76 +30,83 @@ std::string toSDP(const AsteriskSCF::System::NAT::V1::CandidatePtr& candidate)
     if (candidate)
     {
         os << "candidate:";
-        //
-        // Foundation prefix.
-        //
-        switch (candidate->type)
+        if (candidate->foundation.empty())
         {
-        case Host:
-            os << 'H';
-            break;
+            //
+            // Foundation prefix.
+            //
+            switch (candidate->type)
+            {
+            case Host:
+                os << 'H';
+                break;
 
-        case ServerReflexive:
-            os << 'S';
-            break;
+            case ServerReflexive:
+                os << 'S';
+                break;
 
-        case PeerReflexive:
-            os << 'P';
-            break;
+            case PeerReflexive:
+                os << 'P';
+                break;
 
-        case Relayed:
-            os << 'R';
-            break;
+            case Relayed:
+                os << 'R';
+                break;
 
-        default:
-            assert("Unknown candidate type encountered." == 0);
-        }
-        //
-        // Calculate foundation.
-        //
-        string address;
-        unsigned port;
-        if (candidate->mappedAddress.empty())
-        {
+            default:
+                assert("Unknown candidate type encountered." == 0);
+            }
             //
-            // If we do not have a mapped address and the candidate type is not host, then
-            // something is wrong!
+            // Calculate foundation.
             //
-            assert (candidate->type == Host);
-            address = candidate->localAddress;
-            port = candidate->localPort;
-        }
-        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)
+            string address;
+            unsigned port;
+            if (candidate->mappedAddress.empty())
             {
-                boost::hash_combine(seedVal, ipbytes[i]);
+                //
+                // 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();
             }
-            os << seedVal;
         }
         else
         {
-            boost::asio::ip::address_v4 ip = boost::asio::ip::address_v4::from_string(ipaddr);
-            os << ip.to_ulong();
+            os << candidate->foundation;
         }
         os << ' ';
         os << candidate->componentId;
         os << ' ';
-        switch(candidate->transport)
+        switch (candidate->transport)
         {
         case UDP:
             os << "UDP";
@@ -116,14 +123,14 @@ std::string toSDP(const AsteriskSCF::System::NAT::V1::CandidatePtr& candidate)
         //
         if (candidate->type == Host)
         {
-            os << candidate->localAddress << ' ' << candidate->localPort << " typ 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)
+        switch (candidate->type)
         {
         case Host:
             assert("This value isn't valid here" == 0);
@@ -145,7 +152,7 @@ std::string toSDP(const AsteriskSCF::System::NAT::V1::CandidatePtr& candidate)
             assert("Unknown candidate type encountered." == 0);
         }
 
-        os << "raddr " << candidate->localAddress << " rport " << candidate->localPort;
+        os << "raddr " << candidate->baseAddress << " rport " << candidate->basePort;
     }
     return os.str();
 }

commit 8a326029d644f89920c24f9d89c798c63a1b0376
Author: Brent Eagles <beagles at digium.com>
Date:   Mon Jun 20 22:14:12 2011 -0230

    Initial add of some utility code for passing handling connection candidates.

diff --git a/include/AsteriskSCF/NAT/Candidates.h b/include/AsteriskSCF/NAT/Candidates.h
new file mode 100644
index 0000000..4e40c23
--- /dev/null
+++ b/include/AsteriskSCF/NAT/Candidates.h
@@ -0,0 +1,30 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#pragma once
+
+#include <string>
+#include <AsteriskSCF/System/NAT/NATTraversalIf.h>
+
+namespace AsteriskSCF
+{
+namespace NAT
+{
+
+std::string ASTERISK_SCF_ICEBOX_EXPORT toSDP(const AsteriskSCF::System::NAT::V1::CandidatePtr& candidate);
+
+} /* End of namespace NAT */
+} /* End of namespace AsteriskSCF */
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1d46dad..ab1d47f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -27,6 +27,9 @@ asterisk_scf_component_add_file(ice-util-cpp CollocatedIceStorm/CollocatedIceSto
 asterisk_scf_component_add_file(ice-util-cpp ../include/AsteriskSCF/Helpers/Network.h)
 asterisk_scf_component_add_file(ice-util-cpp Helpers/Network.cpp)
 
+asterisk_scf_component_add_file(ice-util-cpp ../include/AsteriskSCF/NAT/Candidates.h)
+asterisk_scf_component_add_file(ice-util-cpp NAT/Candidates.cpp)
+
 #
 # Note, strictly speaking this isn't for component development, but as it is part of this
 # library it sort of belongs here.
diff --git a/src/Helpers/Network.cpp b/src/Helpers/Network.cpp
index c152708..53c0b4f 100644
--- a/src/Helpers/Network.cpp
+++ b/src/Helpers/Network.cpp
@@ -32,7 +32,7 @@ Address::Address(const string& host, unsigned p) :
     try
     {
         boost::asio::ip::address a(address::from_string(mHostname));
-        mAddress = host;
+        mAddress = mHostname;
         mIsIPV6 = a.is_v6();
     }
     catch (const exception&)
diff --git a/src/NAT/Candidates.cpp b/src/NAT/Candidates.cpp
new file mode 100644
index 0000000..941bd1f
--- /dev/null
+++ b/src/NAT/Candidates.cpp
@@ -0,0 +1,151 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <AsteriskSCF/NAT/Candidates.h>
+#include <AsteriskSCF/Helpers/Network.h>
+#include <sstream>
+#include <boost/asio/ip/address.hpp>
+#include <boost/functional/hash.hpp>
+
+using namespace AsteriskSCF::System::NAT::V1;
+using namespace AsteriskSCF::NAT;
+using namespace std;
+
+std::string toSDP(const AsteriskSCF::System::NAT::V1::CandidatePtr& candidate)
+{
+    stringstream os;
+    if (candidate)
+    {
+        os << "candidate:";
+        //
+        // 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->localAddress;
+            port = candidate->localPort;
+        }
+        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();
+        }
+        os << ' ';
+        os << candidate->componentId;
+        os << ' ';
+        switch(candidate->transport)
+        {
+        case UDP:
+            os << "UDP";
+            break;
+        case TCP:
+            os << "TCP";
+            break;
+        default:
+            assert("Invalid transport value" == 0);
+        }
+
+        //
+        // If the candidate is a host candidate then we are almost done.
+        //
+        if (candidate->type == Host)
+        {
+            os << candidate->localAddress << ' ' << candidate->localPort << " 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->localAddress << " rport " << candidate->localPort;
+    }
+    return os.str();
+}

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


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



More information about the asterisk-scf-commits mailing list