/* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once #include #include #include #include #include #include #include #include #include namespace Swift { class TimerFactory; class ConnectionFactory; class DomainNameResolver; class DomainNameResolveError; class IQRouter; /** * - manages list of working S5B proxies * - creates initial connections (for the candidates you provide) */ class SWIFTEN_API SOCKS5BytestreamProxiesManager { public: SOCKS5BytestreamProxiesManager(ConnectionFactory*, TimerFactory*, DomainNameResolver*, IQRouter*, const JID&); ~SOCKS5BytestreamProxiesManager(); void addS5BProxy(S5BProxyRequest::ref); /* * Returns a list of external S5B proxies. If the optinal return value is not initialized a discovery process has been started and * onDiscoveredProxiesChanged signal will be emitted when it is finished. */ const boost::optional >& getOrDiscoverS5BProxies(); void connectToProxies(const std::string& sessionID); std::shared_ptr getProxySessionAndCloseOthers(const JID& proxyJID, const std::string& sessionID); std::shared_ptr createSOCKS5BytestreamClientSession(HostAddressPort addressPort, const std::string& destAddr); public: boost::signals2::signal onDiscoveredProxiesChanged; private: void handleProxiesFound(std::vector proxyHosts); void handleNameLookupResult(const std::vector&, boost::optional, S5BProxyRequest::ref proxy); void queryForProxies(); void handleProxySessionReady(const std::string& sessionID, const JID& jid, std::shared_ptr session, bool error); void handleProxySessionFinished(const std::string& sessionID, const JID& jid, std::shared_ptr session, boost::optional error); private: ConnectionFactory* connectionFactory_; TimerFactory* timerFactory_; DomainNameResolver* resolver_; IQRouter* iqRouter_; JID serviceRoot_; typedef std::vector > > ProxyJIDClientSessionVector; typedef std::map ProxySessionsMap; ProxySessionsMap proxySessions_; std::shared_ptr proxyFinder_; boost::optional > localS5BProxies_; }; }