Use scrape & i2p bitset flags for request

This commit is contained in:
Mikhail Titov 2015-06-27 16:30:00 -05:00
parent 5d3938b39b
commit df21a7e8ce
6 changed files with 25 additions and 32 deletions

View File

@ -100,11 +100,7 @@ namespace libtorrent
TORRENT_EXTRA_EXPORT tracker_response parse_tracker_response(
char const* data, int size, error_code& ec
, bool scrape_request, sha1_hash scrape_ih
#if TORRENT_USE_I2P
, bool is_i2p=false
#endif
);
, int flags, sha1_hash scrape_ih);
TORRENT_EXTRA_EXPORT bool extract_peer_info(bdecode_node const& info
, peer_entry& ret, error_code& ec);

View File

@ -118,8 +118,12 @@ namespace libtorrent
enum kind_t
{
announce_request,
scrape_request
// do not compare against announce_request ! check if not scrape instead
announce_request = 0,
scrape_request = 1,
// affects interpretation of peers string in HTTP response
// see parse_tracker_response()
i2p = 2
};
std::string url;

View File

@ -83,7 +83,7 @@ namespace libtorrent
{
std::string url = tracker_req().url;
if (tracker_req().kind == tracker_request::scrape_request)
if (0 != (tracker_req().kind & tracker_request::scrape_request))
{
// find and replace "announce" with "scrape"
// in request
@ -117,7 +117,7 @@ namespace libtorrent
url += "info_hash=";
url += escape_string((const char*)&tracker_req().info_hash[0], 20);
if (tracker_req().kind == tracker_request::announce_request)
if (0 == (tracker_req().kind & tracker_request::scrape_request))
{
const char* event_string[] = {"completed", "started", "stopped", "paused"};
@ -332,12 +332,7 @@ namespace libtorrent
}
tracker_response resp = parse_tracker_response(data, size, ecode
, tracker_req().kind == tracker_request::scrape_request
, tracker_req().info_hash
#if TORRENT_USE_I2P
, tracker_req().i2pconn != NULL
#endif
);
, tracker_req().kind, tracker_req().info_hash);
if (!resp.warning_message.empty())
cb->tracker_warning(tracker_req(), resp.warning_message);
@ -358,7 +353,7 @@ namespace libtorrent
}
// do slightly different things for scrape requests
if (tracker_req().kind == tracker_request::scrape_request)
if (0 != (tracker_req().kind & tracker_request::scrape_request))
{
cb->tracker_scrape_response(tracker_req(), resp.complete
, resp.incomplete, resp.downloaded, resp.downloaders);
@ -427,11 +422,7 @@ namespace libtorrent
}
tracker_response parse_tracker_response(char const* data, int size, error_code& ec
, bool scrape_request, sha1_hash scrape_ih
#if TORRENT_USE_I2P
, bool is_i2p
#endif
)
, int flags, sha1_hash scrape_ih)
{
tracker_response resp;
@ -471,7 +462,7 @@ namespace libtorrent
if (warning)
resp.warning_message = warning.string_value();
if (scrape_request)
if (0 != (flags & tracker_request::scrape_request))
{
bdecode_node files = e.dict_find_dict("files");
if (!files)
@ -508,7 +499,8 @@ namespace libtorrent
char const* peers = peers_ent.string_ptr();
int len = peers_ent.string_length();
#if TORRENT_USE_I2P
if (is_i2p) {
if (0 != (flags & tracker_request::i2p))
{
error_code parse_error;
for (int i = 0; i < len; i += 32)
{

View File

@ -1250,6 +1250,7 @@ namespace aux {
#endif
#if TORRENT_USE_I2P
req.i2pconn = &m_i2p_conn;
req.kind |= tracker_request::i2p;
#endif
if (is_any(req.bind_ip)) req.bind_ip = m_listen_interface.address();

View File

@ -3224,7 +3224,7 @@ namespace libtorrent
req.filter = m_ip_filter;
req.info_hash = m_torrent_file->info_hash();
req.kind = tracker_request::scrape_request;
req.kind |= tracker_request::scrape_request;
req.url = m_trackers[i].url;
req.auth = tracker_login();
req.key = tracker_key();
@ -3247,7 +3247,7 @@ namespace libtorrent
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(req.kind == tracker_request::scrape_request);
TORRENT_ASSERT(0 != (req.kind & tracker_request::scrape_request));
announce_entry* ae = find_tracker(req);
if (ae)
@ -3305,7 +3305,7 @@ namespace libtorrent
TORRENT_ASSERT(is_single_thread());
INVARIANT_CHECK;
TORRENT_ASSERT(r.kind == tracker_request::announce_request);
TORRENT_ASSERT(0 == (r.kind & tracker_request::scrape_request));
// TODO: 2 this looks suspicious. Figure out why it makes sense to use the
// first IP in this list and leave a comment here
@ -11680,7 +11680,7 @@ namespace libtorrent
debug_log("*** tracker error: (%d) %s %s", ec.value()
, ec.message().c_str(), msg.c_str());
#endif
if (r.kind == tracker_request::announce_request)
if (0 == (r.kind & tracker_request::scrape_request))
{
announce_entry* ae = find_tracker(r);
if (ae)
@ -11703,7 +11703,7 @@ namespace libtorrent
, ae?ae->fails:0, response_code, r.url, ec, msg);
}
}
else if (r.kind == tracker_request::scrape_request)
else if (0 != (r.kind & tracker_request::scrape_request))
{
if (response_code == 410)
{

View File

@ -288,9 +288,9 @@ namespace libtorrent
// use if if it hasn't expired
if (aux::time_now() < cc->second.expires)
{
if (tracker_req().kind == tracker_request::announce_request)
if (0 == (tracker_req().kind & tracker_request::scrape_request))
send_udp_announce();
else if (tracker_req().kind == tracker_request::scrape_request)
else if (0 != (tracker_req().kind & tracker_request::scrape_request))
send_udp_scrape();
return;
}
@ -468,9 +468,9 @@ namespace libtorrent
cce.connection_id = connection_id;
cce.expires = aux::time_now() + seconds(m_man.settings().get_int(settings_pack::udp_tracker_token_expiry));
if (tracker_req().kind == tracker_request::announce_request)
if (0 == (tracker_req().kind & tracker_request::scrape_request))
send_udp_announce();
else if (tracker_req().kind == tracker_request::scrape_request)
else if (0 != (tracker_req().kind & tracker_request::scrape_request))
send_udp_scrape();
return true;
}