rpc

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LOff    = iota // Log nothing about core and rpc operation.
	LInfo   = iota // Log status of routes, links and names.
	LDetail = iota // Also log query-announce and rpc protocol events.
)

Verbosity levels in logging.

View Source
const (
	UpStart      = 2
	UpData       = 3
	UpClose      = 4
	UpCancel     = 5
	DownResponse = 8
	DownData     = 9
	DownFinish   = 10
)
View Source
const TokenLength uint = 0

TokenLength is the length of a token in bytes.

Variables

View Source
var BlankAddress = &Address{}

BlankAddress is an address that has no parts.

View Source
var HANDLER_UNUSED_ID uint64 = 0
View Source
var LogLevel int = LInfo

LogLevel changes the amount of logged messages. It only applies when cores are being created.

Functions

func FrameToProtoClearTicket

func FrameToProtoClearTicket(f Frame) *pb.RPCFrame

func IsUpstream

func IsUpstream(f Frame) bool

IsUpstream returns true if the frame goes from client to server, false if it goes from server to client (downstream)

func IsValidShortID

func IsValidShortID(x ShortID) bool

IsValidShortID checks if the given number is a valid value for a ShortID.

func MetricToProto

func MetricToProto(m Metric) *pb.Metric

func NewClientCall

func NewClientCall(identity uint64, infoStr string, ctx context.Context, memm MemoryManager) (*ClientCall, Handler)

func NewRunningQuery

func NewRunningQuery() *runningQuery

func RandHandlerID

func RandHandlerID() uint64

RandHandlerID returns a random uint64 that excludes some reserved numbers.

func ShortIDString

func ShortIDString(x ShortID) string

ShortIDString returns a shortened string representation of the ShortID.

Types

type Address

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

Address is an immutable data structure of a sequence of segment, like parts in a filesystem path. Modifications are cheap operations without any copies by modifying and chaining slice headers. However some operations trigger compactification of all slices into a single continuous string which can be used for serialization or as a comparable map key. The compactification does not change the represented address but is a costly copy so addresses should generally be passed around as pointer so this step is done only once. Since an address is immutable, a once compacted address never becomes uncompact again.

func AddrLocal

func AddrLocal() *Address

AddrLocal returns a static address prefix representing local addresses. This prefix will be substituted with the address of the local group.

func AddressFromProto

func AddressFromProto(ap []byte) *Address

func MustParseAddress

func MustParseAddress(s string) *Address

MustParseAddress same as ParseAddress but panics on error.

func NewAddress

func NewAddress(parts ...string) *Address

NewAddress creates a new address from the given strings, each one part of the address sequence. The resulting address is compact.

func NewAddressFromData

func NewAddressFromData(s string) *Address

NewAddressFromData creates a new address from the given data string which must be the result from Address.Data(). The resulting address is compact and this operation is fast.

func ParseAddress

func ParseAddress(s string) (*Address, error)

ParseAddress parses a string into an address.

func (Address) Append

func (a Address) Append(other ...*Address) *Address

Append returns a new address that is a concatenation of this and the other addresses. No data is copied, the result is not compact.

func (Address) Appends

func (a Address) Appends(other ...string) *Address

Appends returns a new address that is a concatenation of this and the other strings, each one address part. No data is copied, the result is not compact.

func (*Address) Compact

func (a *Address) Compact() *IBList

Compact optimizes the data representation of this address into a single contigous string. Is a no-op if this address is already compact.

func (*Address) Compare

func (a *Address) Compare(other *Address) int

This operation compacts both addresses..

func (*Address) Data

func (a *Address) Data() string

Data returns the raw string representation of this address. An address can be reconstructed from this string quickly without parsing. This operation compacts the address and once compacted, it is quick without further copies or string construction.

func (Address) Equal

func (a Address) Equal(other *Address) bool

func (Address) Get

func (a Address) Get(i int) string

Get returns a part of the address.

func (Address) Iter

func (a Address) Iter() func() (string, bool)

func (Address) Len

func (a Address) Len() int

func (Address) Slice

func (a Address) Slice(from, to int) *Address

Slice returns a new address that is a sub list of this address. A 'to'-value of -1 means till the end. / No data is copied, the result is not compact.

func (Address) StartsWith

func (a Address) StartsWith(other *Address) bool

func (*Address) String

func (a *Address) String() string

String returns a string of the contents of this address with an arbitrary separation character. Note that the address may not be a legal UTF-8 string and can contain arbitrary byte sequences. This operation compacts the address and once compacted, it is quick without further copies or string construction.

func (Address) ToProto

func (a Address) ToProto() []byte

type AnnounceFrame

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

func NewAnnounceFrame

func NewAnnounceFrame(name *Address, metric Metric, deadline time.Time) *AnnounceFrame

func NewAnnounceFrameFromProto

func NewAnnounceFrameFromProto(m *pb.Announce) *AnnounceFrame

func (*AnnounceFrame) Deadline

func (f *AnnounceFrame) Deadline() time.Time

func (*AnnounceFrame) Metric

func (f *AnnounceFrame) Metric() Metric

func (*AnnounceFrame) Name

func (f *AnnounceFrame) Name() *Address

func (*AnnounceFrame) Proto

func (f *AnnounceFrame) Proto() *pb.Announce

type ByteArray

type ByteArray = []byte

type Call

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

func (*Call) Ctx

func (call *Call) Ctx() context.Context

func (*Call) RPC

func (call *Call) RPC() *RPC

type CancelError

type CancelError struct {
	Message string
}

func (CancelError) Error

func (t CancelError) Error() string

type Chunk

type Chunk struct {
	Data      []byte
	Remaining int
	// contains filtered or unexported fields
}

Chunk is a payload fragment. Large payloads can be split across multiple chunks.

type ChunkFrame

type ChunkFrame interface {
	Frame
	Chunk() *Chunk
}

type ClientCall

type ClientCall struct {
	Call
	// contains filtered or unexported fields
}

func (*ClientCall) Cancel

func (c *ClientCall) Cancel(message string)

func (*ClientCall) CloseSend

func (c *ClientCall) CloseSend()

func (*ClientCall) Init

func (c *ClientCall) Init(rpc *RPC, rcv FrameReceiver, snd FrameSender)

func (*ClientCall) Receive

func (c *ClientCall) Receive() ([]byte, error)

func (*ClientCall) Send

func (c *ClientCall) Send(data []byte) error

type ClosedError

type ClosedError struct{}

func (ClosedError) Error

func (r ClosedError) Error() string

type Core

type Core struct {
	// TODO consider optimizing thread sync. there are also mutexes in manager and router, maybe 'm' is redundant, or the others are.
	// But the slow query requires a short mutex and the router but should not block the whole core.
	Manager
	// contains filtered or unexported fields
}

Core is a central component of an Arpc network node. It is responsible for holding all active RPCs, all active routes, dispatching messages and resolving routes for new RPCs.

func NewCore

func NewCore(group *Address, maxMemory int) *Core

NewCore creates a new core instance with a random core identifier suffix. This is recommended for general use.

func NewCoreExt

func NewCoreExt(group *Address, maxMemory int, coreID string) (core *Core)

NewCoreExt creates a new core instance with given parameters. Provides more parameterization options than NewCore.

func (*Core) Group

func (c *Core) Group() *Address

Group is the address prexis this core operates in.

func (*Core) ID

func (c *Core) ID() *Address

ID is a unique identifier for this core. It includes the group ID as a prefix.

func (*Core) Log

func (c *Core) Log() util.Logger

Log returns the logger of the core. All log messages specific to a core should use this logger so logs from different cores can be distinguished in tests.

func (*Core) MemMan

func (c *Core) MemMan() MemoryManager

MemMan returns the memory management module of the core.

func (*Core) Quanda

func (c *Core) Quanda() *Quanda

Quanda returns the query and announce module of the core.

func (*Core) QueryRoute

func (c *Core) QueryRoute(ctx context.Context, dest *Address, remoteQuery bool) (*Address, Handler, error)

QueryRoute looks up a route by quering the network. It returns immediately if a route to the destination is already known at the core. Otherwise a network query is run that blocks until it times out or a solution is found. The timeout can be shortened by setting one in the provided context. If a route is found, returns the address for the found route, which may be a parent of the queried destination, and the route handler. Otherwise returns an error.

func (*Core) RouteAndDispatch

func (c *Core) RouteAndDispatch(ctx context.Context, frame Frame, downstreamHandler Handler) error

RouteAndDispatch dispatches frames to their destination. If it is a start frame, a route to its destination is looked up and a local routing entry for the RPC is tracked. Returns an error if no routing entry exists for the frame, if no route can be found to the destination of a start frame or if starting the RPC fails for other reasons.

