Class: QuartzTorrent::Request

Inherits:
PeerWireMessage show all
Defined in:
lib/quartz_torrent/peermsg.rb

Overview

Request message. Request a block within a piece.

Constant Summary

Constants inherited from PeerWireMessage

PeerWireMessage::MessageBitfield, PeerWireMessage::MessageCancel, PeerWireMessage::MessageChoke, PeerWireMessage::MessageExtended, PeerWireMessage::MessageHave, PeerWireMessage::MessageInterested, PeerWireMessage::MessageKeepAlive, PeerWireMessage::MessagePiece, PeerWireMessage::MessageRequest, PeerWireMessage::MessageUnchoke, PeerWireMessage::MessageUninterested

Instance Attribute Summary collapse

Attributes inherited from PeerWireMessage

#messageId

Instance Method Summary collapse

Methods inherited from PeerWireMessage

#length

Constructor Details

#initializeRequest

Returns a new instance of Request.



245
246
247
# File 'lib/quartz_torrent/peermsg.rb', line 245

def initialize
  super(MessageRequest)
end

Instance Attribute Details

#blockLengthObject

Returns the value of attribute blockLength.



251
252
253
# File 'lib/quartz_torrent/peermsg.rb', line 251

def blockLength
  @blockLength
end

#blockOffsetObject

Returns the value of attribute blockOffset.



250
251
252
# File 'lib/quartz_torrent/peermsg.rb', line 250

def blockOffset
  @blockOffset
end

#pieceIndexObject

Returns the value of attribute pieceIndex.



249
250
251
# File 'lib/quartz_torrent/peermsg.rb', line 249

def pieceIndex
  @pieceIndex
end

Instance Method Details

#payloadLengthObject



253
254
255
# File 'lib/quartz_torrent/peermsg.rb', line 253

def payloadLength
  12
end

#serializeTo(io) ⇒ Object



257
258
259
260
# File 'lib/quartz_torrent/peermsg.rb', line 257

def serializeTo(io)
  super(io)
  io.write [@pieceIndex, @blockOffset, @blockLength].pack("NNN")
end

#to_sObject



266
267
268
269
# File 'lib/quartz_torrent/peermsg.rb', line 266

def to_s
  s = super
  s + ": piece index=#{@pieceIndex}, block offset=#{@blockOffset}, block length=#{@blockLength}"
end

#unserialize(payload) ⇒ Object



262
263
264
# File 'lib/quartz_torrent/peermsg.rb', line 262

def unserialize(payload)
  @pieceIndex, @blockOffset, @blockLength = payload.unpack("NNN")
end