added support for tracker warnings

This commit is contained in:
Arvid Norberg 2005-08-10 23:32:39 +00:00
parent 0050334bca
commit e514643056
7 changed files with 106 additions and 52 deletions

View File

@ -108,47 +108,48 @@
<li><a class="reference" href="#tracker-announce-alert" id="id88" name="id88">tracker_announce_alert</a></li>
<li><a class="reference" href="#tracker-alert" id="id89" name="id89">tracker_alert</a></li>
<li><a class="reference" href="#tracker-reply-alert" id="id90" name="id90">tracker_reply_alert</a></li>
<li><a class="reference" href="#hash-failed-alert" id="id91" name="id91">hash_failed_alert</a></li>
<li><a class="reference" href="#peer-ban-alert" id="id92" name="id92">peer_ban_alert</a></li>
<li><a class="reference" href="#peer-error-alert" id="id93" name="id93">peer_error_alert</a></li>
<li><a class="reference" href="#invalid-request-alert" id="id94" name="id94">invalid_request_alert</a></li>
<li><a class="reference" href="#torrent-finished-alert" id="id95" name="id95">torrent_finished_alert</a></li>
<li><a class="reference" href="#metadata-received-alert" id="id96" name="id96">metadata_received_alert</a></li>
<li><a class="reference" href="#fastresume-rejected-alert" id="id97" name="id97">fastresume_rejected_alert</a></li>
<li><a class="reference" href="#dispatcher" id="id98" name="id98">dispatcher</a></li>
<li><a class="reference" href="#tracker-warning-alert" id="id91" name="id91">tracker_warning_alert</a></li>
<li><a class="reference" href="#hash-failed-alert" id="id92" name="id92">hash_failed_alert</a></li>
<li><a class="reference" href="#peer-ban-alert" id="id93" name="id93">peer_ban_alert</a></li>
<li><a class="reference" href="#peer-error-alert" id="id94" name="id94">peer_error_alert</a></li>
<li><a class="reference" href="#invalid-request-alert" id="id95" name="id95">invalid_request_alert</a></li>
<li><a class="reference" href="#torrent-finished-alert" id="id96" name="id96">torrent_finished_alert</a></li>
<li><a class="reference" href="#metadata-received-alert" id="id97" name="id97">metadata_received_alert</a></li>
<li><a class="reference" href="#fastresume-rejected-alert" id="id98" name="id98">fastresume_rejected_alert</a></li>
<li><a class="reference" href="#dispatcher" id="id99" name="id99">dispatcher</a></li>
</ul>
</li>
<li><a class="reference" href="#exceptions" id="id99" name="id99">exceptions</a><ul>
<li><a class="reference" href="#invalid-handle" id="id100" name="id100">invalid_handle</a></li>
<li><a class="reference" href="#duplicate-torrent" id="id101" name="id101">duplicate_torrent</a></li>
<li><a class="reference" href="#invalid-encoding" id="id102" name="id102">invalid_encoding</a></li>
<li><a class="reference" href="#type-error" id="id103" name="id103">type_error</a></li>
<li><a class="reference" href="#invalid-torrent-file" id="id104" name="id104">invalid_torrent_file</a></li>
<li><a class="reference" href="#exceptions" id="id100" name="id100">exceptions</a><ul>
<li><a class="reference" href="#invalid-handle" id="id101" name="id101">invalid_handle</a></li>
<li><a class="reference" href="#duplicate-torrent" id="id102" name="id102">duplicate_torrent</a></li>
<li><a class="reference" href="#invalid-encoding" id="id103" name="id103">invalid_encoding</a></li>
<li><a class="reference" href="#type-error" id="id104" name="id104">type_error</a></li>
<li><a class="reference" href="#invalid-torrent-file" id="id105" name="id105">invalid_torrent_file</a></li>
</ul>
</li>
<li><a class="reference" href="#examples" id="id105" name="id105">examples</a><ul>
<li><a class="reference" href="#dump-torrent" id="id106" name="id106">dump_torrent</a></li>
<li><a class="reference" href="#simple-client" id="id107" name="id107">simple client</a></li>
<li><a class="reference" href="#make-torrent" id="id108" name="id108">make_torrent</a></li>
<li><a class="reference" href="#examples" id="id106" name="id106">examples</a><ul>
<li><a class="reference" href="#dump-torrent" id="id107" name="id107">dump_torrent</a></li>
<li><a class="reference" href="#simple-client" id="id108" name="id108">simple client</a></li>
<li><a class="reference" href="#make-torrent" id="id109" name="id109">make_torrent</a></li>
</ul>
</li>
<li><a class="reference" href="#fast-resume" id="id109" name="id109">fast resume</a><ul>
<li><a class="reference" href="#file-format" id="id110" name="id110">file format</a></li>
<li><a class="reference" href="#fast-resume" id="id110" name="id110">fast resume</a><ul>
<li><a class="reference" href="#file-format" id="id111" name="id111">file format</a></li>
</ul>
</li>
<li><a class="reference" href="#threads" id="id111" name="id111">threads</a></li>
<li><a class="reference" href="#storage-allocation" id="id112" name="id112">storage allocation</a><ul>
<li><a class="reference" href="#full-allocation" id="id113" name="id113">full allocation</a></li>
<li><a class="reference" href="#compact-allocation" id="id114" name="id114">compact allocation</a></li>
<li><a class="reference" href="#threads" id="id112" name="id112">threads</a></li>
<li><a class="reference" href="#storage-allocation" id="id113" name="id113">storage allocation</a><ul>
<li><a class="reference" href="#full-allocation" id="id114" name="id114">full allocation</a></li>
<li><a class="reference" href="#compact-allocation" id="id115" name="id115">compact allocation</a></li>
</ul>
</li>
<li><a class="reference" href="#extensions" id="id115" name="id115">extensions</a><ul>
<li><a class="reference" href="#chat-messages" id="id116" name="id116">chat messages</a></li>
<li><a class="reference" href="#metadata-from-peers" id="id117" name="id117">metadata from peers</a></li>
<li><a class="reference" href="#extensions" id="id116" name="id116">extensions</a><ul>
<li><a class="reference" href="#chat-messages" id="id117" name="id117">chat messages</a></li>
<li><a class="reference" href="#metadata-from-peers" id="id118" name="id118">metadata from peers</a></li>
</ul>
</li>
<li><a class="reference" href="#filename-checks" id="id118" name="id118">filename checks</a></li>
<li><a class="reference" href="#acknowledgements" id="id119" name="id119">acknowledgements</a></li>
<li><a class="reference" href="#filename-checks" id="id119" name="id119">filename checks</a></li>
<li><a class="reference" href="#acknowledgements" id="id120" name="id120">acknowledgements</a></li>
</ul>
</div>
<div class="section" id="introduction">
@ -1993,7 +1994,6 @@ struct file_error_alert: alert
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
};
</pre>
@ -2010,7 +2010,6 @@ struct tracker_announce_alert: alert
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
};
</pre>
@ -2052,6 +2051,23 @@ struct tracker_reply_alert: alert
};
</pre>
</div>
<div class="section" id="tracker-warning-alert">
<h2><a name="tracker-warning-alert">tracker_warning_alert</a></h2>
<p>This alert is triggered if the tracker reply contains a warning field. Usually this
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 <tt class="docutils literal"><span class="pre">warning</span></tt>.</p>
<pre class="literal-block">
struct tracker_warning_alert: alert
{
tracker_warning_alert(torrent_handle const&amp; h
, std::string const&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
};
</pre>
</div>
<div class="section" id="hash-failed-alert">
<h2><a name="hash-failed-alert">hash_failed_alert</a></h2>
<p>This alert is generated when a finished piece fails its hash check. You can get the handle
@ -2066,7 +2082,6 @@ struct hash_failed_alert: alert
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
int piece_index;
};
@ -2086,7 +2101,6 @@ struct peer_ban_alert: alert
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
address ip;
torrent_handle handle;
};
@ -2106,7 +2120,6 @@ struct peer_error_alert: alert
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
address ip;
peer_id id;
};
@ -2129,7 +2142,6 @@ struct invalid_request_alert: alert
, std::string const&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
address ip;
peer_request request;
@ -2162,7 +2174,6 @@ struct torrent_finished_alert: alert
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
};
</pre>
@ -2181,7 +2192,6 @@ struct metadata_received_alert: alert
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
};
</pre>
@ -2198,7 +2208,6 @@ struct fastresume_rejected_alert: alert
, std::string const&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
};
</pre>

