From 5a5ee51f4b69d1abc8d7f1dc6924850588dc18c3 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Wed, 6 Dec 2023 07:17:59 +0530 Subject: [PATCH] feat: include pubsubTopics supported by peer in getPeers REST API (#943) --- cmd/waku/server/rest/admin.go | 10 ++++++---- cmd/waku/server/rest/admin_api.yaml | 6 +++++- waku/v2/node/wakunode2.go | 22 ++++++++++++++-------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cmd/waku/server/rest/admin.go b/cmd/waku/server/rest/admin.go index 22628935..1e719e1d 100644 --- a/cmd/waku/server/rest/admin.go +++ b/cmd/waku/server/rest/admin.go @@ -23,10 +23,11 @@ type AdminService struct { } type WakuPeer struct { - ID string `json:"id"` - MultiAddrs []string `json:"multiaddrs"` - Protocols []string `json:"protocols"` - Connected bool `json:"connected"` + ID string `json:"id"` + MultiAddrs []string `json:"multiaddrs"` + Protocols []string `json:"protocols"` + Connected bool `json:"connected"` + PubsubTopics []string `json:"pubsubTopics"` } 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.PubsubTopics = peer.PubsubTopics response = append(response, wPeer) } diff --git a/cmd/waku/server/rest/admin_api.yaml b/cmd/waku/server/rest/admin_api.yaml index a96c6881..04834b0a 100644 --- a/cmd/waku/server/rest/admin_api.yaml +++ b/cmd/waku/server/rest/admin_api.yaml @@ -85,4 +85,8 @@ components: items: type: string connected: - type: boolean \ No newline at end of file + type: boolean + pubsubTopics: + type: array + items: + type: string \ No newline at end of file diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index a9f22657..fa975bdd 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -53,10 +53,11 @@ import ( const discoveryConnectTimeout = 20 * time.Second type Peer struct { - ID peer.ID `json:"peerID"` - Protocols []protocol.ID `json:"protocols"` - Addrs []ma.Multiaddr `json:"addrs"` - Connected bool `json:"connected"` + ID peer.ID `json:"peerID"` + Protocols []protocol.ID `json:"protocols"` + Addrs []ma.Multiaddr `json:"addrs"` + Connected bool `json:"connected"` + PubsubTopics []string `json:"pubsubTopics"` } 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)...) + topics, err := w.host.Peerstore().(*wps.WakuPeerstoreImpl).PubSubTopics(peerId) + if err != nil { + return nil, err + } peers = append(peers, &Peer{ - ID: peerId, - Protocols: protocols, - Connected: connected, - Addrs: addrs, + ID: peerId, + Protocols: protocols, + Connected: connected, + Addrs: addrs, + PubsubTopics: topics, }) } return peers, nil