Skip to content

Commit

Permalink
Possibility to connect to Sonic nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jenikd committed Jul 11, 2024
1 parent 06c1726 commit 7548273
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions gossip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gossip
import (
"errors"
"fmt"
"github.com/ethereum/go-ethereum/p2p/enode"
"math"
"math/rand"
"strings"
Expand Down Expand Up @@ -773,6 +774,17 @@ func (h *handler) highestPeerProgress() PeerProgress {
return max
}

// isUseless checks if the peer is banned from discovery and ban it if it should be
func isUseless(node *enode.Node, name string) bool {
useless := discfilter.Banned(node.ID(), node.Record())
lowerName := strings.ToLower(name)
if !useless && !strings.Contains(lowerName, "opera") && !strings.Contains(lowerName, "sonic") {
useless = true
discfilter.Ban(node.ID())
}
return useless
}

// handle is the callback invoked to manage the life cycle of a peer. When
// this function terminates, the peer is disconnected.
func (h *handler) handle(p *peer) error {
Expand All @@ -783,11 +795,7 @@ func (h *handler) handle(p *peer) error {
p.Log().Error("Snapshot extension barrier failed", "err", err)
return err
}
useless := discfilter.Banned(p.Node().ID(), p.Node().Record())
if !useless && (!eligibleForSnap(p.Peer) || !strings.Contains(strings.ToLower(p.Name()), "opera")) {
useless = true
discfilter.Ban(p.ID())
}
useless := isUseless(p.Node(), p.Name())
if !p.Peer.Info().Network.Trusted && useless {
if h.peers.UselessNum() >= h.maxPeers/10 {
// don't allow more than 10% of useless peers
Expand Down

0 comments on commit 7548273

Please sign in to comment.