Replace ValidIpAddress by IpAddress
This commit is contained in:
parent
83b4943c17
commit
daadffe30a
|
@ -55,11 +55,11 @@ when isMainModule:
|
||||||
config.setupLogging()
|
config.setupLogging()
|
||||||
config.setupMetrics()
|
config.setupMetrics()
|
||||||
|
|
||||||
if config.nat == ValidIpAddress.init(IPv4_any()):
|
if config.nat == IPv4_any():
|
||||||
error "`--nat` cannot be set to the any (`0.0.0.0`) address"
|
error "`--nat` cannot be set to the any (`0.0.0.0`) address"
|
||||||
quit QuitFailure
|
quit QuitFailure
|
||||||
|
|
||||||
if config.nat == ValidIpAddress.init("127.0.0.1"):
|
if config.nat == static parseIpAddress("127.0.0.1"):
|
||||||
warn "`--nat` is set to loopback, your node wont properly announce over the DHT"
|
warn "`--nat` is set to loopback, your node wont properly announce over the DHT"
|
||||||
|
|
||||||
if not(checkAndCreateDataDir((config.dataDir).string)):
|
if not(checkAndCreateDataDir((config.dataDir).string)):
|
||||||
|
|
|
@ -114,9 +114,9 @@ type
|
||||||
|
|
||||||
metricsAddress* {.
|
metricsAddress* {.
|
||||||
desc: "Listening address of the metrics server"
|
desc: "Listening address of the metrics server"
|
||||||
defaultValue: ValidIpAddress.init("127.0.0.1")
|
defaultValue: defaultAddress(config)
|
||||||
defaultValueDesc: "127.0.0.1"
|
defaultValueDesc: "127.0.0.1"
|
||||||
name: "metrics-address" }: ValidIpAddress
|
name: "metrics-address" }: IpAddress
|
||||||
|
|
||||||
metricsPort* {.
|
metricsPort* {.
|
||||||
desc: "Listening HTTP port of the metrics server"
|
desc: "Listening HTTP port of the metrics server"
|
||||||
|
@ -142,17 +142,17 @@ type
|
||||||
# TODO: change this once we integrate nat support
|
# TODO: change this once we integrate nat support
|
||||||
nat* {.
|
nat* {.
|
||||||
desc: "IP Addresses to announce behind a NAT"
|
desc: "IP Addresses to announce behind a NAT"
|
||||||
defaultValue: ValidIpAddress.init("127.0.0.1")
|
defaultValue: defaultAddress(config)
|
||||||
defaultValueDesc: "127.0.0.1"
|
defaultValueDesc: "127.0.0.1"
|
||||||
abbr: "a"
|
abbr: "a"
|
||||||
name: "nat" }: ValidIpAddress
|
name: "nat" }: IpAddress
|
||||||
|
|
||||||
discoveryIp* {.
|
discoveryIp* {.
|
||||||
desc: "Discovery listen address"
|
desc: "Discovery listen address"
|
||||||
defaultValue: ValidIpAddress.init(IPv4_any())
|
defaultValue: IPv4_any()
|
||||||
defaultValueDesc: "0.0.0.0"
|
defaultValueDesc: "0.0.0.0"
|
||||||
abbr: "e"
|
abbr: "e"
|
||||||
name: "disc-ip" }: ValidIpAddress
|
name: "disc-ip" }: IpAddress
|
||||||
|
|
||||||
discoveryPort* {.
|
discoveryPort* {.
|
||||||
desc: "Discovery (UDP) port"
|
desc: "Discovery (UDP) port"
|
||||||
|
@ -413,6 +413,9 @@ type
|
||||||
logutils.formatIt(LogFormat.textLines, EthAddress): it.short0xHexLog
|
logutils.formatIt(LogFormat.textLines, EthAddress): it.short0xHexLog
|
||||||
logutils.formatIt(LogFormat.json, EthAddress): %it
|
logutils.formatIt(LogFormat.json, EthAddress): %it
|
||||||
|
|
||||||
|
func defaultAddress*(conf: CodexConf): IpAddress =
|
||||||
|
result = static parseIpAddress("127.0.0.1")
|
||||||
|
|
||||||
func persistence*(self: CodexConf): bool =
|
func persistence*(self: CodexConf): bool =
|
||||||
self.cmd == StartUpCmd.persistence
|
self.cmd == StartUpCmd.persistence
|
||||||
|
|
||||||
|
@ -445,13 +448,17 @@ const
|
||||||
|
|
||||||
proc parseCmdArg*(T: typedesc[MultiAddress],
|
proc parseCmdArg*(T: typedesc[MultiAddress],
|
||||||
input: string): MultiAddress
|
input: string): MultiAddress
|
||||||
{.upraises: [ValueError, LPError].} =
|
{.upraises: [ValueError] .} =
|
||||||
var ma: MultiAddress
|
var ma: MultiAddress
|
||||||
let res = MultiAddress.init(input)
|
try:
|
||||||
if res.isOk:
|
let res = MultiAddress.init(input)
|
||||||
ma = res.get()
|
if res.isOk:
|
||||||
else:
|
ma = res.get()
|
||||||
warn "Invalid MultiAddress", input=input, error = res.error()
|
else:
|
||||||
|
warn "Invalid MultiAddress", input=input, error = res.error()
|
||||||
|
quit QuitFailure
|
||||||
|
except LPError as exc:
|
||||||
|
warn "Invalid MultiAddress uri", uri = input, error = exc.msg
|
||||||
quit QuitFailure
|
quit QuitFailure
|
||||||
ma
|
ma
|
||||||
|
|
||||||
|
@ -461,6 +468,9 @@ proc parseCmdArg*(T: type SignedPeerRecord, uri: string): T =
|
||||||
if not res.fromURI(uri):
|
if not res.fromURI(uri):
|
||||||
warn "Invalid SignedPeerRecord uri", uri = uri
|
warn "Invalid SignedPeerRecord uri", uri = uri
|
||||||
quit QuitFailure
|
quit QuitFailure
|
||||||
|
except LPError as exc:
|
||||||
|
warn "Invalid SignedPeerRecord uri", uri = uri, error = exc.msg
|
||||||
|
quit QuitFailure
|
||||||
except CatchableError as exc:
|
except CatchableError as exc:
|
||||||
warn "Invalid SignedPeerRecord uri", uri = uri, error = exc.msg
|
warn "Invalid SignedPeerRecord uri", uri = uri, error = exc.msg
|
||||||
quit QuitFailure
|
quit QuitFailure
|
||||||
|
@ -494,7 +504,11 @@ proc readValue*(r: var TomlReader, val: var SignedPeerRecord) =
|
||||||
error "invalid SignedPeerRecord configuration value", error = err.msg
|
error "invalid SignedPeerRecord configuration value", error = err.msg
|
||||||
quit QuitFailure
|
quit QuitFailure
|
||||||
|
|
||||||
val = SignedPeerRecord.parseCmdArg(uri)
|
try:
|
||||||
|
val = SignedPeerRecord.parseCmdArg(uri)
|
||||||
|
except LPError as err:
|
||||||
|
warn "Invalid SignedPeerRecord uri", uri = uri, error = err.msg
|
||||||
|
quit QuitFailure
|
||||||
|
|
||||||
proc readValue*(r: var TomlReader, val: var MultiAddress) =
|
proc readValue*(r: var TomlReader, val: var MultiAddress) =
|
||||||
without input =? r.readValue(string).catch, err:
|
without input =? r.readValue(string).catch, err:
|
||||||
|
|
|
@ -147,7 +147,7 @@ proc updateAnnounceRecord*(d: Discovery, addrs: openArray[MultiAddress]) =
|
||||||
d.protocol.updateRecord(d.providerRecord)
|
d.protocol.updateRecord(d.providerRecord)
|
||||||
.expect("Should update SPR")
|
.expect("Should update SPR")
|
||||||
|
|
||||||
proc updateDhtRecord*(d: Discovery, ip: ValidIpAddress, port: Port) =
|
proc updateDhtRecord*(d: Discovery, ip: IpAddress, port: Port) =
|
||||||
## Update providers record
|
## Update providers record
|
||||||
##
|
##
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ proc stop*(d: Discovery) {.async.} =
|
||||||
proc new*(
|
proc new*(
|
||||||
T: type Discovery,
|
T: type Discovery,
|
||||||
key: PrivateKey,
|
key: PrivateKey,
|
||||||
bindIp = ValidIpAddress.init(IPv4_any()),
|
bindIp = IPv4_any(),
|
||||||
bindPort = 0.Port,
|
bindPort = 0.Port,
|
||||||
announceAddrs: openArray[MultiAddress],
|
announceAddrs: openArray[MultiAddress],
|
||||||
bootstrapNodes: openArray[SignedPeerRecord] = [],
|
bootstrapNodes: openArray[SignedPeerRecord] = [],
|
||||||
|
@ -203,7 +203,7 @@ proc new*(
|
||||||
|
|
||||||
self.protocol = newProtocol(
|
self.protocol = newProtocol(
|
||||||
key,
|
key,
|
||||||
bindIp = bindIp.toNormalIp,
|
bindIp = bindIp,
|
||||||
bindPort = bindPort,
|
bindPort = bindPort,
|
||||||
record = self.providerRecord.get,
|
record = self.providerRecord.get,
|
||||||
bootstrapRecords = bootstrapNodes,
|
bootstrapRecords = bootstrapNodes,
|
||||||
|
|
|
@ -18,7 +18,7 @@ import pkg/stew/shims/net
|
||||||
|
|
||||||
func remapAddr*(
|
func remapAddr*(
|
||||||
address: MultiAddress,
|
address: MultiAddress,
|
||||||
ip: Option[ValidIpAddress] = ValidIpAddress.none,
|
ip: Option[IpAddress] = IpAddress.none,
|
||||||
port: Option[Port] = Port.none
|
port: Option[Port] = Port.none
|
||||||
): MultiAddress =
|
): MultiAddress =
|
||||||
## Remap addresses to new IP and/or Port
|
## Remap addresses to new IP and/or Port
|
||||||
|
|
Loading…
Reference in New Issue