diff options
author | Remko Tronçon <git@el-tramo.be> | 2012-12-25 14:39:48 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2013-05-11 10:22:56 (GMT) |
commit | 927d62cc54c8a5087dba6b61afa9ad30dc528a23 (patch) | |
tree | e67dc911bd30c0519d31a542d8e085bbb209879d /Swiften/Network | |
parent | 17b188343e7208b875af7af30d94f0bf948f6b93 (diff) | |
download | swift-contrib-927d62cc54c8a5087dba6b61afa9ad30dc528a23.zip swift-contrib-927d62cc54c8a5087dba6b61afa9ad30dc528a23.tar.bz2 |
File Transfer refactoring.
Allocate S5B server lazily.
Forward forts lazily.
Various state machine fixes.
Temporarily disabling S5B proxy support.
Change-Id: I3145e85a99b15a7e457306bbfbe9c0eb570191e4
Diffstat (limited to 'Swiften/Network')
-rw-r--r-- | Swiften/Network/HostAddress.cpp | 7 | ||||
-rw-r--r-- | Swiften/Network/HostAddress.h | 1 | ||||
-rw-r--r-- | Swiften/Network/MiniUPnPInterface.cpp | 11 | ||||
-rw-r--r-- | Swiften/Network/NATPortMapping.h | 3 | ||||
-rw-r--r-- | Swiften/Network/UnixNetworkEnvironment.cpp | 2 | ||||
-rw-r--r-- | Swiften/Network/WindowsNetworkEnvironment.cpp | 2 |
6 files changed, 22 insertions, 4 deletions
diff --git a/Swiften/Network/HostAddress.cpp b/Swiften/Network/HostAddress.cpp index 9443b53..ff5c1c4 100644 --- a/Swiften/Network/HostAddress.cpp +++ b/Swiften/Network/HostAddress.cpp @@ -15,6 +15,9 @@ #include <Swiften/Base/foreach.h> #include <string> +static boost::asio::ip::address localhost4 = boost::asio::ip::address(boost::asio::ip::address_v4::loopback()); +static boost::asio::ip::address localhost6 = boost::asio::ip::address(boost::asio::ip::address_v6::loopback()); + namespace Swift { HostAddress::HostAddress() { @@ -61,4 +64,8 @@ boost::asio::ip::address HostAddress::getRawAddress() const { return address_; } +bool HostAddress::isLocalhost() const { + return address_ == localhost4 || address_ == localhost6; +} + } diff --git a/Swiften/Network/HostAddress.h b/Swiften/Network/HostAddress.h index b8e3462..c62239b 100644 --- a/Swiften/Network/HostAddress.h +++ b/Swiften/Network/HostAddress.h @@ -26,6 +26,7 @@ namespace Swift { } bool isValid() const; + bool isLocalhost() const; private: boost::asio::ip::address address_; diff --git a/Swiften/Network/MiniUPnPInterface.cpp b/Swiften/Network/MiniUPnPInterface.cpp index c729371..bfa989f 100644 --- a/Swiften/Network/MiniUPnPInterface.cpp +++ b/Swiften/Network/MiniUPnPInterface.cpp @@ -72,7 +72,16 @@ boost::optional<NATPortMapping> MiniUPnPInterface::addPortForward(int actualLoca std::string localPort = boost::lexical_cast<std::string>(mapping.getLocalPort()); std::string leaseSeconds = boost::lexical_cast<std::string>(mapping.getLeaseInSeconds()); - int ret = UPNP_AddPortMapping(p->urls.controlURL, p->data.first.servicetype, publicPort.c_str(), localPort.c_str(), p->localAddress.c_str(), 0, mapping.getPublicPort() == NATPortMapping::TCP ? "TCP" : "UDP", 0, leaseSeconds.c_str()); + int ret = UPNP_AddPortMapping( + p->urls.controlURL, + p->data.first.servicetype, + publicPort.c_str(), + localPort.c_str(), + p->localAddress.c_str(), + 0, + mapping.getProtocol() == NATPortMapping::TCP ? "TCP" : "UDP", + 0, + leaseSeconds.c_str()); if (ret == UPNPCOMMAND_SUCCESS) { return mapping; } diff --git a/Swiften/Network/NATPortMapping.h b/Swiften/Network/NATPortMapping.h index a7982d6..0f6bd95 100644 --- a/Swiften/Network/NATPortMapping.h +++ b/Swiften/Network/NATPortMapping.h @@ -16,7 +16,8 @@ namespace Swift { UDP }; - NATPortMapping(int localPort, int publicPort, Protocol protocol = TCP, int leaseInSeconds = 60 * 60 * 24) : publicPort(publicPort), localPort(localPort), protocol(protocol), leaseInSeconds(leaseInSeconds) { + NATPortMapping(int localPort, int publicPort, Protocol protocol = TCP, int leaseInSeconds = 60 * 60 * 24) : + publicPort(publicPort), localPort(localPort), protocol(protocol), leaseInSeconds(leaseInSeconds) { } diff --git a/Swiften/Network/UnixNetworkEnvironment.cpp b/Swiften/Network/UnixNetworkEnvironment.cpp index 52c5cbe..5740a65 100644 --- a/Swiften/Network/UnixNetworkEnvironment.cpp +++ b/Swiften/Network/UnixNetworkEnvironment.cpp @@ -42,7 +42,7 @@ std::vector<NetworkInterface> UnixNetworkEnvironment::getNetworkInterfaces() con sockaddr_in6* sa = reinterpret_cast<sockaddr_in6*>(a->ifa_addr); address = HostAddress(reinterpret_cast<const unsigned char*>(&(sa->sin6_addr)), 16); } - if (address) { + if (address && !address->isLocalhost()) { std::map<std::string, NetworkInterface>::iterator i = interfaces.insert(std::make_pair(name, NetworkInterface(name, a->ifa_flags & IFF_LOOPBACK))).first; i->second.addAddress(*address); } diff --git a/Swiften/Network/WindowsNetworkEnvironment.cpp b/Swiften/Network/WindowsNetworkEnvironment.cpp index 20f559d..e2d1966 100644 --- a/Swiften/Network/WindowsNetworkEnvironment.cpp +++ b/Swiften/Network/WindowsNetworkEnvironment.cpp @@ -50,7 +50,7 @@ std::vector<NetworkInterface> WindowsNetworkEnvironment::getNetworkInterfaces() sockaddr_in6* sa = reinterpret_cast<sockaddr_in6*>(address->Address.lpSockaddr); hostAddress = HostAddress(reinterpret_cast<const unsigned char*>(&(sa->sin6_addr)), 16); } - if (hostAddress) { + if (hostAddress && !hostAddress->isLocalhost()) { std::map<std::string, NetworkInterface>::iterator i = interfaces.insert(std::make_pair(name, NetworkInterface(name, false))).first; i->second.addAddress(*hostAddress); } |