made a common base class for torrent alerts. Made the bandwidth quota block size variable depending on the limit

This commit is contained in:
Arvid Norberg 2007-01-16 05:05:52 +00:00
parent 977ab61140
commit 69ef67d71e
8 changed files with 138 additions and 242 deletions

View File

@ -1921,8 +1921,8 @@ in the torrent. Each boolean tells you if the peer has that piece (if it's set t
or if the peer miss that piece (set to false).</p> or if the peer miss that piece (set to false).</p>
<p><tt class="docutils literal"><span class="pre">seed</span></tt> is true if this peer is a seed.</p> <p><tt class="docutils literal"><span class="pre">seed</span></tt> is true if this peer is a seed.</p>
<p><tt class="docutils literal"><span class="pre">upload_limit</span></tt> is the number of bytes per second we are allowed to send to this <p><tt class="docutils literal"><span class="pre">upload_limit</span></tt> is the number of bytes per second we are allowed to send to this
peer every second. It may be -1 if there's no limit. The upload limits of all peers peer every second. It may be -1 if there's no local limit on the peer. The global
should sum up to the upload limit set by <tt class="docutils literal"><span class="pre">session::set_upload_limit</span></tt>.</p> limit and the torrent limit is always enforced anyway.</p>
<p><tt class="docutils literal"><span class="pre">download_limit</span></tt> is the number of bytes per second this peer is allowed to <p><tt class="docutils literal"><span class="pre">download_limit</span></tt> is the number of bytes per second this peer is allowed to
receive. -1 means it's unlimited.</p> receive. -1 means it's unlimited.</p>
<p><tt class="docutils literal"><span class="pre">load_balancing</span></tt> is a measurement of the balancing of free download (that we get) <p><tt class="docutils literal"><span class="pre">load_balancing</span></tt> is a measurement of the balancing of free download (that we get)
@ -2390,7 +2390,7 @@ public:
enum severity_t { debug, info, warning, critical, fatal, none }; enum severity_t { debug, info, warning, critical, fatal, none };
alert(severity_t severity, const std::string&amp; msg); alert(severity_t severity, std::string const&amp; msg);
virtual ~alert(); virtual ~alert();
std::string const&amp; msg() const; std::string const&amp; msg() const;
@ -2402,6 +2402,16 @@ public:
<p>This means that all alerts have at least a string describing it. They also <p>This means that all alerts have at least a string describing it. They also
have a severity level that can be used to sort them or present them to the have a severity level that can be used to sort them or present them to the
user in different ways.</p> user in different ways.</p>
<p>There's another alert base class that all most alerts derives from, all the
alerts that are generated for a specific torrent are derived from:</p>
<pre class="literal-block">
struct torrent_alert: alert
{
torrent_alert(torrent_handle const&amp; h, severity_t s, std::string const&amp; msg);
torrent_handle handle;
};
</pre>
<p>The specific alerts, that all derives from <tt class="docutils literal"><span class="pre">alert</span></tt>, are:</p> <p>The specific alerts, that all derives from <tt class="docutils literal"><span class="pre">alert</span></tt>, are:</p>
<div class="section"> <div class="section">
<h2><a id="listen-failed-alert" name="listen-failed-alert">listen_failed_alert</a></h2> <h2><a id="listen-failed-alert" name="listen-failed-alert">listen_failed_alert</a></h2>
@ -2421,14 +2431,13 @@ struct listen_failed_alert: alert
<p>If the storage fails to read or write files that it needs access to, this alert is <p>If the storage fails to read or write files that it needs access to, this alert is
generated and the torrent is paused. It is generated as severity level <tt class="docutils literal"><span class="pre">fatal</span></tt>.</p> generated and the torrent is paused. It is generated as severity level <tt class="docutils literal"><span class="pre">fatal</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct file_error_alert: alert struct file_error_alert: torrent_alert
{ {
file_error_alert( file_error_alert(
const torrent_handle&amp; h const torrent_handle&amp; h
, const std::string&amp; msg); , const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2437,14 +2446,13 @@ struct file_error_alert: alert
<p>This alert is generated each time a tracker announce is sent (or attempted to be sent). <p>This alert is generated each time a tracker announce is sent (or attempted to be sent).
It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p> It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct tracker_announce_alert: alert struct tracker_announce_alert: torrent_alert
{ {
tracker_announce_alert( tracker_announce_alert(
const torrent_handle&amp; h const torrent_handle&amp; h
, const std::string&amp; msg); , const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2458,13 +2466,12 @@ the tracker belongs to. This alert is generated as severity level <tt class="doc
authentication, 404 means not found etc. If the tracker timed out, the code will be set authentication, 404 means not found etc. If the tracker timed out, the code will be set
to 0.</p> to 0.</p>
<pre class="literal-block"> <pre class="literal-block">
struct tracker_alert: alert struct tracker_alert: torrent_alert
{ {
tracker_alert(const torrent_handle&amp; h, int times, int status tracker_alert(torrent_handle const&amp; h, int times, int status
, const std::string&amp; msg); , const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
int times_in_row; int times_in_row;
int status_code; int status_code;
}; };
@ -2475,13 +2482,12 @@ struct tracker_alert: alert
<p>This alert is only for informational purpose. It is generated when a tracker announce <p>This alert is only for informational purpose. It is generated when a tracker announce
succeeds. It is generated with severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p> succeeds. It is generated with severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct tracker_reply_alert: alert struct tracker_reply_alert: torrent_alert
{ {
tracker_reply_alert(const torrent_handle&amp; h tracker_reply_alert(const torrent_handle&amp; h
, const std::string&amp; msg); , const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2492,13 +2498,12 @@ 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 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> the tracker. It is generated with severity level <tt class="docutils literal"><span class="pre">warning</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct tracker_warning_alert: alert struct tracker_warning_alert: torrent_alert
{ {
tracker_warning_alert(torrent_handle const&amp; h tracker_warning_alert(torrent_handle const&amp; h
, std::string const&amp; msg); , std::string const&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2508,9 +2513,10 @@ struct tracker_warning_alert: alert
generated as severity level <tt class="docutils literal"><span class="pre">warning</span></tt>.</p> generated as severity level <tt class="docutils literal"><span class="pre">warning</span></tt>.</p>
<p>It contains <tt class="docutils literal"><span class="pre">url</span></tt> to the HTTP seed that failed along with an error message.</p> <p>It contains <tt class="docutils literal"><span class="pre">url</span></tt> to the HTTP seed that failed along with an error message.</p>
<pre class="literal-block"> <pre class="literal-block">
struct url_seed_alert: alert struct url_seed_alert: torrent_alert
{ {
url_seed_alert(std::string const&amp; h, const std::string&amp; msg); url_seed_alert(torrent_handle const&amp; h, std::string const&amp; h
, const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
std::string url; std::string url;
@ -2523,15 +2529,15 @@ struct url_seed_alert: alert
to the torrent which got the failed piece and the index of the piece itself from the alert. to the torrent which got the failed piece and the index of the piece itself from the alert.
This alert is generated as severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p> This alert is generated as severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct hash_failed_alert: alert struct hash_failed_alert: torrent_alert
{ {
hash_failed_alert( hash_failed_alert(
const torrent_handle&amp; h torrent_handle const&amp; h
, int index , int index
, const std::string&amp; msg); , const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
int piece_index; int piece_index;
}; };
</pre> </pre>
@ -2542,7 +2548,7 @@ struct hash_failed_alert: alert
to us. It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>. The <tt class="docutils literal"><span class="pre">handle</span></tt> member is a <a class="reference" href="#torrent-handle">torrent_handle</a> to us. It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>. The <tt class="docutils literal"><span class="pre">handle</span></tt> member is a <a class="reference" href="#torrent-handle">torrent_handle</a>
to the torrent that this peer was a member of.</p> to the torrent that this peer was a member of.</p>
<pre class="literal-block"> <pre class="literal-block">
struct peer_ban_alert: alert struct peer_ban_alert: torrent_alert
{ {
peer_ban_alert( peer_ban_alert(
asio::ip::tcp::endpoint const&amp; pip asio::ip::tcp::endpoint const&amp; pip
@ -2550,8 +2556,8 @@ struct peer_ban_alert: alert
, const std::string&amp; msg); , const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
asio::ip::tcp::endpoint ip; asio::ip::tcp::endpoint ip;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2581,7 +2587,7 @@ is a handle to the torrent the peer is a member of. <tt class="docutils literal"
<tt class="docutils literal"><span class="pre">request</span></tt> is the actual incoming request from the peer. The alert is generated as severity level <tt class="docutils literal"><span class="pre">request</span></tt> is the actual incoming request from the peer. The alert is generated as severity level
<tt class="docutils literal"><span class="pre">debug</span></tt>.</p> <tt class="docutils literal"><span class="pre">debug</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct invalid_request_alert: alert struct invalid_request_alert: torrent_alert
{ {
invalid_request_alert( invalid_request_alert(
peer_request const&amp; r peer_request const&amp; r
@ -2591,7 +2597,7 @@ struct invalid_request_alert: alert
, std::string const&amp; msg); , std::string const&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
asio::ip::tcp::endpoint ip; asio::ip::tcp::endpoint ip;
peer_request request; peer_request request;
peer_id id; peer_id id;
@ -2616,14 +2622,13 @@ should be read, and <tt class="docutils literal"><span class="pre">length</span>
It will only be generated once per torrent. It contains a torrent_handle to the It will only be generated once per torrent. It contains a torrent_handle to the
torrent in question. This alert is generated as severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p> torrent in question. This alert is generated as severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct torrent_finished_alert: alert struct torrent_finished_alert:torrent_ alert
{ {
torrent_finished_alert( torrent_finished_alert(
const torrent_handle&amp; h const torrent_handle&amp; h
, const std::string&amp; msg); , const std::string&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2635,14 +2640,13 @@ automatically retry to fetch it in this case. This is only relevant when running
torrent-less download, with the metadata extension provided by libtorrent. torrent-less download, with the metadata extension provided by libtorrent.
It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p> It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct metadata_failed_alert: alert struct metadata_failed_alert: torrent_alert
{ {
metadata_failed_alert( metadata_failed_alert(
const torrent_handle&amp; h torrent_handle const&amp; h
, const std::string&amp; msg); , std::string const&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2653,14 +2657,13 @@ can start downloading. It is not generated on torrents that are started with met
only those that needs to download it from peers (when utilizing the libtorrent extension). only those that needs to download it from peers (when utilizing the libtorrent extension).
It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p> It is generated at severity level <tt class="docutils literal"><span class="pre">info</span></tt>.</p>
<pre class="literal-block"> <pre class="literal-block">
struct metadata_received_alert: alert struct metadata_received_alert: torrent_alert
{ {
metadata_received_alert( metadata_received_alert(
const torrent_handle&amp; h torrent_handle const_&amp; h
, const std::string&amp; msg); , std::string const&amp; msg);
virtual std::auto_ptr&lt;alert&gt; clone() const; virtual std::auto_ptr&lt;alert&gt; clone() const;
torrent_handle handle;
}; };
</pre> </pre>
</div> </div>
@ -2679,29 +2682,6 @@ struct fastresume_rejected_alert: alert
torrent_handle handle; torrent_handle handle;
}; };
</pre> </pre>
<!-- chat_message_alert
- - - - - - - - - - - - - - - - - -
This alert is generated when you receive a chat message from another peer. Chat messages
are supported as an extension ("chat"). It is generated as severity level ``critical``,
even though it doesn't necessarily require any user intervention, it's high priority
since you would almost never want to ignore such a message. The alert class contain
a torrent_handle_ to the torrent in which the sender-peer is a member and the ip
of the sending peer.
::
struct chat_message_alert: alert
{
chat_message_alert(const torrent_handle& h
, const address& sender
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
address ip;
}; -->
</div> </div>
<div class="section"> <div class="section">
<h2><a id="dispatcher" name="dispatcher">dispatcher</a></h2> <h2><a id="dispatcher" name="dispatcher">dispatcher</a></h2>

View File

@ -1900,8 +1900,8 @@ or if the peer miss that piece (set to false).
``seed`` is true if this peer is a seed. ``seed`` is true if this peer is a seed.
``upload_limit`` is the number of bytes per second we are allowed to send to this ``upload_limit`` is the number of bytes per second we are allowed to send to this
peer every second. It may be -1 if there's no limit. The upload limits of all peers peer every second. It may be -1 if there's no local limit on the peer. The global
should sum up to the upload limit set by ``session::set_upload_limit``. limit and the torrent limit is always enforced anyway.
``download_limit`` is the number of bytes per second this peer is allowed to ``download_limit`` is the number of bytes per second this peer is allowed to
receive. -1 means it's unlimited. receive. -1 means it's unlimited.
@ -2424,7 +2424,7 @@ is its synopsis::
enum severity_t { debug, info, warning, critical, fatal, none }; enum severity_t { debug, info, warning, critical, fatal, none };
alert(severity_t severity, const std::string& msg); alert(severity_t severity, std::string const& msg);
virtual ~alert(); virtual ~alert();
std::string const& msg() const; std::string const& msg() const;
@ -2437,6 +2437,16 @@ This means that all alerts have at least a string describing it. They also
have a severity level that can be used to sort them or present them to the have a severity level that can be used to sort them or present them to the
user in different ways. user in different ways.
There's another alert base class that all most alerts derives from, all the
alerts that are generated for a specific torrent are derived from::
struct torrent_alert: alert
{
torrent_alert(torrent_handle const& h, severity_t s, std::string const& msg);
torrent_handle handle;
};
The specific alerts, that all derives from ``alert``, are: The specific alerts, that all derives from ``alert``, are:
@ -2464,14 +2474,13 @@ generated and the torrent is paused. It is generated as severity level ``fatal``
:: ::
struct file_error_alert: alert struct file_error_alert: torrent_alert
{ {
file_error_alert( file_error_alert(
const torrent_handle& h const torrent_handle& h
, const std::string& msg); , const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
}; };
@ -2483,14 +2492,13 @@ It is generated at severity level ``info``.
:: ::
struct tracker_announce_alert: alert struct tracker_announce_alert: torrent_alert
{ {
tracker_announce_alert( tracker_announce_alert(
const torrent_handle& h const torrent_handle& h
, const std::string& msg); , const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
}; };
@ -2508,13 +2516,12 @@ to 0.
:: ::
struct tracker_alert: alert struct tracker_alert: torrent_alert
{ {
tracker_alert(const torrent_handle& h, int times, int status tracker_alert(torrent_handle const& h, int times, int status
, const std::string& msg); , const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
int times_in_row; int times_in_row;
int status_code; int status_code;
}; };
@ -2528,13 +2535,12 @@ succeeds. It is generated with severity level ``info``.
:: ::
struct tracker_reply_alert: alert struct tracker_reply_alert: torrent_alert
{ {
tracker_reply_alert(const torrent_handle& h tracker_reply_alert(const torrent_handle& h
, const std::string& msg); , const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
}; };
tracker_warning_alert tracker_warning_alert
@ -2547,13 +2553,12 @@ the tracker. It is generated with severity level ``warning``.
:: ::
struct tracker_warning_alert: alert struct tracker_warning_alert: torrent_alert
{ {
tracker_warning_alert(torrent_handle const& h tracker_warning_alert(torrent_handle const& h
, std::string const& msg); , std::string const& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
}; };
@ -2567,15 +2572,15 @@ It contains ``url`` to the HTTP seed that failed along with an error message.
:: ::
struct url_seed_alert: alert struct url_seed_alert: torrent_alert
{ {
url_seed_alert(std::string const& h, const std::string& msg); url_seed_alert(torrent_handle const& h, std::string const& h
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
std::string url; std::string url;
}; };
hash_failed_alert hash_failed_alert
----------------- -----------------
@ -2586,15 +2591,15 @@ This alert is generated as severity level ``info``.
:: ::
struct hash_failed_alert: alert struct hash_failed_alert: torrent_alert
{ {
hash_failed_alert( hash_failed_alert(
const torrent_handle& h torrent_handle const& h
, int index , int index
, const std::string& msg); , const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
int piece_index; int piece_index;
}; };
@ -2608,7 +2613,7 @@ to the torrent that this peer was a member of.
:: ::
struct peer_ban_alert: alert struct peer_ban_alert: torrent_alert
{ {
peer_ban_alert( peer_ban_alert(
asio::ip::tcp::endpoint const& pip asio::ip::tcp::endpoint const& pip
@ -2616,8 +2621,8 @@ to the torrent that this peer was a member of.
, const std::string& msg); , const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
asio::ip::tcp::endpoint ip; asio::ip::tcp::endpoint ip;
torrent_handle handle;
}; };
@ -2653,7 +2658,7 @@ is a handle to the torrent the peer is a member of. ``
:: ::
struct invalid_request_alert: alert struct invalid_request_alert: torrent_alert
{ {
invalid_request_alert( invalid_request_alert(
peer_request const& r peer_request const& r
@ -2663,7 +2668,7 @@ is a handle to the torrent the peer is a member of. ``
, std::string const& msg); , std::string const& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
asio::ip::tcp::endpoint ip; asio::ip::tcp::endpoint ip;
peer_request request; peer_request request;
peer_id id; peer_id id;
@ -2692,14 +2697,13 @@ torrent in question. This alert is generated as severity level ``info``.
:: ::
struct torrent_finished_alert: alert struct torrent_finished_alert:torrent_ alert
{ {
torrent_finished_alert( torrent_finished_alert(
const torrent_handle& h const torrent_handle& h
, const std::string& msg); , const std::string& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
}; };
@ -2714,14 +2718,13 @@ It is generated at severity level ``info``.
:: ::
struct metadata_failed_alert: alert struct metadata_failed_alert: torrent_alert
{ {
metadata_failed_alert( metadata_failed_alert(
const torrent_handle& h torrent_handle const& h
, const std::string& msg); , std::string const& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
}; };
@ -2735,14 +2738,13 @@ It is generated at severity level ``info``.
:: ::
struct metadata_received_alert: alert struct metadata_received_alert: torrent_alert
{ {
metadata_received_alert( metadata_received_alert(
const torrent_handle& h torrent_handle const_& h
, const std::string& msg); , std::string const& msg);
virtual std::auto_ptr<alert> clone() const; virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
}; };
@ -2766,31 +2768,6 @@ resume file was rejected. It is generated at severity level ``warning``.
.. chat_message_alert
------------------
This alert is generated when you receive a chat message from another peer. Chat messages
are supported as an extension ("chat"). It is generated as severity level ``critical``,
even though it doesn't necessarily require any user intervention, it's high priority
since you would almost never want to ignore such a message. The alert class contain
a torrent_handle_ to the torrent in which the sender-peer is a member and the ip
of the sending peer.
::
struct chat_message_alert: alert
{
chat_message_alert(const torrent_handle& h
, const address& sender
, const std::string& msg);
virtual std::auto_ptr<alert> clone() const;
torrent_handle handle;
address ip;
};
dispatcher dispatcher
---------- ----------

View File

@ -868,11 +868,11 @@ int main(int ac, char* av[])
out << (s.progress*100) << "% "; out << (s.progress*100) << "% ";
out << progress_bar(s.progress, 49, progress_bar_color); out << progress_bar(s.progress, 49, progress_bar_color);
out << "\n"; out << "\n";
out << "total downloaded: " << esc("32") << s.total_done << esc("0") << " Bytes\n"; out << "total downloaded: " << esc("32") << s.total_done << esc("0") << " Bytes ";
out << "peers: " << s.num_peers << " " out << "peers: " << s.num_peers << " "
<< "seeds: " << s.num_seeds << " " << "seeds: " << s.num_seeds << " "
<< "distributed copies: " << s.distributed_copies << "\n"; << "distributed copies: " << s.distributed_copies << "\n"
out << "download: " << esc("32") << add_suffix(s.download_rate) << "/s " << esc("0") << "download: " << esc("32") << add_suffix(s.download_rate) << "/s " << esc("0")
<< "(" << esc("32") << add_suffix(s.total_download) << esc("0") << ") "; << "(" << esc("32") << add_suffix(s.total_download) << esc("0") << ") ";
} }
else else
@ -884,11 +884,9 @@ int main(int ac, char* av[])
<< "ratio: " << ratio(s.total_payload_download, s.total_payload_upload) << "\n"; << "ratio: " << ratio(s.total_payload_download, s.total_payload_upload) << "\n";
if (s.state != torrent_status::seeding) if (s.state != torrent_status::seeding)
{ {
out << "info-hash: " << h.info_hash() << "\n";
boost::posix_time::time_duration t = s.next_announce; boost::posix_time::time_duration t = s.next_announce;
out << "next announce: " << esc("37") << out << "next announce: " << esc("37") <<
boost::posix_time::to_simple_string(t) << esc("0") << "\n"; boost::posix_time::to_simple_string(t) << esc("0") << " ";
out << "tracker: " << s.current_tracker << "\n"; out << "tracker: " << s.current_tracker << "\n";
} }

View File

@ -41,14 +41,24 @@ POSSIBILITY OF SUCH DAMAGE.
namespace libtorrent namespace libtorrent
{ {
struct TORRENT_EXPORT tracker_alert: alert struct TORRENT_EXPORT torrent_alert: alert
{
torrent_alert(torrent_handle const& h, alert::severity_t s
, std::string const& msg)
: alert(s, msg)
, handle(h)
{}
torrent_handle handle;
};
struct TORRENT_EXPORT tracker_alert: torrent_alert
{ {
tracker_alert(torrent_handle const& h tracker_alert(torrent_handle const& h
, int times , int times
, int status , int status
, std::string const& msg) , std::string const& msg)
: alert(alert::warning, msg) : torrent_alert(h, alert::warning, msg)
, handle(h)
, times_in_row(times) , times_in_row(times)
, status_code(status) , status_code(status)
{} {}
@ -56,85 +66,71 @@ namespace libtorrent
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_alert(*this)); } { return std::auto_ptr<alert>(new tracker_alert(*this)); }
torrent_handle handle;
int times_in_row; int times_in_row;
int status_code; int status_code;
}; };
struct TORRENT_EXPORT tracker_warning_alert: alert struct TORRENT_EXPORT tracker_warning_alert: torrent_alert
{ {
tracker_warning_alert(torrent_handle const& h tracker_warning_alert(torrent_handle const& h
, std::string const& msg) , std::string const& msg)
: alert(alert::warning, msg) : torrent_alert(h, alert::warning, msg)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_warning_alert(*this)); } { return std::auto_ptr<alert>(new tracker_warning_alert(*this)); }
torrent_handle handle;
}; };
struct TORRENT_EXPORT tracker_reply_alert: alert struct TORRENT_EXPORT tracker_reply_alert: torrent_alert
{ {
tracker_reply_alert(torrent_handle const& h tracker_reply_alert(torrent_handle const& h
, std::string const& msg) , std::string const& msg)
: alert(alert::info, msg) : torrent_alert(h, alert::info, msg)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_reply_alert(*this)); } { return std::auto_ptr<alert>(new tracker_reply_alert(*this)); }
torrent_handle handle;
}; };
struct TORRENT_EXPORT tracker_announce_alert: alert struct TORRENT_EXPORT tracker_announce_alert: torrent_alert
{ {
tracker_announce_alert(torrent_handle const& h, std::string const& msg) tracker_announce_alert(torrent_handle const& h, std::string const& msg)
: alert(alert::info, msg) : torrent_alert(h, alert::info, msg)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new tracker_announce_alert(*this)); } { return std::auto_ptr<alert>(new tracker_announce_alert(*this)); }
torrent_handle handle;
}; };
struct TORRENT_EXPORT hash_failed_alert: alert struct TORRENT_EXPORT hash_failed_alert: torrent_alert
{ {
hash_failed_alert( hash_failed_alert(
torrent_handle const& h torrent_handle const& h
, int index , int index
, std::string const& msg) , std::string const& msg)
: alert(alert::info, msg) : torrent_alert(h, alert::info, msg)
, handle(h)
, piece_index(index) , piece_index(index)
{ assert(index >= 0);} { assert(index >= 0);}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new hash_failed_alert(*this)); } { return std::auto_ptr<alert>(new hash_failed_alert(*this)); }
torrent_handle handle;
int piece_index; int piece_index;
}; };
struct TORRENT_EXPORT peer_ban_alert: alert struct TORRENT_EXPORT peer_ban_alert: torrent_alert
{ {
peer_ban_alert(tcp::endpoint const& pip, torrent_handle h, std::string const& msg) peer_ban_alert(tcp::endpoint const& pip, torrent_handle h, std::string const& msg)
: alert(alert::info, msg) : torrent_alert(h, alert::info, msg)
, ip(pip) , ip(pip)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new peer_ban_alert(*this)); } { return std::auto_ptr<alert>(new peer_ban_alert(*this)); }
tcp::endpoint ip; tcp::endpoint ip;
torrent_handle handle;
}; };
struct TORRENT_EXPORT peer_error_alert: alert struct TORRENT_EXPORT peer_error_alert: alert
@ -152,25 +148,7 @@ namespace libtorrent
peer_id pid; peer_id pid;
}; };
struct TORRENT_EXPORT chat_message_alert: alert struct TORRENT_EXPORT invalid_request_alert: torrent_alert
{
chat_message_alert(
const torrent_handle& h
, const tcp::endpoint& sender
, const std::string& msg)
: alert(alert::critical, msg)
, handle(h)
, ip(sender)
{}
virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new chat_message_alert(*this)); }
torrent_handle handle;
tcp::endpoint ip;
};
struct TORRENT_EXPORT invalid_request_alert: alert
{ {
invalid_request_alert( invalid_request_alert(
peer_request const& r peer_request const& r
@ -178,8 +156,7 @@ namespace libtorrent
, tcp::endpoint const& sender , tcp::endpoint const& sender
, peer_id const& pid_ , peer_id const& pid_
, std::string const& msg) , std::string const& msg)
: alert(alert::debug, msg) : torrent_alert(h, alert::debug, msg)
, handle(h)
, ip(sender) , ip(sender)
, request(r) , request(r)
, pid(pid_) , pid(pid_)
@ -188,33 +165,30 @@ namespace libtorrent
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new invalid_request_alert(*this)); } { return std::auto_ptr<alert>(new invalid_request_alert(*this)); }
torrent_handle handle;
tcp::endpoint ip; tcp::endpoint ip;
peer_request request; peer_request request;
peer_id pid; peer_id pid;
}; };
struct TORRENT_EXPORT torrent_finished_alert: alert struct TORRENT_EXPORT torrent_finished_alert: torrent_alert
{ {
torrent_finished_alert( torrent_finished_alert(
const torrent_handle& h const torrent_handle& h
, const std::string& msg) , const std::string& msg)
: alert(alert::warning, msg) : torrent_alert(h, alert::warning, msg)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new torrent_finished_alert(*this)); } { return std::auto_ptr<alert>(new torrent_finished_alert(*this)); }
torrent_handle handle;
}; };
struct TORRENT_EXPORT url_seed_alert: alert struct TORRENT_EXPORT url_seed_alert: torrent_alert
{ {
url_seed_alert( url_seed_alert(
const std::string& url_ torrent_handle const& h
, const std::string& url_
, const std::string& msg) , const std::string& msg)
: alert(alert::warning, msg) : torrent_alert(h, alert::warning, msg)
, url(url_) , url(url_)
{} {}
@ -224,49 +198,40 @@ namespace libtorrent
std::string url; std::string url;
}; };
struct TORRENT_EXPORT file_error_alert: alert struct TORRENT_EXPORT file_error_alert: torrent_alert
{ {
file_error_alert( file_error_alert(
const torrent_handle& h const torrent_handle& h
, const std::string& msg) , const std::string& msg)
: alert(alert::fatal, msg) : torrent_alert(h, alert::fatal, msg)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new file_error_alert(*this)); } { return std::auto_ptr<alert>(new file_error_alert(*this)); }
torrent_handle handle;
}; };
struct TORRENT_EXPORT metadata_failed_alert: alert struct TORRENT_EXPORT metadata_failed_alert: torrent_alert
{ {
metadata_failed_alert( metadata_failed_alert(
const torrent_handle& h const torrent_handle& h
, const std::string& msg) , const std::string& msg)
: alert(alert::info, msg) : torrent_alert(h, alert::info, msg)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new metadata_failed_alert(*this)); } { return std::auto_ptr<alert>(new metadata_failed_alert(*this)); }
torrent_handle handle;
}; };
struct TORRENT_EXPORT metadata_received_alert: alert struct TORRENT_EXPORT metadata_received_alert: torrent_alert
{ {
metadata_received_alert( metadata_received_alert(
const torrent_handle& h const torrent_handle& h
, const std::string& msg) , const std::string& msg)
: alert(alert::info, msg) : torrent_alert(h, alert::info, msg)
, handle(h)
{} {}
virtual std::auto_ptr<alert> clone() const virtual std::auto_ptr<alert> clone() const
{ return std::auto_ptr<alert>(new metadata_received_alert(*this)); } { return std::auto_ptr<alert>(new metadata_received_alert(*this)); }
torrent_handle handle;
}; };
struct TORRENT_EXPORT listen_failed_alert: alert struct TORRENT_EXPORT listen_failed_alert: alert

View File

@ -53,6 +53,12 @@ namespace libtorrent
class peer_connection; class peer_connection;
class torrent; class torrent;
// the maximum block of bandwidth quota to
// hand out is 33kB. The block size may
// be smaller on lower limits
const int max_bandwidth_block_size = 33000;
const int min_bandwidth_block_size = 4000;
#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING #if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING
namespace aux namespace aux
{ {

View File

@ -42,7 +42,6 @@ namespace libtorrent
namespace namespace
{ {
const pt::time_duration window_size = pt::seconds(1); const pt::time_duration window_size = pt::seconds(1);
const int bandwidth_block_size = 17000;
} }
history_entry::history_entry(intrusive_ptr<peer_connection> p history_entry::history_entry(intrusive_ptr<peer_connection> p
@ -96,7 +95,7 @@ namespace libtorrent
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING #if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING
(*m_ses->m_logger) << "bw history [" << m_channel << "]\n"; // (*m_ses->m_logger) << "bw history [" << m_channel << "]\n";
#endif #endif
m_history.push_front(e); m_history.push_front(e);
@ -117,7 +116,7 @@ namespace libtorrent
if (e) return; if (e) return;
#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING #if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING
(*m_ses->m_logger) << "bw expire [" << m_channel << "]\n"; // (*m_ses->m_logger) << "bw expire [" << m_channel << "]\n";
#endif #endif
assert(!m_history.empty()); assert(!m_history.empty());
@ -156,13 +155,18 @@ namespace libtorrent
{ {
INVARIANT_CHECK; INVARIANT_CHECK;
#if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING #if defined TORRENT_LOGGING || defined TORRENT_VERBOSE_LOGGING
(*m_ses->m_logger) << "hand out bw [" << m_channel << "]\n"; // (*m_ses->m_logger) << "hand out bw [" << m_channel << "]\n";
#endif #endif
pt::ptime now(pt::microsec_clock::universal_time()); pt::ptime now(pt::microsec_clock::universal_time());
// available bandwidth to hand out // available bandwidth to hand out
int amount = m_limit - m_current_quota; int amount = m_limit - m_current_quota;
int bandwidth_block_size_limit = max_bandwidth_block_size;
if (m_queue.size() > 3 && bandwidth_block_size_limit / int(m_queue.size()) > m_limit)
bandwidth_block_size_limit = std::max(max_bandwidth_block_size / int(m_queue.size() - 2)
, min_bandwidth_block_size);
while (!m_queue.empty() && amount > 0) while (!m_queue.empty() && amount > 0)
{ {
@ -186,9 +190,9 @@ namespace libtorrent
// so, hand out max_assignable, but no more than // so, hand out max_assignable, but no more than
// the available bandwidth (amount) and no more // the available bandwidth (amount) and no more
// than the bandwidth_block_size // than the max_bandwidth_block_size
int single_amount = std::min(amount int single_amount = std::min(amount
, std::min(bandwidth_block_size , std::min(bandwidth_block_size_limit
, max_assignable)); , max_assignable));
amount -= single_amount; amount -= single_amount;
if (single_amount > 0) peer->assign_bandwidth(m_channel, single_amount); if (single_amount > 0) peer->assign_bandwidth(m_channel, single_amount);

View File

@ -1209,7 +1209,7 @@ namespace libtorrent
std::stringstream msg; std::stringstream msg;
msg << "HTTP seed hostname lookup failed: " << e.message(); msg << "HTTP seed hostname lookup failed: " << e.message();
m_ses.m_alerts.post_alert( m_ses.m_alerts.post_alert(
url_seed_alert(url, msg.str())); url_seed_alert(get_handle(), url, msg.str()));
} }
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
(*m_ses.m_logger) << " ** HOSTNAME LOOKUP FAILED!**: " << url << "\n"; (*m_ses.m_logger) << " ** HOSTNAME LOOKUP FAILED!**: " << url << "\n";
@ -1457,13 +1457,13 @@ namespace libtorrent
void torrent::request_bandwidth(int channel void torrent::request_bandwidth(int channel
, boost::intrusive_ptr<peer_connection> p) , boost::intrusive_ptr<peer_connection> p)
{ {
if (m_bandwidth_limit[channel].max_assignable() >= 17000) if (m_bandwidth_limit[channel].max_assignable() >= max_bandwidth_block_size)
{ {
if (channel == peer_connection::upload_channel) if (channel == peer_connection::upload_channel)
m_ses.m_ul_bandwidth_manager.request_bandwidth(p); m_ses.m_ul_bandwidth_manager.request_bandwidth(p);
else if (channel == peer_connection::download_channel) else if (channel == peer_connection::download_channel)
m_ses.m_dl_bandwidth_manager.request_bandwidth(p); m_ses.m_dl_bandwidth_manager.request_bandwidth(p);
m_bandwidth_limit[channel].assign(17000); m_bandwidth_limit[channel].assign(max_bandwidth_block_size);
} }
else else
{ {
@ -1474,10 +1474,11 @@ namespace libtorrent
void torrent::expire_bandwidth(int channel, int amount) void torrent::expire_bandwidth(int channel, int amount)
{ {
assert(amount >= -1); assert(amount >= -1);
if (amount == -1) amount = 17000; if (amount == -1) amount = max_bandwidth_block_size;
m_bandwidth_limit[channel].expire(amount); m_bandwidth_limit[channel].expire(amount);
while (!m_bandwidth_queue[channel].empty() && m_bandwidth_limit[channel].max_assignable() >= 17000) while (!m_bandwidth_queue[channel].empty()
&& m_bandwidth_limit[channel].max_assignable() >= max_bandwidth_block_size)
{ {
intrusive_ptr<peer_connection> p = m_bandwidth_queue[channel].front(); intrusive_ptr<peer_connection> p = m_bandwidth_queue[channel].front();
m_bandwidth_queue[channel].pop_front(); m_bandwidth_queue[channel].pop_front();
@ -1485,14 +1486,15 @@ namespace libtorrent
m_ses.m_ul_bandwidth_manager.request_bandwidth(p); m_ses.m_ul_bandwidth_manager.request_bandwidth(p);
else if (channel == peer_connection::download_channel) else if (channel == peer_connection::download_channel)
m_ses.m_dl_bandwidth_manager.request_bandwidth(p); m_ses.m_dl_bandwidth_manager.request_bandwidth(p);
m_bandwidth_limit[channel].assign(17000); m_bandwidth_limit[channel].assign(max_bandwidth_block_size);
} }
} }
void torrent::assign_bandwidth(int channel, int amount) void torrent::assign_bandwidth(int channel, int amount)
{ {
assert(amount >= 0); assert(amount >= 0);
if (amount < 17000) expire_bandwidth(channel, 17000 - amount); if (amount < max_bandwidth_block_size)
expire_bandwidth(channel, max_bandwidth_block_size - amount);
} }
// called when torrent is finished (all interested pieces downloaded) // called when torrent is finished (all interested pieces downloaded)

View File

@ -659,43 +659,7 @@ namespace libtorrent
peer->get_peer_info(p); peer->get_peer_info(p);
} }
} }
/*
bool torrent_handle::send_chat_message(tcp::endpoint ip, std::string message) const
{
if (m_ses == 0) throw_invalid_handle();
session_impl::mutex_t::scoped_lock l(m_ses->m_mutex);
boost::shared_ptr<torrent> t = m_ses->find_torrent(m_info_hash).lock();
if (!t) return false;
for (torrent::const_peer_iterator i = t->begin();
i != t->end(); ++i)
{
peer_connection* peer = i->second;
// peers that haven't finished the handshake should
// not be included in this list
if (peer->associated_torrent().expired()) continue;
tcp::endpoint sender = peer->get_socket()->remote_endpoint();
// loop until we find the required ip tcp::endpoint
if (ip != sender) continue;
bt_peer_connection* p = dynamic_cast<bt_peer_connection*>(peer);
if (!p) return false;
// peers that don's support chat message extension
// should not be included either
if (!p->supports_extension(extended_chat_message))
return false;
// send the message
p->write_chat_message(message);
return true;
}
return false;
}
*/
void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const void torrent_handle::get_download_queue(std::vector<partial_piece_info>& queue) const
{ {
INVARIANT_CHECK; INVARIANT_CHECK;