kademlia/examples/example.py

32 lines
608 B
Python
Raw Normal View History

import logging
import asyncio
2014-01-20 05:04:22 +01:00
from kademlia.network import Server
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):
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)
#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()