Documentation
¶
Overview ¶
Package basic gives a default implementation of the Engine interface. It only connects to local forwarding node via Unix socket.
Index ¶
- Constants
- func NewTimer() ndn.Timer
- type DummyTimer
- type Engine
- func (e *Engine) AttachHandler(prefix enc.Name, handler ndn.InterestHandler) error
- func (e *Engine) DetachHandler(prefix enc.Name) error
- func (e *Engine) EngineTrait() ndn.Engine
- func (e *Engine) ExecMgmtCmd(module string, cmd string, args any) (any, error)
- func (e *Engine) Express(interest *ndn.EncodedInterest, callback ndn.ExpressCallbackFunc) error
- func (e *Engine) Face() ndn.Face
- func (e *Engine) IsRunning() bool
- func (e *Engine) Post(task func())
- func (e *Engine) RegisterRoute(prefix enc.Name) error
- func (e *Engine) SetCmdSec(signer ndn.Signer, validator func(enc.Name, enc.Wire, ndn.Signature) bool)
- func (*Engine) Spec() ndn.Spec
- func (e *Engine) Start() error
- func (e *Engine) Stop() error
- func (e *Engine) String() string
- func (e *Engine) Timer() ndn.Timer
- func (e *Engine) UnregisterRoute(prefix enc.Name) error
- type NameTrie
- func (n *NameTrie[V]) Depth() int
- func (n *NameTrie[V]) ExactMatch(name enc.Name) *NameTrie[V]
- func (n *NameTrie[V]) FirstNodeIf(pred func(V) bool) *NameTrie[V]
- func (n *NameTrie[V]) FirstSatisfyOrNew(name enc.Name, pred func(V) bool) *NameTrie[V]
- func (n *NameTrie[V]) HasChildren() bool
- func (n *NameTrie[V]) MatchAlways(name enc.Name) *NameTrie[V]
- func (n *NameTrie[V]) Parent() *NameTrie[V]
- func (n *NameTrie[V]) PrefixMatch(name enc.Name) *NameTrie[V]
- func (n *NameTrie[V]) Prune()
- func (n *NameTrie[V]) PruneIf(pred func(V) bool)
- func (n *NameTrie[V]) SetValue(value V)
- func (n *NameTrie[V]) Value() V
- type Timer
Constants ¶
const DefaultInterestLife = 4 * time.Second
const TimeoutMargin = 10 * time.Millisecond
Variables ¶
This section is empty.
Functions ¶
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 ¶
(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 ¶
(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 ¶
(AI GENERATED DESCRIPTION): Detaches the handler associated with the specified prefix by removing the corresponding FIB entry.
func (*Engine) EngineTrait ¶
(AI GENERATED DESCRIPTION): Returns the Engine instance itself as an ndn.Engine.
func (*Engine) ExecMgmtCmd ¶
(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
(AI GENERATED DESCRIPTION): Returns the ndn.Face instance that the Engine uses for communication.
func (*Engine) IsRunning ¶
(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 ¶
(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 ¶
(AI GENERATED DESCRIPTION): Returns the engine’s NDN specification, which is currently an empty `spec.Spec` instance.
func (*Engine) Start ¶
(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 ¶
(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
(AI GENERATED DESCRIPTION): Returns the fixed string `"basic-engine"` as the Engine’s string representation.
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 ¶
NewNameTrie creates a new NameTrie and returns the root node.
func (*NameTrie[V]) ExactMatch ¶
ExactMatch returns the node that matches the name exactly. If no node matches, it returns nil.
func (*NameTrie[V]) FirstNodeIf ¶
FirstNodeIf returns the first node that satisfies given condition, in DFS order.
func (*NameTrie[V]) FirstSatisfyOrNew ¶
FirstSatisfyOrNew finds or creates the first node along the path that satisfies the predicate.
func (*NameTrie[V]) HasChildren ¶
HasChildren returns whether the node has children.
func (*NameTrie[V]) MatchAlways ¶
MatchAlways finds or creates the node that matches the name exactly.
func (*NameTrie[V]) PrefixMatch ¶
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
PruneIf deletes the node and its ancestors if they are empty. Whether empty or not is defined by a given function.
type Timer ¶
type Timer struct{}
func (Timer) Nonce ¶
(AI GENERATED DESCRIPTION): Generates an 8‑byte cryptographically secure random nonce using crypto/rand and returns it as a byte slice.
func (Timer) Now ¶
(AI GENERATED DESCRIPTION): Timer.Now returns the current local time from the system clock.