Improved link establishment.

This commit is contained in:
Mark Qvist 2021-09-03 16:14:08 +02:00
parent 32e4c262ef
commit ecf0c55fd6

View File

@ -45,8 +45,10 @@ class Link:
MDU = math.floor((RNS.Reticulum.MTU-RNS.Reticulum.HEADER_MINSIZE-RNS.Identity.FERNET_OVERHEAD)/RNS.Identity.AES128_BLOCKSIZE)*RNS.Identity.AES128_BLOCKSIZE - 1 MDU = math.floor((RNS.Reticulum.MTU-RNS.Reticulum.HEADER_MINSIZE-RNS.Identity.FERNET_OVERHEAD)/RNS.Identity.AES128_BLOCKSIZE)*RNS.Identity.AES128_BLOCKSIZE - 1
# This value is set at a reasonable # This value is set at a reasonable level for a 1 Kb/s channel.
# level for a 1 Kb/s channel. #
# TODO: Find a way to automatically raise or lower this according to
# channel bandwidth and utilisation.
ESTABLISHMENT_TIMEOUT_PER_HOP = 5 ESTABLISHMENT_TIMEOUT_PER_HOP = 5
""" """
Default timeout for link establishment in seconds per hop to destination. Default timeout for link establishment in seconds per hop to destination.
@ -230,28 +232,29 @@ class Link:
self.had_outbound() self.had_outbound()
def validate_proof(self, packet): def validate_proof(self, packet):
if self.initiator and len(packet.data) == RNS.Identity.SIGLENGTH//8: if self.status == Link.HANDSHAKE:
signed_data = self.link_id+self.peer_pub_bytes+self.peer_sig_pub_bytes if self.initiator and len(packet.data) == RNS.Identity.SIGLENGTH//8:
signature = packet.data[:RNS.Identity.SIGLENGTH//8] signed_data = self.link_id+self.peer_pub_bytes+self.peer_sig_pub_bytes
signature = packet.data[:RNS.Identity.SIGLENGTH//8]
if self.destination.identity.validate(signature, signed_data): if self.destination.identity.validate(signature, signed_data):
self.rtt = time.time() - self.request_time self.rtt = time.time() - self.request_time
self.attached_interface = packet.receiving_interface self.attached_interface = packet.receiving_interface
self.__remote_identity = self.destination.identity self.__remote_identity = self.destination.identity
RNS.Transport.activate_link(self) RNS.Transport.activate_link(self)
RNS.log("Link "+str(self)+" established with "+str(self.destination)+", RTT is "+str(self.rtt), RNS.LOG_VERBOSE) RNS.log("Link "+str(self)+" established with "+str(self.destination)+", RTT is "+str(self.rtt), RNS.LOG_VERBOSE)
rtt_data = umsgpack.packb(self.rtt) rtt_data = umsgpack.packb(self.rtt)
rtt_packet = RNS.Packet(self, rtt_data, context=RNS.Packet.LRRTT) rtt_packet = RNS.Packet(self, rtt_data, context=RNS.Packet.LRRTT)
rtt_packet.send() rtt_packet.send()
self.had_outbound() self.had_outbound()
self.status = Link.ACTIVE self.status = Link.ACTIVE
if self.callbacks.link_established != None: if self.callbacks.link_established != None:
thread = threading.Thread(target=self.callbacks.link_established, args=(self,)) thread = threading.Thread(target=self.callbacks.link_established, args=(self,))
thread.setDaemon(True) thread.setDaemon(True)
thread.start() thread.start()
else: else:
RNS.log("Invalid link proof signature received by "+str(self)+". Ignoring.", RNS.LOG_DEBUG) RNS.log("Invalid link proof signature received by "+str(self)+". Ignoring.", RNS.LOG_DEBUG)
def identify(self, identity): def identify(self, identity):