CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/kademlia/pong.rb
Views: 11704
1
# -*- coding: binary -*-
2
3
4
module Rex
5
module Proto
6
module Kademlia
7
# Opcode for a PING response
8
PONG = 0x61
9
10
# A Kademlia pong message.
11
class Pong < Message
12
# @return [Integer] the source port from which the PING was received
13
attr_reader :port
14
15
def initialize(port = nil)
16
super(PONG)
17
@port = port
18
end
19
20
# Builds a pong from given data
21
#
22
# @param data [String] the data to decode
23
# @return [Pong] the pong if the data is valid, nil otherwise
24
def self.from_data(data)
25
message = super(data)
26
return if message.type != PONG
27
return if message.body.size != 2
28
Pong.new(message.body.unpack('v')[0])
29
end
30
31
# Get this Pong as a String
32
#
33
# @return [String] the string representation of this Pong
34
def to_str
35
super + [@port].pack('v')
36
end
37
end
38
end
39
end
40
end
41
42