Documentation
¶
Index ¶
- func UseLogger(logger slog.Logger)
- type BanManager
- func (bm *BanManager) AddBanScore(p *peer.Peer, persistent, transient uint32, reason string) bool
- func (bm *BanManager) AddPeer(p *peer.Peer) error
- func (bm *BanManager) BanPeer(p *peer.Peer)
- func (bm *BanManager) BanScore(p *peer.Peer) uint32
- func (bm *BanManager) IsPeerWhitelisted(p *peer.Peer) bool
- func (bm *BanManager) RemovePeer(p *peer.Peer)
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BanManager ¶
type BanManager struct {
// contains filtered or unexported fields
}
BanManager represents a peer ban score tracking manager.
func NewBanManager ¶
func NewBanManager(cfg *Config) *BanManager
NewBanManager initializes a new peer banning manager.
func (*BanManager) AddBanScore ¶
AddBanScore increases the persistent and decaying ban scores of the provided peer by the values passed as parameters. If the resulting score exceeds half of the ban threshold, a warning is logged including the reason provided. Further, if the score is above the ban threshold, the peer will be banned.
func (*BanManager) AddPeer ¶
func (bm *BanManager) AddPeer(p *peer.Peer) error
AddPeer adds the provided peer to the ban manager.
func (*BanManager) BanPeer ¶
func (bm *BanManager) BanPeer(p *peer.Peer)
BanPeer bans the provided peer.
func (*BanManager) BanScore ¶
func (bm *BanManager) BanScore(p *peer.Peer) uint32
BanScore returns the ban score of the provided peer.
func (*BanManager) IsPeerWhitelisted ¶
func (bm *BanManager) IsPeerWhitelisted(p *peer.Peer) bool
IsPeerWhitelisted checks if the provided peer is whitelisted.
func (*BanManager) RemovePeer ¶
func (bm *BanManager) RemovePeer(p *peer.Peer)
RemovePeer discards the provided peer from the ban manager.
type Config ¶
type Config struct {
// DisableBanning represents the status of disabling banning of
// misbehaving peers.
DisableBanning bool
// BanThreshold represents the maximum allowed ban score before
// misbehaving peers are disconnecting and banned.
BanThreshold uint32
// BanDuration is the duration for which misbehaving peers stay banned for.
BanDuration time.Duration
// MaxPeers indicates the maximum number of inbound and outbound
// peers allowed.
MaxPeers int
// Whitelist represents the whitelisted IPs of the server.
WhiteList []net.IPNet
}
Config is the configuration struct for the ban manager.