network

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialer

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

Dialer enforces policy before opening outbound connections.

func NewDialer

func NewDialer(cfg DialerConfig) *Dialer

func (*Dialer) DialContext

func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)

type DialerConfig

type DialerConfig struct {
	Policy   Policy
	Resolver Resolver
	Base     *net.Dialer
	Meter    *Meter
}

type Limits

type Limits struct {
	MaxRequests      int
	MaxBytesSent     int64
	MaxBytesReceived int64
	MaxRuntime       time.Duration
}

Limits defines optional per-session network caps.

type Meter

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

Meter tracks and enforces network usage limits.

func NewMeter

func NewMeter(limits Limits) *Meter

func NewMeterFromUsage

func NewMeterFromUsage(limits Limits, usage Usage) *Meter

func (*Meter) Snapshot

func (m *Meter) Snapshot() Usage

type Mode

type Mode string

Mode controls outbound networking behavior.

const (
	// ModeOff blocks all outbound networking.
	ModeOff Mode = "off"
	// ModeAllowlist permits outbound networking only to allowlisted destinations.
	ModeAllowlist Mode = "allowlist"
	// ModeFull permits outbound networking without destination restrictions.
	ModeFull Mode = "full"
)

type Policy

type Policy struct {
	Mode              Mode
	AllowDomains      []string
	AllowCIDRs        []netip.Prefix
	AllowPorts        map[int]struct{}
	DenyPrivateRanges bool
}

Policy defines destination-level networking restrictions.

func DefaultPolicy

func DefaultPolicy() Policy

DefaultPolicy returns a permissive policy for backward compatibility.

func (Policy) EvaluateAddress

func (p Policy) EvaluateAddress(ctx context.Context, address string, resolver Resolver) (netip.Addr, int, string, error)

EvaluateAddress validates destination host:port against policy and returns the allowed resolved IP to dial.

type Resolver

type Resolver interface {
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

Resolver resolves hostnames to IP addresses.

type Usage

type Usage struct {
	Requests      int
	BytesSent     int64
	BytesReceived int64
	Runtime       time.Duration
}

Usage captures consumed network resources.

Jump to

Keyboard shortcuts

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