*** empty log message ***

This commit is contained in:
Arvid Norberg 2004-10-29 13:21:09 +00:00
parent a326bc4391
commit a34130b446
13 changed files with 252 additions and 176 deletions

View File

@ -13,109 +13,110 @@
<div class="contents topic" id="contents">
<p class="topic-title"><a name="contents">Contents</a></p>
<ul class="simple">
<li><a class="reference" href="#introduction" id="id17" name="id17">introduction</a></li>
<li><a class="reference" href="#downloading-and-building" id="id18" name="id18">downloading and building</a><ul>
<li><a class="reference" href="#cygwin-and-msvc" id="id19" name="id19">cygwin and msvc</a></li>
<li><a class="reference" href="#release-and-debug-builds" id="id20" name="id20">release and debug builds</a></li>
<li><a class="reference" href="#introduction" id="id18" name="id18">introduction</a></li>
<li><a class="reference" href="#downloading-and-building" id="id19" name="id19">downloading and building</a><ul>
<li><a class="reference" href="#cygwin-and-msvc" id="id20" name="id20">cygwin and msvc</a></li>
<li><a class="reference" href="#release-and-debug-builds" id="id21" name="id21">release and debug builds</a></li>
</ul>
</li>
<li><a class="reference" href="#using" id="id21" name="id21">using</a></li>
<li><a class="reference" href="#session" id="id22" name="id22">session</a><ul>
<li><a class="reference" href="#id8" id="id23" name="id23">session()</a></li>
<li><a class="reference" href="#id9" id="id24" name="id24">~session()</a></li>
<li><a class="reference" href="#add-torrent" id="id25" name="id25">add_torrent()</a></li>
<li><a class="reference" href="#remove-torrent" id="id26" name="id26">remove_torrent()</a></li>
<li><a class="reference" href="#set-upload-rate-limit-set-download-rate-limit" id="id27" name="id27">set_upload_rate_limit() set_download_rate_limit()</a></li>
<li><a class="reference" href="#status" id="id28" name="id28">status()</a></li>
<li><a class="reference" href="#is-listening-listen-port-listen-on" id="id29" name="id29">is_listening() listen_port() listen_on()</a></li>
<li><a class="reference" href="#pop-alert-set-severity-level" id="id30" name="id30">pop_alert() set_severity_level()</a></li>
<li><a class="reference" href="#using" id="id22" name="id22">using</a></li>
<li><a class="reference" href="#session" id="id23" name="id23">session</a><ul>
<li><a class="reference" href="#id8" id="id24" name="id24">session()</a></li>
<li><a class="reference" href="#id9" id="id25" name="id25">~session()</a></li>
<li><a class="reference" href="#add-torrent" id="id26" name="id26">add_torrent()</a></li>
<li><a class="reference" href="#remove-torrent" id="id27" name="id27">remove_torrent()</a></li>
<li><a class="reference" href="#set-upload-rate-limit-set-download-rate-limit" id="id28" name="id28">set_upload_rate_limit() set_download_rate_limit()</a></li>
<li><a class="reference" href="#set-max-uploads-set-max-connections" id="id29" name="id29">set_max_uploads() set_max_connections()</a></li>
<li><a class="reference" href="#status" id="id30" name="id30">status()</a></li>
<li><a class="reference" href="#is-listening-listen-port-listen-on" id="id31" name="id31">is_listening() listen_port() listen_on()</a></li>
<li><a class="reference" href="#pop-alert-set-severity-level" id="id32" name="id32">pop_alert() set_severity_level()</a></li>
</ul>
</li>
<li><a class="reference" href="#entry" id="id31" name="id31">entry</a><ul>
<li><a class="reference" href="#integer-string-list-dict-type" id="id32" name="id32">integer() string() list() dict() type()</a></li>
<li><a class="reference" href="#entry" id="id33" name="id33">entry</a><ul>
<li><a class="reference" href="#integer-string-list-dict-type" id="id34" name="id34">integer() string() list() dict() type()</a></li>
</ul>
</li>
<li><a class="reference" href="#torrent-info" id="id33" name="id33">torrent_info</a><ul>
<li><a class="reference" href="#begin-files-end-files-rbegin-files-rend-files" id="id34" name="id34">begin_files() end_files() rbegin_files() rend_files()</a></li>
<li><a class="reference" href="#num-files-file-at" id="id35" name="id35">num_files() file_at()</a></li>
<li><a class="reference" href="#print" id="id36" name="id36">print()</a></li>
<li><a class="reference" href="#trackers" id="id37" name="id37">trackers()</a></li>
<li><a class="reference" href="#total-size-piece-length-piece-size-num-pieces" id="id38" name="id38">total_size() piece_length() piece_size() num_pieces()</a></li>
<li><a class="reference" href="#hash-for-piece-info-hash" id="id39" name="id39">hash_for_piece() info_hash()</a></li>
<li><a class="reference" href="#name-comment-creation-date" id="id40" name="id40">name() comment() creation_date()</a></li>
<li><a class="reference" href="#torrent-info" id="id35" name="id35">torrent_info</a><ul>
<li><a class="reference" href="#begin-files-end-files-rbegin-files-rend-files" id="id36" name="id36">begin_files() end_files() rbegin_files() rend_files()</a></li>
<li><a class="reference" href="#num-files-file-at" id="id37" name="id37">num_files() file_at()</a></li>
<li><a class="reference" href="#print" id="id38" name="id38">print()</a></li>
<li><a class="reference" href="#trackers" id="id39" name="id39">trackers()</a></li>
<li><a class="reference" href="#total-size-piece-length-piece-size-num-pieces" id="id40" name="id40">total_size() piece_length() piece_size() num_pieces()</a></li>
<li><a class="reference" href="#hash-for-piece-info-hash" id="id41" name="id41">hash_for_piece() info_hash()</a></li>
<li><a class="reference" href="#name-comment-creation-date" id="id42" name="id42">name() comment() creation_date()</a></li>
</ul>
</li>
<li><a class="reference" href="#torrent-handle" id="id41" name="id41">torrent_handle</a><ul>
<li><a class="reference" href="#save-path" id="id42" name="id42">save_path()</a></li>
<li><a class="reference" href="#move-storage" id="id43" name="id43">move_storage()</a></li>
<li><a class="reference" href="#force-reannounce" id="id44" name="id44">force_reannounce()</a></li>
<li><a class="reference" href="#connect-peer" id="id45" name="id45">connect_peer()</a></li>
<li><a class="reference" href="#set-ratio" id="id46" name="id46">set_ratio()</a></li>
<li><a class="reference" href="#set-upload-limit-set-download-limit" id="id47" name="id47">set_upload_limit() set_download_limit()</a></li>
<li><a class="reference" href="#pause-resume-is-paused" id="id48" name="id48">pause() resume() is_paused()</a></li>
<li><a class="reference" href="#is-seed" id="id49" name="id49">is_seed()</a></li>
<li><a class="reference" href="#set-tracker-login" id="id50" name="id50">set_tracker_login()</a></li>
<li><a class="reference" href="#use-interface" id="id51" name="id51">use_interface()</a></li>
<li><a class="reference" href="#info-hash" id="id52" name="id52">info_hash()</a></li>
<li><a class="reference" href="#set-max-uploads-set-max-connections" id="id53" name="id53">set_max_uploads() set_max_connections()</a></li>
<li><a class="reference" href="#write-resume-data" id="id54" name="id54">write_resume_data()</a></li>
<li><a class="reference" href="#metadata" id="id55" name="id55">metadata()</a></li>
<li><a class="reference" href="#id11" id="id56" name="id56">status()</a></li>
<li><a class="reference" href="#get-download-queue" id="id57" name="id57">get_download_queue()</a></li>
<li><a class="reference" href="#get-peer-info" id="id58" name="id58">get_peer_info()</a></li>
<li><a class="reference" href="#get-torrent-info" id="id59" name="id59">get_torrent_info()</a></li>
<li><a class="reference" href="#is-valid" id="id60" name="id60">is_valid()</a></li>
<li><a class="reference" href="#torrent-handle" id="id43" name="id43">torrent_handle</a><ul>
<li><a class="reference" href="#save-path" id="id44" name="id44">save_path()</a></li>
<li><a class="reference" href="#move-storage" id="id45" name="id45">move_storage()</a></li>
<li><a class="reference" href="#force-reannounce" id="id46" name="id46">force_reannounce()</a></li>
<li><a class="reference" href="#connect-peer" id="id47" name="id47">connect_peer()</a></li>
<li><a class="reference" href="#set-ratio" id="id48" name="id48">set_ratio()</a></li>
<li><a class="reference" href="#set-upload-limit-set-download-limit" id="id49" name="id49">set_upload_limit() set_download_limit()</a></li>
<li><a class="reference" href="#pause-resume-is-paused" id="id50" name="id50">pause() resume() is_paused()</a></li>
<li><a class="reference" href="#is-seed" id="id51" name="id51">is_seed()</a></li>
<li><a class="reference" href="#set-tracker-login" id="id52" name="id52">set_tracker_login()</a></li>
<li><a class="reference" href="#use-interface" id="id53" name="id53">use_interface()</a></li>
<li><a class="reference" href="#info-hash" id="id54" name="id54">info_hash()</a></li>
<li><a class="reference" href="#id11" id="id55" name="id55">set_max_uploads() set_max_connections()</a></li>
<li><a class="reference" href="#write-resume-data" id="id56" name="id56">write_resume_data()</a></li>
<li><a class="reference" href="#metadata" id="id57" name="id57">metadata()</a></li>
<li><a class="reference" href="#id12" id="id58" name="id58">status()</a></li>
<li><a class="reference" href="#get-download-queue" id="id59" name="id59">get_download_queue()</a></li>
<li><a class="reference" href="#get-peer-info" id="id60" name="id60">get_peer_info()</a></li>
<li><a class="reference" href="#get-torrent-info" id="id61" name="id61">get_torrent_info()</a></li>
<li><a class="reference" href="#is-valid" id="id62" name="id62">is_valid()</a></li>
</ul>
</li>
<li><a class="reference" href="#torrent-status" id="id61" name="id61">torrent_status</a></li>
<li><a class="reference" href="#peer-info" id="id62" name="id62">peer_info</a></li>
<li><a class="reference" href="#address" id="id63" name="id63">address</a></li>
<li><a class="reference" href="#http-settings" id="id64" name="id64">http_settings</a></li>
<li><a class="reference" href="#big-number" id="id65" name="id65">big_number</a></li>
<li><a class="reference" href="#hasher" id="id66" name="id66">hasher</a></li>
<li><a class="reference" href="#fingerprint" id="id67" name="id67">fingerprint</a></li>
<li><a class="reference" href="#free-functions" id="id68" name="id68">free functions</a><ul>
<li><a class="reference" href="#identify-client" id="id69" name="id69">identify_client()</a></li>
<li><a class="reference" href="#bdecode-bencode" id="id70" name="id70">bdecode() bencode()</a></li>
<li><a class="reference" href="#torrent-status" id="id63" name="id63">torrent_status</a></li>
<li><a class="reference" href="#peer-info" id="id64" name="id64">peer_info</a></li>
<li><a class="reference" href="#address" id="id65" name="id65">address</a></li>
<li><a class="reference" href="#http-settings" id="id66" name="id66">http_settings</a></li>
<li><a class="reference" href="#big-number" id="id67" name="id67">big_number</a></li>
<li><a class="reference" href="#hasher" id="id68" name="id68">hasher</a></li>
<li><a class="reference" href="#fingerprint" id="id69" name="id69">fingerprint</a></li>
<li><a class="reference" href="#free-functions" id="id70" name="id70">free functions</a><ul>
<li><a class="reference" href="#identify-client" id="id71" name="id71">identify_client()</a></li>
<li><a class="reference" href="#bdecode-bencode" id="id72" name="id72">bdecode() bencode()</a></li>
</ul>
</li>
<li><a class="reference" href="#alerts" id="id71" name="id71">alerts</a><ul>
<li><a class="reference" href="#listen-failed-alert" id="id72" name="id72">listen_failed_alert</a></li>
<li><a class="reference" href="#file-error-alert" id="id73" name="id73">file_error_alert</a></li>
<li><a class="reference" href="#tracker-alert" id="id74" name="id74">tracker_alert</a></li>
<li><a class="reference" href="#hash-failed-alert" id="id75" name="id75">hash_failed_alert</a></li>
<li><a class="reference" href="#peer-ban-alert" id="id76" name="id76">peer_ban_alert</a></li>
<li><a class="reference" href="#peer-error-alert" id="id77" name="id77">peer_error_alert</a></li>
<li><a class="reference" href="#invalid-request-alert" id="id78" name="id78">invalid_request_alert</a></li>
<li><a class="reference" href="#torrent-finished-alert" id="id79" name="id79">torrent_finished_alert</a></li>
<li><a class="reference" href="#metadata-received-alert" id="id80" name="id80">metadata_received_alert</a></li>
<li><a class="reference" href="#dispatcher" id="id81" name="id81">dispatcher</a></li>
<li><a class="reference" href="#alerts" id="id73" name="id73">alerts</a><ul>
<li><a class="reference" href="#listen-failed-alert" id="id74" name="id74">listen_failed_alert</a></li>
<li><a class="reference" href="#file-error-alert" id="id75" name="id75">file_error_alert</a></li>
<li><a class="reference" href="#tracker-alert" id="id76" name="id76">tracker_alert</a></li>
<li><a class="reference" href="#hash-failed-alert" id="id77" name="id77">hash_failed_alert</a></li>
<li><a class="reference" href="#peer-ban-alert" id="id78" name="id78">peer_ban_alert</a></li>
<li><a class="reference" href="#peer-error-alert" id="id79" name="id79">peer_error_alert</a></li>
<li><a class="reference" href="#invalid-request-alert" id="id80" name="id80">invalid_request_alert</a></li>
<li><a class="reference" href="#torrent-finished-alert" id="id81" name="id81">torrent_finished_alert</a></li>
<li><a class="reference" href="#metadata-received-alert" id="id82" name="id82">metadata_received_alert</a></li>
<li><a class="reference" href="#dispatcher" id="id83" name="id83">dispatcher</a></li>
</ul>
</li>
<li><a class="reference" href="#exceptions" id="id82" name="id82">exceptions</a><ul>
<li><a class="reference" href="#invalid-handle" id="id83" name="id83">invalid_handle</a></li>
<li><a class="reference" href="#duplicate-torrent" id="id84" name="id84">duplicate_torrent</a></li>
<li><a class="reference" href="#invalid-encoding" id="id85" name="id85">invalid_encoding</a></li>
<li><a class="reference" href="#type-error" id="id86" name="id86">type_error</a></li>
<li><a class="reference" href="#invalid-torrent-file" id="id87" name="id87">invalid_torrent_file</a></li>
<li><a class="reference" href="#exceptions" id="id84" name="id84">exceptions</a><ul>
<li><a class="reference" href="#invalid-handle" id="id85" name="id85">invalid_handle</a></li>
<li><a class="reference" href="#duplicate-torrent" id="id86" name="id86">duplicate_torrent</a></li>
<li><a class="reference" href="#invalid-encoding" id="id87" name="id87">invalid_encoding</a></li>
<li><a class="reference" href="#type-error" id="id88" name="id88">type_error</a></li>
<li><a class="reference" href="#invalid-torrent-file" id="id89" name="id89">invalid_torrent_file</a></li>
</ul>
</li>
<li><a class="reference" href="#examples" id="id88" name="id88">examples</a><ul>
<li><a class="reference" href="#dump-torrent" id="id89" name="id89">dump_torrent</a></li>
<li><a class="reference" href="#simple-client" id="id90" name="id90">simple client</a></li>
<li><a class="reference" href="#examples" id="id90" name="id90">examples</a><ul>
<li><a class="reference" href="#dump-torrent" id="id91" name="id91">dump_torrent</a></li>
<li><a class="reference" href="#simple-client" id="id92" name="id92">simple client</a></li>
</ul>
</li>
<li><a class="reference" href="#fast-resume" id="id91" name="id91">fast resume</a><ul>
<li><a class="reference" href="#file-format" id="id92" name="id92">file format</a></li>
<li><a class="reference" href="#fast-resume" id="id93" name="id93">fast resume</a><ul>
<li><a class="reference" href="#file-format" id="id94" name="id94">file format</a></li>
</ul>
</li>
<li><a class="reference" href="#extensions" id="id93" name="id93">extensions</a><ul>
<li><a class="reference" href="#chat-messages" id="id94" name="id94">chat messages</a></li>
<li><a class="reference" href="#metadata-from-peers" id="id95" name="id95">metadata from peers</a></li>
<li><a class="reference" href="#extensions" id="id95" name="id95">extensions</a><ul>
<li><a class="reference" href="#chat-messages" id="id96" name="id96">chat messages</a></li>
<li><a class="reference" href="#metadata-from-peers" id="id97" name="id97">metadata from peers</a></li>
</ul>
</li>
<li><a class="reference" href="#filename-checks" id="id96" name="id96">filename checks</a></li>
<li><a class="reference" href="#acknowledgements" id="id97" name="id97">acknowledgements</a></li>
<li><a class="reference" href="#filename-checks" id="id98" name="id98">filename checks</a></li>
<li><a class="reference" href="#acknowledgements" id="id99" name="id99">acknowledgements</a></li>
</ul>
</div>
<div class="section" id="introduction">
@ -180,8 +181,8 @@ boost.filesystem, boost.date_time and various other boost libraries as well as z
<ul class="simple">
<li>Windows 2000 vc7.1</li>
<li>Linux x86 (debian) GCC 3.0.4, GCC 3.2.3</li>
<li>Windows 2000, msvc6 sp5 (does not support 64-bit values due to problems with operator&lt;&lt;(ostream&amp;, __int64))</li>
<li>MacOS X, GCC 3.3</li>
<li>SunOS 5.8 GCC 3.1</li>
</ul>
</blockquote>
<p>Fails on:</p>
@ -189,6 +190,7 @@ boost.filesystem, boost.date_time and various other boost libraries as well as z
<ul class="simple">
<li>GCC 2.95.4 (<tt class="literal"><span class="pre">std::ios_base</span></tt> is missing)</li>
<li>Cygwin GCC 3.3.1 (builds but crashes)</li>
<li>msvc6 sp5</li>
</ul>
</blockquote>
<p>libtorrent is released under the <a class="reference" href="http://www.opensource.org/licenses/bsd-license.php">BSD-license</a>.</p>
@ -339,6 +341,8 @@ class session: public boost::noncopyable
void set_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second);
void set_max_uploads(int limit);
void set_max_connections(int limit);
session_status status() const;
@ -351,7 +355,6 @@ class session: public boost::noncopyable
std::auto_ptr&lt;alert&gt; pop_alert();
void set_severity_level(alert::severity_t s);
};
</pre>
<p>Once it's created, the session object will spawn the main thread that will do all the work.
@ -440,6 +443,20 @@ you don't want to limit upload rate, you can set this to -1 (the default).
<tt class="literal"><span class="pre">set_download_rate_limit()</span></tt> works the same way but for download rate instead
of upload rate.</p>
</div>
<div class="section" id="set-max-uploads-set-max-connections">
<h2><a name="set-max-uploads-set-max-connections">set_max_uploads() set_max_connections()</a></h2>
<blockquote>
<pre class="literal-block">
void set_max_uploads(int limit);
void set_max_connections(int limit);
</pre>
</blockquote>
<p>These functions will set a global limit on the number of unchoked peers (uploads)
and the number of connections opened. The number of connections is set to a hard
minimum of at least two connections per torrent, so if you set a too low
connections limit, and open too many torrents, the limit will not be met. The
number of uploads is at least one per torrent.</p>
</div>
<div class="section" id="status">
<h2><a name="status">status()</a></h2>
<blockquote>
@ -981,8 +998,8 @@ sha1_hash info_hash() const;
</blockquote>
<p><tt class="literal"><span class="pre">info_hash()</span></tt> returns the info-hash for the torrent.</p>
</div>
<div class="section" id="set-max-uploads-set-max-connections">
<h2><a name="set-max-uploads-set-max-connections">set_max_uploads() set_max_connections()</a></h2>
<div class="section" id="id11">
<h2><a name="id11">set_max_uploads() set_max_connections()</a></h2>
<blockquote>
<pre class="literal-block">
void set_max_uploads(int max_uploads);
@ -1030,8 +1047,8 @@ std::vector&lt;char&gt; const&amp; metadata() const;
.torrent file. This buffer will be valid as long as the torrent is still running. When hashed,
it will produce the same hash as the info-hash.</p>
</div>
<div class="section" id="id11">
<h2><a name="id11">status()</a></h2>
<div class="section" id="id12">
<h2><a name="id12">status()</a></h2>
<blockquote>
<pre class="literal-block">
torrent_status status();

