TCP performance improvements

This commit is contained in:
Mark Qvist 2020-05-12 08:50:51 +02:00
parent d121562b22
commit bf49eb2475
3 changed files with 43 additions and 35 deletions

View File

@ -55,7 +55,7 @@ Some countries still ban the use of encryption when operating under an amateur r
- pyserial - pyserial
## How do I get started? ## How do I get started?
Full documentation and video tutorials are coming with the stable alpha release. Until then, you are mostly on your own. If you really want to experiment already, you could take a look in the "Examples" folder, for some well-documented example programs. Be sure to also read the [Reticulum Overview Document](http://unsigned.io/wp-content/uploads/2018/04/Reticulum_Overview_v0.4.pdf). Full documentation and video tutorials are coming with the stable alpha release. Until then, you are mostly on your own. If you really want to experiment already, you could take a look in the "Examples" folder, for some well-documented example programs. The default configuration file created by Reticulum on the first run is also worth reading. Be sure to also read the [Reticulum Overview Document](http://unsigned.io/wp-content/uploads/2018/04/Reticulum_Overview_v0.4.pdf).
If you just need Reticulum as a dependency for another application, the easiest way is probably via pip: If you just need Reticulum as a dependency for another application, the easiest way is probably via pip:

View File

@ -78,10 +78,13 @@ class TCPClientInterface(Interface):
data_buffer = b"" data_buffer = b""
while True: while True:
data_in = self.socket.recv(1) data_in = self.socket.recv(1024)
if len(data_in) > 0: if len(data_in) > 0:
byte = ord(data_in) pointer = 0
while pointer < len(data_in):
byte = data_in[pointer]
pointer += 1
if (in_frame and byte == HDLC.FLAG): if (in_frame and byte == HDLC.FLAG):
in_frame = False in_frame = False
self.processIncoming(data_buffer) self.processIncoming(data_buffer)
@ -108,9 +111,8 @@ class TCPClientInterface(Interface):
except Exception as e: except Exception as e:
self.online = False self.online = False
RNS.log("An interface error occurred, the contained exception was: "+str(e), RNS.LOG_ERROR) RNS.log("An interface error occurred, the contained exception was: "+str(e), RNS.LOG_ERROR)
RNS.log("The interface "+str(self.name)+" is now offline. Restart Reticulum to attempt reconnection.", RNS.LOG_ERROR) RNS.log("Tearing down "+str(self), RNS.LOG_ERROR)
raise e self.teardown()
def teardown(self): def teardown(self):
self.online = False self.online = False
@ -128,8 +130,6 @@ class TCPServerInterface(Interface):
def __init__(self, owner, name, bindip=None, bindport=None): def __init__(self, owner, name, bindip=None, bindport=None):
self.IN = True self.IN = True
self.OUT = False self.OUT = False
self.transmit_delay = 0.001
self.name = name self.name = name
if (bindip != None and bindport != None): if (bindip != None and bindport != None):

View File

@ -438,6 +438,7 @@ class Resource:
pi = 0 pi = 0
for part in self.parts: for part in self.parts:
if part.map_hash == requested_hash: if part.map_hash == requested_hash:
try:
if not part.sent: if not part.sent:
part.send() part.send()
self.sent_parts += 1 self.sent_parts += 1
@ -446,6 +447,10 @@ class Resource:
self.last_activity = time.time() self.last_activity = time.time()
self.last_part_sent = self.last_activity self.last_part_sent = self.last_activity
break break
except Exception as e:
RNS.log("Resource could not send parts, cancelling transfer!", RNS.LOG_ERROR)
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
self.cancel()
pi += 1 pi += 1
if wants_more_hashmap: if wants_more_hashmap:
@ -488,8 +493,11 @@ class Resource:
self.status = Resource.FAILED self.status = Resource.FAILED
if self.initiator: if self.initiator:
if self.link.status == RNS.Link.ACTIVE: if self.link.status == RNS.Link.ACTIVE:
try:
cancel_packet = RNS.Packet(self.link, self.hash, context=RNS.Packet.RESOURCE_ICL) cancel_packet = RNS.Packet(self.link, self.hash, context=RNS.Packet.RESOURCE_ICL)
cancel_packet.send() cancel_packet.send()
except Exception as e:
RNS.log("Could not send resource cancel packet, the contained exception was: "+str(e), RNS.LOG_ERROR)
self.link.cancel_outgoing_resource(self) self.link.cancel_outgoing_resource(self)
else: else:
self.link.cancel_incoming_resource(self) self.link.cancel_incoming_resource(self)