feat(cli)!: change --listen-addrs to --listen-port

This allows specifying the port only for the listening address, the address that is announced on the DHT for peer connections. It makes the developer experience less confusing, and easier to change for things like port forwarding.

# Conflicts:
#	storage/storage.nim
#	tests/integration/multinodes.nim
This commit is contained in:
E M 2026-02-16 23:00:19 +11:00
parent ab413bdfcf
commit 04f7c6cfd5
No known key found for this signature in database
5 changed files with 18 additions and 13 deletions

View File

@ -240,7 +240,8 @@ paths:
description: |
If supplied, it will be used to dial the peer.
The address has to target the listening address of the peer,
which is specified with the `--listen-addrs` CLI flag.
which is /ip4/0.0.0.0/tcp/<port>, where port is specified
with the `--listen-port` CLI flag.
responses:
"200":

View File

@ -135,14 +135,13 @@ type
name: "data-dir"
.}: OutDir
listenAddrs* {.
desc: "Multi Addresses to listen on",
defaultValue:
@[MultiAddress.init("/ip4/0.0.0.0/tcp/0").expect("Should init multiaddress")],
defaultValueDesc: "/ip4/0.0.0.0/tcp/0",
abbr: "i",
name: "listen-addrs"
.}: seq[MultiAddress]
listenPort* {.
desc: "Port to listen on for remote peer connections. Announced in the DHT as /ip4/0.0.0.0/tcp/",
defaultValue: 0,
defaultValueDesc: "Chooses a random port for the MultiAddress, eg /ip4/0.0.0.0/tcp/0",
abbr: "l",
name: "listen-port"
.}: int
nat* {.
desc:

View File

@ -440,7 +440,9 @@ proc initNodeApi(node: StorageNodeRef, conf: StorageConf, router: var RestRouter
## to invoke peer discovery, if it succeeds
## the returned addresses will be used to dial
##
## `addrs` the listening addresses of the peers to dial, eg the one specified with `--listen-addrs`
## `addrs` the listening addresses of the peers to dial, which is
## /ip4/0.0.0.0/tcp/<port>, where port is specified with the
## `--listen-port` CLI flag.
##
var headers = buildCorsHeaders("GET", allowedOrigin)

View File

@ -139,10 +139,14 @@ proc new*(
T: type StorageServer, config: StorageConf, privateKey: StoragePrivateKey
): StorageServer =
## create StorageServer including setting up datastore, repostore, etc
let listenAddr = MultiAddress
.init(DefaultListenAddress & $config.listenPort)
.expect("Default multiaddress and provied port not valid")
let switch = SwitchBuilder
.new()
.withPrivateKey(privateKey)
.withAddresses(config.listenAddrs)
.withAddresses(@[listenAddr])
.withRng(random.Rng.instance())
.withNoise()
.withMplex(5.minutes, 5.minutes)
@ -190,7 +194,7 @@ proc new*(
discovery = Discovery.new(
switch.peerInfo.privateKey,
announceAddrs = config.listenAddrs,
announceAddrs = @[listenAddr],
bindPort = config.discoveryPort,
bootstrapNodes = config.bootstrapNodes,
store = discoveryStore,

View File

@ -135,7 +135,6 @@ template multinodesuite*(suiteName: string, body: untyped) =
config.addCliOption("--data-dir", datadir)
config.addCliOption("--nat", "none")
config.addCliOption("--listen-addrs", "/ip4/127.0.0.1/tcp/0")
except StorageConfigError as e:
raiseMultiNodeSuiteError "invalid cli option, error: " & e.msg