diff --git a/Jamfile b/Jamfile
index 25b683dbd..45666ac59 100755
--- a/Jamfile
+++ b/Jamfile
@@ -48,6 +48,7 @@ project torrent
SOURCES =
allocate_resources.cpp
alert.cpp
+ async_gethostbyname.cpp
entry.cpp
escape_string.cpp
file.cpp
diff --git a/docs/index.html b/docs/index.html
index 33ed9ce82..f12760055 100755
--- a/docs/index.html
+++ b/docs/index.html
@@ -55,7 +55,7 @@ example client.
There's a mailing list, general libtorrent discussion.
-
You can usually find me as hydri in #btports @ irc.freenode.net.
+
You can usually find me as hydri in #libtorrent on irc.freenode.net.
diff --git a/docs/index.rst b/docs/index.rst
index 8fb363771..5c030c5b4 100755
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -54,7 +54,7 @@ There's a `mailing list`__, general libtorrent discussion.
__ http://lists.sourceforge.net/lists/listinfo/libtorrent-discuss
-You can usually find me as hydri in ``#btports @ irc.freenode.net``.
+You can usually find me as hydri in ``#libtorrent`` on ``irc.freenode.net``.
Acknowledgements
diff --git a/include/libtorrent/http_tracker_connection.hpp b/include/libtorrent/http_tracker_connection.hpp
index 68740c6c1..6a3293a37 100755
--- a/include/libtorrent/http_tracker_connection.hpp
+++ b/include/libtorrent/http_tracker_connection.hpp
@@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_id.hpp"
#include "libtorrent/peer.hpp"
#include "libtorrent/tracker_manager.hpp"
+#include "libtorrent/async_gethostbyname.hpp"
namespace libtorrent
{
@@ -96,6 +97,7 @@ namespace libtorrent
int m_content_length;
std::string m_location;
+ dns_lookup m_name_lookup;
boost::shared_ptr
m_socket;
int m_recv_pos;
std::vector m_buffer;
diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp
index 7e41652b7..8bc19c3ab 100755
--- a/include/libtorrent/tracker_manager.hpp
+++ b/include/libtorrent/tracker_manager.hpp
@@ -62,7 +62,7 @@ namespace libtorrent
struct request_callback;
class tracker_manager;
- address parse_url(std::string const& url);
+// address parse_url(std::string const& url);
// encodes a string using the base64 scheme
std::string base64encode(const std::string& s);
diff --git a/include/libtorrent/udp_tracker_connection.hpp b/include/libtorrent/udp_tracker_connection.hpp
index a11fd310b..9e1c93670 100755
--- a/include/libtorrent/udp_tracker_connection.hpp
+++ b/include/libtorrent/udp_tracker_connection.hpp
@@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/peer_id.hpp"
#include "libtorrent/peer.hpp"
#include "libtorrent/tracker_manager.hpp"
+#include "libtorrent/async_gethostbyname.hpp"
namespace libtorrent
{
@@ -93,6 +94,7 @@ namespace libtorrent
bool parse_announce_response(const char* buf, int ret);
bool parse_scrape_response(const char* buf, int ret);
+ dns_lookup m_name_lookup;
boost::shared_ptr m_socket;
// used for time outs
diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp
index a79b37166..0b239a282 100755
--- a/src/http_tracker_connection.cpp
+++ b/src/http_tracker_connection.cpp
@@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/bencode.hpp"
#include "libtorrent/torrent.hpp"
#include "libtorrent/io.hpp"
+#include "libtorrent/async_gethostbyname.hpp"
using namespace libtorrent;
@@ -113,13 +114,6 @@ namespace libtorrent
connect_to_host = &hostname;
}
- // TODO: this is a problem. DNS-lookup is blocking!
- // (may block up to 5 seconds)
- address a(connect_to_host->c_str(), port);
- if (has_requester()) requester().m_tracker_address = a;
- boost::shared_ptr s(new socket(socket::tcp, false));
- s->connect(a);
-
m_send_buffer.assign("GET ");
if (using_proxy)
{
@@ -224,7 +218,9 @@ namespace libtorrent
requester().debug_log("info_hash: " + info_hash_str.str() + "\n");
}
#endif
- m_socket = s;
+
+ m_name_lookup = dns_lookup(connect_to_host->c_str(), port);
+ m_socket.reset(new socket(socket::tcp, false));
}
// returns true if this connection is finished and should be removed from
@@ -235,7 +231,31 @@ namespace libtorrent
try
{
#endif
-
+
+ if (m_name_lookup.running())
+ {
+ if (!m_name_lookup.finished()) return false;
+
+ if (m_name_lookup.failed())
+ {
+ if (has_requester()) requester().tracker_request_error(
+ m_req, -1, "hostname not found: " + m_name_lookup.error());
+ return true;
+ }
+ address a(m_name_lookup.ip());
+ if (has_requester()) requester().m_tracker_address = a;
+
+#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
+ if (has_requester()) requester().debug_log("name lookup successful");
+#endif
+
+ m_socket->connect(a);
+
+ // clear the lookup entry so it will not be
+ // marked as running anymore
+ m_name_lookup = dns_lookup();
+ }
+
using namespace boost::posix_time;
time_duration d = second_clock::universal_time() - m_request_time;
diff --git a/src/identify_client.cpp b/src/identify_client.cpp
index c41b9b494..98637df4a 100755
--- a/src/identify_client.cpp
+++ b/src/identify_client.cpp
@@ -167,6 +167,7 @@ namespace
, map_entry("M", "Mainline")
, map_entry("MP", "MooPolice")
, map_entry("MT", "Moonlight Torrent")
+ , map_entry("O", "Osprey Permaseed")
, map_entry("S", "Shadow")
, map_entry("SN", "ShareNet")
, map_entry("SS", "SwarmScope")
@@ -176,6 +177,7 @@ namespace
, map_entry("U", "UPnP")
, map_entry("XT", "XanTorrent")
, map_entry("ZT", "ZipTorrent")
+ , map_entry("lt", "libTorrent (libtorrent.rakshasa.no/)")
, map_entry("pX", "pHoeniX")
};
@@ -256,11 +258,13 @@ namespace libtorrent
if (find_string(PID, "Plus")) return "Plus!";
if (find_string(PID, "exbc")) return "BitComet";
if (find_string(PID, "-G3")) return "G3 Torrent";
+ if (find_string(PID, "OP")) return "Opera";
if (find_string(PID, "XBT")) return "XBT";
if (find_string(PID, "-BOW") && PID[7] == '-')
return "Bits on Wheels " + std::string(PID + 4, PID + 7);
+
if (find_string(PID, "eX"))
{
std::string user(PID + 2, PID + 14);
diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp
index e2198c2ce..ecaa4409b 100755
--- a/src/tracker_manager.cpp
+++ b/src/tracker_manager.cpp
@@ -74,7 +74,7 @@ namespace
namespace libtorrent
{
-
+/*
address parse_url(std::string const& url)
{
std::string hostname; // hostname only
@@ -121,7 +121,7 @@ namespace libtorrent
return address(hostname.c_str(), port);
}
-
+*/
// returns -1 if gzip header is invalid or the header size in bytes
int gzip_header(const char* buf, int size)
{
diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp
index a92f9b6bf..09c16c31c 100755
--- a/src/udp_tracker_connection.cpp
+++ b/src/udp_tracker_connection.cpp
@@ -73,14 +73,9 @@ namespace libtorrent
, m_settings(stn)
, m_attempts(0)
{
- // TODO: this is a problem. DNS-lookup is blocking!
- // (may block up to 5 seconds)
- address a(hostname.c_str(), port);
- if (has_requester()) requester().m_tracker_address = a;
+ m_name_lookup = dns_lookup(hostname.c_str(), port);
m_socket.reset(new socket(socket::udp, false));
- m_socket->connect(a);
- send_udp_connect();
}
bool udp_tracker_connection::send_finished() const
@@ -97,6 +92,31 @@ namespace libtorrent
{
using namespace boost::posix_time;
+ if (m_name_lookup.running())
+ {
+ if (!m_name_lookup.finished()) return false;
+
+ if (m_name_lookup.failed())
+ {
+ if (has_requester()) requester().tracker_request_error(
+ m_request, -1, "hostname not found: " + m_name_lookup.error());
+ return true;
+ }
+ address a(m_name_lookup.ip());
+ if (has_requester()) requester().m_tracker_address = a;
+
+#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
+ if (has_requester()) requester().debug_log("name lookup successful");
+#endif
+
+ m_socket->connect(a);
+ send_udp_connect();
+
+ // clear the lookup entry so it will not be
+ // marked as running anymore
+ m_name_lookup = dns_lookup();
+ }
+
time_duration d = second_clock::universal_time() - m_request_time;
if (m_connection_id == 0
&& d > seconds(udp_connect_timeout))