View File

@ -68,13 +68,14 @@ libtorrent has been successfully compiled and tested on:
* Windows 2000 vc7.1
* Linux x86 (debian) GCC 3.0.4, GCC 3.2.3
* Windows 2000, msvc6 sp5 (does not support 64-bit values due to problems with operator<<(ostream&, __int64))
* MacOS X, GCC 3.3
* SunOS 5.8 GCC 3.1
Fails on:
* GCC 2.95.4 (``std::ios_base`` is missing)
* Cygwin GCC 3.3.1 (builds but crashes)
* msvc6 sp5
libtorrent is released under the BSD-license_.
@ -238,6 +239,8 @@ The ``session`` class has the following synopsis::
void set_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second);
void set_max_uploads(int limit);
void set_max_connections(int limit);
session_status status() const;
@ -250,7 +253,6 @@ The ``session`` class has the following synopsis::
std::auto_ptr<alert> pop_alert();
void set_severity_level(alert::severity_t s);
};
Once it's created, the session object will spawn the main thread that will do all the work.
@ -348,6 +350,21 @@ you don't want to limit upload rate, you can set this to -1 (the default).
of upload rate.
set_max_uploads() set_max_connections()
---------------------------------------
::
void set_max_uploads(int limit);
void set_max_connections(int limit);
These functions will set a global limit on the number of unchoked peers (uploads)
and the number of connections opened. The number of connections is set to a hard
minimum of at least two connections per torrent, so if you set a too low
connections limit, and open too many torrents, the limit will not be met. The
number of uploads is at least one per torrent.
status()
--------

