erigon-pulse/cmd/lightclient/sentinel/gater.go
Giulio rebuffo 0fb982bfeb
Added p2p connection and libp2p host to Erigon Lightclient (#5500)
* added p2p connection and libp2p host

* added p2p connection and libp2p host

* oooops

Co-authored-by: giuliorebuffo <giuliorebuffo@system76-pc.localdomain>
2022-09-24 20:48:56 +02:00

37 lines
1.2 KiB
Go

package sentinel
import (
"github.com/ledgerwatch/erigon/cmd/lightclient/sentinel/peers"
"github.com/libp2p/go-libp2p/core/control"
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
)
// InterceptPeerDial tests whether we're permitted to Dial the specified peer.
func (_ *Sentinel) InterceptPeerDial(_ peer.ID) (allow bool) {
return true
}
// InterceptAddrDial tests whether we're permitted to dial the specified
// multiaddr for the given peer.
func (s *Sentinel) InterceptAddrDial(pid peer.ID, m multiaddr.Multiaddr) (allow bool) {
return !s.peers.IsBadPeer(pid)
}
// InterceptAccept checks whether the incidental inbound connection is allowed.
func (s *Sentinel) InterceptAccept(n network.ConnMultiaddrs) (allow bool) {
return len(s.host.Network().Peers()) < peers.DefaultMaxPeers
}
// InterceptSecured tests whether a given connection, now authenticated,
// is allowed.
func (_ *Sentinel) InterceptSecured(_ network.Direction, _ peer.ID, _ network.ConnMultiaddrs) (allow bool) {
return true
}
// InterceptUpgraded tests whether a fully capable connection is allowed.
func (_ *Sentinel) InterceptUpgraded(_ network.Conn) (allow bool, reason control.DisconnectReason) {
return true, 0
}