ip_observer

package
v4.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadIPObserver

type BadIPObserver struct {
	// contains filtered or unexported fields
}

func NewBadIPObserver

func NewBadIPObserver(opts BadIPObserverOpts) (*BadIPObserver, error)

func (*BadIPObserver) Close

func (o *BadIPObserver) Close() error

Close stops callback goroutine. It always returns a nil err.

func (*BadIPObserver) Observe

func (o *BadIPObserver) Observe(addr netip.Addr)

Observe notifies the BadIPObserver that this addr has one error event.

func (*BadIPObserver) ServeHTTP

func (o *BadIPObserver) ServeHTTP(w http.ResponseWriter, req *http.Request)

type BadIPObserverOpts

type BadIPObserverOpts struct {
	HPLimiterOpts concurrent_limiter.HPLimiterOpts

	// TTL specifies the duration that a bad ip will stay in the
	// BadIPObserver if no error is reported. Optional. Default is 10min.
	TTL time.Duration

	// OnUpdateCallBack specifies a local cmd or url that will be called if
	// the bad ip list is updated. Optional.
	// If it starts with "http://" or "https://", BadIPObserverOpts will post
	// a list of bad ip/cidr, split by "/n", to this url.
	// Otherwise, BadIPObserverOpts trades this as a local cmd and will execute
	// it. User should fetch the list of bad ips themselves. OnUpdateCallBack
	// implements the http.Handler interface.
	OnUpdateCallBack string

	CleanerInterval time.Duration // Optional. Default is 10s.
	Logger          *zap.Logger   // Optional. Default is a noop logger.
}

type IPObserver

type IPObserver interface {
	// Observe notifies the IPObserver. addr must be valid.
	Observe(addr netip.Addr)
}

type NopObserver

type NopObserver struct{}

func NewNopObserver

func NewNopObserver() NopObserver

func (NopObserver) Observe

func (n NopObserver) Observe(_ netip.Addr)

Jump to

Keyboard shortcuts

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