mirror of https://github.com/status-im/go-waku.git
feat(c-bindings): update bootnodes
This commit is contained in:
parent
b0c094b0b6
commit
f6fe353e2e
|
@ -1219,6 +1219,27 @@ For example:
|
|||
}
|
||||
```
|
||||
|
||||
### `extern char* waku_discv5_update_bootnodes(char* bootnodes)`
|
||||
Update the bootnode list used for discovering new peers via DiscoveryV5
|
||||
|
||||
**Parameters**
|
||||
|
||||
1. `char* bootnodes`: JSON array containing the bootnode ENRs i.e. `["enr:...", "enr:..."]`
|
||||
|
||||
**Returns**
|
||||
|
||||
A [`JsonResponse`](#jsonresponse-type).
|
||||
If the execution is successful, the `result` field is set to `true`.
|
||||
|
||||
For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"result": true
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### `extern char* waku_discv5_stop()`
|
||||
Stops the DiscoveryV5 service
|
||||
|
||||
|
|
|
@ -7,7 +7,9 @@ import (
|
|||
)
|
||||
|
||||
// Returns a list of objects containing the peerID, enr and multiaddresses for each node found
|
||||
// given a url to a DNS discoverable ENR tree
|
||||
//
|
||||
// given a url to a DNS discoverable ENR tree
|
||||
//
|
||||
// The nameserver can optionally be specified to resolve the enrtree url. Otherwise NULL or
|
||||
// empty to automatically use the default system dns.
|
||||
// If ms is greater than 0, the subscription must happen before the timeout
|
||||
|
@ -18,3 +20,12 @@ func waku_dns_discovery(url *C.char, nameserver *C.char, ms C.int) *C.char {
|
|||
response := mobile.DnsDiscovery(C.GoString(url), C.GoString(nameserver), int(ms))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
||||
// Update the bootnode list used for discovering new peers via DiscoveryV5
|
||||
// The bootnodes param should contain a JSON array containing the bootnode ENRs i.e. `["enr:...", "enr:..."]`
|
||||
//
|
||||
//export waku_discv5_update_bootnodes
|
||||
func waku_discv5_update_bootnodes(bootnodes *C.char) *C.char {
|
||||
response := mobile.SetBootnodes(C.GoString(bootnodes))
|
||||
return C.CString(response)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ package gowaku
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/p2p/enode"
|
||||
"github.com/waku-org/go-waku/waku/v2/dnsdisc"
|
||||
)
|
||||
|
||||
|
@ -79,3 +81,38 @@ func StopDiscoveryV5() string {
|
|||
wakuState.node.DiscV5().Stop()
|
||||
return MakeJSONResponse(nil)
|
||||
}
|
||||
|
||||
func SetBootnodes(bootnodes string) string {
|
||||
if wakuState.node == nil {
|
||||
return MakeJSONResponse(errWakuNodeNotReady)
|
||||
}
|
||||
if wakuState.node.DiscV5() == nil {
|
||||
return MakeJSONResponse(errors.New("DiscV5 is not mounted"))
|
||||
}
|
||||
|
||||
var tmp []json.RawMessage
|
||||
if err := json.Unmarshal([]byte(bootnodes), &tmp); err != nil {
|
||||
return MakeJSONResponse(err)
|
||||
}
|
||||
|
||||
var enrList []string
|
||||
for _, el := range tmp {
|
||||
var enr string
|
||||
if err := json.Unmarshal(el, &enr); err != nil {
|
||||
return MakeJSONResponse(err)
|
||||
}
|
||||
enrList = append(enrList, enr)
|
||||
}
|
||||
|
||||
var nodes []*enode.Node
|
||||
for _, addr := range enrList {
|
||||
node, err := enode.Parse(enode.ValidSchemes, addr)
|
||||
if err != nil {
|
||||
return MakeJSONResponse(err)
|
||||
}
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
|
||||
err := wakuState.node.DiscV5().SetBootnodes(nodes)
|
||||
return MakeJSONResponse(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue