mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-18 00:09:52 +00:00
* tcp/rest/websocket/metrics/discv5 default port changed to 0 * all CLI port types are now uint16 (instead of Port) * any port set to 0 on conf results in a random port bound * write back bound values to both WakuConf and WakuNode.ports * REST GET /info reports actually bound ports for enabled services * conf builders now err if any port config is unset * setupDiscoveryV5 returns Result and errors out on port 0 * rename setupAndStartDiscv5WithAutoPort to setupAndStartDiscv5 * updateWaku ENR rebuild now runs after discv5 startup * remove Port(0) conf from tests (0 is default) * add port = 0 to conf builder tests (conf builder has no default)
51 lines
1.4 KiB
Nim
51 lines
1.4 KiB
Nim
import chronicles, std/[net, options], results
|
|
import ../waku_conf
|
|
|
|
logScope:
|
|
topics = "waku conf builder metrics server"
|
|
|
|
###################################
|
|
## 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))
|
|
|
|
if b.httpPort.isNone():
|
|
return err("metricsServer.httpPort is not specified")
|
|
|
|
return ok(
|
|
some(
|
|
MetricsServerConf(
|
|
httpAddress: b.httpAddress.get(static parseIpAddress("127.0.0.1")),
|
|
httpPort: b.httpPort.get(),
|
|
logging: b.logging.get(false),
|
|
)
|
|
)
|
|
)
|