if have_storage: store1 = pysos.Dict('sto%d.dat' % port1) else: store1 = {} dht1 = DHT(host1, port1, storage=store1) myseeds = [(host1, port1)] host2, port2 = 'localhost', 14901 if have_storage: store2 = pysos.Dict('sto%d.dat' % port2) else: store2 = {} dht2 = DHT(host2, port2, seeds=myseeds, storage=store2) # store some values via DHT1 or 2 dht1["my_key"] = [u"My", u"json-serializable", u"Object"] dht1["akey1"] = ["Some", "Strings", "for key1"] dht1["akey2"] = ["Other", "Strings", "for key2"] dht2["akey3"] = ["Further", "Strings", "for key3"] # demo retrieve data from nodes print("Blocking get from DHT1 = %s" % str(dht2["my_key"])) dht2.get("my_key", lambda data: print("Threaded get from DHT2 = %s" % str(data))) # test iteration over node data (only see values known on the node) print("Iterating over all values as seen by DHT2:") for key in dht2: print('"%s" -> %s' % (key, dht2[key])) # shutdown servers dht1.server.shutdown() dht1.server.server_close() dht2.server.shutdown() dht2.server.server_close()
dhts.append (ndht) port += 1 testo = ["My", "json-serializable", "Object"] random.choice (dhts)["my_key"] = testo for x in range (0, 1): assert (random.choice (dhts)["my_key"] == testo) """ host1, port1 = 'localhost', 3000 dht1 = DHT(host1, port1) host2, port2 = 'localhost', 3001 dht2 = DHT(host2, port2, bootstrap_nodes=[(host1, port1)]) host3, port3 = 'localhost', 3002 dht3 = DHT(host3, port3, bootstrap_nodes=[(host2, port2)]) dht1["my_key"] = [u"My", u"json-serializable", u"Object"] dht2.get("my_key", lambda d: print('Find:', d)) dht3.get("my_key", lambda d: print('Find:', d)) #print (dht2["my_key"]) print(dht1.peers()) print(dht2.peers()) print(dht3.peers())
hosts.append (nhost) dhts.append (ndht) port += 1 testo = ["My", "json-serializable", "Object"] random.choice (dhts)["my_key"] = testo for x in range (0, 1): assert (random.choice (dhts)["my_key"] == testo) """ host1, port1 = 'localhost', 3001 dht1 = DHT(host1, port1, storage=shelve.open('sto1.dat')) host2, port2 = 'localhost', 3002 dht2 = DHT(host2, port2, seeds=[(host1, port1)], storage=shelve.open('sto2.dat')) host3, port3 = 'localhost', 3003 dht3 = DHT(host3, port3, seeds=[(host2, port2)], storage=shelve.open('sto3.dat')) dht1["my_key"] = [u"My", u"json-serializable", u"Object"] dht2.get("my_key", lambda d: print('Find:', d)) dht3.get("my_key", lambda d: print('Find:', d)) # print(dht2["my_key"]) print(dht1.peers()) print(dht2.peers()) print(dht3.peers())