schema

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NodeRegister map[string]*NodeImplDesc
View Source
var PolicyRegister map[string]*PolicyImplDesc

Functions

func QueryInterface added in v0.0.2

func QueryInterface[T NodeImpl](node *Node) T

QueryInterface casts a node to a specific NodeImpl type

func RegisterNodeImpl added in v0.0.2

func RegisterNodeImpl(desc *NodeImplDesc)

func RegisterPolicyImpl added in v0.0.2

func RegisterPolicyImpl(desc *PolicyImplDesc)

Types

type BaseNodeImpl added in v0.0.2

type BaseNodeImpl struct {
	Node        *Node
	OnAttachEvt *EventTarget
	OnDetachEvt *EventTarget
}

BaseNodeImpl is the default implementation of NodeImpl

func (*BaseNodeImpl) CastTo added in v0.0.2

func (n *BaseNodeImpl) CastTo(ptr any) any

func (*BaseNodeImpl) NodeImplTrait added in v0.0.2

func (n *BaseNodeImpl) NodeImplTrait() NodeImpl

func (*BaseNodeImpl) OnAttach added in v0.0.2

func (n *BaseNodeImpl) OnAttach() error

OnAttach is called when the node is attached to an engine

func (*BaseNodeImpl) OnDetach added in v0.0.2

func (n *BaseNodeImpl) OnDetach()

OnDetach is called when the node is detached from an engine

func (*BaseNodeImpl) OnInterest added in v0.0.2

func (n *BaseNodeImpl) OnInterest(
	interest ndn.Interest, reply ndn.ReplyFunc,
	extra ndn.InterestHandlerExtra, matching enc.Matching,
)

OnInterest is the callback function when there is an incoming Interest.

func (*BaseNodeImpl) TreeNode added in v0.0.2

func (n *BaseNodeImpl) TreeNode() *Node

type CacheEntry added in v0.0.2

type CacheEntry struct {
	RawData  enc.Wire
	Validity time.Time
}

type Callback added in v0.0.2

type Callback = func(event *Event) any

Callback represents a callback that handles an event

type Event

type Event struct {
	// TargetNode is the node that triggers the event, valid for all events.
	// Generally equals to Target.Node. Exception: on the callback of Need,
	// Target.Node is matched with Data name but TargetNode is the Interest node.
	TargetNode *Node
	// Target is the target (matched node) that triggers the event
	// Valid for events handling a specific packet.
	Target *MatchedNode
	// Deadline is now + InterestLifetime
	Deadline *time.Time
	// RawPacket is the raw Interest or Data wire
	RawPacket enc.Wire
	// SigCovered contains the bytes of the raw packet that are covered by the signature
	SigCovered enc.Wire
	// Signature is the signature of the packet received.
	Signature ndn.Signature
	// Interest is the received Interest.
	Interest ndn.Interest
	// Data is the received Data.
	Data ndn.Data
	// IntConfig is the config of the Interest that is going to encode.
	IntConfig *ndn.InterestConfig
	// DataConfig is the config of the Data that is going to produce.
	DataConfig *ndn.DataConfig
	// Content is the content of Data or AppParam of Interest.
	Content enc.Wire
	// NackReason is the reason of Network NACK given by the forwarder.
	NackReason *uint64
	// ValidResult is the validation result given by last validator.
	ValidResult *ValidRes
	// SelfProduced indicates whether the Data is produced by myself (this program).
	SelfProduced *bool
	// ValidDuration is The validity period of a data in the storage produced by this node
	// i.e. how long the local storage will serve it.
	// Should be larger than FreshnessPeriod. Not affected data fetched remotely.
	ValidDuration *time.Duration
	// Reply is the func called to reply to an Interest
	Reply ndn.ReplyFunc
	// NeedStatus is the result status in the callback of need()
	NeedStatus *ndn.InterestResult
	// Error is the optional error happened in an event
	Error error
	// Extra arguments used by application
	Extra map[string]any
}

Event represents the context of a triggered event

type EventGetter added in v0.0.2

type EventGetter func(owner any) *EventTarget

func DefaultEventTarget added in v0.0.2

func DefaultEventTarget(event PropKey) EventGetter

DefaultEventTarget returns the default event target getter of given event name.

type EventTarget added in v0.0.2

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

Event is a chain of callback functions for an event. The execution order is supposed to be the addition order.

func (*EventTarget) Add added in v0.0.2

func (e *EventTarget) Add(callback *Callback)

Add a callback. Note that callback should be a *func.

func (*EventTarget) Dispatch added in v0.0.2

func (e *EventTarget) Dispatch(event *Event) any

Dispatch fires the event, calls every callback and returns the last result

func (*EventTarget) DispatchUntil added in v0.0.2

func (e *EventTarget) DispatchUntil(event *Event, acceptFunc func(any) bool) any

DispatchUntil fires the event until `acceptFunc` returns `true`, and returns the accepted result Returns the last result if no result is acceptable, and nil if no callback is called.

func (*EventTarget) Remove added in v0.0.2

func (e *EventTarget) Remove(callback *Callback)

Remove a callback Seems not useful at all. Do we remove it?

func (*EventTarget) Val added in v0.0.2

func (e *EventTarget) Val() []*Callback

Val returns the value of the event. Used by nodes only.

type ExpressPoint

type ExpressPoint struct {
	BaseNodeImpl

	OnInt           *EventTarget
	OnValidateInt   *EventTarget
	OnValidateData  *EventTarget
	OnSearchStorage *EventTarget
	OnSaveStorage   *EventTarget
	OnGetIntSigner  *EventTarget

	CanBePrefix bool
	MustBeFresh bool
	Lifetime    time.Duration
	SupressInt  bool
}

func (*ExpressPoint) CastTo added in v0.0.2

func (n *ExpressPoint) CastTo(ptr any) any

func (*ExpressPoint) NeedCallback added in v0.0.2

func (n *ExpressPoint) NeedCallback(
	mNode MatchedNode, callback Callback, appParam enc.Wire, intConfig *ndn.InterestConfig, supress bool,
) error

NeedCallback is callback version of Need(). The Need() function to obtain the corresponding Data. May express an Interest if the Data is not stored. `intConfig` is optional and if given, will overwrite the default setting. The callback function will be called in another goroutine no matter what the result is. So if `callback` can handle errors, it is safe to ignore the return value. TODO: (Urgent) NeedXXX needs a way for the user to optionally specify the deadline of the Interest without touching anything else in intConfig

func (*ExpressPoint) NeedChan added in v0.0.2

func (n *ExpressPoint) NeedChan(
	mNode MatchedNode, appParam enc.Wire, intConfig *ndn.InterestConfig, supress bool,
) chan NeedResult

NeedChan is the channel version of Need()

func (*ExpressPoint) NodeImplTrait added in v0.0.2

func (n *ExpressPoint) NodeImplTrait() NodeImpl

func (*ExpressPoint) OnInterest

func (n *ExpressPoint) OnInterest(
	interest ndn.Interest, reply ndn.ReplyFunc,
	extra ndn.InterestHandlerExtra, matching enc.Matching,
)

func (*ExpressPoint) SearchCache

func (n *ExpressPoint) SearchCache(event *Event) enc.Wire

type FixedHmacIntSignerPolicy added in v0.0.2

type FixedHmacIntSignerPolicy struct {
	Key string
	// contains filtered or unexported fields
}

func (*FixedHmacIntSignerPolicy) Apply added in v0.0.2

func (p *FixedHmacIntSignerPolicy) Apply(node *Node)

func (*FixedHmacIntSignerPolicy) PolicyTrait added in v0.0.2

func (p *FixedHmacIntSignerPolicy) PolicyTrait() Policy

type FixedHmacSignerPolicy added in v0.0.2

type FixedHmacSignerPolicy struct {
	Key         string
	KeyName     enc.Name
	SignForCert bool
	ExpireTime  time.Duration
}

func (*FixedHmacSignerPolicy) Apply added in v0.0.2

func (p *FixedHmacSignerPolicy) Apply(node *Node)

func (*FixedHmacSignerPolicy) PolicyTrait added in v0.0.2

