core

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NyProtoId = 8
)

Variables

This section is empty.

Functions

func AddMetric

func AddMetric(a, b uint32) uint32

func Bootstrap added in v0.3.3

func Bootstrap(centralPath, nodePath, logPath string, verbose bool)

Bootstrap manages the lifetime of the whole application. Nylon may be restarted multiple times, but Bootstrap is only called once.

func CleanupWireGuardDevice

func CleanupWireGuardDevice(s *state.State, n *Nylon) error

func ComputeRoutes

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

func ConfigureAlias

func ConfigureAlias(ifName string, prefix netip.Prefix) error

func ConfigureRoute

func ConfigureRoute(dev tun.Device, itfName string, route netip.Prefix, via netip.Addr) error

func Exec

func Exec(name string, arg ...string) error

func FetchConfig added in v0.3.3

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

fetches and unbundles central config from url

func FullTableUpdate

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

func Get

func Get[T state.NyModule](s *state.State) T

func HandleAckRetract

func HandleAckRetract(s *state.RouterState, r Router, neighId state.NodeId, svc state.ServiceId)

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 HandleNylonIPCGet

func HandleNylonIPCGet(s *state.State, rw *bufio.ReadWriter) error

func HandleSeqnoRequest

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

func IPCGet

func IPCGet(itf string) (string, error)

func InitInterface

func InitInterface(ifName string) error

func InitUAPI

func InitUAPI(e *state.Env, itfName string) (net.Listener, error)

func MainLoop

func MainLoop(s *state.State, dispatch <-chan func(*state.State) error) error

func NeighContainsFunc

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

func NewWireGuardDevice

func NewWireGuardDevice(s *state.State, 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 RunGC

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

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

func SolveStarvation

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

func Start

func Start(ccfg state.CentralCfg, ncfg state.LocalCfg, logLevel slog.Level, configPath string, aux map[string]any, initState **state.State) (bool, error)

func Stop

func Stop(s *state.State)

func UpdateWireGuard

func UpdateWireGuard(s *state.State) error

func VerifyForwarding

func VerifyForwarding() error

Types

type EpPing

type EpPing struct {
	TimeSent time.Time
}

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[state.ServiceId]struct{}
	Updates    map[state.ServiceId]*protocol.Ny_Update
}

type Nylon

type Nylon struct {
	PingBuf *ttlcache.Cache[uint64, EpPing]
	Device  *device.Device
	Tun     tun.Device
	// contains filtered or unexported fields
}

Nylon struct must be thread safe, since it can receive packets through PolyReceiver

func (*Nylon) Cleanup

func (n *Nylon) Cleanup(s *state.State) error

func (*Nylon) Init

func (n *Nylon) Init(s *state.State) error

func (*Nylon) InstallTC

func (n *Nylon) InstallTC(s *state.State)

func (*Nylon) Probe

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

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

type NylonRouter

type NylonRouter struct {
	*state.State
	LastStarvationRequest time.Time
	IO                    map[state.NodeId]*IOPending
	// ForwardTable contains the full routing table
	ForwardTable bart.Table[RouteTableEntry]
	// LoopbackTable contains only routes to services hosted on this node
	LoopbackTable bart.Table[RouteTableEntry]
}

func (*NylonRouter) BroadcastRequestSeqno

func (r *NylonRouter) BroadcastRequestSeqno(src state.Source, seqno uint16, hopCnt uint8)

func (*NylonRouter) BroadcastSendRouteUpdate

func (r *NylonRouter) BroadcastSendRouteUpdate(advRoute state.PubRoute)

func (*NylonRouter) Cleanup

func (r *NylonRouter) Cleanup(s *state.State) error

func (*NylonRouter) GcRouter

func (r *NylonRouter) GcRouter(s *state.State) error

func (*NylonRouter) GetNeighIO

func (r *NylonRouter) GetNeighIO(neigh state.NodeId) *IOPending

func (*NylonRouter) Init

func (r *NylonRouter) Init(s *state.State) error

func (*NylonRouter) Log

func (r *NylonRouter) Log(event RouterEvent, desc string, args ...any)

func (*NylonRouter) RequestSeqno

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

func (*NylonRouter) SendAckRetract

func (r *NylonRouter) SendAckRetract(neigh state.NodeId, svc state.ServiceId)

func (*NylonRouter) SendRouteUpdate

func (r *NylonRouter) SendRouteUpdate(neigh state.NodeId, advRoute state.PubRoute)

func (*NylonRouter) TableDeleteRoute

func (r *NylonRouter) TableDeleteRoute(svc state.ServiceId)

func (*NylonRouter) TableInsertRoute

func (r *NylonRouter) TableInsertRoute(svc state.ServiceId, route state.SelRoute)

func (*NylonRouter) UpdateNeighbour

func (r *NylonRouter) UpdateNeighbour(neigh state.NodeId)

type RouteTableEntry

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

type Router

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

Router is an interface that defines the underlying router operations

type RouterEvent

type RouterEvent int
const (
	InconsistentState RouterEvent = iota + 1000
	NoEpToNeighbour
)
const (
	RouteChanged RouterEvent = iota + 2000
	RouteExpired
	RoutePushed
	RouteStarved
)

info events

func (RouterEvent) String

func (i RouterEvent) String() string

Jump to

Keyboard shortcuts

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