Class: Rex::Proto::Kademlia::Pong

Inherits:
Message
  • Object
show all
Defined in:
lib/rex/proto/kademlia/pong.rb

Overview

A Kademlia pong message.

Constant Summary

Constants inherited from Message

Message::COMPRESSED_PACKET, Message::STANDARD_PACKET

Instance Attribute Summary collapse

Attributes inherited from Message

#body, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

#==

Constructor Details

#initialize(port = nil) ⇒ Pong

Returns a new instance of Pong.


15
16
17
18
# File 'lib/rex/proto/kademlia/pong.rb', line 15

def initialize(port = nil)
  super(PONG)
  @port = port
end

Instance Attribute Details

#portInteger (readonly)

Returns the source port from which the PING was received.

Returns:

  • (Integer)

    the source port from which the PING was received


13
14
15
# File 'lib/rex/proto/kademlia/pong.rb', line 13

def port
  @port
end

Class Method Details

.from_data(data) ⇒ Pong

Builds a pong from given data

Parameters:

  • data (String)

    the data to decode

Returns:

  • (Pong)

    the pong if the data is valid, nil otherwise


24
25
26
27
28
29
# File 'lib/rex/proto/kademlia/pong.rb', line 24

def self.from_data(data)
  message = super(data)
  return if message.type != PONG
  return if message.body.size != 2
  Pong.new(message.body.unpack('v')[0])
end

Instance Method Details

#to_strString

Get this Pong as a String

Returns:

  • (String)

    the string representation of this Pong


34
35
36
# File 'lib/rex/proto/kademlia/pong.rb', line 34

def to_str
  super + [@port].pack('v')
end