Class: DHT::Manager
Instance Method Summary collapse
- #dcell_nodes ⇒ Object
- #find_nodes ⇒ Object
- #key ⇒ Object
- #me ⇒ Object
- #node_for(key) ⇒ Object
- #nodes ⇒ Object
- #storage_for(key) ⇒ Object
Instance Method Details
#dcell_nodes ⇒ Object
35 36 37 |
# File 'lib/dht/manager.rb', line 35 def dcell_nodes DCell::Node.all end |
#find_nodes ⇒ Object
7 8 9 |
# File 'lib/dht/manager.rb', line 7 def find_nodes dcell_nodes.inject({}) { |hash, node| hash[node[:storage].key] = node; hash } end |
#key ⇒ Object
27 28 29 |
# File 'lib/dht/manager.rb', line 27 def key Key.for_content(me.addr) end |
#me ⇒ Object
39 40 41 |
# File 'lib/dht/manager.rb', line 39 def me DCell.me end |
#node_for(key) ⇒ Object
21 22 23 24 25 |
# File 'lib/dht/manager.rb', line 21 def node_for(key) key = Key.for_content(key.to_s) node_key = nodes.keys.min { |a,b| a.distance_to(key) <=> b.distance_to(key) } nodes[node_key] end |
#nodes ⇒ Object
31 32 33 |
# File 'lib/dht/manager.rb', line 31 def nodes @nodes = find_nodes end |
#storage_for(key) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/dht/manager.rb', line 11 def storage_for(key) closest_node = node_for(key) if closest_node == me me[:storage] else closest_node[:manager].storage_for(key) end end |