summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-12-25 14:39:48 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-05-11 10:22:56 (GMT)
commit927d62cc54c8a5087dba6b61afa9ad30dc528a23 (patch)
treee67dc911bd30c0519d31a542d8e085bbb209879d /Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp
parent17b188343e7208b875af7af30d94f0bf948f6b93 (diff)
downloadswift-927d62cc54c8a5087dba6b61afa9ad30dc528a23.zip
swift-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/FileTransfer/SOCKS5BytestreamProxiesManager.cpp')
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp
new file mode 100644
index 0000000..0b94763
--- /dev/null
+++ b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2011 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h>
+
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <Swiften/Base/foreach.h>
+#include <Swiften/FileTransfer/SOCKS5BytestreamClientSession.h>
+#include <Swiften/Base/Log.h>
+
+namespace Swift {
+
+SOCKS5BytestreamProxiesManager::SOCKS5BytestreamProxiesManager(ConnectionFactory *connFactory, TimerFactory *timeFactory) : connectionFactory(connFactory), timerFactory(timeFactory) {
+
+}
+
+void SOCKS5BytestreamProxiesManager::addS5BProxy(S5BProxyRequest::ref proxy) {
+ localS5BProxies.push_back(proxy);
+}
+
+const std::vector<S5BProxyRequest::ref>& SOCKS5BytestreamProxiesManager::getS5BProxies() const {
+ return localS5BProxies;
+}
+
+void SOCKS5BytestreamProxiesManager::connectToProxies(const std::string& sessionID) {
+ SWIFT_LOG(debug) << "session ID: " << sessionID << std::endl;
+ ProxyJIDClientSessionMap clientSessions;
+
+ foreach(S5BProxyRequest::ref proxy, localS5BProxies) {
+ boost::shared_ptr<Connection> conn = connectionFactory->createConnection();
+
+ boost::shared_ptr<SOCKS5BytestreamClientSession> session = boost::make_shared<SOCKS5BytestreamClientSession>(conn, proxy->getStreamHost().get().addressPort, sessionID, timerFactory);
+ clientSessions[proxy->getStreamHost().get().jid] = session;
+ session->start();
+ }
+
+ proxySessions[sessionID] = clientSessions;
+}
+
+boost::shared_ptr<SOCKS5BytestreamClientSession> SOCKS5BytestreamProxiesManager::getProxySessionAndCloseOthers(const JID& proxyJID, const std::string& sessionID) {
+ // checking parameters
+ if (proxySessions.find(sessionID) == proxySessions.end()) {
+ return boost::shared_ptr<SOCKS5BytestreamClientSession>();
+ }
+ if (proxySessions[sessionID].find(proxyJID) == proxySessions[sessionID].end()) {
+ return boost::shared_ptr<SOCKS5BytestreamClientSession>();
+ }
+
+ // get active session
+ boost::shared_ptr<SOCKS5BytestreamClientSession> activeSession = proxySessions[sessionID][proxyJID];
+ proxySessions[sessionID].erase(proxyJID);
+
+ // close other sessions
+ foreach(const ProxyJIDClientSessionMap::value_type& myPair, proxySessions[sessionID]) {
+ myPair.second->stop();
+ }
+
+ proxySessions.erase(sessionID);
+
+ return activeSession;
+}
+
+boost::shared_ptr<SOCKS5BytestreamClientSession> SOCKS5BytestreamProxiesManager::createSOCKS5BytestreamClientSession(HostAddressPort addressPort, const std::string& destAddr) {
+ SOCKS5BytestreamClientSession::ref connection = boost::make_shared<SOCKS5BytestreamClientSession>(connectionFactory->createConnection(), addressPort, destAddr, timerFactory);
+ return connection;
+}
+
+}