core

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NyProtoId = 8
)

Variables

View Source
var ErrFutureAlreadyAwaited = errors.New("future already awaited")

Functions

func AddMetric

func AddMetric(a, b uint32) uint32

func AwaitAll added in v0.4.4

func AwaitAll[T any](ctx context.Context, futures []Future[T]) ([]T, error)

AwaitAll blocks until every input future completes or ctx is canceled. Values are returned in the same order as the input slice. AwaitAll awaits and consumes every completed input future in order.

func Bootstrap added in v0.3.3

func Bootstrap(centralPath, nodePath, logPath string, verbose bool, opts state.NylonOptions)

Bootstrap provides startup logic in a real environment

func CleanupWireGuardDevice

func CleanupWireGuardDevice(n *Nylon) error

func ComputeRoutes

func ComputeRoutes(s *state.RouterState, r Router)

func ConfigureAlias

func ConfigureAlias(logger *slog.Logger, ifName string, addr netip.Addr) error

func ConfigureRoute

func ConfigureRoute(logger *slog.Logger, dev tun.Device, itfName string, route netip.Prefix) error

func Exec

func Exec(logger *slog.Logger, name string, arg ...string) error

func ExecSplit added in v0.4.0

func ExecSplit(logger *slog.Logger, command string) error

func FetchConfig added in v0.3.3

func FetchConfig(repoStr string, key state.NyPublicKey, maxSize int64) (*state.CentralCfg, error)

fetches and unbundles central config from url

func FullTableUpdate

func FullTableUpdate(s *state.RouterState, r Router)

func HandleAckRetract

func HandleAckRetract(s *state.RouterState, r Router, neighId state.NodeId, prefix netip.Prefix)

func HandleNeighbourUpdate

func HandleNeighbourUpdate(s *state.RouterState, r Router, neighId state.NodeId, adv state.PubRoute)

this function should also be called on every probe

func HandleNylonIPC added in v0.4.0

func HandleNylonIPC(n *Nylon, rw *bufio.ReadWriter) error

func HandleSeqnoRequest

func HandleSeqnoRequest(s *state.RouterState, r Router, fromNeigh state.NodeId, src state.Source, reqSeqno uint16, hopCnt uint8)

func InitInterface

func InitInterface(logger *slog.Logger, ifName string) error

func InitUAPI

func InitUAPI(logger *slog.Logger, itfName string) (net.Listener, error)

func IsStrictlyBetter added in v0.4.0

func IsStrictlyBetter(curRoute state.SelRoute, newRoute state.SelRoute) bool

func NeighContainsFunc

func NeighContainsFunc(s *state.RouterState, f func(neigh state.NodeId, route state.NeighRoute) bool) bool

func NewWireGuardDevice

func NewWireGuardDevice(n *Nylon) (dev *device.Device, tunDevice tun.Device, realItf string, err error)

func PushFullTable

func PushFullTable(s *state.RouterState, r Router, neigh state.NodeId)

func RemoveAlias added in v0.4.0

func RemoveAlias(logger *slog.Logger, ifName string, addr netip.Addr) error

func RemoveRoute added in v0.4.0

func RemoveRoute(logger *slog.Logger, dev tun.Device, itfName string, route netip.Prefix) error

func RunGC

func RunGC(s *state.RouterState, r Router)

func SendIPCRequest added in v0.4.0

func SendIPCRequest(itf string, req *protocol.IpcRequest) (*protocol.IpcResponse, error)

func SendIPCStream added in v0.4.0

func SendIPCStream(itf string, req *protocol.IpcRequest, handler func(*protocol.IpcResponse) error) error

func SeqnoGe

func SeqnoGe(a, b uint16) bool

func SeqnoGt

func SeqnoGt(a, b uint16) bool

func SeqnoLe

func SeqnoLe(a, b uint16) bool

func SeqnoLt

func SeqnoLt(a, b uint16) bool

func ShouldSwitch

func ShouldSwitch(curRoute state.SelRoute, newRoute state.SelRoute, tunable *state.RouterTunables) bool

func SolveStarvation

func SolveStarvation(router *state.RouterState, r Router)

Types

type AppliedSystemState added in v0.4.0

type AppliedSystemState struct {
	Routes  []netip.Prefix
	Aliases []netip.Addr
	Peers   map[state.NodeId]state.NyPublicKey
}

type ApplyResult added in v0.4.0

type ApplyResult string
const (
	ApplyNoop            ApplyResult = "noop"
	ApplyApplied         ApplyResult = "applied"
	ApplyRejected        ApplyResult = "rejected"
	ApplyRestartRequired ApplyResult = "restart_required"
)

type EpPing

type EpPing struct {
	TimeSent time.Time
	Peer     state.NodeId
	Complete func(protocol.EndpointProbeStatus, time.Duration)
}

type ForwardingTables added in v0.4.5

type ForwardingTables struct {
	// Forward contains the full routing table.
	Forward *bart.Table[RouteTableEntry]
	// Exit contains only routes to services hosted on this node.
	Exit *bart.Table[RouteTableEntry]
}

type Future added in v0.4.4

type Future[T any] struct {
	// contains filtered or unexported fields
}

Future is a single-assignment async result.

func NewDispatchFuture added in v0.4.4

func NewDispatchFuture[T any](n *Nylon, fun func() (T, error)) Future[T]

func NewFuture added in v0.4.4

func NewFuture[T any]() (Future[T], func(T, error))

NewFuture returns a Future and its completion function. Only the first completion call is used; later calls are ignored.

func (Future[T]) Await added in v0.4.4

func (f Future[T]) Await(ctx context.Context) (T, error)

Await blocks until the future completes or ctx is canceled. Only one Await call may wait for or consume a result at a time; concurrent calls and calls after the result has been consumed return ErrFutureAlreadyAwaited.

func (Future[T]) Done added in v0.4.4

func (f Future[T]) Done() <-chan struct{}

Done returns a receive-only readiness channel for use in select statements. Receive from Done, then call Await to consume the result.

type IOPending

type IOPending struct {
	// SeqnoReq values represent a pair of (seqno, hop count)
	SeqnoReq   map[state.Source]state.Pair[uint16, uint8]
	SeqnoDedup *ttlcache.Cache[state.Source, uint16]
	Acks       map[netip.Prefix]struct{}
	Updates    map[netip.Prefix]*protocol.Ny_Update
}

type Nylon

type Nylon struct {
	Trace *NylonTrace

	// tunables and options
	state.RouterTunables
	state.NylonOptions

	// state
	state.ConfigState
	RouterState      *state.RouterState
	AppliedSystem    AppliedSystemState
	PingBuf          *ttlcache.Cache[uint64, EpPing]
	PeerMap          atomic.Pointer[map[state.NyPublicKey]state.NodeId]
	DNSResolver      *state.DNSResolver
	EndpointResolver *state.EndpointResolver

	// runtime/application
	DispatchChannel chan func() error
	Log             *slog.Logger
	ConfigPath      string

	// resources
	Tun tun.Device

	Interface string
	Device    *device.Device

	// only used for debugging & tests
	AuxConfig map[string]any

	// lifecycle
	Context context.Context
	Cancel  context.CancelCauseFunc
	// contains filtered or unexported fields
}

func NewNylon added in v0.4.0

func NewNylon(ccfg state.CentralCfg, ncfg state.LocalCfg, logLevel slog.Level, configPath string, aux map[string]any, opts state.NylonOptions, tunables *state.RouterTunables) (*Nylon, error)

func (*Nylon) ApplyCentralConfig added in v0.4.0

func (n *Nylon) ApplyCentralConfig(cfg *state.CentralCfg) (ApplyResult, error)

func (*Nylon) BroadcastRequestSeqno added in v0.4.0

func (n *Nylon) BroadcastRequestSeqno(src state.Source, seqno uint16, hopCnt uint8)

func (*Nylon) BroadcastSendRouteUpdate added in v0.4.0

func (n *Nylon) BroadcastSendRouteUpdate(advRoute state.PubRoute)

func (*Nylon) Cleanup

func (n *Nylon) Cleanup() error

func (*Nylon) CleanupRouter added in v0.4.0

func (n *Nylon) CleanupRouter() error

func (*Nylon) ComputeSysRouteTable added in v0.4.0

func (n *Nylon) ComputeSysRouteTable() []netip.Prefix

ComputeSysRouteTable computes: computed = prefixes - (((n.CentralCfg.ExcludeIPs U selected self prefixes) - n.LocalCfg.UnexcludeIPs) U n.LocalCfg.ExcludeIPs)