View File

@ -1995,7 +1995,6 @@ generated and the torrent is paused. It is generated as severity level ``fatal``
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
};
@ -2015,7 +2014,6 @@ It is generated at severity level ``info``.
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
};
@ -2063,7 +2061,27 @@ succeeds. It is generated with severity level ``info``.
torrent_handle handle;
};
tracker_warning_alert
---------------------
This alert is triggered if the tracker reply contains a warning field. Usually this
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: alert
{
tracker_warning_alert(torrent_handle const& h
, std::string const& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
};
hash_failed_alert
-----------------
@ -2081,7 +2099,6 @@ This alert is generated as severity level ``info``.
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
int piece_index;
};
@ -2104,7 +2121,6 @@ to the torrent that this peer was a member of.
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
address ip;
torrent_handle handle;
};
@ -2127,7 +2143,6 @@ is generated as severity level ``debug``.
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
address ip;
peer_id id;
};
@ -2153,7 +2168,6 @@ is a handle to the torrent the peer is a member of. ``
, std::string const& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
address ip;
peer_request request;
@ -2190,7 +2204,6 @@ torrent in question. This alert is generated as severity level ``info``.
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
};
@ -2211,7 +2224,6 @@ It is generated at severity level ``info``.
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
};
@ -2231,7 +2243,6 @@ resume file was rejected. It is generated at severity level ``warning``.
, std::string const& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
};

