Fixing tunnel & client for mac

This commit is contained in:
Adolfo Gómez García 2021-07-03 21:48:38 +02:00
parent 9ca3a7cdeb
commit a359ff2263
2 changed files with 18 additions and 5 deletions

View File

@ -22,8 +22,19 @@ class UdsApplication(QtWidgets.QApplication):
self.lastWindowClosed.connect(self.closeTunnels) # type: ignore self.lastWindowClosed.connect(self.closeTunnels) # type: ignore
def cleanTunnels(self) -> None: def cleanTunnels(self) -> None:
for k in [i for i, tunnel in enumerate(self.tunnels) if tunnel.poll() is not None]: def isRunning(p: subprocess.Popen):
try:
if p.poll() is None:
return True
except Exception as e:
logger.debug('Got error polling subprocess: %s', e)
return False
for k in [i for i, tunnel in enumerate(self.tunnels) if not isRunning(tunnel)]:
try:
del self.tunnels[k] del self.tunnels[k]
except Exception as e:
logger.debug('Error closing tunnel: %s', e)
def closeTunnels(self) -> None: def closeTunnels(self) -> None:
logger.debug('Closing remaining tunnels') logger.debug('Closing remaining tunnels')

View File

@ -40,6 +40,7 @@ from . import consts
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from multiprocessing.managers import Namespace from multiprocessing.managers import Namespace
import curio.io
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -92,7 +93,7 @@ class Proxy:
Proxy._getUdsUrl(cfg, ticket, 'stop', {'sent': str(counter.sent), 'recv': str(counter.recv)}) # Ignore results Proxy._getUdsUrl(cfg, ticket, 'stop', {'sent': str(counter.sent), 'recv': str(counter.recv)}) # Ignore results
@staticmethod @staticmethod
async def doProxy(source, destination, counter: stats.StatsSingleCounter) -> None: async def doProxy(source: 'curio.io.Socket', destination: 'curio.io.Socket', counter: stats.StatsSingleCounter) -> None:
try: try:
while True: while True:
data = await source.recv(consts.BUFFER_SIZE) data = await source.recv(consts.BUFFER_SIZE)
@ -101,8 +102,9 @@ class Proxy:
await destination.sendall(data) await destination.sendall(data)
counter.add(len(data)) counter.add(len(data))
except Exception: except Exception:
# Connection broken # Connection broken, same result as closed for us (even log is removed)
logger.info('CONNECTION LOST FROM %s to %s', source, destination) # logger.info('CONNECTION LOST FROM %s to %s', source.getsockname(), destination.getpeername())
pass
# Method responsible of proxying requests # Method responsible of proxying requests