feat: add multiaddresses to waku2 peers
This commit is contained in:
parent
e83ad01e66
commit
a6c7067f3b
|
@ -84,8 +84,8 @@ func (w *gethWakuWrapper) SubscribeToConnStatusChanges() (*types.ConnStatusSubsc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peers function only added for compatibility with waku V2
|
// Peers function only added for compatibility with waku V2
|
||||||
func (w *gethWakuWrapper) Peers() map[string][]string {
|
func (w *gethWakuWrapper) Peers() map[string]types.WakuV2Peer {
|
||||||
p := make(map[string][]string)
|
p := make(map[string]types.WakuV2Peer)
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -241,7 +241,7 @@ func (w *gethWakuV2Wrapper) AddRelayPeer(address string) (string, error) {
|
||||||
return w.waku.AddRelayPeer(address)
|
return w.waku.AddRelayPeer(address)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *gethWakuV2Wrapper) Peers() map[string][]string {
|
func (w *gethWakuV2Wrapper) Peers() map[string]types.WakuV2Peer {
|
||||||
return w.waku.Peers()
|
return w.waku.Peers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConnStatus struct {
|
type ConnStatus struct {
|
||||||
IsOnline bool `json:"isOnline"`
|
IsOnline bool `json:"isOnline"`
|
||||||
HasHistory bool `json:"hasHistory"`
|
HasHistory bool `json:"hasHistory"`
|
||||||
Peers map[string][]string `json:"peers"`
|
Peers map[string]WakuV2Peer `json:"peers"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WakuV2Peer struct {
|
||||||
|
Protocols []string `json:"protocols"`
|
||||||
|
Addresses []string `json:"addresses"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConnStatusSubscription struct {
|
type ConnStatusSubscription struct {
|
||||||
|
@ -71,7 +76,7 @@ type Waku interface {
|
||||||
// PeerCount
|
// PeerCount
|
||||||
PeerCount() int
|
PeerCount() int
|
||||||
|
|
||||||
Peers() map[string][]string
|
Peers() map[string]WakuV2Peer
|
||||||
|
|
||||||
StartDiscV5() error
|
StartDiscV5() error
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
|
import "github.com/status-im/status-go/eth-node/types"
|
||||||
|
|
||||||
func (m *Messenger) AddStorePeer(address string) (string, error) {
|
func (m *Messenger) AddStorePeer(address string) (string, error) {
|
||||||
return m.transport.AddStorePeer(address)
|
return m.transport.AddStorePeer(address)
|
||||||
}
|
}
|
||||||
|
@ -20,6 +22,6 @@ func (m *Messenger) DropPeer(peerID string) error {
|
||||||
return m.transport.DropPeer(peerID)
|
return m.transport.DropPeer(peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) Peers() map[string][]string {
|
func (m *Messenger) Peers() map[string]types.WakuV2Peer {
|
||||||
return m.transport.Peers()
|
return m.transport.Peers()
|
||||||
}
|
}
|
||||||
|
|
|
@ -435,7 +435,7 @@ func (t *Transport) PeerCount() int {
|
||||||
return t.waku.PeerCount()
|
return t.waku.PeerCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Transport) Peers() map[string][]string {
|
func (t *Transport) Peers() map[string]types.WakuV2Peer {
|
||||||
return t.waku.Peers()
|
return t.waku.Peers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1159,7 +1159,7 @@ func (api *PublicAPI) DropPeer(peerID string) error {
|
||||||
return api.service.messenger.DropPeer(peerID)
|
return api.service.messenger.DropPeer(peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) Peers() map[string][]string {
|
func (api *PublicAPI) Peers() map[string]types.WakuV2Peer {
|
||||||
return api.service.messenger.Peers()
|
return api.service.messenger.Peers()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -263,7 +263,7 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger, appDB *sql.DB) (*Waku,
|
||||||
return
|
return
|
||||||
case c := <-connStatusChan:
|
case c := <-connStatusChan:
|
||||||
waku.connStatusMu.Lock()
|
waku.connStatusMu.Lock()
|
||||||
latestConnStatus := formatConnStatus(c)
|
latestConnStatus := formatConnStatus(waku.node, c)
|
||||||
for k, subs := range waku.connStatusSubscriptions {
|
for k, subs := range waku.connStatusSubscriptions {
|
||||||
if subs.Active() {
|
if subs.Active() {
|
||||||
subs.C <- latestConnStatus
|
subs.C <- latestConnStatus
|
||||||
|
@ -1121,8 +1121,8 @@ func (w *Waku) PeerCount() int {
|
||||||
return w.node.PeerCount()
|
return w.node.PeerCount()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Waku) Peers() map[string][]string {
|
func (w *Waku) Peers() map[string]types.WakuV2Peer {
|
||||||
return FormatPeerStats(w.node.PeerStats())
|
return FormatPeerStats(w.node, w.node.PeerStats())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Waku) StartDiscV5() error {
|
func (w *Waku) StartDiscV5() error {
|
||||||
|
@ -1231,18 +1231,25 @@ func toDeterministicID(id string, expectedLen int) (string, error) {
|
||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatPeerStats(peers node.PeerStats) map[string][]string {
|
func FormatPeerStats(wakuNode *node.WakuNode, peers node.PeerStats) map[string]types.WakuV2Peer {
|
||||||
p := make(map[string][]string)
|
p := make(map[string]types.WakuV2Peer)
|
||||||
for k, v := range peers {
|
for k, v := range peers {
|
||||||
p[k.Pretty()] = v
|
peerInfo := wakuNode.Host().Peerstore().PeerInfo(k)
|
||||||
|
wakuV2Peer := types.WakuV2Peer{}
|
||||||
|
wakuV2Peer.Protocols = v
|
||||||
|
hostInfo, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/p2p/%s", k.Pretty()))
|
||||||
|
for _, addr := range peerInfo.Addrs {
|
||||||
|
wakuV2Peer.Addresses = append(wakuV2Peer.Addresses, addr.Encapsulate(hostInfo).String())
|
||||||
|
}
|
||||||
|
p[k.Pretty()] = wakuV2Peer
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatConnStatus(c node.ConnStatus) types.ConnStatus {
|
func formatConnStatus(wakuNode *node.WakuNode, c node.ConnStatus) types.ConnStatus {
|
||||||
return types.ConnStatus{
|
return types.ConnStatus{
|
||||||
IsOnline: c.IsOnline,
|
IsOnline: c.IsOnline,
|
||||||
HasHistory: c.HasHistory,
|
HasHistory: c.HasHistory,
|
||||||
Peers: FormatPeerStats(c.Peers),
|
Peers: FormatPeerStats(wakuNode, c.Peers),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue