Mercurial > lbo > hg > clusterconsensus
changeset 0:073442e4dfe6
Initial commit
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 07 Oct 2016 20:06:32 +0200 |
parents | |
children | 50b3f6da682f |
files | .hgignore types.go |
diffstat | 2 files changed, 55 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Fri Oct 07 20:06:32 2016 +0200 @@ -0,0 +1,1 @@ +.*swp$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/types.go Fri Oct 07 20:06:32 2016 +0200 @@ -0,0 +1,54 @@ +package clusterconsensus + +// A change that can be applied to a State and sent over the wire +// Client-provided +type Change interface { + Serialize() []byte + Deserialize([]byte) Change +} + +// A state machine containing the overall state. +// Client-provided +type State interface { + Snapshot() []byte + Apply(Change) + Install([]byte) +} + +// A channel that is connected to a peer and can roundtrip messages. +type Transport interface { + Send([]byte) error + Recv() ([]byte, error) +} + +// A remote member of the consensus +type Member struct { + addr string +} + +// One participant of the consensus +// implements participating; implementation-provided +type Participant struct { + members []Member + master Member + self Member + + contacts map[Member]Transport + + instance uint64 // nth round + serial uint64 // nth submission in this round + + state State + staging map[uint64]Change // staging area for changes + + // Used to deserialize changes + protoTypeDeserialize Change +} + +// Implemented by Participant +// Used by Server for asynchronous, external callbacks +type Participating interface { + Prepare(instance uint64, m Member) bool + Accept(instance, serial uint64, changes []Change) + StartParticipation(instance, serial uint64, master Member, members []Member, snapshot []byte) +}