rpc

package
v0.0.0-...-78fffcb Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 25 Imported by: 472

Documentation

Index

Constants

View Source
const ConnectionLogMsgKey string = "msg"
View Source
const DefaultMaxFrameLength = 100 * 1024 * 1024

DefaultMaxFrameLength (100 MiB) is a reasonable default value for the maxFrameLength parameter in NewTransporter.

Variables

This section is empty.

Functions

func AddRpcTagsToContext

func AddRpcTagsToContext(ctx context.Context, logTagsToAdd CtxRpcTags) context.Context

AddRpcTagsToContext adds the given log tag mappings (logTagsToAdd) to the given context, creating a new one if necessary. Returns the resulting context with the new log tag mappings.

func AddrToString

func AddrToString(addr net.Addr) string

func DisableSigPipe

func DisableSigPipe(c net.Conn) error

func RPCInstrumentTag

func RPCInstrumentTag(methodType MethodType, method string) string

func WithFireNow

func WithFireNow(ctx context.Context) context.Context

WithFireNow returns a context.Context with a CtxFireNow attached.

A bit more background: when random backoff is enabled, the RPC client waits on a random timer before trying to reconnect to server in event of a disconnection. However, we want this to happen only if the client device is idling. Users of this package should use WithFireNow to amend the context passed into any RPC calls that should cause a reconnect immediately. In general, that's all RPC calls except those that perform ping-like functions.

Types

type AlreadyRegisteredError

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

func (AlreadyRegisteredError) Error

func (a AlreadyRegisteredError) Error() string

type CallNotFoundError

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

func (CallNotFoundError) Error

func (c CallNotFoundError) Error() string

type CancellableTimer

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

CancellableTimer can be used to wait on a random backoff timer. A pointer to a zero value of CancellableTimer if usable.

func (*CancellableTimer) FireNow

func (b *CancellableTimer) FireNow()

FireNow fast-forwards any existing timer so that any Wait() calls on b wakes up immediately. If no timer exists, this is a no-op.

func (*CancellableTimer) StartConstant

func (b *CancellableTimer) StartConstant(waitDur time.Duration)

StartConstant starts a backoff timer. The timer is fast-forward-able with b.FireNow(). Use b.Wait() to wait for the timer.

It's OK to call b.Start() multiple times. It essentially resets the timer to a new value, i.e., any pending b.Wait() waits until the last effective timer completes.

func (*CancellableTimer) StartRandom

func (b *CancellableTimer) StartRandom(maxWait time.Duration) time.Duration

StartRandom starts a random backoff timer. The timer is fast-forward-able with b.FireNow(). Use b.Wait() to wait for the timer.

It's OK to call b.Start() multiple times. It essentially resets the timer to a new value, i.e., any pending b.Wait() waits until the last effective timer completes.

func (*CancellableTimer) Wait

func (b *CancellableTimer) Wait()

Wait waits on any existing random timer. If there isn't a timer started, Wait() returns immediately. If b.Start() is called in the middle of the wait, it waits until the new timer completes (no matter it's sonner or later than the old timer). If FireNow() is called, Wait() returns immediately.

type Client

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

Client allows calls and notifies on the given transporter, or any protocol type. All will share the same ErrorUnwrapper hook for unwrapping incoming msgpack objects and converting to possible Go-native `Error` types

func NewClient

func NewClient(xp Transporter, u ErrorUnwrapper,
	tagsFunc LogTagsFromContext) *Client

NewClient constructs a new client from the given RPC Transporter and the ErrorUnwrapper.

func NewClientWithSendNotifier

func NewClientWithSendNotifier(xp Transporter, u ErrorUnwrapper,
	tagsFunc LogTagsFromContext, sendNotifier SendNotifier) *Client

NewClientWithSendNotifier constructs a new client from the given RPC Transporter, the ErrorUnwrapper, and the SendNotifier

func (*Client) Call

func (c *Client) Call(ctx context.Context, method string, arg interface{}, res interface{}, timeout time.Duration) error

Call makes an msgpack RPC call over the transports that's bound to this client. The name of the method, and the argument are given. On reply, the result field will be populated (if applicable). It returns an Error on error, where the error might have been unwrapped from Msgpack via the UnwrapErrorFunc in this client. `timeout` will optionally set a deadline on the given `ctx`.

func (*Client) CallCompressed

func (c *Client) CallCompressed(ctx context.Context, method string,
	arg interface{}, res interface{}, ctype CompressionType, timeout time.Duration) error

CallCompressed acts as Call but allows the response to be compressed with the given CompressionType.

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, method string, arg interface{}, timeout time.Duration) (err error)

Notify notifies the server, with the given method and argument. It does not wait to hear back for an error. An error might happen in sending the call, in which case a native Go Error is returned. The UnwrapErrorFunc in the underlying client isn't relevant in this case.

type CompressionType

type CompressionType int
const (
	CompressionNone       CompressionType = 0
	CompressionGzip       CompressionType = 1
	CompressionMsgpackzip CompressionType = 2
)

func (CompressionType) NewCompressor

func (t CompressionType) NewCompressor() compressor

func (CompressionType) String

func (t CompressionType) String() string

type Connection

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

Connection encapsulates all client connection handling.

func MakeConnectionForTest

func MakeConnectionForTest(t TestLogger) (net.Conn, *Connection)

MakeConnectionForTest returns a Connection object, and a net.Conn object representing the other end of that connection.

func NewConnectionWithTransport

func NewConnectionWithTransport(
	handler ConnectionHandler,
	transport ConnectionTransport,
	errorUnwrapper ErrorUnwrapper,
	logOutput LogOutputWithDepthAdder,
	opts ConnectionOpts,
) *Connection

NewConnectionWithTransport allows for connections with a custom transport.

func NewTLSConnection

func NewTLSConnection(
	srvRemote Remote,
	rootCerts []byte,
	errorUnwrapper ErrorUnwrapper,
	handler ConnectionHandler,
	logFactory LogFactory,
	instrumenterStorage NetworkInstrumenterStorage,
	logOutput LogOutputWithDepthAdder,
	maxFrameLength int32,
	opts ConnectionOpts,
) *Connection

NewTLSConnection returns a connection that tries to connect to the given server address with TLS.

func NewTLSConnectionWithConnectionLogFactory

func NewTLSConnectionWithConnectionLogFactory(
	srvRemote Remote,
	rootCerts []byte,
	errorUnwrapper ErrorUnwrapper,
	handler ConnectionHandler,
	logFactory LogFactory,
	instrumenterStorage NetworkInstrumenterStorage,
	connectionLogFactory ConnectionLogFactory,
	maxFrameLength int32,
	opts ConnectionOpts,
) *Connection

NewTLSConnectionWithConnectionLogFactory is like NewTLSConnection, but with a custom logger.

func NewTLSConnectionWithDialable

func NewTLSConnectionWithDialable(
	srvRemote Remote,
	rootCerts []byte,
	errorUnwrapper ErrorUnwrapper,
	handler ConnectionHandler,
	logFactory LogFactory,
	instrumenterStorage NetworkInstrumenterStorage,
	logOutput LogOutputWithDepthAdder,
	maxFrameLength int32,
	opts ConnectionOpts,
	dialable Dialable,
) *Connection

NewTLSConnection returns a connection that tries to connect to the given server address with TLS.

func NewTLSConnectionWithTLSConfig

func NewTLSConnectionWithTLSConfig(
	srvRemote Remote,
	tlsConfig *tls.Config,
	errorUnwrapper ErrorUnwrapper,
	handler ConnectionHandler,
	logFactory LogFactory,
	instrumenterStorage NetworkInstrumenterStorage,
	logOutput LogOutputWithDepthAdder,
	maxFrameLength int32,
	opts ConnectionOpts,
) *Connection

NewTLSConnectionWithTLSConfig allows you to specify a RootCA pool and also a serverName (if wanted) via the full Go TLS config object.

func (*Connection) DoCommand

func (c *Connection) DoCommand(ctx context.Context, name string, timeout time.Duration,
	rpcFunc func(GenericClient) error) error

