routing

package
v0.2.9-beta.10 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package routing implements the beacon-registration and NAT punch-coordination handlers for the registry server.

The package owns the beacon cluster state (registration, TTL-based listing) and the punch endpoint lookup. It exposes a Store that holds the beacon map and the PunchBackend interface that the *server.Server satisfies for the punch operation.

Index

Constants

View Source
const BeaconRegisterCooldown = 10 * time.Second

BeaconRegisterCooldown is the minimum interval between successive HandleBeaconRegister calls for the same beacon ID. This prevents an attacker (even an admin-token-armed one) from churning through many distinct beacon IDs faster than one per cooldown window.

View Source
const BeaconTTL = 60 * time.Second

BeaconTTL is how long a beacon registration is valid without re-register.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeaconEntry

type BeaconEntry struct {
	ID       uint32
	Addr     string
	LastSeen time.Time
}

type PunchBackend

type PunchBackend interface {
	// NodePubKeyAndAdminToken returns false if the node does not exist.
	NodePubKeyAndAdminToken(nodeID uint32) (pubKey []byte, adminToken string, ok bool)

	// VerifyPunchSignature accepts either an Ed25519 signature or an admin-token fallback.
	VerifyPunchSignature(pubKey []byte, adminToken string, msg map[string]interface{}, challenge string) error

	// NodeAddrs returns false for addrA or addrB when the respective node is absent.
	NodeAddrs(nodeA, nodeB uint32) (addrA string, okA bool, addrB string, okB bool)

	IsTrusted(nodeA, nodeB uint32) bool
	StrictDirectoryAuth() bool
}

PunchBackend is satisfied by *server.Server and provides the node address lookups that HandlePunch needs. The interface is intentionally narrow: only the three operations the punch handler requires are exposed.

type Store

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

Store holds the beacon cluster state and implements the three beacon/punch routing handlers.

func NewStore

func NewStore(backend PunchBackend) *Store

NewStore creates a Store with a real-time clock. backend may be nil if HandlePunch will never be called (e.g. in tests that only exercise beacon registration/listing).

func (*Store) HandleBeaconList

func (st *Store) HandleBeaconList() (map[string]interface{}, error)

HandleBeaconList returns all known (non-expired) beacon instances.

func (*Store) HandleBeaconRegister

func (st *Store) HandleBeaconRegister(msg map[string]interface{}) (map[string]interface{}, error)

HandleBeaconRegister registers or refreshes a beacon instance for peer discovery.

func (*Store) HandlePunch

func (st *Store) HandlePunch(msg map[string]interface{}) (map[string]interface{}, error)

func (*Store) ReapStale

func (st *Store) ReapStale()

ReapStale deletes beacons whose LastSeen is older than BeaconTTL. Called by the server's background reap loop.

func (*Store) SetClock

func (st *Store) SetClock(fn func() time.Time)

SetClock replaces the time source (for deterministic testing).

Jump to

Keyboard shortcuts

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