forked from premiere/premiere-libtorrent
added async. gethostbyname support and updated the makefile
This commit is contained in:
parent
c1ec7e8830
commit
42f8393ab0
1
Jamfile
1
Jamfile
|
@ -48,6 +48,7 @@ project torrent
|
||||||
SOURCES =
|
SOURCES =
|
||||||
allocate_resources.cpp
|
allocate_resources.cpp
|
||||||
alert.cpp
|
alert.cpp
|
||||||
|
async_gethostbyname.cpp
|
||||||
entry.cpp
|
entry.cpp
|
||||||
escape_string.cpp
|
escape_string.cpp
|
||||||
file.cpp
|
file.cpp
|
||||||
|
|
|
@ -55,7 +55,7 @@ example client.</p>
|
||||||
<div class="section" id="feedback">
|
<div class="section" id="feedback">
|
||||||
<h1><a name="feedback">Feedback</a></h1>
|
<h1><a name="feedback">Feedback</a></h1>
|
||||||
<p>There's a <a class="reference" href="http://lists.sourceforge.net/lists/listinfo/libtorrent-discuss">mailing list</a>, general libtorrent discussion.</p>
|
<p>There's a <a class="reference" href="http://lists.sourceforge.net/lists/listinfo/libtorrent-discuss">mailing list</a>, general libtorrent discussion.</p>
|
||||||
<p>You can usually find me as hydri in <tt class="docutils literal"><span class="pre">#btports</span> <span class="pre">@</span> <span class="pre">irc.freenode.net</span></tt>.</p>
|
<p>You can usually find me as hydri in <tt class="docutils literal"><span class="pre">#libtorrent</span></tt> on <tt class="docutils literal"><span class="pre">irc.freenode.net</span></tt>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="acknowledgements">
|
<div class="section" id="acknowledgements">
|
||||||
<h1><a name="acknowledgements">Acknowledgements</a></h1>
|
<h1><a name="acknowledgements">Acknowledgements</a></h1>
|
||||||
|
|
|
@ -54,7 +54,7 @@ There's a `mailing list`__, general libtorrent discussion.
|
||||||
|
|
||||||
__ http://lists.sourceforge.net/lists/listinfo/libtorrent-discuss
|
__ 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
|
Acknowledgements
|
||||||
|
|
|
@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/peer_id.hpp"
|
#include "libtorrent/peer_id.hpp"
|
||||||
#include "libtorrent/peer.hpp"
|
#include "libtorrent/peer.hpp"
|
||||||
#include "libtorrent/tracker_manager.hpp"
|
#include "libtorrent/tracker_manager.hpp"
|
||||||
|
#include "libtorrent/async_gethostbyname.hpp"
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
@ -96,6 +97,7 @@ namespace libtorrent
|
||||||
int m_content_length;
|
int m_content_length;
|
||||||
std::string m_location;
|
std::string m_location;
|
||||||
|
|
||||||
|
dns_lookup m_name_lookup;
|
||||||
boost::shared_ptr<socket> m_socket;
|
boost::shared_ptr<socket> m_socket;
|
||||||
int m_recv_pos;
|
int m_recv_pos;
|
||||||
std::vector<char> m_buffer;
|
std::vector<char> m_buffer;
|
||||||
|
|
|
@ -62,7 +62,7 @@ namespace libtorrent
|
||||||
struct request_callback;
|
struct request_callback;
|
||||||
class tracker_manager;
|
class tracker_manager;
|
||||||
|
|
||||||
address parse_url(std::string const& url);
|
// address parse_url(std::string const& url);
|
||||||
|
|
||||||
// encodes a string using the base64 scheme
|
// encodes a string using the base64 scheme
|
||||||
std::string base64encode(const std::string& s);
|
std::string base64encode(const std::string& s);
|
||||||
|
|
|
@ -56,6 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/peer_id.hpp"
|
#include "libtorrent/peer_id.hpp"
|
||||||
#include "libtorrent/peer.hpp"
|
#include "libtorrent/peer.hpp"
|
||||||
#include "libtorrent/tracker_manager.hpp"
|
#include "libtorrent/tracker_manager.hpp"
|
||||||
|
#include "libtorrent/async_gethostbyname.hpp"
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
@ -93,6 +94,7 @@ namespace libtorrent
|
||||||
bool parse_announce_response(const char* buf, int ret);
|
bool parse_announce_response(const char* buf, int ret);
|
||||||
bool parse_scrape_response(const char* buf, int ret);
|
bool parse_scrape_response(const char* buf, int ret);
|
||||||
|
|
||||||
|
dns_lookup m_name_lookup;
|
||||||
boost::shared_ptr<socket> m_socket;
|
boost::shared_ptr<socket> m_socket;
|
||||||
|
|
||||||
// used for time outs
|
// used for time outs
|
||||||
|
|
|
@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
#include "libtorrent/torrent.hpp"
|
#include "libtorrent/torrent.hpp"
|
||||||
#include "libtorrent/io.hpp"
|
#include "libtorrent/io.hpp"
|
||||||
|
#include "libtorrent/async_gethostbyname.hpp"
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
@ -113,13 +114,6 @@ namespace libtorrent
|
||||||
connect_to_host = &hostname;
|
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<socket> s(new socket(socket::tcp, false));
|
|
||||||
s->connect(a);
|
|
||||||
|
|
||||||
m_send_buffer.assign("GET ");
|
m_send_buffer.assign("GET ");
|
||||||
if (using_proxy)
|
if (using_proxy)
|
||||||
{
|
{
|
||||||
|
@ -224,7 +218,9 @@ namespace libtorrent
|
||||||
requester().debug_log("info_hash: " + info_hash_str.str() + "\n");
|
requester().debug_log("info_hash: " + info_hash_str.str() + "\n");
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
// returns true if this connection is finished and should be removed from
|
||||||
|
@ -236,6 +232,30 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
#endif
|
#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;
|
using namespace boost::posix_time;
|
||||||
|
|
||||||
time_duration d = second_clock::universal_time() - m_request_time;
|
time_duration d = second_clock::universal_time() - m_request_time;
|
||||||
|
|
|
@ -167,6 +167,7 @@ namespace
|
||||||
, map_entry("M", "Mainline")
|
, map_entry("M", "Mainline")
|
||||||
, map_entry("MP", "MooPolice")
|
, map_entry("MP", "MooPolice")
|
||||||
, map_entry("MT", "Moonlight Torrent")
|
, map_entry("MT", "Moonlight Torrent")
|
||||||
|
, map_entry("O", "Osprey Permaseed")
|
||||||
, map_entry("S", "Shadow")
|
, map_entry("S", "Shadow")
|
||||||
, map_entry("SN", "ShareNet")
|
, map_entry("SN", "ShareNet")
|
||||||
, map_entry("SS", "SwarmScope")
|
, map_entry("SS", "SwarmScope")
|
||||||
|
@ -176,6 +177,7 @@ namespace
|
||||||
, map_entry("U", "UPnP")
|
, map_entry("U", "UPnP")
|
||||||
, map_entry("XT", "XanTorrent")
|
, map_entry("XT", "XanTorrent")
|
||||||
, map_entry("ZT", "ZipTorrent")
|
, map_entry("ZT", "ZipTorrent")
|
||||||
|
, map_entry("lt", "libTorrent (libtorrent.rakshasa.no/)")
|
||||||
, map_entry("pX", "pHoeniX")
|
, map_entry("pX", "pHoeniX")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -256,11 +258,13 @@ namespace libtorrent
|
||||||
if (find_string(PID, "Plus")) return "Plus!";
|
if (find_string(PID, "Plus")) return "Plus!";
|
||||||
if (find_string(PID, "exbc")) return "BitComet";
|
if (find_string(PID, "exbc")) return "BitComet";
|
||||||
if (find_string(PID, "-G3")) return "G3 Torrent";
|
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, "XBT")) return "XBT";
|
||||||
|
|
||||||
if (find_string(PID, "-BOW") && PID[7] == '-')
|
if (find_string(PID, "-BOW") && PID[7] == '-')
|
||||||
return "Bits on Wheels " + std::string(PID + 4, PID + 7);
|
return "Bits on Wheels " + std::string(PID + 4, PID + 7);
|
||||||
|
|
||||||
|
|
||||||
if (find_string(PID, "eX"))
|
if (find_string(PID, "eX"))
|
||||||
{
|
{
|
||||||
std::string user(PID + 2, PID + 14);
|
std::string user(PID + 2, PID + 14);
|
||||||
|
|
|
@ -74,7 +74,7 @@ namespace
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
address parse_url(std::string const& url)
|
address parse_url(std::string const& url)
|
||||||
{
|
{
|
||||||
std::string hostname; // hostname only
|
std::string hostname; // hostname only
|
||||||
|
@ -121,7 +121,7 @@ namespace libtorrent
|
||||||
|
|
||||||
return address(hostname.c_str(), port);
|
return address(hostname.c_str(), port);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// returns -1 if gzip header is invalid or the header size in bytes
|
// returns -1 if gzip header is invalid or the header size in bytes
|
||||||
int gzip_header(const char* buf, int size)
|
int gzip_header(const char* buf, int size)
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,14 +73,9 @@ namespace libtorrent
|
||||||
, m_settings(stn)
|
, m_settings(stn)
|
||||||
, m_attempts(0)
|
, m_attempts(0)
|
||||||
{
|
{
|
||||||
// TODO: this is a problem. DNS-lookup is blocking!
|
m_name_lookup = dns_lookup(hostname.c_str(), port);
|
||||||
// (may block up to 5 seconds)
|
|
||||||
address a(hostname.c_str(), port);
|
|
||||||
if (has_requester()) requester().m_tracker_address = a;
|
|
||||||
m_socket.reset(new socket(socket::udp, false));
|
m_socket.reset(new socket(socket::udp, false));
|
||||||
m_socket->connect(a);
|
|
||||||
|
|
||||||
send_udp_connect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool udp_tracker_connection::send_finished() const
|
bool udp_tracker_connection::send_finished() const
|
||||||
|
@ -97,6 +92,31 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
using namespace boost::posix_time;
|
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;
|
time_duration d = second_clock::universal_time() - m_request_time;
|
||||||
if (m_connection_id == 0
|
if (m_connection_id == 0
|
||||||
&& d > seconds(udp_connect_timeout))
|
&& d > seconds(udp_connect_timeout))
|
||||||
|
|
Loading…
Reference in New Issue