fix: get peers api to not include own node ID as peer (#974)

This commit is contained in:
Prem Chaitanya Prathi 2024-01-03 08:05:04 +05:30 committed by GitHub
parent b5068b4357
commit bad57fcb0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -62,6 +62,10 @@ func (a *AdminService) getV1Peers(w http.ResponseWriter, req *http.Request) {
response := make([]WakuPeer, 0) response := make([]WakuPeer, 0)
for _, peer := range peers { for _, peer := range peers {
if peer.ID.String() == a.node.Host().ID().String() {
//Skip own node id
continue
}
wPeer := WakuPeer{ wPeer := WakuPeer{
ID: peer.ID.Pretty(), ID: peer.ID.Pretty(),
Connected: peer.Connected, Connected: peer.Connected,

View File

@ -57,6 +57,10 @@ func (a *AdminService) GetV1Peers(req *http.Request, args *GetPeersArgs, reply *
return nil return nil
} }
for _, peer := range peers { for _, peer := range peers {
if peer.ID.String() == a.node.Host().ID().String() {
//Skip own node id
continue
}
for _, addr := range peer.Addrs { for _, addr := range peer.Addrs {
for _, proto := range peer.Protocols { for _, proto := range peer.Protocols {
if !server.IsWakuProtocol(proto) { if !server.IsWakuProtocol(proto) {

View File

@ -5,6 +5,8 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"github.com/avast/retry-go/v4"
) )
var dbUrlTemplate = "postgres://postgres@localhost:%s/%s?sslmode=disable" var dbUrlTemplate = "postgres://postgres@localhost:%s/%s?sslmode=disable"
@ -39,8 +41,16 @@ func NewMockPgDB() *sql.DB {
mockPgDBPort = "5432" mockPgDBPort = "5432"
} }
// //
err := retry.Do(
func() error {
dropDBUrl := fmt.Sprintf(dbUrlTemplate, mockPgDBPort, "template1") dropDBUrl := fmt.Sprintf(dbUrlTemplate, mockPgDBPort, "template1")
if err := ResetDefaultTestPostgresDB(dropDBUrl); err != nil { 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) log.Fatalf("an error '%s' while reseting the db", err)
} }
mockDBUrl := fmt.Sprintf(dbUrlTemplate, mockPgDBPort, "postgres") mockDBUrl := fmt.Sprintf(dbUrlTemplate, mockPgDBPort, "postgres")