logos-messaging-nim/waku/factory/conf_builder/web_socket_conf_builder.nim
fryorcraken 994d485b49 chore!: make sharding configuration explicit (#3468)
* Reserve `networkconfig` name to waku network related settings

* Rename cluster conf to network conf

 A `NetworkConf` is a Waku network configuration.

# Conflicts:
#	tests/factory/test_waku_conf.nim

# Conflicts:
#	tests/factory/test_waku_conf.nim

* Improve sharding configuration

A smarter data types simplifies the logic.

* Fixing tests

* fixup! rename to endpointConf

* wip: autosharding is a specific configuration state and treat it like
it

# Conflicts:
#	waku/factory/external_config.nim

* refactor lightpush handler

some metrics error reporting were missing

# Conflicts:
#	waku/waku_lightpush/protocol.nim

* test_node_factory tests pass

* remove warnings

* fix tests

* Revert eager previous replace-all command

* fix up build tools compilation

* metadata is used to store cluster id

* Mount relay routes in static sharding

* Rename activeRelayShards to subscribeShards

To make it clearer that these are the shards the node will subscribe to.

* Remove unused msg var

* Improve error handling

* Set autosharding as default, with 1 shard in network

Also makes shards to subscribe to all shards in auto sharding, none in
static sharding.
2025-07-04 17:10:53 +10:00

71 lines
2.0 KiB
Nim

import chronicles, std/[net, options], results
import waku/factory/waku_conf
logScope:
topics = "waku conf builder websocket"
##############################
## WebSocket Config Builder ##
##############################
type WebSocketConfBuilder* = object
enabled*: Option[bool]
webSocketPort*: Option[Port]
secureEnabled*: Option[bool]
keyPath*: Option[string]
certPath*: Option[string]
proc init*(T: type WebSocketConfBuilder): WebSocketConfBuilder =
WebSocketConfBuilder()
proc withEnabled*(b: var WebSocketConfBuilder, enabled: bool) =
b.enabled = some(enabled)
proc withSecureEnabled*(b: var WebSocketConfBuilder, secureEnabled: bool) =
b.secureEnabled = some(secureEnabled)
if b.secureEnabled.get():
b.enabled = some(true) # ws must be enabled to use wss
proc withWebSocketPort*(b: var WebSocketConfBuilder, webSocketPort: Port) =
b.webSocketPort = some(webSocketPort)
proc withWebSocketPort*(b: var WebSocketConfBuilder, webSocketPort: uint16) =
b.webSocketPort = some(Port(webSocketPort))
proc withKeyPath*(b: var WebSocketConfBuilder, keyPath: string) =
b.keyPath = some(keyPath)
proc withCertPath*(b: var WebSocketConfBuilder, certPath: string) =
b.certPath = some(certPath)
proc build*(b: WebSocketConfBuilder): Result[Option[WebSocketConf], string] =
if not b.enabled.get(false):
return ok(none(WebSocketConf))
if b.webSocketPort.isNone():
return err("websocket.port is not specified")
if not b.secureEnabled.get(false):
return ok(
some(
WebSocketConf(
port: b.websocketPort.get(), secureConf: none(WebSocketSecureConf)
)
)
)
if b.keyPath.get("") == "":
return err("WebSocketSecure enabled but key path is not specified")
if b.certPath.get("") == "":
return err("WebSocketSecure enabled but cert path is not specified")
return ok(
some(
WebSocketConf(
port: b.webSocketPort.get(),
secureConf: some(
WebSocketSecureConf(keyPath: b.keyPath.get(), certPath: b.certPath.get())
),
)
)
)