TCP performance improvements
This commit is contained in:
parent
d121562b22
commit
bf49eb2475
@ -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:
|
||||||
|
|
||||||
|
@ -78,27 +78,30 @@ 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
|
||||||
if (in_frame and byte == HDLC.FLAG):
|
while pointer < len(data_in):
|
||||||
in_frame = False
|
byte = data_in[pointer]
|
||||||
self.processIncoming(data_buffer)
|
pointer += 1
|
||||||
elif (byte == HDLC.FLAG):
|
if (in_frame and byte == HDLC.FLAG):
|
||||||
in_frame = True
|
in_frame = False
|
||||||
data_buffer = b""
|
self.processIncoming(data_buffer)
|
||||||
elif (in_frame and len(data_buffer) < RNS.Reticulum.MTU):
|
elif (byte == HDLC.FLAG):
|
||||||
if (byte == HDLC.ESC):
|
in_frame = True
|
||||||
escape = True
|
data_buffer = b""
|
||||||
else:
|
elif (in_frame and len(data_buffer) < RNS.Reticulum.MTU):
|
||||||
if (escape):
|
if (byte == HDLC.ESC):
|
||||||
if (byte == HDLC.FLAG ^ HDLC.ESC_MASK):
|
escape = True
|
||||||
byte = HDLC.FLAG
|
else:
|
||||||
if (byte == HDLC.ESC ^ HDLC.ESC_MASK):
|
if (escape):
|
||||||
byte = HDLC.ESC
|
if (byte == HDLC.FLAG ^ HDLC.ESC_MASK):
|
||||||
escape = False
|
byte = HDLC.FLAG
|
||||||
data_buffer = data_buffer+bytes([byte])
|
if (byte == HDLC.ESC ^ HDLC.ESC_MASK):
|
||||||
|
byte = HDLC.ESC
|
||||||
|
escape = False
|
||||||
|
data_buffer = data_buffer+bytes([byte])
|
||||||
else:
|
else:
|
||||||
RNS.log("TCP socket for "+str(self)+" was closed, tearing down interface", RNS.LOG_VERBOSE)
|
RNS.log("TCP socket for "+str(self)+" was closed, tearing down interface", RNS.LOG_VERBOSE)
|
||||||
self.teardown()
|
self.teardown()
|
||||||
@ -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):
|
||||||
|
@ -438,14 +438,19 @@ 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:
|
||||||
if not part.sent:
|
try:
|
||||||
part.send()
|
if not part.sent:
|
||||||
self.sent_parts += 1
|
part.send()
|
||||||
else:
|
self.sent_parts += 1
|
||||||
part.resend()
|
else:
|
||||||
self.last_activity = time.time()
|
part.resend()
|
||||||
self.last_part_sent = self.last_activity
|
self.last_activity = time.time()
|
||||||
break
|
self.last_part_sent = self.last_activity
|
||||||
|
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:
|
||||||
cancel_packet = RNS.Packet(self.link, self.hash, context=RNS.Packet.RESOURCE_ICL)
|
try:
|
||||||
cancel_packet.send()
|
cancel_packet = RNS.Packet(self.link, self.hash, context=RNS.Packet.RESOURCE_ICL)
|
||||||
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user