common

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: Apache-2.0 Copyright (c) 2024-2026 Quad4.io

SPDX-License-Identifier: Apache-2.0 Copyright (c) 2024-2026 Quad4.io

SPDX-License-Identifier: Apache-2.0 Copyright (c) 2024-2026 Quad4.io

SPDX-License-Identifier: Apache-2.0 Copyright (c) 2024-2026 Quad4.io

Index

Constants

View Source
const (
	ResourceStatusPending   = 0x00
	ResourceStatusActive    = 0x01
	ResourceStatusComplete  = 0x02
	ResourceStatusFailed    = 0x03
	ResourceStatusCancelled = 0x04
)

Resource status codes for top-level resource transfers.

View Source
const (
	LinkStatusPending = 0x00
	LinkStatusActive  = 0x01
	LinkStatusClosed  = 0x02
	LinkStatusFailed  = 0x03
)

Link status codes.

View Source
const (
	In  = 0x01
	Out = 0x02
)

Direction bit flags used by destinations and interfaces.

View Source
const (
	DefaultMTU     = 1500
	MaxPacketSize  = 65535
	BitrateMinimum = 5
)

Default sizing and rate-limit values.

View Source
const (
	EstablishTimeout  = 6
	KeepaliveInterval = 360
	StaleTime         = 720
	PathRequestTTL    = 300
	AnnounceTimeout   = 15
)

Timeouts and intervals (seconds unless otherwise noted).

View Source
const (
	MinPort = 1
	MaxPort = 65535
)

Port range for IP-based interfaces.

View Source
const (
	DefaultSharedInstancePort  = 37428
	DefaultInstanceControlPort = 37429
	DefaultLogLevel            = 20
)

Default service ports and log level for the local instance.

View Source
const (
	DestinationSingle = 0x00
	DestinationGroup  = 0x01
	DestinationPlain  = 0x02
)

Destination type discriminators encoded in packet headers.

View Source
const TokenOverhead = 48

TokenCipher overhead in bytes (IV + auth tag area).

Variables

This section is empty.

Functions

func ApplyIFACInbound added in v0.9.0

func ApplyIFACInbound(iface NetworkInterface, raw []byte) ([]byte, bool)

ApplyIFACInbound applies the IFAC policy of Transport.inbound. It returns the recovered raw packet plus a boolean that is true when the packet should continue through normal processing, and false when the packet must be dropped.

Policy: if the interface has IFAC configured, the IFAC flag must be set AND the IFAC must verify, otherwise drop. If the interface has no IFAC configured, packets with the IFAC flag set are dropped.

func ApplyIFACOutbound added in v0.9.0

func ApplyIFACOutbound(iface NetworkInterface, raw []byte) ([]byte, error)

ApplyIFACOutbound masks raw with the interface's IFAC, if configured. When the interface has no IFAC the input is returned unchanged. Errors are returned to the caller; the caller should typically drop the packet on error.

Types

type BaseInterface

type BaseInterface struct {
	Name     string
	Mode     InterfaceMode
	Type     InterfaceType
	Online   bool
	Enabled  bool
	Detached bool

	In  bool
	Out bool

	MTU     int
	Bitrate int64

	TxBytes   uint64
	RxBytes   uint64
	TxPackets uint64
	RxPackets uint64

	Mutex          sync.RWMutex
	Owner          any
	PacketCallback PacketCallback

	// IFACIdentity is set when the interface participates in an IFAC network.
	IFACIdentity IFAC
	// contains filtered or unexported fields
}

BaseInterface provides common implementation for network interfaces

func NewBaseInterface

func NewBaseInterface(name string, ifaceType InterfaceType, enabled bool) BaseInterface

NewBaseInterface creates a new BaseInterface instance

func (*BaseInterface) Detach

func (i *BaseInterface) Detach()

func (*BaseInterface) Disable

func (i *BaseInterface) Disable()

func (*BaseInterface) Enable

func (i *BaseInterface) Enable()

func (*BaseInterface) GetBandwidthAvailable

func (i *BaseInterface) GetBandwidthAvailable() bool

func (*BaseInterface) GetConn

func (i *BaseInterface) GetConn() net.Conn

func (*BaseInterface) GetIFAC added in v0.9.0

func (i *BaseInterface) GetIFAC() IFAC

GetIFAC returns the Interface Access Code identity, or nil if IFAC is not configured on this interface.

func (*BaseInterface) GetMTU

func (i *BaseInterface) GetMTU() int

func (*BaseInterface) GetMode

func (i *BaseInterface) GetMode() InterfaceMode

func (*BaseInterface) GetName

func (i *BaseInterface) GetName() string

func (*BaseInterface) GetPacketCallback

func (i *BaseInterface) GetPacketCallback() PacketCallback

