include endpoint in tracker alerts

This commit is contained in:
Steven Siloti 2017-08-30 20:57:33 -07:00 committed by Arvid Norberg
parent f734ad067b
commit f022285b13
3 changed files with 70 additions and 36 deletions

View File

@ -132,13 +132,16 @@ namespace libtorrent {
{ {
// internal // internal
tracker_alert(aux::stack_allocator& alloc, torrent_handle const& h tracker_alert(aux::stack_allocator& alloc, torrent_handle const& h
, string_view u); , tcp::endpoint const& ep, string_view u);
static const int alert_type = 2; static const int alert_type = 2;
static constexpr alert_category_t static_category = alert::tracker_notification; static constexpr alert_category_t static_category = alert::tracker_notification;
virtual alert_category_t category() const override { return static_category; } virtual alert_category_t category() const override { return static_category; }
virtual std::string message() const override; virtual std::string message() const override;
// endpoint of the listen interface being announced
aux::noexcept_movable<tcp::endpoint> local_endpoint;
// returns a 0-terminated string of the tracker's URL // returns a 0-terminated string of the tracker's URL
char const* tracker_url() const; char const* tracker_url() const;
@ -432,7 +435,8 @@ namespace libtorrent {
{ {
// internal // internal
tracker_error_alert(aux::stack_allocator& alloc tracker_error_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int times, int status, string_view u , torrent_handle const& h, tcp::endpoint const& ep
, int times, int status, string_view u
, error_code const& e, string_view m); , error_code const& e, string_view m);
TORRENT_DEFINE_ALERT(tracker_error_alert, 11) TORRENT_DEFINE_ALERT(tracker_error_alert, 11)
@ -462,7 +466,8 @@ namespace libtorrent {
{ {
// internal // internal
tracker_warning_alert(aux::stack_allocator& alloc tracker_warning_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u, string_view m); , torrent_handle const& h, tcp::endpoint const& ep
, string_view u, string_view m);
TORRENT_DEFINE_ALERT(tracker_warning_alert, 12) TORRENT_DEFINE_ALERT(tracker_warning_alert, 12)
@ -486,7 +491,8 @@ namespace libtorrent {
{ {
// internal // internal
scrape_reply_alert(aux::stack_allocator& alloc scrape_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int incomp, int comp, string_view u); , torrent_handle const& h, tcp::endpoint const& ep
, int incomp, int comp, string_view u);
TORRENT_DEFINE_ALERT(scrape_reply_alert, 13) TORRENT_DEFINE_ALERT(scrape_reply_alert, 13)
@ -505,9 +511,11 @@ namespace libtorrent {
{ {
// internal // internal
scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u, error_code const& e); , torrent_handle const& h, tcp::endpoint const& ep
, string_view u, error_code const& e);
scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u, string_view m); , torrent_handle const& h, tcp::endpoint const& ep
, string_view u, string_view m);
TORRENT_DEFINE_ALERT(scrape_failed_alert, 14) TORRENT_DEFINE_ALERT(scrape_failed_alert, 14)
@ -539,7 +547,8 @@ namespace libtorrent {
{ {
// internal // internal
tracker_reply_alert(aux::stack_allocator& alloc tracker_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int np, string_view u); , torrent_handle const& h, tcp::endpoint const& ep
, int np, string_view u);
TORRENT_DEFINE_ALERT(tracker_reply_alert, 15) TORRENT_DEFINE_ALERT(tracker_reply_alert, 15)
@ -577,7 +586,7 @@ namespace libtorrent {
{ {
// internal // internal
tracker_announce_alert(aux::stack_allocator& alloc tracker_announce_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h, tcp::endpoint const& ep
, string_view u, int e); , string_view u, int e);
TORRENT_DEFINE_ALERT(tracker_announce_alert, 17) TORRENT_DEFINE_ALERT(tracker_announce_alert, 17)
@ -1716,7 +1725,7 @@ namespace libtorrent {
{ {
// internal // internal
trackerid_alert(aux::stack_allocator& alloc, torrent_handle const& h trackerid_alert(aux::stack_allocator& alloc, torrent_handle const& h
, string_view u, const std::string& id); , tcp::endpoint const& ep , string_view u, const std::string& id);
TORRENT_DEFINE_ALERT(trackerid_alert, 61) TORRENT_DEFINE_ALERT(trackerid_alert, 61)

View File

@ -142,8 +142,9 @@ namespace libtorrent {
} }
tracker_alert::tracker_alert(aux::stack_allocator& alloc tracker_alert::tracker_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u) , torrent_handle const& h, tcp::endpoint const& ep, string_view u)
: torrent_alert(alloc, h) : torrent_alert(alloc, h)
, local_endpoint(ep)
, m_url_idx(alloc.copy_string(u)) , m_url_idx(alloc.copy_string(u))
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, url(u) , url(u)
@ -157,7 +158,8 @@ namespace libtorrent {
std::string tracker_alert::message() const std::string tracker_alert::message() const
{ {
return torrent_alert::message() + " (" + tracker_url() + ")"; return torrent_alert::message() + " (" + tracker_url() + ")"
+ "[" + print_endpoint(local_endpoint) + "]";
} }
read_piece_alert::read_piece_alert(aux::stack_allocator& alloc read_piece_alert::read_piece_alert(aux::stack_allocator& alloc
@ -309,9 +311,9 @@ namespace libtorrent {
} }
tracker_error_alert::tracker_error_alert(aux::stack_allocator& alloc tracker_error_alert::tracker_error_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int times, int status, string_view u , torrent_handle const& h, tcp::endpoint const& ep, int times
, error_code const& e, string_view m) , int status, string_view u, error_code const& e, string_view m)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, ep, u)
, times_in_row(times) , times_in_row(times)
, status_code(status) , status_code(status)
, error(e) , error(e)
@ -339,8 +341,9 @@ namespace libtorrent {
} }
tracker_warning_alert::tracker_warning_alert(aux::stack_allocator& alloc tracker_warning_alert::tracker_warning_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u, string_view m) , torrent_handle const& h, tcp::endpoint const& ep
: tracker_alert(alloc, h, u) , string_view u, string_view m)
: tracker_alert(alloc, h, ep, u)
, m_msg_idx(alloc.copy_string(m)) , m_msg_idx(alloc.copy_string(m))
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, msg(m) , msg(m)
@ -360,8 +363,9 @@ namespace libtorrent {
} }
scrape_reply_alert::scrape_reply_alert(aux::stack_allocator& alloc scrape_reply_alert::scrape_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int incomp, int comp, string_view u) , torrent_handle const& h, tcp::endpoint const& ep
: tracker_alert(alloc, h, u) , int incomp, int comp, string_view u)
: tracker_alert(alloc, h, ep, u)
, incomplete(incomp) , incomplete(incomp)
, complete(comp) , complete(comp)
{ {
@ -377,8 +381,9 @@ namespace libtorrent {
} }
scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u, error_code const& e) , torrent_handle const& h, tcp::endpoint const& ep
: tracker_alert(alloc, h, u) , string_view u, error_code const& e)
: tracker_alert(alloc, h, ep, u)
, error(e) , error(e)
, m_msg_idx() , m_msg_idx()
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -389,8 +394,9 @@ namespace libtorrent {
} }
scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc scrape_failed_alert::scrape_failed_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u, string_view m) , torrent_handle const& h, tcp::endpoint const& ep
: tracker_alert(alloc, h, u) , string_view u, string_view m)
: tracker_alert(alloc, h, ep, u)
, error(errors::tracker_failure) , error(errors::tracker_failure)
, m_msg_idx(alloc.copy_string(m)) , m_msg_idx(alloc.copy_string(m))
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
@ -412,8 +418,9 @@ namespace libtorrent {
} }
tracker_reply_alert::tracker_reply_alert(aux::stack_allocator& alloc tracker_reply_alert::tracker_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h, int np, string_view u) , torrent_handle const& h, tcp::endpoint const& ep
: tracker_alert(alloc, h, u) , int np, string_view u)
: tracker_alert(alloc, h, ep, u)
, num_peers(np) , num_peers(np)
{ {
TORRENT_ASSERT(!u.empty()); TORRENT_ASSERT(!u.empty());
@ -430,7 +437,7 @@ namespace libtorrent {
dht_reply_alert::dht_reply_alert(aux::stack_allocator& alloc dht_reply_alert::dht_reply_alert(aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h
, int np) , int np)
: tracker_alert(alloc, h, "") : tracker_alert(alloc, h, {}, "")
, num_peers(np) , num_peers(np)
{} {}
@ -443,8 +450,8 @@ namespace libtorrent {
} }
tracker_announce_alert::tracker_announce_alert(aux::stack_allocator& alloc tracker_announce_alert::tracker_announce_alert(aux::stack_allocator& alloc
, torrent_handle const& h, string_view u, int e) , torrent_handle const& h, tcp::endpoint const& ep, string_view u, int e)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, ep, u)
, event(e) , event(e)
{ {
TORRENT_ASSERT(!u.empty()); TORRENT_ASSERT(!u.empty());
@ -1312,9 +1319,10 @@ namespace {
trackerid_alert::trackerid_alert( trackerid_alert::trackerid_alert(
aux::stack_allocator& alloc aux::stack_allocator& alloc
, torrent_handle const& h , torrent_handle const& h
, tcp::endpoint const& ep
, string_view u , string_view u
, const std::string& id) , const std::string& id)
: tracker_alert(alloc, h, u) : tracker_alert(alloc, h, ep, u)
, m_tracker_idx(alloc.copy_string(id)) , m_tracker_idx(alloc.copy_string(id))
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
, trackerid(id) , trackerid(id)

View File

@ -2934,7 +2934,7 @@ namespace libtorrent {
if (m_ses.alerts().should_post<tracker_announce_alert>()) if (m_ses.alerts().should_post<tracker_announce_alert>())
{ {
m_ses.alerts().emplace_alert<tracker_announce_alert>( m_ses.alerts().emplace_alert<tracker_announce_alert>(
get_handle(), req.url, req.event); get_handle(), aep.local_endpoint, req.url, req.event);
} }
state.sent_announce = true; state.sent_announce = true;
@ -2989,18 +2989,21 @@ namespace libtorrent {
INVARIANT_CHECK; INVARIANT_CHECK;
announce_entry* ae = find_tracker(req.url); announce_entry* ae = find_tracker(req.url);
tcp::endpoint local_endpoint;
if (ae) if (ae)
{ {
for (auto& aep : ae->endpoints) for (auto& aep : ae->endpoints)
{ {
if (aep.socket != req.outgoing_socket) continue; if (aep.socket != req.outgoing_socket) continue;
local_endpoint = aep.local_endpoint;
aep.message = msg; aep.message = msg;
break; break;
} }
} }
if (m_ses.alerts().should_post<tracker_warning_alert>()) if (m_ses.alerts().should_post<tracker_warning_alert>())
m_ses.alerts().emplace_alert<tracker_warning_alert>(get_handle(), req.url, msg); m_ses.alerts().emplace_alert<tracker_warning_alert>(get_handle()
, local_endpoint, req.url, msg);
} }
void torrent::tracker_scrape_response(tracker_request const& req void torrent::tracker_scrape_response(tracker_request const& req
@ -3012,11 +3015,13 @@ namespace libtorrent {
TORRENT_ASSERT(0 != (req.kind & tracker_request::scrape_request)); TORRENT_ASSERT(0 != (req.kind & tracker_request::scrape_request));
announce_entry* ae = find_tracker(req.url); announce_entry* ae = find_tracker(req.url);
tcp::endpoint local_endpoint;
if (ae) if (ae)
{ {
announce_endpoint* aep = ae->find_endpoint(req.outgoing_socket); announce_endpoint* aep = ae->find_endpoint(req.outgoing_socket);
if (aep) if (aep)
{ {
local_endpoint = aep->local_endpoint;
if (incomplete >= 0) aep->scrape_incomplete = incomplete; if (incomplete >= 0) aep->scrape_incomplete = incomplete;
if (complete >= 0) aep->scrape_complete = complete; if (complete >= 0) aep->scrape_complete = complete;
if (downloaded >= 0) aep->scrape_downloaded = downloaded; if (downloaded >= 0) aep->scrape_downloaded = downloaded;
@ -3032,7 +3037,7 @@ namespace libtorrent {
|| req.triggered_manually) || req.triggered_manually)
{ {
m_ses.alerts().emplace_alert<scrape_reply_alert>( m_ses.alerts().emplace_alert<scrape_reply_alert>(
get_handle(), incomplete, complete, req.url); get_handle(), local_endpoint, incomplete, complete, req.url);
} }
} }
@ -3098,11 +3103,13 @@ namespace libtorrent {
settings().get_int(settings_pack::min_announce_interval))); settings().get_int(settings_pack::min_announce_interval)));
announce_entry* ae = find_tracker(r.url); announce_entry* ae = find_tracker(r.url);
tcp::endpoint local_endpoint;
if (ae) if (ae)
{ {
announce_endpoint* aep = ae->find_endpoint(r.outgoing_socket); announce_endpoint* aep = ae->find_endpoint(r.outgoing_socket);
if (aep) if (aep)
{ {
local_endpoint = aep->local_endpoint;
if (resp.incomplete >= 0) aep->scrape_incomplete = resp.incomplete; if (resp.incomplete >= 0) aep->scrape_incomplete = resp.incomplete;
if (resp.complete >= 0) aep->scrape_complete = resp.complete; if (resp.complete >= 0) aep->scrape_complete = resp.complete;
if (resp.downloaded >= 0) aep->scrape_downloaded = resp.downloaded; if (resp.downloaded >= 0) aep->scrape_downloaded = resp.downloaded;
@ -3123,7 +3130,7 @@ namespace libtorrent {
ae->trackerid = resp.trackerid; ae->trackerid = resp.trackerid;
if (m_ses.alerts().should_post<trackerid_alert>()) if (m_ses.alerts().should_post<trackerid_alert>())
m_ses.alerts().emplace_alert<trackerid_alert>(get_handle() m_ses.alerts().emplace_alert<trackerid_alert>(get_handle()
, r.url, resp.trackerid); , aep->local_endpoint, r.url, resp.trackerid);
} }
update_scrape_state(); update_scrape_state();
@ -3246,7 +3253,7 @@ namespace libtorrent {
|| r.triggered_manually) || r.triggered_manually)
{ {
m_ses.alerts().emplace_alert<tracker_reply_alert>( m_ses.alerts().emplace_alert<tracker_reply_alert>(
get_handle(), int(resp.peers.size() + resp.peers4.size()) get_handle(), local_endpoint, int(resp.peers.size() + resp.peers4.size())
#if TORRENT_USE_IPV6 #if TORRENT_USE_IPV6
+ int(resp.peers6.size()) + int(resp.peers6.size())
#endif #endif
@ -10897,6 +10904,7 @@ namespace {
// announce request // announce request
announce_entry* ae = find_tracker(r.url); announce_entry* ae = find_tracker(r.url);
int fails = 0; int fails = 0;
tcp::endpoint local_endpoint;
if (ae) if (ae)
{ {
auto aep = std::find_if(ae->endpoints.begin(), ae->endpoints.end() auto aep = std::find_if(ae->endpoints.begin(), ae->endpoints.end()
@ -10904,6 +10912,7 @@ namespace {
if (aep != ae->endpoints.end()) if (aep != ae->endpoints.end())
{ {
local_endpoint = aep->local_endpoint;
aep->failed(settings().get_int(settings_pack::tracker_backoff) aep->failed(settings().get_int(settings_pack::tracker_backoff)
, retry_interval); , retry_interval);
aep->last_error = ec; aep->last_error = ec;
@ -10931,16 +10940,17 @@ namespace {
|| r.triggered_manually) || r.triggered_manually)
{ {
m_ses.alerts().emplace_alert<tracker_error_alert>(get_handle() m_ses.alerts().emplace_alert<tracker_error_alert>(get_handle()
, fails, response_code, r.url, ec, msg); , local_endpoint, fails, response_code, r.url, ec, msg);
} }
} }
else else
{ {
announce_entry* ae = find_tracker(r.url);
// scrape request // scrape request
if (response_code == 410) if (response_code == 410)
{ {
// never talk to this tracker again // never talk to this tracker again
announce_entry* ae = find_tracker(r.url);
if (ae) ae->fail_limit = 1; if (ae) ae->fail_limit = 1;
} }
@ -10950,7 +10960,14 @@ namespace {
if (m_ses.alerts().should_post<scrape_failed_alert>() if (m_ses.alerts().should_post<scrape_failed_alert>()
|| r.triggered_manually) || r.triggered_manually)
{ {
m_ses.alerts().emplace_alert<scrape_failed_alert>(get_handle(), r.url, ec); tcp::endpoint local_endpoint;
if (ae)
{
auto aep = ae->find_endpoint(r.outgoing_socket);
if (aep) local_endpoint = aep->local_endpoint;
}
m_ses.alerts().emplace_alert<scrape_failed_alert>(get_handle(), local_endpoint, r.url, ec);
} }
} }
// announce to the next working tracker // announce to the next working tracker