streams

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: GPL-3.0 Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stream

type Stream interface {
	// ID returns the id of the stream
	ID() string

	io.Closer
	// CloseWrite closes the stream for writing but leaves it open for
	// reading. It does not free the stream, a call Close or
	// Reset is required.
	CloseWrite() error

	// ReadWithTimeout will read bytes from stream and return the result, will return error if timeout or error.
	// does not close stream when returns
	ReadWithTimeout(timeout time.Duration) ([]byte, error)

	// WriteWithTimeout will write bytes to stream, will return error if timeout or error.
	// does not close stream when returns
	WriteWithTimeout(data []byte, timeout time.Duration) error
}

Stream represents a stream in the system

func NewStream

func NewStream(s core.Stream) Stream

NewStream returns a new instance of stream

type StreamController

type StreamController interface {
	// Request sends a message to the given stream and returns the response
	Request(logger *zap.Logger, peerID peer.ID, protocol protocol.ID, msg []byte) ([]byte, error)
	// HandleStream is called at the beginning of stream handlers to create a wrapper stream and read first message
	HandleStream(logger *zap.Logger, stream core.Stream) ([]byte, StreamResponder, func(), error)
}

StreamController simplifies the interaction with libp2p streams.

func NewStreamController

func NewStreamController(ctx context.Context, host host.Host, fork forks.Fork, requestTimeout time.Duration) StreamController

NewStreamController create a new instance of StreamController

type StreamResponder

type StreamResponder func([]byte) error

StreamResponder abstracts the stream access with a simpler interface that accepts only the data to send

Jump to

Keyboard shortcuts

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