func (*Core) Router

func (c *Core) Router() Router

Router returns the routing module of the core.

func (*Core) StartRPC

func (c *Core) StartRPC(ctx context.Context, dest *Address, metadata []string, props map[string][]byte, downstreamHandler Handler) error

StartRPC starts a new RPC from this core. A route to its destination is looked up and a local routing entry for the RPC is tracked. Returns an error if no route can be found to the destination of a start frame or if starting the RPC fails for other reasons.

func (*Core) Stop

func (c *Core) Stop()

Stop terminates operation of this core.

type DestinationEvent

type DestinationEvent struct {
	Dest   *Address
	Route  Identifiable
	Metric Metric
}

func (DestinationEvent) String

func (e DestinationEvent) String() string

type DestinationEventListener

type DestinationEventListener func(*DestinationEvent)

type DownDataFrame

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

DownDataFrame is a data chunk sent from the server to the client.

func NewDownDataFrame

func NewDownDataFrame(shortID ShortID, chunk *Chunk) DownDataFrame

func (DownDataFrame) Chunk

func (t DownDataFrame) Chunk() *Chunk

func (DownDataFrame) ID

func (t DownDataFrame) ID() ShortID

func (DownDataFrame) Proto

func (t DownDataFrame) Proto() *pb.RPCFrame

func (DownDataFrame) String

func (t DownDataFrame) String() string

func (DownDataFrame) Type

func (t DownDataFrame) Type() int

type DownFinishFrame

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

DownFinishFrame is sent by the server when it completes the RPC, either regularly (status==0) or in error.

func NewDownFinishFrame

func NewDownFinishFrame(shortID ShortID, status int, message string, md []string) DownFinishFrame

func (DownFinishFrame) ID

func (t DownFinishFrame) ID() ShortID

func (DownFinishFrame) Message

func (t DownFinishFrame) Message() string

func (DownFinishFrame) Metadata

func (t DownFinishFrame) Metadata() []string

func (DownFinishFrame) Proto

func (t DownFinishFrame) Proto() *pb.RPCFrame

func (DownFinishFrame) Status

func (t DownFinishFrame) Status() int

func (DownFinishFrame) String

func (t DownFinishFrame) String() string

func (DownFinishFrame) Type

func (t DownFinishFrame) Type() int

type DownResponseFrame

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

DownResponseFrame is response metadata sent from the server after starting the RPC, typically before sending data.

func NewDownResponseFrame

func NewDownResponseFrame(shortID ShortID, md []string) DownResponseFrame

func (DownResponseFrame) ID

func (t DownResponseFrame) ID() ShortID

func (DownResponseFrame) Metadata

func (t DownResponseFrame) Metadata() []string

func (DownResponseFrame) Proto

func (t DownResponseFrame) Proto() *pb.RPCFrame

func (DownResponseFrame) String

func (t DownResponseFrame) String() string

func (DownResponseFrame) Type

func (t DownResponseFrame) Type() int

type FinishError

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

func (FinishError) Error

func (t FinishError) Error() string

func (FinishError) Message

func (t FinishError) Message() string

func (FinishError) Metadata

func (t FinishError) Metadata() []string

func (FinishError) StatusCode

func (t FinishError) StatusCode() int

type Frame

type Frame interface {
	ID() ShortID
	Type() int
	Proto() *pb.RPCFrame
	String() string
}

Frame is the basic frame for all rpc protocol related messages.

func FrameFromProto

func FrameFromProto(msg *pb.RPCFrame, memm MemoryManager) Frame

type FrameCallback

type FrameCallback func(rpc *RPC, frame Frame)

type FrameReceiver

type FrameReceiver func(context.Context) (Frame, error)

type FrameSender

type FrameSender func(context.Context, Frame) error

type FullID

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

FullID is the full ID for a connection.

func NewFullID

func NewFullID(short ShortID, source *Address, dest *Address, token []byte) *FullID

NewFullID create a FullID.

func RandomFullID

func RandomFullID(source *Address, dest *Address) *FullID

RandomFullID creates a random FullID.

func (*FullID) Dest

func (t *FullID) Dest() *Address

func (*FullID) ID

func (t *FullID) ID() ShortID

func (*FullID) Source

func (t *FullID) Source() *Address

