Implemented progress on resource initiator side. Made MDUs more obvious.
This commit is contained in:
parent
a9c4d0e78d
commit
c9d1c938ff
|
@ -89,7 +89,7 @@ def client_connected(link):
|
||||||
data = umsgpack.packb(list_files())
|
data = umsgpack.packb(list_files())
|
||||||
|
|
||||||
# Check the size of the packed data
|
# 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
|
# If it fits in one packet, we will just
|
||||||
# send it as a single packet over the link.
|
# send it as a single packet over the link.
|
||||||
list_packet = RNS.Packet(link, data)
|
list_packet = RNS.Packet(link, data)
|
||||||
|
|
|
@ -23,6 +23,9 @@ class Identity:
|
||||||
HASHLENGTH = 256 # In bits
|
HASHLENGTH = 256 # In bits
|
||||||
SIGLENGTH = KEYSIZE
|
SIGLENGTH = KEYSIZE
|
||||||
|
|
||||||
|
ENCRYPT_CHUNKSIZE = (KEYSIZE-PADDINGSIZE)//8
|
||||||
|
DECRYPT_CHUNKSIZE = KEYSIZE//8
|
||||||
|
|
||||||
TRUNCATED_HASHLENGTH = 80 # In bits
|
TRUNCATED_HASHLENGTH = 80 # In bits
|
||||||
|
|
||||||
# Storage
|
# Storage
|
||||||
|
@ -222,7 +225,7 @@ class Identity:
|
||||||
|
|
||||||
def encrypt(self, plaintext):
|
def encrypt(self, plaintext):
|
||||||
if self.pub != None:
|
if self.pub != None:
|
||||||
chunksize = (Identity.KEYSIZE-Identity.PADDINGSIZE)//8
|
chunksize = Identity.ENCRYPT_CHUNKSIZE
|
||||||
chunks = int(math.ceil(len(plaintext)/(float(chunksize))))
|
chunks = int(math.ceil(len(plaintext)/(float(chunksize))))
|
||||||
|
|
||||||
ciphertext = b"";
|
ciphertext = b"";
|
||||||
|
@ -249,7 +252,7 @@ class Identity:
|
||||||
if self.prv != None:
|
if self.prv != None:
|
||||||
plaintext = None
|
plaintext = None
|
||||||
try:
|
try:
|
||||||
chunksize = (Identity.KEYSIZE)//8
|
chunksize = Identity.DECRYPT_CHUNKSIZE
|
||||||
chunks = int(math.ceil(len(ciphertext)/(float(chunksize))))
|
chunks = int(math.ceil(len(ciphertext)/(float(chunksize))))
|
||||||
|
|
||||||
plaintext = b"";
|
plaintext = b"";
|
||||||
|
|
|
@ -8,6 +8,7 @@ from time import sleep
|
||||||
from .vendor import umsgpack as umsgpack
|
from .vendor import umsgpack as umsgpack
|
||||||
import threading
|
import threading
|
||||||
import base64
|
import base64
|
||||||
|
import math
|
||||||
import time
|
import time
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
|
@ -25,6 +26,8 @@ class Link:
|
||||||
CURVE = ec.SECP256R1()
|
CURVE = ec.SECP256R1()
|
||||||
ECPUBSIZE = 91
|
ECPUBSIZE = 91
|
||||||
BLOCKSIZE = 16
|
BLOCKSIZE = 16
|
||||||
|
AES_HMAC_OVERHEAD = 58
|
||||||
|
MDU = math.floor((RNS.Reticulum.MDU-AES_HMAC_OVERHEAD)/BLOCKSIZE)*BLOCKSIZE - 1
|
||||||
|
|
||||||
# TODO: This should not be hardcoded,
|
# TODO: This should not be hardcoded,
|
||||||
# but calculated from something like
|
# but calculated from something like
|
||||||
|
@ -44,8 +47,8 @@ class Link:
|
||||||
DESTINATION_CLOSED = 0x03
|
DESTINATION_CLOSED = 0x03
|
||||||
|
|
||||||
ACCEPT_NONE = 0x00
|
ACCEPT_NONE = 0x00
|
||||||
ACCEPT_APP = 0x01
|
ACCEPT_APP = 0x01
|
||||||
ACCEPT_ALL = 0x02
|
ACCEPT_ALL = 0x02
|
||||||
resource_strategies = [ACCEPT_NONE, ACCEPT_APP, ACCEPT_ALL]
|
resource_strategies = [ACCEPT_NONE, ACCEPT_APP, ACCEPT_ALL]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -69,7 +72,7 @@ class Link:
|
||||||
#if self.owner.callbacks.link_established != None:
|
#if self.owner.callbacks.link_established != None:
|
||||||
# self.owner.callbacks.link_established(link)
|
# 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
|
return link
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import struct
|
import struct
|
||||||
|
import math
|
||||||
import time
|
import time
|
||||||
import RNS
|
import RNS
|
||||||
|
|
||||||
|
@ -40,11 +41,17 @@ class Packet:
|
||||||
|
|
||||||
# This is used to calculate allowable
|
# This is used to calculate allowable
|
||||||
# payload sizes
|
# 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
|
# TODO: This should be calculated
|
||||||
# more intelligently
|
# more intelligently
|
||||||
|
|
||||||
# Default packet timeout
|
# Default packet timeout
|
||||||
TIMEOUT = 60
|
TIMEOUT = 60
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Resource:
|
||||||
WINDOW_MAX = 7
|
WINDOW_MAX = 7
|
||||||
WINDOW = 4
|
WINDOW = 4
|
||||||
MAPHASH_LEN = 4
|
MAPHASH_LEN = 4
|
||||||
SDU = RNS.Reticulum.MTU - RNS.Packet.HEADER_MAXSIZE
|
SDU = RNS.Packet.MDU
|
||||||
RANDOM_HASH_SIZE = 4
|
RANDOM_HASH_SIZE = 4
|
||||||
|
|
||||||
# TODO: Should be allocated more
|
# TODO: Should be allocated more
|
||||||
|
@ -89,6 +89,7 @@ class Resource:
|
||||||
self.hmu_retry_ok = False
|
self.hmu_retry_ok = False
|
||||||
self.watchdog_lock = False
|
self.watchdog_lock = False
|
||||||
self.__watchdog_job_id = 0
|
self.__watchdog_job_id = 0
|
||||||
|
self.__progress_callback = progress_callback
|
||||||
self.rtt = None
|
self.rtt = None
|
||||||
|
|
||||||
if data != None:
|
if data != None:
|
||||||
|
@ -96,7 +97,8 @@ class Resource:
|
||||||
while not hashmap_ok:
|
while not hashmap_ok:
|
||||||
self.initiator = True
|
self.initiator = True
|
||||||
self.callback = callback
|
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.random_hash = RNS.Identity.getRandomHash()[:Resource.RANDOM_HASH_SIZE]
|
||||||
self.uncompressed_data = data
|
self.uncompressed_data = data
|
||||||
self.compressed_data = bz2.compress(self.uncompressed_data)
|
self.compressed_data = bz2.compress(self.uncompressed_data)
|
||||||
|
@ -478,6 +480,9 @@ class Resource:
|
||||||
if self.sent_parts == len(self.parts):
|
if self.sent_parts == len(self.parts):
|
||||||
self.status = Resource.AWAITING_PROOF
|
self.status = Resource.AWAITING_PROOF
|
||||||
|
|
||||||
|
if self.__progress_callback != None:
|
||||||
|
self.__progress_callback(self)
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
if self.status < Resource.COMPLETE:
|
if self.status < Resource.COMPLETE:
|
||||||
self.status = Resource.FAILED
|
self.status = Resource.FAILED
|
||||||
|
@ -497,7 +502,10 @@ class Resource:
|
||||||
self.__progress_callback = callback
|
self.__progress_callback = callback
|
||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
progress = self.received_count / float(self.total_parts)
|
if self.initiator:
|
||||||
|
progress = self.sent_parts / len(self.parts)
|
||||||
|
else:
|
||||||
|
progress = self.received_count / float(self.total_parts)
|
||||||
return progress
|
return progress
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -14,10 +14,8 @@ import RNS
|
||||||
class Reticulum:
|
class Reticulum:
|
||||||
MTU = 500
|
MTU = 500
|
||||||
HEADER_MAXSIZE = 23
|
HEADER_MAXSIZE = 23
|
||||||
|
|
||||||
PAD_AES_HMAC = 64
|
|
||||||
MDU = MTU - HEADER_MAXSIZE
|
MDU = MTU - HEADER_MAXSIZE
|
||||||
LINK_MDU = MDU - PAD_AES_HMAC
|
|
||||||
router = None
|
router = None
|
||||||
config = None
|
config = None
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ def hexrep(data, delimit=True):
|
||||||
delimiter = ":"
|
delimiter = ":"
|
||||||
if not delimit:
|
if not delimit:
|
||||||
delimiter = ""
|
delimiter = ""
|
||||||
hexrep = delimiter.join("{:02x}".format(ord(c)) for c in data)
|
hexrep = delimiter.join("{:02x}".format(c) for c in data)
|
||||||
return hexrep
|
return hexrep
|
||||||
|
|
||||||
def prettyhexrep(data):
|
def prettyhexrep(data):
|
||||||
|
|
Loading…
Reference in New Issue