Merge c0862f81ffbe40b1f6a21df061cd746ecd938dbc into d1360e26f732b2c606457f423d5c9e47acff4aa5

This commit is contained in:
Vaclav Pavlin 2025-09-04 12:14:00 +02:00 committed by GitHub
commit ed55bfbab5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 3 deletions

View File

@ -1,5 +1,7 @@
package common
type ExtraOptions map[string]interface{}
type WakuConfig struct {
Host string `json:"host,omitempty"`
Nodekey string `json:"nodekey,omitempty"`

View File

@ -372,19 +372,24 @@ func WakuGoCallback(ret C.int, msg *C.char, len C.size_t, resp unsafe.Pointer) {
type WakuNode struct {
wakuCtx unsafe.Pointer
config *common.WakuConfig
extraOptions common.ExtraOptions
MsgChan chan common.Envelope
TopicHealthChan chan topicHealth
ConnectionChangeChan chan connectionChange
nodeName string
}
func NewWakuNode(config *common.WakuConfig, nodeName string) (*WakuNode, error) {
func NewWakuNode(config *common.WakuConfig, nodeName string, opts ...WakuNodeOption) (*WakuNode, error) {
Debug("Creating new WakuNode: %v", nodeName)
n := &WakuNode{
config: config,
nodeName: nodeName,
}
for _, o := range opts {
o(n)
}
wg := sync.WaitGroup{}
jsonConfig, err := json.Marshal(config)
@ -392,6 +397,22 @@ func NewWakuNode(config *common.WakuConfig, nodeName string) (*WakuNode, error)
return nil, err
}
if len(n.extraOptions) > 0 {
configMap := make(common.ExtraOptions)
err = json.Unmarshal(jsonConfig, &configMap)
if err != nil {
return nil, err
}
for k, v := range n.extraOptions {
configMap[k] = v
}
jsonConfig, err = json.Marshal(configMap)
if err != nil {
return nil, err
}
}
var cJsonConfig = C.CString(string(jsonConfig))
var resp = C.allocResp(unsafe.Pointer(&wg))
@ -1503,7 +1524,7 @@ func GetFreePortIfNeeded(tcpPort int, discV5UDPPort int) (int, int, error) {
}
// Create & start node
func StartWakuNode(nodeName string, customCfg *common.WakuConfig) (*WakuNode, error) {
func StartWakuNode(nodeName string, customCfg *common.WakuConfig, opts ...WakuNodeOption) (*WakuNode, error) {
Debug("Initializing %s", nodeName)
@ -1528,7 +1549,7 @@ func StartWakuNode(nodeName string, customCfg *common.WakuConfig) (*WakuNode, er
}
Debug("Creating %s", nodeName)
node, err := NewWakuNode(&nodeCfg, nodeName)
node, err := NewWakuNode(&nodeCfg, nodeName, opts...)
if err != nil {
Error("Failed to create %s: %v", nodeName, err)
return nil, err

13
waku/options.go Normal file
View File

@ -0,0 +1,13 @@
package waku
import "github.com/waku-org/waku-go-bindings/waku/common"
type WakuNodeOption func(*WakuNode)
// This allows you to pass arbitrary valid config options to Nwaku based on https://github.com/waku-org/nwaku/blob/master/waku/factory/external_config.nim
// It is mostly for development and experimental purposes and will be removed in the future.
func WithExtraOptions(extraOptions common.ExtraOptions) WakuNodeOption {
return func(wn *WakuNode) {
wn.extraOptions = extraOptions
}
}