Bitrate guess on TCP and UDP interfaces

This commit is contained in:
Mark Qvist 2022-04-18 18:09:31 +02:00
parent be820b1965
commit d53e8cf037
2 changed files with 10 additions and 0 deletions

View File

@ -59,6 +59,8 @@ class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
pass pass
class TCPClientInterface(Interface): class TCPClientInterface(Interface):
BITRATE_GUESS = 10*1000*1000
RECONNECT_WAIT = 5 RECONNECT_WAIT = 5
RECONNECT_MAX_TRIES = None RECONNECT_MAX_TRIES = None
@ -92,6 +94,7 @@ class TCPClientInterface(Interface):
self.kiss_framing = kiss_framing self.kiss_framing = kiss_framing
self.i2p_tunneled = i2p_tunneled self.i2p_tunneled = i2p_tunneled
self.mode = RNS.Interfaces.Interface.Interface.MODE_FULL self.mode = RNS.Interfaces.Interface.Interface.MODE_FULL
self.bitrate = TCPClientInterface.BITRATE_GUESS
if max_reconnect_tries == None: if max_reconnect_tries == None:
self.max_reconnect_tries = TCPClientInterface.RECONNECT_MAX_TRIES self.max_reconnect_tries = TCPClientInterface.RECONNECT_MAX_TRIES
@ -375,6 +378,8 @@ class TCPClientInterface(Interface):
class TCPServerInterface(Interface): class TCPServerInterface(Interface):
BITRATE_GUESS = 10*1000*1000
@staticmethod @staticmethod
def get_address_for_if(name): def get_address_for_if(name):
import importlib import importlib
@ -429,6 +434,8 @@ class TCPServerInterface(Interface):
ThreadingTCPServer.allow_reuse_address = True ThreadingTCPServer.allow_reuse_address = True
self.server = ThreadingTCPServer(address, handlerFactory(self.incoming_connection)) self.server = ThreadingTCPServer(address, handlerFactory(self.incoming_connection))
self.bitrate = TCPServerInterface.BITRATE_GUESS
thread = threading.Thread(target=self.server.serve_forever) thread = threading.Thread(target=self.server.serve_forever)
thread.setDaemon(True) thread.setDaemon(True)
thread.start() thread.start()
@ -445,6 +452,7 @@ class TCPServerInterface(Interface):
spawned_interface.target_ip = handler.client_address[0] spawned_interface.target_ip = handler.client_address[0]
spawned_interface.target_port = str(handler.client_address[1]) spawned_interface.target_port = str(handler.client_address[1])
spawned_interface.parent_interface = self spawned_interface.parent_interface = self
spawned_interface.bitrate = self.bitrate
spawned_interface.online = True spawned_interface.online = True
RNS.log("Spawned new TCPClient Interface: "+str(spawned_interface), RNS.LOG_VERBOSE) RNS.log("Spawned new TCPClient Interface: "+str(spawned_interface), RNS.LOG_VERBOSE)
RNS.Transport.interfaces.append(spawned_interface) RNS.Transport.interfaces.append(spawned_interface)

View File

@ -30,6 +30,7 @@ import RNS
class UDPInterface(Interface): class UDPInterface(Interface):
BITRATE_GUESS = 10*1000*1000
@staticmethod @staticmethod
def get_address_for_if(name): def get_address_for_if(name):
@ -60,6 +61,7 @@ class UDPInterface(Interface):
self.OUT = False self.OUT = False
self.name = name self.name = name
self.online = False self.online = False
self.bitrate = UDPInterface.BITRATE_GUESS
if device != None: if device != None:
if bindip == None: if bindip == None: