basic

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 16 Imported by: 3

Documentation

Overview

Package basic gives a default implementation of the Engine interface. It only connects to local forwarding node via Unix socket.

Index

Constants

View Source
const DefaultInterestLife = 4 * time.Second
View Source
const TimeoutMargin = 10 * time.Millisecond

Variables

This section is empty.

Functions

func NewTimer

func NewTimer() ndn.Timer

(AI GENERATED DESCRIPTION): Creates and returns a new Timer instance initialized to its zero (empty) state.

Types

type DummyTimer added in v1.5.0

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

func NewDummyTimer added in v1.5.0

func NewDummyTimer() *DummyTimer

(AI GENERATED DESCRIPTION): Creates a new DummyTimer initialized to the Unix epoch (1970‑01‑01T00:00:00Z) with an empty event queue.

func (*DummyTimer) MoveForward added in v1.5.0

func (tm *DummyTimer) MoveForward(d time.Duration)

(AI GENERATED DESCRIPTION): Advances the dummy timer forward by the given duration, executes any scheduled events whose time has passed, and updates the internal event list in a thread‑safe manner.

func (*DummyTimer) Nonce added in v1.5.0

func (*DummyTimer) Nonce() []byte

(AI GENERATED DESCRIPTION): Returns a fixed 8‑byte nonce (0x01…0x08) for use by the dummy timer during testing.

func (*DummyTimer) Now added in v1.5.0

func (tm *DummyTimer) Now() time.Time

(AI GENERATED DESCRIPTION): Returns the time value stored in the DummyTimer instance.

func (*DummyTimer) Schedule added in v1.5.0

func (tm *DummyTimer) Schedule(d time.Duration, f func()) func() error

(AI GENERATED DESCRIPTION): Schedules a callback to run after a specified duration and returns a function that can cancel the scheduled event if it has not yet fired.

func (*DummyTimer) Sleep added in v1.5.0

func (tm *DummyTimer) Sleep(d time.Duration)

(AI GENERATED DESCRIPTION): Sleeps for the specified duration by scheduling a callback in the DummyTimer and blocking until that callback signals completion.

type Engine

