Class: Ciri::P2P::Kad::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ciri/p2p/kad.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_node_id) ⇒ Node

Returns a new instance of Node.



48
49
50
51
# File 'lib/ciri/p2p/kad.rb', line 48

def initialize(raw_node_id)
  @raw_node_id = raw_node_id
  @id = Utils.big_endian_decode(Utils.keccak(raw_node_id))
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



46
47
48
# File 'lib/ciri/p2p/kad.rb', line 46

def id
  @id
end

#raw_node_idObject (readonly)

Returns the value of attribute raw_node_id.



46
47
48
# File 'lib/ciri/p2p/kad.rb', line 46

def raw_node_id
  @raw_node_id
end

Instance Method Details

#<=>(other) ⇒ Object



61
62
63
# File 'lib/ciri/p2p/kad.rb', line 61

def <=>(other)
  @id <=> other.id
end

#==(other) ⇒ Object



57
58
59
# File 'lib/ciri/p2p/kad.rb', line 57

def ==(other)
  self.class == other.class && self.id == other.id
end

#distance_to(id) ⇒ Object



53
54
55
# File 'lib/ciri/p2p/kad.rb', line 53

def distance_to(id)
  @id ^ id
end