mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-03-07 04:43:10 +00:00
Add --listen-ip as well, so users can specify a well-known ip address
This commit is contained in:
parent
33f7ebfa4f
commit
9c0fd2f0c3
@ -135,20 +135,29 @@ type
|
||||
name: "data-dir"
|
||||
.}: OutDir
|
||||
|
||||
listenIp* {.
|
||||
desc:
|
||||
"IP address to listen on for remote peer connections. Announced in the DHT as a multiaddress, eg /ip4/<listen-ip>/tcp/<listen-port>. IP address can be v4 or v6",
|
||||
defaultValue: "0.0.0.0".parseIpAddress,
|
||||
defaultValueDesc: "Listens on all addresses.",
|
||||
abbr: "i",
|
||||
name: "listen-ip"
|
||||
.}: IpAddress
|
||||
|
||||
listenPort* {.
|
||||
desc:
|
||||
"Port to listen on for remote peer connections. Announced in the DHT as /ip4/0.0.0.0/tcp/",
|
||||
"Port to listen on for remote peer connections. Announced in the DHT as a multiaddress, eg /ip4/<listen-ip>/tcp/<listen-port>. Port must be in the range 0-65535.",
|
||||
defaultValue: 0,
|
||||
defaultValueDesc:
|
||||
"Chooses a random port for the MultiAddress, eg /ip4/0.0.0.0/tcp/0",
|
||||
defaultValueDesc: "Listens on a random free port.",
|
||||
abbr: "l",
|
||||
name: "listen-port"
|
||||
.}: int
|
||||
.}: 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"
|
||||
|
||||
@ -139,14 +139,12 @@ 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 listenMultiAddr = getMultiAddrWithIpAndTcpPort(config.listenIp, config.listenPort)
|
||||
|
||||
let switch = SwitchBuilder
|
||||
.new()
|
||||
.withPrivateKey(privateKey)
|
||||
.withAddresses(@[listenAddr])
|
||||
.withAddresses(@[listenMultiAddr])
|
||||
.withRng(random.Rng.instance())
|
||||
.withNoise()
|
||||
.withMplex(5.minutes, 5.minutes)
|
||||
@ -194,7 +192,7 @@ proc new*(
|
||||
|
||||
discovery = Discovery.new(
|
||||
switch.peerInfo.privateKey,
|
||||
announceAddrs = @[listenAddr],
|
||||
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]] =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user