yamuxer

package
v0.0.0-...-cc25aa6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

README

yamuxer

Yamuxer is an abstraction over Yamux which dispatches streams to handlers based on type

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Listener   *net.TCPListener
	TLSConfig  *tls.Config
	Dispatcher Dispatcher
	Deadline   time.Duration
	LogOutput  io.Writer
}

Config is used to create a new yamuxer.

type Dispatcher

type Dispatcher interface {

	// Register adds a Handler for the given type.
	Register(StreamType, Handler)

	// RegisterFunc adds a HandlerFunc for the given type.
	RegisterFunc(StreamType, HandlerFunc)

	// Dispatch reads the first byte and passes the connection to the handler
	// for the given type.
	Dispatch(grim.GrimReaper, net.Conn)
}

Dispatcher processes stream connections and hands them off to the registered handler.

func NewDispatcher

func NewDispatcher(l log.Logger, unknownHandler Handler) Dispatcher

NewDispatcher creates a Dispatcher implementation which also allows for the optional handling of unknown streams. If the unknown handler is nil, the streams will be closed immediately.

type Handler

type Handler interface {
	Handle(context.Context, net.Conn)
}

Handler handles incoming stream connections for a stream type.

type HandlerFunc

type HandlerFunc func(context.Context, net.Conn)

HandlerFunc handles incoming stream connections.

type StreamType

type StreamType byte

StreamType is the stream enum. There can only be one handler per type. 0x00 is a reserved StreamType.

var UnknownStreamType StreamType = 0x00

UnknownStreamType is a cautionary type as it covered the nil byte.

type Yamuxer

type Yamuxer interface {
	Start()
	Stop()
}

Yamuxer is a simple interface which starts listening for connections on Start and waits for all connections to be closed on Stop.

func New

func New(context context.Context, c *Config) Yamuxer

New creates an implementation of the Yamuxer interface using the given context and config.

Jump to

Keyboard shortcuts

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