ndn

package module
v0.0.0-...-cd5cb16 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2017 License: GPL-2.0 Imports: 26 Imported by: 9

README

Named-Data Network (NDN)

This package provides elegant and simple ndn library for research and testing purpose. NDN evolves quickly, and the latest format that the current implementation follows is on ndn doc

GoDoc

Benchmark

2017-01

BenchmarkDataEncodeRSA-8     	     500	   2459538 ns/op
BenchmarkDataEncodeECDSA-8   	    2000	    813159 ns/op
BenchmarkDataEncodeHMAC-8    	  200000	      6028 ns/op
BenchmarkDataEncode-8        	 1000000	      1779 ns/op
BenchmarkDataDecode-8        	  500000	      3067 ns/op
BenchmarkInterestEncode-8    	 2000000	       614 ns/op
BenchmarkInterestDecode-8    	 2000000	       910 ns/op

2015-10

BenchmarkDataEncodeRSA-8         50000   2732604 ns/op
BenchmarkDataEncodeECDSA-8    200000   1135775 ns/op
BenchmarkDataEncodeHMAC-8     200000      6597 ns/op
BenchmarkDataEncode-8        1000000      1613 ns/op
BenchmarkDataDecode-8         300000      3938 ns/op
BenchmarkInterestEncode-8    2000000       616 ns/op
BenchmarkInterestDecode-8    2000000       907 ns/op

2015-03

BenchmarkDataEncodeRSA	     100	  11268142 ns/op
BenchmarkDataEncodeECDSA	    1000	   2305271 ns/op
BenchmarkDataEncode	  100000	     13603 ns/op
BenchmarkDataDecode	  100000	     18023 ns/op
BenchmarkInterestEncode	  200000	      8303 ns/op
BenchmarkInterestDecode	  200000	     11306 ns/op

2014-08

BenchmarkDataEncodeRSA	     100	  10602984 ns/op
BenchmarkDataEncodeECDSA	    1000	   2331976 ns/op
BenchmarkDataEncode	   50000	     34764 ns/op
BenchmarkDataDecode	   50000	     71636 ns/op
BenchmarkInterestEncode	  200000	     11575 ns/op
BenchmarkInterestDecode	  100000	     33929 ns/op

2014-01

BenchmarkDataSHA256Encode     100000         22272 ns/op
BenchmarkDataSHA256Decode     100000         27381 ns/op
BenchmarkDataRSAEncode       100      23419913 ns/op
BenchmarkDataRSADecode     50000         68238 ns/op
BenchmarkInterestEncode   200000          9064 ns/op
BenchmarkInterestDecode   100000         17223 ns/op

Note: RSA key is 2048 bits. ECDSA uses P224.

Documentation

Overview

Package ndn implements named-data networking.

Index

Constants

View Source
const (
	CompressionTypeNone uint64 = 0
	CompressionTypeGZIP        = 1
)

CompressionType specifies compression algorithm for data packets.

View Source
const (
	CacheControlPublic  uint64 = 0
	CacheControlNoStore        = 1
	CacheControlPrivate        = 2
)

CacheControl specifies caching strategy for data packets.

View Source
const (
	EncryptionTypeNone       uint64 = 0
	EncryptionTypeAESWithCTR        = 1
)

EncryptionType specifies encryption algorithm for data packets.

View Source
const (
	SignatureTypeDigestSHA256    uint64 = 0
	SignatureTypeSHA256WithRSA          = 1
	SignatureTypeDigestCRC32C           = 2
	SignatureTypeSHA256WithECDSA        = 3
	SignatureTypeSHA256WithHMAC         = 4
)

SignatureType specifies signing algorithm for data packets.

View Source
const (
	ISO8601 = "20060102T150405"
)

ISO8601 is the time format for ValidityPeriod.

Variables

View Source
var (
	ErrNotSupported     = errors.New("feature not supported")
	ErrInvalidSignature = errors.New("invalid signature")
	ErrInvalidPEM       = errors.New("invalid pem")
)

Errors introduced by Key.

View Source
var (
	ErrTimeout        = errors.New("timeout")
	ErrResponseStatus = errors.New("bad command response status")
)

