Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ( // ExceededBanThreshold 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 // InvalidBlock signals that a peer served us a bad block. InvalidBlock Reason = 5 )
We prevent using `iota` to ensure the order does not have the value since these are serialized within the database.
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.