diff --git a/docs/manual.html b/docs/manual.html index 9e3db057e..d0f50de2d 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -37,7 +37,7 @@
max_half_open_connections() returns the set limit. This limit defaults to 8 on windows.
bool load_asnum_db(char const* file); bool load_country_db(char const* file); +int as_for_ip(address const& adr);
These functions are not available if TORRENT_DISABLE_GEO_IP is defined. They expects a path to the MaxMind ASN database and MaxMind GeoIP database respectively. This will be used to look up which AS and country peers belong to.
+as_for_ip returns the AS number for the IP address specified. If the IP is not +in the database or the ASN database is not loaded, 0 is returned.
This is a base class for all alerts related to trackers.
++struct tracker_alert: torrent_alert +{ + tracker_alert(torrent_handle const& h + , std::string const& url + , alert::severity_t s + , std::string const& msg); + + std::string url; +}; ++
This alert is generated on tracker time outs, premature disconnects, invalid response or a HTTP response other than "200 OK". From the alert you can get the handle to the torrent the tracker belongs to. This alert is generated as severity level warning.
@@ -3633,10 +3653,10 @@ the tracker belongs to. This alert is generated as severity level -struct tracker_alert: torrent_alert +struct tracker_error_alert: tracker_alert { - tracker_alert(torrent_handle const& h, int times, int status - , const std::string& msg); + tracker_error_alert(torrent_handle const& h, int times, int status + , std::string const& url, std::string const& msg); virtual std::auto_ptr<alert> clone() const; int times_in_row; @@ -3650,11 +3670,12 @@ struct tracker_alert: torrent_alert succeeds. It is generated regardless what kind of tracker was used, be it UDP, HTTP or the DHT. It is generated with severity level info.-struct tracker_reply_alert: torrent_alert +struct tracker_reply_alert: tracker_alert { tracker_reply_alert(const torrent_handle& h , int num_peers - , const std::string& msg); + . std::string const& url + , std::string const& msg); int num_peers; @@ -3671,9 +3692,10 @@ means that the tracker announce was successful, but the tracker has a message to the client. The message string in the alert will contain the warning message from the tracker. It is generated with severity level warning.-struct tracker_warning_alert: torrent_alert +struct tracker_warning_alert: tracker_alert { tracker_warning_alert(torrent_handle const& h + , std::string const& url , std::string const& msg); virtual std::auto_ptr<alert> clone() const; @@ -3683,11 +3705,12 @@ struct tracker_warning_alert: torrent_alertscrape_reply_alert
-struct scrape_reply_alert: torrent_alert +struct scrape_reply_alert: tracker_alert { scrape_reply_alert(torrent_handle const& h , int incomplete_ , int complete_ + , std::string const& url , std::string const& msg); int incomplete; @@ -3703,9 +3726,10 @@ may be -1 if the reponse was malformed.scrape_failed_alert
-struct scrape_failed_alert: torrent_alert +struct scrape_failed_alert: tracker_alert { scrape_failed_alert(torrent_handle const& h + , std::string const& url , std::string const& msg); virtual std::auto_ptr<alert> clone() const; diff --git a/docs/manual.rst b/docs/manual.rst index 0006e8445..b115eded0 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3740,6 +3740,23 @@ It is generated at severity level ``info``. tracker_alert ------------- +This is a base class for all alerts related to trackers. + +:: + + struct tracker_alert: torrent_alert + { + tracker_alert(torrent_handle const& h + , std::string const& url + , alert::severity_t s + , std::string const& msg); + + std::string url; + }; + +tracker_error_alert +------------------- + This alert is generated on tracker time outs, premature disconnects, invalid response or a HTTP response other than "200 OK". From the alert you can get the handle to the torrent the tracker belongs to. This alert is generated as severity level ``warning``. @@ -3751,10 +3768,10 @@ to 0. :: - struct tracker_alert: torrent_alert + struct tracker_error_alert: tracker_alert { - tracker_alert(torrent_handle const& h, int times, int status - , const std::string& msg); + tracker_error_alert(torrent_handle const& h, int times, int status + , std::string const& url, std::string const& msg); virtual std::auto_ptrclone() const; int times_in_row; @@ -3771,11 +3788,12 @@ the DHT. It is generated with severity level ``info``. :: - struct tracker_reply_alert: torrent_alert + struct tracker_reply_alert: tracker_alert { tracker_reply_alert(const torrent_handle& h , int num_peers - , const std::string& msg); + . std::string const& url + , std::string const& msg); int num_peers; @@ -3795,9 +3813,10 @@ the tracker. It is generated with severity level ``warning``. :: - struct tracker_warning_alert: torrent_alert + struct tracker_warning_alert: tracker_alert { tracker_warning_alert(torrent_handle const& h + , std::string const& url , std::string const& msg); virtual std::auto_ptr clone() const; @@ -3808,11 +3827,12 @@ scrape_reply_alert :: - struct scrape_reply_alert: torrent_alert + struct scrape_reply_alert: tracker_alert { scrape_reply_alert(torrent_handle const& h , int incomplete_ , int complete_ + , std::string const& url , std::string const& msg); int incomplete; @@ -3830,9 +3850,10 @@ scrape_failed_alert :: - struct scrape_failed_alert: torrent_alert + struct scrape_failed_alert: tracker_alert { scrape_failed_alert(torrent_handle const& h + , std::string const& url , std::string const& msg); virtual std::auto_ptr clone() const; diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 1dc843ede..4d82641a6 100755 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -56,39 +56,55 @@ namespace libtorrent struct TORRENT_EXPORT tracker_alert: torrent_alert { tracker_alert(torrent_handle const& h + , std::string const& url_ + , alert::severity_t s + , std::string const& msg) + : torrent_alert(h, s, msg) + , url(url_) + {} + + std::string url; + }; + + struct TORRENT_EXPORT tracker_error_alert: tracker_alert + { + tracker_error_alert(torrent_handle const& h , int times , int status + , std::string const& url , std::string const& msg) - : torrent_alert(h, alert::warning, msg) + : tracker_alert(h, url, alert::warning, msg) , times_in_row(times) , status_code(status) {} virtual std::auto_ptr clone() const - { return std::auto_ptr (new tracker_alert(*this)); } + { return std::auto_ptr (new tracker_error_alert(*this)); } int times_in_row; int status_code; }; - struct TORRENT_EXPORT tracker_warning_alert: torrent_alert + struct TORRENT_EXPORT tracker_warning_alert: tracker_alert { tracker_warning_alert(torrent_handle const& h + , std::string const& url , std::string const& msg) - : torrent_alert(h, alert::warning, msg) + : tracker_alert(h, url, alert::warning, msg) {} virtual std::auto_ptr clone() const { return std::auto_ptr (new tracker_warning_alert(*this)); } }; - struct TORRENT_EXPORT scrape_reply_alert: torrent_alert + struct TORRENT_EXPORT scrape_reply_alert: tracker_alert { scrape_reply_alert(torrent_handle const& h , int incomplete_ , int complete_ + , std::string const& url , std::string const& msg) - : torrent_alert(h, alert::info, msg) + : tracker_alert(h, url, alert::info, msg) , incomplete(incomplete_) , complete(complete_) {} @@ -100,23 +116,25 @@ namespace libtorrent { return std::auto_ptr (new scrape_reply_alert(*this)); } }; - struct TORRENT_EXPORT scrape_failed_alert: torrent_alert + struct TORRENT_EXPORT scrape_failed_alert: tracker_alert { scrape_failed_alert(torrent_handle const& h + , std::string const& url , std::string const& msg) - : torrent_alert(h, alert::warning, msg) + : tracker_alert(h, url, alert::warning, msg) {} virtual std::auto_ptr clone() const { return std::auto_ptr (new scrape_failed_alert(*this)); } }; - struct TORRENT_EXPORT tracker_reply_alert: torrent_alert + struct TORRENT_EXPORT tracker_reply_alert: tracker_alert { tracker_reply_alert(torrent_handle const& h , int np + , std::string const& url , std::string const& msg) - : torrent_alert(h, alert::info, msg) + : tracker_alert(h, url, alert::info, msg) , num_peers(np) {} @@ -126,10 +144,12 @@ namespace libtorrent { return std::auto_ptr (new tracker_reply_alert(*this)); } }; - struct TORRENT_EXPORT tracker_announce_alert: torrent_alert + struct TORRENT_EXPORT tracker_announce_alert: tracker_alert { - tracker_announce_alert(torrent_handle const& h, std::string const& msg) - : torrent_alert(h, alert::info, msg) + tracker_announce_alert(torrent_handle const& h + , std::string const& url + , std::string const& msg) + : tracker_alert(h, url, alert::info, msg) {} virtual std::auto_ptr clone() const diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 801d99598..a34d34347 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -318,7 +318,8 @@ namespace libtorrent tracker_request const& r); virtual void tracker_request_error(tracker_request const& r , int response_code, const std::string& str); - virtual void tracker_warning(std::string const& msg); + virtual void tracker_warning(tracker_request const& req + , std::string const& msg); virtual void tracker_scrape_response(tracker_request const& req , int complete, int incomplete, int downloaded); diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 580e6d5eb..2d8df1a36 100755 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -118,20 +118,21 @@ namespace libtorrent friend class tracker_manager; request_callback(): m_manager(0) {} virtual ~request_callback() {} - virtual void tracker_warning(std::string const& msg) = 0; + virtual void tracker_warning(tracker_request const& req + , std::string const& msg) = 0; virtual void tracker_scrape_response(tracker_request const& req , int complete, int incomplete, int downloads) {} virtual void tracker_response( - tracker_request const& + tracker_request const& req , std::vector & peers , int interval , int complete , int incomplete , address const& external_ip) = 0; virtual void tracker_request_timed_out( - tracker_request const&) = 0; + tracker_request const& req) = 0; virtual void tracker_request_error( - tracker_request const& + tracker_request const& req , int response_code , const std::string& description) = 0; diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index 3adad2ca1..ea4f0fda0 100755 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -306,7 +306,7 @@ namespace libtorrent entry const* warning = e.find_key("warning message"); if (warning && warning->type() == entry::string_t) { - cb->tracker_warning(warning->string()); + cb->tracker_warning(tracker_req(), warning->string()); } std::vector peer_list; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index e8b34c9bb..3bfcf0adc 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1035,7 +1035,7 @@ namespace aux { { m_alerts.post_alert( tracker_announce_alert( - t.get_handle(), "tracker announce")); + t.get_handle(), req.url, "tracker announce")); } } @@ -1672,7 +1672,7 @@ namespace aux { { m_alerts.post_alert( tracker_announce_alert( - t.get_handle(), "tracker announce, event=stopped")); + t.get_handle(), req.url, "tracker announce, event=stopped")); } } #ifndef NDEBUG diff --git a/src/torrent.cpp b/src/torrent.cpp index 48a466a9c..e2ac69409 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -727,7 +727,7 @@ namespace libtorrent if (m_ses.m_alerts.should_post(alert::info)) { m_ses.m_alerts.post_alert(tracker_reply_alert( - get_handle(), peers.size(), "Got peers from DHT")); + get_handle(), peers.size(), "DHT", "Got peers from DHT")); } std::for_each(peers.begin(), peers.end(), bind( &policy::peer_from_tracker, boost::ref(m_policy), _1, peer_id(0) @@ -767,7 +767,7 @@ namespace libtorrent return !m_paused && m_next_request < time_now(); } - void torrent::tracker_warning(std::string const& msg) + void torrent::tracker_warning(tracker_request const& req, std::string const& msg) { session_impl::mutex_t::scoped_lock l(m_ses.m_mutex); @@ -775,7 +775,7 @@ namespace libtorrent if (m_ses.m_alerts.should_post(alert::warning)) { - m_ses.m_alerts.post_alert(tracker_warning_alert(get_handle(), msg)); + m_ses.m_alerts.post_alert(tracker_warning_alert(get_handle(), req.url, msg)); } } @@ -792,10 +792,8 @@ namespace libtorrent if (m_ses.m_alerts.should_post(alert::info)) { - std::stringstream s; - s << "Got scrape response from tracker: " << req.url; m_ses.m_alerts.post_alert(scrape_reply_alert( - get_handle(), m_incomplete, m_complete, s.str())); + get_handle(), m_incomplete, m_complete, req.url, "got scrape response from tracker")); } } @@ -891,10 +889,8 @@ namespace libtorrent if (m_ses.m_alerts.should_post(alert::info)) { - std::stringstream s; - s << "Got response from tracker: " << r.url; m_ses.m_alerts.post_alert(tracker_reply_alert( - get_handle(), peer_list.size(), s.str())); + get_handle(), peer_list.size(), r.url, "got response from tracker")); } m_got_tracker_response = true; } @@ -3740,16 +3736,14 @@ namespace libtorrent if (m_ses.m_alerts.should_post(alert::warning)) { - std::stringstream s; - s << "tracker: \"" << r.url << "\" timed out"; if (r.kind == tracker_request::announce_request) { - m_ses.m_alerts.post_alert(tracker_alert(get_handle() - , m_failed_trackers + 1, 0, s.str())); + m_ses.m_alerts.post_alert(tracker_error_alert(get_handle() + , m_failed_trackers + 1, 0, r.url, "tracker timed out")); } else if (r.kind == tracker_request::scrape_request) { - m_ses.m_alerts.post_alert(scrape_failed_alert(get_handle(), s.str())); + m_ses.m_alerts.post_alert(scrape_failed_alert(get_handle(), r.url, "tracker timed out")); } } @@ -3772,16 +3766,14 @@ namespace libtorrent #endif if (m_ses.m_alerts.should_post(alert::warning)) { - std::stringstream s; - s << "tracker: \"" << r.url << "\" " << str; if (r.kind == tracker_request::announce_request) { - m_ses.m_alerts.post_alert(tracker_alert(get_handle() - , m_failed_trackers + 1, response_code, s.str())); + m_ses.m_alerts.post_alert(tracker_error_alert(get_handle() + , m_failed_trackers + 1, response_code, r.url, str)); } else if (r.kind == tracker_request::scrape_request) { - m_ses.m_alerts.post_alert(scrape_failed_alert(get_handle(), s.str())); + m_ses.m_alerts.post_alert(scrape_failed_alert(get_handle(), r.url, str)); } } diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index a6320786f..1eda73841 100755 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -144,7 +144,7 @@ namespace libtorrent { std::string tracker_address_type = target_address.address().is_v4() ? "IPv4" : "IPv6"; std::string bind_address_type = bind_interface().is_v4() ? "IPv4" : "IPv6"; - cb->tracker_warning("the tracker only resolves to an " + cb->tracker_warning(tracker_req(), "the tracker only resolves to an " + tracker_address_type + " address, and you're listening on an " + bind_address_type + " socket. This may prevent you from receiving incoming connections."); }