summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.cpp27
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
@@ -13,17 +13,17 @@
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
28namespace Swift { 28namespace Swift {
29 29
@@ -44,7 +44,6 @@ void SOCKS5BytestreamProxiesManager::addS5BProxy(S5BProxyRequest::ref proxy) {
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
@@ -106,6 +105,7 @@ 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);
@@ -120,20 +120,25 @@ void SOCKS5BytestreamProxiesManager::handleProxyFound(S5BProxyRequest::ref proxy
120 proxyFinder_.reset(); 120 proxyFinder_.reset();
121} 121}
122 122
123void SOCKS5BytestreamProxiesManager::handleNameLookupResult(const std::vector<HostAddress>& address, boost::optional<DomainNameResolveError> error, S5BProxyRequest::ref proxy) { 123void 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}