forked from premiere/premiere-libtorrent
*** empty log message ***
This commit is contained in:
parent
5e3896aae0
commit
89b1f1f5d5
|
@ -70,7 +70,7 @@ namespace libtorrent
|
||||||
, tracker_request const& req
|
, tracker_request const& req
|
||||||
, std::string const& hostname
|
, std::string const& hostname
|
||||||
, unsigned short port
|
, unsigned short port
|
||||||
, std::string const& request
|
, std::string request
|
||||||
, boost::weak_ptr<request_callback> c
|
, boost::weak_ptr<request_callback> c
|
||||||
, const http_settings& stn
|
, const http_settings& stn
|
||||||
, std::string const& password = "");
|
, std::string const& password = "");
|
||||||
|
|
|
@ -77,6 +77,19 @@ namespace libtorrent
|
||||||
|
|
||||||
struct tracker_request
|
struct tracker_request
|
||||||
{
|
{
|
||||||
|
tracker_request()
|
||||||
|
: kind(announce_request)
|
||||||
|
, event(none)
|
||||||
|
, key(0)
|
||||||
|
, num_want(0)
|
||||||
|
{}
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
announce_request,
|
||||||
|
scrape_request
|
||||||
|
} kind;
|
||||||
|
|
||||||
enum event_t
|
enum event_t
|
||||||
{
|
{
|
||||||
none,
|
none,
|
||||||
|
@ -162,10 +175,6 @@ namespace libtorrent
|
||||||
tracker_connections_t m_connections;
|
tracker_connections_t m_connections;
|
||||||
const http_settings& m_settings;
|
const http_settings& m_settings;
|
||||||
};
|
};
|
||||||
/*
|
|
||||||
inline request_callback::~request_callback()
|
|
||||||
{ if (m_manager) m_manager->abort_request(this); }
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TORRENT_TRACKER_MANAGER_HPP_INCLUDED
|
#endif // TORRENT_TRACKER_MANAGER_HPP_INCLUDED
|
||||||
|
|
|
@ -82,7 +82,7 @@ namespace libtorrent
|
||||||
, tracker_request const& req
|
, tracker_request const& req
|
||||||
, std::string const& hostname
|
, std::string const& hostname
|
||||||
, unsigned short port
|
, unsigned short port
|
||||||
, std::string const& request
|
, std::string request
|
||||||
, boost::weak_ptr<request_callback> c
|
, boost::weak_ptr<request_callback> c
|
||||||
, const http_settings& stn
|
, const http_settings& stn
|
||||||
, std::string const& auth)
|
, std::string const& auth)
|
||||||
|
@ -129,46 +129,69 @@ namespace libtorrent
|
||||||
m_send_buffer += boost::lexical_cast<std::string>(port);
|
m_send_buffer += boost::lexical_cast<std::string>(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_req.kind == tracker_request::scrape_request)
|
||||||
|
{
|
||||||
|
// TODO: find and replace "announce" with "scrape"
|
||||||
|
// in request
|
||||||
|
|
||||||
|
std::size_t pos = request.find("announce");
|
||||||
|
if (pos == std::string::npos)
|
||||||
|
throw std::runtime_error("scrape is not available on url: '"
|
||||||
|
+ m_req.url +"'");
|
||||||
|
request.replace(pos, 8, "scrape");
|
||||||
|
}
|
||||||
|
|
||||||
m_send_buffer += request;
|
m_send_buffer += request;
|
||||||
|
|
||||||
m_send_buffer += "?info_hash=";
|
// if request-string already contains
|
||||||
|
// some parameters, append an ampersand instead
|
||||||
|
// of a question mark
|
||||||
|
if (request.find('?') != std::string::npos)
|
||||||
|
m_send_buffer += "&";
|
||||||
|
else
|
||||||
|
m_send_buffer += "?";
|
||||||
|
|
||||||
|
m_send_buffer += "info_hash=";
|
||||||
m_send_buffer += escape_string(
|
m_send_buffer += escape_string(
|
||||||
reinterpret_cast<const char*>(req.info_hash.begin()), 20);
|
reinterpret_cast<const char*>(req.info_hash.begin()), 20);
|
||||||
|
|
||||||
m_send_buffer += "&peer_id=";
|
if (m_req.kind == tracker_request::announce_request)
|
||||||
m_send_buffer += escape_string(
|
|
||||||
reinterpret_cast<const char*>(req.id.begin()), 20);
|
|
||||||
|
|
||||||
m_send_buffer += "&port=";
|
|
||||||
m_send_buffer += boost::lexical_cast<std::string>(req.listen_port);
|
|
||||||
|
|
||||||
m_send_buffer += "&uploaded=";
|
|
||||||
m_send_buffer += boost::lexical_cast<std::string>(req.uploaded);
|
|
||||||
|
|
||||||
m_send_buffer += "&downloaded=";
|
|
||||||
m_send_buffer += boost::lexical_cast<std::string>(req.downloaded);
|
|
||||||
|
|
||||||
m_send_buffer += "&left=";
|
|
||||||
m_send_buffer += boost::lexical_cast<std::string>(req.left);
|
|
||||||
|
|
||||||
if (req.event != tracker_request::none)
|
|
||||||
{
|
{
|
||||||
const char* event_string[] = {"completed", "started", "stopped"};
|
m_send_buffer += "&peer_id=";
|
||||||
m_send_buffer += "&event=";
|
m_send_buffer += escape_string(
|
||||||
m_send_buffer += event_string[req.event - 1];
|
reinterpret_cast<const char*>(req.id.begin()), 20);
|
||||||
}
|
|
||||||
m_send_buffer += "&key=";
|
|
||||||
std::stringstream key_string;
|
|
||||||
key_string << std::hex << req.key;
|
|
||||||
m_send_buffer += key_string.str();
|
|
||||||
m_send_buffer += "&compact=1";
|
|
||||||
m_send_buffer += "&numwant=";
|
|
||||||
m_send_buffer += boost::lexical_cast<std::string>(
|
|
||||||
std::min(req.num_want, 999));
|
|
||||||
|
|
||||||
// extension that tells the tracker that
|
m_send_buffer += "&port=";
|
||||||
// we don't need any peer_id's in the response
|
m_send_buffer += boost::lexical_cast<std::string>(req.listen_port);
|
||||||
m_send_buffer += "&no_peer_id=1";
|
|
||||||
|
m_send_buffer += "&uploaded=";
|
||||||
|
m_send_buffer += boost::lexical_cast<std::string>(req.uploaded);
|
||||||
|
|
||||||
|
m_send_buffer += "&downloaded=";
|
||||||
|
m_send_buffer += boost::lexical_cast<std::string>(req.downloaded);
|
||||||
|
|
||||||
|
m_send_buffer += "&left=";
|
||||||
|
m_send_buffer += boost::lexical_cast<std::string>(req.left);
|
||||||
|
|
||||||
|
if (req.event != tracker_request::none)
|
||||||
|
{
|
||||||
|
const char* event_string[] = {"completed", "started", "stopped"};
|
||||||
|
m_send_buffer += "&event=";
|
||||||
|
m_send_buffer += event_string[req.event - 1];
|
||||||
|
}
|
||||||
|
m_send_buffer += "&key=";
|
||||||
|
std::stringstream key_string;
|
||||||
|
key_string << std::hex << req.key;
|
||||||
|
m_send_buffer += key_string.str();
|
||||||
|
m_send_buffer += "&compact=1";
|
||||||
|
m_send_buffer += "&numwant=";
|
||||||
|
m_send_buffer += boost::lexical_cast<std::string>(
|
||||||
|
std::min(req.num_want, 999));
|
||||||
|
|
||||||
|
// extension that tells the tracker that
|
||||||
|
// we don't need any peer_id's in the response
|
||||||
|
m_send_buffer += "&no_peer_id=1";
|
||||||
|
}
|
||||||
|
|
||||||
m_send_buffer += " HTTP/1.0\r\nAccept-Encoding: gzip\r\n"
|
m_send_buffer += " HTTP/1.0\r\nAccept-Encoding: gzip\r\n"
|
||||||
"User-Agent: ";
|
"User-Agent: ";
|
||||||
|
@ -546,11 +569,9 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
if (!has_requester()) return;
|
if (!has_requester()) return;
|
||||||
|
|
||||||
std::vector<peer_entry> peer_list;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// parse the response
|
// parse the response
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
entry const& failure = e["failure reason"];
|
entry const& failure = e["failure reason"];
|
||||||
|
@ -561,9 +582,22 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
catch (type_error const&) {}
|
catch (type_error const&) {}
|
||||||
|
|
||||||
int interval = (int)e["interval"].integer();
|
std::vector<peer_entry> peer_list;
|
||||||
|
|
||||||
peer_list.clear();
|
if (m_req.kind == tracker_request::scrape_request)
|
||||||
|
{
|
||||||
|
std::string ih;
|
||||||
|
std::copy(m_req.info_hash.begin(), m_req.info_hash.end()
|
||||||
|
, std::back_inserter(ih));
|
||||||
|
entry scrape_data = e["files"][ih];
|
||||||
|
int complete = scrape_data["complete"].integer();
|
||||||
|
int incomplete = scrape_data["incomplete"].integer();
|
||||||
|
requester().tracker_response(peer_list, 0, complete
|
||||||
|
, incomplete);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int interval = (int)e["interval"].integer();
|
||||||
|
|
||||||
if (e["peers"].type() == entry::string_t)
|
if (e["peers"].type() == entry::string_t)
|
||||||
{
|
{
|
||||||
|
|
|
@ -251,8 +251,8 @@ namespace libtorrent
|
||||||
|
|
||||||
if (find_string(PID, "eX"))
|
if (find_string(PID, "eX"))
|
||||||
{
|
{
|
||||||
std::string user(PID + 2, PID + 20);
|
std::string user(PID + 2, PID + 14);
|
||||||
return "eXeem ('" + user + "')";
|
return std::string("eXeem ('") + user.c_str() + "')";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::equal(PID, PID + 13, "\0\0\0\0\0\0\0\0\0\0\0\0\x97"))
|
if (std::equal(PID, PID + 13, "\0\0\0\0\0\0\0\0\0\0\0\0\x97"))
|
||||||
|
|
|
@ -1033,6 +1033,12 @@ namespace libtorrent
|
||||||
= boost::posix_time::seconds(0);
|
= boost::posix_time::seconds(0);
|
||||||
st.announce_interval = boost::posix_time::seconds(m_duration);
|
st.announce_interval = boost::posix_time::seconds(m_duration);
|
||||||
|
|
||||||
|
if (m_last_working_tracker >= 0)
|
||||||
|
{
|
||||||
|
st.current_tracker
|
||||||
|
= m_trackers[m_last_working_tracker].url;
|
||||||
|
}
|
||||||
|
|
||||||
// if we don't have any metadata, stop here
|
// if we don't have any metadata, stop here
|
||||||
|
|
||||||
if (!valid_metadata())
|
if (!valid_metadata())
|
||||||
|
@ -1042,29 +1048,16 @@ namespace libtorrent
|
||||||
else
|
else
|
||||||
st.state = torrent_status::downloading_metadata;
|
st.state = torrent_status::downloading_metadata;
|
||||||
|
|
||||||
if (m_have_metadata.empty())
|
st.progress = std::count(
|
||||||
{
|
m_have_metadata.begin()
|
||||||
st.progress = 0.f;
|
, m_have_metadata.end()
|
||||||
}
|
, true) / 256.f;
|
||||||
else
|
|
||||||
{
|
|
||||||
st.progress = std::count(
|
|
||||||
m_have_metadata.begin()
|
|
||||||
, m_have_metadata.end()
|
|
||||||
, true) / 256.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill in status that depends on metadata
|
// fill in status that depends on metadata
|
||||||
|
|
||||||
if (m_last_working_tracker >= 0)
|
|
||||||
{
|
|
||||||
st.current_tracker
|
|
||||||
= m_trackers[m_last_working_tracker].url;
|
|
||||||
}
|
|
||||||
|
|
||||||
st.progress = st.total_done
|
st.progress = st.total_done
|
||||||
/ static_cast<float>(m_torrent_file.total_size());
|
/ static_cast<float>(m_torrent_file.total_size());
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <boost/tuple/tuple.hpp>
|
||||||
|
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
|
|
||||||
|
@ -357,40 +358,35 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void tracker_manager::queue_request(
|
namespace
|
||||||
tracker_request req
|
|
||||||
, std::string const& auth
|
|
||||||
, boost::weak_ptr<request_callback> c)
|
|
||||||
{
|
{
|
||||||
assert(req.num_want >= 0);
|
|
||||||
if (req.event == tracker_request::stopped)
|
|
||||||
req.num_want = 0;
|
|
||||||
|
|
||||||
try
|
boost::tuple<std::string, std::string, int, std::string>
|
||||||
|
parse_url_components(std::string url)
|
||||||
{
|
{
|
||||||
std::string hostname; // hostname only
|
std::string hostname; // hostname only
|
||||||
std::string protocol; // should be http
|
std::string protocol; // should be http
|
||||||
int port = 80;
|
int port = 80;
|
||||||
|
|
||||||
// PARSE URL
|
// PARSE URL
|
||||||
std::string::iterator start = req.url.begin();
|
std::string::iterator start = url.begin();
|
||||||
std::string::iterator end
|
std::string::iterator end
|
||||||
= std::find(req.url.begin(), req.url.end(), ':');
|
= std::find(url.begin(), url.end(), ':');
|
||||||
protocol = std::string(start, end);
|
protocol = std::string(start, end);
|
||||||
|
|
||||||
if (end == req.url.end()) throw std::runtime_error("invalid url");
|
if (end == url.end()) throw std::runtime_error("invalid url");
|
||||||
++end;
|
++end;
|
||||||
if (end == req.url.end()) throw std::runtime_error("invalid url");
|
if (end == url.end()) throw std::runtime_error("invalid url");
|
||||||
if (*end != '/') throw std::runtime_error("invalid url");
|
if (*end != '/') throw std::runtime_error("invalid url");
|
||||||
++end;
|
++end;
|
||||||
if (end == req.url.end()) throw std::runtime_error("invalid url");
|
if (end == url.end()) throw std::runtime_error("invalid url");
|
||||||
if (*end != '/') throw std::runtime_error("invalid url");
|
if (*end != '/') throw std::runtime_error("invalid url");
|
||||||
++end;
|
++end;
|
||||||
start = end;
|
start = end;
|
||||||
|
|
||||||
end = std::find(start, req.url.end(), '/');
|
end = std::find(start, url.end(), '/');
|
||||||
std::string::iterator port_pos
|
std::string::iterator port_pos
|
||||||
= std::find(start, req.url.end(), ':');
|
= std::find(start, url.end(), ':');
|
||||||
|
|
||||||
if (port_pos < end)
|
if (port_pos < end)
|
||||||
{
|
{
|
||||||
|
@ -402,7 +398,8 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
catch(boost::bad_lexical_cast&)
|
catch(boost::bad_lexical_cast&)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("invalid url: \"" + req.url + "\"");
|
throw std::runtime_error("invalid url: \"" + url
|
||||||
|
+ "\", port number expected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -411,7 +408,29 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
|
|
||||||
start = end;
|
start = end;
|
||||||
std::string request_string = std::string(start, req.url.end());
|
return boost::make_tuple(protocol, hostname, port
|
||||||
|
, std::string(start, url.end()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tracker_manager::queue_request(
|
||||||
|
tracker_request req
|
||||||
|
, std::string const& auth
|
||||||
|
, boost::weak_ptr<request_callback> c)
|
||||||
|
{
|
||||||
|
assert(req.num_want >= 0);
|
||||||
|
if (req.event == tracker_request::stopped)
|
||||||
|
req.num_want = 0;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::string protocol;
|
||||||
|
std::string hostname;
|
||||||
|
int port;
|
||||||
|
std::string request_string;
|
||||||
|
|
||||||
|
boost::tie(protocol, hostname, port, request_string)
|
||||||
|
= parse_url_components(req.url);
|
||||||
|
|
||||||
boost::shared_ptr<tracker_connection> con;
|
boost::shared_ptr<tracker_connection> con;
|
||||||
|
|
||||||
|
@ -454,6 +473,7 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void tracker_manager::abort_request(request_callback* c)
|
void tracker_manager::abort_request(request_callback* c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,6 +73,9 @@ namespace libtorrent
|
||||||
, m_settings(stn)
|
, m_settings(stn)
|
||||||
, m_attempts(0)
|
, m_attempts(0)
|
||||||
{
|
{
|
||||||
|
// only announce is suppoerted at this time
|
||||||
|
assert(req.kind == tracker_request::announce_request);
|
||||||
|
|
||||||
// TODO: this is a problem. DNS-lookup is blocking!
|
// TODO: this is a problem. DNS-lookup is blocking!
|
||||||
// (may block up to 5 seconds)
|
// (may block up to 5 seconds)
|
||||||
address a(hostname.c_str(), port);
|
address a(hostname.c_str(), port);
|
||||||
|
|
Loading…
Reference in New Issue