Errors introduced by communicating with forwarder.

Functions

func EncodeCertificate

func EncodeCertificate(key Key, w io.Writer) error

EncodeCertificate invokes CertificateToData and encodes this data packet in base64 encoding.

See DecodeCertificate.

func EncodePrivateKey

func EncodePrivateKey(key Key, w io.Writer) error

EncodePrivateKey encodes the private key in PEM encoding.

See DecodePrivateKey.

func NewCRC32C

func NewCRC32C() hash.Hash

NewCRC32C creates a new CRC32C hash.

func SendControl

func SendControl(w Sender, module, command string, params *Parameters, key Key) error

SendControl sends command and waits for its response.

ErrResponseStatus is returned if the status code is not 200.

func SignData

func SignData(key Key, d *Data) (err error)

SignData signs a data packet with the given key.

func VerifyData

func VerifyData(key Key, d *Data) error

VerifyData verifies a data packet with the given key.

It also checks ValidityPeriod.

Types

type Cache

type Cache interface {
	Add(*Data)
	Get(*Interest) *Data
}

Cache stores data packet and finds data packet by interest

func NewCache

func NewCache(size int) Cache

NewCache creates a new thread-safe in-memory LRU content store

type Command

type Command struct {
	Local          string                  `tlv:"8"`
	NFD            string                  `tlv:"8"`
	Module         string                  `tlv:"8"`
	Command        string                  `tlv:"8"`
	Parameters     parametersComponent     `tlv:"8"`
	Timestamp      uint64                  `tlv:"8"`
	Nonce          uint64                  `tlv:"8"`
	SignatureInfo  signatureInfoComponent  `tlv:"8"`
	SignatureValue signatureValueComponent `tlv:"8*"`
}

Command alters forwarder state.

See http://redmine.named-data.net/projects/nfd/wiki/Management.

func (*Command) ReadFrom

func (cmd *Command) ReadFrom(r tlv.Reader) error

ReadFrom implements tlv.ReadFrom.

func (*Command) WriteTo

func (cmd *Command) WriteTo(w tlv.Writer) error

WriteTo implements tlv.WriteTo.

type CommandResponse

type CommandResponse struct {
	StatusCode uint64     `tlv:"102"`
	StatusText string     `tlv:"103"`
	Parameters Parameters `tlv:"104?"`
}

CommandResponse contains status code and text.

StatusCode generally follows HTTP convention [RFC2616].

type Data

type Data struct {
	Name           Name          `tlv:"7"`
	MetaInfo       MetaInfo      `tlv:"20"`
	Content        []byte        `tlv:"21"`
	SignatureInfo  SignatureInfo `tlv:"22"`
	SignatureValue []byte        `tlv:"23*"`
}

Data represents some arbitrary binary data (held in the Content element) together with its Name, some additional bits of information (MetaInfo), and a digital Signature of the other three elements.

func CertificateToData

func CertificateToData(key Key) (d *Data, err error)

CertificateToData creates a data packet from a self-signed public key.

See CertificateFromData.

func (*Data) ReadFrom

func (d *Data) ReadFrom(r tlv.Reader) error

ReadFrom implements tlv.ReadFrom.

Signature will not be verified.

func (*Data) WriteTo

func (d *Data) WriteTo(w tlv.Writer) error

WriteTo implements tlv.WriteTo.

SHA256 digest will be populated if SignatureValue is empty.

type ECDSAKey

type ECDSAKey struct {
	Name
	*ecdsa.PrivateKey
}

ECDSAKey implements Key.

func (*ECDSAKey) Locator

func (key *ECDSAKey) Locator() Name

Locator returns public key locator.

func (*ECDSAKey) Private

func (key *ECDSAKey) Private() ([]byte, error)

Private encodes private key.

func (*ECDSAKey) Public

func (key *ECDSAKey) Public() ([]byte, error)

Public encodes public key.

func (*ECDSAKey) Sign

func (key *ECDSAKey) Sign(v interface{}) ([]byte, error)

Sign creates signature.

func (*ECDSAKey) SignatureType

func (key *ECDSAKey) SignatureType() uint64

SignatureType returns signature type generated from the key.

