summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp')
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
index 33a5283..f749735 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServerManager.cpp
@@ -1,50 +1,49 @@
/*
* Copyright (c) 2012-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
/*
* Copyright (c) 2011 Tobias Markmann
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/FileTransfer/SOCKS5BytestreamServerManager.h>
#include <memory>
#include <boost/bind.hpp>
#include <Swiften/Base/Log.h>
-#include <Swiften/Base/foreach.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamServer.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamServerPortForwardingUser.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamServerResourceUser.h>
#include <Swiften/Network/ConnectionServer.h>
#include <Swiften/Network/ConnectionServerFactory.h>
#include <Swiften/Network/NATTraversalForwardPortRequest.h>
#include <Swiften/Network/NATTraversalGetPublicIPRequest.h>
#include <Swiften/Network/NATTraversalRemovePortForwardingRequest.h>
#include <Swiften/Network/NATTraverser.h>
#include <Swiften/Network/NetworkEnvironment.h>
using namespace Swift;
static const int LISTEN_PORTS_BEGIN = 10000;
static const int LISTEN_PORTS_END = 11000;
SOCKS5BytestreamServerManager::SOCKS5BytestreamServerManager(
SOCKS5BytestreamRegistry* bytestreamRegistry,
ConnectionServerFactory* connectionServerFactory,
NetworkEnvironment* networkEnvironment,
NATTraverser* natTraverser) :
bytestreamRegistry(bytestreamRegistry),
connectionServerFactory(connectionServerFactory),
networkEnvironment(networkEnvironment),
natTraverser(natTraverser),
state(Start),
server(nullptr),
attemptedPortMapping_(false) {
}
@@ -61,91 +60,91 @@ SOCKS5BytestreamServerManager::~SOCKS5BytestreamServerManager() {
}
std::shared_ptr<SOCKS5BytestreamServerResourceUser> SOCKS5BytestreamServerManager::aquireResourceUser() {
std::shared_ptr<SOCKS5BytestreamServerResourceUser> resourceUser;
if (s5bServerResourceUser_.expired()) {
resourceUser = std::make_shared<SOCKS5BytestreamServerResourceUser>(this);
s5bServerResourceUser_ = resourceUser;
}
else {
resourceUser = s5bServerResourceUser_.lock();
}
return resourceUser;
}
std::shared_ptr<SOCKS5BytestreamServerPortForwardingUser> SOCKS5BytestreamServerManager::aquirePortForwardingUser() {
std::shared_ptr<SOCKS5BytestreamServerPortForwardingUser> portForwardingUser;
if (s5bServerPortForwardingUser_.expired()) {
portForwardingUser = std::make_shared<SOCKS5BytestreamServerPortForwardingUser>(this);
s5bServerPortForwardingUser_ = portForwardingUser;
}
else {
portForwardingUser = s5bServerPortForwardingUser_.lock();
}
return portForwardingUser;
}
std::vector<HostAddressPort> SOCKS5BytestreamServerManager::getHostAddressPorts() const {
std::vector<HostAddressPort> result;
if (connectionServer) {
std::vector<NetworkInterface> networkInterfaces = networkEnvironment->getNetworkInterfaces();
- foreach (const NetworkInterface& networkInterface, networkInterfaces) {
- foreach (const HostAddress& address, networkInterface.getAddresses()) {
+ for (const auto& networkInterface : networkInterfaces) {
+ for (const auto& address : networkInterface.getAddresses()) {
result.push_back(HostAddressPort(address, connectionServerPort));
}
}
}
return result;
}
std::vector<HostAddressPort> SOCKS5BytestreamServerManager::getAssistedHostAddressPorts() const {
std::vector<HostAddressPort> result;
if (publicAddress && portMapping) {
result.push_back(HostAddressPort(*publicAddress, portMapping->getPublicPort()));
}
return result;
}
bool SOCKS5BytestreamServerManager::isInitialized() const {
return state == Initialized;
}
void SOCKS5BytestreamServerManager::initialize() {
if (state == Start) {
state = Initializing;
// Find a port to listen on
assert(!connectionServer);
int port;
for (port = LISTEN_PORTS_BEGIN; port < LISTEN_PORTS_END; ++port) {
SWIFT_LOG(debug) << "Trying to start server on port " << port << std::endl;
- connectionServer = connectionServerFactory->createConnectionServer(HostAddress("::"), port);
+ connectionServer = connectionServerFactory->createConnectionServer(HostAddress::fromString("::").get(), port);
boost::optional<ConnectionServer::Error> error = connectionServer->tryStart();
if (!error) {
break;
}
else if (*error != ConnectionServer::Conflict) {
SWIFT_LOG(debug) << "Error starting server" << std::endl;
onInitialized(false);
return;
}
connectionServer.reset();
}
if (!connectionServer) {
SWIFT_LOG(debug) << "Unable to find an open port" << std::endl;
onInitialized(false);
return;
}
SWIFT_LOG(debug) << "Server started succesfully" << std::endl;
connectionServerPort = port;
// Start bytestream server. Should actually happen before the connectionserver is started
// but that doesn't really matter here.
assert(!server);
server = new SOCKS5BytestreamServer(connectionServer, bytestreamRegistry);
server->start();
checkInitializeFinished();
}
}
bool SOCKS5BytestreamServerManager::isPortForwardingReady() const {
return attemptedPortMapping_ && !getPublicIPRequest && !forwardPortRequest;