Documentation
¶
Index ¶
- Variables
- func ConvertOpinionToInt32(x Opinion) int32
- func ConvertOpinionsToInts32(opinions []Opinion) []int32
- func OpinionCaller(handler interface{}, params ...interface{})
- func RoundStatsCaller(handler interface{}, params ...interface{})
- type Context
- type DRNGRoundBasedVoter
- type Events
- type Opinion
- type OpinionEvent
- type OpinionGiver
- type OpinionGiverFunc
- type Opinions
- type QueriedOpinions
- type RoundStats
- type Voter
Constants ¶
This section is empty.
Variables ¶
var ( // ErrVotingNotFound is returned when a voting for a given id wasn't found. ErrVotingNotFound = errors.New("no voting found") )
Functions ¶
func ConvertOpinionToInt32 ¶
ConvertOpinionToInt32 converts the given Opinion to an int32.
func ConvertOpinionsToInts32 ¶
ConvertOpinionsToInts32 converts the given slice of Opinion to a slice of int32.
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
// 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
}
Context is the context of votes from multiple rounds about a given item.
func NewContext ¶
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 Opinion ¶
type Opinion byte
Opinion is an opinion about a given thing.
func ConvertInt32Opinion ¶
ConvertInt32Opinion converts the given int32 to an Opinion.
func ConvertInts32ToOpinions ¶
ConvertInts32ToOpinions converts the given slice of int32 to a slice of Opinion.
type OpinionEvent ¶
type OpinionEvent struct {
// ID is the of the conflict.
ID string
// Opinion is an opinion about a conflict.
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 OpinionGiver ¶
type OpinionGiver interface {
// Query queries the OpinionGiver for its opinions on the given IDs.
// The passed in context can be used to signal cancellation of the query.
Query(ctx context.Context, ids []string) (Opinions, error)
// ID returns the ID of the opinion giver.
ID() string
}
OpinionGiver gives opinions about the given IDs.
type OpinionGiverFunc ¶
type OpinionGiverFunc func() ([]OpinionGiver, error)
OpinionGiverFunc is a function which gives a slice of OpinionGivers or an error.
type QueriedOpinions ¶
type QueriedOpinions struct {
// The ID of the opinion giver.
OpinionGiverID string `json:"opinion_giver_id"`
// The map of IDs to opinions.
Opinions map[string]Opinion `json:"opinions"`
// The amount of times the opinion giver's opinion has counted.
// Usually this number is 1 but due to randomization of the queried opinion givers,
// the same opinion giver's opinions might be taken into account multiple times.
TimesCounted int `json:"times_counted"`
}
QueriedOpinions represents queried opinions from a given opinion giver.
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 []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, initOpn Opinion) error
// IntermediateOpinion gets intermediate Opinion about the given ID.
IntermediateOpinion(id string) (Opinion, error)
// Events returns the Events instance of the given Voter.
Events() Events
}
Voter votes on hashes.