View File

@ -273,7 +273,6 @@ namespace libtorrent
// and how much we are allowed to use.
resource_request m_ul_bandwidth_quota;
resource_request m_dl_bandwidth_quota;
resource_request m_unchoked_quota;
private:

View File

@ -107,17 +107,6 @@ namespace libtorrent
// the peer is not interested in our pieces
void not_interested(peer_connection& c);
void set_max_uploads(int num_unchoked);
int get_max_uploads() const { return m_max_uploads; }
/*
A limit on the number of sockets opened, for use on systems where a
user has a limited number of open file descriptors. And for windows
which has a buggy tcp-stack.
*/
void set_max_connections(int num_connected);
int get_max_connections() const { return m_max_connections; }
#ifndef NDEBUG
bool has_connection(const peer_connection* p);
@ -173,6 +162,11 @@ namespace libtorrent
return m_num_peers;
}
int num_uploads() const
{
return m_num_unchoked;
}
private:
bool unchoke_one_peer();
@ -213,13 +207,6 @@ namespace libtorrent
int m_num_peers;
torrent* m_torrent;
// the total number of unchoked peers at
// any given time. If set to -1, it's unlimited.
// must be 2 or higher otherwise.
int m_max_uploads;
int m_max_connections;
// the number of unchoked peers
// at any given time
int m_num_unchoked;

