cidrindex

package
v1.50.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry[T any] struct {
	CIDR     netip.Prefix
	Metadata T
}

type Index

type Index[T any] struct {
	// contains filtered or unexported fields
}

Index maintains a CIDR tree for fast IP-to-metadata lookups with LRU caching.

func NewIndex

func NewIndex[T any](cacheSize uint32, cacheTTL time.Duration) (*Index[T], error)

NewIndex creates a new CIDR index with the specified cache size and TTL.

func (*Index[T]) Add

func (idx *Index[T]) Add(cidr netip.Prefix, metadata T) error

Add inserts a CIDR range with associated metadata into the index.

func (*Index[T]) Cleanup

func (idx *Index[T]) Cleanup(ttl time.Duration) int

Cleanup removes deleted entries that are older than the specified TTL.

func (*Index[T]) Contains

func (idx *Index[T]) Contains(ip netip.Addr) bool

Contains checks if the given IP address is contained in any CIDR range.

func (*Index[T]) Lookup

func (idx *Index[T]) Lookup(ip netip.Addr) (*LookupResult[T], bool)

Lookup finds the most specific CIDR range containing the given IP address.

func (*Index[T]) MarkDeleted

func (idx *Index[T]) MarkDeleted(cidr netip.Prefix)

MarkDeleted marks the given CIDR range as deleted without removing it from the index.

func (*Index[T]) Rebuild

func (idx *Index[T]) Rebuild(entries []Entry[T]) error

Rebuild replaces all entries in the index with the provided entries.

func (*Index[T]) Remove

func (idx *Index[T]) Remove(cidr netip.Prefix) error

Remove deletes the given CIDR range from the index.

type LookupResult

type LookupResult[T any] struct {
	IP         netip.Addr
	Metadata   T
	ResolvedAt time.Time
}

Jump to

Keyboard shortcuts

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