Class: Roma::Routing::MerkleTree

Inherits:
Object
  • Object
show all
Defined in:
lib/roma/routing/merkle_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dgst_bits, div_bits) ⇒ MerkleTree

Returns a new instance of MerkleTree.



12
13
14
15
16
17
# File 'lib/roma/routing/merkle_tree.rb', line 12

def initialize(dgst_bits,div_bits)
  @tree = {}
  @dgst_bits = dgst_bits
  @div_bits = div_bits
  create_tree_instance('0')
end

Instance Attribute Details

#dgst_bitsObject (readonly)

Returns the value of attribute dgst_bits.



10
11
12
# File 'lib/roma/routing/merkle_tree.rb', line 10

def dgst_bits
  @dgst_bits
end

#div_bitsObject (readonly)

Returns the value of attribute div_bits.



9
10
11
# File 'lib/roma/routing/merkle_tree.rb', line 9

def div_bits
  @div_bits
end

#treeObject (readonly)

Returns the value of attribute tree.



8
9
10
# File 'lib/roma/routing/merkle_tree.rb', line 8

def tree
  @tree
end

Instance Method Details

#get(id) ⇒ Object



25
26
27
# File 'lib/roma/routing/merkle_tree.rb', line 25

def get(id)
  @tree[id]
end

#set(vn, nodes) ⇒ Object



19
20
21
22
23
# File 'lib/roma/routing/merkle_tree.rb', line 19

def set(vn,nodes)
  id = '0' + (vn >> (@dgst_bits-@div_bits)).to_s(2).rjust(@div_bits,'0')
  @tree[id] = Digest::SHA1.hexdigest(nodes.to_s)
  update(parent(id))
end

#to_vn(id) ⇒ Object



29
30
31
# File 'lib/roma/routing/merkle_tree.rb', line 29

def to_vn(id)
  id[1,id.length].to_i(2) << (@dgst_bits-@div_bits)
end