Class: Rex::Proto::Kademlia::Message
- Inherits:
-
Object
- Object
- Rex::Proto::Kademlia::Message
- Defined in:
- lib/rex/proto/kademlia/message.rb
Overview
A simple Kademlia message
Direct Known Subclasses
Constant Summary collapse
- STANDARD_PACKET =
The header that non-compressed Kad messages use
0xE4
- COMPRESSED_PACKET =
The header that compressed Kad messages use, which is currently unsupported
0xE5
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
The message body.
-
#type ⇒ Integer
readonly
The message type.
Class Method Summary collapse
-
.from_data(data) ⇒ Message
Construct a new Message from the provided data.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares this Message and another Message for equality.
-
#initialize(type, body = '') ⇒ Message
constructor
Construct a new Message from the provided type and body.
-
#to_str ⇒ String
Get this Message as a String.
Constructor Details
#initialize(type, body = '') ⇒ Message
Construct a new Message from the provided type and body
36 37 38 39 |
# File 'lib/rex/proto/kademlia/message.rb', line 36 def initialize(type, body = '') @type = type @body = body end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns the message body.
30 31 32 |
# File 'lib/rex/proto/kademlia/message.rb', line 30 def body @body end |
#type ⇒ Integer (readonly)
Returns the message type.
28 29 30 |
# File 'lib/rex/proto/kademlia/message.rb', line 28 def type @type end |
Class Method Details
.from_data(data) ⇒ Message
Construct a new Message from the provided data
45 46 47 48 49 50 51 52 53 |
# File 'lib/rex/proto/kademlia/message.rb', line 45 def self.from_data(data) return if data.length < 2 header, type = data.unpack('CC') if header == COMPRESSED_PACKET fail NotImplementedError, "Unable to handle #{data.length}-byte compressed Kademlia message" end return if header != STANDARD_PACKET Message.new(type, data[2, data.length]) end |
Instance Method Details
#==(other) ⇒ Boolean
Compares this Message and another Message for equality
66 67 68 |
# File 'lib/rex/proto/kademlia/message.rb', line 66 def ==(other) type == other.type && body == other.body end |
#to_str ⇒ String
Get this Message as a String
58 59 60 |
# File 'lib/rex/proto/kademlia/message.rb', line 58 def to_str [STANDARD_PACKET, @type].pack('CC') + @body end |