func (*FullID) String

func (t *FullID) String() string

type HalfCloseError

type HalfCloseError struct {
}

func (HalfCloseError) Error

func (t HalfCloseError) Error() string

type Handler

type Handler interface {
	Identifiable
	Init(*RPC, FrameReceiver, FrameSender)
}

Handler handles one direction of the communication for an RPC. An RPC has 2 Handler, one for upstream (to the server) and one downstream (to the client).

type IBList

type IBList string

first 2 bytes contains number of parts: n then n-1 times 2 bytes indexes of each part after the first after n * 2 bytes the first part

func NewIBList

func NewIBList(bss ...string) (res IBList)

func (IBList) Get

func (ib IBList) Get(i int) string

func (IBList) Len

func (ib IBList) Len() int

func (IBList) String

func (ib IBList) String() string

type IDCollision

type IDCollision struct {
	ID ShortID
}

func (IDCollision) Error

func (t IDCollision) Error() string

type IDMismatch

type IDMismatch struct {
	Frame Frame
}

func (IDMismatch) Error

func (t IDMismatch) Error() string

type IDUnknown

type IDUnknown struct {
	Frame Frame
}

func (IDUnknown) Error

func (t IDUnknown) Error() string

type Identifiable

type Identifiable interface {
	// Must be constant and sufficiently unique for security purposes.
	ID() uint64
	String() string
}

type InitFunc

type InitFunc func(*RPC, FrameReceiver, FrameSender)

type LinkHandler

type LinkHandler struct {
	MultiRPCHandler
	// contains filtered or unexported fields
}

implements Handler

func NewLinkHandler

func NewLinkHandler(id uint64, infoString string, initRPC InitFunc, send func(*pb.LinkFrame) error) *LinkHandler

func (*LinkHandler) Send

func (lh *LinkHandler) Send(lf *pb.LinkFrame) error

type Manager

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

The Manager holds all active RPCs. Its biggest function is that it works as a demultiplexer by dispatching RPCFrames to the RPC they belong to based on the RPC ID. Here one can also register listeners RPC events and track statistics. Unless we go for keepalives and auto cleanup, the manager is not responsible for closing RPCs, this is the job of the module who creates the RPC.

func NewManager

func NewManager() *Manager

func (*Manager) Add

func (rpcm *Manager) Add(rpc *RPC) error

Add registers an RPC at the manager. It must be unstarted, no frames have been sent yet. The RPC is automatically removed after it finishes.

func (*Manager) AddListener

func (t *Manager) AddListener(cb FrameCallback)

func (*Manager) Dispatch

func (rpcm *Manager) Dispatch(ctx context.Context, frame Frame, identity uint64) error

func (*Manager) GetRPCs

func (rpcm *Manager) GetRPCs() []*RPC

GetRPCs returns a snapshot list of current active RPCs. For debugging, slow.

type MemoryManager

type MemoryManager interface {
	// The total memory managed by this instance.
	Max() int
	// A snapshot of the memory amount currently acquired, only for debugging purposes and may be slow.
	Used() int
	// Reserve some of the memory from the manager. This blocks until enough memory is available.
	// The returned ticket must be released eventually!
	Acquire(int) MemoryTicket
	// Reserve some of the memory from the manager only if enough memory is available, never blocks.
	// If a ticket is returned, it must be released eventually!
	AcquireLow(int) MemoryTicket

	AcquireCtx(context.Context, int) (MemoryTicket, error)
	// contains filtered or unexported methods
}

A MemoryManager helps track and limit memory consumption of certain processes. It guards an amount of memory. To use some of this memory, a ticket must be acquired and released later to free the memory for other users.

func NewCondMemoryManager

func NewCondMemoryManager(max int) MemoryManager

NewCondMemoryManager creates a memory manager that uses a central mutex for all memory interactions.

func NewNoMemoryManager

func NewNoMemoryManager() MemoryManager

type MemoryTicket

type MemoryTicket interface {
	// Size returns the amount of memory that can be used with this ticket.
	Size() int
	// Reduce can be used to lower the ticket size if it turns out that less memory is needed.
	// Implementations can choose to ignore this or shrink less than requested.
	ReduceTo(newSize int)
	// Release to set the ticket size to 0 and free all memory.
	Release()
}

A MemoryTicket allows an amount of memory to be used.

type Metric

type Metric struct {
	Hops int
}

Metric describes the quality of a route. It has a comparison function to sort metrics from best to worst routes.

var MetricOffline Metric = Metric{Hops: -1}

func MetricFromProto

func MetricFromProto(m *pb.Metric) Metric

func (Metric) String

func (m Metric) String() string

type MultiRPCHandler

type MultiRPCHandler struct {
	SingleRPCHandler
	// contains filtered or unexported fields
}

MultiRPCHandler is an implementation of Handler that tracks open RPCs and aborts them when the handler is closed.

func NewMultiRPCHandler

func NewMultiRPCHandler(id uint64, infoString string, initRPC InitFunc) *MultiRPCHandler

func NewServerCallHandler

func NewServerCallHandler(identity uint64, infoStr string, ctx context.Context, memm MemoryManager, serverCallHandler func(serverCall *ServerCall)) *MultiRPCHandler

func (*MultiRPCHandler) Close

func (r *MultiRPCHandler) Close()

Close sends a signal to all active RPCs over this route to abort and push a finish frame. NOT THREAD SAFE

func (*MultiRPCHandler) Init

func (r *MultiRPCHandler) Init(rpc *RPC, rcv FrameReceiver, snd FrameSender)

Init implements Handler.Init. NOT THREAD SAFE

type PrefixMapEntry

type PrefixMapEntry struct {
	Key   *Address
	Value interface{}
}

type PrefixTreeMap

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

func (*PrefixTreeMap) Clear

func (ptm *PrefixTreeMap) Clear()

Clear removes all entries from the tree.

func (*PrefixTreeMap) Get

func (ptm *PrefixTreeMap) Get(key *Address) interface{}

func (PrefixTreeMap) GetChildren

func (ptm PrefixTreeMap) GetChildren(key *Address) (children []PrefixMapEntry)

GetChildren returns the direct children of a node, if one exists for the given key. Otherwise returns nil. Values can be nil if the child node has no value directly assigned to it.

func (PrefixTreeMap) GetNearest

func (ptm PrefixTreeMap) GetNearest(key *Address) (depth int, value interface{})

GetNearest returns the entry of the tree with the most matching prefix of the given key and the value associated with it, which can be nil. Returns a length 0 key if no entry with any matching prefix exist.

func (PrefixTreeMap) GetSubtree

func (ptm PrefixTreeMap) GetSubtree(key *Address) (entries []PrefixMapEntry)

GetSubtree returns all keys with values of the subtree including the given key, or nil if the key is not part of the tree.

func (PrefixTreeMap) IterateSubtree

func (ptm PrefixTreeMap) IterateSubtree(key *Address, action func(PrefixMapEntry) bool)

IterateSubtree performs the action on all nodes of the entire subtree, including keys with nil values. Aborts when the action returns false.

func (*PrefixTreeMap) Put

func (ptm *PrefixTreeMap) Put(key *Address, value interface{}) (previousValue interface{})

Put maps the given key to the given value and returns the previously mapped value, which can be nil.

func (*PrefixTreeMap) Remove

func (ptm *PrefixTreeMap) Remove(key *Address) (previousValue interface{})

Remove clears the mapped value of the given key. If the key is parent of another key, its value is set to nil. Returns the previous value, which can be nil.

func (PrefixTreeMap) RemoveSubtree

func (ptm PrefixTreeMap) RemoveSubtree(key *Address) (entries []PrefixMapEntry)

RemoveSubtree removes the subtree including the given key and returns the removed entries, or nil if the key is not part of the tree.

func (*PrefixTreeMap) Size

func (ptm *PrefixTreeMap) Size() int

type Quanda

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

Quanda is a module handling the query and announce protocol.

func NewQuanda

func NewQuanda(router Router, log util.Logger) (quanda *Quanda)

func (*Quanda) HandleAnnounce

func (qa *Quanda) HandleAnnounce(announce *AnnounceFrame, handler *LinkHandler)

func (*Quanda) HandleQuery

func (qa *Quanda) HandleQuery(query *QueryFrame, handler *LinkHandler)

func (*Quanda) OpenQueryNames

func (qa *Quanda) OpenQueryNames() (openQueries []*Address)

func (*Quanda) Stop

func (qa *Quanda) Stop()

type QueryFrame

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

func NewQueryFrame

func NewQueryFrame(name *Address, deadline time.Time) *QueryFrame

