[bittorrent] Bitfield data... First bits meaning?

Alan McGovern alan.mcgovern at gmail.com
Sat Dec 9 08:46:35 EST 2006


>From here: http://wiki.theory.org/BitTorrentSpecification

bitfield: <len=0001+X><id=5><bitfield>

The *bitfield* 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.

The *bitfield* 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.

*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.*

On 12/9/06, Bernard Morin <jrchukalescu at gmail.com> wrote:
> Hi everyone...
> I'm newbie on this forum and in bittorrent development too...
> For a semester project, I'm writing a bittorrent client in Java.
> Everything works fine, messages exchange is set up and peers communicates
> correctly, except that I don't understand the meaning of the first bits of
> the bitfield messages...
> Actually, bitfield should represent the pieces that the remote peers have.
> But when I check this field, it always contains cleared (0) bits at the
> beginning and the end, even when I'm contacting a seed...
> For the trailing bits, it is ok, since they are spare bits and should be
> ignored. But the first ones, I just don't get what they mean...
> Could someone help me please...
> _______________________________________________
> BitTorrent mailing list
> BitTorrent at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/bittorrent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ibiblio.org/pipermail/bittorrent/attachments/20061209/570c83dc/attachment.html 

More information about the BitTorrent mailing list