From c498bf5668eb7831cdce52838b94dcb0ee07c38f Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Thu, 30 Jun 2022 20:07:48 +0200 Subject: [PATCH] Updated examples --- Examples/Filetransfer.py | 8 ++++++-- Examples/Identify.py | 10 +++++++--- Examples/Link.py | 8 ++++++-- Examples/Request.py | 8 ++++++-- Examples/Speedtest.py | 8 ++++++-- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Examples/Filetransfer.py b/Examples/Filetransfer.py index 8f66199..d6654c3 100644 --- a/Examples/Filetransfer.py +++ b/Examples/Filetransfer.py @@ -215,8 +215,12 @@ def client(destination_hexhash, configpath): # We need a binary representation of the destination # hash that was entered on the command line try: - if len(destination_hexhash) != 20: - raise ValueError("Destination length is invalid, must be 20 hexadecimal characters (10 bytes)") + dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 + if len(destination_hexhash) != dest_len: + raise ValueError( + "Destination length is invalid, must be {hex} hexadecimal characters ({byte} bytes).".format(hex=dest_len, byte=dest_len//2) + ) + destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") diff --git a/Examples/Identify.py b/Examples/Identify.py index 4c31ba5..45ba18e 100644 --- a/Examples/Identify.py +++ b/Examples/Identify.py @@ -84,7 +84,7 @@ def client_connected(link): def client_disconnected(link): RNS.log("Client disconnected") -def remote_identified(identity): +def remote_identified(link, identity): RNS.log("Remote identified as: "+str(identity)) def server_packet_received(message, packet): @@ -124,8 +124,12 @@ def client(destination_hexhash, configpath): # We need a binary representation of the destination # hash that was entered on the command line try: - if len(destination_hexhash) != 20: - raise ValueError("Destination length is invalid, must be 20 hexadecimal characters (10 bytes)") + dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 + if len(destination_hexhash) != dest_len: + raise ValueError( + "Destination length is invalid, must be {hex} hexadecimal characters ({byte} bytes).".format(hex=dest_len, byte=dest_len//2) + ) + destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") diff --git a/Examples/Link.py b/Examples/Link.py index 71df9a0..6b3210c 100644 --- a/Examples/Link.py +++ b/Examples/Link.py @@ -110,8 +110,12 @@ def client(destination_hexhash, configpath): # We need a binary representation of the destination # hash that was entered on the command line try: - if len(destination_hexhash) != 20: - raise ValueError("Destination length is invalid, must be 20 hexadecimal characters (10 bytes)") + dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 + if len(destination_hexhash) != dest_len: + raise ValueError( + "Destination length is invalid, must be {hex} hexadecimal characters ({byte} bytes).".format(hex=dest_len, byte=dest_len//2) + ) + destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") diff --git a/Examples/Request.py b/Examples/Request.py index 45d6089..e097538 100644 --- a/Examples/Request.py +++ b/Examples/Request.py @@ -110,8 +110,12 @@ def client(destination_hexhash, configpath): # We need a binary representation of the destination # hash that was entered on the command line try: - if len(destination_hexhash) != 20: - raise ValueError("Destination length is invalid, must be 20 hexadecimal characters (10 bytes)") + dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 + if len(destination_hexhash) != dest_len: + raise ValueError( + "Destination length is invalid, must be {hex} hexadecimal characters ({byte} bytes).".format(hex=dest_len, byte=dest_len//2) + ) + destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n") diff --git a/Examples/Speedtest.py b/Examples/Speedtest.py index 6fc340d..b66a556 100644 --- a/Examples/Speedtest.py +++ b/Examples/Speedtest.py @@ -166,8 +166,12 @@ def client(destination_hexhash, configpath): # We need a binary representation of the destination # hash that was entered on the command line try: - if len(destination_hexhash) != 20: - raise ValueError("Destination length is invalid, must be 20 hexadecimal characters (10 bytes)") + dest_len = (RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2 + if len(destination_hexhash) != dest_len: + raise ValueError( + "Destination length is invalid, must be {hex} hexadecimal characters ({byte} bytes).".format(hex=dest_len, byte=dest_len//2) + ) + destination_hash = bytes.fromhex(destination_hexhash) except: RNS.log("Invalid destination entered. Check your input!\n")