streams

package module
v0.0.0-...-5957fb3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2016 License: MIT Imports: 2 Imported by: 0

README

Streams: Just give me a stream!

Streams is an interface for using multiplexing transport protocols in Go. The intent is to make creating and receiving streams easy to use from an application. Streams is designed to provide a unified implementation for building applications which require multiplexed streaming and need to easily swap between underlying implementations. The target implementations for Streams is spdy/3.1, http2, and sshv2.

Why is this useful?

Building complex networked applications which require many streams of communication is hard. Creating and managing these streams of communication is challenging and further complicated by the desire to support multiple protocols and the need for debugging. Creating a simple interface for using these protocols not only allows simplification of management, but also makes writing debugging tools and handlers easier. Initially setting up the multiplexing protocol is only necessary to do once per connection in a complex application. However creating streams is a constant operation with low overhead to the protocol but has a high management cost to the application as the streams accumulate. A simple interface to manage these accumulating streams makes working with streams more productive.

Interface

type Stream interface {
	io.ReadWriteCloser
	Headers() http.Header
	Reset() error
}

type Listener interface {
	Accept() (Stream, error)
}

type StreamProvider interface {
	NewStream(http.Header) (Stream, error)
	Close() error
	Listen(StreamHandler) Listener
}

Multiplexing Protocols

Spdy/3.1

Implementation using github.com/docker/spdystream

HTTP/2

Future implementation using golang's http2 library

SSH

Future implementation using github.com/golang/crypto/ssh

Simple Framer

Naive framing protocol intended to implement the streams interface with minimal protocol on top of a raw byte stream

TBD: Simple framer definition

Wrappers

The implementation of the stream provider may wrap another implementation to provide additional features. These additional features may be used to span multiple connections or add debugging.

Documentation

Overview

Package streams is an interface for using multiplexed transports protocols in a way that allows swapping between protocols without changing the higher level implementation.

The `StreamProvider` interface is intended to abstract the underlying protocol in a way that is centered around creating and managing the individually multiplexed streams. Streams may either be created locally or remotely. In the case of remotely created streams, a listener must be used to accept new streams.

The `Stream` interface allows sending and receiving bytes as easy as any io.ReadWriteCloser. In addition to reading and writing, the interface allows for retrieving the create headers and fully resetting the stream. The `Close` method is used to signal that no more writes will occur locally on the stream. This puts the stream in a half-closed state, still allowing for remote writes and local reads. Once the remote side calls `Close`, the stream will be fully closed, causing any future reads to return `io.EOF`. The `Reset` method is used to force the stream into a fully closed state. This should only be called in error cases which do not allow for any further action to occur on the stream. Forcing the stream into a fully close state may cause remote writes to fail, which should be handled by the remote.

The `Listener` interface is used to retrieve remotely created streams for local use. The `Accept` method will return the new stream will require the application to manage the local lifecycle of that stream. If the retrieved stream is invalid, possibly due to a bad header configuration, the application should call `Reset` on the stream, indicating to the remote side this stream will not be used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

type Listener interface {
	Accept() (Stream, error)
}

Listener is an interface for returning remotely created streams.

type Stream

type Stream interface {
	io.ReadWriteCloser
	Headers() http.Header
	Reset() error
}

Stream is an interface to represent a single byte stream on a multi-plexed connection with plus headers and a method to force full closure.

type StreamHandler

type StreamHandler func(http.Header) (http.Header, bool, error)

StreamHandler is a function to handle a new stream by adding response headers and whether the stream should be accepted. If a stream is not accepted, it will not be returned by an accept on the listener. Any error returned by the handler should be returned on accept.

type StreamProvider

type StreamProvider interface {
	NewStream(http.Header) (Stream, error)
	Close() error
	Listen(StreamHandler) Listener
}

StreamProvider is the minimal interface for creating new streams and receiving remotely created streams.

Directories

Path Synopsis
Package spdy is an implementation of the streams interface using spdy/3.1
Package spdy is an implementation of the streams interface using spdy/3.1

Jump to

Keyboard shortcuts

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