mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-06-25 13:14:31 -07:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3819485c20 | |||
| 3ca06bbf3a |
+47
-6
@@ -324,6 +324,11 @@ class Transport:
|
||||
if packet.packet_type != RNS.Packet.ANNOUNCE and packet.destination_hash in Transport.destination_table:
|
||||
outbound_interface = Transport.destination_table[packet.destination_hash][5]
|
||||
|
||||
# If there's more than one hop to the destination, and we know
|
||||
# a path, we insert the packet into transport by adding the next
|
||||
# transport nodes address to the header, and modifying the flags.
|
||||
# This rule applies both for "normal" transport, and when connected
|
||||
# to a local shared Reticulum instance.
|
||||
if Transport.destination_table[packet.destination_hash][2] > 1:
|
||||
if packet.header_type == RNS.Packet.HEADER_1:
|
||||
# Insert packet into transport
|
||||
@@ -333,19 +338,44 @@ class Transport:
|
||||
new_raw += Transport.destination_table[packet.destination_hash][1]
|
||||
new_raw += packet.raw[2:]
|
||||
# TODO: Remove at some point
|
||||
RNS.log("Packet was inserted into transport via "+RNS.prettyhexrep(Transport.destination_table[packet.destination_hash][1])+" on: "+str(outbound_interface), RNS.LOG_DEBUG)
|
||||
RNS.log("Packet was inserted into transport via "+RNS.prettyhexrep(Transport.destination_table[packet.destination_hash][1])+" on: "+str(outbound_interface), RNS.LOG_EXTREME)
|
||||
outbound_interface.processOutgoing(new_raw)
|
||||
Transport.destination_table[packet.destination_hash][0] = time.time()
|
||||
sent = True
|
||||
|
||||
# In the special case where we are connected to a local shared
|
||||
# Reticulum instance, and the destination is one hop away, we
|
||||
# also add transport headers to inject the packet into transport
|
||||
# via the shared instance. Normally a packet for a destination
|
||||
# one hop away would just be broadcast directly, but since we
|
||||
# are "behind" a shared instance, we need to get that instance
|
||||
# to transport it onto the network.
|
||||
elif Transport.destination_table[packet.destination_hash][2] == 1 and Transport.owner.is_connected_to_shared_instance:
|
||||
if packet.header_type == RNS.Packet.HEADER_1:
|
||||
# Insert packet into transport
|
||||
new_flags = (RNS.Packet.HEADER_2) << 6 | (Transport.TRANSPORT) << 4 | (packet.flags & 0b00001111)
|
||||
new_raw = struct.pack("!B", new_flags)
|
||||
new_raw += packet.raw[1:2]
|
||||
new_raw += Transport.destination_table[packet.destination_hash][1]
|
||||
new_raw += packet.raw[2:]
|
||||
# TODO: Remove at some point
|
||||
RNS.log("Packet was inserted into transport via "+RNS.prettyhexrep(Transport.destination_table[packet.destination_hash][1])+" on: "+str(outbound_interface), RNS.LOG_EXTREME)
|
||||
outbound_interface.processOutgoing(new_raw)
|
||||
Transport.destination_table[packet.destination_hash][0] = time.time()
|
||||
sent = True
|
||||
|
||||
# If none of the above applies, we know the destination is
|
||||
# directly reachable, and also on which interface, so we
|
||||
# simply transmit the packet directly on that one.
|
||||
else:
|
||||
# Destination is directly reachable, and we know on
|
||||
# what interface, so transmit only on that one
|
||||
outbound_interface.processOutgoing(packet.raw)
|
||||
sent = True
|
||||
|
||||
# If we don't have a known path for the destination, we'll
|
||||
# broadcast the packet on all outgoing interfaces, or the
|
||||
# just the relevant interface if the packet has an attached
|
||||
# interface, or belongs to a link.
|
||||
else:
|
||||
# Broadcast packet on all outgoing interfaces, or the relevant
|
||||
# interface if packet is for a link or has an attached interface
|
||||
for interface in Transport.interfaces:
|
||||
if interface.OUT:
|
||||
should_transmit = True
|
||||
@@ -961,7 +991,12 @@ class Transport:
|
||||
local_rebroadcasts = 0
|
||||
block_rebroadcasts = True
|
||||
announce_hops = packet.hops
|
||||
retransmit_timeout = now + Transport.PATH_REQUEST_GRACE # + (RNS.rand() * Transport.PATHFINDER_RW)
|
||||
|
||||
if is_from_local_client:
|
||||
retransmit_timeout = now
|
||||
else:
|
||||
# TODO: Look at this timing
|
||||
retransmit_timeout = now + Transport.PATH_REQUEST_GRACE # + (RNS.rand() * Transport.PATHFINDER_RW)
|
||||
|
||||
# This handles an edge case where a peer sends a past
|
||||
# request for a destination just after an announce for
|
||||
@@ -982,6 +1017,12 @@ class Transport:
|
||||
if not interface == attached_interface:
|
||||
Transport.requestPathOnInterface(destination_hash, interface)
|
||||
|
||||
elif not is_from_local_client and len(Transport.local_client_interfaces) > 0:
|
||||
# Forward the path request on all local
|
||||
# client interfaces
|
||||
for interface in Transport.local_client_interfaces:
|
||||
Transport.requestPathOnInterface(destination_hash, interface)
|
||||
|
||||
else:
|
||||
RNS.log("No known path to requested destination, ignoring request", RNS.LOG_DEBUG)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user