From 7a432786e707c7fae0b55e4fb3a3d4c32b21bdc5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 23 Apr 2008 01:54:21 +0000 Subject: [PATCH] added url to tracker alerts. introduced a base class for all tracker alerts --- docs/manual.html | 144 ++++++++++++++----------- docs/manual.rst | 37 +++++-- include/libtorrent/alert_types.hpp | 46 +++++--- include/libtorrent/torrent.hpp | 3 +- include/libtorrent/tracker_manager.hpp | 9 +- src/http_tracker_connection.cpp | 2 +- src/session_impl.cpp | 4 +- src/torrent.cpp | 30 ++---- src/udp_tracker_connection.cpp | 2 +- 9 files changed, 168 insertions(+), 109 deletions(-) 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 @@
  • set_max_uploads() set_max_connections()
  • num_uploads() num_connections()
  • set_max_half_open_connections() max_half_open_connections()
  • -
  • load_asnum_db() load_country_db()
  • +
  • load_asnum_db() load_country_db() int as_for_ip()
  • load_state() state()
  • set_ip_filter()
  • status()
  • @@ -148,67 +148,68 @@
  • file_error_alert
  • tracker_announce_alert
  • tracker_alert
  • -
  • tracker_reply_alert
  • -
  • tracker_warning_alert
  • -
  • scrape_reply_alert
  • -
  • scrape_failed_alert
  • -
  • url_seed_alert
  • -
  • hash_failed_alert
  • -
  • peer_ban_alert
  • -
  • peer_error_alert
  • -
  • invalid_request_alert
  • -
  • torrent_finished_alert
  • -
  • metadata_failed_alert
  • -
  • metadata_received_alert
  • -
  • fastresume_rejected_alert
  • -
  • set_max_uploads() set_max_connections()
  • num_uploads() num_connections()
  • set_max_half_open_connections() max_half_open_connections()
  • -
  • load_asnum_db() load_country_db()
  • +
  • load_asnum_db() load_country_db() int as_for_ip()
  • load_state() state()
  • set_ip_filter()
  • status()
  • @@ -148,67 +148,68 @@
  • file_error_alert
  • tracker_announce_alert
  • tracker_alert
  • -
  • tracker_reply_alert
  • -
  • tracker_warning_alert
  • -
  • scrape_reply_alert
  • -
  • scrape_failed_alert
  • -
  • url_seed_alert
  • -
  • hash_failed_alert
  • -
  • peer_ban_alert
  • -
  • peer_error_alert
  • -
  • invalid_request_alert
  • -
  • torrent_finished_alert
  • -
  • metadata_failed_alert
  • -
  • metadata_received_alert
  • -
  • fastresume_rejected_alert
  • -
  • 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;
    @@ -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_ptr clone() 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: tr
    1000
    acker_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_mana