class QuartzTorrent::PeerWireMessage
Represents a bittorrent peer protocol wire message (a non-handshake message). All messages other than handshake have a 4-byte length, 1-byte message id, and payload.
Constants
- MessageBitfield
- MessageCancel
- MessageChoke
- MessageExtended
- MessageHave
- MessageInterested
- MessageKeepAlive
- MessagePiece
- MessageRequest
- MessageUnchoke
- MessageUninterested
Attributes
messageId[R]
Get the message id of this message (the message type from the peer wire protocol).
Public Class Methods
new(messageId)
click to toggle source
Create a new PeerWireMessage
with the specified message id.
# File lib/quartz_torrent/peermsg.rb, line 91 def initialize(messageId) @messageId = messageId end
Public Instance Methods
length()
click to toggle source
Total message length
# File lib/quartz_torrent/peermsg.rb, line 110 def length payloadLength + 5 end
payloadLength()
click to toggle source
Subclasses must implement this method. It should return an integer.
# File lib/quartz_torrent/peermsg.rb, line 105 def payloadLength raise "Subclasses of PeerWireMessage must implement payloadLength but #{self.class} didn't" end
serializeTo(io)
click to toggle source
Serialize this message to the passed io
# File lib/quartz_torrent/peermsg.rb, line 99 def serializeTo(io) io.write [payloadLength+1].pack("N") io.write [@messageId].pack("C") end
to_s()
click to toggle source
# File lib/quartz_torrent/peermsg.rb, line 119 def to_s "#{self.class} message" end
unserialize(payload)
click to toggle source
Unserialize the message from the passed string.
# File lib/quartz_torrent/peermsg.rb, line 115 def unserialize(payload) raise "Subclasses of PeerWireMessage must implement unserialize but #{self.class} didn't" end