func (*BaseInterface) GetRxBytes added in v0.9.0

func (i *BaseInterface) GetRxBytes() uint64

func (*BaseInterface) GetRxPackets added in v0.9.0

func (i *BaseInterface) GetRxPackets() uint64

func (*BaseInterface) GetTxBytes added in v0.9.0

func (i *BaseInterface) GetTxBytes() uint64

func (*BaseInterface) GetTxPackets added in v0.9.0

func (i *BaseInterface) GetTxPackets() uint64

func (*BaseInterface) GetType

func (i *BaseInterface) GetType() InterfaceType

Default implementations for BaseInterface

func (*BaseInterface) IsDetached

func (i *BaseInterface) IsDetached() bool

func (*BaseInterface) IsEnabled

func (i *BaseInterface) IsEnabled() bool

func (*BaseInterface) IsOnline

func (i *BaseInterface) IsOnline() bool

func (*BaseInterface) ProcessIncoming

func (i *BaseInterface) ProcessIncoming(data []byte)

func (*BaseInterface) ProcessOutgoing

func (i *BaseInterface) ProcessOutgoing(data []byte) error

ProcessOutgoing on the abstract BaseInterface is intentionally a fail-loud stub: any concrete network interface that uses BaseInterface as its base MUST override ProcessOutgoing to actually transmit bytes. Returning an error here surfaces dynamic-dispatch mistakes (e.g. a *BaseInterface pointer leaking through a callback closure) instead of letting the transport silently swallow every outgoing packet.

func (*BaseInterface) Send

func (i *BaseInterface) Send(data []byte, address string) error

func (*BaseInterface) SendLinkPacket

func (i *BaseInterface) SendLinkPacket(dest []byte, data []byte, timestamp time.Time) error

func (*BaseInterface) SendPathRequest

func (i *BaseInterface) SendPathRequest(data []byte) error

func (*BaseInterface) SetIFAC added in v0.9.0

func (i *BaseInterface) SetIFAC(id IFAC)

SetIFAC stores an Interface Access Code identity on this interface. Pass nil to disable IFAC. Subsequent calls to ApplyIFACOutbound / ApplyIFACInbound will use the new value.

func (*BaseInterface) SetPacketCallback

func (i *BaseInterface) SetPacketCallback(callback PacketCallback)

func (*BaseInterface) Start

func (i *BaseInterface) Start() error

Default implementations that should be overridden by specific interfaces

func (*BaseInterface) Stop

func (i *BaseInterface) Stop() error

type ConfigProvider

type ConfigProvider interface {
	GetConfigPath() string
	GetLogLevel() int
	GetInterfaces() map[string]InterfaceConfig
}

type IFAC added in v0.9.0

type IFAC interface {
	// Size returns the per-interface IFAC size in bytes.
	Size() int
	// Mask wraps a raw outbound packet with an authenticated Interface Access
	// Code; the returned buffer is the bytes to write on the wire.
	Mask(raw []byte) ([]byte, error)
	// Unmask validates an inbound packet's IFAC. It returns (raw, true) when
	// the packet had a valid IFAC stripped, (raw, true) unchanged when the
	// IFAC flag is not set, and (nil, false) when validation failed.
	Unmask(raw []byte) ([]byte, bool, error)
}

IFAC is the subset of pkg/ifac.Identity that interfaces and transport need to authenticate and mask/unmask raw packets. Living in pkg/common avoids an import cycle (pkg/common -> pkg/ifac -> pkg/identity -> pkg/common).

type InterfaceConfig

type InterfaceConfig struct {
	Name              string
	Type              string
	Enabled           bool
	Address           string
	Port              int
	TargetHost        string
	TargetPort        int
	TargetAddress     string
	Interface         string
	KISSFraming       bool
	I2PTunneled       bool
	PreferIPv6        bool
	MaxReconnTries    int
	Bitrate           int64
	MTU               int
	GroupID           string
	DiscoveryScope    string
	DiscoveryPort     int
	DataPort          int
	MulticastAddrType string
	Devices           []string
	IgnoredDevices    []string

	AnnounceCap           float64 // % of bitrate; 0 => default 2%
	AnnounceRateTarget    float64 // min seconds between same-dest rebroadcasts; 0 => off
	AnnounceRateGrace     int
	AnnounceRatePenalty   float64
	IngressControl        bool
	IngressControlSet     bool // false => use default (ingress on)
	ICNewTime             int
	ICBurstFreqNew        float64
	ICBurstFreq           float64
	ICMaxHeldAnnounces    int
	ICBurstHold           int
	ICBurstPenalty        int
	ICHeldReleaseInterval int
}

InterfaceConfig is per-interface settings (announce_* / ic_* match reference Reticulum).

type InterfaceMode

type InterfaceMode byte

Interface types

const (
	IFModeFull InterfaceMode = iota
	IFModePoint
	IFModeGateway
	IFModeAccessPoint
	IFModeRoaming
	IFModeBoundary
)

Interface operational modes.

type InterfaceType

type InterfaceType byte
const (
	IFTypeNone InterfaceType = iota
	IFTypeUDP
	IFTypeTCP
	IFTypeUnix
	IFTypeI2P
	IFTypeBluetooth
	IFTypeSerial
	IFTypeAuto
)

Interface type discriminators.

type LinkEstablishedCallback

type LinkEstablishedCallback func(any)

type LinkStatus

type LinkStatus struct {
	Established bool
	LastSeen    time.Time
	RTT         time.Duration
	Quality     float64
	Hops        uint8
}

LinkStatus represents the current state of a link

type NetworkInterface

type NetworkInterface interface {
	// Core interface operations
	Start() error
	Stop() error
	Enable()
	Disable()
	Detach()

	// Network operations
	Send(data []byte, address string) error
	GetConn() net.Conn
	GetMTU() int
	GetName() string

	// Interface properties
	GetType() InterfaceType
	GetMode() InterfaceMode
	IsEnabled() bool
	IsOnline() bool
	IsDetached() bool
	GetBandwidthAvailable() bool

	// Packet handling
	ProcessIncoming([]byte)
	ProcessOutgoing([]byte) error
	SendPathRequest([]byte) error
	SendLinkPacket([]byte, []byte, time.Time) error
	SetPacketCallback(PacketCallback)
	GetPacketCallback() PacketCallback
	GetTxBytes() uint64
	GetRxBytes() uint64
	GetTxPackets() uint64
	GetRxPackets() uint64

	// Interface Access Code accessors. SetIFAC(nil) disables IFAC on this
	// interface. When IFAC is set, outbound packets are masked before send and
	// inbound packets without a valid IFAC are dropped, matching the policy of
	// Transport.transmit / Transport.inbound.
	SetIFAC(IFAC)
	GetIFAC() IFAC
}

NetworkInterface defines the interface for all network communication methods

type NetworkStats

type NetworkStats struct {
	BytesSent       uint64
	BytesReceived   uint64
	PacketsSent     uint64
	PacketsReceived uint64
	LastUpdated     time.Time
}

NetworkStats holds interface statistics

type PacketCallback

type PacketCallback func([]byte, NetworkInterface)

type Path

type Path struct {
	Interface   NetworkInterface
	LastSeen    time.Time
	NextHop     []byte
	Hops        uint8
	LastUpdated time.Time
	HopCount    uint8
}

type PathRequest

type PathRequest struct {
	DestinationHash []byte
	Tag             []byte
	TTL             int
	Recursive       bool
}

PathRequest represents a path discovery request

type PathResponse

type PathResponse struct {
	DestinationHash []byte
	NextHop         []byte
	Hops            uint8
	Tag             []byte
}

PathResponse represents a path discovery response

type PathStatus

type PathStatus byte
const (
	PathStatusUnknown PathStatus = iota
	PathStatusDirect
	PathStatusRelay
	PathStatusFailed
)

Path status.

type ProofRequestedCallback

type ProofRequestedCallback func([]byte, []byte)

Common callbacks

type RatchetIDReceiver

type RatchetIDReceiver struct {
	LatestRatchetID []byte
}

RatchetIDReceiver holds ratchet ID information

type RequestHandler

type RequestHandler struct {
	Path              string
	ResponseGenerator func(path string, data []byte, requestID []byte, linkID []byte, remoteIdentity any, requestedAt int64) any
	AllowMode         byte
	AllowedList       [][]byte
}

RequestHandler manages path requests and responses

type ReticulumConfig

type ReticulumConfig struct {
	ConfigPath          string
	EnableTransport     bool
	ShareInstance       bool
	SharedInstancePort  int
	InstanceControlPort int
	PanicOnInterfaceErr bool
	LogLevel            int
	Interfaces          map[string]*InterfaceConfig
	AppName             string
	AppAspect           string
}

ReticulumConfig represents the main configuration structure

func DefaultConfig

func DefaultConfig() *ReticulumConfig

func NewReticulumConfig

func NewReticulumConfig() *ReticulumConfig

NewReticulumConfig creates a new ReticulumConfig with default values

func (*ReticulumConfig) Validate

func (c *ReticulumConfig) Validate() error

Validate checks if the configuration is valid

type TransportMode

type TransportMode byte
const (
	TransportModeDirect TransportMode = iota
	TransportModeRelay
	TransportModeGateway
)

Transport modes.

Jump to

Keyboard shortcuts

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