-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.py
34 lines (26 loc) · 799 Bytes
/
query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from twisted.internet import reactor
from twisted.python import log
import sys
sys.path.insert(0, "kademlia")
from kademlia.network import Server
log.startLogging(sys.stdout)
if len(sys.argv) != 4:
print "Usage: python query.py <bootstrap ip> <bootstrap port> <key>"
sys.exit(1)
ip = sys.argv[1]
port = int(sys.argv[2])
key = sys.argv[3]
print "Getting %s (with bootstrap %s:%i)" % (key, ip, port)
def done(result):
print "Key result:"
print result
reactor.stop()
def bootstrapDone(found, server, key):
if len(found) == 0:
print "Could not connect to the bootstrap server."
reactor.stop()
server.get(key).addCallback(done)
server = Server()
server.listen(port-1)
server.bootstrap([(ip, port)]).addCallback(bootstrapDone, server, key)
reactor.run()