View File

@ -229,6 +229,8 @@ namespace libtorrent
// unlimited
int m_upload_rate;
int m_download_rate;
int m_max_uploads;
int m_max_connections;
// statistics gathered from all torrents.
stat m_stat;
@ -327,9 +329,8 @@ namespace libtorrent
void set_http_settings(const http_settings& s);
void set_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit(int bytes_per_second);
// TODO: global max connections setting
// TODO: global max uploads setting
void set_max_uploads(int limit);
void set_max_connections(int limit);
std::auto_ptr<alert> pop_alert();
void set_severity_level(alert::severity_t s);

View File

@ -329,11 +329,13 @@ namespace libtorrent
resource_request m_ul_bandwidth_quota;
resource_request m_dl_bandwidth_quota;
resource_request m_unchoked_quota;
resource_request m_uploads_quota;
resource_request m_connections_quota;
void set_upload_limit(int limit);
void set_download_limit(int limit);
void set_max_uploads(int limit);
void set_max_connections(int limit);
bool move_storage(boost::filesystem::path const& save_path);
bool valid_metadata() const { return m_storage.get() != 0; }

View File

@ -89,6 +89,7 @@ namespace libtorrent
torrent_info();
torrent_info(sha1_hash const& info_hash);
torrent_info(entry const& torrent_file);
~torrent_info();
entry create_torrent() const;
entry create_info_metadata() const;