func (*ECDSAKey) Verify

func (key *ECDSAKey) Verify(v interface{}, signature []byte) error

Verify checks signature.

type Exclude

type Exclude []Interval

Exclude allows requester to specify list and/or ranges of names components that MUST NOT appear as a continuation of the Name prefix in the responding Data packet to the Interest.

See http://named-data.net/doc/ndn-tlv/interest.html#exclude.

func (Exclude) MarshalBinary

func (ex Exclude) MarshalBinary() ([]byte, error)

MarshalBinary encodes Exclude in tlv.

Exclude is a special case in tlv package. It needs to implement encoding.BinaryMarshaler to marshal itself into a binary form.

func (Exclude) Match

func (ex Exclude) Match(c lpm.Component) bool

Match checks whether the given component is in the intervals.

func (*Exclude) UnmarshalBinary

func (ex *Exclude) UnmarshalBinary(b []byte) error

UnmarshalBinary decodes Exclude tlv-encoded data.

Exclude is a special case in tlv package. It needs to implement encoding.BinaryUnmarshaler to unmarshal a binary representation of itself.

type FIBEntry

type FIBEntry struct {
	Name    Name            `tlv:"7"`
	NextHop []NextHopRecord `tlv:"129"`
}

FIBEntry is not available in go-nfd.

type Face

type Face interface {
	Sender
	LocalAddr() net.Addr
	RemoteAddr() net.Addr
	Close() error
}

Face implements Sender.

func NewFace

func NewFace(transport net.Conn, recv chan<- *Interest) Face

NewFace creates a face from net.Conn.

recv is the incoming interest queue. If it is nil, incoming interests will be ignored. Otherwise, this queue must be handled before it is full.

type FaceStatus

type FaceStatus struct {
	FaceID           uint64 `tlv:"105"`
	URI              string `tlv:"114"`
	LocalURI         string `tlv:"129"`
	ExpirationPeriod uint64 `tlv:"109?"`
	Scope            uint64 `tlv:"132"`
	Persistency      uint64 `tlv:"133"`
	LinkType         uint64 `tlv:"134"`
	Flags            uint64 `tlv:"108"`
	InInterest       uint64 `tlv:"144"`
	InData           uint64 `tlv:"145"`
	InNack           uint64 `tlv:"151"`
	OutInterest      uint64 `tlv:"146"`
	OutData          uint64 `tlv:"147"`
	OutNack          uint64 `tlv:"152"`
	InByte           uint64 `tlv:"148"`
	OutByte          uint64 `tlv:"149"`
}

FaceStatus is not available in go-nfd.

type FinalBlockID

type FinalBlockID struct {
	Component lpm.Component `tlv:"8"`
}

FinalBlockID indicates the identifier of the final block in a sequence of fragments. It should be present in the final block itself, and may also be present in other fragments to provide advanced warning of the end to consumers. The value here should be equal to the last explicit Name Component of the final block.

type ForwarderStatus

type ForwarderStatus struct {
	NFDVersion       string `tlv:"128"`
	StartTimestamp   uint64 `tlv:"129"`
	CurrentTimestamp uint64 `tlv:"130"`
	NameTreeEntry    uint64 `tlv:"131"`
	FIBEntry         uint64 `tlv:"132"`
	PITEntry         uint64 `tlv:"133"`
	MeasurementEntry uint64 `tlv:"134"`
	CSEntry          uint64 `tlv:"135"`
	InInterest       uint64 `tlv:"144"`
	InData           uint64 `tlv:"145"`
	InNack           uint64 `tlv:"151"`
	OutInterest      uint64 `tlv:"146"`
	OutData          uint64 `tlv:"147"`
	OutNack          uint64 `tlv:"152"`
}

ForwarderStatus is not available in go-nfd.

type HMACKey

type HMACKey struct {
	Name
	PrivateKey []byte
}

HMACKey implements Key.

func (*HMACKey) Locator

func (key *HMACKey) Locator() Name

Locator returns public key locator.

func (*HMACKey) Private

func (key *HMACKey) Private() ([]byte, error)

Private encodes private key.

func (*HMACKey) Public

func (key *HMACKey) Public() ([]byte, error)

Public encodes public key.

func (*HMACKey) Sign

func (key *HMACKey) Sign(v interface{}) ([]byte, error)

Sign creates signature.

func (*HMACKey) SignatureType

func (key *HMACKey) SignatureType() uint64

SignatureType returns signature type generated from the key.

func (*HMACKey) Verify

func (key *HMACKey) Verify(v interface{}, signature []byte) error

Verify checks signature.

type Interest

type Interest struct {
	Name      Name      `tlv:"7"`
	Selectors Selectors `tlv:"9?"`
	Nonce     uint64    `tlv:"10"`
	LifeTime  uint64    `tlv:"12?"`
}

Interest carries a name that identifies the desired data.

func (*Interest) ReadFrom

func (i *Interest) ReadFrom(r tlv.Reader) error

ReadFrom implements tlv.ReadFrom.

func (*Interest) WriteTo

func (i *Interest) WriteTo(w tlv.Writer) error

WriteTo implements tlv.WriteTo.

Nonce will be populated if it is empty.

type Interval

type Interval struct {
	lpm.Component
	Any bool // Component..?
}

Interval is part of an Exclude list.

If none of the Any components are specified, the filter excludes only to the names specified in the Exclude list.

If a leading Any component is specified, then the filter excludes all names that are smaller or equal (in NDN name component canonical ordering) to the first NameComponent in the Exclude list.

If a trailing Any component is specified, then the filter excludes all names that are larger or equal (in NDN name component canonical ordering) to the last NameComponent in the Exclude list.

If Any component is specified between two NameComponents in the list, then the filter excludes all names from the range from the right NameComponent to the left NameComponent, including both ends.

type Key

type Key interface {
	Locator() Name
	SignatureType() uint64
	// If the key is symmetric, Private is identical to Public.
	Private() ([]byte, error)
	Public() ([]byte, error)

	Sign(interface{}) ([]byte, error)
	Verify(interface{}, []byte) error
}

Key signs and verifies data packets.

func CertificateFromData

func CertificateFromData(d *Data) (key Key, err error)

CertificateFromData creates a public key from a data packet.

See CertificateToData.

func DecodeCertificate

func DecodeCertificate(r io.Reader) (key Key, err error)

DecodeCertificate decodes a data packet in base64 encoding, and invokes CertificateFromData.

See EncodeCertificate.

func DecodePrivateKey

func DecodePrivateKey(r io.Reader) (key Key, err error)

DecodePrivateKey decodes the private key in PEM encoding.

See EncodePrivateKey.

type KeyLocator

type KeyLocator struct {
	Name   Name   `tlv:"7?"`
	Digest []byte `tlv:"29?"`
}

KeyLocator specifies either Name that points to another Data packet containing certificate or public key or KeyDigest to identify the public key within a specific trust model.

type MetaInfo

type MetaInfo struct {
	ContentType          uint64       `tlv:"24?"`
	FreshnessPeriod      uint64       `tlv:"25?"`
	FinalBlockID         FinalBlockID `tlv:"26?"`
	CompressionType      uint64       `tlv:"128?"`
	EncryptionType       uint64       `tlv:"129?"`
	EncryptionKeyLocator KeyLocator   `tlv:"130?"`
	EncryptionIV         []byte       `tlv:"131?"`
	CacheControl         uint64       `tlv:"132?"`
}

MetaInfo contains information about the data packet itself.

type Name

type Name struct {
	Components           []lpm.Component `tlv:"8"`
	ImplicitDigestSHA256 lpm.Component   `tlv:"1?"`
}

Name is a hierarchical name for NDN content, which contains a sequence of name components.

func NewName

func NewName(s string) (n Name)

NewName creates a name by invoking lpm.NewComponents.

func (*Name) Compare

func (n *Name) Compare(n2 Name) int

Compare compares two names according to http://named-data.net/doc/ndn-tlv/name.html#canonical-order.

-1 if a < b; 0 if a == b; 1 if a > b

func (*Name) Len

func (n *Name) Len() int

Len returns the number of components.

func (*Name) ReadFrom

func (n *Name) ReadFrom(r tlv.Reader) error

ReadFrom implements tlv.ReadFrom

