asndb

package
v0.2.0-dev.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 16 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 asndb reads, writes and looks up the release-pinned autonomous-system table.

Index

Constants

View Source
const (
	MinReleaseIPv4Ranges = 300_000
	MinReleaseASNs       = 50_000
	MaxReleaseAge        = 45 * 24 * time.Hour
)

Variables

This section is empty.

Functions

func AppendTSV

func AppendTSV(r io.Reader, family Family, table *Table) error

AppendTSV reads the five-column ip2asn TSV format (start, end, ASN, country, description), transparently accepting either plain text or gzip. Each source must be sorted and non-overlapping.

func ValidateRelease

func ValidateRelease(db *DB, now time.Time) error

ValidateRelease applies the minimum-size and freshness checks used by generation and release signing.

func ValidateReleaseWith

func ValidateReleaseWith(db *DB, now time.Time, limits ReleaseLimits) error

ValidateReleaseWith applies the same checks with an explicit policy.

func Write

func Write(w io.Writer, table Table) error

Write validates table, inserts ASN 0 for gaps, and writes a deterministic gzip stream.

Types

type DB

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

DB retains the uncompressed table so Lookup can binary-search its pointer-free sections without allocating.

func Parse

func Parse(r io.Reader) (*DB, error)

Parse reads and strictly validates a gzip-compressed table.

func (*DB) ASNCount

func (db *DB) ASNCount() int

ASNCount returns the number of operator records.

func (*DB) Built

func (db *DB) Built() time.Time

Built returns the source timestamp stored in the table header.

func (*DB) ContentHash

func (db *DB) ContentHash() [32]byte

ContentHash is SHA-256 of the canonical uncompressed table payload.

func (*DB) IPv4RangeCount

func (db *DB) IPv4RangeCount() int

IPv4RangeCount returns the number of mapped IPv4 intervals, excluding ASN 0 gap entries.

func (*DB) IPv6RangeCount

func (db *DB) IPv6RangeCount() int

IPv6RangeCount returns the number of mapped IPv6 /64 intervals, excluding ASN 0 gap entries.

func (*DB) Lookup

func (db *DB) Lookup(addr netip.Addr) uint32

Lookup returns the ASN for addr, or 0 for a gap, invalid address, or unsupported family.

func (*DB) Name

func (db *DB) Name(asn uint32) (country, name string, ok bool)

Name returns the country and operator name for asn. The strings are allocated only on this metadata path.

type Family

type Family uint8

Family selects the address family in an ip2asn TSV file.

const (
	FamilyIPv4 Family = iota + 1
	FamilyIPv6
)

type IPv4Range

type IPv4Range struct {
	Start uint32
	End   uint32
	ASN   uint32
}

IPv4Range and IPv6Range use inclusive endpoints. IPv6 ranges are indexed at /64 granularity.

type IPv6Range

type IPv6Range struct {
	Start uint64
	End   uint64
	ASN   uint32
}

type Operator

type Operator struct {
	ASN     uint32
	Country string
	Name    string
}

Operator names one autonomous system. Country is an ISO 3166-1 alpha-2 code, or empty if unknown.

type ReleaseLimits

type ReleaseLimits struct {
	MinIPv4Ranges int
	MinASNs       int
	MaxAge        time.Duration
}

ReleaseLimits makes the release sanity policy explicit and lets tests exercise its boundaries with small tables.

func DefaultReleaseLimits

func DefaultReleaseLimits() ReleaseLimits

DefaultReleaseLimits returns the minimum production quality policy.

type Table

type Table struct {
	Built time.Time
	IPv4  []IPv4Range
	IPv6  []IPv6Range
	ASNs  []Operator
	// contains filtered or unexported fields
}

Table is the uncompressed input to Write. Ranges must be sorted and non-overlapping; gaps are added by Write.

Jump to

Keyboard shortcuts

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