View File

@ -113,16 +113,20 @@ namespace libtorrent
{
int sum_given = 0;
int sum_max = 0;
int sum_min = 0;
for (It i = m_start, end(m_end); i != end; ++i)
{
assert(((*i).*m_res).max >= 0);
assert(((*i).*m_res).min >= 0);
assert(((*i).*m_res).max >= ((*i).*m_res).min);
assert(((*i).*m_res).given >= 0);
assert(((*i).*m_res).given <= ((*i).*m_res).max);
sum_given = saturated_add(sum_given, ((*i).*m_res).given);
sum_max = saturated_add(sum_max, ((*i).*m_res).max);
sum_min = saturated_add(sum_min, ((*i).*m_res).min);
}
assert(sum_given == std::min(m_resources, sum_max));
assert(sum_given == std::min(std::max(m_resources, sum_min), sum_max));
}
};
@ -171,6 +175,7 @@ namespace libtorrent
if (resources == 0 || sum_max == 0)
return;
resources = std::max(resources, sum_min);
int resources_to_distribute = std::min(resources, sum_max) - sum_min;
assert(resources_to_distribute >= 0);

View File

@ -324,8 +324,8 @@ namespace libtorrent
policy::policy(torrent* t)
: m_num_peers(0)
, m_torrent(t)
, m_max_uploads(std::numeric_limits<int>::max())
, m_max_connections(std::numeric_limits<int>::max())
// , m_max_uploads(std::numeric_limits<int>::max())
// , m_max_connections(std::numeric_limits<int>::max())
, m_num_unchoked(0)
, m_available_free_upload(0)
, m_last_optimistic_disconnect(boost::gregorian::date(1970,boost::gregorian::Jan,1))
@ -593,10 +593,10 @@ namespace libtorrent
++num_connected_peers;
}
if (m_max_connections != std::numeric_limits<int>::max())
if (m_torrent->m_connections_quota.given != std::numeric_limits<int>::max())
{
int max_connections = m_max_connections;
int max_connections = m_torrent->m_connections_quota.given;
if (num_connected_peers >= max_connections)
{
@ -622,7 +622,7 @@ namespace libtorrent
}
}
while (m_torrent->num_peers() < m_max_connections)
while (m_torrent->num_peers() < m_torrent->m_connections_quota.given)
{
if (!connect_one_peer())
break;
@ -665,7 +665,7 @@ namespace libtorrent
// ------------------------
if (m_torrent->is_seed())
{
if (num_connected_peers > m_max_uploads)
if (num_connected_peers > m_torrent->m_uploads_quota.given)
{
// this means there are some peers that
// are choked. To have the choked peers
@ -675,7 +675,7 @@ namespace libtorrent
seed_unchoke_one_peer();
}
while (m_num_unchoked > m_max_uploads)
while (m_num_unchoked > m_torrent->m_uploads_quota.given)
{
peer* p = find_seed_choke_candidate();
assert(p != 0);
@ -686,7 +686,7 @@ namespace libtorrent
// make sure we have enough
// unchoked peers
while (m_num_unchoked < m_max_uploads)
while (m_num_unchoked < m_torrent->m_uploads_quota.given)
{
if (!seed_unchoke_one_peer()) break;
}
@ -719,11 +719,11 @@ namespace libtorrent
}
}
if (m_max_uploads < m_torrent->num_peers())
if (m_torrent->m_uploads_quota.given < m_torrent->num_peers())
{
// make sure we don't have too many
// unchoked peers
while (m_num_unchoked > m_max_uploads)
while (m_num_unchoked > m_torrent->m_uploads_quota.given)
{
peer* p = find_choke_candidate();
assert(p);
@ -745,7 +745,8 @@ namespace libtorrent
// make sure we have enough
// unchoked peers
while (m_num_unchoked < m_max_uploads && unchoke_one_peer());
while (m_num_unchoked < m_torrent->m_uploads_quota.given
&& unchoke_one_peer());
}
#ifndef NDEBUG
check_invariant();
@ -776,7 +777,7 @@ namespace libtorrent
// TODO: only allow _one_ connection to use this
// override at a time
if (m_torrent->num_peers() >= m_max_connections
if (m_torrent->num_peers() >= m_torrent->m_connections_quota.given
&& c.get_socket()->sender().ip() != m_torrent->current_tracker().ip())
{
throw protocol_error("too many connections, refusing incoming connection"); // cause a disconnect
@ -870,7 +871,7 @@ namespace libtorrent
if (i->banned) return;
if (m_torrent->num_peers() < m_max_connections
if (m_torrent->num_peers() < m_torrent->m_connections_quota.given
&& !m_torrent->is_paused())
{
connect_peer(&*i);
@ -1001,7 +1002,7 @@ namespace libtorrent
bool policy::connect_one_peer()
{
if(m_torrent->num_peers() >= m_max_connections)
if(m_torrent->num_peers() >= m_torrent->m_connections_quota.given)
return false;
peer* p = find_connect_candidate();
if (p == 0) return false;
@ -1083,21 +1084,6 @@ namespace libtorrent
i->connection = 0;
}
void policy::set_max_uploads(int max_uploads)
{
assert(max_uploads > 1 || max_uploads == -1);
if (max_uploads == -1) max_uploads = std::numeric_limits<int>::max();
m_max_uploads = max_uploads;
}
void policy::set_max_connections(int max_connections)
{
assert(max_connections > 1 || max_connections == -1);
if (max_connections == -1) max_connections = std::numeric_limits<int>::max();
assert(max_connections >= 2);
m_max_connections = max_connections;
}
void policy::peer_is_interesting(peer_connection& c)
{
c.send_interested();
@ -1117,7 +1103,7 @@ namespace libtorrent
void policy::check_invariant() const
{
assert(m_max_uploads >= 2);
assert(m_torrent->m_uploads_quota.given >= 2);
int actual_unchoked = 0;
for (std::vector<peer>::const_iterator i = m_peers.begin();
i != m_peers.end();
@ -1126,7 +1112,7 @@ namespace libtorrent
if (!i->connection) continue;
if (!i->connection->is_choked()) actual_unchoked++;
}
assert(actual_unchoked <= m_max_uploads);
assert(actual_unchoked <= m_torrent->m_uploads_quota.given);
}
#endif

View File

@ -196,6 +196,8 @@ namespace libtorrent { namespace detail
, m_abort(false)
, m_upload_rate(-1)
, m_download_rate(-1)
, m_max_uploads(-1)
, m_max_connections(-1)
, m_incoming_connection(false)
{
#ifndef NDEBUG
@ -694,15 +696,24 @@ namespace libtorrent { namespace detail
, m_torrents
, &torrent::m_dl_bandwidth_quota);
allocate_resources(m_max_uploads == -1
? std::numeric_limits<int>::max()
: m_max_uploads
, m_torrents
, &torrent::m_uploads_quota);
allocate_resources(m_max_connections == -1
? std::numeric_limits<int>::max()
: m_max_connections
, m_torrents
, &torrent::m_connections_quota);
for (std::map<sha1_hash, boost::shared_ptr<torrent> >::iterator i
= m_torrents.begin(); i != m_torrents.end(); ++i)
{
i->second->distribute_resources();
}
// TODO: there's a problem when removing torrents while
// they're waiting for tracker response. The requester-pointer
// will become invalid.
m_tracker_manager.tick();
}
@ -1045,6 +1056,20 @@ namespace libtorrent
m_checker_thread.join();
}
void session::set_max_uploads(int limit)
{
assert(limit > 0 || limit == -1);
boost::mutex::scoped_lock l(m_impl.m_mutex);
m_impl.m_max_uploads = limit;
}
void session::set_max_connections(int limit)
{
assert(limit > 0 || limit == -1);
boost::mutex::scoped_lock l(m_impl.m_mutex);
m_impl.m_max_connections = limit;
}
void session::set_upload_rate_limit(int bytes_per_second)
{
assert(bytes_per_second > 0 || bytes_per_second == -1);

View File

@ -178,6 +178,11 @@ namespace libtorrent
, m_download_bandwidth_limit(std::numeric_limits<int>::max())
, m_save_path(complete(save_path))
{
m_uploads_quota.min = 2;
m_connections_quota.min = 2;
m_uploads_quota.max = std::numeric_limits<int>::max();
m_connections_quota.max = std::numeric_limits<int>::max();
m_policy.reset(new policy(this));
bencode(std::back_inserter(m_metadata), metadata["info"]);
init();
@ -215,6 +220,11 @@ namespace libtorrent
, m_download_bandwidth_limit(std::numeric_limits<int>::max())
, m_save_path(complete(save_path))
{
m_uploads_quota.min = 2;
m_connections_quota.min = 2;
m_uploads_quota.max = std::numeric_limits<int>::max();
m_connections_quota.max = std::numeric_limits<int>::max();
m_trackers.push_back(announce_entry(tracker_url));
m_requested_metadata.resize(256, 0);
m_policy.reset(new policy(this));
@ -534,7 +544,7 @@ namespace libtorrent
req.event = m_event;
req.url = m_trackers[m_currently_trying_tracker].url;
req.num_want = std::max(
(m_policy->get_max_connections()
(m_connections_quota.given
- m_policy->num_peers()), 0);
// default initialize, these should be set by caller
@ -761,6 +771,20 @@ namespace libtorrent
}
#endif
void torrent::set_max_uploads(int limit)
{
assert(limit >= -1);
if (limit == -1) limit = std::numeric_limits<int>::max();
m_uploads_quota.max = std::max(m_uploads_quota.min, limit);
}
void torrent::set_max_connections(int limit)
{
assert(limit >= -1);
if (limit == -1) limit = std::numeric_limits<int>::max();
m_connections_quota.max = std::max(m_connections_quota.min, limit);
}
void torrent::set_upload_limit(int limit)
{
assert(limit >= -1);
@ -807,12 +831,8 @@ namespace libtorrent
return;
}
m_time_scaler--;
if (m_time_scaler <= 0)
{
m_time_scaler = 10;
m_policy->pulse();
}
m_connections_quota.used = (int)m_connections.size();
m_uploads_quota.used = m_policy->num_uploads();
m_ul_bandwidth_quota.used = 0;
m_ul_bandwidth_quota.max = 0;
@ -844,7 +864,6 @@ namespace libtorrent
m_dl_bandwidth_quota.max = saturated_add(
m_dl_bandwidth_quota.max
, p->m_dl_bandwidth_quota.max);
}
m_ul_bandwidth_quota.max
@ -859,6 +878,13 @@ namespace libtorrent
void torrent::distribute_resources()
{
m_time_scaler--;
if (m_time_scaler <= 0)
{
m_time_scaler = 10;
m_policy->pulse();
}
// distribute allowed upload among the peers
allocate_resources(m_ul_bandwidth_quota.given
, m_connections
@ -869,8 +895,16 @@ namespace libtorrent
, m_connections
, &peer_connection::m_dl_bandwidth_quota);
using boost::bind;
// tell all peers to reset their used quota. This is
// a new second and they can again use up their quota
/*
std::for_each(m_connections.begin(), m_connections.end()
, bind(&peer_connection::reset_upload_quota
, bind(&std::pair<address, peer_connection*>::second, _1)));
*/
for (std::map<address, peer_connection*>::iterator i = m_connections.begin();
i != m_connections.end(); ++i)
{

View File

@ -70,6 +70,8 @@ namespace std
};
#endif
using boost::bind;
namespace libtorrent
{
@ -180,9 +182,7 @@ namespace libtorrent
assert(max_uploads >= 2 || max_uploads == -1);
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&policy::set_max_uploads
, boost::bind(&torrent::get_policy, _1)
, max_uploads));
, bind(&torrent::set_max_uploads, _1, max_uploads));
}
void torrent_handle::use_interface(const char* net_interface)
@ -190,7 +190,7 @@ namespace libtorrent
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::use_interface, _1, net_interface));
, bind(&torrent::use_interface, _1, net_interface));
}
void torrent_handle::set_max_connections(int max_connections)
@ -198,8 +198,7 @@ namespace libtorrent
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&policy::set_max_connections
, boost::bind(&torrent::get_policy, _1), max_connections));
, bind(&torrent::set_max_connections, _1, max_connections));
}
void torrent_handle::set_upload_limit(int limit)
@ -209,7 +208,7 @@ namespace libtorrent
assert(limit >= -1);
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::set_upload_limit, _1, limit));
, bind(&torrent::set_upload_limit, _1, limit));
}
void torrent_handle::set_download_limit(int limit)
@ -219,7 +218,7 @@ namespace libtorrent
assert(limit >= -1);
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::set_download_limit, _1, limit));
, bind(&torrent::set_download_limit, _1, limit));
}
bool torrent_handle::move_storage(boost::filesystem::path const& save_path)
@ -227,7 +226,7 @@ namespace libtorrent
INVARIANT_CHECK;
return call_member<bool>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::move_storage, _1, save_path));
, bind(&torrent::move_storage, _1, save_path));
}
bool torrent_handle::has_metadata() const
@ -235,7 +234,7 @@ namespace libtorrent
INVARIANT_CHECK;
return call_member<bool>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::valid_metadata, _1));
, bind(&torrent::valid_metadata, _1));
}
bool torrent_handle::is_seed() const
@ -243,7 +242,7 @@ namespace libtorrent
INVARIANT_CHECK;
return call_member<bool>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::is_seed, _1));
, bind(&torrent::is_seed, _1));
}
bool torrent_handle::is_paused() const
@ -251,7 +250,7 @@ namespace libtorrent
INVARIANT_CHECK;
return call_member<bool>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::is_paused, _1));
, bind(&torrent::is_paused, _1));
}
void torrent_handle::pause()
@ -259,7 +258,7 @@ namespace libtorrent
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::pause, _1));
, bind(&torrent::pause, _1));
}
void torrent_handle::resume()
@ -267,7 +266,7 @@ namespace libtorrent
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::resume, _1));
, bind(&torrent::resume, _1));
}
void torrent_handle::set_tracker_login(std::string const& name, std::string const& password)
@ -275,7 +274,7 @@ namespace libtorrent
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::set_tracker_login, _1, name, password));
, bind(&torrent::set_tracker_login, _1, name, password));
}
@ -318,7 +317,7 @@ namespace libtorrent
INVARIANT_CHECK;
return call_member<std::vector<announce_entry> const&>(m_ses
, m_chk, m_info_hash, boost::bind(&torrent::trackers, _1));
, m_chk, m_info_hash, bind(&torrent::trackers, _1));
}
void torrent_handle::replace_trackers(std::vector<announce_entry> const& urls)
@ -326,7 +325,7 @@ namespace libtorrent
INVARIANT_CHECK;
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::replace_trackers, _1, urls));
, bind(&torrent::replace_trackers, _1, urls));
}
const torrent_info& torrent_handle::get_torrent_info() const
@ -335,7 +334,7 @@ namespace libtorrent
if (!has_metadata()) throw invalid_handle();
return call_member<torrent_info const&>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::torrent_file, _1));
, bind(&torrent::torrent_file, _1));
}
bool torrent_handle::is_valid() const
@ -481,7 +480,7 @@ namespace libtorrent
INVARIANT_CHECK;
return call_member<boost::filesystem::path>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::save_path, _1));
, bind(&torrent::save_path, _1));
}
std::vector<char> const& torrent_handle::metadata() const
@ -489,7 +488,7 @@ namespace libtorrent
INVARIANT_CHECK;
return call_member<std::vector<char> const&>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::metadata, _1));
, bind(&torrent::metadata, _1));
}
void torrent_handle::connect_peer(const address& adr) const
@ -530,7 +529,7 @@ namespace libtorrent
ratio = 1.f;
call_member<void>(m_ses, m_chk, m_info_hash
, boost::bind(&torrent::set_ratio, _1, ratio));
, bind(&torrent::set_ratio, _1, ratio));
}
void torrent_handle::get_peer_info(std::vector<peer_info>& v) const

View File

@ -141,6 +141,9 @@ namespace libtorrent
{
}
torrent_info::~torrent_info()
{}
void torrent_info::set_piece_size(int size)
{
// make sure the size is an even 2 exponential