2016-07-12 14:32:02 +02:00
|
|
|
import logging
|
|
|
|
import asyncio
|
|
|
|
|
2014-01-20 05:04:22 +01:00
|
|
|
from kademlia.network import Server
|
|
|
|
|
2016-07-12 14:32:02 +02:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.set_debug(True)
|
|
|
|
|
|
|
|
server = Server()
|
|
|
|
server.listen(8468)
|
2014-01-20 05:04:22 +01:00
|
|
|
|
|
|
|
def done(result):
|
2016-07-12 14:32:02 +02:00
|
|
|
print("Key result:", result)
|
2014-01-20 05:04:22 +01:00
|
|
|
|
|
|
|
def setDone(result, server):
|
|
|
|
server.get("a key").addCallback(done)
|
|
|
|
|
|
|
|
def bootstrapDone(found, server):
|
|
|
|
server.set("a key", "a value").addCallback(setDone, server)
|
|
|
|
|
2016-07-12 14:32:02 +02:00
|
|
|
#server.bootstrap([("1.2.3.4", 8468)]).addCallback(bootstrapDone, server)
|
|
|
|
|
|
|
|
try:
|
|
|
|
loop.run_forever()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2017-08-31 02:42:21 +02:00
|
|
|
finally:
|
|
|
|
server.stop()
|
|
|
|
loop.close()
|