View File

@ -50,7 +50,7 @@ namespace libtorrent
, handle(h)
, times_in_row(times)
, status_code(status)
{}
{}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_alert(*this)); }
@ -60,13 +60,29 @@ namespace libtorrent
int status_code;
};
struct tracker_warning_alert: alert
{
tracker_warning_alert(torrent_handle const& h
, std::string const& msg)
: alert(alert::warning, msg)
, handle(h)
{}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_warning_alert(*this)); }
torrent_handle handle;
};
struct tracker_reply_alert: alert
{
tracker_reply_alert(torrent_handle const& h
, std::string const& msg)
: alert(alert::info, msg)
, handle(h)
{}
{}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_reply_alert(*this)); }
@ -79,7 +95,7 @@ namespace libtorrent
tracker_announce_alert(torrent_handle const& h, std::string const& msg)
: alert(alert::info, msg)
, handle(h)
{}
{}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_announce_alert(*this)); }
@ -96,7 +112,7 @@ namespace libtorrent
: alert(alert::info, msg)
, handle(h)
, piece_index(index)
{ assert(index >= 0);}
{ assert(index >= 0);}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new hash_failed_alert(*this)); }
@ -239,7 +255,7 @@ namespace libtorrent
, std::string const& msg)
: alert(alert::warning, msg)
, handle(h)
{}
{}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new fastresume_rejected_alert(*this)); }

View File

@ -222,6 +222,7 @@ 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);
// generates a request string for sending
// to the tracker

View File

@ -110,6 +110,7 @@ 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_response(
tracker_request const&
, std::vector<peer_entry>& peers

View File

@ -608,6 +608,14 @@ namespace libtorrent
}
catch (type_error const&) {}
try
{
entry const& warning = e["warning message"];
if (has_requester())
requester().tracker_warning(warning.string());
}
catch(type_error const&) {}
std::vector<peer_entry> peer_list;
if (m_req.kind == tracker_request::scrape_request)

View File

@ -291,6 +291,14 @@ namespace libtorrent
m_next_request < second_clock::universal_time();
}
void torrent::tracker_warning(std::string const& msg)
{
if (m_ses.m_alerts.should_post(alert::warning))
{
m_ses.m_alerts.post_alert(tracker_warning_alert(get_handle(), msg));
}
}
void torrent::tracker_response(
tracker_request const&
, std::vector<peer_entry>& peer_list