routing

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package routing implements the beacon-registration and NAT punch-coordination handlers extracted from the registry server (R1.4 decomposition).

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 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)
}

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