mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-15 06:49:28 +00:00
* any port set to 0 on conf results in a random port bound * Debug API MyBoundPorts reports actually bound ports for all services, reports 0 if disabled * write back bound values to both WakuConf and WakuNode.ports * setupDiscoveryV5 returns Result and errors out on port 0 * rename setupAndStartDiscv5WithAutoPort to setupAndStartDiscv5 * updateWaku ENR rebuild now runs after discv5 startup * Add DefaultP2pTcpPort, DefaultDiscv5UdpPort, DefaultWebSocketPort, DefaultRestPort, DefaultMetricsHttpPort * add tests
50 lines
1.4 KiB
Nim
50 lines
1.4 KiB
Nim
import chronicles, std/[net, options], results
|
|
import ../waku_conf
|
|
|
|
logScope:
|
|
topics = "waku conf builder metrics server"
|
|
|
|
const DefaultMetricsHttpPort*: Port = Port(8008)
|
|
|
|
###################################
|
|
## Metrics Server Config Builder ##
|
|
###################################
|
|
type MetricsServerConfBuilder* = object
|
|
enabled*: Option[bool]
|
|
|
|
httpAddress*: Option[IpAddress]
|
|
httpPort*: Option[Port]
|
|
logging*: Option[bool]
|
|
|
|
proc init*(T: type MetricsServerConfBuilder): MetricsServerConfBuilder =
|
|
MetricsServerConfBuilder()
|
|
|
|
proc withEnabled*(b: var MetricsServerConfBuilder, enabled: bool) =
|
|
b.enabled = some(enabled)
|
|
|
|
proc withHttpAddress*(b: var MetricsServerConfBuilder, httpAddress: IpAddress) =
|
|
b.httpAddress = some(httpAddress)
|
|
|
|
proc withHttpPort*(b: var MetricsServerConfBuilder, httpPort: Port) =
|
|
b.httpPort = some(httpPort)
|
|
|
|
proc withHttpPort*(b: var MetricsServerConfBuilder, httpPort: uint16) =
|
|
b.httpPort = some(Port(httpPort))
|
|
|
|
proc withLogging*(b: var MetricsServerConfBuilder, logging: bool) =
|
|
b.logging = some(logging)
|
|
|
|
proc build*(b: MetricsServerConfBuilder): Result[Option[MetricsServerConf], string] =
|
|
if not b.enabled.get(false):
|
|
return ok(none(MetricsServerConf))
|
|
|
|
return ok(
|
|
some(
|
|
MetricsServerConf(
|
|
httpAddress: b.httpAddress.get(static parseIpAddress("127.0.0.1")),
|
|
httpPort: b.httpPort.get(DefaultMetricsHttpPort),
|
|
logging: b.logging.get(false),
|
|
)
|
|
)
|
|
)
|