func (p *FixedHmacSignerPolicy) PolicyTrait() Policy

type LeafNode

type LeafNode struct {
	ExpressPoint

	OnGetDataSigner *EventTarget

	ContentType ndn.ContentType
	Freshness   time.Duration
	ValidDur    time.Duration
}

LeafNode is a leaf of the NTSchema tree, a point where Data packets can be named.

func (*LeafNode) CastTo added in v0.0.2

func (n *LeafNode) CastTo(ptr any) any

func (*LeafNode) NodeImplTrait added in v0.0.2

func (n *LeafNode) NodeImplTrait() NodeImpl

func (*LeafNode) Provide

func (n *LeafNode) Provide(
	mNode MatchedNode, content enc.Wire, dataCfg *ndn.DataConfig,
) enc.Wire

Provide a Data packet with given name and content. Name is constructed from matching if nil. If given, name must agree with matching.

type ListenerList added in v0.0.2

type ListenerList []string

type MatchedNode added in v0.0.2

type MatchedNode struct {
	Node     *Node
	Matching enc.Matching
	Name     enc.Name
}

MatchedNode represents a node with a matching

func (MatchedNode) Call added in v0.0.2

func (mNode MatchedNode) Call(funcName string, args ...any) any

Call calls the specified function provided by the node with give agruments.

func (MatchedNode) Logger added in v0.0.2

func (mNode MatchedNode) Logger(module string) *log.Entry

Logger returns the logger used in functions provided by this node. If module is "", the node's impl's class name will be used as a default value.

func (MatchedNode) Refine added in v0.0.2

func (mNode MatchedNode) Refine(name enc.Name) *MatchedNode

Refine a matching with a longer name. `name` must include current name as a prefix.

type MemStoragePolicy added in v0.0.2

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

MemStoragePolicy is a policy that stored data in a memory storage. It will iteratively applies to all children in a subtree.

func (*MemStoragePolicy) Apply added in v0.0.2

func (p *MemStoragePolicy) Apply(node *Node)

func (*MemStoragePolicy) Get added in v0.0.2

func (p *MemStoragePolicy) Get(name enc.Name, canBePrefix bool, mustBeFresh bool) enc.Wire

func (*MemStoragePolicy) PolicyTrait added in v0.0.2

func (p *MemStoragePolicy) PolicyTrait() Policy

func (*MemStoragePolicy) Put added in v0.0.2

func (p *MemStoragePolicy) Put(name enc.Name, rawData enc.Wire, validity time.Time)

type NeedResult added in v0.0.2

type NeedResult struct {
	// Status is the result of Need (data, NACKed, timed out, validation failure)
	Status ndn.InterestResult
	// Content is the needed data object
	Content enc.Wire
	// Data packet if available. Note that this may be nil if the node aggregates multiple packets.
	// Please use Extra to obtain extra info in that case.
	Data ndn.Data
	// ValidResult is the result of validation of this data object
	ValidResult *ValidRes
	// NackReason is the reason for NACK
	NackReason *uint64
	// Extra info used by application
	Extra map[string]any
}

func (NeedResult) Get added in v0.0.2

func (r NeedResult) Get() (ndn.InterestResult, enc.Wire)

type Node added in v0.0.2

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

Node is the class for a NTSchema node, the container of NodeImpl. TODO: Inheritance from BaseNode is really a bad model of this thing but I cannot come up with a better one in limited time. If possible, a mixin programming model may be better. TODO: (updated) a better choice may be separate the tree node (that handles Child, Parent, etc.) and the polymorphic functional part (than handles Get, Set, Events, etc.) For WASM use in the future, we may need a list of properties. Also, add ENV for Init.

func (*Node) AddEventListener added in v0.0.2

func (n *Node) AddEventListener(eventName PropKey, callback *Callback)

