Documentation ¶
Index ¶
Constants ¶
const ( // ConflictType defines an object type conflict. ConflictType = iota // TimestampType defines an object type timestamp. TimestampType )
Variables ¶
var ( // ErrVotingNotFound is returned when a voting for a given id wasn't found. ErrVotingNotFound = errors.New("no voting found") )
Functions ¶
func OpinionCaller ¶
func OpinionCaller(handler interface{}, params ...interface{})
OpinionCaller calls the given handler with an OpinionEvent (containing its opinions, its associated ID and context).
func RoundStatsCaller ¶
func RoundStatsCaller(handler interface{}, params ...interface{})
RoundStatsCaller calls the given handler with a RoundStats.
Types ¶
type Context ¶
type Context struct { ID string Type ObjectType // The percentage of OpinionGivers who liked this item on the last query. Liked float64 // The number of voting rounds performed. Rounds int // Append-only list of opinions formed after each round. // the first opinion is the initial opinion when this vote context was created. Opinions []opinion.Opinion }
Context is the context of votes from multiple rounds about a given item.
func NewContext ¶
func NewContext(id string, objectType ObjectType, initOpn opinion.Opinion) *Context
NewContext creates a new vote context.
func (*Context) AddOpinion ¶
AddOpinion adds the given opinion to this vote context.
func (*Context) HadFirstRound ¶
HadFirstRound tells whether the vote context just had its first round.
func (*Context) IsFinalized ¶
IsFinalized tells whether this vote context is finalized by checking whether the opinion was held for finalizationThreshold number of rounds.
func (*Context) LastOpinion ¶
LastOpinion returns the last formed opinion.
type DRNGRoundBasedVoter ¶
DRNGRoundBasedVoter is a Voter which votes in rounds and uses random numbers which were generated in a decentralized fashion.
type Events ¶
type Events struct { // Fired when an Opinion has been finalized. Finalized *events.Event // Fired when an Opinion couldn't be finalized. Failed *events.Event // Fired when a DRNGRoundBasedVoter has executed a round. RoundExecuted *events.Event // Fired when internal errors occur. Error *events.Event }
Events defines events which happen on a Voter.
type ObjectType ¶ added in v0.3.2
type ObjectType uint8
ObjectType is the object type of a voting (e.g., conflict or timestamp)
type OpinionEvent ¶
type OpinionEvent struct { // ID is the of the conflict. ID string // Opinion is an opinion about a conflict. Opinion opinion.Opinion // Ctx contains all relevant infos regarding the conflict. Ctx Context }
OpinionEvent is the struct containing data to be passed around with Finalized and Failed events.
type RoundStats ¶
type RoundStats struct { // The time it took to complete a round. Duration time.Duration `json:"duration"` // The rand number used during the round. RandUsed float64 `json:"rand_used"` // The vote contexts on which opinions were formed and queried. // This list does not include the vote contexts which were finalized/aborted // during the execution of the round. // Create a copy of this map if you need to modify any of its elements. ActiveVoteContexts map[string]*Context `json:"active_vote_contexts"` // The opinions which were queried during the round per opinion giver. QueriedOpinions []opinion.QueriedOpinions `json:"queried_opinions"` }
RoundStats encapsulates data about an executed round.
type Voter ¶
type Voter interface { // Vote submits the given ID for voting with its initial Opinion. Vote(id string, objectType ObjectType, initOpn opinion.Opinion) error // IntermediateOpinion gets intermediate Opinion about the given ID. IntermediateOpinion(id string) (opinion.Opinion, error) // Events returns the Events instance of the given Voter. Events() Events }
Voter votes on hashes.