type Engine struct {

	// (advanced usage) global hook on receiving data packets
	OnDataHook func(data ndn.Data, raw enc.Wire, sigCov enc.Wire) error
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine(face ndn.Face, timer ndn.Timer) *Engine

(AI GENERATED DESCRIPTION): Creates and initializes a new Engine instance, wiring the given face and timer into its state and setting up all internal data structures, locks, queues, and configuration needed for packet processing.

func (*Engine) AttachHandler

func (e *Engine) AttachHandler(prefix enc.Name, handler ndn.InterestHandler) error

(AI GENERATED DESCRIPTION): Registers an `InterestHandler` for a given name prefix in the Engine’s FIB, rejecting the operation if a handler is already attached for that prefix.

func (*Engine) DetachHandler

func (e *Engine) DetachHandler(prefix enc.Name) error

(AI GENERATED DESCRIPTION): Detaches the handler associated with the specified prefix by removing the corresponding FIB entry.

func (*Engine) EngineTrait

func (e *Engine) EngineTrait() ndn.Engine

(AI GENERATED DESCRIPTION): Returns the Engine instance itself as an ndn.Engine.

func (*Engine) ExecMgmtCmd

func (e *Engine) ExecMgmtCmd(module string, cmd string, args any) (any, error)

(AI GENERATED DESCRIPTION): Executes a named‑data management command by crafting a signed Interest for the specified module and command with the given arguments, sending it, validating the response signature, parsing the control response, and returning the result or an error.

func (*Engine) Express

func (e *Engine) Express(interest *ndn.EncodedInterest, callback ndn.ExpressCallbackFunc) error

(AI GENERATED DESCRIPTION): Expresses an NDN interest by inserting it into the PIT with deadline and callback handling, optionally wrapping it in a link packet, and sending it through the configured face.

func (*Engine) Face added in v1.5.2

func (e *Engine) Face() ndn.Face

(AI GENERATED DESCRIPTION): Returns the ndn.Face instance that the Engine uses for communication.

func (*Engine) IsRunning

func (e *Engine) IsRunning() bool

(AI GENERATED DESCRIPTION): **IsRunning** – Returns `true` if the engine is currently running, otherwise `false`.

func (*Engine) Post added in v1.5.1

func (e *Engine) Post(task func())

(AI GENERATED DESCRIPTION): Enqueues a task to the engine's internal task queue, performing a non‑blocking send and spawning a goroutine to enqueue the task if the channel is currently full.

func (*Engine) RegisterRoute

func (e *Engine) RegisterRoute(prefix enc.Name) error

(AI GENERATED DESCRIPTION): Registers the supplied name prefix with the engine’s routing information base by issuing a RIB‑management command.

func (*Engine) SetCmdSec added in v1.5.0

func (e *Engine) SetCmdSec(signer ndn.Signer, validator func(enc.Name, enc.Wire, ndn.Signature) bool)

(AI GENERATED DESCRIPTION): Sets the Engine’s command security by assigning a signer for management packets and a validator function for checking incoming command signatures.

func (*Engine) Spec

func (*Engine) Spec() ndn.Spec

(AI GENERATED DESCRIPTION): Returns the engine’s NDN specification, which is currently an empty `spec.Spec` instance.

func (*Engine) Start

func (e *Engine) Start() error

(AI GENERATED DESCRIPTION): Starts the engine by opening its face, registering packet and error callbacks, and launching a goroutine that processes received packets and queued tasks until the engine is stopped.

func (*Engine) Stop

func (e *Engine) Stop() error

(AI GENERATED DESCRIPTION): Stops the engine by signaling its close channel (terminating its operation) and returns an error if the engine was not running.

func (*Engine) String added in v1.4.3

func (e *Engine) String() string

(AI GENERATED DESCRIPTION): Returns the fixed string `"basic-engine"` as the Engine’s string representation.

func (*Engine) Timer

func (e *Engine) Timer() ndn.Timer

(AI GENERATED DESCRIPTION): Returns the `ndn.Timer` instance used by the Engine.

func (*Engine) UnregisterRoute

func (e *Engine) UnregisterRoute(prefix enc.Name) error

(AI GENERATED DESCRIPTION): Unregisters the specified NDN prefix from the Engine’s routing information base (RIB) by issuing a management command and logs the result.

type NameTrie

type NameTrie[V any] struct {
	// contains filtered or unexported fields
}

NameTrie is a simple implementation of a Name trie (node/subtree) used for PIT and FIB. It is slow due to the usage of TlvStr(). Subject to change when it explicitly affects performance.

func NewNameTrie

func NewNameTrie[V any]() *NameTrie[V]

NewNameTrie creates a new NameTrie and returns the root node.

func (*NameTrie[V]) Depth

func (n *NameTrie[V]) Depth() int

Depth returns the depth of a node in the tree.

func (*NameTrie[V]) ExactMatch

func (n *NameTrie[V]) ExactMatch(name enc.Name) *NameTrie[V]

ExactMatch returns the node that matches the name exactly. If no node matches, it returns nil.

func (*NameTrie[V]) FirstNodeIf

func (n *NameTrie[V]) FirstNodeIf(pred func(V) bool) *NameTrie[V]

FirstNodeIf returns the first node that satisfies given condition, in DFS order.

func (*NameTrie[V]) FirstSatisfyOrNew

func (n *NameTrie[V]) FirstSatisfyOrNew(name enc.Name, pred func(V) bool) *NameTrie[V]

FirstSatisfyOrNew finds or creates the first node along the path that satisfies the predicate.

func (*NameTrie[V]) HasChildren

func (n *NameTrie[V]) HasChildren() bool

HasChildren returns whether the node has children.

func (*NameTrie[V]) MatchAlways

func (n *NameTrie[V]) MatchAlways(name enc.Name) *NameTrie[V]

MatchAlways finds or creates the node that matches the name exactly.

func (*NameTrie[V]) Parent

func (n *NameTrie[V]) Parent() *NameTrie[V]

Parent returns its parent node.

func (*NameTrie[V]) PrefixMatch

func (n *NameTrie[V]) PrefixMatch(name enc.Name) *NameTrie[V]

PrefixMatch returns the longest prefix match of the name. Always succeeds, but the returned node may be empty.

func (*NameTrie[V]) Prune added in v1.4.3

func (n *NameTrie[V]) Prune()

Prune deletes the node itself if no children. Automatically removes ancestors if empty.

func (*NameTrie[V]) PruneIf added in v1.4.3

func (n *NameTrie[V]) PruneIf(pred func(V) bool)

PruneIf deletes the node and its ancestors if they are empty. Whether empty or not is defined by a given function.

func (*NameTrie[V]) SetValue

func (n *NameTrie[V]) SetValue(value V)

SetValue puts some value in the node.

func (*NameTrie[V]) Value

func (n *NameTrie[V]) Value() V

Value returns the value stored in the node.

type Timer

type Timer struct{}

func (Timer) Nonce

func (Timer) Nonce() []byte

(AI GENERATED DESCRIPTION): Generates an 8‑byte cryptographically secure random nonce using crypto/rand and returns it as a byte slice.

func (Timer) Now

func (Timer) Now() time.Time

(AI GENERATED DESCRIPTION): Timer.Now returns the current local time from the system clock.

func (Timer) Schedule

func (Timer) Schedule(d time.Duration, f func()) func() error

(AI GENERATED DESCRIPTION): Schedules a callback to run after the given duration and returns a closure that cancels the scheduled call, returning an error if it has already been cancelled.

func (Timer) Sleep

func (Timer) Sleep(d time.Duration)

(AI GENERATED DESCRIPTION): Pauses execution for the specified duration by invoking `time.Sleep`.

Jump to

Keyboard shortcuts

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