fix: no peers available

This commit is contained in:
Richard Ramos 2021-09-30 10:54:48 -04:00
parent ba3a59f225
commit 58fe0c6241
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F

View File

@ -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
}