streamutil

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package streamutil provides utility functions to make handling streams easier.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingPeerID      = errors.New("missing peer ID")
	ErrMissingProtocolIDs = errors.New("missing protocol IDs")
)

Errors used by the stream provider.

View Source
var OptPeerID = func(peerID peer.ID) StreamOption {
	return func(opts *StreamOptions) {
		opts.PeerID = peerID
	}
}

OptPeerID configures the remote peer.

View Source
var OptProtocolIDs = func(pids ...protocol.ID) StreamOption {
	return func(opts *StreamOptions) {
		opts.PIDs = pids
	}
}

OptProtocolIDs configures the protocol IDs.

Functions

func WithAutoClose

func WithAutoClose(service string, method string, h AutoCloseHandler) inet.StreamHandler

WithAutoClose transforms an AutoCloseHandler to a StreamHandler.

Types

type AutoCloseHandler

type AutoCloseHandler func(context.Context, *monitoring.Span, inet.Stream, Codec) error

AutoCloseHandler is a specialized stream handler that closes the stream when exiting. It automatically logs the handler error.

type Codec

type Codec interface {
	multicodec.Encoder
	multicodec.Decoder
}

Codec implements an Encoder and a Decoder.

func NewProtobufCodec

func NewProtobufCodec(stream inet.Stream) Codec

NewProtobufCodec creates a Codec over the given stream, using protobuf as the message format.

type ProtobufCodec

type ProtobufCodec struct {
	multicodec.Encoder
	multicodec.Decoder
}

ProtobufCodec uses protobuf to encode messages.

type Provider

type Provider interface {
	NewStream(context.Context, ihost.Host, ...StreamOption) (Stream, error)
}

Provider lets you configure streams with added features.

func NewStreamProvider

func NewStreamProvider() Provider

NewStreamProvider returns a new provider.

type Stream

type Stream interface {
	Conn() inet.Conn
	Codec() Codec
	Close()
}

Stream is a simplified stream abstraction.

type StreamOption

type StreamOption func(opts *StreamOptions)

StreamOption configures a single stream option.

type StreamOptions

type StreamOptions struct {
	PeerID peer.ID
	PIDs   []protocol.ID
}

StreamOptions are used to configure a stream.

type StreamProvider

type StreamProvider struct{}

StreamProvider implements the Provider interface.

func (*StreamProvider) NewStream

func (p *StreamProvider) NewStream(ctx context.Context, host ihost.Host, opts ...StreamOption) (Stream, error)

NewStream creates a new stream.

Directories

Path Synopsis
Package mockstream is a generated GoMock package.
Package mockstream is a generated GoMock package.

Jump to

Keyboard shortcuts

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