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

@ -27,6 +27,7 @@ type WakuPeer struct {
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

@ -86,3 +86,7 @@ components:
type: string type: string
connected: connected:
type: boolean type: boolean
pubsubTopics:
type: array
items:
type: string

View File

@ -57,6 +57,7 @@ type Peer struct {
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