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.


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

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


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

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


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

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


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

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