Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Participant ¶
type Participant interface {
// Ballot returns this participant's vote on the subject. The bool is
// false to abstain, which happens when the subject cannot be judged.
Ballot(reportID string, subject event.ReportEvent) (vote.Event, bool, error)
// Broadcast publishes a ballot (or a Final announcement) to the other
// participants.
Broadcast(v vote.Event) error
// Decided is invoked exactly once per round, on the single
// participant that carries the decision.
Decided(subject event.ReportEvent, outcome vote.Event, voters []domain.ID)
}
Participant is the local voter a round acts for. This package owns the voting protocol — who votes, when, who carries the decision — and knows nothing of what a ballot means or what happens once a round decides: everything domain-specific sits behind this interface, implemented by the caller.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a participant's collection of live vote rounds. It owns what spans rounds — which ones are still open, which are already spent, and how many participants are out there — and hands each round the one number it cannot derive alone: when this participant's turn to vote comes up.
Locking: Registry.mx may be held while calling into a round, never the other way around. A round calls back (onDone) without holding its own lock, so the two never deadlock.
func NewRegistry ¶
func NewRegistry(self string, member Participant, schedule Schedule) *Registry
func (*Registry) AddVote ¶
AddVote routes an incoming ballot to its round, opening one if the ballot arrived before the subject did.
func (*Registry) MarkFinalized ¶
MarkFinalized records that some participant carried the round's decision and drops this copy, cancelling its takeover timer.
func (*Registry) Open ¶
func (rs *Registry) Open(rep event.ReportEvent)
Open starts (or joins) the round for a subject and schedules this participant's vote at its deterministic turn.
type Schedule ¶
Schedule carries a round's clock settings as state, so callers (and tests) can stretch them without turning the constants above into mutable globals.
func DefaultSchedule ¶
func DefaultSchedule() Schedule