election

package
v0.8.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

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

type Election struct {
	*Config

	sync.RWMutex
	// contains filtered or unexported fields
}

Election is the structure of an election.

func NewElection

func NewElection(config *Config) (*Election, error)

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

func (election *Election) GetResult() (interface{}, error)

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

func (election *Election) HasStarted() bool

HasStarted returns if an election has started.

func (*Election) IsStopped

func (election *Election) IsStopped() bool

IsStopped return if an election is stopped.

func (*Election) NeighborVoteCount

func (election *Election) NeighborVoteCount() int

NeighborVoteCount counts the number of neighbor votes received.

func (*Election) ReceiveVote

func (election *Election) ReceiveVote(neighborID, vote interface{}) error

ReceiveVote receives and saves a vote from a neighbor.

func (*Election) SetInitialVote

func (election *Election) SetInitialVote(vote interface{}) error

SetInitialVote sets the initial vote if election has not started, otherwise returns error.

func (*Election) Start

func (election *Election) Start() bool

Start starts an election and will stop the election after duration. Returns if start success. Multiple concurrent call will only return success once.

func (*Election) Stop

func (election *Election) Stop()

Stop stops an election. Typically this should not be called directly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL