nodes = self.table.findNodes(key)
nodes = map(lambda node: node.senderDict(), nodes)
return {'nodes' : nodes}, self.node.senderDict()
-#------ testing
+
+### TESTING ###
+from random import randrange
+import threading, thread, sys, time
+from sha import sha
+from hash import newID
+
def test_build_net(quiet=0, peers=24, host='localhost', pause=0, startport=2001):
- from whrandom import randrange
- import threading
- import thread
- import sys
port = startport
l = []
peer.addContact(host, n.port)
if pause:
time.sleep(.33)
- sys.stdout.flush()
time.sleep(10)
print "finding close nodes...."
f.set()
peer.findCloseNodes(cb)
flag.wait()
- sys.stdout.flush()
# for peer in l:
# peer.refreshTable()
return l
def test_find_nodes(l, quiet=0):
- import threading, sys
- from whrandom import randrange
flag = threading.Event()
n = len(l)
flag.wait()
def test_find_value(l, quiet=0):
- from whrandom import randrange
- from sha import sha
- from hash import newID
- import time, threading, sys
fa = threading.Event()
fb = threading.Event()
key = newID()
value = newID()
- if not quiet:
- print "inserting value..."
- sys.stdout.flush()
+ if not quiet: print "inserting value..."
a.storeValueForKey(key, value)
time.sleep(3)
if not quiet:
print "finding..."
- sys.stdout.flush()
class cb:
def __init__(self, flag, value=value):
print "find NOT FOUND"
else:
print "find FOUND"
- sys.stdout.flush()
else:
if self.val in values:
self.found = 1
if __name__ == "__main__":
import sys
n = 8
- if len(sys.argv) > 1:
- n = int(sys.argv[1])
+ if len(sys.argv) > 1: n = int(sys.argv[1])
l = test_build_net(peers=n)
time.sleep(3)
print "finding nodes..."