From bad57fcb0cae53aa2c36f8c969ee1ae229e6ee0a Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Wed, 3 Jan 2024 08:05:04 +0530 Subject: [PATCH] fix: get peers api to not include own node ID as peer (#974) --- cmd/waku/server/rest/admin.go | 4 ++++ cmd/waku/server/rpc/admin.go | 4 ++++ waku/persistence/postgres/mock.go | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/cmd/waku/server/rest/admin.go b/cmd/waku/server/rest/admin.go index f945c681..8bee1cc6 100644 --- a/cmd/waku/server/rest/admin.go +++ b/cmd/waku/server/rest/admin.go @@ -62,6 +62,10 @@ func (a *AdminService) getV1Peers(w http.ResponseWriter, req *http.Request) { response := make([]WakuPeer, 0) for _, peer := range peers { + if peer.ID.String() == a.node.Host().ID().String() { + //Skip own node id + continue + } wPeer := WakuPeer{ ID: peer.ID.Pretty(), Connected: peer.Connected, diff --git a/cmd/waku/server/rpc/admin.go b/cmd/waku/server/rpc/admin.go index 956300c8..be1b6a79 100644 --- a/cmd/waku/server/rpc/admin.go +++ b/cmd/waku/server/rpc/admin.go @@ -57,6 +57,10 @@ func (a *AdminService) GetV1Peers(req *http.Request, args *GetPeersArgs, reply * return nil } for _, peer := range peers { + if peer.ID.String() == a.node.Host().ID().String() { + //Skip own node id + continue + } for _, addr := range peer.Addrs { for _, proto := range peer.Protocols { if !server.IsWakuProtocol(proto) { diff --git a/waku/persistence/postgres/mock.go b/waku/persistence/postgres/mock.go index df601a53..5ed272cc 100644 --- a/waku/persistence/postgres/mock.go +++ b/waku/persistence/postgres/mock.go @@ -5,6 +5,8 @@ import ( "fmt" "log" "os" + + "github.com/avast/retry-go/v4" ) var dbUrlTemplate = "postgres://postgres@localhost:%s/%s?sslmode=disable" @@ -39,8 +41,16 @@ func NewMockPgDB() *sql.DB { mockPgDBPort = "5432" } // - dropDBUrl := fmt.Sprintf(dbUrlTemplate, mockPgDBPort, "template1") - if err := ResetDefaultTestPostgresDB(dropDBUrl); err != nil { + err := retry.Do( + func() error { + + dropDBUrl := fmt.Sprintf(dbUrlTemplate, mockPgDBPort, "template1") + if err := ResetDefaultTestPostgresDB(dropDBUrl); err != nil { + return err + } + return nil + }, retry.Attempts(3)) + if err != nil { log.Fatalf("an error '%s' while reseting the db", err) } mockDBUrl := fmt.Sprintf(dbUrlTemplate, mockPgDBPort, "postgres")