Documentation ¶
Index ¶
- Constants
- func Init(customProtocol MessageProtocol) (string, error)
- func Join(customProtocol MessageProtocol, addr, token string) error
- type LocalNode
- type LocalNodeSetter
- type MessageProtocol
- type MessagePtrFactory
- type MessageReceiveEventHandler
- type MessageTypeTranslator
- type MessageTypeTranslatorGetter
- type RemoteNode
- type SharedState
- type SharedStateGetter
Constants ¶
const ( // RPCHeaderOffset is the min header byte free to // be used for a custom protocol RPCHeaderOffset = rpcJoinCluster + 1 )
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(customProtocol MessageProtocol) (string, error)
Init creates a new localNode which seeds a new cluster of raft nodes; each consecutive raft node needs the token to connect to this node
func Join ¶
func Join(customProtocol MessageProtocol, addr, token string) error
Join creates a new localNode and tries to connect it to an existing cluster of raft nodes
Types ¶
type LocalNode ¶
type LocalNode interface { RemoteNode AppendLogMessage([]byte, time.Duration) error RemoteProcedureCall(RemoteNode, uint8, interface{}, interface{}) error GetRemoteNodes() ([]RemoteNode, error) GetAuthToken() string }
LocalNode is a raft node which is the local node.
type LocalNodeSetter ¶
type LocalNodeSetter interface {
SetLocalNode(LocalNode)
}
LocalNodeSetter represents a protocol interface which receives a reference to a LocalNode once a cluster has been joined / created.
type MessageProtocol ¶
type MessageProtocol interface { SharedStateGetter LocalNodeSetter MessageTypeTranslatorGetter MessageReceiveEventHandler }
MessageProtocol is a message oriented protocol sharing a common state over all nodes of the "overlay" network
type MessagePtrFactory ¶
type MessagePtrFactory func() interface{}
MessagePtrFactory emits a new request struct ptr
type MessageReceiveEventHandler ¶
type MessageReceiveEventHandler interface { // OnMessageReceive is called when a message was recieved and has been // properly decoded; return either an error or an struct ptr; both will // be sent back to the requesting client OnMessageReceive(uint8, interface{}) (interface{}, error) }
MessageReceiveEventHandler represents a protocol interface which is notified about incoming messages, properly decoded into the interface{} with the rpc type
type MessageTypeTranslator ¶
type MessageTypeTranslator map[uint8]MessagePtrFactory
MessageTypeTranslator is a map associating rpc types (uint8) to MessagePtrFactorys
type MessageTypeTranslatorGetter ¶
type MessageTypeTranslatorGetter interface { // GetTypeTranslator returns the protocol's // type translator GetTypeTranslator() MessageTypeTranslator }
MessageTypeTranslatorGetter implements GetTypeTranslator() func
type RemoteNode ¶
RemoteNode is a raft node which is not the local node. This is supposed to only be a reference to this node.
type SharedState ¶
type SharedState interface { // and applies the represented change to the // local state AppendLogMessage([]byte) // the writer Encode(io.Writer) error // into the local state Decode(io.Reader) error }
SharedState is a interface representing a log / transaction based state which can be shared over multiple nodes. The raft protocol ensures that the state is equalized on all nodes
type SharedStateGetter ¶
type SharedStateGetter interface { SharedState }GetSharedState()
SharedStateGetter implements the GetSharedState() func