def test_find_nodes(root, closeme): # seed net = Network(7001, root) seeds[0] += ":{0}".format(net.node.node_id) print seeds net.join(seeds) closeme.append(net) node = net.get_local() # can find self assert net.find_nodes(node.node_id) != None # check for consistency across nodes net2 = Network(7002, root) net2.join(seeds) closeme.append(net2) net3 = Network(7003, root) net3.join(seeds) closeme.append(net3) # some more random nodes for i in range(7004, 7024): n = Network(i, root) n.join(seeds) closeme.append(n) # find a random id target = generate_random() # just pull out the id's for comparison nodes = [ x.node_id for x in net.find_nodes(target, 5) ] # same response from other nodes assert nodes == [ x.node_id for x in net2.find_nodes(target, 5) ] assert nodes == [ x.node_id for x in net3.find_nodes(target, 5) ]
def test_find_nodes(root, closeme): # seed net = Network([], root) net.join() node = net.get_local() seeds = [ "{0}:{1}:{2}".format(node['address'], node['port'], node['node_id']) ] closeme.append(net) # can find self assert net.find_nodes(node['node_id']) != None # check for consistency across nodes net2 = Network(seeds, root) net2.join() closeme.append(net2) net3 = Network(seeds, root) net3.join() closeme.append(net3) # some more random nodes for _ in range(20): n = Network(seeds, root) n.join() closeme.append(n) # give them a bit of time to register with the seed time.sleep(2) # find a random id target = z85.encode(generate_random()) # just pull out the id's for comparison nodes = [x['node_id'] for x in net2.find_nodes(target, 5)] # same response from other nodes assert nodes == [x['node_id'] for x in net3.find_nodes(target, 5)] # check that the routing agrees they're in distance order # need to transform back to raw bytes nodes = [z85.decode(x) for x in nodes] nodes2 = list(nodes) distance_sort(nodes2, z85.decode(target)) assert nodes == nodes2
def test_find_nodes(root, closeme): # seed net = Network([], root) net.join() node = net.get_local() seeds = ["{0}:{1}:{2}".format(node['address'], node['port'], node['node_id'])] closeme.append(net) # can find self assert net.find_nodes(node['node_id']) != None # check for consistency across nodes net2 = Network(seeds, root) net2.join() closeme.append(net2) net3 = Network(seeds, root) net3.join() closeme.append(net3) # some more random nodes for _ in range(20): n = Network(seeds, root) n.join() closeme.append(n) # give them a bit of time to register with the seed time.sleep(2) # find a random id target = z85.encode(generate_random()) # just pull out the id's for comparison nodes = [ x['node_id'] for x in net2.find_nodes(target, 5) ] # same response from other nodes assert nodes == [ x['node_id'] for x in net3.find_nodes(target, 5) ] # check that the routing agrees they're in distance order # need to transform back to raw bytes nodes = [ z85.decode(x) for x in nodes ] nodes2 = list(nodes) distance_sort(nodes2, z85.decode(target)) assert nodes == nodes2
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import tempfile import urllib import urllib2 import webbrowser from peerz.routing import generate_random, Node, RoutingZone def render_graph(dot): with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp: data = urllib.urlencode({'cht': 'gv:dot', 'chl': dot}) print data u = urllib2.urlopen('http://chart.apis.google.com/chart', data) tmp.write(u.read()) tmp.close() webbrowser.open_new_tab(tmp.name) if __name__ == '__main__': node = Node('a', 0, generate_random()) nodetree = RoutingZone(node.node_id, bdepth=4, binsize=4) nodetree.add(node) for x in xrange(1, 500): nodetree.add(Node('b', x, generate_random())) render_graph(nodetree.visualise())
def poll_random(self): # should really find a stale bucket not just random self.engine.txmap.create(FindNodes, [z85.encode(generate_random())], self.engine)
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import tempfile import urllib import urllib2 import webbrowser from peerz.routing import generate_random, Node, RoutingZone def render_graph(dot): with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp: data = urllib.urlencode({'cht': 'gv:dot', 'chl': dot}) print data u = urllib2.urlopen('http://chart.apis.google.com/chart', data) tmp.write(u.read()) tmp.close() webbrowser.open_new_tab(tmp.name) if __name__ == '__main__': node = Node('a', 0, generate_random()) nodetree = RoutingZone(node.node_id, bdepth=4, binsize=4) nodetree.add(node) for x in xrange(1, 500): nodetree.add(Node('b', x, generate_random())) render_graph(nodetree.visualise())
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import tempfile import urllib import urllib2 import webbrowser from peerz.routing import generate_random, Node, RoutingZone def render_graph(dot): with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as tmp: data = urllib.urlencode({'cht': 'gv:dot', 'chl': dot}) print data u = urllib2.urlopen('http://chart.apis.google.com/chart', data) tmp.write(u.read()) tmp.close() webbrowser.open_new_tab(tmp.name) if __name__ == '__main__': node = Node('localhost', 65535, generate_random()) nodetree = RoutingZone(node.node_id, bdepth=4, binsize=4) nodetree.add(node) for x in xrange(1, 1000): nodetree.add(Node('localhost', x, generate_random())) render_graph(nodetree.visualise())