traffic

package
v1.100.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package traffic contains helpers for evaluating traffic steering scores and picking appropriate nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NodeHasher

type NodeHasher func(tailcfg.NodeID) uint64

NodeHasher returns a 64-bit hash of a node ID.

func MakeRendezvousHasher

func MakeRendezvousHasher(seed tailcfg.NodeID) NodeHasher

MakeRendezvousHasher returns a function that hashes a node ID to a uint64. https://en.wikipedia.org/wiki/Rendezvous_hashing

func (NodeHasher) Compare

func (h NodeHasher) Compare(a, b tailcfg.NodeID) int

Compare compares the node ID hashes of peers a and b, using the same convention as cmp.Compare. Since h is seeded with the current node’s ID, the ordering between a and b will remain stable for this node; but the order may flip for when h is seeded for another node. This function should return zero, if and only if a and b have the same node ID.

type Score

type Score int

Score is a node’s traffic score, where any int could be a valid score. A higher traffic score suggests that the client should prefer that peer over one with a lower traffic score.

type Scores

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

Scores is a memoization cache for the traffic scores of the current node’s peers.

func ScoresFor

func ScoresFor(self tailcfg.NodeID, peers []tailcfg.NodeView) Scores

ScoresFor returns a new Scores cache for the current node’s ID, after scoring the peer nodes and adding these scores to the cache.

func (Scores) All

func (ss Scores) All() iter.Seq2[tailcfg.NodeID, Score]

All returns an iterator over the scores for every peer in the cache. The iteration order is not specified and is not guaranteed to be the same from one call to the next.

func (Scores) IsValid

func (ss Scores) IsValid() bool

IsValid reports whether ss has been initialized with the current node ID.

func (*Scores) Score

func (ss *Scores) Score(n tailcfg.NodeView) Score

Score scores the given peer node and returns it after adding the score to the cache.

func (*Scores) ScorePeers

func (ss *Scores) ScorePeers(peers []tailcfg.NodeView)

ScorePeers scores the peer nodes and adds these scores to the cache.

func (Scores) SortNodes

func (ss Scores) SortNodes(nodes []tailcfg.NodeView)

SortNodes sorts the slice of nodes in descending order of Scores.Score, using rendezvous hashing to break ties when both nodes have the same score. After sorting, the zeroth element is the preferred node.

Jump to

Keyboard shortcuts

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