mirror of
https://github.com/status-im/status-go.git
synced 2025-03-03 08:00:54 +00:00
- some minor progress to add nwaku in status-go - nwaku.go: GetNumConnectedPeers controls when passed pubsub is empty - waku_test.go: adapt TestWakuV2Store - add missing shard.go - feat_: build nwaku with nix and use build tags to choose between go-waku and nwaku (#5896) - chore_: update nwaku - nwaku bump (#5911) - bump: nwaku - chore: add USE_NWAKU env flag - fix: build libwaku only if needed - feat: testing discovery and dialing with nwaku integration (#5940)
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package wakuv2
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type NwakuInfo struct {
|
|
ListenAddresses []string `json:"listenAddresses"`
|
|
EnrUri string `json:"enrUri"`
|
|
}
|
|
|
|
func GetNwakuInfo(host *string, port *int) (NwakuInfo, error) {
|
|
nwakuRestPort := 8645
|
|
if port != nil {
|
|
nwakuRestPort = *port
|
|
}
|
|
envNwakuRestPort := os.Getenv("NWAKU_REST_PORT")
|
|
if envNwakuRestPort != "" {
|
|
v, err := strconv.Atoi(envNwakuRestPort)
|
|
if err != nil {
|
|
return NwakuInfo{}, err
|
|
}
|
|
nwakuRestPort = v
|
|
}
|
|
|
|
nwakuRestHost := "localhost"
|
|
if host != nil {
|
|
nwakuRestHost = *host
|
|
}
|
|
envNwakuRestHost := os.Getenv("NWAKU_REST_HOST")
|
|
if envNwakuRestHost != "" {
|
|
nwakuRestHost = envNwakuRestHost
|
|
}
|
|
|
|
resp, err := http.Get(fmt.Sprintf("http://%s:%d/debug/v1/info", nwakuRestHost, nwakuRestPort))
|
|
if err != nil {
|
|
return NwakuInfo{}, err
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return NwakuInfo{}, err
|
|
}
|
|
|
|
var data NwakuInfo
|
|
err = json.Unmarshal(body, &data)
|
|
if err != nil {
|
|
return NwakuInfo{}, err
|
|
}
|
|
|
|
return data, nil
|
|
}
|