Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMemTransportFunc ¶
NewMemTransportFunc returns a function that itself returns in-memory transport instances that communicate with each other. It stops processing messages when the context is closed.
Types ¶
type LeaderCast ¶
type LeaderCast struct {
// contains filtered or unexported fields
}
LeaderCast provides a naive consensus implementation. Given a cluster with a static ordered set of nodes, the leader selected for each duty broadcasts its proposed data. All other nodes await and resolve the leader's data.
Note this is neither HA nor BFT.
func New ¶
func New(transport Transport, peerIdx, peers int) *LeaderCast
New returns a new leader cast consensus implementation for the peer at index of a total number of peers.
func (*LeaderCast) Propose ¶
func (l *LeaderCast) Propose(ctx context.Context, duty core.Duty, data core.UnsignedDataSet) error
Propose proposes an unsigned duty data object for consensus. If this peer is the leader, then it is broadcasted to all peers (including self), else the proposal is ignored.
func (*LeaderCast) Run ¶
func (l *LeaderCast) Run(ctx context.Context)
func (*LeaderCast) Subscribe ¶
func (l *LeaderCast) Subscribe(fn func(ctx context.Context, duty core.Duty, set core.UnsignedDataSet) error)
Subscribe registers a callback for unsigned duty data proposals from leaders. Note this function is not thread safe, it should be called *before* Run or Propose.
type Transport ¶
type Transport interface { // Broadcast proposal all *other* peers. Broadcast(ctx context.Context, fromIdx int, d core.Duty, data core.UnsignedDataSet) error // AwaitNext blocks and returns when the next proposal is received from *another* peer. AwaitNext(ctx context.Context) (fromIdx int, d core.Duty, data core.UnsignedDataSet, err error) }
Transport abstracts the transport layer for leader cast consensus.