Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
5a7c8753
Commit
5a7c8753
authored
8 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
python/tools: use asyncio in pingpong test
parent
19fdec96
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/tools/pingpong.py
+17
-7
17 additions, 7 deletions
python/tools/pingpong.py
with
17 additions
and
7 deletions
python/tools/pingpong.py
+
17
−
7
View file @
5a7c8753
...
...
@@ -17,6 +17,7 @@
import
opendht
as
dht
import
time
import
asyncio
ping_node
=
dht
.
DhtRunner
()
ping_node
.
run
(
port
=
5632
)
...
...
@@ -35,19 +36,28 @@ loc_pong = dht.InfoHash.get(str(loc_ping))
i
=
0
MAX
=
8192
def
pong
(
node
,
h
):
loop
=
asyncio
.
get_event_loop
()
def
done
(
h
,
ok
):
print
(
h
,
"
over
"
,
ok
)
def
ping
(
node
,
h
):
global
i
print
(
"
got ping
"
,
h
,
i
)
time
.
sleep
(
0.0075
)
time
.
sleep
(
0.0075
)
i
+=
1
if
i
<
MAX
:
node
.
put
(
h
,
dht
.
Value
(
b
"
hey
"
),
lambda
ok
,
nodes
:
print
(
"
over
"
,
ok
))
node
.
put
(
h
,
dht
.
Value
(
b
"
hey
"
),
lambda
ok
,
nodes
:
done
(
node
.
getNodeId
().
decode
(),
ok
))
else
:
loop
.
stop
()
def
pong
(
node
,
h
):
print
(
node
.
getNodeId
().
decode
(),
"
got ping
"
,
h
,
i
)
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
))
p
o
ng
_node
.
put
(
loc_pong
,
dht
.
Value
(
b
"
hey
"
),
lambda
ok
,
nodes
:
print
(
"
i over
"
,
ok
)
)
p
i
ng
(
pong_node
,
loc_ping
)
while
(
i
<
MAX
):
time
.
sleep
(
1
)
loop
.
run_forever
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment