Class: Roma::Routing::MerkleTree
- Inherits:
-
Object
- Object
- Roma::Routing::MerkleTree
- Defined in:
- lib/roma/routing/merkle_tree.rb
Instance Attribute Summary collapse
-
#dgst_bits ⇒ Object
readonly
Returns the value of attribute dgst_bits.
-
#div_bits ⇒ Object
readonly
Returns the value of attribute div_bits.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #get(id) ⇒ Object
-
#initialize(dgst_bits, div_bits) ⇒ MerkleTree
constructor
A new instance of MerkleTree.
- #set(vn, nodes) ⇒ Object
- #to_vn(id) ⇒ Object
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_bits ⇒ Object (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_bits ⇒ Object (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 |
#tree ⇒ Object (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 |