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
|
||||
, std::string const& hostname
|
||||
, unsigned short port
|
||||
, std::string const& request
|
||||
, std::string request
|
||||
, boost::weak_ptr<request_callback> c
|
||||
, const http_settings& stn
|
||||
, std::string const& password = "");
|
||||
|
|
|
@ -77,6 +77,19 @@ namespace libtorrent
|
|||
|
||||
struct tracker_request
|
||||
{
|
||||
tracker_request()
|
||||
: kind(announce_request)
|
||||
, event(none)
|
||||
, key(0)
|
||||
, num_want(0)
|
||||
{}
|
||||
|
||||
enum
|
||||
{
|
||||
announce_request,
|
||||
scrape_request
|
||||
} kind;
|
||||
|
||||
enum event_t
|
||||
{
|
||||
none,
|
||||
|
@ -162,10 +175,6 @@ namespace libtorrent
|
|||
tracker_connections_t m_connections;
|
||||
const http_settings& m_settings;
|
||||
};
|
||||
/*
|
||||
inline request_callback::~request_callback()
|
||||
{ if (m_manager) m_manager->abort_request(this); }
|
||||
*/
|
||||
}
|
||||
|
||||
#endif // TORRENT_TRACKER_MANAGER_HPP_INCLUDED
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace libtorrent
|
|||
, tracker_request const& req
|
||||
, std::string const& hostname
|
||||
, unsigned short port
|
||||
, std::string const& request
|
||||
, std::string request
|
||||
, boost::weak_ptr<request_callback> c
|
||||
, const http_settings& stn
|
||||
, std::string const& auth)
|
||||
|
@ -129,12 +129,34 @@ namespace libtorrent
|
|||
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 += "?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(
|
||||
reinterpret_cast<const char*>(req.info_hash.begin()), 20);
|
||||
|
||||
if (m_req.kind == tracker_request::announce_request)
|
||||
{
|
||||
m_send_buffer += "&peer_id=";
|
||||
m_send_buffer += escape_string(
|
||||
reinterpret_cast<const char*>(req.id.begin()), 20);
|
||||
|
@ -169,6 +191,7 @@ namespace libtorrent
|
|||
// 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"
|
||||
"User-Agent: ";
|
||||
|
@ -546,11 +569,9 @@ namespace libtorrent
|
|||
{
|
||||
if (!has_requester()) return;
|
||||
|
||||
std::vector<peer_entry> peer_list;
|
||||
try
|
||||
{
|
||||
// parse the response
|
||||
|
||||
try
|
||||
{
|
||||
entry const& failure = e["failure reason"];
|
||||
|
@ -561,9 +582,22 @@ namespace libtorrent
|
|||
}
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -251,8 +251,8 @@ namespace libtorrent
|
|||
|
||||
if (find_string(PID, "eX"))
|
||||
{
|
||||
std::string user(PID + 2, PID + 20);
|
||||
return "eXeem ('" + user + "')";
|
||||
std::string user(PID + 2, PID + 14);
|
||||
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"))
|
||||
|
|
|
@ -1033,6 +1033,12 @@ namespace libtorrent
|
|||
= boost::posix_time::seconds(0);
|
||||
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 (!valid_metadata())
|
||||
|
@ -1042,29 +1048,16 @@ namespace libtorrent
|
|||
else
|
||||
st.state = torrent_status::downloading_metadata;
|
||||
|
||||
if (m_have_metadata.empty())
|
||||
{
|
||||
st.progress = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
st.progress = std::count(
|
||||
m_have_metadata.begin()
|
||||
, m_have_metadata.end()
|
||||
, true) / 256.f;
|
||||
}
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
// 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
|
||||
/ static_cast<float>(m_torrent_file.total_size());
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <cctype>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
|
@ -357,40 +358,35 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
|
||||
void tracker_manager::queue_request(
|
||||
tracker_request req
|
||||
, std::string const& auth
|
||||
, boost::weak_ptr<request_callback> c)
|
||||
namespace
|
||||
{
|
||||
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 protocol; // should be http
|
||||
int port = 80;
|
||||
|
||||
// PARSE URL
|
||||
std::string::iterator start = req.url.begin();
|
||||
std::string::iterator start = url.begin();
|
||||
std::string::iterator end
|
||||
= std::find(req.url.begin(), req.url.end(), ':');
|
||||
= std::find(url.begin(), url.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;
|
||||
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");
|
||||
++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");
|
||||
++end;
|
||||
start = end;
|
||||
|
||||
end = std::find(start, req.url.end(), '/');
|
||||
end = std::find(start, url.end(), '/');
|
||||
std::string::iterator port_pos
|
||||
= std::find(start, req.url.end(), ':');
|
||||
= std::find(start, url.end(), ':');
|
||||
|
||||
if (port_pos < end)
|
||||
{
|
||||
|
@ -402,7 +398,8 @@ namespace libtorrent
|
|||
}
|
||||
catch(boost::bad_lexical_cast&)
|
||||
{
|
||||
throw std::runtime_error("invalid url: \"" + req.url + "\"");
|
||||
throw std::runtime_error("invalid url: \"" + url
|
||||
+ "\", port number expected");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -411,7 +408,29 @@ namespace libtorrent
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
|
@ -454,6 +473,7 @@ namespace libtorrent
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void tracker_manager::abort_request(request_callback* c)
|
||||
{
|
||||
|
|
|
@ -73,6 +73,9 @@ namespace libtorrent
|
|||
, m_settings(stn)
|
||||
, 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!
|
||||
// (may block up to 5 seconds)
|
||||
address a(hostname.c_str(), port);
|
||||
|
|
Loading…
Reference in New Issue