status-go/protocol/encryption/publisher/persistence.go

39 lines
778 B
Go
Raw Normal View History

2019-07-17 22:25:42 +00:00
package publisher
import (
"encoding/hex"
"sync"
)
type persistence struct {
2019-07-17 22:25:42 +00:00
lastAcksMutex sync.Mutex
lastPublished int64
2019-07-17 22:25:42 +00:00
lastAcks map[string]int64
}
func newPersistence() *persistence {
return &persistence{
2019-07-17 22:25:42 +00:00
lastAcks: make(map[string]int64),
}
}
func (s *persistence) getLastPublished() int64 {
return s.lastPublished
2019-07-17 22:25:42 +00:00
}
func (s *persistence) setLastPublished(lastPublished int64) {
s.lastPublished = lastPublished
2019-07-17 22:25:42 +00:00
}
func (s *persistence) lastAck(identity []byte) int64 {
2019-07-17 22:25:42 +00:00
s.lastAcksMutex.Lock()
defer s.lastAcksMutex.Unlock()
return s.lastAcks[hex.EncodeToString(identity)]
2019-07-17 22:25:42 +00:00
}
func (s *persistence) setLastAck(identity []byte, lastAck int64) {
2019-07-17 22:25:42 +00:00
s.lastAcksMutex.Lock()
defer s.lastAcksMutex.Unlock()
s.lastAcks[hex.EncodeToString(identity)] = lastAck
}