Skip to content

Commit

Permalink
TFTP connections should never connect
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Jul 20, 2024
1 parent 852ee58 commit aa096c3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
13 changes: 8 additions & 5 deletions runtimepy/net/udp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions runtimepy/net/udp/tftp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion tests/data/valid/connection_arbiter/tftp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ clients:
name: tftp_client
defer: true
kwargs:
remote_addr: [localhost, "$tftp_server"]
remote_addr: [127.0.0.1, "$tftp_server"]

0 comments on commit aa096c3

Please sign in to comment.