📄 bit torrent specification.htm
字号:
<P class=tightenable>There are mainly two conventions how to encode client and
client version information into the peer_id, Azureus-style and
Shadow's-style.</P>
<P class=tightenable>Azureus-style uses the following encoding: '-', two
characters for client id, four ascii digits for version number, '-', followed by
random numbers.</P>
<P class=tightenable>For example: '-AZ2060-'...</P>
<P class="tightenable bottom">known clients that uses this encoding style
are:</P>
<UL>
<LI class="tightenable top bottom">'AZ' - <A class=namedurl
href="http://azureus.sf.net/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>Azureus</SPAN></A>
<LI class="tightenable top bottom">'BB' - <A class=namedurl
href="http://www.btvampire.com/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>BitBuddy</SPAN></A>
<LI class="tightenable top bottom">'CT' - <A class=namedurl
href="http://ctorrent.sourceforge.net/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>CTorrent</SPAN></A>
<LI class="tightenable top bottom">'MT' - <A class=namedurl
href="http://www.moonlighttorrent.com/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>MoonlightTorrent</SPAN></A>
<LI class="tightenable top bottom">'LT' - <A class=namedurl
href="http://libtorrent.sf.net/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>libtorrent</SPAN></A>
<LI class="tightenable top bottom">'BX' - Bittorrent X
<LI class="tightenable top bottom">'TS' - <A class=namedurl
href="http://www.torrentstorm.com/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>Torrentstorm</SPAN></A>
<LI class="tightenable top bottom">'TN' - TorrentDotNET
<LI class="tightenable top bottom">'SS' - SwarmScope
<LI class="tightenable top bottom">'XT' - <A class=namedurl
href="http://www.xantorrent.pwp.blueyonder.co.uk/xantorrent.zip"><SPAN
style="WHITE-SPACE: nowrap"><IMG class=linkicon alt=""
src="Bit Torrent Specification.files/http.png" border=0>XanTorrent</SPAN></A>
<LI class="tightenable top bottom">'BS' - <A class=namedurl
href="http://btslave.sourceforge.net/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>BTSlave</SPAN></A>
<LI class="tightenable top bottom">'ZT' - <A class=namedurl
href="http://www.ziptorrent.com/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>ZipTorrent</SPAN></A>
<LI class="tightenable top bottom">'AR' - <A class=namedurl
href="http://dev.int64.org/arctic.html"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>Arctic</SPAN></A>
<LI class="tightenable top bottom">'SB' - Swiftbit
<LI class="tightenable top bottom">'MP' - <A class=namedurl
href="http://www.moopolice.de/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>MooPolice</SPAN></A>
<LI class="tightenable top bottom">'lt' - <A class=namedurl
href="http://libtorrent.rakshasa.no/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>libTorrent</SPAN></A>
<LI class="tightenable top bottom">'BC' - <A class=namedurl
href="http://www.bitcomet.com/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>BitComet</SPAN></A>
<LI class="tightenable top bottom">'QT' - Qt 4 Torrent example
<LI class="tightenable top bottom">'UT' - <A class=namedurl
href="http://www.utorrent.com/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>礣orrent</SPAN></A>?
<LI class="tightenable top bottom">'SZ' - <A class=namedurl
href="http://shareaza.sourceforge.net/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>Shareaza</SPAN></A>
<LI class="tightenable top">'RT' - <A class=namedurl
href="http://www.halogenware.com/software/retriever.html"><SPAN
style="WHITE-SPACE: nowrap"><IMG class=linkicon alt=""
src="Bit Torrent Specification.files/http.png" border=0>Retriever</SPAN></A>
</LI></UL>
<P class=tightenable>Shadow's style uses the following encoding: one ascii
alphanumeric for client identification, three ascii digits for version number,
'----', followed by random numbers.</P>
<P class=tightenable>For example: 'S587----'...</P>
<P class="tightenable bottom">known clients that uses this encoding style
are:</P>
<UL>
<LI class="tightenable top bottom">'S' - <A class=namedurl
href="http://bt.degreez.net/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>Shadow's</SPAN> client</A>
<LI class="tightenable top bottom">'U' - <A class=namedurl
href="http://aaron2003.myftp.org/upnpclient.html"><SPAN
style="WHITE-SPACE: nowrap"><IMG class=linkicon alt=""
src="Bit Torrent Specification.files/http.png" border=0>UPnP</SPAN> NAT Bit
Torrent</A>
<LI class="tightenable top bottom">'T' - <A class=namedurl
href="http://bittornado.com/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>BitTornado</SPAN></A>
<LI class="tightenable top bottom">'A' - <A class=namedurl
href="http://pingpong-abc.sourceforge.net/"><SPAN
style="WHITE-SPACE: nowrap"><IMG class=linkicon alt=""
src="Bit Torrent Specification.files/http.png" border=0>ABC</SPAN></A>
<LI class="tightenable top">'O' - <A class=namedurl
href="http://osprey.ibiblio.org/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>Osprey</SPAN> Permaseed</A> </LI></UL>
<P class=tightenable>Bram's client now uses this style... 'M3-4-2--'.</P>
<P class=tightenable><A class=namedurl href="http://www.bitcomet.com/"><SPAN
style="WHITE-SPACE: nowrap"><IMG class=linkicon alt=""
src="Bit Torrent Specification.files/http.png" border=0>BitComet</SPAN></A> does
something different still. Its peer_id consists of four ASCII characters 'exbc',
followed by two bytes x and y, followed by random characters. The version number
is x in decimal before the decimal point and y as two decimal digits after the
decimal point. The encoding for <SPAN class=wikiunknown><A
onmouseover='window.status="Create: BitComet"; return true;'
title="Create: BitComet" onmouseout="window.status='';return true;"
href="http://wiki.theory.org/BitComet?action=create">?</A><U>BitComet</U></SPAN>
Peer IDs changed to Azureus-style as of <SPAN class=wikiunknown><A
onmouseover='window.status="Create: BitComet"; return true;'
title="Create: BitComet" onmouseout="window.status='';return true;"
href="http://wiki.theory.org/BitComet?action=create">?</A><U>BitComet</U></SPAN>
version 0.59. Therefore x will always be zero.</P>
<P class=tightenable><A class=namedurl
href="http://xbtt.sourceforge.net/client/"><SPAN
style="WHITE-SPACE: nowrap"><IMG class=linkicon alt=""
src="Bit Torrent Specification.files/http.png" border=0>XBT</SPAN> Client</A>
has its own style too. Its peer_id consists of the three uppercase characters
'XBT' followed by three ASCII digits representing the version number. If the
client is a debug build, the seventh byte is the lowercase character 'd',
otherwise it is a '-'. Following that is a '-' then random digits, uppercase and
lowercase letters. Example: 'XBT054d-' at the beginning would indicate a debug
build of version 0.5.4.</P>
<P class=tightenable><A class=namedurl href="http://snapshot.opera.com/"><SPAN
style="WHITE-SPACE: nowrap"><IMG class=linkicon alt=""
src="Bit Torrent Specification.files/http.png" border=0>Opera</SPAN> 8
previews</A> use the following peer_id scheme: The first two characters are 'OP'
and the next four digits equal the build number. All following characters are
random lowercase hexdecimal digits.</P>
<P class=tightenable>Many clients are using all random numbers or 12 zeroes
followed by random numbers (like older versions of <A class=namedurl
href="http://bitconjurer.org/BitTorrent/"><SPAN style="WHITE-SPACE: nowrap"><IMG
class=linkicon alt="" src="Bit Torrent Specification.files/http.png"
border=0>Bram's</SPAN> client</A>).</P>
<H3>Messages</H3>
<P class=tightenable>All of the remaining messages in the protocol take the form
of <length prefix><message ID><payload>. The length prefix is
a four byte big-endian value. The message ID is a single decimal character. The
payload is message dependent.</P>
<H4><B>keep-alive</B>: <len=0000></H4>
<P class=tightenable>The <B>keep-alive</B> message is a message with zero bytes,
specified with the length prefix set to zero. There is no message ID and no
payload. Peers may close a connection if they receive no messages for a certain
period of time, so a keep-alive message can be sent to maintain the connection.
A keep-alive message is generally sent once every two minutes.</P>
<H4><B>choke</B>: <len=0001><id=0></H4>
<P class=tightenable>The <B>choke</B> message is fixed-length and has no
payload.</P>
<H4><B>unchoke</B>: <len=0001><id=1></H4>
<P class=tightenable>The <B>unchoke</B> message is fixed-length and has no
payload.</P>
<H4><B>interested</B>: <len=0001><id=2></H4>
<P class=tightenable>The <B>interested</B> message is fixed-length and has no
payload.</P>
<H4><B>not interested</B>: <len=0001><id=3></H4>
<P class=tightenable>The <B>not interested</B> message is fixed-length and has
no payload.</P>
<H4><B>have</B>: <len=0005><id=4><piece index></H4>
<P class=tightenable>The <B>have</B> message is fixed length. The payload is the
zero-based index of a piece that has just been successfully downloaded and
verified via the hash.</P>
<P class=tightenable><I>Implementer's Note: That is the strict definition, in
reality some games may be played. In particular because peers are extremely
unlikely to download pieces that they already have, a peer may choose not to
advertise having a piece to a peer that already has that piece. At a minimum
"HAVE supression" will result in a 50% reduction in the number of HAVE messages,
this translates to around a 25-35% reduction in protocol overhead.</I></P>
<P class=tightenable><I>A malicious peer might also choose to advertise having
pieces that it knows the peer will never download. Due to this attempting to
model peers using this information is a <B>bad idea</B></I></P>
<H4><B>bitfield</B>: <len=0001+X><id=5><bitfield></H4>
<P class=tightenable>The <B>bitfield</B> message may only be sent immediately
after the handshaking sequence is completed, and before any other messages are
sent. It is optional, and need not be sent if a client has no pieces.</P>
<P class=tightenable>The <B>bitfield</B> message is variable length, where X is
the length of the bitfield. The payload is a bitfield representing the pieces
that have been successfully downloaded. The high bit in the first byte
corresponds to piece index 0. Bits that are cleared indicated a missing piece,
and set bits indicate a valid and available piece. Spare bits at the end are set
to zero.</P>
<P class=tightenable><I>A bitfield of the wrong length is considered an error.
Clients should drop the connection if they receive bitfields that are not of the
correct size, or if the bitfield has any of the spare bits set.</I></P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -