deprecate status_code from tracker_error_alert (it's already part of the error_code), simplify code a bit
This commit is contained in:
parent
d45de18ba7
commit
a54f76d5df
|
@ -383,10 +383,10 @@ void bind_alert()
|
|||
"tracker_error_alert", no_init)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
.def_readonly("msg", &tracker_error_alert::msg)
|
||||
.def_readonly("status_code", &tracker_error_alert::status_code)
|
||||
#endif
|
||||
.def("error_message", &tracker_error_alert::error_message)
|
||||
.def_readonly("times_in_row", &tracker_error_alert::times_in_row)
|
||||
.def_readonly("status_code", &tracker_error_alert::status_code)
|
||||
.def_readonly("error", &tracker_error_alert::error)
|
||||
;
|
||||
|
||||
|
|
|
@ -439,7 +439,7 @@ namespace libtorrent {
|
|||
// internal
|
||||
tracker_error_alert(aux::stack_allocator& alloc
|
||||
, torrent_handle const& h, tcp::endpoint const& ep
|
||||
, int times, int status, string_view u
|
||||
, int times, string_view u
|
||||
, error_code const& e, string_view m);
|
||||
|
||||
TORRENT_DEFINE_ALERT(tracker_error_alert, 11)
|
||||
|
@ -448,7 +448,6 @@ namespace libtorrent {
|
|||
std::string message() const override;
|
||||
|
||||
int const times_in_row;
|
||||
int const status_code;
|
||||
error_code const error;
|
||||
|
||||
// the message associated with this error
|
||||
|
@ -458,6 +457,7 @@ namespace libtorrent {
|
|||
aux::allocation_slot m_msg_idx;
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
public:
|
||||
int const status_code;
|
||||
std::string TORRENT_DEPRECATED_MEMBER msg;
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -1299,7 +1299,7 @@ namespace aux {
|
|||
, std::list<address> const& ip_list
|
||||
, struct tracker_response const& resp) override;
|
||||
void tracker_request_error(tracker_request const& r
|
||||
, int response_code, error_code const& ec, const std::string& str
|
||||
, error_code const& ec, const std::string& str
|
||||
, seconds32 retry_interval) override;
|
||||
bool should_log() const override;
|
||||
void debug_log(const char* fmt, ...) const override TORRENT_FORMAT(2,3);
|
||||
|
|
|
@ -724,7 +724,7 @@ namespace libtorrent {
|
|||
, std::list<address> const& ip_list
|
||||
, struct tracker_response const& resp) override;
|
||||
void tracker_request_error(tracker_request const& r
|
||||
, int response_code, error_code const& ec, const std::string& msg
|
||||
, error_code const& ec, const std::string& msg
|
||||
, seconds32 retry_interval) override;
|
||||
void tracker_warning(tracker_request const& req
|
||||
, std::string const& msg) override;
|
||||
|
|
|
@ -243,7 +243,6 @@ namespace libtorrent {
|
|||
, struct tracker_response const& response) = 0;
|
||||
virtual void tracker_request_error(
|
||||
tracker_request const& req
|
||||
, int response_code
|
||||
, error_code const& ec
|
||||
, const std::string& msg
|
||||
, seconds32 retry_interval) = 0;
|
||||
|
@ -309,7 +308,7 @@ namespace libtorrent {
|
|||
|
||||
tracker_request const& tracker_req() const { return m_req; }
|
||||
|
||||
void fail(error_code const& ec, int code = -1, char const* msg = ""
|
||||
void fail(error_code const& ec, char const* msg = ""
|
||||
, seconds32 interval = seconds32(0), seconds32 min_interval = seconds32(0));
|
||||
virtual void start() = 0;
|
||||
virtual void close() = 0;
|
||||
|
@ -330,7 +329,7 @@ namespace libtorrent {
|
|||
|
||||
protected:
|
||||
|
||||
void fail_impl(error_code const& ec, int code = -1, std::string msg = std::string()
|
||||
void fail_impl(error_code const& ec, std::string msg = std::string()
|
||||
, seconds32 interval = seconds32(0), seconds32 min_interval = seconds32(0));
|
||||
|
||||
std::weak_ptr<request_callback> m_requester;
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace libtorrent {
|
|||
bool on_scrape_response(span<char const> buf);
|
||||
|
||||
// wraps tracker_connection::fail
|
||||
void fail(error_code const& ec, int code = -1
|
||||
void fail(error_code const& ec
|
||||
, char const* msg = ""
|
||||
, seconds32 interval = seconds32(0)
|
||||
, seconds32 min_interval = seconds32(30));
|
||||
|
|
|
@ -312,13 +312,13 @@ namespace libtorrent {
|
|||
|
||||
tracker_error_alert::tracker_error_alert(aux::stack_allocator& alloc
|
||||
, torrent_handle const& h, tcp::endpoint const& ep, int times
|
||||
, int status, string_view u, error_code const& e, string_view m)
|
||||
, 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)
|
||||
, m_msg_idx(alloc.copy_string(m))
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
, status_code(e && e.category() == http_category() ? e.value() : -1)
|
||||
, msg(m)
|
||||
#endif
|
||||
{
|
||||
|
@ -333,8 +333,8 @@ namespace libtorrent {
|
|||
std::string tracker_error_alert::message() const
|
||||
{
|
||||
char ret[400];
|
||||
std::snprintf(ret, sizeof(ret), "%s (%d) %s \"%s\" (%d)"
|
||||
, tracker_alert::message().c_str(), status_code
|
||||
std::snprintf(ret, sizeof(ret), "%s %s \"%s\" (%d)"
|
||||
, tracker_alert::message().c_str()
|
||||
, convert_from_native(error.message()).c_str(), error_message()
|
||||
, times_in_row);
|
||||
return ret;
|
||||
|
|
|
@ -157,7 +157,7 @@ namespace libtorrent {
|
|||
{
|
||||
if (tracker_req().i2pconn->local_endpoint().empty())
|
||||
{
|
||||
fail(errors::no_i2p_endpoint, -1, "Waiting for i2p acceptor from SAM bridge", seconds32(5));
|
||||
fail(errors::no_i2p_endpoint, "Waiting for i2p acceptor from SAM bridge", seconds32(5));
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -193,7 +193,7 @@ namespace libtorrent {
|
|||
|
||||
if (!tracker_req().outgoing_socket)
|
||||
{
|
||||
fail(errors::invalid_listen_socket, -1, "outgoing socket was closed");
|
||||
fail(errors::invalid_listen_socket, "outgoing socket was closed");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -318,13 +318,13 @@ namespace libtorrent {
|
|||
if (parser.status_code() != 200)
|
||||
{
|
||||
fail(error_code(parser.status_code(), http_category())
|
||||
, parser.status_code(), parser.message().c_str());
|
||||
, parser.message().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (ec && ec != boost::asio::error::eof)
|
||||
{
|
||||
fail(ec, parser.status_code());
|
||||
fail(ec);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ namespace libtorrent {
|
|||
|
||||
if (ecode)
|
||||
{
|
||||
fail(ecode, parser.status_code(), resp.failure_reason.c_str()
|
||||
fail(ecode, resp.failure_reason.c_str()
|
||||
, resp.interval, resp.min_interval);
|
||||
close();
|
||||
return;
|
||||
|
|
|
@ -7107,12 +7107,12 @@ namespace {
|
|||
}
|
||||
|
||||
void tracker_logger::tracker_request_error(tracker_request const&
|
||||
, int response_code, error_code const& ec, const std::string& str
|
||||
, error_code const& ec, const std::string& str
|
||||
, seconds32 const retry_interval)
|
||||
{
|
||||
TORRENT_UNUSED(retry_interval);
|
||||
debug_log("*** tracker error: %d: %s %s"
|
||||
, response_code, ec.message().c_str(), str.c_str());
|
||||
debug_log("*** tracker error: %s %s"
|
||||
, ec.message().c_str(), str.c_str());
|
||||
}
|
||||
|
||||
bool tracker_logger::should_log() const
|
||||
|
|
|
@ -10902,7 +10902,7 @@ namespace {
|
|||
}
|
||||
|
||||
void torrent::tracker_request_error(tracker_request const& r
|
||||
, int const response_code, error_code const& ec, std::string const& msg
|
||||
, error_code const& ec, std::string const& msg
|
||||
, seconds32 const retry_interval)
|
||||
{
|
||||
TORRENT_ASSERT(is_single_thread());
|
||||
|
@ -10949,7 +10949,7 @@ namespace {
|
|||
int const tracker_index = int(ae - m_trackers.data());
|
||||
|
||||
// never talk to this tracker again
|
||||
if (response_code == 410) ae->fail_limit = 1;
|
||||
if (ec == error_code(410, http_category())) ae->fail_limit = 1;
|
||||
|
||||
deprioritize_tracker(tracker_index);
|
||||
}
|
||||
|
@ -10957,7 +10957,7 @@ namespace {
|
|||
|| r.triggered_manually)
|
||||
{
|
||||
m_ses.alerts().emplace_alert<tracker_error_alert>(get_handle()
|
||||
, local_endpoint, fails, response_code, r.url, ec, msg);
|
||||
, local_endpoint, fails, r.url, ec, msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -10965,7 +10965,7 @@ namespace {
|
|||
announce_entry* ae = find_tracker(r.url);
|
||||
|
||||
// scrape request
|
||||
if (response_code == 410)
|
||||
if (ec == error_code(410, http_category()))
|
||||
{
|
||||
// never talk to this tracker again
|
||||
if (ae != nullptr) ae->fail_limit = 1;
|
||||
|
|
|
@ -160,19 +160,19 @@ namespace libtorrent {
|
|||
return m_requester.lock();
|
||||
}
|
||||
|
||||
void tracker_connection::fail(error_code const& ec, int code
|
||||
void tracker_connection::fail(error_code const& ec
|
||||
, char const* msg, seconds32 const interval, seconds32 const min_interval)
|
||||
{
|
||||
// we need to post the error to avoid deadlock
|
||||
get_io_service().post(std::bind(&tracker_connection::fail_impl
|
||||
, shared_from_this(), ec, code, std::string(msg), interval, min_interval));
|
||||
, shared_from_this(), ec, std::string(msg), interval, min_interval));
|
||||
}
|
||||
|
||||
void tracker_connection::fail_impl(error_code const& ec, int code
|
||||
void tracker_connection::fail_impl(error_code const& ec
|
||||
, std::string const msg, seconds32 const interval, seconds32 const min_interval)
|
||||
{
|
||||
std::shared_ptr<request_callback> cb = requester();
|
||||
if (cb) cb->tracker_request_error(m_req, code, ec, msg
|
||||
if (cb) cb->tracker_request_error(m_req, ec, msg
|
||||
, interval.count() == 0 ? min_interval : interval);
|
||||
close();
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ namespace libtorrent {
|
|||
// we need to post the error to avoid deadlock
|
||||
if (std::shared_ptr<request_callback> r = c.lock())
|
||||
ios.post(std::bind(&request_callback::tracker_request_error, r, req
|
||||
, -1, error_code(errors::unsupported_url_protocol)
|
||||
, error_code(errors::unsupported_url_protocol)
|
||||
, "", seconds32(0)));
|
||||
}
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ namespace libtorrent {
|
|||
, settings.get_int(settings_pack::tracker_receive_timeout));
|
||||
}
|
||||
|
||||
void udp_tracker_connection::fail(error_code const& ec, int code
|
||||
void udp_tracker_connection::fail(error_code const& ec
|
||||
, char const* msg, seconds32 const interval, seconds32 const min_interval)
|
||||
{
|
||||
// m_target failed. remove it from the endpoint list
|
||||
|
@ -138,7 +138,7 @@ namespace libtorrent {
|
|||
// fail the whole announce
|
||||
if (m_endpoints.empty() || !tracker_req().outgoing_socket)
|
||||
{
|
||||
tracker_connection::fail(ec, code, msg, interval, min_interval);
|
||||
tracker_connection::fail(ec, msg, interval, min_interval);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -424,7 +424,7 @@ namespace libtorrent {
|
|||
|
||||
if (action == action_t::error)
|
||||
{
|
||||
fail(error_code(errors::tracker_failure), -1
|
||||
fail(error_code(errors::tracker_failure)
|
||||
, std::string(buf.data(), buf.size()).c_str());
|
||||
return true;
|
||||
}
|
||||
|
@ -702,7 +702,7 @@ namespace libtorrent {
|
|||
|
||||
if (action == action_t::error)
|
||||
{
|
||||
fail(error_code(errors::tracker_failure), -1
|
||||
fail(error_code(errors::tracker_failure)
|
||||
, std::string(buf.data(), buf.size()).c_str());
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue