rpc

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStreamClosed = errors.New("stream closed")
)

Functions

This section is empty.

Types

type Handler

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

Handler is responsible for registering RPC request handlers for RPC types.

func NewHandler

func NewHandler() *Handler

func (*Handler) Find

func (h *Handler) Find(rpcType Type) (HandlerFunc, bool)

Find looks up the handler for the given RPC type.

func (*Handler) Register

func (h *Handler) Register(rpcType Type, handler HandlerFunc)

Register adds a new handler for the given RPC request type.

type HandlerFunc

type HandlerFunc func(message []byte) []byte

HandlerFunc handles the given request message and returns a response.

type Stream

type Stream interface {
	Addr() string
	RPC(ctx context.Context, rpcType Type, req []byte) ([]byte, error)
	Monitor(
		ctx context.Context,
		interval time.Duration,
		timeout time.Duration,
	) error
	Close() error
}

Stream represents a bi-directional RPC stream between two peers. Either peer can send an RPC request to the other.

The stream uses the underlying bi-directional connection to send RPC requests, and multiplexes multiple concurrent request/response RPCs on the same connection.

Incoming RPC requests are handled in their own goroutine to avoid blocking the stream.

func NewStream

func NewStream(conn conn.Conn, handler *Handler, logger log.Logger) Stream

NewStream creates an RPC stream on top of the given message-oriented connection.

type Type

type Type uint16

Type is an identifier for the RPC request/response type.

const (
	// TypeHeartbeat sends health checks between peers.
	TypeHeartbeat Type = iota + 1
	// TypeProxyHTTP sends a HTTP request and response between the Piko server
	// and an upstream listener.
	TypeProxyHTTP
)

func (*Type) String

func (t *Type) String() string

Jump to

Keyboard shortcuts

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