Skip to content

Feature/multi port - #151

Merged
JordanYates merged 3 commits into
mainfrom
feature/multi-port
Jul 14, 2026
Merged

Feature/multi port#151
JordanYates merged 3 commits into
mainfrom
feature/multi-port

Conversation

@Aeyohan

@Aeyohan Aeyohan commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Support multiple gateways and specifying which gateway a tool should connect to.
Updated all tools with the --server-port option.
Ports must be odd (since they are used in pairs).

@Aeyohan
Aeyohan force-pushed the feature/multi-port branch from e88228f to 2d5030c Compare July 10, 2026 08:05
@Aeyohan

Aeyohan commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Forgot to push a fix

@Aeyohan
Aeyohan requested a review from JordanYates July 10, 2026 08:21

@JordanYates JordanYates left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basic argparse testing for the helper type should be added in tests/util/test_argparse.py

Comment thread src/infuse_iot/socket_comms.py Outdated
parser.add_argument(
'--server-port',
dest='server_sock',
default=[default_multicast_address()] if multi_port else default_multicast_address(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sometimes a list of list[tuple[addr, port]], and sometimes just a tuple[addr, port]. It's passed directly into LocalServer, which only support the later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser outputs either a single port -> single socket pair, or a list of ports-> list of socket pairs depending on multi_port.
If a tool is designed to support multiple apps like how ota_upgrade was adapted in

self._clients = [LocalClient(addr, 1.0) for addr in args.server_sock]

, the tool can indicate this by setting multi_port to true, and then it's up to the tool to handle the socket list using list comprehension.

Comment thread src/infuse_iot/socket_comms.py Outdated
dest='server_sock',
default=[default_multicast_address()] if multi_port else default_multicast_address(),
type=server_port_parser,
nargs= '+' if multi_port else None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nargs = '+' means one or more. Is this intended? What would be the meaning if 4 port numbers are supplied?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when a tool specifies it supports multiple ports, it can use as many ports. I've had a reference sample of ota_upgrade using multiple gateways (tested with 2) where I tried entering 2 or 3 ports. The ports are converted to a list of socket tuples. In the case of the ota_upgrade, it setups comms with each of the gateways on the other side of the port (if it's available). Providing 4 port numbers, means connecting to as many as 4 gateways/scripts to use as workers to perform updates.

noting this only occurs when a tool specifies it opts-in for multiple ports. By default it will only allow 1.

@Aeyohan

Aeyohan commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Basic argparse testing for the helper type should be added in tests/util/test_argparse.py

Does it make sense to also move add_server_port_parser to util/argpase.py?

@JordanYates

Copy link
Copy Markdown
Contributor

Does it make sense to also move add_server_port_parser to util/argpase.py?

No strong opinions either way, its very specific to the socket comms abstraction, unlike the other helpers in util/argparse.py

@Aeyohan
Aeyohan force-pushed the feature/multi-port branch from 2d5030c to ba40e95 Compare July 13, 2026 01:17
@Aeyohan

Aeyohan commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Changed server_port_parser() to class ServerPort and moved it along with add_server_port_parser() to utils/argparse.py
(to avoid cyclical imports)

Added tests for both ServerPort and add_server_port_parser()
Updated add_server_port_parser() imports

@Aeyohan
Aeyohan requested a review from JordanYates July 13, 2026 23:03
return default_multicast_address(port)

def add_server_port_parser(parser: argparse.ArgumentParser, multi_port: bool = False):
parser.add_argument(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a docstring to this function please

Aeyohan added 3 commits July 14, 2026 10:49
Add an argparse helper to parse port numbers and preprocess them into a
socket (addr/port tuple).
Add an argparse helper to add a `--server-port` argument to tools that
need it.
This can be used to specify a different UDP port to allow for multiple
gateway scripts and corresponding connections to run simultaneously.

Signed-off-by: Aeyohan Furtado <aeyohan@embeint.com>
Added tests for the `add_server_port_parser` function for registering
the `--server-port` argument. Tests include checking correct single and
multi-port handling and default values for each.
Added test for the `ServerPort` type to ensure that it correctly parses
valid and invalid port numbers.

Signed-off-by: Aeyohan Furtado <aeyohan@embeint.com>
Added the `--server-port` argument to any tools that act or interact
with a gateway.

Signed-off-by: Aeyohan Furtado <aeyohan@embeint.com>
@Aeyohan
Aeyohan force-pushed the feature/multi-port branch from ba40e95 to f560e6d Compare July 14, 2026 00:49
@Aeyohan

Aeyohan commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Added missing doc string

@JordanYates
JordanYates merged commit a3fb476 into main Jul 14, 2026
7 checks passed
@JordanYates
JordanYates deleted the feature/multi-port branch July 14, 2026 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants