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 - Packet Link protocol: - LpPacket Security abstraction: - Signer - Verifier
Index ¶
- Constants
- Variables
- func PitTokenFromUint(n uint64) []byte
- func PitTokenToUint(token []byte) uint64
- func RegisterSigInfoExtension(typ uint32)
- type ContentType
- type Data
- func (data Data) CanSatisfy(interest Interest) bool
- func (data Data) ComputeDigest() []byte
- func (data Data) FullName() Name
- func (data Data) MarshalTlv() (typ uint32, value []byte, e error)
- func (data *Data) SignWith(signer func(name Name, si *SigInfo) (LLSign, error)) error
- func (data Data) String() string
- func (data Data) ToPacket() *Packet
- func (data *Data) UnmarshalBinary(wire []byte) error
- func (data Data) VerifyWith(verifier func(name Name, si SigInfo) (LLVerify, error)) error
- type FHDelegation
- type ForwardingHint
- type HopLimit
- type Interest
- func (interest *Interest) ApplyDefaultLifetime() time.Duration
- func (interest Interest) MarshalTlv() (typ uint32, value []byte, e error)
- func (interest *Interest) SignWith(signer func(name Name, si *SigInfo) (LLSign, error)) error
- func (interest Interest) String() string
- func (interest Interest) ToPacket() *Packet
- func (interest *Interest) UnmarshalBinary(wire []byte) 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 LpL3
- type LpPacket
- type Name
- func (name Name) Compare(other Name) int
- func (name Name) Equal(other Name) bool
- 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) MarshalTlv() (typ uint32, value []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) MarshalTlv() (typ uint32, value []byte, e error)
- func (comp NameComponent) String() string
- func (comp *NameComponent) UnmarshalTlv(typ uint32, value []byte) error
- func (comp NameComponent) Valid() bool
- type Nonce
- type Packet
- type PrefixAnnouncement
- type SelfLearningHeaders
- type SigInfo
- type Signable
- type SignableVerifiable
- type Signer
- type SignerVerifier
- type ValidityPeriod
- 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 NewInterest. CanBePrefixFlag = tCanBePrefix(true) // MustBeFreshFlag enables MustBeFresh in NewInterest. MustBeFreshFlag = tMustBeFresh(true) )
Variables ¶
var ( ErrNotLpFrame = errors.New("not NDNLPv2 frame") ErrUnexpectedElem = errors.New("unexpected TLV element") ErrFragment = errors.New("bad fragment") ErrReliability = errors.New("error encoding reliability headers") ErrSequenceSize = errors.New("sequence number not 8 octets") 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") ErrSigType = errors.New("bad SigType") ErrKeyLocator = errors.New("bad KeyLocator") ErrSigNonce = errors.New("bad SigNonce") ErrSigValue = errors.New("bad SigValue") )
Simple error conditions.
Functions ¶
func PitTokenFromUint ¶
PitTokenFromUint creates a PIT token from uint64, interpreted as big endian.
func PitTokenToUint ¶
PitTokenToUint reads a 8-octet PIT token as uint64, interpreted as big endian. Returns 0 if the input token is not 8 octets.
func RegisterSigInfoExtension ¶
func RegisterSigInfoExtension(typ uint32)
RegisterSigInfoExtension registers an extension TLV-TYPE in SigInfo.
Types ¶
type ContentType ¶
type ContentType uint
ContentType represents a ContentType field.
func (ContentType) MarshalTlv ¶
func (ct ContentType) MarshalTlv() (typ uint32, value []byte, e error)
MarshalTlv encodes this ContentType.
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 Content []byte SigInfo *SigInfo SigValue []byte // contains filtered or unexported fields }
Data represents a Data packet.
func MakeData ¶
func MakeData(args ...interface{}) (data Data)
MakeData creates a Data from flexible arguments. Arguments can contain:
- string or Name: set Name
- ContentType
- time.Duration: set Freshness
- []byte: set Content
- LpL3: copy PitToken and CongMark
- Interest or *Interest: copy Name, set FreshnessPeriod if Interest has MustBeFresh, inherit LpL3
func (Data) CanSatisfy ¶
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) MarshalTlv ¶
MarshalTlv encodes this Data.
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 FHDelegation ¶
FHDelegation represents a delegation of forwarding hint.
func MakeFHDelegation ¶
func MakeFHDelegation(preference int, name interface{}) (del FHDelegation)
MakeFHDelegation creates a delegation. name should be either Name or string.
func (FHDelegation) MarshalTlv ¶
func (del FHDelegation) MarshalTlv() (typ uint32, value []byte, e error)
MarshalTlv encodes this delegation.
func (*FHDelegation) UnmarshalBinary ¶
func (del *FHDelegation) UnmarshalBinary(wire []byte) error
UnmarshalBinary decodes from TLV-VALUE.
type ForwardingHint ¶
type ForwardingHint []FHDelegation
ForwardingHint represents a forwarding hint.
func (*ForwardingHint) Append ¶
func (fh *ForwardingHint) Append(preference int, name interface{})
Append adds a delegation. name should be either Name or string.
func (ForwardingHint) MarshalTlv ¶
func (fh ForwardingHint) MarshalTlv() (typ uint32, value []byte, e error)
MarshalTlv encodes this forwarding hint.
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) MarshalTlv ¶
MarshalTlv encodes this HopLimit.
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 ¶
func MakeInterest(args ...interface{}) (interest Interest)
MakeInterest creates an Interest from flexible arguments. Arguments can contain:
- string or Name: set Name
- CanBePrefixFlag: set CanBePrefix
- MustBeFreshFlag: set MustBeFresh
- FHDelegation: append forwarding hint delegation
- 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) MarshalTlv ¶
MarshalTlv encodes this Interest.
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) MarshalTlv ¶
func (kl KeyLocator) MarshalTlv() (typ uint32, value []byte, e error)
MarshalTlv encodes this KeyLocator.
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 LpL3 ¶
type LpL3 struct { PitToken []byte NextHopFaceID uint64 IncomingFaceID uint64 CachePolicyType uint64 // CachePolicy wrapper is implicit CongestionMark uint64 }
LpL3 contains layer 3 fields in NDNLPv2 header.
type LpPacket ¶
type LpPacket struct { Sequence util.Optional FragIndex int FragCount int Acks []uint64 TxSequence util.Optional SelfLearningHeaders SelfLearningHeaders LpFragment *Packet }
LpPacket represents an NDNLPv2 frame.
func (LpPacket) MarshalTlv ¶
MarshalTlv encodes this frame.
type Name ¶
type Name []NameComponent
Name represents a name. The zero Name has zero components.
func ParseName ¶
ParseName parses URI representation of name. It uses best effort and can accept any input.
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 TLV-VALUE of this name.
func (Name) MarshalText ¶
MarshalText implements encoding.TextMarshaler interface.
func (Name) MarshalTlv ¶
MarshalTlv encodes this name.
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. The zero NameComponent is invalid.
func MakeNameComponent ¶
func MakeNameComponent(typ uint32, value []byte) (comp NameComponent)
MakeNameComponent constructs a NameComponent from TLV-TYPE and TLV-VALUE.
func ParseNameComponent ¶
func ParseNameComponent(input string) (comp NameComponent)
ParseNameComponent parses 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) MarshalTlv ¶
func (comp NameComponent) MarshalTlv() (typ uint32, value []byte, e error)
MarshalTlv encodes this component.
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) MarshalTlv ¶
MarshalTlv encodes this Nonce.
func (*Nonce) UnmarshalBinary ¶
UnmarshalBinary decodes from wire encoding.
type Packet ¶
type Packet struct { Lp LpL3 Interest *Interest Data *Data // contains filtered or unexported fields }
Packet represents an NDN layer 3 packet with associated LpL3.
func (*Packet) MarshalTlv ¶
MarshalTlv encodes this packet.
type PrefixAnnouncement ¶
type PrefixAnnouncement struct { ExpirationPeriod int ValidityPeriod ValidityPeriod }
PrefixAnnouncement holds the Content field of a prefix announcement object.
func (PrefixAnnouncement) MarshalTlv ¶
func (a PrefixAnnouncement) MarshalTlv() (typ uint32, value []byte, e error)
MarshalTlv encodes this PrefixAnnouncment.
type SelfLearningHeaders ¶
SelfLearningHeaders represents frame headers for self-learning.
func (SelfLearningHeaders) Empty ¶
func (slh SelfLearningHeaders) Empty() bool
Empty returns true if SelfLearningHeaders has zero fields.
func (SelfLearningHeaders) Encode ¶
func (slh SelfLearningHeaders) Encode() (fields []interface{}, err error)
Encode encodes the self-learning headers
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 an encodable object for either ISigInfo or DSigInfo TLV-TYPE. If si is nil, the encoding result contains SigType=SigNull.
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 ValidityPeriod ¶
ValidityPeriod contains two timestamps indicating a temporal range of validity.
func (ValidityPeriod) MarshalTlv ¶
func (v ValidityPeriod) MarshalTlv() (typ uint32, value []byte, e error)
MarshalTlv encodes this ValidityPeriod.
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 contains Assigned Numbers in Named Data Networking (NDN).
|
Package an contains Assigned Numbers in Named Data Networking (NDN). |
Package keychain implements signing and verification on NDN packets.
|
Package keychain implements signing and verification on NDN packets. |
eckey
Package eckey implements SigSha256WithEcdsa signature type.
|
Package eckey implements SigSha256WithEcdsa signature type. |
rsakey
Package rsakey implements SigSha256WithRsa signature type.
|
Package rsakey implements SigSha256WithRsa signature type. |
Package l3 defines a network layer face abstraction.
|
Package l3 defines a network layer face abstraction. |
Package ndntestenv contains helper functions to validate NDN packets in test code.
|
Package ndntestenv contains helper functions to validate NDN packets in test code. |
Package ndntestvector contains test vectors of NDN packets.
|
Package ndntestvector contains test vectors of NDN packets. |
Package tlv implements Type-Length-Value (TLV) encoding in Named Data Networking (NDN).
|
Package tlv implements Type-Length-Value (TLV) encoding in Named Data Networking (NDN). |