add peerlist length check
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2024-04-23 18:43:54 +02:00
parent bbbf1f2638
commit 8427e5ca2e
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk

View file

@ -736,7 +736,7 @@ func (c *Client) OnConnection() {
if lastLen < PeerListResponseMaxPeers {
//improvement from normal p2pool: pad response with other peers from peer list, not connected
peerList := c.Owner.PeerList()
for i := lastLen; i < PeerListResponseMaxPeers; i++ {
for i := lastLen; i < PeerListResponseMaxPeers && len(peerList) > 0; i++ {
k := unsafeRandom.IntN(len(peerList)) % len(peerList)
peer := peerList[k]
if !slices.ContainsFunc(entriesToSend, func(addrPort netip.AddrPort) bool {