Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
clients
python
DuniterPy
Commits
99383cbd
Commit
99383cbd
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#58
cleanup ws2P v1 connection example console messages
parent
d7e9b1b9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/request_ws2p.py
+8
-8
8 additions, 8 deletions
examples/request_ws2p.py
with
8 additions
and
8 deletions
examples/request_ws2p.py
+
8
−
8
View file @
99383cbd
...
@@ -61,20 +61,20 @@ async def main():
...
@@ -61,20 +61,20 @@ async def main():
async
with
ws_connection
as
ws
:
async
with
ws_connection
as
ws
:
print
(
"
Connected successfully to web socket endpoint
"
)
print
(
"
Connected successfully to web socket endpoint
"
)
print
(
"
Send
message CONNECT :
"
+
connect_
message
)
print
(
"
Send
CONNECT
message
"
)
await
ws
.
send_str
(
connect_message
)
await
ws
.
send_str
(
connect_message
)
# Iterate on each message received...
# Iterate on each message received...
async
for
msg
in
ws
:
async
for
msg
in
ws
:
# if message type is text...
# if message type is text...
if
msg
.
type
==
aiohttp
.
WSMsgType
.
TEXT
:
if
msg
.
type
==
aiohttp
.
WSMsgType
.
TEXT
:
print
(
msg
.
data
)
#
print(msg.data)
try
:
try
:
# Validate jsonschema and return a
the json
dict
# Validate
json string with
jsonschema and return a dict
data
=
parse_text
(
msg
.
data
,
ws2p
.
network
.
WS2P_CONNECT_MESSAGE_SCHEMA
)
data
=
parse_text
(
msg
.
data
,
ws2p
.
network
.
WS2P_CONNECT_MESSAGE_SCHEMA
)
print
(
"
Received a CONNECT message
"
)
print
(
"
Received a CONNECT message
"
)
remote_connect_document
=
Connect
(
CURRENCY
,
data
[
"
pub
"
],
data
[
"
challenge
"
],
data
[
"
sig
"
])
remote_connect_document
=
Connect
(
CURRENCY
,
data
[
"
pub
"
],
data
[
"
challenge
"
],
data
[
"
sig
"
])
print
(
"
Re
mote
CONNECT message signature is valid
"
)
print
(
"
Re
ceived
CONNECT message signature is valid
"
)
ack_message
=
Ack
(
CURRENCY
,
signing_key
.
pubkey
,
ack_message
=
Ack
(
CURRENCY
,
signing_key
.
pubkey
,
remote_connect_document
.
challenge
).
get_signed_json
(
remote_connect_document
.
challenge
).
get_signed_json
(
...
@@ -85,13 +85,13 @@ async def main():
...
@@ -85,13 +85,13 @@ async def main():
except
jsonschema
.
exceptions
.
ValidationError
:
except
jsonschema
.
exceptions
.
ValidationError
:
try
:
try
:
# Validate jsonschema and return a
the json
dict
# Validate
json string with
jsonschema and return a dict
data
=
parse_text
(
msg
.
data
,
ws2p
.
network
.
WS2P_ACK_MESSAGE_SCHEMA
)
data
=
parse_text
(
msg
.
data
,
ws2p
.
network
.
WS2P_ACK_MESSAGE_SCHEMA
)
print
(
"
Received a ACK message
"
)
print
(
"
Received a ACK message
"
)
# create ACK document from ACK response to verify signature
# create ACK document from ACK response to verify signature
Ack
(
CURRENCY
,
data
[
"
pub
"
],
connect_document
.
challenge
,
data
[
"
sig
"
])
Ack
(
CURRENCY
,
data
[
"
pub
"
],
connect_document
.
challenge
,
data
[
"
sig
"
])
print
(
"
Re
mote
ACK message signature is valid
"
)
print
(
"
Re
ceived
ACK message signature is valid
"
)
# Si ACK response ok, create OK message
# Si ACK response ok, create OK message
ok_message
=
Ok
(
CURRENCY
,
signing_key
.
pubkey
,
connect_document
.
challenge
).
get_signed_json
(
ok_message
=
Ok
(
CURRENCY
,
signing_key
.
pubkey
,
connect_document
.
challenge
).
get_signed_json
(
signing_key
)
signing_key
)
...
@@ -101,12 +101,12 @@ async def main():
...
@@ -101,12 +101,12 @@ async def main():
await
ws
.
send_str
(
ok_message
)
await
ws
.
send_str
(
ok_message
)
except
jsonschema
.
exceptions
.
ValidationError
:
except
jsonschema
.
exceptions
.
ValidationError
:
try
:
try
:
# Validate jsonschema and return a
the json
dict
# Validate
json string with
jsonschema and return a dict
data
=
parse_text
(
msg
.
data
,
ws2p
.
network
.
WS2P_OK_MESSAGE_SCHEMA
)
data
=
parse_text
(
msg
.
data
,
ws2p
.
network
.
WS2P_OK_MESSAGE_SCHEMA
)
print
(
"
Received a OK message
"
)
print
(
"
Received a OK message
"
)
Ok
(
CURRENCY
,
remote_connect_document
.
pubkey
,
connect_document
.
challenge
,
data
[
"
sig
"
])
Ok
(
CURRENCY
,
remote_connect_document
.
pubkey
,
connect_document
.
challenge
,
data
[
"
sig
"
])
print
(
"
Re
mote
OK message signature is valid
"
)
print
(
"
Re
ceived
OK message signature is valid
"
)
except
jsonschema
.
exceptions
.
ValidationError
:
except
jsonschema
.
exceptions
.
ValidationError
:
pass
pass
...
...
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