forked from premiere/premiere-libtorrent
*** empty log message ***
This commit is contained in:
parent
b0359b8f91
commit
f997f4c226
|
@ -10,6 +10,37 @@
|
||||||
<body>
|
<body>
|
||||||
<div class="document" id="bittorrent-udp-tracker-protocol-extension">
|
<div class="document" id="bittorrent-udp-tracker-protocol-extension">
|
||||||
<h1 class="title">Bittorrent udp-tracker protocol extension</h1>
|
<h1 class="title">Bittorrent udp-tracker protocol extension</h1>
|
||||||
|
<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="id6" name="id6">introduction</a></li>
|
||||||
|
<li><a class="reference" href="#connecting" id="id7" name="id7">connecting</a><ul>
|
||||||
|
<li><a class="reference" href="#client-sends-packet" id="id8" name="id8">Client sends packet:</a></li>
|
||||||
|
<li><a class="reference" href="#server-replies-with-packet" id="id9" name="id9">Server replies with packet:</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a class="reference" href="#announcing" id="id10" name="id10">announcing</a><ul>
|
||||||
|
<li><a class="reference" href="#id2" id="id11" name="id11">Client sends packet:</a></li>
|
||||||
|
<li><a class="reference" href="#id3" id="id12" name="id12">Server replies with packet:</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a class="reference" href="#scraping" id="id13" name="id13">scraping</a><ul>
|
||||||
|
<li><a class="reference" href="#id4" id="id14" name="id14">Client sends packet:</a></li>
|
||||||
|
<li><a class="reference" href="#id5" id="id15" name="id15">Server replies with packet:</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a class="reference" href="#errors" id="id16" name="id16">errors</a><ul>
|
||||||
|
<li><a class="reference" href="#server-replies-packet" id="id17" name="id17">server replies packet:</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li><a class="reference" href="#actions" id="id18" name="id18">actions</a></li>
|
||||||
|
<li><a class="reference" href="#extensions" id="id19" name="id19">extensions</a></li>
|
||||||
|
<li><a class="reference" href="#authentication" id="id20" name="id20">authentication</a></li>
|
||||||
|
<li><a class="reference" href="#credits" id="id21" name="id21">credits</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="introduction">
|
||||||
|
<h1><a name="introduction">introduction</a></h1>
|
||||||
<p>A tracker with the protocol "udp://" in its URI
|
<p>A tracker with the protocol "udp://" in its URI
|
||||||
is supposed to be contacted using this protocol.</p>
|
is supposed to be contacted using this protocol.</p>
|
||||||
<p>This protocol is supported by
|
<p>This protocol is supported by
|
||||||
|
@ -22,6 +53,7 @@ are specified with ANSI-C standard types.</p>
|
||||||
<p>If no response to a request is received within 15 seconds, resend
|
<p>If no response to a request is received within 15 seconds, resend
|
||||||
the request. If no reply has been received after 60 seconds, stop
|
the request. If no reply has been received after 60 seconds, stop
|
||||||
retrying.</p>
|
retrying.</p>
|
||||||
|
</div>
|
||||||
<div class="section" id="connecting">
|
<div class="section" id="connecting">
|
||||||
<h1><a name="connecting">connecting</a></h1>
|
<h1><a name="connecting">connecting</a></h1>
|
||||||
<div class="section" id="client-sends-packet">
|
<div class="section" id="client-sends-packet">
|
||||||
|
@ -181,35 +213,9 @@ in the reply. Use -1 for default.</td>
|
||||||
<td>port</td>
|
<td>port</td>
|
||||||
<td>The port you're listening on.</td>
|
<td>The port you're listening on.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
<tr><td>uint16_t</td>
|
||||||
</table>
|
<td>extensions</td>
|
||||||
<p>If the server requires authorization, the following structure has to be
|
<td>See <a class="reference" href="#extensions">extensions</a></td>
|
||||||
appended on the announce packet.</p>
|
|
||||||
<table border class="table">
|
|
||||||
<colgroup>
|
|
||||||
<col width="18%" />
|
|
||||||
<col width="28%" />
|
|
||||||
<col width="54%" />
|
|
||||||
</colgroup>
|
|
||||||
<thead valign="bottom">
|
|
||||||
<tr><th>size</th>
|
|
||||||
<th>name</th>
|
|
||||||
<th>description</th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody valign="top">
|
|
||||||
<tr><td>uint8_t[20]</td>
|
|
||||||
<td>passwd_hash</td>
|
|
||||||
<td>The sha1-hash of the announce packet
|
|
||||||
with the password appended. The
|
|
||||||
announce message here means the
|
|
||||||
mandatory part, not including this
|
|
||||||
authentication appendix.</td>
|
|
||||||
</tr>
|
|
||||||
<tr><td>int8_t[]</td>
|
|
||||||
<td>username</td>
|
|
||||||
<td>The rest of the packet is the
|
|
||||||
username.</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -315,9 +321,18 @@ scrape.</td>
|
||||||
<td>transaction_id</td>
|
<td>transaction_id</td>
|
||||||
<td>Randomized by client.</td>
|
<td>Randomized by client.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr><td>int16_t</td>
|
||||||
|
<td>num_info_hashes</td>
|
||||||
|
<td>The number of info-hashes that will
|
||||||
|
follow.</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td>uint16_t</td>
|
||||||
|
<td>extensions</td>
|
||||||
|
<td>See <a class="reference" href="#extensions">extensions</a>.</td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<p>The rest of the packet contains a variable number of the following structure:</p>
|
<p>The following structure is repeated <tt class="literal"><span class="pre">num_info_hashes</span></tt> times:</p>
|
||||||
<table border class="table">
|
<table border class="table">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col width="18%" />
|
<col width="18%" />
|
||||||
|
@ -445,6 +460,53 @@ describing the error.</td>
|
||||||
</ul>
|
</ul>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="section" id="extensions">
|
||||||
|
<h1><a name="extensions">extensions</a></h1>
|
||||||
|
<p>The extensions field is a bitmask. The following
|
||||||
|
bits are assigned:</p>
|
||||||
|
<blockquote>
|
||||||
|
<ul class="simple">
|
||||||
|
<li>1 = <a class="reference" href="#authentication">authentication</a>.</li>
|
||||||
|
</ul>
|
||||||
|
</blockquote>
|
||||||
|
</div>
|
||||||
|
<div class="section" id="authentication">
|
||||||
|
<h1><a name="authentication">authentication</a></h1>
|
||||||
|
<p>The packet will have an authentication part
|
||||||
|
appended to it. It has the following format:</p>
|
||||||
|
<table border class="table">
|
||||||
|
<colgroup>
|
||||||
|
<col width="18%" />
|
||||||
|
<col width="28%" />
|
||||||
|
<col width="54%" />
|
||||||
|
</colgroup>
|
||||||
|
<thead valign="bottom">
|
||||||
|
<tr><th>size</th>
|
||||||
|
<th>name</th>
|
||||||
|
<th>description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody valign="top">
|
||||||
|
<tr><td>int8_t</td>
|
||||||
|
<td>username_length</td>
|
||||||
|
<td>The number of characters in the
|
||||||
|
username.</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td>int8_t[]</td>
|
||||||
|
<td>username</td>
|
||||||
|
<td>The username, the number of characters
|
||||||
|
as specified in the previous field.</td>
|
||||||
|
</tr>
|
||||||
|
<tr><td>uint8_t[20]</td>
|
||||||
|
<td>passwd_hash</td>
|
||||||
|
<td>sha1(packet + sha1(password))
|
||||||
|
The packet in this case means the
|
||||||
|
entire packet except these 20 bytes
|
||||||
|
that are the password hash.</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
<div class="section" id="credits">
|
<div class="section" id="credits">
|
||||||
<h1><a name="credits">credits</a></h1>
|
<h1><a name="credits">credits</a></h1>
|
||||||
<p>Protocol designed by Olaf van der Spek</p>
|
<p>Protocol designed by Olaf van der Spek</p>
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
Bittorrent udp-tracker protocol extension
|
Bittorrent udp-tracker protocol extension
|
||||||
=========================================
|
=========================================
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
|
||||||
|
|
||||||
|
introduction
|
||||||
|
++++++++++++
|
||||||
|
|
||||||
A tracker with the protocol "udp://" in its URI
|
A tracker with the protocol "udp://" in its URI
|
||||||
is supposed to be contacted using this protocol.
|
is supposed to be contacted using this protocol.
|
||||||
|
|
||||||
|
@ -113,21 +119,7 @@ Client sends packet:
|
||||||
+-------------+---------------------+----------------------------------------+
|
+-------------+---------------------+----------------------------------------+
|
||||||
| uint16_t | port | The port you're listening on. |
|
| uint16_t | port | The port you're listening on. |
|
||||||
+-------------+---------------------+----------------------------------------+
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
| uint16_t | extensions | See extensions_ |
|
||||||
If the server requires authorization, the following structure has to be
|
|
||||||
appended on the announce packet.
|
|
||||||
|
|
||||||
+-------------+---------------------+----------------------------------------+
|
|
||||||
| size | name | description |
|
|
||||||
+=============+=====================+========================================+
|
|
||||||
| uint8_t[20] | passwd_hash | The sha1-hash of the announce packet |
|
|
||||||
| | | with the password appended. The |
|
|
||||||
| | | announce message here means the |
|
|
||||||
| | | mandatory part, not including this |
|
|
||||||
| | | authentication appendix. |
|
|
||||||
+-------------+---------------------+----------------------------------------+
|
|
||||||
| int8_t[] | username | The rest of the packet is the |
|
|
||||||
| | | username. |
|
|
||||||
+-------------+---------------------+----------------------------------------+
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,8 +176,13 @@ Client sends packet:
|
||||||
+-------------+---------------------+----------------------------------------+
|
+-------------+---------------------+----------------------------------------+
|
||||||
| int32_t | transaction_id | Randomized by client. |
|
| int32_t | transaction_id | Randomized by client. |
|
||||||
+-------------+---------------------+----------------------------------------+
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
| int16_t | num_info_hashes | The number of info-hashes that will |
|
||||||
|
| | | follow. |
|
||||||
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
| uint16_t | extensions | See extensions_. |
|
||||||
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
|
||||||
The rest of the packet contains a variable number of the following structure:
|
The following structure is repeated ``num_info_hashes`` times:
|
||||||
|
|
||||||
+-------------+---------------------+----------------------------------------+
|
+-------------+---------------------+----------------------------------------+
|
||||||
| size | name | description |
|
| size | name | description |
|
||||||
|
@ -221,6 +218,7 @@ The rest of the packet contains a variable number of the following structures:
|
||||||
| | | leechers. |
|
| | | leechers. |
|
||||||
+-------------+---------------------+----------------------------------------+
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
errors
|
errors
|
||||||
++++++
|
++++++
|
||||||
|
|
||||||
|
@ -253,6 +251,38 @@ The action fields has the following encoding:
|
||||||
* error = 3 (only in server replies)
|
* error = 3 (only in server replies)
|
||||||
|
|
||||||
|
|
||||||
|
extensions
|
||||||
|
++++++++++
|
||||||
|
|
||||||
|
The extensions field is a bitmask. The following
|
||||||
|
bits are assigned:
|
||||||
|
|
||||||
|
* 1 = authentication_.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
authentication
|
||||||
|
++++++++++++++
|
||||||
|
|
||||||
|
The packet will have an authentication part
|
||||||
|
appended to it. It has the following format:
|
||||||
|
|
||||||
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
| size | name | description |
|
||||||
|
+=============+=====================+========================================+
|
||||||
|
| int8_t | username_length | The number of characters in the |
|
||||||
|
| | | username. |
|
||||||
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
| int8_t[] | username | The username, the number of characters |
|
||||||
|
| | | as specified in the previous field. |
|
||||||
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
| uint8_t[20] | passwd_hash | sha1(packet + sha1(password)) |
|
||||||
|
| | | The packet in this case means the |
|
||||||
|
| | | entire packet except these 20 bytes |
|
||||||
|
| | | that are the password hash. |
|
||||||
|
+-------------+---------------------+----------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
credits
|
credits
|
||||||
+++++++
|
+++++++
|
||||||
|
|
||||||
|
|
|
@ -548,8 +548,8 @@ namespace libtorrent
|
||||||
// remove old disconnected peers from the list
|
// remove old disconnected peers from the list
|
||||||
m_peers.erase(
|
m_peers.erase(
|
||||||
std::remove_if(m_peers.begin()
|
std::remove_if(m_peers.begin()
|
||||||
, m_peers.end()
|
, m_peers.end()
|
||||||
, old_disconnected_peer())
|
, old_disconnected_peer())
|
||||||
, m_peers.end());
|
, m_peers.end());
|
||||||
|
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
@ -747,7 +747,7 @@ namespace libtorrent
|
||||||
// if the connection comes from the tracker,
|
// if the connection comes from the tracker,
|
||||||
// it's probably just a NAT-check. Ignore the
|
// it's probably just a NAT-check. Ignore the
|
||||||
// num connections constraint then.
|
// num connections constraint then.
|
||||||
// TODO: mske sure this works
|
// TODO: make sure this works
|
||||||
// TODO: only allow _one_ connection to use this
|
// TODO: only allow _one_ connection to use this
|
||||||
// override at a time
|
// override at a time
|
||||||
if (m_torrent->num_peers() >= m_max_connections
|
if (m_torrent->num_peers() >= m_max_connections
|
||||||
|
|
|
@ -77,91 +77,6 @@ namespace std
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
int saturated_add(int a, int b)
|
|
||||||
{
|
|
||||||
assert(a>=0);
|
|
||||||
assert(b>=0);
|
|
||||||
|
|
||||||
int sum=a+b;
|
|
||||||
if(sum<0)
|
|
||||||
sum=std::numeric_limits<int>::max();
|
|
||||||
|
|
||||||
assert(sum>=a && sum>=b);
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// adjusts the upload rates of every peer connection
|
|
||||||
// to make sure the sum of all send quotas equals
|
|
||||||
// the given upload_limit. An upload limit of
|
|
||||||
// std::numeric_limits<int>::max() means unlimited upload
|
|
||||||
// rate, but the rates of each peer has to be set anyway,
|
|
||||||
// since it depends on the download rate from the peer.
|
|
||||||
/*
|
|
||||||
void control_upload_rates(
|
|
||||||
int upload_limit,
|
|
||||||
libtorrent::detail::session_impl::connection_map connections)
|
|
||||||
{
|
|
||||||
assert(upload_limit >= 0);
|
|
||||||
|
|
||||||
using namespace libtorrent;
|
|
||||||
std::vector<resource_request *> requests;
|
|
||||||
|
|
||||||
for (detail::session_impl::connection_map::iterator c = connections.begin();
|
|
||||||
c != connections.end(); ++c)
|
|
||||||
{
|
|
||||||
boost::shared_ptr<peer_connection> p = c->second;
|
|
||||||
requests.push_back(p->upload_bandwidth_quota());
|
|
||||||
}
|
|
||||||
|
|
||||||
allocate_resources(upload_limit, requests);
|
|
||||||
|
|
||||||
for (detail::session_impl::connection_map::iterator c = connections.begin();
|
|
||||||
c != connections.end(); ++c)
|
|
||||||
{
|
|
||||||
boost::shared_ptr<peer_connection> p = c->second;
|
|
||||||
p->update_send_quota_left();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
void control_number_of_connections(
|
|
||||||
int connections_limit,
|
|
||||||
libtorrent::detail::session_impl::torrent_map hash_list)
|
|
||||||
{
|
|
||||||
assert(connections_limit >= 0);
|
|
||||||
|
|
||||||
using namespace libtorrent;
|
|
||||||
std::vector<resource_consumer> torrents;
|
|
||||||
|
|
||||||
for (detail::session_impl::torrent_map::iterator c = hash_list.begin();
|
|
||||||
c != hash_list.end(); ++c)
|
|
||||||
{
|
|
||||||
boost::shared_ptr<torrent> t = c->second;
|
|
||||||
|
|
||||||
int estimated_capacity=t->num_peers()+1;
|
|
||||||
int limit =t->get_policy().get_max_connections();
|
|
||||||
if(limit==-1)
|
|
||||||
limit=std::numeric_limits<int>::max();
|
|
||||||
|
|
||||||
torrents.push_back(resource_consumer(t,limit,estimated_capacity));
|
|
||||||
}
|
|
||||||
|
|
||||||
allocate_resources(connections_limit, torrents);
|
|
||||||
|
|
||||||
for (std::vector<resource_consumer>::iterator r=torrents.begin();
|
|
||||||
r!=torrents.end(); ++r)
|
|
||||||
{
|
|
||||||
// TODO: inform torrent of how many connections it's allowed.
|
|
||||||
// boost::any_cast<boost::shared_ptr<torrent> >
|
|
||||||
// (r->who())->set_send_quota(r->allowed_use());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace libtorrent { namespace detail
|
namespace libtorrent { namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue