summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordknn <yoann.blein@free.fr>2012-08-29 11:16:57 (GMT)
committerdknn <yoann.blein@free.fr>2012-09-22 09:34:49 (GMT)
commit949278e9418e4090c2f3c68ed313cf4853b25ef1 (patch)
treef66f927a7325af16cb1e8444b40d06a649d09fb5 /Swiften/Network
parent56b5b129c2fbea3828faaf0cdf882534c2433eff (diff)
downloadswift-contrib-949278e9418e4090c2f3c68ed313cf4853b25ef1.zip
swift-contrib-949278e9418e4090c2f3c68ed313cf4853b25ef1.tar.bz2
Add UDP support in nat traversal
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/MiniUPnPInterface.cpp4
-rw-r--r--Swiften/Network/MiniUPnPInterface.h6
-rw-r--r--Swiften/Network/NATPMPInterface.cpp6
-rw-r--r--Swiften/Network/NATPMPInterface.h2
-rw-r--r--Swiften/Network/NATTraversalInterface.h2
-rw-r--r--Swiften/Network/NATTraverser.h5
-rw-r--r--Swiften/Network/NullNATTraversalInterface.h2
-rw-r--r--Swiften/Network/NullNATTraverser.cpp4
-rw-r--r--Swiften/Network/NullNATTraverser.h4
-rw-r--r--Swiften/Network/PlatformNATTraversalWorker.cpp13
-rw-r--r--Swiften/Network/PlatformNATTraversalWorker.h4
11 files changed, 27 insertions, 25 deletions
diff --git a/Swiften/Network/MiniUPnPInterface.cpp b/Swiften/Network/MiniUPnPInterface.cpp
index c729371..e15ba3a 100644
--- a/Swiften/Network/MiniUPnPInterface.cpp
+++ b/Swiften/Network/MiniUPnPInterface.cpp
@@ -61,12 +61,12 @@ boost::optional<HostAddress> MiniUPnPInterface::getPublicIP() {
}
}
-boost::optional<NATPortMapping> MiniUPnPInterface::addPortForward(int actualLocalPort, int actualPublicPort) {
+boost::optional<NATPortMapping> MiniUPnPInterface::addPortForward(int actualLocalPort, int actualPublicPort, NATPortMapping::Protocol protocol) {
if (!p->isValid) {
return boost::optional<NATPortMapping>();
}
- NATPortMapping mapping(actualLocalPort, actualPublicPort, NATPortMapping::TCP);
+ NATPortMapping mapping(actualLocalPort, actualPublicPort, protocol);
std::string publicPort = boost::lexical_cast<std::string>(mapping.getPublicPort());
std::string localPort = boost::lexical_cast<std::string>(mapping.getLocalPort());
diff --git a/Swiften/Network/MiniUPnPInterface.h b/Swiften/Network/MiniUPnPInterface.h
index 61d12ca..d917f7c 100644
--- a/Swiften/Network/MiniUPnPInterface.h
+++ b/Swiften/Network/MiniUPnPInterface.h
@@ -21,9 +21,9 @@ namespace Swift {
virtual bool isAvailable();
- boost::optional<HostAddress> getPublicIP();
- boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort);
- bool removePortForward(const NATPortMapping&);
+ virtual boost::optional<HostAddress> getPublicIP();
+ virtual boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort, NATPortMapping::Protocol protocol);
+ virtual bool removePortForward(const NATPortMapping&);
private:
struct Private;
diff --git a/Swiften/Network/NATPMPInterface.cpp b/Swiften/Network/NATPMPInterface.cpp
index 220e3e9..2634eaf 100644
--- a/Swiften/Network/NATPMPInterface.cpp
+++ b/Swiften/Network/NATPMPInterface.cpp
@@ -61,8 +61,8 @@ boost::optional<HostAddress> NATPMPInterface::getPublicIP() {
}
}
-boost::optional<NATPortMapping> NATPMPInterface::addPortForward(int localPort, int publicPort) {
- NATPortMapping mapping(localPort, publicPort, NATPortMapping::TCP);
+boost::optional<NATPortMapping> NATPMPInterface::addPortForward(int localPort, int publicPort, NATPortMapping::Protocol protocol) {
+ NATPortMapping mapping(localPort, publicPort, protocol);
if (sendnewportmappingrequest(&p->natpmp, mapping.getProtocol() == NATPortMapping::TCP ? NATPMP_PROTOCOL_TCP : NATPMP_PROTOCOL_UDP, mapping.getLeaseInSeconds(), mapping.getPublicPort(), mapping.getLocalPort()) < 0) {
SWIFT_LOG(debug) << "Failed to send NAT-PMP port forwarding request!" << std::endl;
return boost::optional<NATPortMapping>();
@@ -81,7 +81,7 @@ boost::optional<NATPortMapping> NATPMPInterface::addPortForward(int localPort, i
} while(r == NATPMP_TRYAGAIN);
if (r == 0) {
- NATPortMapping result(response.pnu.newportmapping.privateport, response.pnu.newportmapping.mappedpublicport, NATPortMapping::TCP, response.pnu.newportmapping.lifetime);
+ NATPortMapping result(response.pnu.newportmapping.privateport, response.pnu.newportmapping.mappedpublicport, protocol, response.pnu.newportmapping.lifetime);
return result;
}
else {
diff --git a/Swiften/Network/NATPMPInterface.h b/Swiften/Network/NATPMPInterface.h
index e079a59..f3bf432 100644
--- a/Swiften/Network/NATPMPInterface.h
+++ b/Swiften/Network/NATPMPInterface.h
@@ -21,7 +21,7 @@ namespace Swift {
virtual bool isAvailable();
virtual boost::optional<HostAddress> getPublicIP();
- virtual boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort);
+ virtual boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort, NATPortMapping::Protocol protocol);
virtual bool removePortForward(const NATPortMapping&);
private:
diff --git a/Swiften/Network/NATTraversalInterface.h b/Swiften/Network/NATTraversalInterface.h
index c84deba..6c09e7b 100644
--- a/Swiften/Network/NATTraversalInterface.h
+++ b/Swiften/Network/NATTraversalInterface.h
@@ -18,7 +18,7 @@ namespace Swift {
virtual bool isAvailable() = 0;
virtual boost::optional<HostAddress> getPublicIP() = 0;
- virtual boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort) = 0;
+ virtual boost::optional<NATPortMapping> addPortForward(int localPort, int publicPort, NATPortMapping::Protocol protocol) = 0;
virtual bool removePortForward(const NATPortMapping&) = 0;
};
}
diff --git a/Swiften/Network/NATTraverser.h b/Swiften/Network/NATTraverser.h
index e48ce26..5273b35 100644
--- a/Swiften/Network/NATTraverser.h
+++ b/Swiften/Network/NATTraverser.h
@@ -7,6 +7,7 @@
#pragma once
#include <boost/shared_ptr.hpp>
+#include <Swiften/Network/NATPortMapping.h>
namespace Swift {
class NATTraversalGetPublicIPRequest;
@@ -18,7 +19,7 @@ namespace Swift {
virtual ~NATTraverser();
virtual boost::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest() = 0;
- virtual boost::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort) = 0;
- virtual boost::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort) = 0;
+ virtual boost::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort, NATPortMapping::Protocol protocol) = 0;
+ virtual boost::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort, NATPortMapping::Protocol protocol) = 0;
};
}
diff --git a/Swiften/Network/NullNATTraversalInterface.h b/Swiften/Network/NullNATTraversalInterface.h
index 72a4a08..ec70615 100644
--- a/Swiften/Network/NullNATTraversalInterface.h
+++ b/Swiften/Network/NullNATTraversalInterface.h
@@ -21,7 +21,7 @@ namespace Swift {
return boost::optional<HostAddress>();
}
- virtual boost::optional<NATPortMapping> addPortForward(int, int) {
+ virtual boost::optional<NATPortMapping> addPortForward(int, int, NATPortMapping::Protocol) {
return boost::optional<NATPortMapping>();
}
diff --git a/Swiften/Network/NullNATTraverser.cpp b/Swiften/Network/NullNATTraverser.cpp
index 8cb35cd..2cd6658 100644
--- a/Swiften/Network/NullNATTraverser.cpp
+++ b/Swiften/Network/NullNATTraverser.cpp
@@ -62,11 +62,11 @@ boost::shared_ptr<NATTraversalGetPublicIPRequest> NullNATTraverser::createGetPub
return boost::make_shared<NullNATTraversalGetPublicIPRequest>(eventLoop);
}
-boost::shared_ptr<NATTraversalForwardPortRequest> NullNATTraverser::createForwardPortRequest(int, int) {
+boost::shared_ptr<NATTraversalForwardPortRequest> NullNATTraverser::createForwardPortRequest(int, int, NATPortMapping::Protocol) {
return boost::make_shared<NullNATTraversalForwardPortRequest>(eventLoop);
}
-boost::shared_ptr<NATTraversalRemovePortForwardingRequest> NullNATTraverser::createRemovePortForwardingRequest(int, int) {
+boost::shared_ptr<NATTraversalRemovePortForwardingRequest> NullNATTraverser::createRemovePortForwardingRequest(int, int, NATPortMapping::Protocol) {
return boost::make_shared<NullNATTraversalRemovePortForwardingRequest>(eventLoop);
}
diff --git a/Swiften/Network/NullNATTraverser.h b/Swiften/Network/NullNATTraverser.h
index 5775a9b..8505112 100644
--- a/Swiften/Network/NullNATTraverser.h
+++ b/Swiften/Network/NullNATTraverser.h
@@ -16,8 +16,8 @@ namespace Swift {
NullNATTraverser(EventLoop* eventLoop);
boost::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest();
- boost::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort);
- boost::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort);
+ boost::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort, NATPortMapping::Protocol);
+ boost::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort, NATPortMapping::Protocol);
private:
EventLoop* eventLoop;
diff --git a/Swiften/Network/PlatformNATTraversalWorker.cpp b/Swiften/Network/PlatformNATTraversalWorker.cpp
index c962b3b..bce0bbc 100644
--- a/Swiften/Network/PlatformNATTraversalWorker.cpp
+++ b/Swiften/Network/PlatformNATTraversalWorker.cpp
@@ -60,7 +60,7 @@ class PlatformNATTraversalGetPublicIPRequest : public NATTraversalGetPublicIPReq
class PlatformNATTraversalForwardPortRequest : public NATTraversalForwardPortRequest, public PlatformNATTraversalRequest {
public:
- PlatformNATTraversalForwardPortRequest(PlatformNATTraversalWorker* worker, unsigned int localIP, unsigned int publicIP) : PlatformNATTraversalRequest(worker), localIP(localIP), publicIP(publicIP) {
+ PlatformNATTraversalForwardPortRequest(PlatformNATTraversalWorker* worker, unsigned int localIP, unsigned int publicIP, NATPortMapping::Protocol protocol) : PlatformNATTraversalRequest(worker), localIP(localIP), publicIP(publicIP), protocol(protocol) {
}
virtual void run() {
@@ -68,12 +68,13 @@ class PlatformNATTraversalForwardPortRequest : public NATTraversalForwardPortReq
}
virtual void runBlocking() {
- onResult(getNATTraversalInterface()->addPortForward(localIP, publicIP));
+ onResult(getNATTraversalInterface()->addPortForward(localIP, publicIP, protocol));
}
private:
unsigned int localIP;
unsigned int publicIP;
+ NATPortMapping::Protocol protocol;
};
class PlatformNATTraversalRemovePortForwardingRequest : public NATTraversalRemovePortForwardingRequest, public PlatformNATTraversalRequest {
@@ -133,12 +134,12 @@ boost::shared_ptr<NATTraversalGetPublicIPRequest> PlatformNATTraversalWorker::cr
return boost::make_shared<PlatformNATTraversalGetPublicIPRequest>(this);
}
-boost::shared_ptr<NATTraversalForwardPortRequest> PlatformNATTraversalWorker::createForwardPortRequest(int localPort, int publicPort) {
- return boost::make_shared<PlatformNATTraversalForwardPortRequest>(this, localPort, publicPort);
+boost::shared_ptr<NATTraversalForwardPortRequest> PlatformNATTraversalWorker::createForwardPortRequest(int localPort, int publicPort, NATPortMapping::Protocol protocol) {
+ return boost::make_shared<PlatformNATTraversalForwardPortRequest>(this, localPort, publicPort, protocol);
}
-boost::shared_ptr<NATTraversalRemovePortForwardingRequest> PlatformNATTraversalWorker::createRemovePortForwardingRequest(int localPort, int publicPort) {
- NATPortMapping mapping(localPort, publicPort, NATPortMapping::TCP); // FIXME
+boost::shared_ptr<NATTraversalRemovePortForwardingRequest> PlatformNATTraversalWorker::createRemovePortForwardingRequest(int localPort, int publicPort, NATPortMapping::Protocol protocol) {
+ NATPortMapping mapping(localPort, publicPort, protocol); // FIXME
return boost::make_shared<PlatformNATTraversalRemovePortForwardingRequest>(this, mapping);
}
diff --git a/Swiften/Network/PlatformNATTraversalWorker.h b/Swiften/Network/PlatformNATTraversalWorker.h
index 8060e31..5c4a387 100644
--- a/Swiften/Network/PlatformNATTraversalWorker.h
+++ b/Swiften/Network/PlatformNATTraversalWorker.h
@@ -37,8 +37,8 @@ namespace Swift {
~PlatformNATTraversalWorker();
boost::shared_ptr<NATTraversalGetPublicIPRequest> createGetPublicIPRequest();
- boost::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort);
- boost::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort);
+ boost::shared_ptr<NATTraversalForwardPortRequest> createForwardPortRequest(int localPort, int publicPort, NATPortMapping::Protocol protocol);
+ boost::shared_ptr<NATTraversalRemovePortForwardingRequest> createRemovePortForwardingRequest(int localPort, int publicPort, NATPortMapping::Protocol protocol);
private:
NATTraversalInterface* getNATTraversalInterface() const;