Documentation
¶
Overview ¶
Package endpointselect provides endpoint selection strategies for tunnel connections.
Index ¶
Constants ¶
const ( // DefaultProbeTimeout is the default timeout for each endpoint probe. DefaultProbeTimeout = 3 * time.Second // DefaultMaxConcurrent is the default maximum number of concurrent probes. DefaultMaxConcurrent = 10 // DefaultPingsPerEndpoint is the default number of ping requests per endpoint. DefaultPingsPerEndpoint = 3 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LatencySelector ¶
type LatencySelector struct {
// contains filtered or unexported fields
}
LatencySelector selects endpoints based on QUIC handshake latency.
func NewLatencySelector ¶
func NewLatencySelector(opts ...Option) *LatencySelector
NewLatencySelector creates a new LatencySelector.
func (*LatencySelector) Select ¶
Select returns the endpoint with the lowest latency. It cancels remaining probes as soon as one endpoint responds: only the single winner is consumed, so waiting out unreachable endpoints' timeouts would just delay startup.
func (*LatencySelector) SelectWithResults ¶
func (s *LatencySelector) SelectWithResults(ctx context.Context, endpoints []string) (string, []ProbeResult, error)
SelectWithResults returns the endpoint with the lowest latency along with all probe results. Unlike Select, every probe runs to completion: callers of this method rank the full endpoint set, and an early cancel would corrupt the losers' measurements (a probe cut off after one ping reports handshake time, and one cut off before any ping drops out of the ranking entirely).
type Option ¶
type Option func(*latencyOptions)
Option configures a LatencySelector.
func WithInsecureSkipVerify ¶
WithInsecureSkipVerify sets whether to skip TLS certificate verification.
func WithMaxConcurrent ¶
WithMaxConcurrent sets the maximum number of concurrent probes.
func WithPingsPerEndpoint ¶
WithPingsPerEndpoint sets the number of ping requests per endpoint. The latencies are aggregated using a trimmed mean (removing outliers).
func WithProbeTimeout ¶
WithProbeTimeout sets the timeout for each endpoint probe.
type ProbeResult ¶
type ProbeResult struct {
// Addr is the endpoint address that was probed.
Addr string
// Latency is the measured latency for the endpoint.
// Zero if the probe failed.
Latency time.Duration
// Error contains any error that occurred during probing.
Error error
// ProbedAt is the time when the probe was performed.
ProbedAt time.Time
}
ProbeResult contains the result of probing a single endpoint.
type RandomSelector ¶
type RandomSelector struct{}
RandomSelector selects a random endpoint from the list.
func NewRandomSelector ¶
func NewRandomSelector() *RandomSelector
NewRandomSelector creates a new RandomSelector.
func (*RandomSelector) SelectWithResults ¶
func (s *RandomSelector) SelectWithResults(ctx context.Context, endpoints []string) (string, []ProbeResult, error)
SelectWithResults returns a random endpoint along with a single result entry.
type SelectionStrategy ¶
type SelectionStrategy string
SelectionStrategy defines the type for endpoint selection strategies.
const ( // StrategyLatency selects the endpoint with the lowest latency. StrategyLatency SelectionStrategy = "latency" // StrategyRandom selects a random endpoint. StrategyRandom SelectionStrategy = "random" )
func ParseStrategy ¶
func ParseStrategy(s string) (SelectionStrategy, error)
ParseStrategy parses a string into a SelectionStrategy.
type Selector ¶
type Selector interface {
// Select returns the best endpoint from the given list based on
// the selection strategy. Returns an error if no endpoint could be selected.
Select(ctx context.Context, endpoints []string) (string, error)
// SelectWithResults returns the best endpoint along with all probe results.
// This is useful for logging and debugging.
SelectWithResults(ctx context.Context, endpoints []string) (string, []ProbeResult, error)
}
Selector is the interface for endpoint selection strategies.
func NewSelector ¶
func NewSelector(strategy SelectionStrategy, opts ...Option) (Selector, error)
NewSelector creates a new Selector based on the given strategy.