feat: include pubsubTopics supported by peer in getPeers REST API (#943)

This commit is contained in:
Prem Chaitanya Prathi 2023-12-06 07:17:59 +05:30 committed by GitHub
parent 13e2d7ac4b
commit 5a5ee51f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 13 deletions

View File

@ -23,10 +23,11 @@ type AdminService struct {
} }
type WakuPeer struct { type WakuPeer struct {
ID string `json:"id"` ID string `json:"id"`
MultiAddrs []string `json:"multiaddrs"` MultiAddrs []string `json:"multiaddrs"`
Protocols []string `json:"protocols"` Protocols []string `json:"protocols"`
Connected bool `json:"connected"` Connected bool `json:"connected"`
PubsubTopics []string `json:"pubsubTopics"`
} }
type WakuPeerInfo struct { type WakuPeerInfo struct {
@ -76,6 +77,7 @@ func (a *AdminService) getV1Peers(w http.ResponseWriter, req *http.Request) {
} }
wPeer.Protocols = append(wPeer.Protocols, string(proto)) wPeer.Protocols = append(wPeer.Protocols, string(proto))
} }
wPeer.PubsubTopics = peer.PubsubTopics
response = append(response, wPeer) response = append(response, wPeer)
} }

View File

@ -85,4 +85,8 @@ components:
items: items:
type: string type: string
connected: connected:
type: boolean type: boolean
pubsubTopics:
type: array
items:
type: string

View File

@ -53,10 +53,11 @@ import (
const discoveryConnectTimeout = 20 * time.Second const discoveryConnectTimeout = 20 * time.Second
type Peer struct { type Peer struct {
ID peer.ID `json:"peerID"` ID peer.ID `json:"peerID"`
Protocols []protocol.ID `json:"protocols"` Protocols []protocol.ID `json:"protocols"`
Addrs []ma.Multiaddr `json:"addrs"` Addrs []ma.Multiaddr `json:"addrs"`
Connected bool `json:"connected"` Connected bool `json:"connected"`
PubsubTopics []string `json:"pubsubTopics"`
} }
type storeFactory func(w *WakuNode) store.Store type storeFactory func(w *WakuNode) store.Store
@ -858,11 +859,16 @@ func (w *WakuNode) Peers() ([]*Peer, error) {
} }
addrs := utils.EncapsulatePeerID(peerId, w.host.Peerstore().Addrs(peerId)...) addrs := utils.EncapsulatePeerID(peerId, w.host.Peerstore().Addrs(peerId)...)
topics, err := w.host.Peerstore().(*wps.WakuPeerstoreImpl).PubSubTopics(peerId)
if err != nil {
return nil, err
}
peers = append(peers, &Peer{ peers = append(peers, &Peer{
ID: peerId, ID: peerId,
Protocols: protocols, Protocols: protocols,
Connected: connected, Connected: connected,
Addrs: addrs, Addrs: addrs,
PubsubTopics: topics,
}) })
} }
return peers, nil return peers, nil