mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
python: add wrapper for ValueCallback
This commit is contained in:
1 parent
d958b0ea5f
commit
22741436e3
6 files changed
+36
-11
No files matched your search
@@ -43,7 +43,7 @@ loop = asyncio.get_event_loop()
|
||||
pending_tests = {}
|
||||
keys = [dht.InfoHash.getRandom() for _ in range(args.num_ops)]
|
||||
|
||||
def listen_cb(key, val):
|
||||
def listen_cb(key, val, expired):
|
||||
global pending_tests
|
||||
kstr = str(key)
|
||||
if kstr in pending_tests:
|
||||
@@ -54,7 +54,7 @@ def listen_cb(key, val):
|
||||
return True
|
||||
|
||||
def listen(key):
|
||||
node1.listen(key, lambda v: loop.call_soon_threadsafe(listen_cb, key, v))
|
||||
node1.listen(key, lambda v, e: loop.call_soon_threadsafe(listen_cb, key, v, e))
|
||||
|
||||
for key in keys:
|
||||
listen(key)
|
||||
|
||||
@@ -54,8 +54,8 @@ def pong(node, h):
|
||||
loop.call_soon_threadsafe(ping, node, h)
|
||||
return True
|
||||
|
||||
ping_node.listen(loc_ping, lambda v: pong(pong_node, loc_pong))
|
||||
pong_node.listen(loc_pong, lambda v: pong(ping_node, loc_ping))
|
||||
ping_node.listen(loc_ping, lambda v, e: pong(pong_node, loc_pong) if not e else True)
|
||||
pong_node.listen(loc_pong, lambda v, e: pong(ping_node, loc_ping) if not e else True)
|
||||
|
||||
ping(pong_node, loc_ping)
|
||||
|
||||
|
||||
Reference in new issue
Block a user