banmanager

package
v0.0.0-...-f9146c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2024 License: ISC Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.

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

func (bm *BanManager) AddBanScore(p *peer.Peer, persistent, transient uint32, reason string) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL