Documentation
¶
Overview ¶
Package platform provides Platform types and the sharded routable view.
Index ¶
- Constants
- func CompileModelRegexFilters(platformID string, regexFilters []string) ([]*regexp.Regexp, error)
- func CompileRegexFilters(regexFilters []string) ([]*regexp.Regexp, error)
- func MatchRegionFilter(region string, filters []string) bool
- func NormalizeFixedAccountHeaders(raw string) (string, []string, error)
- func NormalizePlatformName(raw string) string
- func ValidatePlatformName(name string) error
- func ValidateRegionFilters(regionFilters []string) error
- type AllocationPolicy
- type GeoLookupFunc
- type GetEntryFunc
- type Platform
- type PoolRangeFunc
- type ReadOnlyView
- type ReverseProxyEmptyAccountBehavior
- type ReverseProxyMissAction
- type RoutableView
- func (rv *RoutableView) Add(h node.Hash)
- func (rv *RoutableView) Clear()
- func (rv *RoutableView) Contains(h node.Hash) bool
- func (rv *RoutableView) RandomPick(rng *rand.Rand) (node.Hash, bool)
- func (rv *RoutableView) Range(fn func(node.Hash) bool)
- func (rv *RoutableView) Remove(h node.Hash)
- func (rv *RoutableView) Size() int
Constants ¶
const DefaultPlatformID = "00000000-0000-0000-0000-000000000000"
DefaultPlatformID is the well-known UUID of the built-in Default platform.
const DefaultPlatformName = "Default"
DefaultPlatformName is the built-in platform name.
Variables ¶
This section is empty.
Functions ¶
func CompileModelRegexFilters ¶
CompileModelRegexFilters compiles regex filters from persisted model values.
func CompileRegexFilters ¶
CompileRegexFilters compiles regex filters in order.
func MatchRegionFilter ¶ added in v1.0.4
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 ¶
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
NormalizePlatformName trims leading/trailing spaces from platform name.
func ValidatePlatformName ¶ added in v1.0.0
ValidatePlatformName validates platform naming rules required by proxy auth parsing.
func ValidateRegionFilters ¶
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 ¶
GeoLookupFunc resolves an IP address to a lowercase ISO country code.
type GetEntryFunc ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (b ReverseProxyEmptyAccountBehavior) IsValid() bool
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 ¶
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.