From 58fe0c6241edbde5d9e070b95cce2ebc46bb9c1e Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 30 Sep 2021 10:54:48 -0400 Subject: [PATCH] fix: no peers available --- client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client.go b/client.go index 1978894..394a687 100644 --- a/client.go +++ b/client.go @@ -2,6 +2,7 @@ package rendezvous import ( "context" + "errors" "fmt" "math/rand" "time" @@ -71,6 +72,11 @@ func (r *rendezvousPoint) getRandomPeer() (peer.ID, error) { peerIDs = append(peerIDs, peer) } } + + if len(peerIDs) == 0 { + return "", errors.New("no peers available") + } + return peerIDs[rand.Intn(len(peerIDs))], nil // nolint: gosec }