resolver

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package resolver performs concurrent reverse DNS lookups with a per-run cache so the same IP is not resolved twice. Lookups are capped by their own timeout so a slow PTR server can't stall the scan pipeline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache resolves IPs to hostnames with dedupe and a single-flight-style barrier so concurrent callers for the same IP share one lookup.

func New

func New(opts Options) *Cache

New returns an empty cache.

func (*Cache) Lookup

func (c *Cache) Lookup(ctx context.Context, addr netip.Addr) (string, error)

Lookup returns the cached hostname for addr, performing a lookup if needed. Returns ("", nil) when the reverse lookup succeeded but returned no name, and ("", err) when the lookup itself failed. Callers typically just want the string, in which case they can ignore the error.

type LookupFunc

type LookupFunc func(ctx context.Context, addr netip.Addr) (string, error)

LookupFunc is the injectable resolver. Returning "" means "no name"; returning an error is distinct and is recorded for observability but otherwise treated the same as "no name" (callers render the IP).

type Options

type Options struct {
	// Lookup does the PTR query. If nil, net.DefaultResolver.LookupAddr
	// is used.
	Lookup LookupFunc
	// Timeout per individual lookup. 0 → 2s.
	Timeout time.Duration
}

Options tunes the cache.

Jump to

Keyboard shortcuts

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