1# -*- coding: binary -*- 2 3module Rex 4module Proto 5module 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 20end 21end 22end 23 24