2021-04-30 19:55:12 +00:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
|
|
|
types2 "github.com/Secured-Finance/dione/consensus/types"
|
|
|
|
mapset "github.com/Secured-Finance/golang-set"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MessageLog struct {
|
|
|
|
messages mapset.Set
|
|
|
|
maxLogSize int
|
2021-06-02 21:19:52 +00:00
|
|
|
validationFuncMap map[types2.MessageType]func(message types2.ConsensusMessage)
|
2021-04-30 19:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMessageLog() *MessageLog {
|
|
|
|
msgLog := &MessageLog{
|
|
|
|
messages: mapset.NewSet(),
|
|
|
|
maxLogSize: 0, // TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgLog
|
|
|
|
}
|
|
|
|
|
2021-06-02 21:19:52 +00:00
|
|
|
func (ml *MessageLog) AddMessage(msg types2.ConsensusMessage) {
|
2021-04-30 19:55:12 +00:00
|
|
|
ml.messages.Add(msg)
|
|
|
|
}
|
|
|
|
|
2021-06-02 21:19:52 +00:00
|
|
|
func (ml *MessageLog) Exists(msg types2.ConsensusMessage) bool {
|
2021-04-30 19:55:12 +00:00
|
|
|
return ml.messages.Contains(msg)
|
|
|
|
}
|
|
|
|
|
2021-06-02 21:19:52 +00:00
|
|
|
func (ml *MessageLog) Get(typ types2.MessageType, consensusID string) []*types2.ConsensusMessage {
|
|
|
|
var result []*types2.ConsensusMessage
|
2021-04-30 19:55:12 +00:00
|
|
|
|
|
|
|
for v := range ml.messages.Iter() {
|
2021-06-02 21:19:52 +00:00
|
|
|
msg := v.(types2.ConsensusMessage)
|
|
|
|
if msg.Type == typ && msg.Task.ConsensusID == consensusID {
|
|
|
|
result = append(result, &msg)
|
2021-04-30 19:55:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|