diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-12-03 07:53:34 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-12-03 08:09:01 (GMT) |
commit | 9b3edba27b8683f1a87ad66ee05802dd93bbbdfc (patch) | |
tree | e78433ae108123ce370b6abdb1474ec5dcedc75a /Swiften | |
parent | e15c6fd319af1303db47f00e78e4ec42d0605279 (diff) | |
download | swift-contrib-9b3edba27b8683f1a87ad66ee05802dd93bbbdfc.zip swift-contrib-9b3edba27b8683f1a87ad66ee05802dd93bbbdfc.tar.bz2 |
Added debugging output for DNS.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Network/Connector.cpp | 12 | ||||
-rw-r--r-- | Swiften/Network/PlatformDomainNameResolver.cpp | 6 | ||||
-rw-r--r-- | Swiften/Network/PlatformDomainNameServiceQuery.cpp | 3 | ||||
-rw-r--r-- | Swiften/Network/PlatformDomainNameServiceQuery.h | 2 |
4 files changed, 22 insertions, 1 deletions
diff --git a/Swiften/Network/Connector.cpp b/Swiften/Network/Connector.cpp index c9087d7..6e454ad 100644 --- a/Swiften/Network/Connector.cpp +++ b/Swiften/Network/Connector.cpp @@ -13,6 +13,7 @@ Connector::Connector(const String& hostname, DomainNameResolver* resolver, Conne } void Connector::start() { + std::cout << "Connector::start()" << std::endl; assert(!currentConnection); assert(!serviceQuery); queriedAllHosts = false; @@ -29,6 +30,7 @@ void Connector::queryAddress(const String& hostname) { } void Connector::handleServiceQueryResult(const std::vector<DomainNameServiceQuery::Result>& result) { + std::cout << "Received SRV results" << std::endl; serviceQueryResults = std::deque<DomainNameServiceQuery::Result>(result.begin(), result.end()); serviceQuery.reset(); tryNextHostname(); @@ -36,36 +38,44 @@ void Connector::handleServiceQueryResult(const std::vector<DomainNameServiceQuer void Connector::tryNextHostname() { if (queriedAllHosts) { + std::cout << "Connector::tryNextHostName(): Queried all hosts. Error." << std::endl; onConnectFinished(boost::shared_ptr<Connection>()); } else if (serviceQueryResults.empty()) { + std::cout << "Connector::tryNextHostName(): Falling back on A resolution" << std::endl; // Fall back on simple address resolving queriedAllHosts = true; queryAddress(hostname); } else { + std::cout << "Connector::tryNextHostName(): Querying next address" << std::endl; queryAddress(serviceQueryResults.front().hostname); } } void Connector::handleAddressQueryResult(const HostAddress& address, boost::optional<DomainNameResolveError> error) { + std::cout << "Connector::handleAddressQueryResult(): Start" << std::endl; addressQuery.reset(); if (!serviceQueryResults.empty()) { DomainNameServiceQuery::Result serviceQueryResult = serviceQueryResults.front(); serviceQueryResults.pop_front(); if (error) { + std::cout << "Connector::handleAddressQueryResult(): A lookup for SRV host " << serviceQueryResult.hostname << " failed." << std::endl; tryNextHostname(); } else { + std::cout << "Connector::handleAddressQueryResult(): A lookup for SRV host " << serviceQueryResult.hostname << " succeeded: " << address.toString() << std::endl; tryConnect(HostAddressPort(address, serviceQueryResult.port)); } } else if (error) { + std::cout << "Connector::handleAddressQueryResult(): Fallback address query failed. Giving up" << std::endl; // The fallback address query failed assert(queriedAllHosts); onConnectFinished(boost::shared_ptr<Connection>()); } else { + std::cout << "Connector::handleAddressQueryResult(): Fallback address query succeeded: " << address.toString() << std::endl; // The fallback query succeeded tryConnect(HostAddressPort(address, 5222)); } @@ -73,12 +83,14 @@ void Connector::handleAddressQueryResult(const HostAddress& address, boost::opti void Connector::tryConnect(const HostAddressPort& target) { assert(!currentConnection); + std::cout << "Connector::tryConnect() " << target.getAddress().toString() << " " << target.getPort() << std::endl; currentConnection = connectionFactory->createConnection(); currentConnection->onConnectFinished.connect(boost::bind(&Connector::handleConnectionConnectFinished, this, _1)); currentConnection->connect(target); } void Connector::handleConnectionConnectFinished(bool error) { + std::cout << "Connector::handleConnectionConnectFinished() " << error << std::endl; if (error) { currentConnection.reset(); tryNextHostname(); diff --git a/Swiften/Network/PlatformDomainNameResolver.cpp b/Swiften/Network/PlatformDomainNameResolver.cpp index 3636cd6..755b177 100644 --- a/Swiften/Network/PlatformDomainNameResolver.cpp +++ b/Swiften/Network/PlatformDomainNameResolver.cpp @@ -40,22 +40,28 @@ namespace { } void doRun() { + std::cout << "PlatformDomainNameResolver::doRun()" << std::endl; boost::asio::ip::tcp::resolver resolver(ioService); boost::asio::ip::tcp::resolver::query query(hostname.getUTF8String(), "5222"); try { + std::cout << "PlatformDomainNameResolver::doRun(): Resolving" << std::endl; boost::asio::ip::tcp::resolver::iterator endpointIterator = resolver.resolve(query); + std::cout << "PlatformDomainNameResolver::doRun(): Resolved" << std::endl; if (endpointIterator == boost::asio::ip::tcp::resolver::iterator()) { + std::cout << "PlatformDomainNameResolver::doRun(): Error 1" << std::endl; emitError(); } else { boost::asio::ip::address address = (*endpointIterator).endpoint().address(); HostAddress result = (address.is_v4() ? HostAddress(&address.to_v4().to_bytes()[0], 4) : HostAddress(&address.to_v6().to_bytes()[0], 16)); + std::cout << "PlatformDomainNameResolver::doRun(): Success" << std::endl; MainEventLoop::postEvent( boost::bind(boost::ref(onResult), result, boost::optional<DomainNameResolveError>()), shared_from_this()); } } catch (...) { + std::cout << "PlatformDomainNameResolver::doRun(): Error 2" << std::endl; emitError(); } safeToJoin = true; diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.cpp b/Swiften/Network/PlatformDomainNameServiceQuery.cpp index 12afbb7..bc2138d 100644 --- a/Swiften/Network/PlatformDomainNameServiceQuery.cpp +++ b/Swiften/Network/PlatformDomainNameServiceQuery.cpp @@ -82,9 +82,11 @@ void PlatformDomainNameServiceQuery::doRun() { #else + std::cout << "SRV: Querying " << service << std::endl; ByteArray response; response.resize(NS_PACKETSZ); int responseLength = res_query(const_cast<char*>(service.getUTF8Data()), ns_c_in, ns_t_srv, reinterpret_cast<u_char*>(response.getData()), response.getSize()); + std::cout << "res_query done " << (responseLength != -1) << std::endl; if (responseLength == -1) { emitError(); return; @@ -162,6 +164,7 @@ void PlatformDomainNameServiceQuery::doRun() { safeToJoin = true; std::sort(records.begin(), records.end(), SRVRecordPriorityComparator()); + std::cout << "Sending out " << records.size() << " SRV results " << std::endl; MainEventLoop::postEvent(boost::bind(boost::ref(onResult), records)); } diff --git a/Swiften/Network/PlatformDomainNameServiceQuery.h b/Swiften/Network/PlatformDomainNameServiceQuery.h index 1b1c1b5..753e2c6 100644 --- a/Swiften/Network/PlatformDomainNameServiceQuery.h +++ b/Swiften/Network/PlatformDomainNameServiceQuery.h @@ -21,7 +21,7 @@ namespace Swift { private: boost::thread* thread; - bool safeToJoin; String service; + bool safeToJoin; }; } |