*** empty log message ***
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
<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="#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="#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="#print" id="id36" name="id36">print()</a></li>
|
||||||
<li><a class="reference" href="#trackers-prioritize-tracker" id="id37" name="id37">trackers() prioritize_tracker()</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="#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="#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="#name-comment-creation-date" id="id40" name="id40">name() comment() creation_date()</a></li>
|
||||||
@@ -635,7 +635,7 @@ class torrent_info
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
torrent_info(const entry& torrent_file)
|
torrent_info(entry const& torrent_file)
|
||||||
torrent_info(int piece_size, const char* name);
|
torrent_info(int piece_size, const char* name);
|
||||||
|
|
||||||
entry create_torrent() const;
|
entry create_torrent() const;
|
||||||
@@ -645,7 +645,7 @@ public:
|
|||||||
void add_tracker(std::string const& url, int tier = 0);
|
void add_tracker(std::string const& url, int tier = 0);
|
||||||
void add_file(boost::filesystem::path file, size_type size);
|
void add_file(boost::filesystem::path file, size_type size);
|
||||||
|
|
||||||
typedef std::vector>file_entry>::const_iterator file_iterator;
|
typedef std::vector<file_entry>::const_iterator file_iterator;
|
||||||
typedef std::vector<file_entry>::const_reverse_iterator reverse_file_iterator;
|
typedef std::vector<file_entry>::const_reverse_iterator reverse_file_iterator;
|
||||||
|
|
||||||
file_iterator begin_files() const;
|
file_iterator begin_files() const;
|
||||||
@@ -654,11 +654,9 @@ public:
|
|||||||
reverse_file_iterator rend_files() const;
|
reverse_file_iterator rend_files() const;
|
||||||
|
|
||||||
int num_files() const;
|
int num_files() const;
|
||||||
const file_entry& file_at(int index) const;
|
file_entry const& file_at(int index) const;
|
||||||
|
|
||||||
const std::vector<announce_entry>& trackers() const;
|
std::vector<announce_entry> const& trackers() const;
|
||||||
|
|
||||||
int prioritize_tracker(int index);
|
|
||||||
|
|
||||||
size_type total_size() const;
|
size_type total_size() const;
|
||||||
size_type piece_length() const;
|
size_type piece_length() const;
|
||||||
@@ -720,12 +718,11 @@ void print(std::ostream& os) const;
|
|||||||
<p>The <tt class="literal"><span class="pre">print()</span></tt> function is there for debug purposes only. It will print the info from
|
<p>The <tt class="literal"><span class="pre">print()</span></tt> function is there for debug purposes only. It will print the info from
|
||||||
the torrent file to the given outstream.</p>
|
the torrent file to the given outstream.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="trackers-prioritize-tracker">
|
<div class="section" id="trackers">
|
||||||
<h2><a name="trackers-prioritize-tracker">trackers() prioritize_tracker()</a></h2>
|
<h2><a name="trackers">trackers()</a></h2>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
const std::vector<announce_entry>& trackers() const;
|
const std::vector<announce_entry>& trackers() const;
|
||||||
int prioritize_tracker(int index);
|
|
||||||
</pre>
|
</pre>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<p>The <tt class="literal"><span class="pre">trackers()</span></tt> function will return a sorted vector of <tt class="literal"><span class="pre">announce_entry</span></tt>.
|
<p>The <tt class="literal"><span class="pre">trackers()</span></tt> function will return a sorted vector of <tt class="literal"><span class="pre">announce_entry</span></tt>.
|
||||||
@@ -735,14 +732,11 @@ ones with lower tier will always be tried before the one with higher tier number
|
|||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
struct announce_entry
|
struct announce_entry
|
||||||
{
|
{
|
||||||
|
announce_entry(std::string const& url);
|
||||||
std::string url;
|
std::string url;
|
||||||
int tier;
|
int tier;
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
<p>The <tt class="literal"><span class="pre">prioritize_tracker()</span></tt> is used internally to move a tracker to the front
|
|
||||||
of its tier group. i.e. It will never be moved pass a tracker with a different tier
|
|
||||||
number. For more information about how multiple trackers are dealt with, see the
|
|
||||||
<a class="reference" href="http://home.elp.rr.com/tur/multitracker-spec.txt">specification</a>.</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="total-size-piece-length-piece-size-num-pieces">
|
<div class="section" id="total-size-piece-length-piece-size-num-pieces">
|
||||||
<h2><a name="total-size-piece-length-piece-size-num-pieces">total_size() piece_length() piece_size() num_pieces()</a></h2>
|
<h2><a name="total-size-piece-length-piece-size-num-pieces">total_size() piece_length() piece_size() num_pieces()</a></h2>
|
||||||
@@ -813,6 +807,9 @@ struct torrent_handle
|
|||||||
|
|
||||||
void set_tracker_login(std::string const& username, std::string const& password);
|
void set_tracker_login(std::string const& username, std::string const& password);
|
||||||
|
|
||||||
|
std::vector<announce_entry> const& trackers() const;
|
||||||
|
void replace_trackers(std::vector<announce_entry> const&);
|
||||||
|
|
||||||
void set_ratio(float ratio);
|
void set_ratio(float ratio);
|
||||||
void set_max_uploads(int max_uploads);
|
void set_max_uploads(int max_uploads);
|
||||||
void set_max_connections(int max_connections);
|
void set_max_connections(int max_connections);
|
||||||
@@ -840,6 +837,7 @@ struct torrent_handle
|
|||||||
<p>The default constructor will initialize the handle to an invalid state. Which means you cannot
|
<p>The default constructor will initialize the handle to an invalid state. Which means you cannot
|
||||||
perform any operation on it, unless you first assign it a valid handle. If you try to perform
|
perform any operation on it, unless you first assign it a valid handle. If you try to perform
|
||||||
any operation on an uninitialized handle, it will throw <tt class="literal"><span class="pre">invalid_handle</span></tt>.</p>
|
any operation on an uninitialized handle, it will throw <tt class="literal"><span class="pre">invalid_handle</span></tt>.</p>
|
||||||
|
<p><em>TODO: document ``trackers()`` and ``replace_trackers()``</em></p>
|
||||||
<div class="section" id="save-path">
|
<div class="section" id="save-path">
|
||||||
<h2><a name="save-path">save_path()</a></h2>
|
<h2><a name="save-path">save_path()</a></h2>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
@@ -1691,13 +1689,16 @@ struct file_error_alert: alert
|
|||||||
<p>This alert is generated on tracker time outs, premature disconnects, invalid response or
|
<p>This alert is generated on tracker time outs, premature disconnects, invalid response or
|
||||||
a HTTP response other than "200 OK". From the alert you can get the handle to the torrent
|
a HTTP response other than "200 OK". From the alert you can get the handle to the torrent
|
||||||
the tracker belongs to. This alert is generated as severity level <tt class="literal"><span class="pre">warning</span></tt>.</p>
|
the tracker belongs to. This alert is generated as severity level <tt class="literal"><span class="pre">warning</span></tt>.</p>
|
||||||
|
<p>The <tt class="literal"><span class="pre">times_in_row</span></tt> member says how many times in a row this tracker has failed.</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
struct tracker_alert: alert
|
struct tracker_alert: alert
|
||||||
{
|
{
|
||||||
tracker_alert(const torrent_handle& h, const std::string& msg);
|
tracker_alert(const torrent_handle& h, int times
|
||||||
|
, const std::string& msg);
|
||||||
virtual std::auto_ptr<alert> clone() const;
|
virtual std::auto_ptr<alert> clone() const;
|
||||||
|
|
||||||
torrent_handle handle;
|
torrent_handle handle;
|
||||||
|
int times_in_row;
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -559,7 +559,7 @@ The ``torrent_info`` has the following synopsis::
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
torrent_info(const entry& torrent_file)
|
torrent_info(entry const& torrent_file)
|
||||||
torrent_info(int piece_size, const char* name);
|
torrent_info(int piece_size, const char* name);
|
||||||
|
|
||||||
entry create_torrent() const;
|
entry create_torrent() const;
|
||||||
@@ -569,7 +569,7 @@ The ``torrent_info`` has the following synopsis::
|
|||||||
void add_tracker(std::string const& url, int tier = 0);
|
void add_tracker(std::string const& url, int tier = 0);
|
||||||
void add_file(boost::filesystem::path file, size_type size);
|
void add_file(boost::filesystem::path file, size_type size);
|
||||||
|
|
||||||
typedef std::vector>file_entry>::const_iterator file_iterator;
|
typedef std::vector<file_entry>::const_iterator file_iterator;
|
||||||
typedef std::vector<file_entry>::const_reverse_iterator reverse_file_iterator;
|
typedef std::vector<file_entry>::const_reverse_iterator reverse_file_iterator;
|
||||||
|
|
||||||
file_iterator begin_files() const;
|
file_iterator begin_files() const;
|
||||||
@@ -578,11 +578,9 @@ The ``torrent_info`` has the following synopsis::
|
|||||||
reverse_file_iterator rend_files() const;
|
reverse_file_iterator rend_files() const;
|
||||||
|
|
||||||
int num_files() const;
|
int num_files() const;
|
||||||
const file_entry& file_at(int index) const;
|
file_entry const& file_at(int index) const;
|
||||||
|
|
||||||
const std::vector<announce_entry>& trackers() const;
|
std::vector<announce_entry> const& trackers() const;
|
||||||
|
|
||||||
int prioritize_tracker(int index);
|
|
||||||
|
|
||||||
size_type total_size() const;
|
size_type total_size() const;
|
||||||
size_type piece_length() const;
|
size_type piece_length() const;
|
||||||
@@ -649,13 +647,12 @@ The ``print()`` function is there for debug purposes only. It will print the inf
|
|||||||
the torrent file to the given outstream.
|
the torrent file to the given outstream.
|
||||||
|
|
||||||
|
|
||||||
trackers() prioritize_tracker()
|
trackers()
|
||||||
-------------------------------
|
----------
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
const std::vector<announce_entry>& trackers() const;
|
const std::vector<announce_entry>& trackers() const;
|
||||||
int prioritize_tracker(int index);
|
|
||||||
|
|
||||||
The ``trackers()`` function will return a sorted vector of ``announce_entry``.
|
The ``trackers()`` function will return a sorted vector of ``announce_entry``.
|
||||||
Each announce entry contains a string, which is the tracker url, and a tier index. The
|
Each announce entry contains a string, which is the tracker url, and a tier index. The
|
||||||
@@ -666,17 +663,11 @@ ones with lower tier will always be tried before the one with higher tier number
|
|||||||
|
|
||||||
struct announce_entry
|
struct announce_entry
|
||||||
{
|
{
|
||||||
|
announce_entry(std::string const& url);
|
||||||
std::string url;
|
std::string url;
|
||||||
int tier;
|
int tier;
|
||||||
};
|
};
|
||||||
|
|
||||||
The ``prioritize_tracker()`` is used internally to move a tracker to the front
|
|
||||||
of its tier group. i.e. It will never be moved pass a tracker with a different tier
|
|
||||||
number. For more information about how multiple trackers are dealt with, see the
|
|
||||||
specification_.
|
|
||||||
|
|
||||||
.. _specification: http://home.elp.rr.com/tur/multitracker-spec.txt
|
|
||||||
|
|
||||||
|
|
||||||
total_size() piece_length() piece_size() num_pieces()
|
total_size() piece_length() piece_size() num_pieces()
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
@@ -756,6 +747,9 @@ Its declaration looks like this::
|
|||||||
|
|
||||||
void set_tracker_login(std::string const& username, std::string const& password);
|
void set_tracker_login(std::string const& username, std::string const& password);
|
||||||
|
|
||||||
|
std::vector<announce_entry> const& trackers() const;
|
||||||
|
void replace_trackers(std::vector<announce_entry> const&);
|
||||||
|
|
||||||
void set_ratio(float ratio);
|
void set_ratio(float ratio);
|
||||||
void set_max_uploads(int max_uploads);
|
void set_max_uploads(int max_uploads);
|
||||||
void set_max_connections(int max_connections);
|
void set_max_connections(int max_connections);
|
||||||
@@ -784,6 +778,7 @@ The default constructor will initialize the handle to an invalid state. Which me
|
|||||||
perform any operation on it, unless you first assign it a valid handle. If you try to perform
|
perform any operation on it, unless you first assign it a valid handle. If you try to perform
|
||||||
any operation on an uninitialized handle, it will throw ``invalid_handle``.
|
any operation on an uninitialized handle, it will throw ``invalid_handle``.
|
||||||
|
|
||||||
|
*TODO: document ``trackers()`` and ``replace_trackers()``*
|
||||||
|
|
||||||
save_path()
|
save_path()
|
||||||
-----------
|
-----------
|
||||||
@@ -1709,17 +1704,22 @@ This alert is generated on tracker time outs, premature disconnects, invalid res
|
|||||||
a HTTP response other than "200 OK". From the alert you can get the handle to the torrent
|
a HTTP response other than "200 OK". From the alert you can get the handle to the torrent
|
||||||
the tracker belongs to. This alert is generated as severity level ``warning``.
|
the tracker belongs to. This alert is generated as severity level ``warning``.
|
||||||
|
|
||||||
|
The ``times_in_row`` member says how many times in a row this tracker has failed.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
struct tracker_alert: alert
|
struct tracker_alert: alert
|
||||||
{
|
{
|
||||||
tracker_alert(const torrent_handle& h, const std::string& msg);
|
tracker_alert(const torrent_handle& h, int times
|
||||||
|
, const std::string& msg);
|
||||||
virtual std::auto_ptr<alert> clone() const;
|
virtual std::auto_ptr<alert> clone() const;
|
||||||
|
|
||||||
torrent_handle handle;
|
torrent_handle handle;
|
||||||
|
int times_in_row;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hash_failed_alert
|
hash_failed_alert
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
@@ -43,15 +43,18 @@ namespace libtorrent
|
|||||||
struct tracker_alert: alert
|
struct tracker_alert: alert
|
||||||
{
|
{
|
||||||
tracker_alert(const torrent_handle& h
|
tracker_alert(const torrent_handle& h
|
||||||
|
, int times
|
||||||
, const std::string& msg)
|
, const std::string& msg)
|
||||||
: alert(alert::warning, msg)
|
: alert(alert::warning, msg)
|
||||||
, handle(h)
|
, handle(h)
|
||||||
|
, times_in_row(times)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
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;
|
torrent_handle handle;
|
||||||
|
int times_in_row;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hash_failed_alert: alert
|
struct hash_failed_alert: alert
|
||||||
|
@@ -93,10 +93,6 @@ namespace libtorrent
|
|||||||
|
|
||||||
struct invalid_encoding: std::exception
|
struct invalid_encoding: std::exception
|
||||||
{
|
{
|
||||||
invalid_encoding()
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
}
|
|
||||||
virtual const char* what() const throw() { return "invalid bencoding"; }
|
virtual const char* what() const throw() { return "invalid bencoding"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -301,6 +301,11 @@ namespace libtorrent
|
|||||||
piece_manager& filesystem();
|
piece_manager& filesystem();
|
||||||
torrent_info const& torrent_file() const { return m_torrent_file; }
|
torrent_info const& torrent_file() const { return m_torrent_file; }
|
||||||
|
|
||||||
|
std::vector<announce_entry> const& trackers() const
|
||||||
|
{ return m_trackers; }
|
||||||
|
|
||||||
|
void replace_trackers(std::vector<announce_entry> const& urls);
|
||||||
|
|
||||||
torrent_handle get_handle() const;
|
torrent_handle get_handle() const;
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
@@ -343,6 +348,7 @@ namespace libtorrent
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
void try_next_tracker();
|
void try_next_tracker();
|
||||||
|
int prioritize_tracker(int tracker_index);
|
||||||
|
|
||||||
torrent_info m_torrent_file;
|
torrent_info m_torrent_file;
|
||||||
|
|
||||||
@@ -396,11 +402,13 @@ namespace libtorrent
|
|||||||
|
|
||||||
std::auto_ptr<piece_picker> m_picker;
|
std::auto_ptr<piece_picker> m_picker;
|
||||||
|
|
||||||
|
std::vector<announce_entry> m_trackers;
|
||||||
// this is an index into m_torrent_file.trackers()
|
// this is an index into m_torrent_file.trackers()
|
||||||
int m_last_working_tracker;
|
int m_last_working_tracker;
|
||||||
int m_currently_trying_tracker;
|
int m_currently_trying_tracker;
|
||||||
// the number of connection attempts that has
|
// the number of connection attempts that has
|
||||||
// failed in a row
|
// failed in a row, this is currently used to
|
||||||
|
// determine the timeout until next try.
|
||||||
int m_failed_trackers;
|
int m_failed_trackers;
|
||||||
|
|
||||||
// this is a counter that is increased every
|
// this is a counter that is increased every
|
||||||
|
@@ -183,6 +183,9 @@ namespace libtorrent
|
|||||||
torrent_status status() const;
|
torrent_status status() const;
|
||||||
void get_download_queue(std::vector<partial_piece_info>& queue) const;
|
void get_download_queue(std::vector<partial_piece_info>& queue) const;
|
||||||
|
|
||||||
|
std::vector<announce_entry> const& trackers() const;
|
||||||
|
void replace_trackers(std::vector<announce_entry> const&);
|
||||||
|
|
||||||
bool has_metadata() const;
|
bool has_metadata() const;
|
||||||
const torrent_info& get_torrent_info() const;
|
const torrent_info& get_torrent_info() const;
|
||||||
bool is_valid() const;
|
bool is_valid() const;
|
||||||
|
@@ -67,6 +67,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
struct announce_entry
|
struct announce_entry
|
||||||
{
|
{
|
||||||
|
announce_entry(std::string const& u): url(u), tier(0) {}
|
||||||
std::string url;
|
std::string url;
|
||||||
int tier;
|
int tier;
|
||||||
};
|
};
|
||||||
@@ -115,11 +116,6 @@ namespace libtorrent
|
|||||||
|
|
||||||
const std::vector<announce_entry>& trackers() const { return m_urls; }
|
const std::vector<announce_entry>& trackers() const { return m_urls; }
|
||||||
|
|
||||||
// this will move the tracker with the given index
|
|
||||||
// to a prioritized position in the list (move it towards
|
|
||||||
// the begining) and return the new index to the tracker.
|
|
||||||
int prioritize_tracker(int index);
|
|
||||||
|
|
||||||
size_type total_size() const { assert(m_piece_length > 0); return m_total_size; }
|
size_type total_size() const { assert(m_piece_length > 0); return m_total_size; }
|
||||||
size_type piece_length() const { assert(m_piece_length > 0); return m_piece_length; }
|
size_type piece_length() const { assert(m_piece_length > 0); return m_piece_length; }
|
||||||
int num_pieces() const { assert(m_piece_length > 0); return (int)m_piece_hash.size(); }
|
int num_pieces() const { assert(m_piece_length > 0); return (int)m_piece_hash.size(); }
|
||||||
|
@@ -162,6 +162,7 @@ namespace libtorrent
|
|||||||
, m_policy()
|
, m_policy()
|
||||||
, m_ses(ses)
|
, m_ses(ses)
|
||||||
, m_picker(0)
|
, m_picker(0)
|
||||||
|
, m_trackers(m_torrent_file.trackers())
|
||||||
, m_last_working_tracker(-1)
|
, m_last_working_tracker(-1)
|
||||||
, m_currently_trying_tracker(0)
|
, m_currently_trying_tracker(0)
|
||||||
, m_failed_trackers(0)
|
, m_failed_trackers(0)
|
||||||
@@ -213,6 +214,7 @@ namespace libtorrent
|
|||||||
, m_download_bandwidth_limit(std::numeric_limits<int>::max())
|
, m_download_bandwidth_limit(std::numeric_limits<int>::max())
|
||||||
, m_save_path(save_path)
|
, m_save_path(save_path)
|
||||||
{
|
{
|
||||||
|
m_trackers.push_back(announce_entry(tracker_url));
|
||||||
m_requested_metadata.resize(256, 0);
|
m_requested_metadata.resize(256, 0);
|
||||||
m_policy.reset(new policy(this));
|
m_policy.reset(new policy(this));
|
||||||
m_torrent_file.add_tracker(tracker_url);
|
m_torrent_file.add_tracker(tracker_url);
|
||||||
@@ -265,7 +267,7 @@ namespace libtorrent
|
|||||||
if (interval < 60) interval = 60;
|
if (interval < 60) interval = 60;
|
||||||
|
|
||||||
m_last_working_tracker
|
m_last_working_tracker
|
||||||
= m_torrent_file.prioritize_tracker(m_currently_trying_tracker);
|
= prioritize_tracker(m_currently_trying_tracker);
|
||||||
m_next_request = boost::posix_time::second_clock::local_time()
|
m_next_request = boost::posix_time::second_clock::local_time()
|
||||||
+ boost::posix_time::seconds(m_duration);
|
+ boost::posix_time::seconds(m_duration);
|
||||||
m_currently_trying_tracker = 0;
|
m_currently_trying_tracker = 0;
|
||||||
@@ -416,15 +418,20 @@ namespace libtorrent
|
|||||||
|
|
||||||
// decrease the trust point of all peers that sent
|
// decrease the trust point of all peers that sent
|
||||||
// parts of this piece.
|
// parts of this piece.
|
||||||
for (std::vector<address>::iterator i = downloaders.begin();
|
// first, build a set of all peers that participated
|
||||||
i != downloaders.end();
|
std::set<address> peers;
|
||||||
++i)
|
std::copy(downloaders.begin(), downloaders.end(), std::inserter(peers, peers.begin()));
|
||||||
|
|
||||||
|
for (std::set<address>::iterator i = peers.begin()
|
||||||
|
, end(peers.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
peer_iterator p = m_connections.find(*i);
|
peer_iterator p = m_connections.find(*i);
|
||||||
if (p == m_connections.end()) continue;
|
if (p == m_connections.end()) continue;
|
||||||
p->second->received_invalid_data();
|
p->second->received_invalid_data();
|
||||||
|
|
||||||
if (p->second->trust_points() <= -7)
|
// either, we have received too many failed hashes
|
||||||
|
// or this was the only peer that sent us this piece.
|
||||||
|
if (p->second->trust_points() <= -7 || peers.size() == 1)
|
||||||
{
|
{
|
||||||
// we don't trust this peer anymore
|
// we don't trust this peer anymore
|
||||||
// ban it.
|
// ban it.
|
||||||
@@ -467,9 +474,11 @@ namespace libtorrent
|
|||||||
|
|
||||||
// increase the trust point of all peers that sent
|
// increase the trust point of all peers that sent
|
||||||
// parts of this piece.
|
// parts of this piece.
|
||||||
for (std::vector<address>::iterator i = downloaders.begin();
|
std::set<address> peers;
|
||||||
i != downloaders.end();
|
std::copy(downloaders.begin(), downloaders.end(), std::inserter(peers, peers.begin()));
|
||||||
++i)
|
|
||||||
|
for (std::set<address>::iterator i = peers.begin()
|
||||||
|
, end(peers.end()); i != end; ++i)
|
||||||
{
|
{
|
||||||
peer_iterator p = m_connections.find(*i);
|
peer_iterator p = m_connections.find(*i);
|
||||||
if (p == m_connections.end()) continue;
|
if (p == m_connections.end()) continue;
|
||||||
@@ -487,6 +496,15 @@ namespace libtorrent
|
|||||||
return m_username + ":" + m_password;
|
return m_username + ":" + m_password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void torrent::replace_trackers(std::vector<announce_entry> const& urls)
|
||||||
|
{
|
||||||
|
assert(!urls.empty());
|
||||||
|
m_trackers = urls;
|
||||||
|
if (m_currently_trying_tracker >= (int)m_trackers.size())
|
||||||
|
m_currently_trying_tracker = m_trackers.size()-1;
|
||||||
|
m_last_working_tracker = -1;
|
||||||
|
}
|
||||||
|
|
||||||
tracker_request torrent::generate_tracker_request()
|
tracker_request torrent::generate_tracker_request()
|
||||||
{
|
{
|
||||||
m_duration = 1800;
|
m_duration = 1800;
|
||||||
@@ -502,7 +520,7 @@ namespace libtorrent
|
|||||||
req.left = bytes_left();
|
req.left = bytes_left();
|
||||||
if (req.left == -1) req.left = 1000;
|
if (req.left == -1) req.left = 1000;
|
||||||
req.event = m_event;
|
req.event = m_event;
|
||||||
req.url = m_torrent_file.trackers()[m_currently_trying_tracker].url;
|
req.url = m_trackers[m_currently_trying_tracker].url;
|
||||||
req.num_want = std::max(
|
req.num_want = std::max(
|
||||||
(m_policy->get_max_connections()
|
(m_policy->get_max_connections()
|
||||||
- m_policy->num_peers()), 0);
|
- m_policy->num_peers()), 0);
|
||||||
@@ -637,12 +655,27 @@ namespace libtorrent
|
|||||||
force_tracker_request();
|
force_tracker_request();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this will move the tracker with the given index
|
||||||
|
// to a prioritized position in the list (move it towards
|
||||||
|
// the begining) and return the new index to the tracker.
|
||||||
|
int torrent::prioritize_tracker(int index)
|
||||||
|
{
|
||||||
|
assert(index >= 0);
|
||||||
|
if (index >= (int)m_trackers.size()) return (int)m_trackers.size()-1;
|
||||||
|
|
||||||
|
while (index > 0 && m_trackers[index].tier == m_trackers[index-1].tier)
|
||||||
|
{
|
||||||
|
std::swap(m_trackers[index].url, m_trackers[index-1].url);
|
||||||
|
--index;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
void torrent::try_next_tracker()
|
void torrent::try_next_tracker()
|
||||||
{
|
{
|
||||||
++m_currently_trying_tracker;
|
++m_currently_trying_tracker;
|
||||||
|
|
||||||
if ((unsigned)m_currently_trying_tracker >= m_torrent_file.trackers().size())
|
if ((unsigned)m_currently_trying_tracker >= m_trackers.size())
|
||||||
{
|
{
|
||||||
int delay = tracker_retry_delay_min
|
int delay = tracker_retry_delay_min
|
||||||
+ std::min(m_failed_trackers, (int)tracker_failed_max)
|
+ std::min(m_failed_trackers, (int)tracker_failed_max)
|
||||||
@@ -659,6 +692,7 @@ namespace libtorrent
|
|||||||
// don't delay before trying the next tracker
|
// don't delay before trying the next tracker
|
||||||
m_next_request = boost::posix_time::second_clock::local_time();
|
m_next_request = boost::posix_time::second_clock::local_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent::check_files(detail::piece_checker_data& data,
|
void torrent::check_files(detail::piece_checker_data& data,
|
||||||
@@ -921,7 +955,7 @@ namespace libtorrent
|
|||||||
if (m_last_working_tracker >= 0)
|
if (m_last_working_tracker >= 0)
|
||||||
{
|
{
|
||||||
st.current_tracker
|
st.current_tracker
|
||||||
= m_torrent_file.trackers()[m_last_working_tracker].url;
|
= m_trackers[m_last_working_tracker].url;
|
||||||
}
|
}
|
||||||
|
|
||||||
st.progress = st.total_done
|
st.progress = st.total_done
|
||||||
@@ -1060,9 +1094,10 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << "tracker: \""
|
s << "tracker: \""
|
||||||
<< m_torrent_file.trackers()[m_currently_trying_tracker].url
|
<< m_trackers[m_currently_trying_tracker].url
|
||||||
<< "\" timed out";
|
<< "\" timed out";
|
||||||
m_ses.m_alerts.post_alert(tracker_alert(get_handle(), s.str()));
|
m_ses.m_alerts.post_alert(tracker_alert(get_handle()
|
||||||
|
, m_failed_trackers, s.str()));
|
||||||
}
|
}
|
||||||
try_next_tracker();
|
try_next_tracker();
|
||||||
}
|
}
|
||||||
@@ -1079,9 +1114,10 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << "tracker: \""
|
s << "tracker: \""
|
||||||
<< m_torrent_file.trackers()[m_currently_trying_tracker].url
|
<< m_trackers[m_currently_trying_tracker].url
|
||||||
<< "\" " << str;
|
<< "\" " << str;
|
||||||
m_ses.m_alerts.post_alert(tracker_alert(get_handle(), s.str()));
|
m_ses.m_alerts.post_alert(tracker_alert(get_handle()
|
||||||
|
, m_failed_trackers, s.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -313,6 +313,22 @@ namespace libtorrent
|
|||||||
throw invalid_handle();
|
throw invalid_handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<announce_entry> const& torrent_handle::trackers() const
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
|
return call_member<std::vector<announce_entry> const&>(m_ses
|
||||||
|
, m_chk, m_info_hash, boost::bind(&torrent::trackers, _1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void torrent_handle::replace_trackers(std::vector<announce_entry> const& urls)
|
||||||
|
{
|
||||||
|
INVARIANT_CHECK;
|
||||||
|
|
||||||
|
call_member<void>(m_ses, m_chk, m_info_hash
|
||||||
|
, boost::bind(&torrent::replace_trackers, _1, urls));
|
||||||
|
}
|
||||||
|
|
||||||
const torrent_info& torrent_handle::get_torrent_info() const
|
const torrent_info& torrent_handle::get_torrent_info() const
|
||||||
{
|
{
|
||||||
INVARIANT_CHECK;
|
INVARIANT_CHECK;
|
||||||
|
@@ -193,9 +193,8 @@ namespace libtorrent
|
|||||||
const entry::list_type& ll = j->list();
|
const entry::list_type& ll = j->list();
|
||||||
for (entry::list_type::const_iterator k = ll.begin(); k != ll.end(); ++k)
|
for (entry::list_type::const_iterator k = ll.begin(); k != ll.end(); ++k)
|
||||||
{
|
{
|
||||||
announce_entry e;
|
announce_entry e(k->string());
|
||||||
e.tier = (int)std::distance(l.begin(), j);
|
e.tier = (int)std::distance(l.begin(), j);
|
||||||
e.url = k->string();
|
|
||||||
m_urls.push_back(e);
|
m_urls.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,10 +219,7 @@ namespace libtorrent
|
|||||||
{
|
{
|
||||||
i = torrent_file.find_key("announce");
|
i = torrent_file.find_key("announce");
|
||||||
if (i == 0) throw invalid_torrent_file();
|
if (i == 0) throw invalid_torrent_file();
|
||||||
announce_entry e;
|
m_urls.push_back(announce_entry(i->string()));
|
||||||
e.tier = 0;
|
|
||||||
e.url = i->string();
|
|
||||||
m_urls.push_back(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract creation date
|
// extract creation date
|
||||||
@@ -271,8 +267,7 @@ namespace libtorrent
|
|||||||
|
|
||||||
void torrent_info::add_tracker(std::string const& url, int tier)
|
void torrent_info::add_tracker(std::string const& url, int tier)
|
||||||
{
|
{
|
||||||
announce_entry e;
|
announce_entry e(url);
|
||||||
e.url = url;
|
|
||||||
e.tier = tier;
|
e.tier = tier;
|
||||||
m_urls.push_back(e);
|
m_urls.push_back(e);
|
||||||
}
|
}
|
||||||
@@ -414,19 +409,6 @@ namespace libtorrent
|
|||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int torrent_info::prioritize_tracker(int index)
|
|
||||||
{
|
|
||||||
assert(index >= 0);
|
|
||||||
if (index >= (int)m_urls.size()) return (int)m_urls.size()-1;
|
|
||||||
|
|
||||||
while (index > 0 && m_urls[index].tier == m_urls[index-1].tier)
|
|
||||||
{
|
|
||||||
std::swap(m_urls[index].url, m_urls[index-1].url);
|
|
||||||
--index;
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
void torrent_info::print(std::ostream& os) const
|
void torrent_info::print(std::ostream& os) const
|
||||||
{
|
{
|
||||||
os << "trackers:\n";
|
os << "trackers:\n";
|
||||||
|
Reference in New Issue
Block a user