DoCommand executes the specific rpc command wrapped in rpcFunc.

func (*Connection) FastForwardConnectDelayTimer

func (c *Connection) FastForwardConnectDelayTimer()

FastForwardConnectDelayTimer causes any pending reconnect to happen immediately.

func (*Connection) ForceReconnect

func (c *Connection) ForceReconnect(ctx context.Context) error

func (*Connection) GetClient

func (c *Connection) GetClient() GenericClient

GetClient returns an RPC client that uses DoCommand() for RPC calls, and thus handles throttling, disconnections, etc.

func (*Connection) GetServer

func (c *Connection) GetServer() *Server

GetServer is called to retrieve an rpc server suitable for use by the caller.

func (*Connection) IsConnected

func (c *Connection) IsConnected() bool

IsConnected returns true if the connection is connected. The mutex must not be held by the caller.

func (*Connection) Shutdown

func (c *Connection) Shutdown()

Shutdown cancels any reconnect loop in progress. Calling this invalidates the connection object.

type ConnectionHandler

type ConnectionHandler interface {
	// OnConnect is called immediately after a connection has been
	// established.  An implementation would likely log something,
	// register served protocols, and/or perform authentication.
	OnConnect(context.Context, *Connection, GenericClient, *Server) error

	// OnConnectError is called whenever there is an error during connection.
	OnConnectError(err error, reconnectThrottleDuration time.Duration)

	// OnDoCommandError is called whenever there is an error during DoCommand
	OnDoCommandError(err error, nextTime time.Duration)

	// OnDisconnected is called whenever the connection notices it
	// is disconnected.
	OnDisconnected(ctx context.Context, status DisconnectStatus)

	// ShouldRetry is called whenever an error is returned by
	// an RPC function passed to Connection.DoCommand(), and
	// should return whether or not that error signifies that that
	// RPC should retried (with backoff)
	ShouldRetry(name string, err error) bool

	// ShouldRetryOnConnect is called whenever an error is returned
	// during connection establishment, and should return whether or
	// not the connection should be established again.
	ShouldRetryOnConnect(err error) bool

	// HandlerName returns a string representing the type of the connection
	// handler.
	HandlerName() string
}

ConnectionHandler is the callback interface for interacting with the connection.

type ConnectionLog

type ConnectionLog interface {
	Warning(format string, fields ...LogField)
	Debug(format string, fields ...LogField)
	Info(format string, fields ...LogField)
}

ConnectionLog defines an interface used by connection.go for logging. An implementation that does structural logging may ignore `format` completely if `ConnectionLogMsgKey` is provided in LogField.

type ConnectionLogFactory

type ConnectionLogFactory interface {
	Make(section string) ConnectionLog
}

type ConnectionOpts

type ConnectionOpts struct {
	TagsFunc         LogTagsFromContext
	Protocols        []Protocol
	DontConnectNow   bool
	WrapErrorFunc    WrapErrorFunc
	ReconnectBackoff func() backoff.BackOff
	CommandBackoff   func() backoff.BackOff
	// FirstConnectDelayDuration, if it returns non zero, causes a random
	// backoff before the first connection. The random backoff timer is
	// fast-forward-able by passing in a WithFireNow(ctx) into a RPC call.
	FirstConnectDelayDuration time.Duration
	// InitialReconnectBackoffWindow, if it returns non zero, causes a random
	// backoff before reconnecting. The random backoff timer is
	// fast-forward-able by passing in a WithFireNow(ctx) into a RPC call.
	InitialReconnectBackoffWindow func() time.Duration
	// As the name suggests, we normally skip the "initial reconnect backoff"
	// the very first time we try to connect. However, some callers instantiate
	// new Connection objects after a disconnect, and they need the "first
	// connection" to be treated as a reconnect. If this is set,
	// FirstConnectDelayDuration is ineffective.
	ForceInitialBackoff bool
	// DialerTimeout is the Timeout used in net.Dialer when initiating new
	// connections. Zero value is passed as-is to net.Dialer, which means no
	// timeout. Note that OS may impose its own timeout.
	DialerTimeout time.Duration
	// HandshakeTimeout is a timeout on how long we wait for TLS handshake to
	// complete. If no value specified, we default to time.Minute.
	HandshakeTimeout time.Duration
}

This struct contains all the connection parameters that are optional. The mandatory parameters are given as positional arguments to the different wrapper functions, along with this struct.

The backoffs are functions that created backoff.BackOffs, rather than backoff instances, since some backoffs can be stateful and not goroutine-safe (e.g., backoff.Exponential). Connection will call these functions once for each command call and reconnect attempt.

type ConnectionTransport

type ConnectionTransport interface {
	// Dial is called to connect to the server.
	Dial(ctx context.Context) (Transporter, error)

	// IsConnected is called to check for connection status.
	IsConnected() bool

	// Finalize is used to indicate the result of Dial is complete.
	Finalize()

	// Close is used to close any open connection.
	Close()
}

ConnectionTransport is a container for an underlying transport to be used by a Connection instance.

func NewConnectionTransport

func NewConnectionTransport(uri *FMPURI, l LogFactory, instrumenterStorage NetworkInstrumenterStorage,
	wef WrapErrorFunc, maxFrameLength int32) ConnectionTransport

NewConnectionTransport creates a ConnectionTransport for a given FMPURI.

func NewConnectionTransportWithDialable

func NewConnectionTransportWithDialable(uri *FMPURI, l LogFactory, instrumenterStorage NetworkInstrumenterStorage,
	wef WrapErrorFunc, maxFrameLength int32, dialable Dialable) ConnectionTransport

NewConnectionTransportWithDialable creates a ConnectionTransport for a given FMPURI via the given Dialable

type ConnectionTransportTLS

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

ConnectionTransportTLS is a ConnectionTransport implementation that uses TLS+rpc.

func (*ConnectionTransportTLS) Close

func (ct *ConnectionTransportTLS) Close()

Close is an implementation of the ConnectionTransport interface.

func (*ConnectionTransportTLS) Dial

Dial is an implementation of the ConnectionTransport interface.

func (*ConnectionTransportTLS) Finalize

func (ct *ConnectionTransportTLS) Finalize()

Finalize is an implementation of the ConnectionTransport interface.

func (*ConnectionTransportTLS) IsConnected

func (ct *ConnectionTransportTLS) IsConnected() bool

IsConnected is an implementation of the ConnectionTransport interface.

type CtxFireNow

type CtxFireNow struct{}

CtxFireNow is a context key that when set, causes a RPC client to reconnect immediately if needed.

type CtxRpcKey

type CtxRpcKey int

CtxRpcKey is a type defining the context key for the RPC context

const (
	// CtxRpcTagsKey defines a context key that can hold a slice of context keys
	CtxRpcTagsKey CtxRpcKey = iota
)

type CtxRpcTags

type CtxRpcTags map[string]interface{}

func RpcTagsFromContext

func RpcTagsFromContext(ctx context.Context) (CtxRpcTags, bool)

RpcTagsFromContext returns the tags being passed along with the given context.

type Dialable

type Dialable interface {
	// Set the timeout and keepalive options for this Dialable
	SetOpts(timeout time.Duration, keepAlive time.Duration)

	// Dial a connection to the given address
	Dial(ctx context.Context, network string, addr string) (net.Conn, error)
}

Dialable is a custom interface that can be used to replace net.Dial inside this library if desired This is most likely useful for the purpose of routing connections through a proxy

type DisconnectStatus

type DisconnectStatus int

DisconnectStatus is the connection information passed to ConnectionHandler.OnDisconnected().

const (

	// UsingExistingConnection means that an existing
	// connection will be used.
	UsingExistingConnection DisconnectStatus = iota
	// StartingFirstConnection means that a connection will be
	// started, and this is the first one.
	StartingFirstConnection
	// StartingNonFirstConnection means that a connection will be
	// started, and this is not the first one.
	StartingNonFirstConnection
)

type DispatcherError

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

func NewDispatcherError

func NewDispatcherError(d string, a ...interface{}) DispatcherError

func (DispatcherError) Error

func (p DispatcherError) Error() string

type DummyInstrumentationStorage

type DummyInstrumentationStorage struct{}

func NewDummyInstrumentationStorage

func NewDummyInstrumentationStorage() *DummyInstrumentationStorage

func (*DummyInstrumentationStorage) Put

type ErrorUnwrapper

type ErrorUnwrapper interface {
	MakeArg() interface{}
	UnwrapError(arg interface{}) (appError error, dispatchError error)
}

type FMPURI

type FMPURI struct {
	Scheme   string
	HostPort string
	Host     string
}

FMPURI represents a URI with an FMP scheme.

func ParseFMPURI

func ParseFMPURI(s string) (*FMPURI, error)

ParseFMPURI parses an FMPURI.

func (*FMPURI) Dial

func (f *FMPURI) Dial() (net.Conn, error)

func (*FMPURI) DialWithConfig

func (f *FMPURI) DialWithConfig(config *tls.Config) (net.Conn, error)

func (*FMPURI) String

func (f *FMPURI) String() string

func (*FMPURI) UseTLS

func (f *FMPURI) UseTLS() bool

type GenericClient

type GenericClient interface {
	Call(ctx context.Context, method string, arg interface{}, res interface{}, timeout time.Duration) error
	CallCompressed(ctx context.Context, method string,
		arg interface{}, res interface{}, cType CompressionType, timeout time.Duration) error
	Notify(ctx context.Context, method string, arg interface{}, timeout time.Duration) error
}

GenericClient is the interface that is exported to autogenerated RPC stubs from AVDL files.

type InstrumentationRecord

type InstrumentationRecord struct {
	Ctime time.Time
	Dur   time.Duration
	Size  int64
}

type LogFactory

type LogFactory interface {
	NewLog(net.Addr) LogInterface
}

type LogField

type LogField struct {
	Key   string
	Value interface{}
}

func (LogField) Format

func (f LogField) Format(s fmt.State, verb rune)

Format implements the fmt.Formatter interface, to make the structured LogField compatible with format-based non-structured loggers.

type LogInterface

type LogInterface interface {
	TransportStart()
	TransportError(error)
	// The passed-in slice should not be mutated.
	FrameRead([]byte)
	ClientCall(SeqNumber, string, interface{})
	ServerCall(SeqNumber, string, error, interface{})
	ServerReply(SeqNumber, string, error, interface{})
	ClientCallCompressed(SeqNumber, string, interface{}, CompressionType)
	ServerCallCompressed(SeqNumber, string, error, interface{}, CompressionType)
	ServerReplyCompressed(SeqNumber, string, error, interface{}, CompressionType)
	ClientNotify(string, interface{})
	ServerNotifyCall(string, error, interface{})
	ServerNotifyComplete(string, error)
	ClientCancel(SeqNumber, string, error)
	ServerCancelCall(SeqNumber, string)
	ClientReply(SeqNumber, string, error, interface{})
	StartProfiler(format string, args ...interface{}) Profiler
	UnexpectedReply(SeqNumber)
	Warning(format string, args ...interface{})
	Info(format string, args ...interface{})
}

type LogOptions

type LogOptions interface {
	ShowAddress() bool
	ShowArg() bool
	ShowResult() bool
	Profile() bool
	FrameTrace() bool
	ClientTrace() bool
	ServerTrace() bool
	TransportStart() bool
}

func NewStandardLogOptions

func NewStandardLogOptions(opts string, log LogOutput) LogOptions

type LogOutput

type LogOutput interface {
	Error(s string, args ...interface{})
	Warning(s string, args ...interface{})
	Info(s string, args ...interface{})
	Debug(s string, args ...interface{})
	Profile(s string, args ...interface{})
}

type LogOutputWithDepthAdder

type LogOutputWithDepthAdder interface {
	LogOutput
	CloneWithAddedDepth(depth int) LogOutputWithDepthAdder
}

type LogTagsFromContext

type LogTagsFromContext func(ctx context.Context) (map[interface{}]string, bool)

type MemoryInstrumentationStorage

type MemoryInstrumentationStorage struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMemoryInstrumentationStorage

func NewMemoryInstrumentationStorage() *MemoryInstrumentationStorage

func (*MemoryInstrumentationStorage) Put

type MethodNotFoundError

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

func (MethodNotFoundError) Error

func (m MethodNotFoundError) Error() string

type MethodType

type MethodType int
const (
	MethodInvalid        MethodType = -1
	MethodCall           MethodType = 0
	MethodResponse       MethodType = 1
	MethodNotify         MethodType = 2
	MethodCancel         MethodType = 3
	MethodCallCompressed MethodType = 4
)

func (MethodType) String

func (t MethodType) String() string

type NetworkInstrumenter

type NetworkInstrumenter struct {
	*InstrumentationRecord
	sync.Mutex
	// contains filtered or unexported fields
}

func NewNetworkInstrumenter

func NewNetworkInstrumenter(storage NetworkInstrumenterStorage, tag string) *NetworkInstrumenter

NewNetworkInstrumenter records network usage of a single call. Not safe for concurrent use.

func (*NetworkInstrumenter) EndCall

func (r *NetworkInstrumenter) EndCall()

func (*NetworkInstrumenter) Finish

func (r *NetworkInstrumenter) Finish(ctx context.Context) error

func (*NetworkInstrumenter) IncrementSize

func (r *NetworkInstrumenter) IncrementSize(size int64)

func (*NetworkInstrumenter) RecordAndFinish

func (r *NetworkInstrumenter) RecordAndFinish(ctx context.Context, size int64) error

func (*NetworkInstrumenter) String

func (r *NetworkInstrumenter) String() string

type NetworkInstrumenterStorage

type NetworkInstrumenterStorage interface {
	Put(ctx context.Context, tag string, record InstrumentationRecord) error
}

type NilProfiler

type NilProfiler struct{}

Callers shouldn't have to worry about whether an interface is satisfied or not

func (NilProfiler) Stop

func (n NilProfiler) Stop()

type NilResultError

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

func (NilResultError) Error

func (c NilResultError) Error() string

type PacketizerError

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

func NewPacketizerError

func NewPacketizerError(d string, a ...interface{}) PacketizerError

func (PacketizerError) Error

func (p PacketizerError) Error() string

type Profiler

type Profiler interface {
	Stop()
}

type Protocol

type Protocol struct {
	Name      string
	Methods   map[string]ServeHandlerDescription
	WrapError WrapErrorFunc
}

type ProtocolNotFoundError

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

func (ProtocolNotFoundError) Error

func (p ProtocolNotFoundError) Error() string

type RPCDecodeError

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

func (RPCDecodeError) Error

func (r RPCDecodeError) Error() string

type ReceiverError

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

func NewReceiverError

func NewReceiverError(d string, a ...interface{}) ReceiverError

func (ReceiverError) Error

func (p ReceiverError) Error() string

type Remote

type Remote interface {
	// GetAddress gets an address of the Remote to connect to.
	GetAddress() string
	// Peek returns an address of the Remote to connect to without changing the
	// internal state. The returned address is what GetAddress() would return
	// if called.
	Peek() string
	// Reset resets the internal counter so that next call to GetAddress()
	// returns an address as if it were called the first time.
	Reset()
	// String returns a string that represents all addresses in Remote and can
	// be used to construct a Remote that behaves the same way.
	String() string
}

Remote defines an address or a group of addresses that all point to a remote that we can connect to.

func NewFixedRemote

func NewFixedRemote(remoteAddr string) Remote

NewFixedRemote returns a remote that always uses remoteAddr.

func NewPrioritizedRoundRobinRemote

func NewPrioritizedRoundRobinRemote(addressGroups [][]string) (Remote, error)

NewPrioritizedRoundRobinRemote creates a new Remote that include prioritized remote groups. Each call to GetAddress() will round-robin by random order within the first group. If we run out of address within the first group, fallback to second group and do the same thing, until we've iterated all groups where we'll start over from first group.

