mux

package module
v0.0.0-...-9e76cf7 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: 25 Imported by: 7

README

mux

A light-weight NDN application framework that is inspired by express and sinatra.

GoDoc

Available middleware/handler

  • Cacher
  • Logger
  • Segmentor
  • Assembler
  • ChecksumVerifier
  • FileServer
  • StaticFile
  • Encryptor
  • Decryptor
  • Gzipper
  • Gunzipper
  • Signer
  • Verifier
  • Versioner
  • Queuer
  • Listener

Documentation

Overview

Package mux implements a light-weight NDN application framework.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUntrustedKeyName = errors.New("untrusted key name")
	ErrUntrustedData    = errors.New("untrusted data")
	ErrFetchKey         = errors.New("cannot fetch key")
)

Errors returned by Verifier.

View Source
var Cacher = RawCacher(&CacherOptions{
	Cache: ndn.NewCache(65536),
	Copy:  true,
})

Cacher creates a new Cacher middleware instance from the default content store.

View Source
var (
	ErrInvalidChecksum = errors.New("invalid checksum")
)

Errors returned by ChecksumVerifier.

Functions

func Notify

func Notify(listener, dataName string) ndn.Name

Notify returns an interest name to notify that the data packet is ready.

See Listener.

Types

type CacherOptions

type CacherOptions struct {
	Cache       ndn.Cache
	Copy        bool
	SkipPrivate bool
}

CacherOptions specifies how RawCacher serves data.

type Fetcher

type Fetcher struct {
	Handler
}

Fetcher fetches data packets.

func NewFetcher

func NewFetcher() *Fetcher

NewFetcher creates a new fetcher.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(remote ndn.Sender, i *ndn.Interest, mw ...Middleware) ([]byte, error)

Fetch applies added middleware, and fetches a data packet in the end.

Additional one-time middleware will be added after the ones added by invoking Use.

func (*Fetcher) Use

func (f *Fetcher) Use(m Middleware)

Use adds middleware that will be used when Fetch is invoked.

type Handler

type Handler interface {
	ServeNDN(ndn.Sender, *ndn.Interest) error
}

Handler serves interests by invoking SendData and SendInterest from Sender.

func Assembler

func Assembler(next Handler) Handler

Assembler assembles packets broken down by Segmentor.

FinalBlockID is unset after assembly.

See Segmentor.

func ChecksumVerifier

func ChecksumVerifier(next Handler) Handler

ChecksumVerifier verifies packet checksum like SHA256 and CRC32C.

If the signature type is not a supported digest type, that data packet is allowed to pass through without verification.

To verify signature, see Verifier.

func FileServer

func FileServer(from, to string) (string, Handler)

FileServer replaces an interest's prefix to form a file path, and serves a directory on file system.

func Gunzipper

func Gunzipper(next Handler) Handler

Gunzipper decompresses data packets compressed by Gzipper.

See Gzipper.

func Gzipper

func Gzipper(next Handler) Handler

Gzipper compresses data packets with GZIP.

See Gunzipper.

func Listener

func Listener(name string, h func(string, ndn.Sender, *ndn.Interest) error) (string, Handler)

Listener listens to notifications.

The first argument of h is the data name notified from remote.

See Notify.

func Logger

func Logger(next Handler) Handler

Logger prints total time to serve an interest to os.Stderr.

func Queuer

func Queuer(next Handler) Handler

Queuer sends data packets after Handler returns.

By default, data packets are sent as soon as SendData is invoked. It is often used with RawCacher and Segmentor to ensure that all segmented packets are successfully added to the content store before the first segment is sent to the consumer.

func StaticFile

func StaticFile(path string) (string, Handler)

StaticFile serves a file that contains a data packet encoded in base64.

It is often used to serve a certificate.

func Versioner

func Versioner(next Handler) Handler

Versioner adds timestamp version to a data packet.

type HandlerFunc

type HandlerFunc func(ndn.Sender, *ndn.Interest) error

HandlerFunc is a function that implements Handler.

