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/util.rb
Views: 11704
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Kademlia::Util
6
# Decodes an on-the-wire representation of a Kademlia peer to its 16-character hex equivalent
7
#
8
# @param bytes [String] the on-the-wire representation of a Kademlia peer
9
# @return [String] the peer ID if valid, nil otherwise
10
def self.decode_peer_id(bytes)
11
peer_id = 0
12
return nil unless bytes.size == 16
13
bytes.unpack('VVVV').map { |p| peer_id = ((peer_id << 32) ^ p) }
14
peer_id.to_s(16).upcase
15
end
16
17
# TODO
18
# def encode_peer_id(id)
19
# end
20
end
21
end
22
end
23
24