platform

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package platform provides Platform types and the sharded routable view.

Index

Constants

View Source
const DefaultPlatformID = "00000000-0000-0000-0000-000000000000"

DefaultPlatformID is the well-known UUID of the built-in Default platform.

View Source
const DefaultPlatformName = "Default"

DefaultPlatformName is the built-in platform name.

Variables

This section is empty.

Functions

func CompileModelRegexFilters

func CompileModelRegexFilters(platformID string, regexFilters []string) ([]*regexp.Regexp, error)

CompileModelRegexFilters compiles regex filters from persisted model values.

func CompileRegexFilters

func CompileRegexFilters(regexFilters []string) ([]*regexp.Regexp, error)

CompileRegexFilters compiles regex filters in order.

func MatchRegionFilter added in v1.0.4

func MatchRegionFilter(region string, filters []string) bool

MatchRegionFilter applies include/exclude region filters. Positive entries (xx) build an include set; negative entries (!xx) build an exclude set. Unknown regions never match when region filters are configured. Final result is: region known AND (include empty OR region in include) AND (region not in exclude).

func NormalizeFixedAccountHeaders

func NormalizeFixedAccountHeaders(raw string) (string, []string, error)

NormalizeFixedAccountHeaders parses newline-delimited header names, canonicalizes them, removes duplicates (case-insensitive), and returns: 1) normalized newline-delimited value, 2) ordered header slice.

func NormalizePlatformName added in v1.0.0

func NormalizePlatformName(raw string) string

NormalizePlatformName trims leading/trailing spaces from platform name.

func ValidatePlatformName added in v1.0.0

func ValidatePlatformName(name string) error

ValidatePlatformName validates platform naming rules required by proxy auth parsing.

func ValidateRegionFilters

func ValidateRegionFilters(regionFilters []string) error

ValidateRegionFilters validates region filters against lowercase ISO alpha-2 format. Entries may optionally be prefixed with "!" to indicate negation (e.g. !hk).

Types

type AllocationPolicy

type AllocationPolicy string

AllocationPolicy controls how routing scores candidates for new leases.

const (
	AllocationPolicyBalanced         AllocationPolicy = "BALANCED"
	AllocationPolicyPreferLowLatency AllocationPolicy = "PREFER_LOW_LATENCY"
	AllocationPolicyPreferIdleIP     AllocationPolicy = "PREFER_IDLE_IP"
)

func ParseAllocationPolicy

func ParseAllocationPolicy(raw string) AllocationPolicy

ParseAllocationPolicy normalizes external string input into a supported policy. Unknown values fall back to BALANCED for compatibility.

func (AllocationPolicy) IsValid

func (p AllocationPolicy) IsValid() bool

type GeoLookupFunc

type GeoLookupFunc func(netip.Addr) string

GeoLookupFunc resolves an IP address to a lowercase ISO country code.

type GetEntryFunc

type GetEntryFunc func(node.Hash) (*node.NodeEntry, bool)

GetEntryFunc retrieves a node entry from the global pool by hash.

type Platform

type Platform struct {
	ID   string
	Name string

	// Filter configuration.
	RegexFilters  []*regexp.Regexp
	RegionFilters []string // lowercase ISO codes, supports negation "!xx"

	// Other config fields.
	StickyTTLNs                      int64
	ReverseProxyMissAction           string
	ReverseProxyEmptyAccountBehavior string
	ReverseProxyFixedAccountHeader   string
	ReverseProxyFixedAccountHeaders  []string
	AllocationPolicy                 AllocationPolicy
	// contains filtered or unexported fields
}

Platform represents a routing platform with its filtered routable view.

func BuildFromModel

func BuildFromModel(mp model.Platform) (*Platform, error)

BuildFromModel builds a runtime platform from a persisted model.Platform.

func NewConfiguredPlatform

func NewConfiguredPlatform(
	id, name string,
	regexFilters []*regexp.Regexp,
	regionFilters []string,
	stickyTTLNs int64,
	missAction string,
	emptyAccountBehavior string,
	fixedAccountHeader string,
	allocationPolicy string,
) *Platform

NewConfiguredPlatform builds a runtime platform with non-filter settings applied.

func NewPlatform

func NewPlatform(id, name string, regexFilters []*regexp.Regexp, regionFilters []string) *Platform

NewPlatform creates a Platform with an empty routable view.

func (*Platform) FullRebuild

func (p *Platform) FullRebuild(
	poolRange PoolRangeFunc,
	subLookup node.SubLookupFunc,
	geoLookup GeoLookupFunc,
)

