mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-03-10 14:23:06 +00:00
feat(cli)!: change listen addr to listen port (#1409)
This commit is contained in:
parent
ab413bdfcf
commit
3bc6aa8b8d
@ -240,7 +240,9 @@ 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/<listen-ip>/tcp/<listen-port>, where `listen-port` is
|
||||
specified with the `--listen-port` CLI flag and `listen-ip` with the
|
||||
`--listen-ip` CLI flag.
|
||||
|
||||
responses:
|
||||
"200":
|
||||
|
||||
@ -135,19 +135,29 @@ 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",
|
||||
listenIp* {.
|
||||
desc:
|
||||
"IP address to listen on for remote peer connections, can be ipv4 or ipv6",
|
||||
defaultValue: "0.0.0.0".parseIpAddress,
|
||||
defaultValueDesc: "Listens on all addresses.",
|
||||
abbr: "i",
|
||||
name: "listen-addrs"
|
||||
.}: seq[MultiAddress]
|
||||
name: "listen-ip"
|
||||
.}: IpAddress
|
||||
|
||||
listenPort* {.
|
||||
desc:
|
||||
"TCP port to listen on for remote peer connections. Selects a random port if none is specified.",
|
||||
defaultValue: 0,
|
||||
defaultValueDesc: "Listens on a random free port.",
|
||||
abbr: "l",
|
||||
name: "listen-port"
|
||||
.}: Port
|
||||
|
||||
nat* {.
|
||||
desc:
|
||||
"Specify method to use for determining public address. " &
|
||||
"Must be one of: any, none, upnp, pmp, extip:<IP>",
|
||||
"Must be one of: any, none, upnp, pmp, extip:<IP>. " &
|
||||
"If connecting to peers on a local network only, use 'none'.",
|
||||
defaultValue: defaultNatConfig(),
|
||||
defaultValueDesc: "any",
|
||||
name: "nat"
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -475,7 +477,6 @@ proc initDebugApi(node: StorageNodeRef, conf: StorageConf, router: var RestRoute
|
||||
|
||||
try:
|
||||
let table = RestRoutingTable.init(node.discovery.protocol.routingTable)
|
||||
|
||||
let json = %*{
|
||||
"id": $node.switch.peerInfo.peerId,
|
||||
"addrs": node.switch.peerInfo.addrs.mapIt($it),
|
||||
|
||||
@ -139,10 +139,12 @@ proc new*(
|
||||
T: type StorageServer, config: StorageConf, privateKey: StoragePrivateKey
|
||||
): StorageServer =
|
||||
## create StorageServer including setting up datastore, repostore, etc
|
||||
let listenMultiAddr = getMultiAddrWithIpAndTcpPort(config.listenIp, config.listenPort)
|
||||
|
||||
let switch = SwitchBuilder
|
||||
.new()
|
||||
.withPrivateKey(privateKey)
|
||||
.withAddresses(config.listenAddrs)
|
||||
.withAddresses(@[listenMultiAddr])
|
||||
.withRng(random.Rng.instance())
|
||||
.withNoise()
|
||||
.withMplex(5.minutes, 5.minutes)
|
||||
@ -190,7 +192,7 @@ proc new*(
|
||||
|
||||
discovery = Discovery.new(
|
||||
switch.peerInfo.privateKey,
|
||||
announceAddrs = config.listenAddrs,
|
||||
announceAddrs = @[listenMultiAddr],
|
||||
bindPort = config.discoveryPort,
|
||||
bootstrapNodes = config.bootstrapNodes,
|
||||
store = discoveryStore,
|
||||
|
||||
@ -53,6 +53,21 @@ proc getMultiAddrWithIPAndUDPPort*(ip: IpAddress, port: Port): MultiAddress =
|
||||
let ipFamily = if ip.family == IpAddressFamily.IPv4: "/ip4/" else: "/ip6/"
|
||||
return MultiAddress.init(ipFamily & $ip & "/udp/" & $port).expect("valid multiaddr")
|
||||
|
||||
proc getMultiAddrWithIpAndTcpPort*(ip: IpAddress, port: Port): MultiAddress =
|
||||
## Creates a MultiAddress with the specified IP address and TCP port
|
||||
##
|
||||
## Parameters:
|
||||
## - ip: A valid IP address (IPv4 or IPv6)
|
||||
## - port: The TCP port number
|
||||
##
|
||||
## Returns:
|
||||
## A MultiAddress in the format "/ip4/<address>/tcp/<port>" or "/ip6/<address>/tcp/<port>"
|
||||
|
||||
let ipFamily = if ip.family == IpAddressFamily.IPv4: "/ip4/" else: "/ip6/"
|
||||
return MultiAddress.init(ipFamily & $ip & "/tcp/" & $port).expect(
|
||||
"Failed to construct multiaddress with IP and TCP port"
|
||||
)
|
||||
|
||||
proc getAddressAndPort*(
|
||||
ma: MultiAddress
|
||||
): tuple[ip: Option[IpAddress], port: Option[Port]] =
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user