func NewQueryFrameFromProto

func NewQueryFrameFromProto(m *pb.Query) *QueryFrame

func (*QueryFrame) Deadline

func (f *QueryFrame) Deadline() time.Time

func (*QueryFrame) Name

func (f *QueryFrame) Name() *Address

func (*QueryFrame) Proto

func (f *QueryFrame) Proto() *pb.Query

type RPC

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

RPC is the local handler for an end-to-end bidirectional communication channel. 1. ClientCaller creates RPC 2. ClientCaller has downstream handler, sets it to RPC 3. Someone looks up upstream handler and sets it to RPC 4. Use RPC, send messages, start with Start 5. ClientCaller close the RPC to close the channels

func New

func New(ID *FullID) *RPC

func (*RPC) Abort

func (rpc *RPC) Abort(msg string)

Abort stops this RPC externally by sending cancel and finish frames in both directions of the RPC

func (*RPC) Finished

func (rpc *RPC) Finished() bool

Finished returns true when the call has finished, either due to a server Finished-frame or a client Cancel-frame.

func (*RPC) FullID

func (r *RPC) FullID() *FullID

func (*RPC) Log

func (r *RPC) Log() util.Logger

func (*RPC) SetDownstreamHandler

func (rpc *RPC) SetDownstreamHandler(handler Handler)

SetDownstreamHandler sets the handler of the client side of the connection, the initiator.

func (*RPC) SetUpstreamHandler

func (rpc *RPC) SetUpstreamHandler(handler Handler)

SetUpstreamHandler sets the handler on the server side of the connection, the receiver.

func (*RPC) Status

func (rpc *RPC) Status() (uint32, string)

type RPCNotStartedError

type RPCNotStartedError struct {
}

func (RPCNotStartedError) Error

func (t RPCNotStartedError) Error() string

type RouteMap

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

RouteMap is a bitchy data structure that basically has a bidrectional mapping.

First, the obvious use case, given a destination as a query, it has to return the best route to that destination. So some map lookup structure with addresses as keys and a selection of routes as result, of which we can pick the best. Ergo destToRouteMap which has as value a routeHeap where we can retrieve the shortest route.

Second, routes can be updated and a single route can serve multiple destinations, so we need a lookup map with route ids as key to get a second map with destination as key to get a handle to the routeHeap element to change.

func NewRouteMap

func NewRouteMap() *RouteMap

NewRouteMap initializes an empty RouteMap.

func (*RouteMap) Add

func (rmap *RouteMap) Add(r Identifiable) error

Add puts a route in the list of available routes. Initially no destinations are reachable via this route.

func (*RouteMap) AddListener

func (rmap *RouteMap) AddListener(listener DestinationEventListener)

func (*RouteMap) DestinationOffline

func (rmap *RouteMap) DestinationOffline(dest *Address, r Identifiable)

DestinationOffline removes the route as option for the given destination.

func (*RouteMap) DestinationUpdate

func (rmap *RouteMap) DestinationUpdate(dest *Address, r Identifiable, metric Metric)

DestinationUpdate updates the route for a destination with a changed metric, possibly changing the best route for the destination.

func (*RouteMap) Get

func (rmap *RouteMap) Get(id uint64) Identifiable

func (*RouteMap) GetAll

func (rmap *RouteMap) GetAll() (res []Identifiable)

func (*RouteMap) GetNearest

func (rmap *RouteMap) GetNearest(dest *Address) (int, Identifiable, Metric)

func (*RouteMap) Remove

func (rmap *RouteMap) Remove(r Identifiable) bool

Remove takes the route and all destinations that were reachable via this route offline.

func (*RouteMap) Route

func (rmap *RouteMap) Route(dest *Address) Identifiable

Route returns the best route to the destination, or nil if no route is currently available.

type Router

type Router interface {
	Route(dest *Address) Identifiable
	GetNearest(dest *Address) (int, Identifiable, Metric)

	Add(r Identifiable) error
	Get(id uint64) Identifiable
	GetAll() []Identifiable

	DestinationOffline(dest *Address, r Identifiable)
	DestinationUpdate(dest *Address, r Identifiable, metric Metric)
	Remove(h Identifiable) bool

	AddListener(listener DestinationEventListener)
}

type RoutingError

type RoutingError struct {
	Dest  *Address
	Cause error
}

RoutingError is an error issued when an RPC cannot start because no route to its destination could be found.

