Documentation
¶
Overview ¶
Package mux implements a light-weight NDN application framework.
Index ¶
- Variables
- func Notify(listener, dataName string) ndn.Name
- type CacherOptions
- type Fetcher
- type Handler
- func Assembler(next Handler) Handler
- func ChecksumVerifier(next Handler) Handler
- func FileServer(from, to string) (string, Handler)
- func Gunzipper(next Handler) Handler
- func Gzipper(next Handler) Handler
- func Listener(name string, h func(string, ndn.Sender, *ndn.Interest) error) (string, Handler)
- func Logger(next Handler) Handler
- func Queuer(next Handler) Handler
- func StaticFile(path string) (string, Handler)
- func Versioner(next Handler) Handler
- type HandlerFunc
- type Hijacker
- type Middleware
- type Mux
- func (mux *Mux) Handle(name string, h Handler, mw ...Middleware)
- func (mux *Mux) HandleFunc(name string, h HandlerFunc, mw ...Middleware)
- func (mux *Mux) Register(w ndn.Sender, key ndn.Key) error
- func (mux *Mux) Run(w ndn.Sender, ch <-chan *ndn.Interest, key ndn.Key)
- func (mux *Mux) Use(m Middleware)
- type Publisher
- type VerifyRule
Constants ¶
This section is empty.
Variables ¶
var ( ErrUntrustedKeyName = errors.New("untrusted key name") ErrUntrustedData = errors.New("untrusted data") ErrFetchKey = errors.New("cannot fetch key") )
Errors returned by Verifier.
var Cacher = RawCacher(&CacherOptions{ Cache: ndn.NewCache(65536), Copy: true, })
Cacher creates a new Cacher middleware instance from the default content store.
var (
ErrInvalidChecksum = errors.New("invalid checksum")
)
Errors returned by ChecksumVerifier.
Functions ¶
Types ¶
type CacherOptions ¶
CacherOptions specifies how RawCacher serves data.
type Fetcher ¶
type Fetcher struct {
Handler
}
Fetcher fetches data packets.
func (*Fetcher) Fetch ¶
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 ¶
Handler serves interests by invoking SendData and SendInterest from Sender.
func Assembler ¶
Assembler assembles packets broken down by Segmentor.
FinalBlockID is unset after assembly.
See Segmentor.
func ChecksumVerifier ¶
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 ¶
FileServer replaces an interest's prefix to form a file path, and serves a directory on file system.
func Listener ¶
Listener listens to notifications.
The first argument of h is the data name notified from remote.
See Notify.
func Queuer ¶
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 ¶
StaticFile serves a file that contains a data packet encoded in base64.
It is often used to serve a certificate.
type HandlerFunc ¶
HandlerFunc is a function that implements Handler.
type Middleware ¶
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 (*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) Run ¶
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 ¶
Publisher publishes data packets to content store. Typically, it is used with RawCacher, so that the published data is immediately available.
func NewPublisher ¶
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.