diff --git a/runtimepy/net/udp/connection.py b/runtimepy/net/udp/connection.py index 6d05207f..d6f0819f 100644 --- a/runtimepy/net/udp/connection.py +++ b/runtimepy/net/udp/connection.py @@ -126,14 +126,17 @@ def callback(transport_protocol: UdpTransportProtocol) -> None: ) return result is not None + should_connect: bool = True + @classmethod - async def create_connection( - cls: type[T], connect: bool = True, **kwargs - ) -> T: + async def create_connection(cls: type[T], **kwargs) -> T: """Create a UDP connection.""" LOG.debug("kwargs: %s", kwargs) + # Allows certain connections to have more sane defaults. + connect = kwargs.pop("connect", cls.should_connect) + # If the caller specifies a remote address but doesn't want a connected # socket, handle this after initial creation. remote_addr = None @@ -173,8 +176,8 @@ async def create_pair(cls: type[T]) -> tuple[T, T]: sock1.connect(("localhost", sock2.getsockname()[1])) sock2.connect(("localhost", sock1.getsockname()[1])) - conn1 = await cls.create_connection(sock=sock1) - conn2 = await cls.create_connection(sock=sock2) + conn1 = await cls.create_connection(sock=sock1, connect=True) + conn2 = await cls.create_connection(sock=sock2, connect=True) assert conn1.remote_address is not None assert conn2.remote_address is not None diff --git a/runtimepy/net/udp/tftp/base.py b/runtimepy/net/udp/tftp/base.py index 8d743142..18a1d249 100644 --- a/runtimepy/net/udp/tftp/base.py +++ b/runtimepy/net/udp/tftp/base.py @@ -36,6 +36,7 @@ class BaseTftpConnection(UdpConnection): _path: Path default_auto_restart = True + should_connect = False def set_root(self, path: Path) -> None: """Set a new root path for this instance.""" diff --git a/tests/data/valid/connection_arbiter/tftp.yaml b/tests/data/valid/connection_arbiter/tftp.yaml index d428adb6..007a214a 100644 --- a/tests/data/valid/connection_arbiter/tftp.yaml +++ b/tests/data/valid/connection_arbiter/tftp.yaml @@ -10,4 +10,4 @@ clients: name: tftp_client defer: true kwargs: - remote_addr: [localhost, "$tftp_server"] + remote_addr: [127.0.0.1, "$tftp_server"]