Made running Transport a config choice

This commit is contained in:
Mark Qvist 2020-04-27 12:04:14 +02:00
parent b78e0e9ec0
commit 1391c9ef3b
3 changed files with 139 additions and 125 deletions

View File

@ -96,6 +96,7 @@ def client(destination_hexhash, configpath, timeout=None):
# We override the loglevel to provide feedback when
# an announce is received
if RNS.loglevel < RNS.LOG_INFO:
RNS.loglevel = RNS.LOG_INFO
# Tell the user that the client is ready!

View File

@ -40,6 +40,7 @@ class Reticulum:
Reticulum.cachepath = Reticulum.configdir+"/storage/cache"
Reticulum.__allow_unencrypted = False
Reticulum.__transport_enabled = False
Reticulum.__use_implicit_proof = True
if not os.path.isdir(Reticulum.storagepath):
@ -60,7 +61,6 @@ class Reticulum:
self.applyConfig()
RNS.Identity.loadKnownDestinations()
Reticulum.router = self
RNS.Transport.start()
@ -80,22 +80,28 @@ class Reticulum:
if "reticulum" in self.config:
for option in self.config["reticulum"]:
value = self.config["reticulum"][option]
if option == "enable_transport":
v = self.config["reticulum"].as_bool(option)
if v == True:
Reticulum.__transport_enabled = True
if option == "use_implicit_proof":
if value == "true":
v = self.config["reticulum"].as_bool(option)
if v == True:
Reticulum.__use_implicit_proof = True
if value == "false":
if v == False:
Reticulum.__use_implicit_proof = False
if option == "allow_unencrypted":
if value == "true":
v = self.config["reticulum"].as_bool(option)
if v == True:
RNS.log("", RNS.LOG_CRITICAL)
RNS.log("! ! !", RNS.LOG_CRITICAL)
RNS.log("! ! ! ! ! ! ! ! !", RNS.LOG_CRITICAL)
RNS.log("", RNS.LOG_CRITICAL)
RNS.log("Danger! Encryptionless links have been allowed in the config file!", RNS.LOG_CRITICAL)
RNS.log("Beware of the consequences! Any data sent over a link can potentially be intercepted,", RNS.LOG_CRITICAL)
RNS.log("read and modified! If you are not absolutely sure that you want this,", RNS.LOG_CRITICAL)
RNS.log("you should exit Reticulum NOW and change your config file!", RNS.LOG_CRITICAL)
RNS.log("", RNS.LOG_CRITICAL)
RNS.log("! ! !", RNS.LOG_CRITICAL)
RNS.log("! ! ! ! ! ! ! ! !", RNS.LOG_CRITICAL)
RNS.log("", RNS.LOG_CRITICAL)
Reticulum.__allow_unencrypted = True
@ -286,6 +292,10 @@ class Reticulum:
def should_use_implicit_proof():
return Reticulum.__use_implicit_proof
@staticmethod
def transport_enabled():
return Reticulum.__transport_enabled
# Default configuration file:
__default_rns_config__ = '''# This is the default Reticulum config file.
# You should probably edit it to include any additional,

View File

@ -90,6 +90,7 @@ class Transport:
except Exception as e:
RNS.log("Could not load packet hashlist from disk, the contained exception was: "+str(e), RNS.LOG_ERROR)
if RNS.Reticulum.transport_enabled():
# Create transport-specific destinations
path_request_destination = RNS.Destination(None, RNS.Destination.IN, RNS.Destination.PLAIN, Transport.APP_NAME, "path", "request")
path_request_destination.packet_callback(Transport.pathRequestHandler)
@ -98,6 +99,7 @@ class Transport:
thread.setDaemon(True)
thread.start()
if RNS.Reticulum.transport_enabled():
RNS.log("Transport instance "+str(Transport.identity)+" started")
@staticmethod
@ -123,6 +125,7 @@ class Transport:
Transport.receipts_last_checked = time.time()
if RNS.Reticulum.transport_enabled():
# Process announces needing retransmission
if time.time() > Transport.announces_last_checked+Transport.announces_check_interval:
for destination_hash in Transport.announce_table:
@ -170,7 +173,7 @@ class Transport:
if time.time() > link_entry[0] + Transport.LINK_TIMEOUT:
Transport.link_table.pop(link_id)
# Cull the destination table in some way
# Cull the destination table
for destination_hash in Transport.destination_table:
destination_entry = Transport.destination_table[destination_hash]
if time.time() > destination_entry[0] + Transport.DESTINATION_TIMEOUT:
@ -295,6 +298,7 @@ class Transport:
# General transport handling. Takes care of directing
# packets according to transport tables and recording
# entries in reverse and link tables.
if RNS.Reticulum.transport_enabled():
if packet.transport_id != None and packet.packet_type != RNS.Packet.ANNOUNCE:
if packet.transport_id == Transport.identity.hash:
RNS.log("Received packet in transport for "+RNS.prettyhexrep(packet.destination_hash)+" with matching transport ID, transporting it...", RNS.LOG_DEBUG)
@ -348,7 +352,7 @@ class Transport:
else:
pass
# Link transport handling. Directs packetes according
# Link transport handling. Directs packets according
# to entries in the link tables
if packet.packet_type != RNS.Packet.ANNOUNCE and packet.packet_type != RNS.Packet.LINKREQUEST:
if packet.destination_hash in Transport.link_table:
@ -397,7 +401,7 @@ class Transport:
# Check if this is a next retransmission from
# another node. If it is, we're removing the
# announce in question from our pending table
if packet.destination_hash in Transport.announce_table:
if RNS.Reticulum.transport_enabled() and packet.destination_hash in Transport.announce_table:
announce_entry = Transport.announce_table[packet.destination_hash]
if packet.hops-1 == announce_entry[4]:
@ -472,7 +476,7 @@ class Transport:
random_blobs.append(random_blob)
retransmit_timeout = now + math.pow(Transport.PATHFINDER_C, packet.hops) + (RNS.rand() * Transport.PATHFINDER_RW)
if packet.context != RNS.Packet.PATH_RESPONSE:
if RNS.Reticulum.transport_enabled() and packet.context != RNS.Packet.PATH_RESPONSE:
Transport.announce_table[packet.destination_hash] = [now, retransmit_timeout, retries, received_from, packet.hops, packet, local_rebroadcasts, block_rebroadcasts]
Transport.destination_table[packet.destination_hash] = [now, received_from, packet.hops, expires, random_blobs, packet.receiving_interface, packet]
@ -509,7 +513,7 @@ class Transport:
# This is a link request proof, check if it
# needs to be transported
if packet.destination_hash in Transport.link_table:
if RNS.Reticulum.transport_enabled() and packet.destination_hash in Transport.link_table:
link_entry = Transport.link_table[packet.destination_hash]
if packet.receiving_interface == link_entry[2]:
# TODO: Should we validate the LR proof at each transport
@ -538,7 +542,6 @@ class Transport:
for link in Transport.active_links:
if link.link_id == packet.destination_hash:
packet.link = link
# plaintext = link.decrypt(packet.data)
if len(packet.data) == RNS.PacketReceipt.EXPL_LENGTH:
proof_hash = packet.data[:RNS.Identity.HASHLENGTH//8]
@ -546,7 +549,7 @@ class Transport:
proof_hash = None
# Check if this proof neds to be transported
if packet.destination_hash in Transport.reverse_table:
if RNS.Reticulum.transport_enabled() and packet.destination_hash in Transport.reverse_table:
reverse_entry = Transport.reverse_table.pop(packet.destination_hash)
if packet.receiving_interface == reverse_entry[1]:
RNS.log("Proof received on correct interface, transporting it via "+str(reverse_entry[0]), RNS.LOG_DEBUG)