Skip to content

Commit

Permalink
Fixed spawned interface count sometimes being inaccurate on TCP and I…
Browse files Browse the repository at this point in the history
…2P interfaces
  • Loading branch information
markqvist committed Nov 22, 2024
1 parent c02e59e commit e81c22c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
14 changes: 10 additions & 4 deletions RNS/Interfaces/I2PInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,8 @@ def teardown(self):
self.IN = False

if hasattr(self, "parent_interface") and self.parent_interface != None:
if self.parent_interface.clients > 0:
self.parent_interface.clients -= 1
while self in self.parent_interface.spawned_interfaces:
self.parent_interface.spawned_interfaces.remove(self)

if self in RNS.Transport.interfaces:
if not self.initiator:
Expand All @@ -831,6 +831,10 @@ class I2PInterface(Interface):
BITRATE_GUESS = 256*1000
DEFAULT_IFAC_SIZE = 16

@property
def clients(self):
return len(self.spawned_interfaces)

def __init__(self, owner, configuration):
super().__init__()

Expand All @@ -846,7 +850,7 @@ def __init__(self, owner, configuration):
self.HW_MTU = 1064

self.online = False
self.clients = 0
self.spawned_interfaces = []
self.owner = owner
self.connectable = connectable
self.i2p_tunneled = True
Expand Down Expand Up @@ -966,7 +970,9 @@ def incoming_connection(self, handler):
spawned_interface.HW_MTU = self.HW_MTU
RNS.log("Spawned new I2PInterface Peer: "+str(spawned_interface), RNS.LOG_VERBOSE)
RNS.Transport.interfaces.append(spawned_interface)
self.clients += 1
while spawned_interface in self.spawned_interfaces:
self.spawned_interfaces.remove(spawned_interface)
self.spawned_interfaces.append(spawned_interface)
spawned_interface.read_loop()

def processOutgoing(self, data):
Expand Down
18 changes: 12 additions & 6 deletions RNS/Interfaces/TCPInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def __init__(self, owner, configuration, connected_socket=None):

c = Interface.get_config_obj(configuration)
name = c["name"]
target_ip = c["target_host"] if "target_host" in c else None
target_port = int(c["target_port"]) if "target_port" in c else None
target_ip = c["target_host"] if "target_host" in c and c["target_host"] != None else None
target_port = int(c["target_port"]) if "target_port" in c and c["target_host"] != None else None
kiss_framing = False
if "kiss_framing" in c and c.as_bool("kiss_framing") == True:
kiss_framing = True
Expand Down Expand Up @@ -413,7 +413,8 @@ def teardown(self):
self.IN = False

if hasattr(self, "parent_interface") and self.parent_interface != None:
self.parent_interface.clients -= 1
while self in self.parent_interface.spawned_interfaces:
self.parent_interface.spawned_interfaces.remove(self)

if self in RNS.Transport.interfaces:
if not self.initiator:
Expand Down Expand Up @@ -464,7 +465,10 @@ def get_address_for_host(name, bind_port):
raise SystemError(f"No suitable kernel interface available for address \"{name}\" for TCPServerInterface to bind to")


# def __init__(self, owner, name, device=None, bindip=None, bindport=None, i2p_tunneled=False, prefer_ipv6=False):
@property
def clients(self):
return len(self.spawned_interfaces)

def __init__(self, owner, configuration):
super().__init__()

Expand All @@ -483,7 +487,7 @@ def __init__(self, owner, configuration):
self.HW_MTU = 1064

self.online = False
self.clients = 0
self.spawned_interfaces = []

self.IN = True
self.OUT = False
Expand Down Expand Up @@ -578,7 +582,9 @@ def incoming_connection(self, handler):
spawned_interface.online = True
RNS.log("Spawned new TCPClient Interface: "+str(spawned_interface), RNS.LOG_VERBOSE)
RNS.Transport.interfaces.append(spawned_interface)
self.clients += 1
while spawned_interface in self.spawned_interfaces:
self.spawned_interfaces.remove(spawned_interface)
self.spawned_interfaces.append(spawned_interface)
spawned_interface.read_loop()

def received_announce(self, from_spawned=False):
Expand Down

0 comments on commit e81c22c

Please sign in to comment.