diff options
Diffstat (limited to 'Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp')
| -rw-r--r-- | Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp index 26ad8b5..2956ff7 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp | |||
| @@ -11,21 +11,21 @@ | |||
| 11 | */ | 11 | */ |
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | #include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h> | 14 | #include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h> |
| 15 | 15 | ||
| 16 | #include <boost/smart_ptr/make_shared.hpp> | ||
| 17 | #include <boost/bind.hpp> | 16 | #include <boost/bind.hpp> |
| 17 | #include <boost/smart_ptr/make_shared.hpp> | ||
| 18 | 18 | ||
| 19 | #include <Swiften/Base/Log.h> | ||
| 19 | #include <Swiften/Base/foreach.h> | 20 | #include <Swiften/Base/foreach.h> |
| 20 | #include <Swiften/FileTransfer/SOCKS5BytestreamClientSession.h> | 21 | #include <Swiften/FileTransfer/SOCKS5BytestreamClientSession.h> |
| 21 | #include <Swiften/Base/Log.h> | ||
| 22 | #include <Swiften/Network/DomainNameResolver.h> | ||
| 23 | #include <Swiften/Network/ConnectionFactory.h> | 22 | #include <Swiften/Network/ConnectionFactory.h> |
| 24 | #include <Swiften/Network/TimerFactory.h> | ||
| 25 | #include <Swiften/Network/DomainNameAddressQuery.h> | 23 | #include <Swiften/Network/DomainNameAddressQuery.h> |
| 26 | #include <Swiften/Network/DomainNameResolveError.h> | 24 | #include <Swiften/Network/DomainNameResolveError.h> |
| 25 | #include <Swiften/Network/DomainNameResolver.h> | ||
| 26 | #include <Swiften/Network/TimerFactory.h> | ||
| 27 | 27 | ||
| 28 | namespace Swift { | 28 | namespace Swift { |
| 29 | 29 | ||
| 30 | SOCKS5BytestreamProxiesManager::SOCKS5BytestreamProxiesManager(ConnectionFactory *connFactory, TimerFactory *timeFactory, DomainNameResolver* resolver, IQRouter* iqRouter, const JID& serviceRoot) : connectionFactory_(connFactory), timerFactory_(timeFactory), resolver_(resolver), iqRouter_(iqRouter), serviceRoot_(serviceRoot) { | 30 | SOCKS5BytestreamProxiesManager::SOCKS5BytestreamProxiesManager(ConnectionFactory *connFactory, TimerFactory *timeFactory, DomainNameResolver* resolver, IQRouter* iqRouter, const JID& serviceRoot) : connectionFactory_(connFactory), timerFactory_(timeFactory), resolver_(resolver), iqRouter_(iqRouter), serviceRoot_(serviceRoot) { |
| 31 | 31 | ||
| @@ -42,11 +42,10 @@ void SOCKS5BytestreamProxiesManager::addS5BProxy(S5BProxyRequest::ref proxy) { | |||
| 42 | SWIFT_LOG_ASSERT(HostAddress(proxy->getStreamHost().get().host).isValid(), warning) << std::endl; | 42 | SWIFT_LOG_ASSERT(HostAddress(proxy->getStreamHost().get().host).isValid(), warning) << std::endl; |
| 43 | if (!localS5BProxies_) { | 43 | if (!localS5BProxies_) { |
| 44 | localS5BProxies_ = std::vector<S5BProxyRequest::ref>(); | 44 | localS5BProxies_ = std::vector<S5BProxyRequest::ref>(); |
| 45 | } | 45 | } |
| 46 | localS5BProxies_->push_back(proxy); | 46 | localS5BProxies_->push_back(proxy); |
| 47 | onDiscoveredProxiesChanged(); | ||
| 48 | } | 47 | } |
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | const boost::optional<std::vector<S5BProxyRequest::ref> >& SOCKS5BytestreamProxiesManager::getOrDiscoverS5BProxies() { | 50 | const boost::optional<std::vector<S5BProxyRequest::ref> >& SOCKS5BytestreamProxiesManager::getOrDiscoverS5BProxies() { |
| 52 | if (!localS5BProxies_ && !proxyFinder_) { | 51 | if (!localS5BProxies_ && !proxyFinder_) { |
| @@ -104,10 +103,11 @@ boost::shared_ptr<SOCKS5BytestreamClientSession> SOCKS5BytestreamProxiesManager: | |||
| 104 | 103 | ||
| 105 | void SOCKS5BytestreamProxiesManager::handleProxyFound(S5BProxyRequest::ref proxy) { | 104 | void SOCKS5BytestreamProxiesManager::handleProxyFound(S5BProxyRequest::ref proxy) { |
| 106 | if (proxy) { | 105 | if (proxy) { |
| 107 | if (HostAddress(proxy->getStreamHost().get().host).isValid()) { | 106 | if (HostAddress(proxy->getStreamHost().get().host).isValid()) { |
| 108 | addS5BProxy(proxy); | 107 | addS5BProxy(proxy); |
| 108 | onDiscoveredProxiesChanged(); | ||
| 109 | } | 109 | } |
| 110 | else { | 110 | else { |
| 111 | DomainNameAddressQuery::ref resolveRequest = resolver_->createAddressQuery(proxy->getStreamHost().get().host); | 111 | DomainNameAddressQuery::ref resolveRequest = resolver_->createAddressQuery(proxy->getStreamHost().get().host); |
| 112 | resolveRequest->onResult.connect(boost::bind(&SOCKS5BytestreamProxiesManager::handleNameLookupResult, this, _1, _2, proxy)); | 112 | resolveRequest->onResult.connect(boost::bind(&SOCKS5BytestreamProxiesManager::handleNameLookupResult, this, _1, _2, proxy)); |
| 113 | resolveRequest->run(); | 113 | resolveRequest->run(); |
| @@ -118,24 +118,29 @@ void SOCKS5BytestreamProxiesManager::handleProxyFound(S5BProxyRequest::ref proxy | |||
| 118 | } | 118 | } |
| 119 | proxyFinder_->stop(); | 119 | proxyFinder_->stop(); |
| 120 | proxyFinder_.reset(); | 120 | proxyFinder_.reset(); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | void SOCKS5BytestreamProxiesManager::handleNameLookupResult(const std::vector<HostAddress>& address, boost::optional<DomainNameResolveError> error, S5BProxyRequest::ref proxy) { | 123 | void SOCKS5BytestreamProxiesManager::handleNameLookupResult(const std::vector<HostAddress>& addresses, boost::optional<DomainNameResolveError> error, S5BProxyRequest::ref proxy) { |
| 124 | if (error) { | 124 | if (error) { |
| 125 | onDiscoveredProxiesChanged(); | 125 | onDiscoveredProxiesChanged(); |
| 126 | } | 126 | } |
| 127 | else { | 127 | else { |
| 128 | if (address.empty()) { | 128 | if (addresses.empty()) { |
| 129 | SWIFT_LOG(warning) << "S5B proxy hostname does not resolve." << std::endl; | 129 | SWIFT_LOG(warning) << "S5B proxy hostname does not resolve." << std::endl; |
| 130 | onDiscoveredProxiesChanged(); | 130 | onDiscoveredProxiesChanged(); |
| 131 | } | 131 | } |
| 132 | else { | 132 | else { |
| 133 | S5BProxyRequest::StreamHost streamHost = proxy->getStreamHost().get(); | 133 | // generate proxy per returned address |
| 134 | streamHost.host = address[0].toString(); | 134 | foreach (const HostAddress& address, addresses) { |
| 135 | proxy->setStreamHost(streamHost); | 135 | S5BProxyRequest::StreamHost streamHost = proxy->getStreamHost().get(); |
| 136 | addS5BProxy(proxy); | 136 | S5BProxyRequest::ref proxyForAddress = boost::make_shared<S5BProxyRequest>(*proxy); |
| 137 | streamHost.host = address.toString(); | ||
| 138 | proxyForAddress->setStreamHost(streamHost); | ||
| 139 | addS5BProxy(proxyForAddress); | ||
| 140 | } | ||
| 141 | onDiscoveredProxiesChanged(); | ||
| 137 | } | 142 | } |
| 138 | } | 143 | } |
| 139 | } | 144 | } |
| 140 | 145 | ||
| 141 | void SOCKS5BytestreamProxiesManager::queryForProxies() { | 146 | void SOCKS5BytestreamProxiesManager::queryForProxies() { |
Swift