*** empty log message ***
This commit is contained in:
parent
734ff429c2
commit
94919f9806
145
docs/index.html
145
docs/index.html
|
@ -35,21 +35,31 @@
|
||||||
<li><a class="reference" href="#status" id="id14" name="id14">status()</a></li>
|
<li><a class="reference" href="#status" id="id14" name="id14">status()</a></li>
|
||||||
<li><a class="reference" href="#get-download-queue" id="id15" name="id15">get_download_queue()</a></li>
|
<li><a class="reference" href="#get-download-queue" id="id15" name="id15">get_download_queue()</a></li>
|
||||||
<li><a class="reference" href="#get-peer-info" id="id16" name="id16">get_peer_info()</a></li>
|
<li><a class="reference" href="#get-peer-info" id="id16" name="id16">get_peer_info()</a></li>
|
||||||
|
<li><a class="reference" href="#get-torrent-info" id="id17" name="id17">get_torrent_info()</a></li>
|
||||||
|
<li><a class="reference" href="#is-valid" id="id18" name="id18">is_valid()</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a class="reference" href="#address" id="id17" name="id17">address</a></li>
|
<li><a class="reference" href="#address" id="id19" name="id19">address</a></li>
|
||||||
<li><a class="reference" href="#http-settings" id="id18" name="id18">http_settings</a></li>
|
<li><a class="reference" href="#http-settings" id="id20" name="id20">http_settings</a></li>
|
||||||
<li><a class="reference" href="#big-number" id="id19" name="id19">big_number</a></li>
|
<li><a class="reference" href="#big-number" id="id21" name="id21">big_number</a></li>
|
||||||
<li><a class="reference" href="#hasher" id="id20" name="id20">hasher</a></li>
|
<li><a class="reference" href="#hasher" id="id22" name="id22">hasher</a></li>
|
||||||
<li><a class="reference" href="#example-usage" id="id21" name="id21">example usage</a><ul>
|
<li><a class="reference" href="#exceptions" id="id23" name="id23">exceptions</a><ul>
|
||||||
<li><a class="reference" href="#dump-torrent" id="id22" name="id22">dump_torrent</a></li>
|
<li><a class="reference" href="#invalid-handle" id="id24" name="id24">invalid_handle</a></li>
|
||||||
<li><a class="reference" href="#simple-client" id="id23" name="id23">simple client</a></li>
|
<li><a class="reference" href="#duplicate-torrent" id="id25" name="id25">duplicate_torrent</a></li>
|
||||||
|
<li><a class="reference" href="#invalid-encoding" id="id26" name="id26">invalid_encoding</a></li>
|
||||||
|
<li><a class="reference" href="#type-error" id="id27" name="id27">type_error</a></li>
|
||||||
|
<li><a class="reference" href="#invalid-torrent-file" id="id28" name="id28">invalid_torrent_file</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a class="reference" href="#example-usage" id="id29" name="id29">example usage</a><ul>
|
||||||
|
<li><a class="reference" href="#dump-torrent" id="id30" name="id30">dump_torrent</a></li>
|
||||||
|
<li><a class="reference" href="#simple-client" id="id31" name="id31">simple client</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a class="reference" href="#feedback" id="id24" name="id24">Feedback</a></li>
|
<li><a class="reference" href="#feedback" id="id32" name="id32">Feedback</a></li>
|
||||||
<li><a class="reference" href="#aknowledgements" id="id25" name="id25">Aknowledgements</a></li>
|
<li><a class="reference" href="#aknowledgements" id="id33" name="id33">Aknowledgements</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="introduction">
|
<div class="section" id="introduction">
|
||||||
|
@ -159,7 +169,8 @@ The main thread will be idle as long it doesn't have any torrents to participate
|
||||||
You add torrents through the <tt class="literal"><span class="pre">add_torrent()</span></tt>-function where you give an
|
You add torrents through the <tt class="literal"><span class="pre">add_torrent()</span></tt>-function where you give an
|
||||||
object representing the information found in the torrent file and the path where you
|
object representing the information found in the torrent file and the path where you
|
||||||
want to save the files. The <tt class="literal"><span class="pre">save_path</span></tt> will be prepended to the directory-
|
want to save the files. The <tt class="literal"><span class="pre">save_path</span></tt> will be prepended to the directory-
|
||||||
structure in the torrent-file.</p>
|
structure in the torrent-file. <tt class="literal"><span class="pre">add_torrent</span></tt> will throw <tt class="literal"><span class="pre">duplicate_torrent</span></tt> exception
|
||||||
|
if the torrent already exists in the session.</p>
|
||||||
<p><tt class="literal"><span class="pre">remove_torrent()</span></tt> will close all peer connections associated with the torrent and tell
|
<p><tt class="literal"><span class="pre">remove_torrent()</span></tt> will close all peer connections associated with the torrent and tell
|
||||||
the tracker that we've stopped participating in the swarm.</p>
|
the tracker that we've stopped participating in the swarm.</p>
|
||||||
<p>If the torrent you are trying to add already exists in the session (is either queued
|
<p>If the torrent you are trying to add already exists in the session (is either queued
|
||||||
|
@ -388,9 +399,11 @@ struct torrent_handle
|
||||||
{
|
{
|
||||||
torrent_handle();
|
torrent_handle();
|
||||||
|
|
||||||
torrent_status status() const;
|
torrent_status status();
|
||||||
void get_download_queue(std::vector<partial_piece_info>& queue);
|
void get_download_queue(std::vector<partial_piece_info>& queue);
|
||||||
void get_peer_info(std::vector<peer_info>& v);
|
void get_peer_info(std::vector<peer_info>& v);
|
||||||
|
const torrent_info& get_torrent_info();
|
||||||
|
bool is_valid();
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
<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
|
||||||
|
@ -399,7 +412,8 @@ any operation they will simply return.</p>
|
||||||
<div class="section" id="status">
|
<div class="section" id="status">
|
||||||
<h3><a class="toc-backref" href="#id14" name="status">status()</a></h3>
|
<h3><a class="toc-backref" href="#id14" name="status">status()</a></h3>
|
||||||
<p><tt class="literal"><span class="pre">status()</span></tt> will return a structure with information about the status of this
|
<p><tt class="literal"><span class="pre">status()</span></tt> will return a structure with information about the status of this
|
||||||
torrent. It contains the following fields:</p>
|
torrent. If the <tt class="literal"><span class="pre">torrent_handle</span></tt> is invalid, it will throw <tt class="literal"><span class="pre">invalid_handle</span></tt> exception.
|
||||||
|
It contains the following fields:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
struct torrent_status
|
struct torrent_status
|
||||||
{
|
{
|
||||||
|
@ -430,11 +444,6 @@ current task is in the <tt class="literal"><span class="pre">state</span></tt> m
|
||||||
<col width="72%" />
|
<col width="72%" />
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<tbody valign="top">
|
<tbody valign="top">
|
||||||
<tr><td><tt class="literal"><span class="pre">invalid_handle</span></tt></td>
|
|
||||||
<td>This will be the state if you called status on an
|
|
||||||
uninitialized handle (a handle that was constructed
|
|
||||||
with the default constructor).</td>
|
|
||||||
</tr>
|
|
||||||
<tr><td><tt class="literal"><span class="pre">queued_for_checking</span></tt></td>
|
<tr><td><tt class="literal"><span class="pre">queued_for_checking</span></tt></td>
|
||||||
<td>The torrent is in the queue for being checked. But there
|
<td>The torrent is in the queue for being checked. But there
|
||||||
currently is another torrent that are being checked.
|
currently is another torrent that are being checked.
|
||||||
|
@ -498,8 +507,10 @@ may pass then.</p>
|
||||||
<div class="section" id="get-peer-info">
|
<div class="section" id="get-peer-info">
|
||||||
<h3><a class="toc-backref" href="#id16" name="get-peer-info">get_peer_info()</a></h3>
|
<h3><a class="toc-backref" href="#id16" name="get-peer-info">get_peer_info()</a></h3>
|
||||||
<p><tt class="literal"><span class="pre">get_peer_info()</span></tt> takes a reference to a vector that will be cleared and filled
|
<p><tt class="literal"><span class="pre">get_peer_info()</span></tt> takes a reference to a vector that will be cleared and filled
|
||||||
with one entry for each peer connected to this torrent. Each entry contains information about
|
with one entry for each peer connected to this torrent, given the handle is valid. If the
|
||||||
that particular peer. It contains the following information:</p>
|
<tt class="literal"><span class="pre">torrent_handle</span></tt> is invalid, it will throw <tt class="literal"><span class="pre">invalid_handle</span></tt> exception. Each entry in
|
||||||
|
the vector contains information about that particular peer. It contains the following
|
||||||
|
fields:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
struct peer_info
|
struct peer_info
|
||||||
{
|
{
|
||||||
|
@ -543,9 +554,20 @@ or if the peer miss that piece (set to false).</p>
|
||||||
<p><tt class="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="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.</p>
|
peer every second. It may be -1 if there's no limit.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="section" id="get-torrent-info">
|
||||||
|
<h3><a class="toc-backref" href="#id17" name="get-torrent-info">get_torrent_info()</a></h3>
|
||||||
|
<p>Returns a const reference to the <tt class="literal"><span class="pre">torrent_info</span></tt> object associated with this torrent.
|
||||||
|
This reference is valid as long as the <tt class="literal"><span class="pre">torrent_handle</span></tt> is valid, no longer. If the
|
||||||
|
<tt class="literal"><span class="pre">torrent_handle</span></tt> is invalid, <tt class="literal"><span class="pre">invalid_handle</span></tt> exception will be thrown.</p>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="is-valid">
|
||||||
|
<h3><a class="toc-backref" href="#id18" name="is-valid">is_valid()</a></h3>
|
||||||
|
<p>Returns true if this handle refers to a valid torrent and false if it hasn't been initialized
|
||||||
|
or if the torrent it refers to has been aborted.</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="address">
|
<div class="section" id="address">
|
||||||
<h2><a class="toc-backref" href="#id17" name="address">address</a></h2>
|
<h2><a class="toc-backref" href="#id19" name="address">address</a></h2>
|
||||||
<p>The <tt class="literal"><span class="pre">address</span></tt> class represents a name of a network endpoint (usually referred to as
|
<p>The <tt class="literal"><span class="pre">address</span></tt> class represents a name of a network endpoint (usually referred to as
|
||||||
IP-address) and a port number. This is the same thing as a <tt class="literal"><span class="pre">sockaddr_in</span></tt> would contain.
|
IP-address) and a port number. This is the same thing as a <tt class="literal"><span class="pre">sockaddr_in</span></tt> would contain.
|
||||||
Its declaration looks like this:</p>
|
Its declaration looks like this:</p>
|
||||||
|
@ -554,8 +576,7 @@ class address
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
address();
|
address();
|
||||||
address(
|
address(unsigned char a
|
||||||
unsigned char a
|
|
||||||
, unsigned char b
|
, unsigned char b
|
||||||
, unsigned char c
|
, unsigned char c
|
||||||
, unsigned char d
|
, unsigned char d
|
||||||
|
@ -579,7 +600,7 @@ while it does the DNS lookup, it returns a string that points to the address rep
|
||||||
<p><tt class="literal"><span class="pre">ip()</span></tt> will return the 32-bit ip-address as an integer. <tt class="literal"><span class="pre">port()</span></tt> returns the port number.</p>
|
<p><tt class="literal"><span class="pre">ip()</span></tt> will return the 32-bit ip-address as an integer. <tt class="literal"><span class="pre">port()</span></tt> returns the port number.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="http-settings">
|
<div class="section" id="http-settings">
|
||||||
<h2><a class="toc-backref" href="#id18" name="http-settings">http_settings</a></h2>
|
<h2><a class="toc-backref" href="#id20" name="http-settings">http_settings</a></h2>
|
||||||
<p>You have some control over tracker requests through the <tt class="literal"><span class="pre">http_settings</span></tt> object. You
|
<p>You have some control over tracker requests through the <tt class="literal"><span class="pre">http_settings</span></tt> object. You
|
||||||
create it and fill it with your settings and the use <tt class="literal"><span class="pre">session::set_http_settings()</span></tt>
|
create it and fill it with your settings and the use <tt class="literal"><span class="pre">session::set_http_settings()</span></tt>
|
||||||
to apply them. You have control over proxy and authorization settings and also the user-agent
|
to apply them. You have control over proxy and authorization settings and also the user-agent
|
||||||
|
@ -607,9 +628,10 @@ on the uncompressed data. So, if you get 20 bytes of gzip response that'll
|
||||||
expand to 2 megs, it will be interrupted before the entire response has been
|
expand to 2 megs, it will be interrupted before the entire response has been
|
||||||
uncompressed (given your limit is lower than 2 megs). Default limit is
|
uncompressed (given your limit is lower than 2 megs). Default limit is
|
||||||
1 megabyte.</p>
|
1 megabyte.</p>
|
||||||
|
<p>TODO: finish document http_settings</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="big-number">
|
<div class="section" id="big-number">
|
||||||
<h2><a class="toc-backref" href="#id19" name="big-number">big_number</a></h2>
|
<h2><a class="toc-backref" href="#id21" name="big-number">big_number</a></h2>
|
||||||
<p>Both the <tt class="literal"><span class="pre">peer_id</span></tt> and <tt class="literal"><span class="pre">sha1_hash</span></tt> types are typedefs of the class
|
<p>Both the <tt class="literal"><span class="pre">peer_id</span></tt> and <tt class="literal"><span class="pre">sha1_hash</span></tt> types are typedefs of the class
|
||||||
<tt class="literal"><span class="pre">big_number</span></tt>. It represents 20 bytes of data. Its synopsis follows:</p>
|
<tt class="literal"><span class="pre">big_number</span></tt>. It represents 20 bytes of data. Its synopsis follows:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
|
@ -630,7 +652,7 @@ public:
|
||||||
<p>The iterators gives you access to individual bytes.</p>
|
<p>The iterators gives you access to individual bytes.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="hasher">
|
<div class="section" id="hasher">
|
||||||
<h2><a class="toc-backref" href="#id20" name="hasher">hasher</a></h2>
|
<h2><a class="toc-backref" href="#id22" name="hasher">hasher</a></h2>
|
||||||
<p>This class creates sha1-hashes. Its declaration looks like this:</p>
|
<p>This class creates sha1-hashes. Its declaration looks like this:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
class hasher
|
class hasher
|
||||||
|
@ -653,10 +675,69 @@ call <tt class="literal"><span class="pre">reset()</span></tt> to reinitialize i
|
||||||
<p>The sha1-algorithm used was implemented by Steve Reid and released as public domain.
|
<p>The sha1-algorithm used was implemented by Steve Reid and released as public domain.
|
||||||
For more info, see <tt class="literal"><span class="pre">src/sha1.c</span></tt>.</p>
|
For more info, see <tt class="literal"><span class="pre">src/sha1.c</span></tt>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="section" id="exceptions">
|
||||||
|
<h2><a class="toc-backref" href="#id23" name="exceptions">exceptions</a></h2>
|
||||||
|
<p>There are a number of exceptions that can be thrown from different places in libtorrent,
|
||||||
|
here's a complete list with description.</p>
|
||||||
|
<div class="section" id="invalid-handle">
|
||||||
|
<h3><a class="toc-backref" href="#id24" name="invalid-handle">invalid_handle</a></h3>
|
||||||
|
<p>This exception is thrown when querying information from a <tt class="literal"><span class="pre">torrent_handle</span></tt> that hasn't
|
||||||
|
been initialized or that has become invalid.</p>
|
||||||
|
<pre class="literal-block">
|
||||||
|
struct invalid_handle: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="duplicate-torrent">
|
||||||
|
<h3><a class="toc-backref" href="#id25" name="duplicate-torrent">duplicate_torrent</a></h3>
|
||||||
|
<p>This is thrown by <tt class="literal"><span class="pre">session::add_torrent()</span></tt> if the torrent already has been added to
|
||||||
|
the session.</p>
|
||||||
|
<pre class="literal-block">
|
||||||
|
struct duplicate_torrent: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="invalid-encoding">
|
||||||
|
<h3><a class="toc-backref" href="#id26" name="invalid-encoding">invalid_encoding</a></h3>
|
||||||
|
<p>This is thrown by <tt class="literal"><span class="pre">bdecode()</span></tt> if the input data is not a valid bencoding.</p>
|
||||||
|
<pre class="literal-block">
|
||||||
|
struct invalid_encoding: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="type-error">
|
||||||
|
<h3><a class="toc-backref" href="#id27" name="type-error">type_error</a></h3>
|
||||||
|
<p>This is thrown from the accessors of <tt class="literal"><span class="pre">entry</span></tt> if the data type of the <tt class="literal"><span class="pre">entry</span></tt> doesn't
|
||||||
|
match the type you want to extract from it.</p>
|
||||||
|
<pre class="literal-block">
|
||||||
|
struct type_error: std::runtime_error
|
||||||
|
{
|
||||||
|
type_error(const char* error);
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="invalid-torrent-file">
|
||||||
|
<h3><a class="toc-backref" href="#id28" name="invalid-torrent-file">invalid_torrent_file</a></h3>
|
||||||
|
<p>This exception is thrown from the constructor of <tt class="literal"><span class="pre">torrent_info</span></tt> if the given bencoded information
|
||||||
|
doesn't meet the requirements on what information has to be present in a torrent file.</p>
|
||||||
|
<pre class="literal-block">
|
||||||
|
struct invalid_torrent_file: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="section" id="example-usage">
|
<div class="section" id="example-usage">
|
||||||
<h2><a class="toc-backref" href="#id21" name="example-usage">example usage</a></h2>
|
<h2><a class="toc-backref" href="#id29" name="example-usage">example usage</a></h2>
|
||||||
<div class="section" id="dump-torrent">
|
<div class="section" id="dump-torrent">
|
||||||
<h3><a class="toc-backref" href="#id22" name="dump-torrent">dump_torrent</a></h3>
|
<h3><a class="toc-backref" href="#id30" name="dump-torrent">dump_torrent</a></h3>
|
||||||
<p>This is an example of a program that will take a torrent-file as a parameter and
|
<p>This is an example of a program that will take a torrent-file as a parameter and
|
||||||
print information about it to std out:</p>
|
print information about it to std out:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
|
@ -664,13 +745,11 @@ print information about it to std out:</p>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <vector>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "libtorrent/entry.hpp"
|
#include "libtorrent/entry.hpp"
|
||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
#include "libtorrent/session.hpp"
|
#include "libtorrent/torrent_info.hpp"
|
||||||
#include "libtorrent/http_settings.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
@ -722,7 +801,7 @@ int main(int argc, char* argv[])
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="simple-client">
|
<div class="section" id="simple-client">
|
||||||
<h3><a class="toc-backref" href="#id23" name="simple-client">simple client</a></h3>
|
<h3><a class="toc-backref" href="#id31" name="simple-client">simple client</a></h3>
|
||||||
<p>This is a simple client. It doesn't have much output to keep it simple:</p>
|
<p>This is a simple client. It doesn't have much output to keep it simple:</p>
|
||||||
<pre class="literal-block">
|
<pre class="literal-block">
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -775,12 +854,12 @@ int main(int argc, char* argv[])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="feedback">
|
<div class="section" id="feedback">
|
||||||
<h1><a class="toc-backref" href="#id24" name="feedback">Feedback</a></h1>
|
<h1><a class="toc-backref" href="#id32" name="feedback">Feedback</a></h1>
|
||||||
<p>There's a <a class="reference" href="http://lists.sourceforge.net/lists/listinfo/libtorrent-discuss">mailing list</a>.</p>
|
<p>There's a <a class="reference" href="http://lists.sourceforge.net/lists/listinfo/libtorrent-discuss">mailing list</a>.</p>
|
||||||
<p>You can usually find me as hydri in <tt class="literal"><span class="pre">#btports</span> <span class="pre">@</span> <span class="pre">irc.freenode.net</span></tt>.</p>
|
<p>You can usually find me as hydri in <tt class="literal"><span class="pre">#btports</span> <span class="pre">@</span> <span class="pre">irc.freenode.net</span></tt>.</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="aknowledgements">
|
<div class="section" id="aknowledgements">
|
||||||
<h1><a class="toc-backref" href="#id25" name="aknowledgements">Aknowledgements</a></h1>
|
<h1><a class="toc-backref" href="#id33" name="aknowledgements">Aknowledgements</a></h1>
|
||||||
<p>Written by Arvid Norberg and Daniel Wallin. Copyright (c) 2003</p>
|
<p>Written by Arvid Norberg and Daniel Wallin. Copyright (c) 2003</p>
|
||||||
<p>Project is hosted by sourceforge.</p>
|
<p>Project is hosted by sourceforge.</p>
|
||||||
<p><a class="reference" href="http://sourceforge.net"><img alt="sf_logo" src="http://sourceforge.net/sflogo.php?group_id=7994" /></a></p>
|
<p><a class="reference" href="http://sourceforge.net"><img alt="sf_logo" src="http://sourceforge.net/sflogo.php?group_id=7994" /></a></p>
|
||||||
|
|
125
docs/index.rst
125
docs/index.rst
|
@ -138,7 +138,8 @@ The main thread will be idle as long it doesn't have any torrents to participate
|
||||||
You add torrents through the ``add_torrent()``-function where you give an
|
You add torrents through the ``add_torrent()``-function where you give an
|
||||||
object representing the information found in the torrent file and the path where you
|
object representing the information found in the torrent file and the path where you
|
||||||
want to save the files. The ``save_path`` will be prepended to the directory-
|
want to save the files. The ``save_path`` will be prepended to the directory-
|
||||||
structure in the torrent-file.
|
structure in the torrent-file. ``add_torrent`` will throw ``duplicate_torrent`` exception
|
||||||
|
if the torrent already exists in the session.
|
||||||
|
|
||||||
``remove_torrent()`` will close all peer connections associated with the torrent and tell
|
``remove_torrent()`` will close all peer connections associated with the torrent and tell
|
||||||
the tracker that we've stopped participating in the swarm.
|
the tracker that we've stopped participating in the swarm.
|
||||||
|
@ -417,9 +418,11 @@ Its declaration looks like this::
|
||||||
{
|
{
|
||||||
torrent_handle();
|
torrent_handle();
|
||||||
|
|
||||||
torrent_status status() const;
|
torrent_status status();
|
||||||
void get_download_queue(std::vector<partial_piece_info>& queue);
|
void get_download_queue(std::vector<partial_piece_info>& queue);
|
||||||
void get_peer_info(std::vector<peer_info>& v);
|
void get_peer_info(std::vector<peer_info>& v);
|
||||||
|
const torrent_info& get_torrent_info();
|
||||||
|
bool is_valid();
|
||||||
};
|
};
|
||||||
|
|
||||||
The default constructor will initialize the handle to an invalid state. Which means you cannot
|
The default constructor will initialize the handle to an invalid state. Which means you cannot
|
||||||
|
@ -427,13 +430,12 @@ perform any operation on it, unless you first assign it a valid handle. If you t
|
||||||
any operation they will simply return.
|
any operation they will simply return.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
status()
|
status()
|
||||||
~~~~~~~~
|
~~~~~~~~
|
||||||
|
|
||||||
``status()`` will return a structure with information about the status of this
|
``status()`` will return a structure with information about the status of this
|
||||||
torrent. It contains the following fields::
|
torrent. If the ``torrent_handle`` is invalid, it will throw ``invalid_handle`` exception.
|
||||||
|
It contains the following fields::
|
||||||
|
|
||||||
struct torrent_status
|
struct torrent_status
|
||||||
{
|
{
|
||||||
|
@ -459,10 +461,6 @@ torrent. It contains the following fields::
|
||||||
torrent's current task. It may be checking files or downloading. The torrent's
|
torrent's current task. It may be checking files or downloading. The torrent's
|
||||||
current task is in the ``state`` member, it will be one of the following:
|
current task is in the ``state`` member, it will be one of the following:
|
||||||
|
|
||||||
+-----------------------+----------------------------------------------------------+
|
|
||||||
|``invalid_handle`` |This will be the state if you called status on an |
|
|
||||||
| |uninitialized handle (a handle that was constructed |
|
|
||||||
| |with the default constructor). |
|
|
||||||
+-----------------------+----------------------------------------------------------+
|
+-----------------------+----------------------------------------------------------+
|
||||||
|``queued_for_checking``|The torrent is in the queue for being checked. But there |
|
|``queued_for_checking``|The torrent is in the queue for being checked. But there |
|
||||||
| |currently is another torrent that are being checked. |
|
| |currently is another torrent that are being checked. |
|
||||||
|
@ -526,14 +524,14 @@ When a piece fails a hash verification, single blocks may be redownloaded to see
|
||||||
may pass then.
|
may pass then.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get_peer_info()
|
get_peer_info()
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
``get_peer_info()`` takes a reference to a vector that will be cleared and filled
|
``get_peer_info()`` takes a reference to a vector that will be cleared and filled
|
||||||
with one entry for each peer connected to this torrent. Each entry contains information about
|
with one entry for each peer connected to this torrent, given the handle is valid. If the
|
||||||
that particular peer. It contains the following information::
|
``torrent_handle`` is invalid, it will throw ``invalid_handle`` exception. Each entry in
|
||||||
|
the vector contains information about that particular peer. It contains the following
|
||||||
|
fields::
|
||||||
|
|
||||||
struct peer_info
|
struct peer_info
|
||||||
{
|
{
|
||||||
|
@ -584,6 +582,20 @@ or if the peer miss that piece (set to false).
|
||||||
peer every second. It may be -1 if there's no limit.
|
peer every second. It may be -1 if there's no limit.
|
||||||
|
|
||||||
|
|
||||||
|
get_torrent_info()
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Returns a const reference to the ``torrent_info`` object associated with this torrent.
|
||||||
|
This reference is valid as long as the ``torrent_handle`` is valid, no longer. If the
|
||||||
|
``torrent_handle`` is invalid, ``invalid_handle`` exception will be thrown.
|
||||||
|
|
||||||
|
|
||||||
|
is_valid()
|
||||||
|
~~~~~~~~~~
|
||||||
|
|
||||||
|
Returns true if this handle refers to a valid torrent and false if it hasn't been initialized
|
||||||
|
or if the torrent it refers to has been aborted.
|
||||||
|
|
||||||
|
|
||||||
address
|
address
|
||||||
-------
|
-------
|
||||||
|
@ -596,8 +608,7 @@ Its declaration looks like this::
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
address();
|
address();
|
||||||
address(
|
address(unsigned char a
|
||||||
unsigned char a
|
|
||||||
, unsigned char b
|
, unsigned char b
|
||||||
, unsigned char c
|
, unsigned char c
|
||||||
, unsigned char d
|
, unsigned char d
|
||||||
|
@ -658,7 +669,7 @@ expand to 2 megs, it will be interrupted before the entire response has been
|
||||||
uncompressed (given your limit is lower than 2 megs). Default limit is
|
uncompressed (given your limit is lower than 2 megs). Default limit is
|
||||||
1 megabyte.
|
1 megabyte.
|
||||||
|
|
||||||
|
TODO: finish document http_settings
|
||||||
|
|
||||||
big_number
|
big_number
|
||||||
----------
|
----------
|
||||||
|
@ -713,6 +724,84 @@ The sha1-algorithm used was implemented by Steve Reid and released as public dom
|
||||||
For more info, see ``src/sha1.c``.
|
For more info, see ``src/sha1.c``.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
exceptions
|
||||||
|
----------
|
||||||
|
|
||||||
|
There are a number of exceptions that can be thrown from different places in libtorrent,
|
||||||
|
here's a complete list with description.
|
||||||
|
|
||||||
|
|
||||||
|
invalid_handle
|
||||||
|
~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This exception is thrown when querying information from a ``torrent_handle`` that hasn't
|
||||||
|
been initialized or that has become invalid.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
struct invalid_handle: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
duplicate_torrent
|
||||||
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This is thrown by ``session::add_torrent()`` if the torrent already has been added to
|
||||||
|
the session.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
struct duplicate_torrent: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
invalid_encoding
|
||||||
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This is thrown by ``bdecode()`` if the input data is not a valid bencoding.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
struct invalid_encoding: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
type_error
|
||||||
|
~~~~~~~~~~
|
||||||
|
|
||||||
|
This is thrown from the accessors of ``entry`` if the data type of the ``entry`` doesn't
|
||||||
|
match the type you want to extract from it.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
struct type_error: std::runtime_error
|
||||||
|
{
|
||||||
|
type_error(const char* error);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
invalid_torrent_file
|
||||||
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This exception is thrown from the constructor of ``torrent_info`` if the given bencoded information
|
||||||
|
doesn't meet the requirements on what information has to be present in a torrent file.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
struct invalid_torrent_file: std::exception
|
||||||
|
{
|
||||||
|
const char* what() const throw();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
example usage
|
example usage
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
@ -726,13 +815,11 @@ print information about it to std out::
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <vector>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "libtorrent/entry.hpp"
|
#include "libtorrent/entry.hpp"
|
||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
#include "libtorrent/session.hpp"
|
#include "libtorrent/torrent_info.hpp"
|
||||||
#include "libtorrent/http_settings.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|
|
@ -33,14 +33,11 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <exception>
|
|
||||||
#include <vector>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "libtorrent/entry.hpp"
|
#include "libtorrent/entry.hpp"
|
||||||
#include "libtorrent/bencode.hpp"
|
#include "libtorrent/bencode.hpp"
|
||||||
#include "libtorrent/session.hpp"
|
#include "libtorrent/torrent_info.hpp"
|
||||||
#include "libtorrent/http_settings.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|
|
@ -30,21 +30,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
implemented
|
|
||||||
|
|
||||||
* http-proxy authentication for tracker requests
|
|
||||||
* multitracker support
|
|
||||||
* spawns separate temporary threads for file checking
|
|
||||||
*
|
|
||||||
|
|
||||||
missing
|
|
||||||
|
|
||||||
* endgame-mode
|
|
||||||
* correct algorithm for choking and unchoking
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TORRENT_SESSION_HPP_INCLUDED
|
#ifndef TORRENT_SESSION_HPP_INCLUDED
|
||||||
#define TORRENT_SESSION_HPP_INCLUDED
|
#define TORRENT_SESSION_HPP_INCLUDED
|
||||||
|
|
||||||
|
@ -74,8 +59,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
// TODO: if we're not interested and the peer isn't interested, close the connections
|
// TODO: if we're not interested and the peer isn't interested, close the connections
|
||||||
// TODO: instead of implementing end-game mode, have an algorithm that
|
|
||||||
// constantly prioritizes high-bandwidth sources.
|
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,7 +39,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/peer_id.hpp"
|
#include "libtorrent/peer_id.hpp"
|
||||||
#include "libtorrent/peer_info.hpp"
|
#include "libtorrent/peer_info.hpp"
|
||||||
#include "libtorrent/piece_picker.hpp"
|
#include "libtorrent/piece_picker.hpp"
|
||||||
|
#include "libtorrent/torrent_info.hpp"
|
||||||
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
@ -55,11 +55,16 @@ namespace libtorrent
|
||||||
{ return "torrent already exists in session"; }
|
{ return "torrent already exists in session"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct invalid_handle: std::exception
|
||||||
|
{
|
||||||
|
virtual const char* what() const throw()
|
||||||
|
{ return "invalid torrent handle used"; }
|
||||||
|
};
|
||||||
|
|
||||||
struct torrent_status
|
struct torrent_status
|
||||||
{
|
{
|
||||||
enum state_t
|
enum state_t
|
||||||
{
|
{
|
||||||
invalid_handle,
|
|
||||||
queued_for_checking,
|
queued_for_checking,
|
||||||
checking_files,
|
checking_files,
|
||||||
downloading,
|
downloading,
|
||||||
|
@ -96,17 +101,20 @@ namespace libtorrent
|
||||||
torrent_handle(): m_ses(0) {}
|
torrent_handle(): m_ses(0) {}
|
||||||
|
|
||||||
void get_peer_info(std::vector<peer_info>& v);
|
void get_peer_info(std::vector<peer_info>& v);
|
||||||
torrent_status status() const;
|
torrent_status status();
|
||||||
void get_download_queue(std::vector<partial_piece_info>& queue) const;
|
void get_download_queue(std::vector<partial_piece_info>& queue);
|
||||||
|
|
||||||
|
const torrent_info& get_torrent_info();
|
||||||
|
bool is_valid();
|
||||||
|
|
||||||
// TODO: add force reannounce
|
// TODO: add force reannounce
|
||||||
// TODO: add torrent_info getter
|
|
||||||
|
// TODO: add a feature where the user can ask the torrent
|
||||||
|
// to finish all pieces currently in the pipeline, and then
|
||||||
|
// abort the torrent.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// called by session::remove_torrent()
|
|
||||||
void abort() const;
|
|
||||||
|
|
||||||
torrent_handle(detail::session_impl* s,
|
torrent_handle(detail::session_impl* s,
|
||||||
detail::checker_impl* c,
|
detail::checker_impl* c,
|
||||||
const sha1_hash& h)
|
const sha1_hash& h)
|
||||||
|
|
|
@ -841,7 +841,7 @@ void libtorrent::peer_connection::receive_data()
|
||||||
{
|
{
|
||||||
// verify peer_id
|
// verify peer_id
|
||||||
// TODO: It seems like the original client ignores to check the peer id
|
// TODO: It seems like the original client ignores to check the peer id
|
||||||
// can this be correct?
|
// can that be correct?
|
||||||
if (!std::equal(m_recv_buffer.begin(), m_recv_buffer.begin() + 20, (const char*)m_peer_id.begin()))
|
if (!std::equal(m_recv_buffer.begin(), m_recv_buffer.begin() + 20, (const char*)m_peer_id.begin()))
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
|
@ -305,7 +305,7 @@ namespace libtorrent
|
||||||
|
|
||||||
// TODO: since inc_refcount is called
|
// TODO: since inc_refcount is called
|
||||||
// with sequential indices when peers
|
// with sequential indices when peers
|
||||||
// connect, it will sort the pieces
|
// connect, the pieces will be sorted.
|
||||||
// that is not good. one solution is
|
// that is not good. one solution is
|
||||||
// to insert the element at a random
|
// to insert the element at a random
|
||||||
// index when moving it to another
|
// index when moving it to another
|
||||||
|
|
|
@ -37,6 +37,10 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/socket.hpp"
|
#include "libtorrent/socket.hpp"
|
||||||
#include "libtorrent/peer_connection.hpp"
|
#include "libtorrent/peer_connection.hpp"
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) && _MSC_VER < 1300
|
||||||
|
# define for if (false) {} else for
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
enum
|
enum
|
||||||
|
@ -189,6 +193,18 @@ namespace libtorrent
|
||||||
void peer_connection::unchoke();
|
void peer_connection::unchoke();
|
||||||
void peer_connection::request_piece(int index);
|
void peer_connection::request_piece(int index);
|
||||||
const std::vector<int>& peer_connection::download_queue();
|
const std::vector<int>& peer_connection::download_queue();
|
||||||
|
|
||||||
|
TODO: to implement choking/unchoking we need a list with all
|
||||||
|
connected peers. Something like this:
|
||||||
|
|
||||||
|
struct peer
|
||||||
|
{
|
||||||
|
peer_id id;
|
||||||
|
boost::posix_time::ptime last_optimistically_unchoked;
|
||||||
|
float average_down_rate;
|
||||||
|
boost::weak_ptr<peer_connection> connection;
|
||||||
|
};
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/filesystem/convenience.hpp>
|
#include <boost/filesystem/convenience.hpp>
|
||||||
|
#include <boost/filesystem/exception.hpp>
|
||||||
|
|
||||||
#include "libtorrent/peer_id.hpp"
|
#include "libtorrent/peer_id.hpp"
|
||||||
#include "libtorrent/torrent_info.hpp"
|
#include "libtorrent/torrent_info.hpp"
|
||||||
|
@ -104,6 +105,12 @@ namespace libtorrent
|
||||||
std::make_pair(t->info_hash, t->torrent_ptr)).first;
|
std::make_pair(t->info_hash, t->torrent_ptr)).first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(const boost::filesystem::filesystem_error& e)
|
||||||
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
std::cerr << "error while checking files: " << e.what() << "\n";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
{
|
{
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -387,6 +394,9 @@ namespace libtorrent
|
||||||
// will shift bandwidth from the peers that can't
|
// will shift bandwidth from the peers that can't
|
||||||
// utilize all their assigned bandwidth to the peers
|
// utilize all their assigned bandwidth to the peers
|
||||||
// that actually can maintain the upload rate.
|
// that actually can maintain the upload rate.
|
||||||
|
// This should probably be done by accumulating the
|
||||||
|
// left-over bandwidth to next second. Since the
|
||||||
|
// the sockets consumes its data in rather big chunks.
|
||||||
if (m_upload_rate != -1 && !m_connections.empty())
|
if (m_upload_rate != -1 && !m_connections.empty())
|
||||||
{
|
{
|
||||||
assert(m_upload_rate >= 0);
|
assert(m_upload_rate >= 0);
|
||||||
|
@ -561,8 +571,6 @@ namespace libtorrent
|
||||||
// create the torrent and the data associated with
|
// create the torrent and the data associated with
|
||||||
// the checker thread and store it before starting
|
// the checker thread and store it before starting
|
||||||
// the thread
|
// the thread
|
||||||
// TODO: have a queue of checking torrents instead of
|
|
||||||
// having them all run at the same time
|
|
||||||
boost::shared_ptr<torrent> torrent_ptr(new torrent(&m_impl, ti));
|
boost::shared_ptr<torrent> torrent_ptr(new torrent(&m_impl, ti));
|
||||||
|
|
||||||
detail::piece_checker_data d;
|
detail::piece_checker_data d;
|
||||||
|
@ -585,8 +593,28 @@ namespace libtorrent
|
||||||
void session::remove_torrent(const torrent_handle& h)
|
void session::remove_torrent(const torrent_handle& h)
|
||||||
{
|
{
|
||||||
if (h.m_ses != &m_impl) return;
|
if (h.m_ses != &m_impl) return;
|
||||||
// TODO: move the code of abort() here instead of calling it
|
assert(h.m_chk == &m_checker_impl);
|
||||||
h.abort();
|
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock l(m_impl.m_mutex);
|
||||||
|
torrent* t = m_impl.find_torrent(h.m_info_hash);
|
||||||
|
if (t != 0)
|
||||||
|
{
|
||||||
|
t->abort();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock l(m_checker_impl.m_mutex);
|
||||||
|
|
||||||
|
detail::piece_checker_data* d = m_checker_impl.find_torrent(h.m_info_hash);
|
||||||
|
if (d != 0)
|
||||||
|
{
|
||||||
|
d->abort = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void session::set_http_settings(const http_settings& s)
|
void session::set_http_settings(const http_settings& s)
|
||||||
|
|
|
@ -771,9 +771,9 @@ void libtorrent::storage::allocate_pieces(int num)
|
||||||
fs::ofstream out;
|
fs::ofstream out;
|
||||||
|
|
||||||
if (fs::exists(path))
|
if (fs::exists(path))
|
||||||
out.open(path, std::ios_base::binary | std::ios_base::in);
|
out.open(path.native_file_string().c_str(), std::ios_base::binary | std::ios_base::in);
|
||||||
else
|
else
|
||||||
out.open(path, std::ios_base::binary);
|
out.open(path.native_file_string().c_str(), std::ios_base::binary);
|
||||||
|
|
||||||
// std::ofstream out((m_save_path / file_iter->path / file_iter->filename).native_file_string().c_str()
|
// std::ofstream out((m_save_path / file_iter->path / file_iter->filename).native_file_string().c_str()
|
||||||
// , std::ios_base::binary | std::ios_base::in);
|
// , std::ios_base::binary | std::ios_base::in);
|
||||||
|
@ -1156,8 +1156,11 @@ void libtorrent::storage::initialize_pieces(torrent* t,
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(mutex);
|
boost::mutex::scoped_lock lock(mutex);
|
||||||
|
|
||||||
|
// TODO: finish
|
||||||
|
// data->progress = ;
|
||||||
|
|
||||||
if (data->abort)
|
if (data->abort)
|
||||||
;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path path(m_save_path / file_iter->path);
|
fs::path path(m_save_path / file_iter->path);
|
||||||
|
@ -1173,7 +1176,7 @@ void libtorrent::storage::initialize_pieces(torrent* t,
|
||||||
{
|
{
|
||||||
in.close();
|
in.close();
|
||||||
in.clear();
|
in.clear();
|
||||||
in.open(path, std::ios_base::binary);
|
in.open(path.native_file_string().c_str(), std::ios_base::binary);
|
||||||
|
|
||||||
changed_file = false;
|
changed_file = false;
|
||||||
|
|
||||||
|
@ -1311,6 +1314,7 @@ void libtorrent::storage::initialize_pieces(torrent* t,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // OLD STORAGE
|
#if 0 // OLD STORAGE
|
||||||
|
/*
|
||||||
|
|
||||||
// allocate files will create all files that are missing
|
// allocate files will create all files that are missing
|
||||||
// if there are some files that already exists, it checks
|
// if there are some files that already exists, it checks
|
||||||
|
@ -1327,21 +1331,6 @@ void libtorrent::storage::initialize_pieces(torrent* t,
|
||||||
m_save_path = path;
|
m_save_path = path;
|
||||||
m_torrent_file = &t->torrent_file();
|
m_torrent_file = &t->torrent_file();
|
||||||
|
|
||||||
// TEMPORARY!
|
|
||||||
/*
|
|
||||||
m_bytes_left = 0;
|
|
||||||
m_have_piece.resize(m_torrent_file->num_pieces());
|
|
||||||
std::fill(m_have_piece.begin(), m_have_piece.end(), true);
|
|
||||||
return;
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
m_bytes_left = m_torrent_file->total_size();
|
|
||||||
m_have_piece.resize(m_torrent_file->num_pieces());
|
|
||||||
std::fill(m_have_piece.begin(), m_have_piece.end(), false);
|
|
||||||
return;
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// we don't know of any piece we have right now. Initialize
|
// we don't know of any piece we have right now. Initialize
|
||||||
// it to say we don't have anything and fill it in later on.
|
// it to say we don't have anything and fill it in later on.
|
||||||
m_have_piece.resize(m_torrent_file->num_pieces());
|
m_have_piece.resize(m_torrent_file->num_pieces());
|
||||||
|
@ -1476,6 +1465,6 @@ void libtorrent::storage::initialize_pieces(torrent* t,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -63,20 +63,9 @@ namespace std
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
|
|
||||||
torrent_status torrent_handle::status() const
|
torrent_status torrent_handle::status()
|
||||||
{
|
{
|
||||||
if (m_ses == 0)
|
if (m_ses == 0) throw invalid_handle();
|
||||||
{
|
|
||||||
torrent_status st;
|
|
||||||
st.total_download = 0;
|
|
||||||
st.total_upload = 0;
|
|
||||||
st.progress = 0.f;
|
|
||||||
st.state = torrent_status::invalid_handle;
|
|
||||||
st.next_announce = boost::posix_time::time_duration();
|
|
||||||
st.pieces.clear();
|
|
||||||
st.total_done = 0;
|
|
||||||
return st;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(m_chk != 0);
|
assert(m_chk != 0);
|
||||||
{
|
{
|
||||||
|
@ -107,21 +96,54 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent_status st;
|
m_ses = 0;
|
||||||
st.total_download = 0;
|
throw invalid_handle();
|
||||||
st.total_upload = 0;
|
}
|
||||||
st.progress = 0.f;
|
|
||||||
st.state = torrent_status::invalid_handle;
|
const torrent_info& torrent_handle::get_torrent_info()
|
||||||
st.pieces.clear();
|
{
|
||||||
st.next_announce = boost::posix_time::time_duration();
|
if (m_ses == 0) throw invalid_handle();
|
||||||
st.total_done = 0;
|
|
||||||
return st;
|
{
|
||||||
|
boost::mutex::scoped_lock l(m_ses->m_mutex);
|
||||||
|
torrent* t = m_ses->find_torrent(m_info_hash);
|
||||||
|
if (t != 0) return t->torrent_file();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock l(m_chk->m_mutex);
|
||||||
|
detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
|
||||||
|
if (d != 0) return d->torrent_ptr->torrent_file();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ses = 0;
|
||||||
|
throw invalid_handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool torrent_handle::is_valid()
|
||||||
|
{
|
||||||
|
if (m_ses == 0) return false;
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock l(m_ses->m_mutex);
|
||||||
|
torrent* t = m_ses->find_torrent(m_info_hash);
|
||||||
|
if (t != 0) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock l(m_chk->m_mutex);
|
||||||
|
detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
|
||||||
|
if (d != 0) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_ses = 0;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent_handle::get_peer_info(std::vector<peer_info>& v)
|
void torrent_handle::get_peer_info(std::vector<peer_info>& v)
|
||||||
{
|
{
|
||||||
v.clear();
|
v.clear();
|
||||||
if (m_ses == 0) return;
|
if (m_ses == 0) throw invalid_handle();
|
||||||
assert(m_chk != 0);
|
assert(m_chk != 0);
|
||||||
|
|
||||||
boost::mutex::scoped_lock l(m_ses->m_mutex);
|
boost::mutex::scoped_lock l(m_ses->m_mutex);
|
||||||
|
@ -158,11 +180,11 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
queue.clear();
|
queue.clear();
|
||||||
|
|
||||||
if (m_ses == 0) return;
|
if (m_ses == 0) throw invalid_handle();
|
||||||
assert(m_chk != 0);
|
assert(m_chk != 0);
|
||||||
|
|
||||||
boost::mutex::scoped_lock l(m_ses->m_mutex);
|
boost::mutex::scoped_lock l(m_ses->m_mutex);
|
||||||
|
@ -193,31 +215,4 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void torrent_handle::abort() const
|
|
||||||
{
|
|
||||||
if (m_ses == 0) return;
|
|
||||||
assert(m_chk != 0);
|
|
||||||
|
|
||||||
{
|
|
||||||
boost::mutex::scoped_lock l(m_ses->m_mutex);
|
|
||||||
torrent* t = m_ses->find_torrent(m_info_hash);
|
|
||||||
if (t != 0)
|
|
||||||
{
|
|
||||||
t->abort();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
boost::mutex::scoped_lock l(m_chk->m_mutex);
|
|
||||||
|
|
||||||
detail::piece_checker_data* d = m_chk->find_torrent(m_info_hash);
|
|
||||||
if (d != 0)
|
|
||||||
{
|
|
||||||
d->abort = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,7 @@ namespace libtorrent
|
||||||
if (!m_comment.empty())
|
if (!m_comment.empty())
|
||||||
os << "comment: " << m_comment << "\n";
|
os << "comment: " << m_comment << "\n";
|
||||||
if (m_creation_date != boost::posix_time::ptime(boost::gregorian::date(1970, boost::gregorian::Jan, 1)))
|
if (m_creation_date != boost::posix_time::ptime(boost::gregorian::date(1970, boost::gregorian::Jan, 1)))
|
||||||
os << "creation date: " << to_simple_string(m_creation_date) << "\n";
|
os << "creation date: " << boost::posix_time::to_simple_string(m_creation_date) << "\n";
|
||||||
os << "number of pieces: " << num_pieces() << "\n";
|
os << "number of pieces: " << num_pieces() << "\n";
|
||||||
os << "piece length: " << piece_length() << "\n";
|
os << "piece length: " << piece_length() << "\n";
|
||||||
os << "files:\n";
|
os << "files:\n";
|
||||||
|
|
Loading…
Reference in New Issue