Documentation ¶
Overview ¶
Package ndn implements Named Data Networking (NDN) packet semantics. This is the top-level package of NDNgo, a minimal NDN library in pure Go.
This package contains the following important types:
Packet representation: - Interest - Data - Nack - Packet Security abstraction: - Signer - Verifier
Index ¶
- Constants
- Variables
- func RegisterSigInfoExtension(typ uint32)
- type CanSatisfyFlag
- type ContentType
- type Data
- func (data Data) CanSatisfy(interest Interest, optionalFlag ...CanSatisfyFlag) bool
- func (data Data) ComputeDigest() []byte
- func (data Data) Field() tlv.Field
- func (data Data) FullName() Name
- func (data Data) IsFinalBlock() bool
- func (data *Data) SignWith(signer func(name Name, si *SigInfo) (LLSign, error)) error
- func (data Data) String() string
- func (data Data) ToPacket() (packet *Packet)
- func (data *Data) UnmarshalBinary(value []byte) (e error)
- func (data Data) VerifyWith(verifier func(name Name, si SigInfo) (LLVerify, error)) error
- type FinalBlock
- type ForwardingHint
- type HopLimit
- type Interest
- func (interest *Interest) ApplyDefaultLifetime() time.Duration
- func (interest Interest) Field() tlv.Field
- func (interest *Interest) SignWith(signer func(name Name, si *SigInfo) (LLSign, error)) error
- func (interest Interest) String() string
- func (interest Interest) ToPacket() (packet *Packet)
- func (interest *Interest) UnmarshalBinary(wire []byte) (e error)
- func (interest *Interest) UpdateParamsDigest()
- func (interest Interest) VerifyWith(verifier func(name Name, si SigInfo) (LLVerify, error)) error
- type KeyLocator
- type L3Packet
- type LLSign
- type LLVerify
- type LpFragment
- type LpFragmenter
- type LpL3
- type LpReassembler
- type Nack
- type Name
- func (name Name) Append(comps ...NameComponent) (ret Name)
- func (name Name) Compare(other Name) int
- func (name Name) Equal(other Name) bool
- func (name Name) Field() tlv.Field
- func (name Name) Get(i int) NameComponent
- func (name Name) GetPrefix(i int) Name
- func (name Name) IsPrefixOf(other Name) bool
- func (name Name) Length() int
- func (name Name) MarshalBinary() (value []byte, e error)
- func (name Name) MarshalText() (text []byte, e error)
- func (name Name) Slice(i int, j ...int) Name
- func (name Name) String() string
- func (name *Name) UnmarshalBinary(wire []byte) error
- func (name *Name) UnmarshalText(text []byte) error
- type NameComponent
- func (comp NameComponent) Compare(other NameComponent) int
- func (comp NameComponent) Equal(other NameComponent) bool
- func (comp NameComponent) Field() tlv.Field
- func (comp NameComponent) String() string
- func (comp *NameComponent) UnmarshalTLV(typ uint32, value []byte) error
- func (comp NameComponent) Valid() bool
- type Nonce
- type Packet
- type SigInfo
- type Signable
- type SignableVerifiable
- type Signer
- type SignerVerifier
- type Verifiable
- type Verifier
Constants ¶
const ( DefaultInterestLifetime time.Duration = 4000 * time.Millisecond MinInterestLifetime time.Duration = 1 * time.Millisecond MinHopLimit = 1 MaxHopLimit = math.MaxUint8 )
Defaults and limits.
const ( // CanBePrefixFlag enables CanBePrefix in MakeInterest. CanBePrefixFlag = tCanBePrefix(true) // MustBeFreshFlag enables MustBeFresh in MakeInterest. MustBeFreshFlag = tMustBeFresh(true) )
const (
CanSatisfyInCache = 1 << iota
)
const FinalBlockFlag = tFinalBlockFlag(true)
FinalBlockFlag enables MakeData to set FinalBlock to the last name component.
Variables ¶
var ( ErrFragment = errors.New("bad fragment") ErrL3Type = errors.New("unknown L3 packet type") ErrComponentType = errors.New("NameComponent TLV-TYPE out of range") ErrNonceLen = errors.New("Nonce wrong length") ErrLifetime = errors.New("InterestLifetime out of range") ErrHopLimit = errors.New("HopLimit out of range") ErrParamsDigest = errors.New("bad ParamsDigest") ErrContentType = errors.New("bad ContentType") ErrSigType = errors.New("bad SigType") ErrKeyLocator = errors.New("bad KeyLocator") ErrSigNonce = errors.New("bad SigNonce") ErrSigValue = errors.New("bad SigValue") )
Error conditions.
Functions ¶
func RegisterSigInfoExtension ¶
func RegisterSigInfoExtension(typ uint32)
RegisterSigInfoExtension registers an extension TLV-TYPE in SigInfo.
Types ¶
type ContentType ¶
type ContentType uint64
ContentType represents a ContentType field.
func (ContentType) Field ¶
func (ct ContentType) Field() tlv.Field
func (*ContentType) UnmarshalBinary ¶
func (ct *ContentType) UnmarshalBinary(wire []byte) error
UnmarshalBinary decodes from wire encoding.
type Data ¶
type Data struct { Name Name ContentType ContentType Freshness time.Duration FinalBlock NameComponent Content []byte SigInfo *SigInfo SigValue []byte // contains filtered or unexported fields }
Data represents a Data packet.
func MakeData ¶
MakeData creates a Data from flexible arguments. Arguments can contain:
- string or Name: set Name
- ContentType
- time.Duration: set Freshness
- FinalBlock: set FinalBlock
- FinalBlockFlag: set FinalBlock to the last name component, ignored if name is empty
- []byte: set Content
- LpL3: copy PitToken and CongMark
- Interest or *Interest: copy Name, set FreshnessPeriod if Interest has MustBeFresh, inherit LpL3
func (Data) CanSatisfy ¶
func (data Data) CanSatisfy(interest Interest, optionalFlag ...CanSatisfyFlag) bool
CanSatisfy determines whether this Data can satisfy the given Interest.
func (Data) ComputeDigest ¶
ComputeDigest computes implicit digest of this Data.
If data was decoded from Packet (data.packet is assigned), the digest is of the origin packet. Computed digest is cached on data.packet. Modifying a decoded Data will cause this function to return incorrect digest.
If data was constructed (data.packet is unassigned), the digest is of the encoding of the current packet, and is not cached.
func (Data) IsFinalBlock ¶
IsFinalBlock determines whether FinalBlock field equals the last name component.
func (*Data) SignWith ¶
SignWith implements Signable interface. Caller should use signer.Sign(data).
func (*Data) UnmarshalBinary ¶
UnmarshalBinary decodes from TLV-VALUE.
func (Data) VerifyWith ¶
VerifyWith implements Verifiable interface. Caller should use verifier.Verify(data).
If data was decoded from Packet (data.packet is assigned), verification is on the origin packet. Modifying a decoded Data will cause this function to return incorrect result.
If data was constructed (data.packet is unassigned), verification is on the encoding of the current packet.
type FinalBlock ¶
type FinalBlock NameComponent
FinalBlock is passed to MakeData to set FinalBlock field.
type ForwardingHint ¶
type ForwardingHint []Name
ForwardingHint represents a forwarding hint.
func (ForwardingHint) Field ¶
func (fh ForwardingHint) Field() tlv.Field
Field implements tlv.Fielder interface.
func (*ForwardingHint) UnmarshalBinary ¶
func (fh *ForwardingHint) UnmarshalBinary(wire []byte) error
UnmarshalBinary decodes from TLV-VALUE.
type HopLimit ¶
type HopLimit uint8
HopLimit represents a HopLimit field.
func (*HopLimit) UnmarshalBinary ¶
UnmarshalBinary decodes from wire encoding.
type Interest ¶
type Interest struct { Name Name CanBePrefix bool MustBeFresh bool ForwardingHint ForwardingHint Nonce Nonce Lifetime time.Duration HopLimit HopLimit AppParameters []byte SigInfo *SigInfo SigValue []byte // contains filtered or unexported fields }
Interest represents an Interest packet.
func MakeInterest ¶
MakeInterest creates an Interest from flexible arguments. Arguments can contain:
- string or Name: set Name
- CanBePrefixFlag: set CanBePrefix
- MustBeFreshFlag: set MustBeFresh
- ForwardingHint: set forwarding hint
- Nonce: set Nonce
- time.Duration: set Lifetime
- HopLimit: set HopLimit
- []byte: set AppParameters
- LpL3: copy PitToken and CongMark
func (*Interest) ApplyDefaultLifetime ¶
ApplyDefaultLifetime updates Lifetime to the default if it is not set.
func (*Interest) SignWith ¶
SignWith implements Signable interface. Caller should use signer.Sign(interest).
func (*Interest) UnmarshalBinary ¶
UnmarshalBinary decodes from TLV-VALUE.
func (*Interest) UpdateParamsDigest ¶
func (interest *Interest) UpdateParamsDigest()
UpdateParamsDigest appends or updates ParametersSha256DigestComponent. It will not remove erroneously present or duplicate ParametersSha256DigestComponent.
type KeyLocator ¶
KeyLocator represents KeyLocator in SignatureInfo.
func (KeyLocator) Empty ¶
func (kl KeyLocator) Empty() bool
Empty returns true if KeyLocator has zero fields.
func (KeyLocator) Field ¶
func (kl KeyLocator) Field() tlv.Field
Field implements tlv.Fielder interface.
func (KeyLocator) String ¶
func (kl KeyLocator) String() string
func (*KeyLocator) UnmarshalBinary ¶
func (kl *KeyLocator) UnmarshalBinary(wire []byte) error
UnmarshalBinary decodes from TLV-VALUE.
type L3Packet ¶
type L3Packet interface {
ToPacket() *Packet
}
L3Packet represents any NDN layer 3 packet.
type LpFragment ¶
type LpFragment struct { SeqNum uint64 FragIndex int FragCount int Header []byte // encoded NDNLPv2 L3 header fields Payload []byte // LpPayload TLV-VALUE }
LpFragment represents an NDNLPv2 fragmented frame.
func (LpFragment) Field ¶
func (frag LpFragment) Field() tlv.Field
Field implements tlv.Fielder interface.
func (LpFragment) String ¶
func (frag LpFragment) String() string
type LpFragmenter ¶
type LpFragmenter struct {
// contains filtered or unexported fields
}
LpFragmenter splits Packet into fragments.
func NewLpFragmenter ¶
func NewLpFragmenter(mtu int) *LpFragmenter
NewLpFragmenter creates a LpFragmenter.
type LpReassembler ¶
type LpReassembler struct {
// contains filtered or unexported fields
}
LpReassembler reassembles fragments.
func NewLpReassembler ¶
func NewLpReassembler(capacity int) *LpReassembler
NewLpReassembler creates a LpReassembler.
type Nack ¶
Nack represents a Nack packet.
Nack struct does not support encoding or decoding. Instead, you can encode nack.ToPacket(), or decode as Packet then access the Nack.
type Name ¶
type Name []NameComponent
Name represents a name. The zero Name has zero components.
func ParseName ¶
ParseName parses canonical URI representation of name. It uses best effort and can accept any input.
func (Name) Append ¶
func (name Name) Append(comps ...NameComponent) (ret Name)
Append appends zero or more components to a copy of this name.
func (Name) Compare ¶
Compare returns negative when name<other, zero when name==other, positive when name>other.
func (Name) Get ¶
func (name Name) Get(i int) NameComponent
Get returns i-th component. If negative, count from the end. If out-of-range, return invalid NameComponent.
func (Name) GetPrefix ¶
GetPrefix returns a prefix of i components. If negative, count from the end.
func (Name) IsPrefixOf ¶
IsPrefixOf returns true if this name is a prefix of other name.
func (Name) MarshalBinary ¶
MarshalBinary encodes to TLV-VALUE.
func (Name) MarshalText ¶
MarshalText implements encoding.TextMarshaler interface.
func (Name) Slice ¶
Slice returns a sub name between i-th (inclusive) and j-th (exclusive) components. j is optional; the default is toward the end. If negative, count from the end. If out-of-range, return empty name.
func (*Name) UnmarshalBinary ¶
UnmarshalBinary decodes TLV-VALUE from wire format.
func (*Name) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler interface.
type NameComponent ¶
NameComponent represents a name component. Zero value is invalid.
func DecodeFinalBlock ¶
func DecodeFinalBlock(de tlv.DecodingElement) (finalBlock NameComponent, e error)
DecodeFinalBlock decodes FinalBlock name component from FinalBlock TLV element.
func MakeNameComponent ¶
func MakeNameComponent(typ uint32, value []byte) (comp NameComponent)
MakeNameComponent constructs a NameComponent from TLV-TYPE and TLV-VALUE.
func NameComponentFrom ¶
func NameComponentFrom(typ uint32, value tlv.Fielder) NameComponent
NameComponentFrom constructs a NameComponent from TLV-TYPE and tlv.Fielder as TLV-VALUE. If value encodes to an error, returns an invalid NameComponent.
To create a name component with NonNegativeInteger as commonly used in naming conventions:
NameComponentFrom(an.VersionNameComponent, tlv.NNI(1))
func ParseNameComponent ¶
func ParseNameComponent(input string) (comp NameComponent)
ParseNameComponent parses canonical URI representation of name component. It uses best effort and can accept any input.
func (NameComponent) Compare ¶
func (comp NameComponent) Compare(other NameComponent) int
Compare returns negative when comp<other, zero when comp==other, positive when comp>other.
func (NameComponent) Equal ¶
func (comp NameComponent) Equal(other NameComponent) bool
Equal determines whether two components are the same.
func (NameComponent) Field ¶
func (comp NameComponent) Field() tlv.Field
Field implements tlv.Fielder interface.
func (NameComponent) String ¶
func (comp NameComponent) String() string
String returns URI representation of this component.
func (*NameComponent) UnmarshalTLV ¶
func (comp *NameComponent) UnmarshalTLV(typ uint32, value []byte) error
UnmarshalTLV decodes from wire format.
func (NameComponent) Valid ¶
func (comp NameComponent) Valid() bool
Valid checks whether this component has a valid TLV-TYPE.
type Nonce ¶
type Nonce [4]byte
Nonce represents an Interest Nonce.
func NonceFromUint ¶
NonceFromUint converts uint32 to Nonce, interpreted as big endian.
func (*Nonce) UnmarshalBinary ¶
UnmarshalBinary decodes from wire encoding.
type Packet ¶
type Packet struct { Lp LpL3 Fragment *LpFragment Interest *Interest Data *Data Nack *Nack // contains filtered or unexported fields }
Packet represents an NDN layer 3 packet with associated LpL3.
type SigInfo ¶
type SigInfo struct { Type uint32 KeyLocator KeyLocator Nonce []byte Time uint64 SeqNum uint64 Extensions []tlv.Element }
SigInfo represents SignatureInfo on Interest or Data.
func (*SigInfo) EncodeAs ¶
EncodeAs creates a tlv.Fielder for either ISigInfo or DSigInfo TLV-TYPE. If si is nil, the encoding result contains SigType=SigNull.
func (*SigInfo) FindExtension ¶
FindExtension retrieves extension field by TLV-TYPE number.
func (*SigInfo) UnmarshalBinary ¶
UnmarshalBinary decodes from TLV-VALUE.
type SignableVerifiable ¶
type SignableVerifiable interface { Signable Verifiable }
SignableVerifiable is both Signable and Verifiable.
type Signer ¶
Signer is high-level signer, such as a private key.
var NullSigner Signer = nullSigner{}
NullSigner implements Signer for SigNull signature type.
type SignerVerifier ¶
SignerVerifier is both Signer and Verifier.
var DigestSigning SignerVerifier = digestSigning{}
DigestSigning implements Signer and Verifier for SigSha256 signature type.
type Verifiable ¶
type Verifiable interface {
VerifyWith(verifier func(name Name, si SigInfo) (LLVerify, error)) error
}
Verifiable is a packet that can be verified.
type Verifier ¶
type Verifier interface {
Verify(packet Verifiable) error
}
Verifier is high-level verifier, such as a public key.
var NopVerifier Verifier = nopVerifier{}
NopVerifier is a Verifier that performs no verification.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package an exports Assigned Numbers in NDN.
|
Package an exports Assigned Numbers in NDN. |
Package endpoint implements basic consumer and producer functionality.
|
Package endpoint implements basic consumer and producer functionality. |
Package fch provides a simple NDN-FCH client.
|
Package fch provides a simple NDN-FCH client. |
Package keychain implements signing and verification on NDN packets.
|
Package keychain implements signing and verification on NDN packets. |
Package l3 defines a network layer face abstraction.
|
Package l3 defines a network layer face abstraction. |
Package memiftransport implements a transport over a shared memory packet interface (memif).
|
Package memiftransport implements a transport over a shared memory packet interface (memif). |
Package mgmt defines interface of forwarder management features.
|
Package mgmt defines interface of forwarder management features. |
gqlmgmt
Package gqlmgmt provides access to NDN-DPDK GraphQL API.
|
Package gqlmgmt provides access to NDN-DPDK GraphQL API. |
nfdmgmt
Package nfdmgmt provides access to NFD Management API.
|
Package nfdmgmt provides access to NFD Management API. |
Package ndnlayer provides a GoPacket layer for NDN.
|
Package ndnlayer provides a GoPacket layer for NDN. |
Package ndntestenv contains helper functions to validate NDN packets in test code.
|
Package ndntestenv contains helper functions to validate NDN packets in test code. |
tiny
Command tiny verifies that part of NDNgo library is compatible with TinyGo compiler.
|
Command tiny verifies that part of NDNgo library is compatible with TinyGo compiler. |
Package ndntestvector contains test vectors of NDN packets.
|
Package ndntestvector contains test vectors of NDN packets. |
Package packettransport implements a transport based on GoPacket library.
|
Package packettransport implements a transport based on GoPacket library. |
afpacket
Package afpacket implements a transport that communicates over AF_PACKET sockets.
|
Package afpacket implements a transport that communicates over AF_PACKET sockets. |
Package rdr implements Realtime Data Retrieval (RDR) protocol.
|
Package rdr implements Realtime Data Retrieval (RDR) protocol. |
ndn6file
Package ndn6file implements ndn6-file-server protocol.
|
Package ndn6file implements ndn6-file-server protocol. |
Package segmented publishes and retrieves segmented objects.
|
Package segmented publishes and retrieves segmented objects. |
Package sockettransport implements a transport based on stream or datagram sockets.
|
Package sockettransport implements a transport based on stream or datagram sockets. |
Package tlv implements NDN Type-Length-Value (TLV) encoding.
|
Package tlv implements NDN Type-Length-Value (TLV) encoding. |
Package wasmtransport implements l3.Transport for WebAssembly.
|
Package wasmtransport implements l3.Transport for WebAssembly. |