nets

package
v0.2.2-dev.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package nets maps client addresses to ASNs inside the engine and aggregates connection events without retaining addresses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LookupAddr

func LookupAddr(a *Aggregator, addr net.Addr) uint32

LookupAddr resolves a peer address only while network collection is enabled. The address stays in the caller's scope.

Types

type Aggregator

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

Aggregator owns the active lookup table and one ten-minute window of network counts.

func New

func New(mode uint32) *Aggregator

New returns an empty aggregator. A nil aggregator is safe to pass to engine environments.

func (*Aggregator) Add

func (a *Aggregator) Add(inboundID string, asn uint32, event Event, credID, userID string)

Add records one connection event for an already-resolved ASN. The address must stay in the calling engine.

func (*Aggregator) AddN

func (a *Aggregator) AddN(inboundID string, asn uint32, event Event, credID, userID string, count uint32)

AddN records count connection-level observations for one already-resolved ASN.

func (*Aggregator) ClearTable

func (a *Aggregator) ClearTable()

ClearTable prevents further lookups until a matching table is loaded.

func (*Aggregator) Enabled

func (a *Aggregator) Enabled() bool

Enabled reports whether lookups and connection events can be counted.

func (*Aggregator) LoadedSHA

func (a *Aggregator) LoadedSHA() string

LoadedSHA returns the digest of the active table, or an empty string when none is loaded.

func (*Aggregator) Lookup

func (a *Aggregator) Lookup(addr netip.Addr) uint32

Lookup maps an address to its ASN. It does no work when the feature is off or no table is loaded.

func (*Aggregator) Mode

func (a *Aggregator) Mode() uint32

Mode returns 0 for a nil aggregator.

func (*Aggregator) SetMode

func (a *Aggregator) SetMode(mode uint32)

SetMode selects off, aggregate-only, or aggregate-plus-person rows. Turning off drops the current window.

func (*Aggregator) SetTable

func (a *Aggregator) SetTable(db *asndb.DB, sha string)

SetTable atomically replaces the address table and records the digest of its signed source file.

func (*Aggregator) Take

func (a *Aggregator) Take() ([]*pb.NetworkCounters, []*pb.PersonNetwork)

Take transfers the current window to the caller, applying k=3 folding and resetting the aggregator.

type Event

type Event uint8

Event is one connection-level observation. It contains no address data.

const (
	Attempt Event = iota + 1
	Unfinished
	Connect
	Broken
)

Jump to

Keyboard shortcuts

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