2016-07-12 14:32:02 +02:00
|
|
|
import logging
|
|
|
|
import asyncio
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from kademlia.network import Server
|
|
|
|
|
2018-01-02 20:17:36 +01:00
|
|
|
if len(sys.argv) != 4:
|
|
|
|
print("Usage: python get.py <bootstrap node> <bootstrap port> <key>")
|
2016-07-12 14:32:02 +02:00
|
|
|
sys.exit(1)
|
|
|
|
|
2018-01-02 19:14:25 +01:00
|
|
|
handler = logging.StreamHandler()
|
|
|
|
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
log = logging.getLogger('kademlia')
|
|
|
|
log.addHandler(handler)
|
|
|
|
log.setLevel(logging.DEBUG)
|
|
|
|
|
2016-07-12 14:32:02 +02:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.set_debug(True)
|
|
|
|
|
|
|
|
server = Server()
|
2019-01-12 17:44:39 +01:00
|
|
|
loop.run_until_complete(server.listen(8469))
|
2018-01-02 20:17:36 +01:00
|
|
|
bootstrap_node = (sys.argv[1], int(sys.argv[2]))
|
|
|
|
loop.run_until_complete(server.bootstrap([bootstrap_node]))
|
|
|
|
result = loop.run_until_complete(server.get(sys.argv[3]))
|
2016-07-12 14:32:02 +02:00
|
|
|
server.stop()
|
|
|
|
loop.close()
|
|
|
|
|
|
|
|
print("Get result:", result)
|