Any successful connecting attempt should result in a call to Reset(). This is generally handled by the rpc package itself and shouldn't be worried about by the user of rpc package unless noted otherwise.

func ParsePrioritizedRoundRobinRemote

func ParsePrioritizedRoundRobinRemote(str string) (Remote, error)

ParsePrioritizedRoundRobinRemote parses a string into a prioritized round robin Remote. See doc for NewPrioritizedRoundRobinRemote for details on the returned Remote.

Example:

"example0.com,example1.com;example0.net,example1.net" produces a
prioritized round robin remote with two groups, first .com then .net.

type SendNotifier

type SendNotifier func(SeqNumber)

SendNotifier notifies the Caller when an RPC is released into the stream of messages. If, for instance, a caller wants to serialize sends to ensure some sort of client-side ordering, they can use this hook. Note that the hook fires long before the RPC is replied to. It will be called with the RPC sequence number that the RPC got on the way out, or SeqNumber(0) for Notify calls (which don't get sequence numbers).

type SeqNumber

type SeqNumber int

type ServeHandlerDescription

type ServeHandlerDescription struct {
	MakeArg func() interface{}
	Handler func(ctx context.Context, arg interface{}) (ret interface{}, err error)
}

type Server

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

func NewServer

func NewServer(xp Transporter, f WrapErrorFunc) *Server

func (*Server) Done

func (s *Server) Done() <-chan struct{}

Returns a channel that's closed when incoming frames have finished processing, either due to an error or the underlying connection being closed. Successive calls to Done() return the same value.

func (*Server) Err

func (s *Server) Err() error

Err returns a non-nil error value after Done() is closed. After Done() is closed, successive calls to Err return the same value.

func (*Server) Register

func (s *Server) Register(p Protocol) error

func (*Server) Run

func (s *Server) Run() <-chan struct{}

Run starts processing incoming RPC messages asynchronously, if it hasn't been started already. Returns the result of Done(), for convenience.

type SimpleLog

type SimpleLog struct {
	Addr net.Addr
	Out  LogOutput
	Opts LogOptions
}

func (SimpleLog) ClientCall

func (s SimpleLog) ClientCall(q SeqNumber, meth string, arg interface{})

Call

func (SimpleLog) ClientCallCompressed

func (s SimpleLog) ClientCallCompressed(q SeqNumber, meth string, arg interface{}, ctype CompressionType)

CallCompressed

func (SimpleLog) ClientCancel

func (s SimpleLog) ClientCancel(q SeqNumber, meth string, err error)

Cancel

func (SimpleLog) ClientNotify

func (s SimpleLog) ClientNotify(meth string, arg interface{})

Notify

func (SimpleLog) ClientReply

func (s SimpleLog) ClientReply(q SeqNumber, meth string, err error, res interface{})

func (SimpleLog) FrameRead

func (s SimpleLog) FrameRead(bytes []byte)

func (SimpleLog) Info

func (s SimpleLog) Info(format string, args ...interface{})

func (SimpleLog) ServerCall

func (s SimpleLog) ServerCall(q SeqNumber, meth string, err error, arg interface{})

func (SimpleLog) ServerCallCompressed

func (s SimpleLog) ServerCallCompressed(q SeqNumber, meth string, err error, arg interface{}, ctype CompressionType)

func (SimpleLog) ServerCancelCall

func (s SimpleLog) ServerCancelCall(q SeqNumber, meth string)

func (SimpleLog) ServerNotifyCall

func (s SimpleLog) ServerNotifyCall(meth string, err error, arg interface{})

func (SimpleLog) ServerNotifyComplete

func (s SimpleLog) ServerNotifyComplete(meth string, err error)

func (SimpleLog) ServerReply

func (s SimpleLog) ServerReply(q SeqNumber, meth string, err error, res interface{})

func (SimpleLog) ServerReplyCompressed

func (s SimpleLog) ServerReplyCompressed(q SeqNumber, meth string, err error, res interface{}, ctype CompressionType)

func (SimpleLog) StartProfiler

func (s SimpleLog) StartProfiler(format string, args ...interface{}) Profiler

func (SimpleLog) TransportError

func (s SimpleLog) TransportError(e error)

func (SimpleLog) TransportStart

func (s SimpleLog) TransportStart()

func (SimpleLog) UnexpectedReply

func (s SimpleLog) UnexpectedReply(seqno SeqNumber)

func (SimpleLog) Warning

func (s SimpleLog) Warning(format string, args ...interface{})

type SimpleLogFactory

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

func NewSimpleLogFactory

func NewSimpleLogFactory(out LogOutput, opts LogOptions) SimpleLogFactory

func (SimpleLogFactory) NewLog

func (s SimpleLogFactory) NewLog(a net.Addr) LogInterface

type SimpleLogOptions

type SimpleLogOptions struct{}

func (SimpleLogOptions) ClientTrace

func (so SimpleLogOptions) ClientTrace() bool

func (SimpleLogOptions) FrameTrace

func (so SimpleLogOptions) FrameTrace() bool

func (SimpleLogOptions) Profile

func (so SimpleLogOptions) Profile() bool

func (SimpleLogOptions) ServerTrace

func (so SimpleLogOptions) ServerTrace() bool

func (SimpleLogOptions) ShowAddress

func (so SimpleLogOptions) ShowAddress() bool

func (SimpleLogOptions) ShowArg

func (so SimpleLogOptions) ShowArg() bool

func (SimpleLogOptions) ShowResult

func (so SimpleLogOptions) ShowResult() bool

func (SimpleLogOptions) TransportStart

func (so SimpleLogOptions) TransportStart() bool

type SimpleLogOutput

type SimpleLogOutput struct{}

func (SimpleLogOutput) Debug

func (s SimpleLogOutput) Debug(fmt string, args ...interface{})

func (SimpleLogOutput) Error

func (s SimpleLogOutput) Error(fmt string, args ...interface{})

func (SimpleLogOutput) Info

func (s SimpleLogOutput) Info(fmt string, args ...interface{})

func (SimpleLogOutput) Profile

func (s SimpleLogOutput) Profile(fmt string, args ...interface{})

func (SimpleLogOutput) Warning

func (s SimpleLogOutput) Warning(fmt string, args ...interface{})

type SimpleProfiler

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

func (*SimpleProfiler) Stop

func (s *SimpleProfiler) Stop()

type StandardLogOptions

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

func (*StandardLogOptions) ClientTrace

func (s *StandardLogOptions) ClientTrace() bool

func (*StandardLogOptions) FrameTrace

func (s *StandardLogOptions) FrameTrace() bool

func (*StandardLogOptions) Profile

func (s *StandardLogOptions) Profile() bool

func (*StandardLogOptions) ServerTrace

func (s *StandardLogOptions) ServerTrace() bool

func (*StandardLogOptions) ShowAddress

func (s *StandardLogOptions) ShowAddress() bool

func (*StandardLogOptions) ShowArg

func (s *StandardLogOptions) ShowArg() bool

func (*StandardLogOptions) ShowResult

func (s *StandardLogOptions) ShowResult() bool

func (*StandardLogOptions) TransportStart

func (s *StandardLogOptions) TransportStart() bool

type TestLogger

type TestLogger interface {
	Logf(format string, args ...interface{})
	Helper()
}

TestLogger is an interface for things, like *testing.T, that have a Logf and Helper function.

type Transporter

type Transporter interface {
	// IsConnected returns false when incoming packets have
	// finished processing.
	//
	// TODO: Use a better name.
	IsConnected() bool

	// Close closes the transport and releases resources.
	Close()
	// contains filtered or unexported methods
}

func NewTransport

func NewTransport(c net.Conn, l LogFactory, instrumenterStorage NetworkInstrumenterStorage, wef WrapErrorFunc, maxFrameLength int32) Transporter

NewTransport creates a new Transporter from the given connection and parameters. Both sides of a connection should use the same number for maxFrameLength.

type TypeError

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

func NewTypeError

func NewTypeError(expected, actual interface{}) TypeError

func (TypeError) Error

func (t TypeError) Error() string

type WrapErrorFunc

type WrapErrorFunc func(error) interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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