Class: QuartzTorrent::Have

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

Overview

Have message. Sent to all connected peers to notify that we have completed downloading the specified 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

#initializeHave

Returns a new instance of Have.



195
196
197
# File 'lib/quartz_torrent/peermsg.rb', line 195

def initialize
  super(MessageHave)
end

Instance Attribute Details

#pieceIndexObject

Returns the value of attribute pieceIndex.



199
200
201
# File 'lib/quartz_torrent/peermsg.rb', line 199

def pieceIndex
  @pieceIndex
end

Instance Method Details

#payloadLengthObject



201
202
203
# File 'lib/quartz_torrent/peermsg.rb', line 201

def payloadLength
  4
end

#serializeTo(io) ⇒ Object



205
206
207
208
# File 'lib/quartz_torrent/peermsg.rb', line 205

def serializeTo(io)
  super(io)
  io.write [@pieceIndex].pack("N")
end

#to_sObject



214
215
216
217
# File 'lib/quartz_torrent/peermsg.rb', line 214

def to_s
  s = super
  s + ": piece index=#{@pieceIndex}"
end

#unserialize(payload) ⇒ Object



210
211
212
# File 'lib/quartz_torrent/peermsg.rb', line 210

def unserialize(payload)
  @pieceIndex = payload.unpack("N")[0]
end