func (HandlerFunc) ServeNDN

func (f HandlerFunc) ServeNDN(w ndn.Sender, i *ndn.Interest) error

ServeNDN calls the function itself to serve interests.

type Hijacker

type Hijacker interface {
	Hijack() ndn.Sender
}

Hijacker returns underlying Sender.

type Middleware

type Middleware func(Handler) Handler

Middleware transforms one Handler into another.

One can create an arbitrarily long handler chain by nesting middleware.

func Decryptor

func Decryptor(pri *ndn.RSAKey) Middleware

Decryptor decrypts data packets encrypted from encryptor.

It fetches encryped AES content key, and uses its private RSA key to decrypt this AES key. Later this AES key will be used to decrypt data packets.

See Encryptor.

func Encryptor

func Encryptor(keyLocator string, pub ...*ndn.RSAKey) Middleware

Encryptor generates a random AES content key, and encrypts data packets with AES-128 in CTR mode. Then this AES key is encrypted by peers' RSA public keys for distribution (RSA-OAEP).

It does not register keyLocator.

See Decryptor.

func RawCacher

func RawCacher(opt *CacherOptions) Middleware

RawCacher allows data packets to be served from content store directly.

If cpy is true, data packets will be copied when they are added to and retrieved from content store.

func Segmentor

func Segmentor(size int) Middleware

Segmentor breaks a data packet into many by cutting its content with the given size in byte.

FinalBlockID is set on the last segment of the data packet.

See Assembler.

func Signer

func Signer(key ndn.Key) Middleware

Signer signs data packets with the given key.

See Verifier.

func Verifier

func Verifier(rule ...*VerifyRule) Middleware

Verifier checks packet signature.

To verify checksum, see ChecksumVerifier.

type Mux

type Mux struct {
	Handler
	// contains filtered or unexported fields
}

Mux routes an interest to the handler with the longest matching prefix.

func New

func New() *Mux

New creates a new mux.

func (*Mux) Handle

func (mux *Mux) Handle(name string, h Handler, mw ...Middleware)

Handle adds Handler after additional route-specific middleware is applied.

func (*Mux) HandleFunc

func (mux *Mux) HandleFunc(name string, h HandlerFunc, mw ...Middleware)

HandleFunc adds HandlerFunc like Handle.

func (*Mux) Register

func (mux *Mux) Register(w ndn.Sender, key ndn.Key) error

Register registers mux prefixes to nfd.

func (*Mux) Run

func (mux *Mux) Run(w ndn.Sender, ch <-chan *ndn.Interest, key ndn.Key)

Run invokes Register periodically, and serves each incoming interest in a separate goroutine.

func (*Mux) Use

func (mux *Mux) Use(m Middleware)

Use adds middleware that will be used when ServeNDN is invoked.

type Publisher

type Publisher struct {
	ndn.Cache
	// contains filtered or unexported fields
}

Publisher publishes data packets to content store. Typically, it is used with RawCacher, so that the published data is immediately available.

func NewPublisher

func NewPublisher(cache ndn.Cache) *Publisher

NewPublisher creates a new publisher.

func (*Publisher) Publish

func (p *Publisher) Publish(d *ndn.Data, mw ...Middleware) error

Publish applies added middleware, and publishes data packets to content store in the end.

Additional one-time middleware will be added after the ones added by invoking Use.

func (*Publisher) Use

func (p *Publisher) Use(m Middleware)

Use adds middleware that will be used when Publish is invoked.

type VerifyRule

type VerifyRule struct {
	DataPattern string

	KeyPattern string
	DataSHA256 string
	// contains filtered or unexported fields
}

VerifyRule specifies a trust model.

The first rule that has matching DataPattern RE2 regexp is applied. If there is no rule found, verification fails, and the data packet is dropped. DataPattern RE2 regexp capture transforms KeyPattern to match signature key locator. Finally DataSHA256 is used to check the trust anchor.

See https://github.com/google/re2/wiki/Syntax.

Jump to

Keyboard shortcuts

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