Skip to content

Commit bedf7ed

Browse files
committed
Doc cleanup
1 parent 0ed356f commit bedf7ed

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

lib/rex/proto/kademlia/bootstrap_response.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@ module Kademlia
1111

1212
# A Kademlia bootstrap response message
1313
class BootstrapResponse < Message
14+
# @return [String] the ID of the peer that send the bootstrap response
1415
attr_reader :peer_id
16+
# @return [Integer] the TCP port that the responding peer is listening on
1517
attr_reader :tcp_port
18+
# @return [Integer] the version of this peer
1619
attr_reader :version
17-
# An array of hashes containing the peer ID, IP address, UDP and TCP ports as well as the type/version
20+
# @return [Array<Hash<String, Object>>] the peer ID, IP address, UDP/TCP ports and version of each peer
1821
attr_reader :peers
1922

23+
# Constructs a new bootstrap response
24+
#
25+
# @param peer_id [String] the ID of this peer
26+
# @param tcp_port [Integer] the TCP port that this peer is listening on
27+
# @param version [Integer] the version of this peer
28+
# @param peers [Array<Hash<String, Object>>] the peer ID, IP address, UDP/TCP ports and version of each peer
2029
def initialize(peer_id, tcp_port, version, peers)
2130
@peer_id = peer_id
2231
@tcp_port = tcp_port

lib/rex/proto/kademlia/message.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,31 @@ module Proto
1717
#
1818
##
1919
module Kademlia
20+
# A simple Kademlia message
2021
class Message
2122
# The header that non-compressed Kad messages use
2223
STANDARD_PACKET = 0xE4
2324
# The header that compressed Kad messages use, which is currently unsupported
2425
COMPRESSED_PACKET = 0xE5
2526

26-
attr_accessor :type, :body
27+
# @return [Integer] the message type
28+
attr_reader :type
29+
# @return [String] the message body
30+
attr_reader :body
2731

32+
# Construct a new Message from the provided type and body
33+
#
2834
# @param type [String] the message type
2935
# @param body [String] the message body
3036
def initialize(type, body = '')
3137
@type = type
3238
@body = body
3339
end
3440

41+
# Construct a new Message from the provided data
42+
#
43+
# @param data [String] the data to interpret as a Kademlia message
44+
# @return [Message] the message if valid, nil otherwise
3545
def self.from_data(data)
3646
return if data.length < 2
3747
header, type = data.unpack('CC')

lib/rex/proto/kademlia/pong.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ module Kademlia
1010

1111
# A Kademlia pong message.
1212
class Pong < Message
13-
# the source port from which the PING was received
13+
# @return [Integer] the source port from which the PING was received
1414
attr_reader :port
1515

1616
def initialize(port = nil)
1717
super(PONG)
1818
@port = port
1919
end
2020

21+
# Builds a pong from given data
22+
#
23+
# @param data [String] the data to decode
24+
# @return [Pong] the pong if the data is valid, nil otherwise
2125
def self.from_data(data)
2226
message = super(data)
2327
return if message.type != PONG

spec/lib/rex/proto/kademlia/bootstrap_response_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
expect(peer[:ip]).to eq('149.91.116.59')
1919
expect(peer[:tcp_port]).to eq(4882)
2020
expect(peer[:udp_port]).to eq(4992)
21-
expect(peer[:type]).to eq(8)
21+
expect(peer[:version]).to eq(8)
2222
peer = response.peers.last
2323
expect(peer[:id]).to eq('9B896000AEBE0B0A0ECB35457177A107')
2424
expect(peer[:ip]).to eq('83.46.192.208')
2525
expect(peer[:tcp_port]).to eq(3662)
2626
expect(peer[:udp_port]).to eq(3672)
27-
expect(peer[:type]).to eq(8)
27+
expect(peer[:version]).to eq(8)
2828
end
2929

3030
it 'does not decode overly small bootstrap responses' do

0 commit comments

Comments
 (0)