Documentation ¶
Index ¶
- Constants
- func NewRpcPacketFilterList() *rpcPacketFilterList
- type App
- type Cluster
- type Config
- type Raft
- func (r *Raft) AddPeer(addr string) error
- func (r *Raft) Barrier(timeout time.Duration) error
- func (r *Raft) Close()
- func (r *Raft) Command(cmd string, params interface{}, timeout time.Duration) error
- func (r *Raft) DelPeer(addr string) error
- func (r *Raft) GetPeers() ([]string, error)
- func (r *Raft) IsLeader() bool
- func (r *Raft) Leader() string
- func (r *Raft) LeaderCh() <-chan bool
- func (r *Raft) SetPeers(addrs []string) error
- type RaftConfig
- type RpcAddress
- type RpcData
- type RpcEndpoint
- type RpcError
- type RpcInMemoryAddress
- type RpcInMemoryTransport
- type RpcMux
- func (mux *RpcMux) AddPacketFilter(direction int, f *RpcPacketFilter, sequence int64) uint64
- func (mux *RpcMux) ClearPacketFilters(direction int)
- func (mux *RpcMux) GetAddress() RpcAddress
- func (mux *RpcMux) Handle(pkt *RpcPacket)
- func (mux *RpcMux) NewService(destination RpcAddress, service string, parameters RpcParameters) *RpcService
- func (mux *RpcMux) RegisterEndpoint(service string, endpoint RpcEndpoint)
- func (mux *RpcMux) RemovePacketFilter(direction int, f *RpcPacketFilter) bool
- func (mux *RpcMux) RemovePacketFilterById(direction int, id uint64) bool
- func (mux *RpcMux) SendAsync(dest *RpcAddress, service string, request *RpcRequest, ...)
- func (mux *RpcMux) SendSync(dest *RpcAddress, service string, request *RpcRequest, ...) *RpcReply
- func (mux *RpcMux) Shutdown()
- type RpcPacket
- type RpcPacketFilter
- type RpcPacketFilterAction
- type RpcParameters
- type RpcReply
- type RpcRequest
- type RpcService
- type RpcTransport
Constants ¶
const ( ClusterStateNew = "new" ClusterStateExisting = "existing" )
const ( RpcPktRequest = iota // This packet is a request RpcPktReply = iota // This packet is a reply )
const ( RpcErrNone = iota // There has been no error RpcErrTimeout = iota // A timeout has occurred RpcErrShutdown = iota // A shutdown occurred whilst processing the request RpcErrCouldNotSend = iota // Could not send the request RpcErrBadService = iota // The destination does not recognise the service RpcErrBadAddr = iota // The address is bad RpcErrProhibited = iota // Prohibited by filter list RpcErrNotLeader = iota // The RPC command cannot be executed as it was sent to the leader but the recipient was not the leader at the relevant time RpcErrRedirect = iota // The RPC command is redirected elsewhere )
const ( RpcDirectionTx = iota RpcDirectionRx = iota )
Directions of RPC packet
const ( RpcPacketFilterActionNext = iota // Pass the packet to the next filter in the list (default) RpcPacketFilterActionAccept = iota // Accept the packet, and do not pass to the next filter in the list RpcPacketFilterActionReject = iota // Reject the packet, and do not pass to the next filter in the list RpcPacketFilterActionDrop = iota // Reject the packet, and do not pass to the next filter in the list )
Actions for an RpcPacketFilter
Variables ¶
This section is empty.
Functions ¶
func NewRpcPacketFilterList ¶
func NewRpcPacketFilterList() *rpcPacketFilterList
func NewRpcPacketFilterList returns a new list
Types ¶
type RaftConfig ¶
type RpcAddress ¶
type RpcAddress interface { String() string // get the textual representation of the address GetTransportAddress() string // get the transport layer representation of the address (may e.g. do a DNS lookup) }
Type RpcAddress is an interface that represents an opaque RPC address
type RpcData ¶
type RpcData interface {
GetPktType() int // return whether the packet is a request or a reply
}
type RpcData is an interface representing the data within a request or reply packet
type RpcEndpoint ¶
type RpcEndpoint interface {
Handle(mux *RpcMux, request *RpcPacket) *RpcPacket // Handle an incoming packet, returning the reply
}
Type RpcEndpoint is an interface handling packets of a particular service
type RpcError ¶
type RpcError struct {
ErrorType int // The type of the error
}
RpcError holds an error type
type RpcInMemoryAddress ¶
type RpcInMemoryAddress struct {
// contains filtered or unexported fields
}
type RpcInMemoryAddress implements RpcAddress
func (*RpcInMemoryAddress) GetTransportAddress ¶
func (a *RpcInMemoryAddress) GetTransportAddress() string
func (*RpcInMemoryAddress) String ¶
func (a *RpcInMemoryAddress) String() string
type RpcInMemoryTransport ¶
type RpcInMemoryTransport struct {
// contains filtered or unexported fields
}
type RpcInMemoryTransport implements RpcTransport
func NewRpcInMemoryTransport ¶
func NewRpcInMemoryTransport(a RpcAddress) *RpcInMemoryTransport
func (*RpcInMemoryTransport) Close ¶
func (t *RpcInMemoryTransport) Close()
func (*RpcInMemoryTransport) GetAddress ¶
func (t *RpcInMemoryTransport) GetAddress() RpcAddress
func (*RpcInMemoryTransport) Run ¶
func (t *RpcInMemoryTransport) Run(mux *RpcMux)
func (*RpcInMemoryTransport) Send ¶
func (t *RpcInMemoryTransport) Send(pkt *RpcPacket) error
type RpcMux ¶
type RpcMux struct {
// contains filtered or unexported fields
}
Type RpcMux is a struct representing all the registered services, and the service originator
normally there would be one of these per application with a unique generation. The address should not change once created
func NewRpcMux ¶
func NewRpcMux(transport RpcTransport) *RpcMux
func NewRpcMux generates a new RPC mux
The mux initially has no services registered
func (*RpcMux) AddPacketFilter ¶
func (mux *RpcMux) AddPacketFilter(direction int, f *RpcPacketFilter, sequence int64) uint64
func AddPacketFilter adds a packet filter to a mux for traffic in a specified direction, with a specified sequence
returns the id of the packet filter
func (*RpcMux) ClearPacketFilters ¶
func ClearPacketFilters removes all packet filter from a mux for traffic in a specified direction
func (*RpcMux) GetAddress ¶
func (mux *RpcMux) GetAddress() RpcAddress
func GetAddress returns the address of a mux
func (*RpcMux) NewService ¶
func (mux *RpcMux) NewService(destination RpcAddress, service string, parameters RpcParameters) *RpcService
func NewService generates a new RpcService
func (*RpcMux) RegisterEndpoint ¶
func (mux *RpcMux) RegisterEndpoint(service string, endpoint RpcEndpoint)
func RegisterEndpoint registers an endpoint as a service with a mux
pass endpoint as 'nil' to deregister. Service names beginning with '_' are reserved
func (*RpcMux) RemovePacketFilter ¶
func (mux *RpcMux) RemovePacketFilter(direction int, f *RpcPacketFilter) bool
func AddPacketFilter removes a packet filter from a mux for traffic in a specified direction
The pointer must be the same as that given on add
func (*RpcMux) RemovePacketFilterById ¶
func AddPacketFilter removes a packet filter from a mux for traffic in a specified direction
The id must be that returned from add
func (*RpcMux) SendAsync ¶
func (mux *RpcMux) SendAsync(dest *RpcAddress, service string, request *RpcRequest, parameters *RpcParameters, replyChan chan<- RpcReply)
func SendAsync asynchronously sends a request to a given address and service, sending the reply to the specified channel
Note that send errors are transformed into synthesized received packet errors
func (*RpcMux) SendSync ¶
func (mux *RpcMux) SendSync(dest *RpcAddress, service string, request *RpcRequest, parameters *RpcParameters) *RpcReply
func SendSync synchronously sends a request to a given address and service, returning the reply
Note that send errors are transformed into synthesized received packet errors
type RpcPacket ¶
type RpcPacket struct { Source RpcAddress // The source address Dest RpcAddress // The destination address Service string // The name of the service Id uint64 // The sequential Id of the request packet to which this relates MinUnackedId uint64 // The lowest ID we have used that remains unacknowledged (tx) Generation uint64 // The generation of the requestor to which this relates Data RpcData // The RPC data }
Type RpcPacket contains an inflight RPC packet
Note all elements are exported so they are serialized
func (*RpcPacket) MakeError ¶
func (request *RpcPacket) MakeError(source RpcAddress, errNum int) *RpcPacket
func MakeError generates a corresponding error reply packet from a request packet
func (*RpcPacket) MakeReply ¶
func (request *RpcPacket) MakeReply(source RpcAddress) *RpcPacket
func MakeReply generates a corresponding reply packet from a request packet
type RpcPacketFilter ¶
type RpcPacketFilter interface {
Filter(pkt *RpcPacket) RpcPacketFilterAction // returns a filter action for a packet (or nil)
}
Type RpcPacketFilter is an interface that represents a packet filter for RPC
type RpcPacketFilterAction ¶
type RpcPacketFilterAction struct {
Action int
}
Type RpcPacketFilterAction encapsulates an RpcPacketFilterAction
func (RpcPacketFilterAction) String ¶
func (a RpcPacketFilterAction) String() string
func String() converts an RpcFilterActionNext to a string
type RpcParameters ¶
Type RpcParameters specifies the timeout parameters for an Rpc transaction
type RpcReply ¶
type RpcReply struct { ErrorType RpcError // The type of error (if any) Reply interface{} // The reply }
Type RpcReply is a struct containing an RPC reply
Note all elements are exported so they are serialized
func (RpcReply) GetPktType ¶
func getRequestKey returns the packet type associated with a request
type RpcRequest ¶
type RpcRequest struct {
Request interface{} // The request
}
Type RpcRequest is a struct containing an RPC request
Note all elements are exported so they are serialized
func (RpcRequest) GetPktType ¶
func (d RpcRequest) GetPktType() int
func getRequestKey returns the packet type associated with a reply
type RpcService ¶
type RpcService struct { Destination RpcAddress // Destination Service string // Service Mux *RpcMux // Mux Parameters RpcParameters // Parameters }
type RpcService is a convenience struct
It allows multiple requests to be sent to the same Destination, Service with the same Mux and Parameters
func (*RpcService) SendAsync ¶
func (rpcs *RpcService) SendAsync(request *RpcRequest, replyChan chan<- RpcReply)
func SendAsync asynchronously sends a request to a service
func (*RpcService) SendSync ¶
func (rpcs *RpcService) SendSync(request *RpcRequest) *RpcReply
func SendAsync synchronously sends a request to a service
type RpcTransport ¶
type RpcTransport interface { Send(pkt *RpcPacket) error // send an RPC packet asynchronously GetAddress() RpcAddress // address of the transport }
Type RpcTransport is an interface that represents an opaque RPC transport