/* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include 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& 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 conn = connectionFactory->createConnection(); boost::shared_ptr session = boost::make_shared(conn, proxy->getStreamHost().get().addressPort, sessionID, timerFactory); clientSessions[proxy->getStreamHost().get().jid] = session; session->start(); } proxySessions[sessionID] = clientSessions; } boost::shared_ptr SOCKS5BytestreamProxiesManager::getProxySessionAndCloseOthers(const JID& proxyJID, const std::string& sessionID) { // checking parameters if (proxySessions.find(sessionID) == proxySessions.end()) { return boost::shared_ptr(); } if (proxySessions[sessionID].find(proxyJID) == proxySessions[sessionID].end()) { return boost::shared_ptr(); } // get active session boost::shared_ptr 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 SOCKS5BytestreamProxiesManager::createSOCKS5BytestreamClientSession(HostAddressPort addressPort, const std::string& destAddr) { SOCKS5BytestreamClientSession::ref connection = boost::make_shared(connectionFactory->createConnection(), addressPort, destAddr, timerFactory); return connection; } }