File
bitfield.rb
Path: ../lib/net/bittorrent/bitfield.rb
Modified: Wed Sep 15 12:05:54 EDT 2004

NAME

Net::BitTorrent::BitField

INTRODUCTION

What is BitField ?

  When BitTorrent client downloads files,
  they require pieces instead of files. The piece are stream data of file(s).
  BitField is used for checking which pieces does the client have.

Why implemented as array ?

 It was a simple and an easy way.
 Not much worth to optimize this class,
 I thought better to choose maintenance cost.

 I did not Benchmark about BitField.
 It should be in ToDo but low priority, now.

Current Design of BitField

 BitField stores 1 or 0 instead of boolean(true or false),
 Because it can make easier to convert to bitfield binary data.

EXAMPLES

# How to get the BitField from metainfo and storage.

  @bitfield = BitField.create(metainfo['info']['pieces'],
                              storage.get_pieces)

# Check the client have the piece.

  def have?(index)
    return (@bitfield[index] == 1) ? true : false
  end

SEE ALSO

NOTES

AUTHORS

Author:Ikkei Shimomura
Project WebSite:aversa.rubyforge.org
Classes and Modules

Module Net
  ::Module Net::BitTorrent
  ::  ::Class Net::BitTorrent::BitField