election

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 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
	MaxVotingInterval           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{}, uint32, float32, error)

GetResult returns the winner vote, its absolute and relative weight 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() uint32

NeighborVoteCount counts the number of neighbor votes received.

func (*Election) PrefillNeighborVotes

func (election *Election) PrefillNeighborVotes(neighborIDs []interface{}, vote interface{}) error

PrefillNeighborVotes prefills vote for neighborIDs that don't have a vote yet

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