func (RoutingError) Error

func (e RoutingError) Error() string

type ServerCall

type ServerCall struct {
	Call
	// contains filtered or unexported fields
}

func (*ServerCall) Finish

func (c *ServerCall) Finish()

func (*ServerCall) FinishExt

func (c *ServerCall) FinishExt(code codes.Code, message string, md []string)

func (*ServerCall) Receive

func (c *ServerCall) Receive() ([]byte, error)

func (*ServerCall) Send

func (c *ServerCall) Send(data []byte) error

type ServerCallFactory

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

func (*ServerCallFactory) Init

func (scf *ServerCallFactory) Init(rpc *RPC, rcv FrameReceiver, snd FrameSender)

type ShortID

type ShortID = uint64

ShortID is the part of the ID used in all communication of a connection.

func RandomShortID

func RandomShortID() ShortID

RandomShortID generated a random ShortID.

type SingleRPCHandler

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

SingleRPCHandler is an implementation of Handler for a single RPC.

func NewSingleRPCHandler

func NewSingleRPCHandler(id uint64, infoString string, initRPC InitFunc) *SingleRPCHandler

func (*SingleRPCHandler) Close

func (r *SingleRPCHandler) Close()

NOT THREAD SAFE

func (*SingleRPCHandler) ID

func (r *SingleRPCHandler) ID() uint64

ID implements Identifiable.ID

func (*SingleRPCHandler) Init

func (r *SingleRPCHandler) Init(rpc *RPC, rcv FrameReceiver, snd FrameSender)

Init implements Handler.Init. NOT THREAD SAFE

func (*SingleRPCHandler) String

func (r *SingleRPCHandler) String() string

String implements Identifiable.String

type UpCancelFrame

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

UpCancelFrame tells upstream the client has abandoned this RPC.

func NewUpCancelFrame

func NewUpCancelFrame(shortID ShortID, message string) UpCancelFrame

func (UpCancelFrame) ID

func (t UpCancelFrame) ID() ShortID

func (UpCancelFrame) Message

func (t UpCancelFrame) Message() string

func (UpCancelFrame) Proto

func (t UpCancelFrame) Proto() *pb.RPCFrame

func (UpCancelFrame) String

func (t UpCancelFrame) String() string

func (UpCancelFrame) Type

func (t UpCancelFrame) Type() int

type UpCloseFrame

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

UpCloseFrame indicates upstream that the client is finished sending data.

func NewUpCloseFrame

func NewUpCloseFrame(shortID ShortID) UpCloseFrame

func (UpCloseFrame) ID

func (t UpCloseFrame) ID() ShortID

func (UpCloseFrame) Proto

func (t UpCloseFrame) Proto() *pb.RPCFrame

func (UpCloseFrame) String

func (t UpCloseFrame) String() string

func (UpCloseFrame) Type

func (t UpCloseFrame) Type() int

type UpDataFrame

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

func NewUpDataFrame

func NewUpDataFrame(shortID ShortID, chunk *Chunk) UpDataFrame

func (UpDataFrame) Chunk

func (t UpDataFrame) Chunk() *Chunk

func (UpDataFrame) ID

func (t UpDataFrame) ID() ShortID

func (UpDataFrame) Proto

func (t UpDataFrame) Proto() *pb.RPCFrame

func (UpDataFrame) String

func (t UpDataFrame) String() string

func (UpDataFrame) Type

func (t UpDataFrame) Type() int

type UpStartFrame

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

UpStartFrame initiates an RPC and is upstream.

func NewUpStartFrame

func NewUpStartFrame(fullId *FullID, metadata []string, props map[string][]byte) UpStartFrame

func (UpStartFrame) Dest

func (t UpStartFrame) Dest() *Address

func (UpStartFrame) ID

func (t UpStartFrame) ID() ShortID

func (UpStartFrame) Metadata

func (t UpStartFrame) Metadata() []string

func (UpStartFrame) Properties

func (t UpStartFrame) Properties() map[string][]byte

func (UpStartFrame) Proto

func (t UpStartFrame) Proto() *pb.RPCFrame

func (UpStartFrame) Source

func (t UpStartFrame) Source() *Address

func (UpStartFrame) String

func (t UpStartFrame) String() string

func (UpStartFrame) Type

func (t UpStartFrame) Type() int

Jump to

Keyboard shortcuts

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