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
@@ -10,23 +10,23 @@
* See the COPYING file for more information.
*/
#include <Swiften/FileTransfer/SOCKS5BytestreamProxiesManager.h>
-#include <boost/smart_ptr/make_shared.hpp>
#include <boost/bind.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <Swiften/Base/Log.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamClientSession.h>
-#include <Swiften/Base/Log.h>
-#include <Swiften/Network/DomainNameResolver.h>
#include <Swiften/Network/ConnectionFactory.h>
-#include <Swiften/Network/TimerFactory.h>
#include <Swiften/Network/DomainNameAddressQuery.h>
#include <Swiften/Network/DomainNameResolveError.h>
+#include <Swiften/Network/DomainNameResolver.h>
+#include <Swiften/Network/TimerFactory.h>
namespace Swift {
SOCKS5BytestreamProxiesManager::SOCKS5BytestreamProxiesManager(ConnectionFactory *connFactory, TimerFactory *timeFactory, DomainNameResolver* resolver, IQRouter* iqRouter, const JID& serviceRoot) : connectionFactory_(connFactory), timerFactory_(timeFactory), resolver_(resolver), iqRouter_(iqRouter), serviceRoot_(serviceRoot) {
}
@@ -41,13 +41,12 @@ void SOCKS5BytestreamProxiesManager::addS5BProxy(S5BProxyRequest::ref proxy) {
if (proxy) {
SWIFT_LOG_ASSERT(HostAddress(proxy->getStreamHost().get().host).isValid(), warning) << std::endl;
if (!localS5BProxies_) {
localS5BProxies_ = std::vector<S5BProxyRequest::ref>();
}
localS5BProxies_->push_back(proxy);
- onDiscoveredProxiesChanged();
}
}
const boost::optional<std::vector<S5BProxyRequest::ref> >& SOCKS5BytestreamProxiesManager::getOrDiscoverS5BProxies() {
if (!localS5BProxies_ && !proxyFinder_) {
queryForProxies();
@@ -103,12 +102,13 @@ boost::shared_ptr<SOCKS5BytestreamClientSession> SOCKS5BytestreamProxiesManager:
}
void SOCKS5BytestreamProxiesManager::handleProxyFound(S5BProxyRequest::ref proxy) {
if (proxy) {
if (HostAddress(proxy->getStreamHost().get().host).isValid()) {
addS5BProxy(proxy);
+ onDiscoveredProxiesChanged();
}
else {
DomainNameAddressQuery::ref resolveRequest = resolver_->createAddressQuery(proxy->getStreamHost().get().host);
resolveRequest->onResult.connect(boost::bind(&SOCKS5BytestreamProxiesManager::handleNameLookupResult, this, _1, _2, proxy));
resolveRequest->run();
}
@@ -117,26 +117,31 @@ void SOCKS5BytestreamProxiesManager::handleProxyFound(S5BProxyRequest::ref proxy
onDiscoveredProxiesChanged();
}
proxyFinder_->stop();
proxyFinder_.reset();
}
-void SOCKS5BytestreamProxiesManager::handleNameLookupResult(const std::vector<HostAddress>& address, boost::optional<DomainNameResolveError> error, S5BProxyRequest::ref proxy) {
+void SOCKS5BytestreamProxiesManager::handleNameLookupResult(const std::vector<HostAddress>& addresses, boost::optional<DomainNameResolveError> error, S5BProxyRequest::ref proxy) {
if (error) {
onDiscoveredProxiesChanged();
}
else {
- if (address.empty()) {
+ if (addresses.empty()) {
SWIFT_LOG(warning) << "S5B proxy hostname does not resolve." << std::endl;
onDiscoveredProxiesChanged();
}
else {
- S5BProxyRequest::StreamHost streamHost = proxy->getStreamHost().get();
- streamHost.host = address[0].toString();
- proxy->setStreamHost(streamHost);
- addS5BProxy(proxy);
+ // generate proxy per returned address
+ foreach (const HostAddress& address, addresses) {
+ S5BProxyRequest::StreamHost streamHost = proxy->getStreamHost().get();
+ S5BProxyRequest::ref proxyForAddress = boost::make_shared<S5BProxyRequest>(*proxy);
+ streamHost.host = address.toString();
+ proxyForAddress->setStreamHost(streamHost);
+ addS5BProxy(proxyForAddress);
+ }
+ onDiscoveredProxiesChanged();
}
}
}
void SOCKS5BytestreamProxiesManager::queryForProxies() {
proxyFinder_ = boost::make_shared<SOCKS5BytestreamProxyFinder>(serviceRoot_, iqRouter_);