Class: QuartzTorrent::BlockInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_torrent/blockstate.rb

Overview

Information representing a single block (a part of a piece)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pieceIndex, offset, length, peers, blockIndex) ⇒ BlockInfo

Returns a new instance of BlockInfo.



8
9
10
11
12
13
14
# File 'lib/quartz_torrent/blockstate.rb', line 8

def initialize(pieceIndex, offset, length, peers, blockIndex)
  @pieceIndex = pieceIndex
  @offset = offset
  @length = length
  @peers = peers
  @blockIndex = blockIndex
end

Instance Attribute Details

#blockIndexObject

Index of the block in units of the blockSize from the BlockState that created this object.



27
28
29
# File 'lib/quartz_torrent/blockstate.rb', line 27

def blockIndex
  @blockIndex
end

#lengthObject

Length of the block in bytes.



21
22
23
# File 'lib/quartz_torrent/blockstate.rb', line 21

def length
  @length
end

#offsetObject

Offset (in bytes) within the piece where the block begins.



19
20
21
# File 'lib/quartz_torrent/blockstate.rb', line 19

def offset
  @offset
end

#peersObject

A list of peers that have the piece this block belongs to. This block can be requested from these peers.



24
25
26
# File 'lib/quartz_torrent/blockstate.rb', line 24

def peers
  @peers
end

#pieceIndexObject

The index of the piece that this block belongs to.



17
18
19
# File 'lib/quartz_torrent/blockstate.rb', line 17

def pieceIndex
  @pieceIndex
end

Instance Method Details

#getRequestObject

Return a new Bittorrent Request message that requests this block.



30
31
32
33
34
35
36
# File 'lib/quartz_torrent/blockstate.rb', line 30

def getRequest
  m = Request.new
  m.pieceIndex = @pieceIndex
  m.blockOffset = @offset
  m.blockLength = @length
  m
end