mirror of
https://github.com/markqvist/Reticulum.git
synced 2026-11-19 14:36:34 -05:00
Ensure early tunnel synthesis on TCP and I2P interfaces
This commit is contained in:
parent
f361a354ba
commit
ad6c709e80
2 changed files with 35 additions and 12 deletions
|
|
@ -426,8 +426,6 @@ class I2PInterfacePeer(Interface):
|
|||
while self.awaiting_i2p_tunnel: time.sleep(0.25)
|
||||
time.sleep(2)
|
||||
|
||||
if not self.kiss_framing: self.wants_tunnel = True
|
||||
|
||||
if not self.connect(initial=True):
|
||||
thread = threading.Thread(target=self.reconnect)
|
||||
thread.daemon = True
|
||||
|
|
@ -480,10 +478,27 @@ class I2PInterfacePeer(Interface):
|
|||
|
||||
self.socket = None
|
||||
|
||||
def early_synthesis(self, packet):
|
||||
if not self.detached:
|
||||
if not packet.packed: packet.pack()
|
||||
|
||||
if self.kiss_framing: frame = bytes([KISS.FEND])+bytes([KISS.CMD_DATA])+KISS.escape(packet.raw)+bytes([KISS.FEND])
|
||||
else: frame = bytes([HDLC.FLAG])+HDLC.escape(packet.raw)+bytes([HDLC.FLAG])
|
||||
|
||||
self.socket.sendall(frame)
|
||||
self.txb += len(frame)
|
||||
self.last_write = time.time()
|
||||
if hasattr(self, "parent_interface") and self.parent_interface != None and self.parent_count: self.parent_interface.txb += len(frame)
|
||||
|
||||
def connect(self, initial=False):
|
||||
try:
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
self.socket.connect((self.target_ip, self.target_port))
|
||||
|
||||
if not self.kiss_framing:
|
||||
self.wants_tunnel = True
|
||||
RNS.Transport.synthesize_tunnel(self)
|
||||
|
||||
self.online = True
|
||||
|
||||
except Exception as e:
|
||||
|
|
@ -501,8 +516,6 @@ class I2PInterfacePeer(Interface):
|
|||
self.writing = False
|
||||
self.never_connected = False
|
||||
|
||||
if not self.kiss_framing and self.wants_tunnel: RNS.Transport.synthesize_tunnel(self)
|
||||
|
||||
return True
|
||||
|
||||
def reconnect(self):
|
||||
|
|
@ -531,7 +544,6 @@ class I2PInterfacePeer(Interface):
|
|||
thread = threading.Thread(target=self.read_loop)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
if not self.kiss_framing: RNS.Transport.synthesize_tunnel(self)
|
||||
|
||||
else:
|
||||
RNS.log("Attempt to reconnect on a non-initiator I2P interface. This should not happen.", RNS.LOG_ERROR)
|
||||
|
|
|
|||
|
|
@ -176,8 +176,6 @@ class TCPClientInterface(Interface):
|
|||
thread = threading.Thread(target=self.read_loop)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
if not self.kiss_framing:
|
||||
self.wants_tunnel = True
|
||||
|
||||
def set_timeouts_linux(self):
|
||||
if not self.i2p_tunneled:
|
||||
|
|
@ -229,6 +227,18 @@ class TCPClientInterface(Interface):
|
|||
|
||||
self.socket = None
|
||||
|
||||
def early_synthesis(self, packet):
|
||||
if not self.detached:
|
||||
if not packet.packed: packet.pack()
|
||||
|
||||
if self.kiss_framing: frame = bytes([KISS.FEND])+bytes([KISS.CMD_DATA])+KISS.escape(packet.raw)+bytes([KISS.FEND])
|
||||
else: frame = bytes([HDLC.FLAG])+HDLC.escape(packet.raw)+bytes([HDLC.FLAG])
|
||||
|
||||
self.socket.sendall(frame)
|
||||
self.txb += len(frame)
|
||||
if hasattr(self, "parent_interface") and self.parent_interface != None:
|
||||
self.parent_interface.txb += len(frame)
|
||||
|
||||
def connect(self, initial=False):
|
||||
try:
|
||||
if initial:
|
||||
|
|
@ -243,6 +253,11 @@ class TCPClientInterface(Interface):
|
|||
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
self.socket.connect(target_address)
|
||||
self.socket.settimeout(None)
|
||||
|
||||
if not self.kiss_framing:
|
||||
self.wants_tunnel = True
|
||||
RNS.Transport.synthesize_tunnel(self)
|
||||
|
||||
self.online = True
|
||||
|
||||
if initial:
|
||||
|
|
@ -283,9 +298,7 @@ class TCPClientInterface(Interface):
|
|||
self.teardown()
|
||||
break
|
||||
|
||||
try:
|
||||
self.connect()
|
||||
|
||||
try: self.connect()
|
||||
except Exception as e:
|
||||
RNS.log("Connection attempt for "+str(self)+" failed: "+str(e), RNS.LOG_DEBUG)
|
||||
|
||||
|
|
@ -296,8 +309,6 @@ class TCPClientInterface(Interface):
|
|||
thread = threading.Thread(target=self.read_loop)
|
||||
thread.daemon = True
|
||||
thread.start()
|
||||
if not self.kiss_framing:
|
||||
RNS.Transport.synthesize_tunnel(self)
|
||||
|
||||
else:
|
||||
RNS.log("Attempt to reconnect on a non-initiator TCP interface. This should not happen.", RNS.LOG_ERROR)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue