Documentation ¶
Index ¶
- type Config
- type Election
- func (election *Election) GetNeighborIDsByVote(vote interface{}) []interface{}
- func (election *Election) GetResult() (interface{}, error)
- func (election *Election) GetTxVoteChan() <-chan interface{}
- func (election *Election) HasStarted() bool
- func (election *Election) IsStopped() bool
- func (election *Election) NeighborVoteCount() int
- func (election *Election) ReceiveVote(neighborID, vote interface{}) error
- func (election *Election) SetInitialVote(vote interface{}) error
- func (election *Election) Start() bool
- func (election *Election) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Duration time.Duration MinVotingInterval time.Duration ChangeVoteMinRelativeWeight float32 ChangeVoteMinAbsoluteWeight uint32 ConsensusMinRelativeWeight float32 ConsensusMinAbsoluteWeight uint32 GetWeight func(interface{}) uint32 }
Config is the election config.
type Election ¶
Election is the structure of an election.
func NewElection ¶
NewElection creates an election using the config provided.
func (*Election) GetNeighborIDsByVote ¶
func (election *Election) GetNeighborIDsByVote(vote interface{}) []interface{}
GetNeighborIDsByVote get neighbor id list that vote for a certain vote
func (*Election) GetResult ¶
GetResult returns the winner vote if the election is stopped, otherwise returns error.
func (*Election) GetTxVoteChan ¶
func (election *Election) GetTxVoteChan() <-chan interface{}
GetTxVoteChan returns the send vote channel, which should be used to send votes to neighbors.
func (*Election) HasStarted ¶
HasStarted returns if an election has started.
func (*Election) NeighborVoteCount ¶
NeighborVoteCount counts the number of neighbor votes received.
func (*Election) ReceiveVote ¶
ReceiveVote receives and saves a vote from a neighbor.
func (*Election) SetInitialVote ¶
SetInitialVote sets the initial vote if election has not started, otherwise returns error.