Agent: Use SocketAddress in TCPPipeSpawner

This commit is contained in:
Shreya Malviya 2022-09-26 13:25:43 +05:30
parent 426647c5b9
commit 0db0347008
2 changed files with 7 additions and 6 deletions

View File

@ -1,9 +1,10 @@
import socket
from ipaddress import IPv4Address
from logging import getLogger
from threading import Lock
from typing import Set
from common.types import SocketAddress
from .consts import SOCKET_TIMEOUT
from .sockets_pipe import SocketsPipe
@ -15,9 +16,9 @@ class TCPPipeSpawner:
Creates bi-directional pipes between the configured client and other clients.
"""
def __init__(self, target_addr: IPv4Address, target_port: int):
self._target_addr = target_addr
self._target_port = target_port
def __init__(self, target_addr: SocketAddress):
self._target_ip = target_addr.ip
self._target_port = target_addr.port
self._pipes: Set[SocketsPipe] = set()
self._lock = Lock()
@ -31,7 +32,7 @@ class TCPPipeSpawner:
dest = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dest.settimeout(SOCKET_TIMEOUT)
try:
dest.connect((str(self._target_addr), self._target_port))
dest.connect((str(self._target_ip), self._target_port))
except OSError as err:
source.close()
dest.close()

View File

@ -30,7 +30,7 @@ class TCPRelay(Thread, InterruptableThreadMixin):
new_client_timeout=client_disconnect_timeout,
client_disconnect_timeout=client_disconnect_timeout,
)
self._pipe_spawner = TCPPipeSpawner(dest_address.ip, dest_address.port)
self._pipe_spawner = TCPPipeSpawner(dest_address)
relay_filter = RelayConnectionHandler(self._pipe_spawner, self._user_handler)
self._connection_handler = TCPConnectionHandler(
bind_host="",