AddEventListener adds `callback` to the event `eventName` Note that callback is a function pointer (so it's comparable)

func (*Node) Apply added in v0.0.2

func (n *Node) Apply(matching enc.Matching) *MatchedNode

Apply a (variable) matching and obtain the corresponding NDN name For example, apply {"id":[]byte{"aa"}} to a node at /ndn/<id> will get /ndn/aa Will attach "params-sha256" and "sha256digest" to the end of the name if exists.

func (*Node) At added in v0.0.2

func (n *Node) At(path enc.NamePattern) *Node

At gets a node/subtree at a given pattern path. The path does not include the attached prefix.

func (*Node) AttachedPrefix added in v0.0.2

func (n *Node) AttachedPrefix() enc.Name

AttachedPrefix of the root node. Must be nil for all other nodes and before Attach.

func (*Node) Child added in v0.0.2

func (n *Node) Child(edge enc.ComponentPattern) *Node

Child of given edge

func (*Node) Children added in v0.0.2

func (n *Node) Children() []*Node

Children of the node

func (*Node) ConstructName added in v0.0.2

func (n *Node) ConstructName(matching enc.Matching, ret enc.Name) error

ConstructName is the aux function used by Apply

func (*Node) ContinueMatch added in v0.0.2

func (n *Node) ContinueMatch(remainingName enc.Name, curMatching enc.Matching) *Node

ContinueMatch is a sub-function used by Match

func (*Node) Depth added in v0.0.2

func (n *Node) Depth() uint

Depth of the node in the tree. It includes the attached prefix, so the root node may have a positive depth For example, if the root is attached at prefix /ndn, then the child of path /<id> from the root will have a depth=2.

func (*Node) Engine added in v0.0.2

func (n *Node) Engine() ndn.Engine

Engine returns the engine attached

func (*Node) Get added in v0.0.2

func (n *Node) Get(propName PropKey) any

Get a property or callback event

func (*Node) GetEvent added in v0.0.2

func (n *Node) GetEvent(eventName PropKey) *EventTarget

GetEvent returns an event with a given event name. Return nil if not exists.

func (*Node) Impl added in v0.0.2

func (n *Node) Impl() NodeImpl

Impl returns the actual functional part of the node

func (*Node) Log added in v0.0.2

func (n *Node) Log() *log.Entry

Log returns the log entry of this node

func (*Node) Match added in v0.0.2

func (n *Node) Match(name enc.Name) *MatchedNode

Match an NDN name to a (variable) matching For example, /ndn/aa may match to a node at /ndn/<id> with matching <id> = "aa"

func (*Node) OnAttach added in v0.0.2

func (n *Node) OnAttach(path enc.NamePattern, engine ndn.Engine) error

OnAttach is called when the node is attached to an engine Node will call the event set by policy

func (*Node) OnDetach added in v0.0.2

func (n *Node) OnDetach()

OnDetach is called when the node is detached from an engine BaseNode will call the event set by policy

func (*Node) OnInterest added in v0.0.2

func (n *Node) OnInterest(
	interest ndn.Interest,
	reply ndn.ReplyFunc,
	extra ndn.InterestHandlerExtra,
	matching enc.Matching,
)

OnInterest is the function called when an Interest comes. A base node shouldn't receive any Interest, so drops it.

func (*Node) Parent added in v0.0.2

func (n *Node) Parent() *Node

Parent of this node

func (*Node) PutNode added in v0.0.2

func (n *Node) PutNode(path enc.NamePattern, desc *NodeImplDesc) *Node

PutNode creates a node/subtree at a given pattern path. The path does not include the attached prefix. Returns the new node.

func (*Node) RemoveEventListener added in v0.0.2

func (n *Node) RemoveEventListener(eventName PropKey, callback *Callback)

RemoveEventListener removes `callback` from the event `eventName` Note that callback is a function pointer (so it's comparable)

func (*Node) RootNode added in v0.0.2

func (n *Node) RootNode() *Node

RootNode returns the root node in a tree

func (*Node) Set added in v0.0.2

func (n *Node) Set(propName PropKey, value any) error

Set a property. Use Get() to update callback events.

func (*Node) SetAttachedPrefix added in v0.0.2

func (n *Node) SetAttachedPrefix(prefix enc.Name)

SetAttachedPrefix sets the attached prefix of the root node.

func (*Node) UpEdge added in v0.0.2

func (n *Node) UpEdge() enc.ComponentPattern

UpEdge is the edge value from its parent to itself

type NodeDesc added in v0.0.2

type NodeDesc struct {
	Type   string                  `json:"type"`
	Attrs  map[string]any          `json:"attrs,omitempty"`
	Events map[string]ListenerList `json:"events,omitempty"`
}

type NodeFunc added in v0.0.2

type NodeFunc func(mNode MatchedNode, args ...any) any

type NodeImpl added in v0.0.2

type NodeImpl interface {
	// NodeImplTrait is the type trait of NTNode
	NodeImplTrait() NodeImpl

	// CastTo cast the current struct to a pointer which has the same type as ptr
	// Supposed to be used as:
	//
	//   leafNode.CastTo((*ExpressPoint)(nil))  // Get *ExpressPoint
	//
	// This is because `leafNode.(*ExpressPoint)` fails.
	CastTo(ptr any) any

	// OnInterest is the callback function when there is an incoming Interest.
	OnInterest(interest ndn.Interest, reply ndn.ReplyFunc,
		extra ndn.InterestHandlerExtra, matching enc.Matching)

	// OnAttach is called when the node is attached to an engine
	OnAttach() error

	// OnDetach is called when the node is detached from an engine
	OnDetach()

	// TreeNode returns the node container it is in.
	TreeNode() *Node
}

NodeImpl represents the functional part of a node (subtree) of NTSchema. Besides functions listed here, NodeImpl also needs a creator that creates the Node.

func CreateBaseNode added in v0.0.2

func CreateBaseNode(node *Node) NodeImpl

func CreateExpressPoint added in v0.0.2

func CreateExpressPoint(node *Node) NodeImpl

func CreateLeafNode added in v0.0.2

func CreateLeafNode(node *Node) NodeImpl

type NodeImplDesc added in v0.0.2

type NodeImplDesc struct {
	ClassName  string
	Properties map[PropKey]PropertyDesc
	Events     map[PropKey]EventGetter
	Create     func(*Node) NodeImpl
	Functions  map[string]NodeFunc
}
var BaseNodeDesc *NodeImplDesc
var ExpressPointDesc *NodeImplDesc
var LeafNodeDesc *NodeImplDesc

type Policy added in v0.0.2

type Policy interface {
	// PolicyTrait is the type trait of NTPolicy
	PolicyTrait() Policy

	// Apply the policy at a node (subtree). May modify the children of the given node.
	// The execution order is node.Init() -> policy.Apply() -> onAttach()
	// So the properties set here will overwrite Init()'s default values,
	// but be overwriten by onAttach().
	Apply(node *Node)
}

NTPolicy represents a policy, which is a modifier that sets properties and registers events during the initialization of a schema tree. The execution order is: construct the tree -> apply policies & env setup -> attach to engine (see Tree) Though policies are also considered as static knowledge (at compile time), they may be configured differently on different nodes. For example, an storage may access different folders for different instances. TODO: Design for this configuration under different environments. For example, the path to a storage, the name of the self-key, etc are knowledge specific to one instance, and thus dynamically configured. Currently I don't have an idea on the best way to separate the "statically shared part" (NTTree and the nodes) and the "dynamically configure part". (#ENV)

func NewFixedHmacIntSignerPolicy added in v0.0.2

func NewFixedHmacIntSignerPolicy() Policy

func NewFixedHmacSignerPolicy added in v0.0.2

func NewFixedHmacSignerPolicy() Policy

func NewMemStoragePolicy added in v0.0.2

func NewMemStoragePolicy() Policy

func NewRegisterPolicy added in v0.0.2

func NewRegisterPolicy() Policy

func NewSha256SignerPolicy added in v0.0.2

func NewSha256SignerPolicy() Policy

type PolicyDesc added in v0.0.2

type PolicyDesc struct {
	Type   string                  `json:"type"`
	Path   string                  `json:"path"`
	Attrs  map[string]any          `json:"attrs,omitempty"`
	Events map[string]ListenerList `json:"events,omitempty"`
}

type PolicyImplDesc added in v0.0.2

type PolicyImplDesc struct {
	ClassName  string
	Properties map[PropKey]PropertyDesc
	Events     map[PropKey]EventGetter
	Create     func() Policy
}

type PropKey

type PropKey string

PropKey is the type of properties of a node. A property of a node gives the default setting of some procedure as well as event callbacks. We design in this way to support DSL and WASM in future.

const (
	// The event called when the node is attached to an engine. [NodeOnAttachEvent]
	PropOnAttach PropKey = "OnAttachEvt"

	// The event called when the node is detached from an engine. [NodeOnDetachEvent]
	PropOnDetach PropKey = "OnDetachEvt"

	// The event called when an ExpressingPoint or LeafNode receives an Interest. [NodeOnIntEvent]
	PropOnInterest PropKey = "OnInt"

	// The event called when an ExpressingPoint or LeafNode verifies the signature of an Interest. [NodeValidateEvent]
	PropOnValidateInt PropKey = "OnValidateInt"

	// The event called when an ExpressingPoint or LeafNode verifies the signature of a Data. [NodeValidateEvent]
	PropOnValidateData PropKey = "OnValidateData"

	// The event called when an ExpressingPoint or LeafNode searches the storage on Need(). [NodeSearchStorageEvent]
	PropOnSearchStorage PropKey = "OnSearchStorage"

	// The event called to get a signer for an Interest
	PropOnGetIntSigner PropKey = "OnGetIntSigner"

	// The event called to get a signer for a Data
	PropOnGetDataSigner PropKey = "OnGetDataSigner"

	// The event called when an ExpressingPoint or LeafNode saves a packet into the storage.
	// The packet may be produced locally or fetched from the network.
	// TODO: Add a sign to distinguish them.
	// [NodeSaveStorageEvent]
	PropOnSaveStorage PropKey = "OnSaveStorage"

	// Default CanBePrefix for outgoing Interest. [bool]
	PropCanBePrefix PropKey = "CanBePrefix"
	// Default MustBeFresh for outgoing Interest. [bool]
	PropMustBeFresh PropKey = "MustBeFresh"
	// Default Lifetime for outgoing Interest. [time.Duration]
	PropLifetime PropKey = "Lifetime"
	// If true, only local storage is searched. No Interest will be expressed.
	// Note: may be overwritten by the Context.
	// [bool]
	PropSuppressInt PropKey = "SupressInt"

	// Default ContentType for produced Data. [ndn.ContentType]
	PropContentType PropKey = "ContentType"
	// Default FreshnessPeriod for produced Data. [time.Duration]
	PropFreshness PropKey = "Freshness"
	// How long the data is supposed to be stored in the storage. [time.Duration]
	// The validity period of a data in the storage produced by this node,
	// i.e. how long the local storage will serve it.
	// Should be larger than FreshnessPeriod. Not affected data fetched remotely.
	// This is only the rough way to express the life period of some temporary data.
	// For long durable data stored in databases, etc., the users should use the ways
	// specified by the storage developers to express the lifetime.
	PropValidDuration PropKey = "ValidDur"
)

type PropertyDesc added in v0.0.2

type PropertyDesc struct {
	Get func(owner any) any
	Set func(owner any, value any) error
}

func DefaultPropertyDesc added in v0.0.2

func DefaultPropertyDesc(prop PropKey) PropertyDesc

DefaultPropertyDesc returns the default property descriptor of given property name.

func MatchingPropertyDesc added in v0.0.2

func MatchingPropertyDesc(prop PropKey) PropertyDesc

MatchingPropertyDesc returns the descriptor of a `enc.Matching` property. It is of type `map[string]any` in JSON, where `any` is a string.

func NamePropertyDesc added in v0.0.2

func NamePropertyDesc(prop PropKey) PropertyDesc

NamePropertyDesc returns the descriptor of a enc.Name property, which gives an NDN Name in string. Note: Get/Set functions are less used by the go program, as Go can access the field directly.

func SubNodePropertyDesc added in v0.0.2

func SubNodePropertyDesc(pathStr string, prop PropKey) PropertyDesc

SubNodePropertyDesc inherites a subnode's property as a property of the subtree's root.

func TimePropertyDesc added in v0.0.2

func TimePropertyDesc(prop PropKey) PropertyDesc

TimePropertyDesc returns the descriptor of a time property, which gives numbers&strings in milliseconds. Note: Get/Set functions are less used by the go program, as Go can access the field directly.

type RegisterPolicy added in v0.0.2

type RegisterPolicy struct {
	RegisterIf bool
	// It is map[string]any in json
	// but the any can be a string
	Patterns enc.Matching
}

func (*RegisterPolicy) Apply added in v0.0.2

func (p *RegisterPolicy) Apply(node *Node)

func (*RegisterPolicy) PolicyTrait added in v0.0.2

func (p *RegisterPolicy) PolicyTrait() Policy

type SchemaDesc added in v0.0.2

type SchemaDesc struct {
	Nodes    map[string]NodeDesc `json:"nodes"`
	Policies []PolicyDesc        `json:"policies"`
}

func (*SchemaDesc) Instantiate added in v0.0.2

func (sd *SchemaDesc) Instantiate(environment map[string]any) *Tree

type Sha256SignerPolicy added in v0.0.2

type Sha256SignerPolicy struct{}

func (*Sha256SignerPolicy) Apply added in v0.0.2

func (p *Sha256SignerPolicy) Apply(node *Node)

func (*Sha256SignerPolicy) PolicyTrait added in v0.0.2

func (p *Sha256SignerPolicy) PolicyTrait() Policy

type Tree

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

Tree represents an NTSchema tree. It is supposed to be a static knowledge and shared by all parties in the system at compile time. The execution order: construct the tree -> apply policies & env setup -> attach to engine

func CreateFromJson added in v0.0.2

func CreateFromJson(text string, environment map[string]any) *Tree

CreateFromJson creates a schema tree from json description and a given environment

func (*Tree) At

func (t *Tree) At(path enc.NamePattern) *Node

At the path return the node. Path does not include the attached prefix.

func (*Tree) Attach

func (t *Tree) Attach(prefix enc.Name, engine ndn.Engine) error

Attach the tree to the engine at prefix

func (*Tree) Detach

func (t *Tree) Detach()

Detach the schema tree from the engine

func (*Tree) Engine

func (t *Tree) Engine() ndn.Engine

func (*Tree) Match

func (t *Tree) Match(name enc.Name) *MatchedNode

Match an NDN name to a (variable) matching

func (*Tree) PutNode

func (t *Tree) PutNode(path enc.NamePattern, desc *NodeImplDesc) *Node

PutNode puts the specified node at the specified path. Path does not include the attached prefix.

func (*Tree) RLock added in v0.0.2

func (t *Tree) RLock()

RLock locks the tree for read use

func (*Tree) RUnlock added in v0.0.2

func (t *Tree) RUnlock()

RUnlock unlocks the tree locked by RLock

func (*Tree) Root

func (t *Tree) Root() *Node

type ValidRes

type ValidRes = int

ValidRes is the result of data/interest signature validation, given by one validator. When there are multiple validators chained, a packet is valid when there is at least one VrPass and no VrFail.

const (
	VrFail       ValidRes = -2 // An immediate failure. Abort the validation.
	VrTimeout    ValidRes = -1 // Timeout. Abort the validation.
	VrSilence    ValidRes = 0  // The current validator cannot give any result.
	VrPass       ValidRes = 1  // The current validator approves the packet.
	VrBypass     ValidRes = 2  // An immediate success. Bypasses the rest validators that are not executed yet.
	VrCachedData ValidRes = 3  // The data is obtained from a local cache, and the signature is checked before.
)

Directories

Path Synopsis
demosec gives a proof-of-concept demo of how security will be implemented in NTSchema
demosec gives a proof-of-concept demo of how security will be implemented in NTSchema
Generated by the generator, DO NOT modify manually
Generated by the generator, DO NOT modify manually
Generated by the generator, DO NOT modify manually
Generated by the generator, DO NOT modify manually

Jump to

Keyboard shortcuts

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