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
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 constexpr alert_category_t static_category = alert::tracker_notification;
virtual alert_category_t category() const override { return static_category; }
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
char const* tracker_url() const;
@ -432,7 +435,8 @@ namespace libtorrent {
{
// internal
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);
TORRENT_DEFINE_ALERT(tracker_error_alert, 11)
@ -462,7 +466,8 @@ namespace libtorrent {
{
// internal
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)
@ -486,7 +491,8 @@ namespace libtorrent {
{
// internal
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)
@ -505,9 +511,11 @@ namespace libtorrent {
{
// internal
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
, 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)
@ -539,7 +547,8 @@ namespace libtorrent {
{
// internal
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)
@ -577,7 +586,7 @@ namespace libtorrent {
{
// internal
tracker_announce_alert(aux::stack_allocator& alloc
, torrent_handle const& h
, torrent_handle const& h, tcp::endpoint const& ep
, string_view u, int e);
TORRENT_DEFINE_ALERT(tracker_announce_alert, 17)
@ -1716,7 +1725,7 @@ namespace libtorrent {
{
// internal
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)

View File

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

View File

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