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
|
||||
func (w *gethWakuWrapper) Peers() map[string][]string {
|
||||
p := make(map[string][]string)
|
||||
func (w *gethWakuWrapper) Peers() map[string]types.WakuV2Peer {
|
||||
p := make(map[string]types.WakuV2Peer)
|
||||
return p
|
||||
}
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ func (w *gethWakuV2Wrapper) AddRelayPeer(address string) (string, error) {
|
|||
return w.waku.AddRelayPeer(address)
|
||||
}
|
||||
|
||||
func (w *gethWakuV2Wrapper) Peers() map[string][]string {
|
||||
func (w *gethWakuV2Wrapper) Peers() map[string]types.WakuV2Peer {
|
||||
return w.waku.Peers()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,12 @@ import (
|
|||
type ConnStatus struct {
|
||||
IsOnline bool `json:"isOnline"`
|
||||
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 {
|
||||
|
@ -71,7 +76,7 @@ type Waku interface {
|
|||
// PeerCount
|
||||
PeerCount() int
|
||||
|
||||
Peers() map[string][]string
|
||||
Peers() map[string]WakuV2Peer
|
||||
|
||||
StartDiscV5() error
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package protocol
|
||||
|
||||
import "github.com/status-im/status-go/eth-node/types"
|
||||
|
||||
func (m *Messenger) AddStorePeer(address string) (string, error) {
|
||||
return m.transport.AddStorePeer(address)
|
||||
}
|
||||
|
@ -20,6 +22,6 @@ func (m *Messenger) DropPeer(peerID string) error {
|
|||
return m.transport.DropPeer(peerID)
|
||||
}
|
||||
|
||||
func (m *Messenger) Peers() map[string][]string {
|
||||
func (m *Messenger) Peers() map[string]types.WakuV2Peer {
|
||||
return m.transport.Peers()
|
||||
}
|
||||
|
|
|
@ -435,7 +435,7 @@ func (t *Transport) PeerCount() int {
|
|||
return t.waku.PeerCount()
|
||||
}
|
||||
|
||||
func (t *Transport) Peers() map[string][]string {
|
||||
func (t *Transport) Peers() map[string]types.WakuV2Peer {
|
||||
return t.waku.Peers()
|
||||
}
|
||||
|
||||
|
|
|
@ -1159,7 +1159,7 @@ func (api *PublicAPI) DropPeer(peerID string) error {
|
|||
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()
|
||||
}
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ func New(nodeKey string, cfg *Config, logger *zap.Logger, appDB *sql.DB) (*Waku,
|
|||
return
|
||||
case c := <-connStatusChan:
|
||||
waku.connStatusMu.Lock()
|
||||
latestConnStatus := formatConnStatus(c)
|
||||
latestConnStatus := formatConnStatus(waku.node, c)
|
||||
for k, subs := range waku.connStatusSubscriptions {
|
||||
if subs.Active() {
|
||||
subs.C <- latestConnStatus
|
||||
|
@ -1121,8 +1121,8 @@ func (w *Waku) PeerCount() int {
|
|||
return w.node.PeerCount()
|
||||
}
|
||||
|
||||
func (w *Waku) Peers() map[string][]string {
|
||||
return FormatPeerStats(w.node.PeerStats())
|
||||
func (w *Waku) Peers() map[string]types.WakuV2Peer {
|
||||
return FormatPeerStats(w.node, w.node.PeerStats())
|
||||
}
|
||||
|
||||
func (w *Waku) StartDiscV5() error {
|
||||
|
@ -1231,18 +1231,25 @@ func toDeterministicID(id string, expectedLen int) (string, error) {
|
|||
return id, nil
|
||||
}
|
||||
|
||||
func FormatPeerStats(peers node.PeerStats) map[string][]string {
|
||||
p := make(map[string][]string)
|
||||
func FormatPeerStats(wakuNode *node.WakuNode, peers node.PeerStats) map[string]types.WakuV2Peer {
|
||||
p := make(map[string]types.WakuV2Peer)
|
||||
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
|
||||
}
|
||||
|
||||
func formatConnStatus(c node.ConnStatus) types.ConnStatus {
|
||||
func formatConnStatus(wakuNode *node.WakuNode, c node.ConnStatus) types.ConnStatus {
|
||||
return types.ConnStatus{
|
||||
IsOnline: c.IsOnline,
|
||||
HasHistory: c.HasHistory,
|
||||
Peers: FormatPeerStats(c.Peers),
|
||||
Peers: FormatPeerStats(wakuNode, c.Peers),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue