Skip to content
Snippets Groups Projects
Commit 99383cbd authored by Vincent Texier's avatar Vincent Texier
Browse files

[fix] #58 cleanup ws2P v1 connection example console messages

parent d7e9b1b9
No related branches found
No related tags found
No related merge requests found
...@@ -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("Remote CONNECT message signature is valid") print("Received 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("Remote ACK message signature is valid") print("Received 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("Remote OK message signature is valid") print("Received OK message signature is valid")
except jsonschema.exceptions.ValidationError: except jsonschema.exceptions.ValidationError:
pass pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment