ipmap

package
v0.0.0-...-bcff533 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IPMap

type IPMap interface {
	IPMapper
	// Resolves hostname and adds the resulting IPs to its IPSet.
	Add(hostOrIP string) *IPSet
	// Get creates an IPSet for this hostname populated with the IPs
	// discovered by resolving it. Subsequent calls to Get return the
	// same IPSet. Never returns nil.
	Get(hostOrIP string) *IPSet
	// GetAny creates an IPSet for this hostname, which may be empty.
	// Subsequent calls to GetAny return the same IPSet. Never returns nil.
	GetAny(hostOrIP string) *IPSet
	// MakeIPSet creates an IPSet for this hostname bootstrapped with given IPs
	// or IP:Ports. Subsequent calls to MakeIPSet return a new, overriden IPSet.
	MakeIPSet(hostOrIP string, ipps []string, typ IPSetType) *IPSet
	// With sets the default resolver to use for hostname resolution.
	With(r IPMapper)
	// Clear removes all IPSets from the map.
	Clear()
}

IPMap maps hostnames to IPSets.

func NewIPMap

func NewIPMap() IPMap

func NewIPMapFor

func NewIPMapFor(r IPMapper) IPMap

NewIPMapFor returns a fresh IPMap with r as its nameserver.

type IPMapper

type IPMapper interface {
	// net.Resolver does not impl Lookup
	// IPMapper must confirm to net.Resolver
	// Lookup(q []byte) ([]byte, error)
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}

IPMapper is an interface for resolving hostnames to IP addresses. For internal used by firestack.

type IPSet

type IPSet struct {
	sync.RWMutex // Protects this struct.
	// contains filtered or unexported fields
}

IPSet represents an unordered collection of IP addresses for a single host. One IP can be marked as confirmed to be working correctly.

func (*IPSet) Addrs

func (s *IPSet) Addrs() []netip.Addr

Addrs returns a copy of the IP set as a slice in random order. The slice is owned by the caller, but the elements are owned by the set.

func (*IPSet) Confirm

func (s *IPSet) Confirm(ip netip.Addr)

Confirm marks ip as the confirmed address.

func (*IPSet) Confirmed

func (s *IPSet) Confirmed() netip.Addr

Confirmed returns the confirmed IP address, or zeroaddr if there is no such address.

func (*IPSet) Disconfirm

func (s *IPSet) Disconfirm(ip netip.Addr) (ok bool)

Disconfirm sets the confirmed address to zeroaddr if the current confirmed address is the provided ip.

func (*IPSet) Empty

func (s *IPSet) Empty() bool

Empty reports whether the set is empty.

func (*IPSet) Protected

func (s *IPSet) Protected() bool

func (*IPSet) Seed

func (s *IPSet) Seed() []string

Returns bootstrap ips or ip:ports.

func (*IPSet) Size

func (s *IPSet) Size() int

type IPSetType

type IPSetType int

Type of IPSet.

const (
	Protected IPSetType = iota
	Regular
	AutoType
)

func (IPSetType) String

func (h IPSetType) String() string

Jump to

Keyboard shortcuts

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