Improved shared instance and local client handling

This commit is contained in:
Mark Qvist 2021-10-03 15:23:12 +02:00
parent 4c6ba97dca
commit 75c3180933
4 changed files with 45 additions and 41 deletions

View File

@ -527,7 +527,7 @@ class Link:
else: else:
response_resource = RNS.Resource(packed_response, self, request_id = request_id, is_response = True) response_resource = RNS.Resource(packed_response, self, request_id = request_id, is_response = True)
else: else:
identity_string = RNS.prettyhexrep(self.get_remote_identity()) if self.get_remote_identity() != None else "<Unknown>" identity_string = str(self.get_remote_identity()) if self.get_remote_identity() != None else "<Unknown>"
RNS.log("Request "+RNS.prettyhexrep(request_id)+" from "+identity_string+" not allowed for: "+str(path), RNS.LOG_DEBUG) RNS.log("Request "+RNS.prettyhexrep(request_id)+" from "+identity_string+" not allowed for: "+str(path), RNS.LOG_DEBUG)
def handle_response(self, request_id, response_data, response_size, response_transfer_size): def handle_response(self, request_id, response_data, response_size, response_transfer_size):

View File

@ -193,6 +193,7 @@ class Reticulum:
self.is_shared_instance = False self.is_shared_instance = False
self.is_standalone_instance = False self.is_standalone_instance = False
self.is_connected_to_shared_instance = True self.is_connected_to_shared_instance = True
Reticulum.__transport_enabled = False
RNS.log("Connected to local shared instance via: "+str(interface), RNS.LOG_DEBUG) RNS.log("Connected to local shared instance via: "+str(interface), RNS.LOG_DEBUG)
except Exception as e: except Exception as e:
RNS.log("Local shared instance appears to be running, but it could not be connected", RNS.LOG_ERROR) RNS.log("Local shared instance appears to be running, but it could not be connected", RNS.LOG_ERROR)

View File

@ -831,6 +831,7 @@ class Transport:
# If the announce is from a local client, # If the announce is from a local client,
# we announce it immediately, but only one # we announce it immediately, but only one
# time. # time.
if Transport.from_local_client(packet): if Transport.from_local_client(packet):
retransmit_timeout = now retransmit_timeout = now
retries = Transport.PATHFINDER_R retries = Transport.PATHFINDER_R
@ -858,8 +859,8 @@ class Transport:
announce_data = packet.data announce_data = packet.data
if Transport.from_local_client(packet) and packet.context == RNS.Packet.PATH_RESPONSE: if Transport.from_local_client(packet) and packet.context == RNS.Packet.PATH_RESPONSE:
for interface in Transport.interfaces: for local_interface in Transport.local_client_interfaces:
if packet.receiving_interface != interface: if packet.receiving_interface != local_interface:
new_announce = RNS.Packet( new_announce = RNS.Packet(
announce_destination, announce_destination,
announce_data, announce_data,
@ -868,7 +869,7 @@ class Transport:
header_type = RNS.Packet.HEADER_2, header_type = RNS.Packet.HEADER_2,
transport_type = Transport.TRANSPORT, transport_type = Transport.TRANSPORT,
transport_id = Transport.identity.hash, transport_id = Transport.identity.hash,
attached_interface = interface attached_interface = local_interface
) )
new_announce.hops = packet.hops new_announce.hops = packet.hops
@ -876,19 +877,20 @@ class Transport:
else: else:
for local_interface in Transport.local_client_interfaces: for local_interface in Transport.local_client_interfaces:
new_announce = RNS.Packet( if packet.receiving_interface != local_interface:
announce_destination, new_announce = RNS.Packet(
announce_data, announce_destination,
RNS.Packet.ANNOUNCE, announce_data,
context = announce_context, RNS.Packet.ANNOUNCE,
header_type = RNS.Packet.HEADER_2, context = announce_context,
transport_type = Transport.TRANSPORT, header_type = RNS.Packet.HEADER_2,
transport_id = Transport.identity.hash, transport_type = Transport.TRANSPORT,
attached_interface = local_interface transport_id = Transport.identity.hash,
) attached_interface = local_interface
)
new_announce.hops = packet.hops new_announce.hops = packet.hops
new_announce.send() new_announce.send()
destination_table_entry = [now, received_from, announce_hops, expires, random_blobs, packet.receiving_interface, packet] destination_table_entry = [now, received_from, announce_hops, expires, random_blobs, packet.receiving_interface, packet]
Transport.destination_table[packet.destination_hash] = destination_table_entry Transport.destination_table[packet.destination_hash] = destination_table_entry
@ -906,29 +908,30 @@ class Transport:
# Call externally registered callbacks from apps # Call externally registered callbacks from apps
# wanting to know when an announce arrives # wanting to know when an announce arrives
for handler in Transport.announce_handlers: if packet.context != RNS.Packet.PATH_RESPONSE:
try: for handler in Transport.announce_handlers:
# Check that the announced destination matches try:
# the handlers aspect filter # Check that the announced destination matches
execute_callback = False # the handlers aspect filter
if handler.aspect_filter == None: execute_callback = False
# If the handlers aspect filter is set to if handler.aspect_filter == None:
# None, we execute the callback in all cases # If the handlers aspect filter is set to
execute_callback = True # None, we execute the callback in all cases
else:
announce_identity = RNS.Identity.recall(packet.destination_hash)
handler_expected_hash = RNS.Destination.hash_from_name_and_identity(handler.aspect_filter, announce_identity)
if packet.destination_hash == handler_expected_hash:
execute_callback = True execute_callback = True
if execute_callback: else:
handler.received_announce( announce_identity = RNS.Identity.recall(packet.destination_hash)
destination_hash=packet.destination_hash, handler_expected_hash = RNS.Destination.hash_from_name_and_identity(handler.aspect_filter, announce_identity)
announced_identity=announce_identity, if packet.destination_hash == handler_expected_hash:
app_data=RNS.Identity.recall_app_data(packet.destination_hash) execute_callback = True
) if execute_callback:
except Exception as e: handler.received_announce(
RNS.log("Error while processing external announce callback.", RNS.LOG_ERROR) destination_hash=packet.destination_hash,
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR) announced_identity=announce_identity,
app_data=RNS.Identity.recall_app_data(packet.destination_hash)
)
except Exception as e:
RNS.log("Error while processing external announce callback.", RNS.LOG_ERROR)
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
# Handling for linkrequests to local destinations # Handling for linkrequests to local destinations
elif packet.packet_type == RNS.Packet.LINKREQUEST: elif packet.packet_type == RNS.Packet.LINKREQUEST:
@ -1353,7 +1356,7 @@ class Transport:
RNS.log("Destination is local to this system, announcing", RNS.LOG_DEBUG) RNS.log("Destination is local to this system, announcing", RNS.LOG_DEBUG)
local_destination.announce(path_response=True) local_destination.announce(path_response=True)
elif (RNS.Reticulum.transport_enabled() or is_from_local_client) and destination_hash in Transport.destination_table: elif (RNS.Reticulum.transport_enabled() or is_from_local_client or len(Transport.local_client_interfaces) > 0) and destination_hash in Transport.destination_table:
RNS.log("Path found, inserting announce for transmission", RNS.LOG_DEBUG) RNS.log("Path found, inserting announce for transmission", RNS.LOG_DEBUG)
packet = Transport.destination_table[destination_hash][6] packet = Transport.destination_table[destination_hash][6]
received_from = Transport.destination_table[destination_hash][5] received_from = Transport.destination_table[destination_hash][5]

View File

@ -1 +1 @@
__version__ = "0.2.6" __version__ = "0.2.7"