diff --git a/RNS/Interfaces/Interface.py b/RNS/Interfaces/Interface.py index f8949872..84018eb8 100755 --- a/RNS/Interfaces/Interface.py +++ b/RNS/Interfaces/Interface.py @@ -108,6 +108,7 @@ class Interface: self.last_discovery_announce = 0 self.bootstrap_only = False self.recursive_prs = False + self.announces_from_internal = True self.parent_interface = None self.spawned_interfaces = None self.tunnel_id = None diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index fcfb0736..9b067e62 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -813,6 +813,9 @@ class Reticulum: recursive_prs = False if "recursive_prs" in c: recursive_prs = c.as_bool("recursive_prs") + announces_from_internal = True + if "announces_from_internal" in c: announces_from_internal = c.as_bool("announces_from_internal") + ignore_config_warnings = False if "ignore_config_warnings" in c: ignore_config_warnings = c.as_bool("ignore_config_warnings") @@ -894,6 +897,7 @@ class Reticulum: interface.discovery_modulation = discovery_modulation interface.recursive_prs = recursive_prs + interface.announces_from_internal = announces_from_internal interface.announce_rate_target = announce_rate_target interface.announce_rate_grace = announce_rate_grace interface.announce_rate_penalty = announce_rate_penalty @@ -1053,7 +1057,7 @@ class Reticulum: def _add_interface(self, interface, mode = None, configured_bitrate=None, ifac_size=None, ifac_netname=None, ifac_netkey=None, announce_cap=None, announce_rate_target=None, announce_rate_grace=None, announce_rate_penalty=None, - bootstrap_only=False, recursive_prs=False): + bootstrap_only=False, recursive_prs=False, announces_from_internal=True): if not self.is_connected_to_shared_instance: if interface != None and issubclass(type(interface), RNS.Interfaces.Interface.Interface): @@ -1069,6 +1073,7 @@ class Reticulum: else: interface.ifac_size = interface.DEFAULT_IFAC_SIZE interface.recursive_prs = recursive_prs + interface.announces_from_internal = announces_from_internal interface.announce_cap = announce_cap if announce_cap != None else Reticulum.ANNOUNCE_CAP/100.0 interface.announce_rate_target = announce_rate_target interface.announce_rate_grace = announce_rate_grace diff --git a/RNS/Transport.py b/RNS/Transport.py index 37be9338..fdbaa616 100755 --- a/RNS/Transport.py +++ b/RNS/Transport.py @@ -1186,24 +1186,30 @@ class Transport: if packet.destination.type == RNS.Destination.LINK: if packet.destination.status == RNS.Link.CLOSED: should_transmit = False if interface != packet.destination.attached_interface: should_transmit = False - + if packet.attached_interface != None and interface != packet.attached_interface: should_transmit = False if packet.packet_type == RNS.Packet.ANNOUNCE: if packet.attached_interface == None: - if interface.mode == RNS.Interfaces.Interface.Interface.MODE_ACCESS_POINT: + from_interface = Transport.next_hop_interface(packet.destination_hash) + + if from_interface == None: + RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface doesn't exist", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None + should_transmit = False + + elif interface.announces_from_internal == False and from_interface.mode == RNS.Interfaces.Interface.Interface.MODE_INTERNAL: + RNS.log("Blocking announce broadcast on "+str(interface)+" due to internal-mode next hop interface", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None + should_transmit = False + + elif interface.mode == RNS.Interfaces.Interface.Interface.MODE_ACCESS_POINT: RNS.log("Blocking announce broadcast on "+str(interface)+" due to AP mode", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None should_transmit = False elif interface.mode == RNS.Interfaces.Interface.Interface.MODE_INTERNAL: - from_interface = Transport.next_hop_interface(packet.destination_hash) - if from_interface == None or not hasattr(from_interface, "mode"): + if not hasattr(from_interface, "mode"): should_transmit = False - if from_interface == None: - RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface doesn't exist", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None - elif not hasattr(from_interface, "mode"): - RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface has no mode configured", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None + RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface has no mode configured", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None else: if from_interface.mode == RNS.Interfaces.Interface.Interface.MODE_ROAMING: RNS.log("Blocking announce broadcast on "+str(interface)+" due to roaming-mode next-hop interface", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None @@ -1222,13 +1228,9 @@ class Transport: # RNS.log("Allowing announce broadcast on roaming-mode interface from instance-local destination", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None pass else: - from_interface = Transport.next_hop_interface(packet.destination_hash) - if from_interface == None or not hasattr(from_interface, "mode"): + if not hasattr(from_interface, "mode"): should_transmit = False - if from_interface == None: - RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface doesn't exist", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None - elif not hasattr(from_interface, "mode"): - RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface has no mode configured", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None + RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface has no mode configured", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None else: if from_interface.mode == RNS.Interfaces.Interface.Interface.MODE_ROAMING: RNS.log("Blocking announce broadcast on "+str(interface)+" due to roaming-mode next-hop interface", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None @@ -1247,13 +1249,9 @@ class Transport: # RNS.log("Allowing announce broadcast on boundary-mode interface from instance-local destination", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None pass else: - from_interface = Transport.next_hop_interface(packet.destination_hash) - if from_interface == None or not hasattr(from_interface, "mode"): + if not hasattr(from_interface, "mode"): should_transmit = False - if from_interface == None: - RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface doesn't exist", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None - elif not hasattr(from_interface, "mode"): - RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface has no mode configured", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None + RNS.log("Blocking announce broadcast on "+str(interface)+" since next hop interface has no mode configured", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None else: if from_interface.mode == RNS.Interfaces.Interface.Interface.MODE_ROAMING: RNS.log("Blocking announce broadcast on "+str(interface)+" due to roaming-mode next-hop interface", RNS.LOG_EXTREME) if RNS.sl(RNS.LOG_EXTREME) else None diff --git a/docs/source/interfaces.rst b/docs/source/interfaces.rst index e2a518ce..d9fad6b4 100644 --- a/docs/source/interfaces.rst +++ b/docs/source/interfaces.rst @@ -1214,6 +1214,15 @@ These can be used to control various aspects of interface behaviour. recursively discover paths for path requests received on this interface. + + * | The ``announces_from_internal`` option controls whether any + announces *received on* an ``internal`` mode interface will + propagate *out* on the interface this option is set on. Note + that this controls *announce propagation*; even if announces + do not propagate out when received, paths to destinations on + ``internal`` mode interfaces may still be resolvable by means + of path requests. + .. _interfaces-modes: Interface Modes