server

package
v0.0.0-test-go-svm-build2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotConnected = errors.New("peer is not connected")

ErrNotConnected is returned when peer is not connected.

Functions

This section is empty.

Types

type Handler added in v1.0.0

type Handler func(context.Context, []byte) ([]byte, error)

Handler is the handler to be defined by the application.

type Host added in v1.0.0

type Host interface {
	SetStreamHandler(protocol.ID, network.StreamHandler)
	NewStream(context.Context, peer.ID, ...protocol.ID) (network.Stream, error)
	Network() network.Network
}

Host is a subset of libp2p Host interface that needs to be implemented to be usable with server.

type Opt added in v1.0.0

type Opt func(s *Server)

Opt is a type to configure a server.

func WithContext added in v1.0.0

func WithContext(ctx context.Context) Opt

WithContext configures parent context for contexts that are passed to the handler.

func WithLog added in v1.0.0

func WithLog(log log.Log) Opt

WithLog configures logger for the server.

func WithTimeout added in v1.0.0

func WithTimeout(timeout time.Duration) Opt

WithTimeout configures stream timeout.

type Requestor

type Requestor interface {
	Request(context.Context, peer.ID, []byte, func([]byte), func(error)) error
}

Requestor is an interface for requesting replies from peer server.

type Server added in v1.0.0

type Server struct {
	// contains filtered or unexported fields
}

Server for the Handler.

func New added in v1.0.0

func New(h Host, proto string, handler Handler, opts ...Opt) *Server

New server for the handler.

func (*Server) Request added in v1.0.0

func (s *Server) Request(ctx context.Context, pid peer.ID, req []byte, resp func([]byte), failure func(error)) error

Request sends a binary request to the peer. Request is executed in the background, one of the callbacks is guaranteed to be called on success/error.

Directories

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

Jump to

Keyboard shortcuts

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