Skip to content

fix: accept port 0 in parseCmdArg#146

Merged
nitely merged 1 commit into
status-im:masterfrom
igor-sirotin:fix/allow-port-zero
May 21, 2026
Merged

fix: accept port 0 in parseCmdArg#146
nitely merged 1 commit into
status-im:masterfrom
igor-sirotin:fix/allow-port-zero

Conversation

@igor-sirotin

@igor-sirotin igor-sirotin commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Allow 0 in parseCmdArg(T: type Port, s: string). Port 0 is the standard "let the OS assign an ephemeral port" value for socket binds, but the current parser rejects it as out of range.

Downstream context: logos-co/logos-delivery-module#18 — the Waku-based delivery library needs to accept port 0 from a JSON config so that multiple instances on one host can bind without collision. Right now every embedded consumer has to wrap or sidestep this parser.

🤖 Generated with Claude Code

Port 0 is a meaningful value when binding sockets — it asks the OS to
assign an ephemeral port. Embedded users of confutils (e.g. libraries
that re-parse config from JSON) currently can't pass port 0 through
the standard parser, which forces every consumer to roll its own
override.

Refs: logos-co/logos-delivery-module#18

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@igor-sirotin igor-sirotin marked this pull request as ready for review May 20, 2026 20:46
@igor-sirotin

Copy link
Copy Markdown
Contributor Author

@jmgomez @arnetheduck can you please take a look? Is this a reasonable change?

@igor-sirotin

Copy link
Copy Markdown
Contributor Author

cc @nitely 🙏

@nitely

nitely commented May 21, 2026

Copy link
Copy Markdown
Contributor

see 5d8d1ea Port 0 is not a valid port... but it's a valid value so I don't see why not.

@igor-sirotin

igor-sirotin commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

see 5d8d1ea Port 0 is not a valid port... but it's a valid value so I don't see why not.

@nitely wow indeed, my PR is literally a revert of that commit. I wonder why it was ever a problem to have port 0.
Just hope not to break other projects.

@nitely

nitely commented May 21, 2026

Copy link
Copy Markdown
Contributor

Just hope not to break other projects.

I think this is unlikely to break anything because it relaxes a restriction. The other way around, not allowing Port(0) would be a breaking change, ex: if this gets reverted it would break logos-delivery.

Also, you can always make your own version of ‎confutils/std/net.nim that allows port 0.

igor-sirotin added a commit to logos-messaging/logos-delivery that referenced this pull request May 21, 2026
Now that confutils accepts port 0 in parseCmdArg (status-im/nim-confutils#146),
revert the local Port special-case in createWaku and bump confutils to the
fix instead.

confutils is temporarily pinned to the PR fork commit
(igor-sirotin/nim-confutils@0292f00d) until #146 merges to status-im master.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@igor-sirotin

Copy link
Copy Markdown
Contributor Author

I think this is unlikely to break anything because it relaxes a restriction. The other way around, not allowing Port(0) would be a breaking change, ex: if this gets reverted it would break logos-delivery.

Also, you can always make your own version of ‎confutils/std/net.nim that allows port 0.

Agree 💯

@nitely Can you please merge it then, I have zero rights in this repo

@nitely nitely merged commit 36f3115 into status-im:master May 21, 2026
24 checks passed
igor-sirotin added a commit to logos-messaging/logos-delivery that referenced this pull request May 21, 2026
status-im/nim-confutils#146 is merged; move the confutils pin from the
PR fork back to status-im/nim-confutils master (36f3115). Content is
identical to the fork commit, so nimble sha1 and nix sha256 are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@igor-sirotin igor-sirotin deleted the fix/allow-port-zero branch May 21, 2026 20:44
igor-sirotin added a commit to logos-messaging/logos-delivery that referenced this pull request May 22, 2026
* chore: pin confutils to merged upstream commit

status-im/nim-confutils#146 is merged; move the confutils pin from the
PR fork back to status-im/nim-confutils master (36f3115). Content is
identical to the fork commit, so nimble sha1 and nix sha256 are unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
igor-sirotin added a commit to logos-co/logos-delivery-module that referenced this pull request May 23, 2026
In createNode, default each listening port (tcpPort, discv5UdpPort,
restPort, metricsServerPort, websocketPort) to 0 when the caller did
not pin it, so the OS assigns ephemeral ports and multiple module
instances can coexist on one host. Caller-supplied ports are preserved
so fleet configs that pin ports keep working.

logos-delivery now accepts port 0 (status-im/nim-confutils#146), which
is what makes injecting 0 work end to end.

Also stop logging the cfg payload from createNode: it can carry
sensitive config.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
igor-sirotin added a commit to logos-co/logos-delivery-module that referenced this pull request May 25, 2026
In createNode, default each listening port (tcpPort, discv5UdpPort,
restPort, metricsServerPort, websocketPort) to 0 when the caller did
not pin it, so the OS assigns ephemeral ports and multiple module
instances can coexist on one host. Caller-supplied ports are preserved
so fleet configs that pin ports keep working.

logos-delivery now accepts port 0 (status-im/nim-confutils#146), which
is what makes injecting 0 work end to end.

Also stop logging the cfg payload from createNode: it can carry
sensitive config.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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