allregions

package
v0.0.0-...-455eedf Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddrSet

type AddrSet map[*EdgeAddr]UsedBy

Region contains cloudflared edge addresses. The edge is partitioned into several regions for redundancy purposes.

func (AddrSet) AddrUsedBy

func (a AddrSet) AddrUsedBy(connID int) *EdgeAddr

AddrUsedBy finds the address used by the given connection in this region. Returns nil if the connection isn't using any IP.

func (AddrSet) AvailableAddrs

func (a AddrSet) AvailableAddrs() int

AvailableAddrs counts how many unused addresses this region contains.

func (AddrSet) GetAnyAddress

func (a AddrSet) GetAnyAddress() *EdgeAddr

GetAnyAddress returns an arbitrary address from the region.

func (AddrSet) GetUnusedIP

func (a AddrSet) GetUnusedIP(excluding *EdgeAddr) *EdgeAddr

GetUnusedIP returns a random unused address in this region. Returns nil if all addresses are in use.

func (AddrSet) GiveBack

func (a AddrSet) GiveBack(addr *EdgeAddr) (ok bool)

GiveBack the address, ensuring it is no longer assigned to an IP. Returns true if the address is in this region.

func (AddrSet) Use

func (a AddrSet) Use(addr *EdgeAddr, connID int)

Use the address, assigning it to a proxy connection.

type ConfigIPVersion

type ConfigIPVersion int8

ConfigIPVersion is the selection of IP versions from config

const (
	Auto     ConfigIPVersion = 2
	IPv4Only ConfigIPVersion = 4
	IPv6Only ConfigIPVersion = 6
)

func (ConfigIPVersion) String

func (c ConfigIPVersion) String() string

type EdgeAddr

type EdgeAddr struct {
	TCP       *net.TCPAddr
	UDP       *net.UDPAddr
	IPVersion EdgeIPVersion
}

EdgeAddr is a representation of possible ways to refer an edge location.

func ResolveAddrs

func ResolveAddrs(addrs []string, log *zerolog.Logger) (resolved []*EdgeAddr)

ResolveAddrs resolves TCP address given a list of addresses. Address can be a hostname, however, it will return at most one of the hostname's IP addresses.

type EdgeIPVersion

type EdgeIPVersion int8

IPVersion is the IP version of an EdgeAddr

const (
	V4 EdgeIPVersion = 4
	V6 EdgeIPVersion = 6
)

func (EdgeIPVersion) String

func (c EdgeIPVersion) String() string

String returns the enum's constant name.

type Region

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

Region contains cloudflared edge addresses. The edge is partitioned into several regions for redundancy purposes.

func NewRegion

func NewRegion(addrs []*EdgeAddr, overrideIPVersion ConfigIPVersion) Region

NewRegion creates a region with the given addresses, which are all unused.

func (*Region) AddrUsedBy

func (r *Region) AddrUsedBy(connID int) *EdgeAddr

AddrUsedBy finds the address used by the given connection in this region. Returns nil if the connection isn't using any IP.

func (Region) AssignAnyAddress

func (r Region) AssignAnyAddress(connID int, excluding *EdgeAddr) *EdgeAddr

AssignAnyAddress returns a random unused address in this region now assigned to the connID excluding the provided EdgeAddr. Returns nil if all addresses are in use for the region.

func (Region) AvailableAddrs

func (r Region) AvailableAddrs() int

AvailableAddrs counts how many unused addresses this region contains.

func (Region) GetAnyAddress

func (r Region) GetAnyAddress() *EdgeAddr

GetAnyAddress returns an arbitrary address from the region.

func (*Region) GiveBack

func (r *Region) GiveBack(addr *EdgeAddr, hasConnectivityError bool) (ok bool)

GiveBack the address, ensuring it is no longer assigned to an IP. Returns true if the address is in this region.

type Regions

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

Regions stores Cloudflare edge network IPs, partitioned into two regions. This is NOT thread-safe. Users of this package should use it with a lock.

func NewNoResolve

func NewNoResolve(addrs []*EdgeAddr) *Regions

NewNoResolve doesn't resolve the edge. Instead it just uses the given addresses. You probably only need this for testing.

func ResolveEdge

func ResolveEdge(log *zerolog.Logger, region string, overrideIPVersion ConfigIPVersion) (*Regions, error)

ResolveEdge resolves the Cloudflare edge, returning all regions discovered.

func StaticEdge

func StaticEdge(hostnames []string, log *zerolog.Logger) (*Regions, error)

StaticEdge creates a list of edge addresses from the list of hostnames. Mainly used for testing connectivity.

func (*Regions) AddrUsedBy

func (rs *Regions) AddrUsedBy(connID int) *EdgeAddr

AddrUsedBy finds the address used by the given connection. Returns nil if the connection isn't using an address.

func (*Regions) AvailableAddrs

func (rs *Regions) AvailableAddrs() int

AvailableAddrs returns how many edge addresses aren't used.

func (*Regions) GetAnyAddress

func (rs *Regions) GetAnyAddress() *EdgeAddr

GetAnyAddress returns an arbitrary address from the larger region.

func (*Regions) GetUnusedAddr

func (rs *Regions) GetUnusedAddr(excluding *EdgeAddr, connID int) *EdgeAddr

GetUnusedAddr gets an unused addr from the edge, excluding the given addr. Prefer to use addresses evenly across both regions.

func (*Regions) GiveBack

func (rs *Regions) GiveBack(addr *EdgeAddr, hasConnectivityError bool) bool

GiveBack the address so that other connections can use it. Returns true if the address is in this edge.

type UsedBy

type UsedBy struct {
	ConnID int
	Used   bool
}

func InUse

func InUse(connID int) UsedBy

func Unused

func Unused() UsedBy

Jump to

Keyboard shortcuts

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