banman

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrCorruptedStore is an error returned when we attempt to locate any
	// of the ban-related buckets in the database but are unable to.
	ErrCorruptedStore = errors.New("corrupted ban store")

	// ErrUnsupportedIP is an error returned when we attempt to parse an
	// unsupported IP address type.
	ErrUnsupportedIP = errors.New("unsupported IP type")
)

Functions

func ParseIPNet

func ParseIPNet(addr string, mask net.IPMask) (*net.IPNet, error)

ParseIPNet parses the IP network that contains the given address. An optional mask can be provided, to expand the scope of the IP network, otherwise the IP's default is used.

NOTE: This assumes that the address has already been resolved.

Types

type Reason

type Reason uint8

Reason includes the different possible reasons which caused us to ban a peer.

const (
	// ExcedeedBanThreshold signals that a peer exceeded its ban threshold.
	ExceededBanThreshold Reason = 1

	// NoCompactFilters signals that a peer was unable to serve us compact
	// filters.
	NoCompactFilters Reason = 2

	// InvalidFilterHeader signals that a peer served us an invalid filter
	// header.
	InvalidFilterHeader Reason = 3

	// InvalidFilterHeaderCheckpoint signals that a peer served us an
	// invalid filter header checkpoint.
	InvalidFilterHeaderCheckpoint Reason = 4
)

We prevent using `iota` to ensure the order does not have the value since these are serialized within the database.

func (Reason) String

func (r Reason) String() string

String returns a human-readable description for the reason a peer was banned.

type Status

type Status struct {
	// Banned determines whether the IP network is currently banned.
	Banned bool

	// Reason is the reason for which the IP network was banned.
	Reason Reason

	// Expiration is the absolute time in which the ban will expire.
	Expiration time.Time
}

Status gathers all of the details regarding an IP network's ban status.

type Store

type Store interface {
	// BanIPNet creates a ban record for the IP network within the store for
	// the given duration. A reason can also be provided to note why the IP
	// network is being banned. The record will exist until a call to Status
	// is made after the ban expiration.
	BanIPNet(*net.IPNet, Reason, time.Duration) error

	// Status returns the ban status for a given IP network.
	Status(*net.IPNet) (Status, error)
}

Store is the store responsible for maintaining records of banned IP networks. It uses IP networks, rather than single IP addresses, in order to coalesce multiple IP addresses that are likely to be correlated.

func NewStore

func NewStore(db walletdb.DB) (Store, error)

NewStore returns a Store backed by a database.

Jump to

Keyboard shortcuts

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