mirror of
https://github.com/logos-messaging/logos-messaging-go-bindings.git
synced 2026-01-02 14:03:10 +00:00
Merge c0862f81ffbe40b1f6a21df061cd746ecd938dbc into d1360e26f732b2c606457f423d5c9e47acff4aa5
This commit is contained in:
commit
ed55bfbab5
@ -1,5 +1,7 @@
|
||||
package common
|
||||
|
||||
type ExtraOptions map[string]interface{}
|
||||
|
||||
type WakuConfig struct {
|
||||
Host string `json:"host,omitempty"`
|
||||
Nodekey string `json:"nodekey,omitempty"`
|
||||
|
||||
@ -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
13
waku/options.go
Normal 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
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user