refcounter

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIgnore = errors.New("ignore")

ErrIgnore can be returned by AddFunc to indicate that the counter not be incremented for the given prefix.

Functions

This section is empty.

Types

type AddFunc

type AddFunc[I, O any] func(prefix netip.Prefix, in I) (out O, err error)

type AllowedIPsRefCounter

type AllowedIPsRefCounter = Counter[string, string]

AllowedIPsRefCounter is a Counter for AllowedIPs, it takes a peer key on Increment and passes it back to Decrement

type Counter

type Counter[I, O any] struct {
	// contains filtered or unexported fields
}

func New

func New[I, O any](add AddFunc[I, O], remove RemoveFunc[I, O]) *Counter[I, O]

New creates a new Counter instance

func (*Counter[I, O]) Decrement

func (rm *Counter[I, O]) Decrement(prefix netip.Prefix) (Ref[O], error)

Decrement decrements the reference count for the given prefix. If the reference count reaches 0, the RemoveFunc is called.

func (*Counter[I, O]) DecrementWithID

func (rm *Counter[I, O]) DecrementWithID(id string) error

DecrementWithID decrements the reference count for all prefixes associated with the given ID. If the reference count reaches 0, the RemoveFunc is called.

func (*Counter[I, O]) Flush

func (rm *Counter[I, O]) Flush() error

Flush removes all references and calls RemoveFunc for each prefix.

func (*Counter[I, O]) Increment

func (rm *Counter[I, O]) Increment(prefix netip.Prefix, in I) (Ref[O], error)

Increment increments the reference count for the given prefix. If this is the first reference to the prefix, the AddFunc is called.

func (*Counter[I, O]) IncrementWithID

func (rm *Counter[I, O]) IncrementWithID(id string, prefix netip.Prefix, in I) (Ref[O], error)

IncrementWithID increments the reference count for the given prefix and groups it under the given ID. If this is the first reference to the prefix, the AddFunc is called.

type Ref

type Ref[O any] struct {
	Count int
	Out   O
}

type RemoveFunc

type RemoveFunc[I, O any] func(prefix netip.Prefix, out O) error

type RouteRefCounter

type RouteRefCounter = Counter[any, any]

RouteRefCounter is a Counter for Route, it doesn't take any input on Increment and doesn't use any output on Decrement

Jump to

Keyboard shortcuts

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