func (*Nylon) Dispatch added in v0.4.0

func (n *Nylon) Dispatch(fun func() error)

Dispatch Dispatches the function to run on the main thread without waiting for it to complete

func (*Nylon) GcRouter added in v0.4.0

func (n *Nylon) GcRouter() error

func (*Nylon) GetNeighIO added in v0.4.0

func (n *Nylon) GetNeighIO(neigh state.NodeId) *IOPending

func (*Nylon) Init

func (n *Nylon) Init() error

func (*Nylon) InitRouter added in v0.4.0

func (n *Nylon) InitRouter() error

func (*Nylon) InstallTC

func (n *Nylon) InstallTC()

func (*Nylon) Probe

func (n *Nylon) Probe(node state.NodeId, ep *state.NylonEndpoint) error

func (*Nylon) RepeatTask added in v0.4.0

func (n *Nylon) RepeatTask(fun func() error, delay time.Duration)

func (*Nylon) RequestSeqno added in v0.4.0

func (n *Nylon) RequestSeqno(neigh state.NodeId, src state.Source, seqno uint16, hopCnt uint8)

func (*Nylon) RouterEvent added in v0.4.0

func (n *Nylon) RouterEvent(event string, desc string, args ...any)

func (*Nylon) ScheduleTask added in v0.4.0

func (n *Nylon) ScheduleTask(fun func() error, delay time.Duration)

func (*Nylon) SendAckRetract added in v0.4.0

func (n *Nylon) SendAckRetract(neigh state.NodeId, prefix netip.Prefix)

func (*Nylon) SendNylon

func (n *Nylon) SendNylon(pkt *protocol.Ny, endpoint conn.Endpoint, peer *device.Peer) error

func (*Nylon) SendNylonBundle

func (n *Nylon) SendNylonBundle(pkt *protocol.TransportBundle, endpoint conn.Endpoint, peer *device.Peer) error

func (*Nylon) SendRouteUpdate added in v0.4.0

func (n *Nylon) SendRouteUpdate(neigh state.NodeId, advRoute state.PubRoute)

func (*Nylon) Start added in v0.4.0

func (n *Nylon) Start() error

func (*Nylon) Stop added in v0.4.0

func (n *Nylon) Stop()

func (*Nylon) SyncApplicationState added in v0.4.5

func (n *Nylon) SyncApplicationState() error

func (*Nylon) SyncSystemState added in v0.4.0

func (n *Nylon) SyncSystemState() error

func (*Nylon) SyncWireGuard added in v0.4.0

func (n *Nylon) SyncWireGuard() error

func (*Nylon) TableDeleteRoute added in v0.4.0

func (n *Nylon) TableDeleteRoute(prefix netip.Prefix)

func (*Nylon) TableInsertRoute added in v0.4.0

func (n *Nylon) TableInsertRoute(prefix netip.Prefix, route state.SelRoute)

func (*Nylon) UpdateNeighbour added in v0.4.0

func (n *Nylon) UpdateNeighbour(neigh state.NodeId)

type NylonTrace added in v0.4.0

type NylonTrace struct {
	broadcast.Broadcaster
}

func (*NylonTrace) Cleanup added in v0.4.0

func (n *NylonTrace) Cleanup() error

func (*NylonTrace) Init added in v0.4.0

func (n *NylonTrace) Init(core *Nylon) error

type RouteTableEntry

type RouteTableEntry struct {
	Nh        state.NodeId
	Peer      *device.Peer
	Blackhole bool
}

type Router

type Router interface {
	SendRouteUpdate(neigh state.NodeId, advRoute state.PubRoute)
	SendAckRetract(neigh state.NodeId, prefix netip.Prefix)
	BroadcastSendRouteUpdate(advRoute state.PubRoute)
	RequestSeqno(neigh state.NodeId, src state.Source, seqno uint16, hopCnt uint8)
	BroadcastRequestSeqno(src state.Source, seqno uint16, hopCnt uint8)
	TableInsertRoute(prefix netip.Prefix, route state.SelRoute)
	TableDeleteRoute(prefix netip.Prefix)
	RouterEvent(event string, desc string, args ...any)
}

Router is an interface that defines the underlying router operations

Jump to

Keyboard shortcuts

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