FullRebuild clears the routable view and re-evaluates all nodes from the pool. Acquires viewMu — any concurrent NotifyDirty calls block until rebuild completes.

func (*Platform) NotifyDirty

func (p *Platform) NotifyDirty(
	h node.Hash,
	getEntry GetEntryFunc,
	subLookup node.SubLookupFunc,
	geoLookup GeoLookupFunc,
)

NotifyDirty re-evaluates a single node and adds/removes it from the view. Acquires viewMu — serialized with FullRebuild.

func (*Platform) View

func (p *Platform) View() ReadOnlyView

View returns the platform's routable view as a read-only interface. External callers cannot Add/Remove/Clear — only FullRebuild and NotifyDirty can mutate.

type PoolRangeFunc

type PoolRangeFunc func(fn func(node.Hash, *node.NodeEntry) bool)

PoolRangeFunc iterates all nodes in the global pool.

type ReadOnlyView

type ReadOnlyView interface {
	Contains(h node.Hash) bool
	Size() int
	RandomPick(rng *rand.Rand) (node.Hash, bool)
	Range(fn func(node.Hash) bool)
}

ReadOnlyView exposes only the read operations of RoutableView. This is the interface vended to external callers (data plane, API) so they cannot bypass FullRebuild/NotifyDirty to mutate the set.

type ReverseProxyEmptyAccountBehavior

type ReverseProxyEmptyAccountBehavior string

ReverseProxyEmptyAccountBehavior controls how reverse proxy resolves account when the incoming reverse path omits Account.

const (
	// ReverseProxyEmptyAccountBehaviorRandom keeps account empty and routes randomly.
	ReverseProxyEmptyAccountBehaviorRandom ReverseProxyEmptyAccountBehavior = "RANDOM"
	// ReverseProxyEmptyAccountBehaviorFixedHeader extracts account from one fixed request header.
	ReverseProxyEmptyAccountBehaviorFixedHeader ReverseProxyEmptyAccountBehavior = "FIXED_HEADER"
	// ReverseProxyEmptyAccountBehaviorAccountHeaderRule extracts account via account header rules.
	ReverseProxyEmptyAccountBehaviorAccountHeaderRule ReverseProxyEmptyAccountBehavior = "ACCOUNT_HEADER_RULE"
)

func (ReverseProxyEmptyAccountBehavior) IsValid

type ReverseProxyMissAction

type ReverseProxyMissAction string

ReverseProxyMissAction controls how reverse proxy handles requests whose account cannot be resolved from path/header match rules.

const (
	// ReverseProxyMissActionTreatAsEmpty keeps routing as empty-account flow when
	// account extraction fails.
	ReverseProxyMissActionTreatAsEmpty ReverseProxyMissAction = "TREAT_AS_EMPTY"
	ReverseProxyMissActionReject       ReverseProxyMissAction = "REJECT"
)

func NormalizeReverseProxyMissAction

func NormalizeReverseProxyMissAction(raw string) ReverseProxyMissAction

func (ReverseProxyMissAction) IsValid

func (a ReverseProxyMissAction) IsValid() bool

type RoutableView

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

RoutableView is a 64-shard concurrent set supporting O(1) random pick, O(1) add, O(1) remove, and O(1) contains.

func NewRoutableView

func NewRoutableView() *RoutableView

NewRoutableView creates an empty RoutableView.

func (*RoutableView) Add

func (rv *RoutableView) Add(h node.Hash)

Add inserts a hash into the view. No-op if already present.

func (*RoutableView) Clear

func (rv *RoutableView) Clear()

Clear removes all entries from all shards.

func (*RoutableView) Contains

func (rv *RoutableView) Contains(h node.Hash) bool

Contains returns true if the hash is in the view.

func (*RoutableView) RandomPick

func (rv *RoutableView) RandomPick(rng *rand.Rand) (node.Hash, bool)

RandomPick selects a random hash from the view. Returns ok=false if the view is empty.

func (*RoutableView) Range

func (rv *RoutableView) Range(fn func(node.Hash) bool)

Range calls fn for each hash in the view. If fn returns false, iteration stops.

func (*RoutableView) Remove

func (rv *RoutableView) Remove(h node.Hash)

Remove deletes a hash from the view. No-op if absent. Uses swap-last-remove for O(1).

func (*RoutableView) Size

func (rv *RoutableView) Size() int

Size returns the total number of hashes across all shards.

Jump to

Keyboard shortcuts

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