func (Name) String

func (n Name) String() string

func (*Name) WriteTo

func (n *Name) WriteTo(w tlv.Writer) error

WriteTo implements tlv.WriteTo

type NextHopRecord

type NextHopRecord struct {
	FaceID uint64 `tlv:"105"`
	Cost   uint64 `tlv:"106"`
}

NextHopRecord is not available in go-nfd.

type Parameters

type Parameters struct {
	Name             Name     `tlv:"7?"`
	FaceID           uint64   `tlv:"105?"`
	URI              string   `tlv:"114?"`
	Origin           uint64   `tlv:"111?"`
	Cost             uint64   `tlv:"106?"`
	Flags            uint64   `tlv:"108?"`
	Mask             uint64   `tlv:"112?"`
	Strategy         Strategy `tlv:"107?"`
	ExpirationPeriod uint64   `tlv:"109?"`
	FacePersistency  uint64   `tlv:"133?"`
}

Parameters contains arguments to command.

type RIBEntry

type RIBEntry struct {
	Name  Name    `tlv:"7"`
	Route []Route `tlv:"129"`
}

RIBEntry specifies all routes under a name.

type RSAKey

type RSAKey struct {
	Name
	*rsa.PrivateKey
}

RSAKey implements Key.

func (*RSAKey) Locator

func (key *RSAKey) Locator() Name

Locator returns public key locator.

func (*RSAKey) Private

func (key *RSAKey) Private() ([]byte, error)

Private encodes private key.

func (*RSAKey) Public

func (key *RSAKey) Public() ([]byte, error)

Public encodes public key.

func (*RSAKey) Sign

func (key *RSAKey) Sign(v interface{}) ([]byte, error)

Sign creates signature.

func (*RSAKey) SignatureType

func (key *RSAKey) SignatureType() uint64

SignatureType returns signature type generated from the key.

func (*RSAKey) Verify

func (key *RSAKey) Verify(v interface{}, signature []byte) error

Verify checks signature.

type Route

type Route struct {
	FaceID           uint64 `tlv:"105"`
	Origin           uint64 `tlv:"111"`
	Cost             uint64 `tlv:"106"`
	Flags            uint64 `tlv:"108"`
	ExpirationPeriod uint64 `tlv:"109?"`
}

Route contains information about a route.

type Selectors

type Selectors struct {
	MinComponents             uint64     `tlv:"133?"`
	MaxComponents             uint64     `tlv:"134?"`
	PublisherPublicKeyLocator KeyLocator `tlv:"15?"`
	Exclude                   Exclude    `tlv:"16?"`
	ChildSelector             uint64     `tlv:"17?"`
	MustBeFresh               bool       `tlv:"18?"`
}

Selectors are optional elements that further qualify Data that may match the Interest. They are used for discovering and selecting the Data that matches best to what the application wants.

func (*Selectors) Match

func (sel *Selectors) Match(d *Data, interestLen int) bool

Match does not handle ChildSelector and MustBeFresh.

type Sender

type Sender interface {
	SendInterest(*Interest) (*Data, error)
	SendData(*Data) error
}

Sender sends interest and data packets. This is the minimum abstraction for NDN nodes.

type SignatureInfo

type SignatureInfo struct {
	SignatureType  uint64         `tlv:"27"`
	KeyLocator     KeyLocator     `tlv:"28?"`
	ValidityPeriod ValidityPeriod `tlv:"253?"`
}

SignatureInfo is included in signature calculation and fully describes the signature, signature algorithm, and any other relevant information to obtain parent certificate(s), such as KeyLocator.

type Strategy

type Strategy struct {
	Name Name `tlv:"7"`
}

Strategy is a forwarding strategy for a namespace.

type StrategyChoice

type StrategyChoice struct {
	Name     Name     `tlv:"7"`
	Strategy Strategy `tlv:"107"`
}

StrategyChoice is not available in go-nfd.

type ValidityPeriod

type ValidityPeriod struct {
	NotBefore string `tlv:"254"`
	NotAfter  string `tlv:"255"`
}

ValidityPeriod specifies a range when the signature is valid.

Jump to

Keyboard shortcuts

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