forked from FactomProject/factomd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routingelection.go
41 lines (33 loc) · 893 Bytes
/
routingelection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package election
import (
"github.com/FactomProject/factomd/electionsCore/imessage"
"github.com/FactomProject/factomd/electionsCore/messages"
)
// RoutingElection is just an election that returns msgs for broadcasting
type RoutingElection struct {
*Election
}
func NewRoutingElection(e *Election) *RoutingElection {
r := new(RoutingElection)
r.Election = e
return r
}
func (r *RoutingElection) Execute(msg imessage.IMessage) (imessage.IMessage, bool) {
resp, ch := r.Election.Execute(msg, 0)
if resp == nil && ch {
return msg, ch
}
if ll, ok := msg.(*messages.LeaderLevelMessage); ok {
if r.Election.CurrentVote.Level > 0 {
if r.Election.CurrentVote.VolunteerPriority != ll.VolunteerPriority {
return ll, ch
}
} else {
return ll, ch
}
}
if resp == nil && r.Election.CurrentVote.Level > 0 {
return &r.Election.CurrentVote, false
}
return resp, ch
}