Implemented progress on resource initiator side. Made MDUs more obvious.

This commit is contained in:
Mark Qvist 2020-04-28 20:50:57 +02:00
parent a9c4d0e78d
commit c9d1c938ff
7 changed files with 34 additions and 15 deletions

View File

@ -89,7 +89,7 @@ def client_connected(link):
data = umsgpack.packb(list_files())
# Check the size of the packed data
if len(data) <= RNS.Reticulum.LINK_MDU:
if len(data) <= RNS.Link.MDU:
# If it fits in one packet, we will just
# send it as a single packet over the link.
list_packet = RNS.Packet(link, data)

View File

@ -23,6 +23,9 @@ class Identity:
HASHLENGTH = 256 # In bits
SIGLENGTH = KEYSIZE
ENCRYPT_CHUNKSIZE = (KEYSIZE-PADDINGSIZE)//8
DECRYPT_CHUNKSIZE = KEYSIZE//8
TRUNCATED_HASHLENGTH = 80 # In bits
# Storage
@ -222,7 +225,7 @@ class Identity:
def encrypt(self, plaintext):
if self.pub != None:
chunksize = (Identity.KEYSIZE-Identity.PADDINGSIZE)//8
chunksize = Identity.ENCRYPT_CHUNKSIZE
chunks = int(math.ceil(len(plaintext)/(float(chunksize))))
ciphertext = b"";
@ -249,7 +252,7 @@ class Identity:
if self.prv != None:
plaintext = None
try:
chunksize = (Identity.KEYSIZE)//8
chunksize = Identity.DECRYPT_CHUNKSIZE
chunks = int(math.ceil(len(ciphertext)/(float(chunksize))))
plaintext = b"";

View File

@ -8,6 +8,7 @@ from time import sleep
from .vendor import umsgpack as umsgpack
import threading
import base64
import math
import time
import RNS
@ -25,6 +26,8 @@ class Link:
CURVE = ec.SECP256R1()
ECPUBSIZE = 91
BLOCKSIZE = 16
AES_HMAC_OVERHEAD = 58
MDU = math.floor((RNS.Reticulum.MDU-AES_HMAC_OVERHEAD)/BLOCKSIZE)*BLOCKSIZE - 1
# TODO: This should not be hardcoded,
# but calculated from something like
@ -69,7 +72,7 @@ class Link:
#if self.owner.callbacks.link_established != None:
# self.owner.callbacks.link_established(link)
RNS.log("Incoming link request "+str(link)+" accepted, waiting for RTT packet", RNS.LOG_VERBOSE)
RNS.log("Incoming link request "+str(link)+" accepted", RNS.LOG_VERBOSE)
return link
except Exception as e:

View File

@ -1,4 +1,5 @@
import struct
import math
import time
import RNS
@ -40,11 +41,17 @@ class Packet:
# This is used to calculate allowable
# payload sizes
HEADER_MAXSIZE = RNS.Reticulum.HEADER_MAXSIZE
HEADER_MAXSIZE = 23
MDU = RNS.Reticulum.MDU
# With an MTU of 500, the maximum RSA-encrypted
# amount of data we can send in a single packet
# is given by the below calculation; 258 bytes.
RSA_MDU = math.floor(MDU/RNS.Identity.DECRYPT_CHUNKSIZE)*RNS.Identity.ENCRYPT_CHUNKSIZE
PLAIN_MDU = MDU
# TODO: This should be calculated
# more intelligently
# Default packet timeout
TIMEOUT = 60

View File

@ -11,7 +11,7 @@ class Resource:
WINDOW_MAX = 7
WINDOW = 4
MAPHASH_LEN = 4
SDU = RNS.Reticulum.MTU - RNS.Packet.HEADER_MAXSIZE
SDU = RNS.Packet.MDU
RANDOM_HASH_SIZE = 4
# TODO: Should be allocated more
@ -89,6 +89,7 @@ class Resource:
self.hmu_retry_ok = False
self.watchdog_lock = False
self.__watchdog_job_id = 0
self.__progress_callback = progress_callback
self.rtt = None
if data != None:
@ -96,7 +97,8 @@ class Resource:
while not hashmap_ok:
self.initiator = True
self.callback = callback
self.progress_callback = progress_callback
# TODO: Remove
#self.progress_callback = progress_callback
self.random_hash = RNS.Identity.getRandomHash()[:Resource.RANDOM_HASH_SIZE]
self.uncompressed_data = data
self.compressed_data = bz2.compress(self.uncompressed_data)
@ -478,6 +480,9 @@ class Resource:
if self.sent_parts == len(self.parts):
self.status = Resource.AWAITING_PROOF
if self.__progress_callback != None:
self.__progress_callback(self)
def cancel(self):
if self.status < Resource.COMPLETE:
self.status = Resource.FAILED
@ -497,6 +502,9 @@ class Resource:
self.__progress_callback = callback
def progress(self):
if self.initiator:
progress = self.sent_parts / len(self.parts)
else:
progress = self.received_count / float(self.total_parts)
return progress

View File

@ -14,10 +14,8 @@ import RNS
class Reticulum:
MTU = 500
HEADER_MAXSIZE = 23
PAD_AES_HMAC = 64
MDU = MTU - HEADER_MAXSIZE
LINK_MDU = MDU - PAD_AES_HMAC
router = None
config = None

View File

@ -77,7 +77,7 @@ def hexrep(data, delimit=True):
delimiter = ":"
if not delimit:
delimiter = ""
hexrep = delimiter.join("{:02x}".format(ord(c)) for c in data)
hexrep = delimiter.join("{:02x}".format(c) for c in data)
return hexrep
def prettyhexrep(data):