diff --git a/openapi.yaml b/openapi.yaml index 150986d8..d5d96862 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -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/, where port is specified + with the `--listen-port` CLI flag. responses: "200": diff --git a/storage/conf.nim b/storage/conf.nim index 50d191cf..515318d1 100644 --- a/storage/conf.nim +++ b/storage/conf.nim @@ -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: diff --git a/storage/rest/api.nim b/storage/rest/api.nim index 0c4a9c06..67c40ecc 100644 --- a/storage/rest/api.nim +++ b/storage/rest/api.nim @@ -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/, where port is specified with the + ## `--listen-port` CLI flag. ## var headers = buildCorsHeaders("GET", allowedOrigin) diff --git a/storage/storage.nim b/storage/storage.nim index e85b3959..9043f537 100644 --- a/storage/storage.nim +++ b/storage/storage.nim @@ -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, diff --git a/tests/integration/multinodes.nim b/tests/integration/multinodes.nim index f6f8135f..5ee7d202 100644 --- a/tests/integration/multinodes.nim +++ b/tests/integration/multinodes.nim @@ -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