Documentation
¶
Index ¶
- Constants
- func AddRPCTagsToContext(ctx context.Context, logTagsToAdd CtxRPCTags) context.Context
- func AddrToString(addr net.Addr) string
- func DisableSigPipe(_ net.Conn) error
- func InstrumentTag(methodType MethodType, method string) string
- func LogFieldsToString(lfs []LogField, prfx string) string
- func NewLoopbackConnPair() (*LoopbackConn, *LoopbackConn)
- func WithFireNow(ctx context.Context) context.Context
- type AlreadyRegisteredError
- type AlreadyRegisteredV2Error
- type BadLogFlagsError
- type CallNotFoundError
- type CancellableTimer
- type Client
- func (c *Client) Call(ctx context.Context, method Methoder, arg interface{}, res interface{}, ...) error
- func (c *Client) Call2(ctx context.Context, method Methoder, arg interface{}, res interface{}, ...) error
- func (c *Client) CallCompressed(ctx context.Context, method Methoder, arg interface{}, res interface{}, ...) error
- func (c *Client) Notify(ctx context.Context, method Methoder, arg interface{}, timeout time.Duration) (err error)
- func (c *Client) Transport(_ context.Context) (Transporter, error)
- type CompressionType
- type Connection
- func MakeConnectionForTest(t TestLogger) (net.Conn, *Connection)
- func NewConnectionWithTransport(handler ConnectionHandler, transport ConnectionTransport, ...) *Connection
- func NewTLSConnection(srvRemote Remote, rootCerts []byte, errorUnwrapper ErrorUnwrapper, ...) *Connection
- func NewTLSConnectionWithConnectionLogFactory(srvRemote Remote, rootCerts []byte, errorUnwrapper ErrorUnwrapper, ...) *Connection
- func NewTLSConnectionWithDialable(srvRemote Remote, rootCerts []byte, errorUnwrapper ErrorUnwrapper, ...) *Connection
- func NewTLSConnectionWithTLSConfig(srvRemote Remote, tlsConfig *tls.Config, errorUnwrapper ErrorUnwrapper, ...) *Connection
- func (c *Connection) DoCommand(ctx context.Context, name Methoder, timeout time.Duration, ...) error
- func (c *Connection) FastForwardConnectDelayTimer()
- func (c *Connection) ForceReconnect(ctx context.Context) error
- func (c *Connection) GetClient() GenericClient
- func (c *Connection) GetServer() *Server
- func (c *Connection) IsConnected() bool
- func (c *Connection) Shutdown()
- type ConnectionHandler
- type ConnectionLog
- type ConnectionLogFactory
- type ConnectionOpts
- type ConnectionTransport
- type ConnectionTransportTLS
- type CtxFireNow
- type CtxRPCKey
- type CtxRPCTags
- type DataWrap
- type DebugLogHook
- type Decodable
- type DecodeError
- type Decoder
- type DecoderFactory
- type Dialable
- type DisconnectStatus
- type DispatcherError
- type DummyInstrumentationStorage
- type Encoder
- type EncoderFactory
- type ErrorUnwrapper
- type GenericClient
- type InstrumentationRecord
- type LogFactory
- type LogField
- type LogInterface
- type LogOptions
- type LogOutput
- type LogOutputWithDepthAdder
- type LogTagsFromContext
- type LoopbackAddr
- type LoopbackConn
- func (lc *LoopbackConn) Close() (err error)
- func (lc *LoopbackConn) LocalAddr() (addr net.Addr)
- func (lc *LoopbackConn) Read(b []byte) (n int, err error)
- func (lc *LoopbackConn) RemoteAddr() (addr net.Addr)
- func (lc *LoopbackConn) SetDeadline(_ time.Time) (err error)
- func (lc *LoopbackConn) SetReadDeadline(_ time.Time) (err error)
- func (lc *LoopbackConn) SetWriteDeadline(_ time.Time) (err error)
- func (lc *LoopbackConn) Write(b []byte) (n int, err error)
- type LoopbackListener
- type MemoryInstrumentationStorage
- type MethodNotFoundError
- type MethodType
- type MethodV1
- type MethodV2
- type MethodV2NotFoundError
- type Methoder
- type NetworkInstrumenter
- type NetworkInstrumenterStorage
- type NilLogOutput
- func (s NilLogOutput) Debugf(_ string, _ ...interface{})
- func (s NilLogOutput) Debugw(_ string, _ ...LogField)
- func (s NilLogOutput) Errorf(_ string, _ ...interface{})
- func (s NilLogOutput) Errorw(_ string, _ ...LogField)
- func (s NilLogOutput) Infof(_ string, _ ...interface{})
- func (s NilLogOutput) Infow(_ string, _ ...LogField)
- func (s NilLogOutput) Profilef(_ string, _ ...interface{})
- func (s NilLogOutput) Profilew(_ string, _ ...LogField)
- func (s NilLogOutput) Warnf(_ string, _ ...interface{})
- func (s NilLogOutput) Warnw(_ string, _ ...LogField)
- type NilProfiler
- type NilResultError
- type PacketizerError
- type Position
- type Profiler
- type Protocol
- type ProtocolNotFoundError
- type ProtocolUniqueID
- type ProtocolV2
- type ProtocolV2NotFoundError
- type ReceiverError
- type Remote
- type SPURI
- type SendNotifier
- type SeqNumber
- type ServeHandlerDescription
- type ServeHandlerDescriptionV2
- type Server
- type SimpleLog
- func (s SimpleLog) ClientCall(q SeqNumber, meth string, arg interface{})
- func (s SimpleLog) ClientCallCompressed(q SeqNumber, meth string, arg interface{}, ctype CompressionType)
- func (s SimpleLog) ClientCancel(q SeqNumber, meth string, err error)
- func (s SimpleLog) ClientNotify(meth string, arg interface{})
- func (s SimpleLog) ClientReply(q SeqNumber, meth string, err error, res interface{})
- func (s SimpleLog) FrameRead(bytes []byte)
- func (s SimpleLog) Infof(format string, args ...interface{})
- func (s SimpleLog) Infow(msg string, args ...LogField)
- func (s SimpleLog) ServerCall(q SeqNumber, meth string, err error, arg interface{})
- func (s SimpleLog) ServerCallCompressed(q SeqNumber, meth string, err error, arg interface{}, ctype CompressionType)
- func (s SimpleLog) ServerCancelCall(q SeqNumber, meth string)
- func (s SimpleLog) ServerNotifyCall(meth string, err error, arg interface{})
- func (s SimpleLog) ServerNotifyComplete(meth string, err error)
- func (s SimpleLog) ServerReply(q SeqNumber, meth string, err error, res interface{})
- func (s SimpleLog) ServerReplyCompressed(q SeqNumber, meth string, err error, res interface{}, ctype CompressionType)
- func (s SimpleLog) StartProfiler(format string, args ...interface{}) Profiler
- func (s SimpleLog) TransportError(e error)
- func (s SimpleLog) TransportStart()
- func (s SimpleLog) UnexpectedReply(seqno SeqNumber)
- func (s SimpleLog) Warnf(format string, args ...interface{})
- func (s SimpleLog) Warnw(msg string, args ...LogField)
- type SimpleLogFactory
- type SimpleLogOptions
- func (so SimpleLogOptions) ClientTrace() bool
- func (so SimpleLogOptions) FrameTrace() bool
- func (so SimpleLogOptions) Profile() bool
- func (so SimpleLogOptions) ServerTrace() bool
- func (so SimpleLogOptions) ShowAddress() bool
- func (so SimpleLogOptions) ShowArg() bool
- func (so SimpleLogOptions) ShowResult() bool
- func (so SimpleLogOptions) TransportStart() bool
- type SimpleLogOutput
- func (s SimpleLogOutput) Debugf(fmt string, args ...interface{})
- func (s SimpleLogOutput) Debugw(fmt string, args ...LogField)
- func (s SimpleLogOutput) Errorf(fmt string, args ...interface{})
- func (s SimpleLogOutput) Errorw(fmt string, args ...LogField)
- func (s SimpleLogOutput) Infof(fmt string, args ...interface{})
- func (s SimpleLogOutput) Infow(fmt string, args ...LogField)
- func (s SimpleLogOutput) Profilef(fmt string, args ...interface{})
- func (s SimpleLogOutput) Profilew(fmt string, args ...LogField)
- func (s SimpleLogOutput) Warnf(fmt string, args ...interface{})
- func (s SimpleLogOutput) Warnw(fmt string, args ...LogField)
- type SimpleProfiler
- type StandardLogOptions
- func (s *StandardLogOptions) ClientTrace() bool
- func (s *StandardLogOptions) FrameTrace() bool
- func (s *StandardLogOptions) Profile() bool
- func (s *StandardLogOptions) ServerTrace() bool
- func (s *StandardLogOptions) ShowAddress() bool
- func (s *StandardLogOptions) ShowArg() bool
- func (s *StandardLogOptions) ShowResult() bool
- func (s *StandardLogOptions) TransportStart() bool
- type TestLogger
- type Transporter
- type TypeError
- type TypeUniqueID
- type WrapErrorFunc
Constants ¶
const ConnectionLogMsgKey string = "msg"
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 DisableSigPipe ¶
func InstrumentTag ¶
func InstrumentTag(methodType MethodType, method string) string
func LogFieldsToString ¶
Join all the Key/Values together with equal signs. If there are >0 of them, then add the prefix, otherwise, just return an empty string.
func NewLoopbackConnPair ¶
func NewLoopbackConnPair() (*LoopbackConn, *LoopbackConn)
NewLoopbackConnPair makes a new loopback connection pair
func WithFireNow ¶
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 AlreadyRegisteredV2Error ¶
type AlreadyRegisteredV2Error struct {
// contains filtered or unexported fields
}
func (AlreadyRegisteredV2Error) Error ¶
func (a AlreadyRegisteredV2Error) Error() string
type BadLogFlagsError ¶
type BadLogFlagsError struct {
// contains filtered or unexported fields
}
func (BadLogFlagsError) Error ¶
func (b BadLogFlagsError) Error() string
func (BadLogFlagsError) String ¶
func (b BadLogFlagsError) String() 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 Methoder, 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) Call2 ¶
func (c *Client) Call2(ctx context.Context, method Methoder, arg interface{}, res interface{}, timeout time.Duration, ew ErrorUnwrapper) error
Call2 is like Call but you can pass an ErrorUnwrapper in with the call, as suitable to Snowpack RPC
func (*Client) CallCompressed ¶
func (c *Client) CallCompressed(ctx context.Context, method Methoder, 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 Methoder, 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 Methoder, 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 Methoder, 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 { Warnw(format string, fields ...LogField) Debugw(format string, fields ...LogField) Infow(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 *SPURI, l LogFactory, instrumenterStorage NetworkInstrumenterStorage, wef WrapErrorFunc, maxFrameLength int32) ConnectionTransport
NewConnectionTransport creates a ConnectionTransport for a given SPURI.
func NewConnectionTransportWithDialable ¶
func NewConnectionTransportWithDialable(uri *SPURI, l LogFactory, instrumenterStorage NetworkInstrumenterStorage, wef WrapErrorFunc, maxFrameLength int32, dialable Dialable) ConnectionTransport
NewConnectionTransportWithDialable creates a ConnectionTransport for a given SPURI 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 ¶
func (ct *ConnectionTransportTLS) Dial(ctx context.Context) ( Transporter, error)
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
type CtxRPCTags ¶
type CtxRPCTags map[string]interface{}
func TagsFromContext ¶
func TagsFromContext(ctx context.Context) (CtxRPCTags, bool)
TagsFromContext returns the tags being passed along with the given context.
type DebugLogHook ¶
type DebugLogHook func(s string, args ...interface{})
type DecodeError ¶
type DecodeError struct {
// contains filtered or unexported fields
}
func (DecodeError) Error ¶
func (r DecodeError) Error() string
type DecoderFactory ¶
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 ¶
func (d *DummyInstrumentationStorage) Put(context.Context, string, InstrumentationRecord) error
type EncoderFactory ¶
type ErrorUnwrapper ¶
type GenericClient ¶
type GenericClient interface { Transport(ctx context.Context) (Transporter, error) Call(ctx context.Context, method Methoder, arg interface{}, res interface{}, timeout time.Duration) error Call2(ctx context.Context, method Methoder, arg interface{}, res interface{}, timeout time.Duration, ew ErrorUnwrapper) error CallCompressed(ctx context.Context, method Methoder, arg interface{}, res interface{}, cType CompressionType, timeout time.Duration) error Notify(ctx context.Context, method Methoder, arg interface{}, timeout time.Duration) error }
GenericClient is the interface that is exported to autogenerated RPC stubs from AVDL files.
type InstrumentationRecord ¶
type LogFactory ¶
type LogFactory interface {
NewLog(net.Addr) LogInterface
}
type LogField ¶
type LogField struct { Key string Value interface{} }
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) Warnf(format string, args ...interface{}) Warnw(format string, args ...LogField) Infof(format string, args ...interface{}) Infow(format string, args ...LogField) }
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
func ParseStandardLogOptions ¶
func ParseStandardLogOptions(opts string) (LogOptions, error)
type LogOutput ¶
type LogOutput interface { Errorf(s string, args ...interface{}) Errorw(s string, args ...LogField) Warnf(s string, args ...interface{}) Warnw(s string, args ...LogField) Infof(s string, args ...interface{}) Infow(s string, args ...LogField) Debugf(s string, args ...interface{}) Debugw(s string, args ...LogField) Profilef(s string, args ...interface{}) Profilew(s string, args ...LogField) }
type LogOutputWithDepthAdder ¶
type LogOutputWithDepthAdder interface { LogOutput CloneWithAddedDepth(depth int) LogOutputWithDepthAdder }
type LogTagsFromContext ¶
type LoopbackAddr ¶
type LoopbackAddr struct{}
LoopbackAddr is an address class that implement the net.Addr interface for loopback devices
func (LoopbackAddr) Network ¶
func (la LoopbackAddr) Network() (s string)
Network returns the name of the network
func (LoopbackAddr) String ¶
func (la LoopbackAddr) String() (s string)
String returns the string form of address
type LoopbackConn ¶
type LoopbackConn struct {
// contains filtered or unexported fields
}
LoopbackConn implments the net.Conn interface but is used to loopback from a process to itself. It is goroutine safe.
func (*LoopbackConn) Close ¶
func (lc *LoopbackConn) Close() (err error)
Close closes the connection. Any blocked Read or Write operations will be unblocked and return errors.
func (*LoopbackConn) LocalAddr ¶
func (lc *LoopbackConn) LocalAddr() (addr net.Addr)
LocalAddr returns the local network address.
func (*LoopbackConn) Read ¶
func (lc *LoopbackConn) Read(b []byte) (n int, err error)
Read reads data from the connection.
func (*LoopbackConn) RemoteAddr ¶
func (lc *LoopbackConn) RemoteAddr() (addr net.Addr)
RemoteAddr returns the remote network address.
func (*LoopbackConn) SetDeadline ¶
func (lc *LoopbackConn) SetDeadline(_ time.Time) (err error)
SetDeadline sets the read and write deadlines associated with the connection. It is equivalent to calling both SetReadDeadline and SetWriteDeadline.
A deadline is an absolute time after which I/O operations fail with a timeout (see type Error) instead of blocking. The deadline applies to all future I/O, not just the immediately following call to Read or Write.
An idle timeout can be implemented by repeatedly extending the deadline after successful Read or Write calls.
A zero value for t means I/O operations will not time out.
func (*LoopbackConn) SetReadDeadline ¶
func (lc *LoopbackConn) SetReadDeadline(_ time.Time) (err error)
SetReadDeadline sets the deadline for future Read calls. A zero value for t means Read will not time out.
func (*LoopbackConn) SetWriteDeadline ¶
func (lc *LoopbackConn) SetWriteDeadline(_ time.Time) (err error)
SetWriteDeadline sets the deadline for future Write calls. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.
type LoopbackListener ¶
type LoopbackListener struct {
// contains filtered or unexported fields
}
LoopbackListener is a listener that creates new loopback connections. It is goroutine safe.
func NewLoopbackListener ¶
func NewLoopbackListener(lh DebugLogHook) *LoopbackListener
NewLoopbackListener creates a new Loopback listener
func (*LoopbackListener) Accept ¶
func (ll *LoopbackListener) Accept() (ret net.Conn, err error)
Accept waits for and returns the next connection to the listener.
func (*LoopbackListener) Addr ¶
func (ll *LoopbackListener) Addr() (addr net.Addr)
Addr returns the listener's network address.
func (*LoopbackListener) Close ¶
func (ll *LoopbackListener) Close() (err error)
Close closes the listener. Any blocked Accept operations will be unblocked and return errors
type MemoryInstrumentationStorage ¶
func NewMemoryInstrumentationStorage ¶
func NewMemoryInstrumentationStorage() *MemoryInstrumentationStorage
func (*MemoryInstrumentationStorage) Put ¶
func (s *MemoryInstrumentationStorage) Put(_ context.Context, tag string, record InstrumentationRecord) error
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 // V2 of Call and Notify use a more succint naming scheme. Methods are specified as [<unique-protocol-id>,<method-id>], // where the unique protocol ID is a random-ish 32-bit, 48-bit or 64-bit unsigned integer. The method-id is sequetial // within the protocol and will be almost always an unsigned 8-bit. MethodCallV2 MethodType = 5 MethodNotifyV2 MethodType = 6 MethodCancelV2 MethodType = 7 )
func (MethodType) String ¶
func (t MethodType) String() string
type MethodV1 ¶
type MethodV1 struct {
// contains filtered or unexported fields
}
func (*MethodV1) CallMethodType ¶
func (m *MethodV1) CallMethodType() MethodType
func (*MethodV1) CancelMethodType ¶
func (m *MethodV1) CancelMethodType() MethodType
func (*MethodV1) NotifyMethodType ¶
func (m *MethodV1) NotifyMethodType() MethodType
type MethodV2 ¶
type MethodV2 struct {
// contains filtered or unexported fields
}
func NewMethodV2 ¶
func NewMethodV2(p ProtocolUniqueID, m Position, n string) *MethodV2
func (*MethodV2) CallMethodType ¶
func (m *MethodV2) CallMethodType() MethodType
func (*MethodV2) CancelMethodType ¶
func (m *MethodV2) CancelMethodType() MethodType
func (*MethodV2) NotifyMethodType ¶
func (m *MethodV2) NotifyMethodType() MethodType
type MethodV2NotFoundError ¶
type MethodV2NotFoundError struct { ProtID ProtocolUniqueID Method Position ProtName string }
func NewMethodV2NotFoundError ¶
func NewMethodV2NotFoundError(protID ProtocolUniqueID, m Position, n string) MethodV2NotFoundError
func (MethodV2NotFoundError) Error ¶
func (m MethodV2NotFoundError) Error() string
type Methoder ¶
type Methoder interface { String() string CallMethodType() MethodType CancelMethodType() MethodType NotifyMethodType() MethodType // contains filtered or unexported methods }
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 NilLogOutput ¶
type NilLogOutput struct{}
func (NilLogOutput) Debugf ¶
func (s NilLogOutput) Debugf(_ string, _ ...interface{})
func (NilLogOutput) Debugw ¶
func (s NilLogOutput) Debugw(_ string, _ ...LogField)
func (NilLogOutput) Errorf ¶
func (s NilLogOutput) Errorf(_ string, _ ...interface{})
func (NilLogOutput) Errorw ¶
func (s NilLogOutput) Errorw(_ string, _ ...LogField)
func (NilLogOutput) Infof ¶
func (s NilLogOutput) Infof(_ string, _ ...interface{})
func (NilLogOutput) Infow ¶
func (s NilLogOutput) Infow(_ string, _ ...LogField)
func (NilLogOutput) Profilef ¶
func (s NilLogOutput) Profilef(_ string, _ ...interface{})
func (NilLogOutput) Profilew ¶
func (s NilLogOutput) Profilew(_ string, _ ...LogField)
func (NilLogOutput) Warnf ¶
func (s NilLogOutput) Warnf(_ string, _ ...interface{})
func (NilLogOutput) Warnw ¶
func (s NilLogOutput) Warnw(_ string, _ ...LogField)
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 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 ProtocolUniqueID ¶
type ProtocolUniqueID uint64
type ProtocolV2 ¶
type ProtocolV2 struct { Name string ID ProtocolUniqueID Methods map[Position]ServeHandlerDescriptionV2 WrapError WrapErrorFunc }
type ProtocolV2NotFoundError ¶
type ProtocolV2NotFoundError struct {
U ProtocolUniqueID
}
func NewProtocolV2NotFoundError ¶
func NewProtocolV2NotFoundError(u ProtocolUniqueID) ProtocolV2NotFoundError
func (ProtocolV2NotFoundError) Error ¶
func (p ProtocolV2NotFoundError) 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 ¶
NewFixedRemote returns a remote that always uses remoteAddr.
func NewPrioritizedRoundRobinRemote ¶
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 ¶
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 ServeHandlerDescription ¶
type ServeHandlerDescriptionV2 ¶
type ServeHandlerDescriptionV2 struct { ServeHandlerDescription Name string }
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 ¶
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) RegisterV2 ¶
func (s *Server) RegisterV2(p ProtocolV2) error
type SimpleLog ¶
type SimpleLog struct { Addr net.Addr Out LogOutput Opts LogOptions }
func (SimpleLog) ClientCall ¶
Call
func (SimpleLog) ClientCallCompressed ¶
func (s SimpleLog) ClientCallCompressed(q SeqNumber, meth string, arg interface{}, ctype CompressionType)
CallCompressed
func (SimpleLog) ClientCancel ¶
Cancel
func (SimpleLog) ClientNotify ¶
Notify
func (SimpleLog) ClientReply ¶
func (SimpleLog) ServerCall ¶
func (SimpleLog) ServerCallCompressed ¶
func (s SimpleLog) ServerCallCompressed(q SeqNumber, meth string, err error, arg interface{}, ctype CompressionType)
func (SimpleLog) ServerCancelCall ¶
func (SimpleLog) ServerNotifyCall ¶
func (SimpleLog) ServerNotifyComplete ¶
func (SimpleLog) ServerReply ¶
func (SimpleLog) ServerReplyCompressed ¶
func (s SimpleLog) ServerReplyCompressed(q SeqNumber, meth string, err error, res interface{}, ctype CompressionType)
func (SimpleLog) StartProfiler ¶
func (SimpleLog) TransportError ¶
func (SimpleLog) TransportStart ¶
func (s SimpleLog) TransportStart()
func (SimpleLog) UnexpectedReply ¶
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) Debugf ¶
func (s SimpleLogOutput) Debugf(fmt string, args ...interface{})
func (SimpleLogOutput) Debugw ¶
func (s SimpleLogOutput) Debugw(fmt string, args ...LogField)
func (SimpleLogOutput) Errorf ¶
func (s SimpleLogOutput) Errorf(fmt string, args ...interface{})
func (SimpleLogOutput) Errorw ¶
func (s SimpleLogOutput) Errorw(fmt string, args ...LogField)
func (SimpleLogOutput) Infof ¶
func (s SimpleLogOutput) Infof(fmt string, args ...interface{})
func (SimpleLogOutput) Infow ¶
func (s SimpleLogOutput) Infow(fmt string, args ...LogField)
func (SimpleLogOutput) Profilef ¶
func (s SimpleLogOutput) Profilef(fmt string, args ...interface{})
func (SimpleLogOutput) Profilew ¶
func (s SimpleLogOutput) Profilew(fmt string, args ...LogField)
func (SimpleLogOutput) Warnf ¶
func (s SimpleLogOutput) Warnf(fmt string, args ...interface{})
func (SimpleLogOutput) Warnw ¶
func (s SimpleLogOutput) Warnw(fmt string, args ...LogField)
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 // KillIncoming stops processing incoming RPC messages. For calls, // it will reply with the given error. For notifies, it will ignore // the message. KillIncoming(err error) // Conn is the underlying Go connection that this Transport wraps Conn() net.Conn // Close closes the transport and releases resources. Close() // contains filtered or unexported methods }
func NewTransport ¶
func NewTransport(ctx context.Context, 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
type TypeUniqueID ¶
type TypeUniqueID uint64
func (TypeUniqueID) EncodeToBytes ¶
func (t TypeUniqueID) EncodeToBytes(b []byte)
type WrapErrorFunc ¶
type WrapErrorFunc func(error) interface{}
Source Files
¶
- call.go
- client.go
- codec.go
- compress_gzip.go
- compress_msgpackzip.go
- compressor.go
- connection.go
- connection_log.go
- connection_test_util.go
- context.go
- copy_tls_config_go18.go
- dispatch.go
- errors.go
- fmp_uri.go
- instrument.go
- log.go
- log_test_util.go
- loopback.go
- message.go
- packetizer.go
- protocol.go
- receiver.go
- reconnect_backoff.go
- remote.go
- request.go
- server.go
- sigpipe.go
- transport.go
- types.go
- util.go