muxrpc: go.cryptoscope.co/muxrpc Index | Files | Directories

package muxrpc

import "go.cryptoscope.co/muxrpc"

Index

Package Files

ctx.go endpoint.go handler.go packer.go request.go rpc.go rwc.go stream.go

Constants

const ChunkSize = 65536

Variables

var (
    ErrStreamNotReadable = errors.New("muxrpc: this stream can not be read from")
    ErrStreamNotWritable = errors.New("muxrpc: this stream can not be written to")
    ErrStreamNotClosable = errors.New("muxrpc: this stream can not be closed")
)
var ErrSessionTerminated = errors.New("muxrpc: session terminated")

func IsSinkClosed Uses

func IsSinkClosed(err error) bool

IsSinkClosed should be moved to luigi to gether with the error

func NewSinkWriter Uses

func NewSinkWriter(sink luigi.Sink) io.WriteCloser

func NewSourceReader Uses

func NewSourceReader(src luigi.Source) io.Reader

type CallError Uses

type CallError struct {
    Name    string `json:"name"`
    Message string `json:"message"`
    Stack   string `json:"stack"`
}

CallError is returned when a call fails

func (*CallError) Error Uses

func (e *CallError) Error() string

type CallType Uses

type CallType string

CallType is the type of a call

func (CallType) Flags Uses

func (t CallType) Flags() codec.Flag

Flags returns the packet flags of the respective call type

type Endpoint Uses

type Endpoint interface {
    // The different call types:
    Async(ctx context.Context, tipe interface{}, method Method, args ...interface{}) (interface{}, error)
    Source(ctx context.Context, tipe interface{}, method Method, args ...interface{}) (luigi.Source, error)
    Sink(ctx context.Context, method Method, args ...interface{}) (luigi.Sink, error)
    Duplex(ctx context.Context, tipe interface{}, method Method, args ...interface{}) (luigi.Source, luigi.Sink, error)

    // Do allows general calls
    Do(ctx context.Context, req *Request) error

    // Terminate wraps up the RPC session
    Terminate() error

    // Remote returns the network address of the remote
    Remote() net.Addr
}

Endpoint allows calling functions on the RPC peer. go:generate counterfeiter -o mock/endpoint.go . Endpoint

func Handle Uses

func Handle(pkr Packer, handler Handler) Endpoint

Handle handles the connection of the packer using the specified handler.

func HandleWithLogger Uses

func HandleWithLogger(pkr Packer, handler Handler, logger log.Logger) Endpoint

HandleWithLogger same as Handle but let's you overwrite the stderr logger

func HandleWithRemote Uses

func HandleWithRemote(pkr Packer, handler Handler, addr net.Addr) Endpoint

HandleWithRemote also sets the remote address the endpoint is connected to TODO: better passing through packer maybe?!

type Handler Uses

type Handler interface {
    HandleCall(ctx context.Context, req *Request, edp Endpoint)
    HandleConnect(ctx context.Context, edp Endpoint)
}

Handler allows handling connections. When we are being called, HandleCall is called. When a connection is established, HandleConnect is called. TODO: let HandleCall return an error

func ApplyHandlerWrappers Uses

func ApplyHandlerWrappers(h Handler, hws ...HandlerWrapper) Handler

type HandlerMux Uses

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

func (*HandlerMux) HandleCall Uses

func (hm *HandlerMux) HandleCall(ctx context.Context, req *Request, edp Endpoint)

func (*HandlerMux) HandleConnect Uses

func (hm *HandlerMux) HandleConnect(ctx context.Context, edp Endpoint)

func (*HandlerMux) Register Uses

func (hm *HandlerMux) Register(m Method, h Handler)

func (*HandlerMux) RegisterAll Uses

func (hm *HandlerMux) RegisterAll(handlers ...NamedHandler)

type HandlerWrapper Uses

type HandlerWrapper func(Handler) Handler

type Method Uses

type Method []string

func (Method) String Uses

func (m Method) String() string

type NamedHandler Uses

type NamedHandler struct {
    Method  Method
    Handler Handler
}

type Packer Uses

type Packer interface {
    luigi.Source
    luigi.Sink
}

Packer is a duplex stream that sends and receives *codec.Packet values. Usually wraps a network connection or stdio.

func NewPacker Uses

func NewPacker(rwc io.ReadWriteCloser) Packer

NewPacker takes an io.ReadWriteCloser and returns a Packer.

type Request Uses

type Request struct {
    // Stream allows sending and receiving packets
    Stream Stream `json:"-"`

    // Method is the name of the called function
    Method Method `json:"name"`
    // Args contains the call arguments
    RawArgs json.RawMessage `json:"args"`
    // Type is the type of the call, i.e. async, sink, source or duplex
    Type CallType `json:"type"`
    // contains filtered or unexported fields
}

Request assembles the state of an RPC call

func (*Request) Args Uses

func (req *Request) Args() []interface{}

Legacy

func (*Request) Close Uses

func (req *Request) Close() error

func (*Request) CloseWithError Uses

func (req *Request) CloseWithError(cerr error) error

func (*Request) Return Uses

func (req *Request) Return(ctx context.Context, v interface{}) error

Return is a helper that returns on an async call

type Server Uses

type Server interface {
    Remote() net.Addr
    Serve(context.Context) error
}

Server can handle packets to and from a remote party

type Stream Uses

type Stream interface {
    luigi.Source
    luigi.Sink
    luigi.ErrorCloser

    // WithType tells the stream in what type JSON data should be unmarshalled into
    WithType(tipe interface{})

    // WithReq tells the stream what request number should be used for sent messages
    WithReq(req int32)
}

Stream is a muxrpc stream for the general duplex case.

Directories

PathSynopsis
codecPackage codec implements readers and writers for https://github.com/dominictarr/packet-stream-codec
codec/rpctrace
debug
examples
mockCode generated by counterfeiter.
test

Package muxrpc imports 16 packages (graph) and is imported by 51 packages. Updated 2019-10-16. Refresh now. Tools for package owners.