Skip to content
Snippets Groups Projects
Commit 9f3cefec authored by Josh Brooks's avatar Josh Brooks
Browse files

Integrate unknownRounds with session in storage

parent 9051d5de
No related branches found
No related tags found
No related merge requests found
...@@ -51,23 +51,28 @@ func DefaultUnknownRoundsParams() UnknownRoundsParams { ...@@ -51,23 +51,28 @@ func DefaultUnknownRoundsParams() UnknownRoundsParams {
// Build and return new UnknownRounds object // Build and return new UnknownRounds object
func NewUnknownRoundsStore(kv *versioned.KV, func NewUnknownRoundsStore(kv *versioned.KV,
params UnknownRoundsParams) *UnknownRoundsStore { params UnknownRoundsParams) (*UnknownRoundsStore, error) {
// Build the UnmixedMessagesMap // Build the UnmixedMessagesMap
// Modify the prefix of the KV // Modify the prefix of the KV
kv = kv.Prefix(unknownRoundPrefix) kv = kv.Prefix(unknownRoundPrefix)
return &UnknownRoundsStore{ urs:= &UnknownRoundsStore{
rounds: make(map[id.Round]*uint64), rounds: make(map[id.Round]*uint64),
params: params, params: params,
kv: kv, kv: kv,
} }
return urs, urs.save()
} }
// LoadUnknownRoundsStore loads the data for a UnknownRoundStore from disk into an object // LoadUnknownRoundsStore loads the data for a UnknownRoundStore from disk into an object
func LoadUnknownRoundsStore(kv *versioned.KV, params UnknownRoundsParams) (*UnknownRoundsStore, error) { func LoadUnknownRoundsStore(kv *versioned.KV, params UnknownRoundsParams) (*UnknownRoundsStore, error) {
kv = kv.Prefix(unknownRoundPrefix) kv = kv.Prefix(unknownRoundPrefix)
urs := NewUnknownRoundsStore(kv, params) urs, err := NewUnknownRoundsStore(kv, params)
if err != nil {
return nil, err
}
// Get the versioned data from the kv // Get the versioned data from the kv
obj, err := kv.Get(unknownRoundsStorageKey, unknownRoundsStorageVersion) obj, err := kv.Get(unknownRoundsStorageKey, unknownRoundsStorageVersion)
......
...@@ -27,7 +27,10 @@ func TestNewUnknownRoundsStore(t *testing.T) { ...@@ -27,7 +27,10 @@ func TestNewUnknownRoundsStore(t *testing.T) {
params: DefaultUnknownRoundsParams(), params: DefaultUnknownRoundsParams(),
} }
store := NewUnknownRoundsStore(kv, DefaultUnknownRoundsParams()) store, err := NewUnknownRoundsStore(kv, DefaultUnknownRoundsParams())
if err != nil {
t.Fatalf("Failed to create known round store: %v", err)
}
// Compare manually created object with NewUnknownRoundsStore // Compare manually created object with NewUnknownRoundsStore
if !reflect.DeepEqual(expectedStore, store) { if !reflect.DeepEqual(expectedStore, store) {
...@@ -60,7 +63,10 @@ func TestNewUnknownRoundsStore(t *testing.T) { ...@@ -60,7 +63,10 @@ func TestNewUnknownRoundsStore(t *testing.T) {
// Full test // Full test
func TestUnknownRoundsStore_Iterate(t *testing.T) { func TestUnknownRoundsStore_Iterate(t *testing.T) {
kv := versioned.NewKV(make(ekv.Memstore)) kv := versioned.NewKV(make(ekv.Memstore))
store := NewUnknownRoundsStore(kv, DefaultUnknownRoundsParams()) store, err := NewUnknownRoundsStore(kv, DefaultUnknownRoundsParams())
if err != nil {
t.Fatalf("Failed to create known round store: %v", err)
}
// Return true only for rounds that are even // Return true only for rounds that are even
mockChecker := func(rid id.Round) bool { mockChecker := func(rid id.Round) bool {
...@@ -138,7 +144,10 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) { ...@@ -138,7 +144,10 @@ func TestUnknownRoundsStore_Iterate(t *testing.T) {
// Unit test // Unit test
func TestLoadUnknownRoundsStore(t *testing.T) { func TestLoadUnknownRoundsStore(t *testing.T) {
kv := versioned.NewKV(make(ekv.Memstore)) kv := versioned.NewKV(make(ekv.Memstore))
store := NewUnknownRoundsStore(kv, DefaultUnknownRoundsParams()) store, err := NewUnknownRoundsStore(kv, DefaultUnknownRoundsParams())
if err != nil {
t.Fatalf("Failed to create known round store: %v", err)
}
// Construct 3 lists of round IDs // Construct 3 lists of round IDs
roundListLen := 25 roundListLen := 25
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
package storage package storage
import ( import (
"gitlab.com/elixxir/client/storage/rounds"
"sync" "sync"
"testing" "testing"
...@@ -62,6 +63,7 @@ type Session struct { ...@@ -62,6 +63,7 @@ type Session struct {
garbledMessages *utility.MeteredCmixMessageBuffer garbledMessages *utility.MeteredCmixMessageBuffer
reception *reception.Store reception *reception.Store
clientVersion *clientVersion.Store clientVersion *clientVersion.Store
unknownRounds *rounds.UnknownRoundsStore
} }
// Initialize a new Session object // Initialize a new Session object
...@@ -141,6 +143,11 @@ func New(baseDir, password string, u userInterface.User, currentVersion version. ...@@ -141,6 +143,11 @@ func New(baseDir, password string, u userInterface.User, currentVersion version.
return nil, errors.WithMessage(err, "Failed to create client version store.") return nil, errors.WithMessage(err, "Failed to create client version store.")
} }
s.unknownRounds, err = rounds.NewUnknownRoundsStore(s.kv, rounds.DefaultUnknownRoundsParams())
if err != nil {
return nil, errors.WithMessage(err, "Failed to create unknown round store.")
}
return s, nil return s, nil
} }
...@@ -212,6 +219,11 @@ func Load(baseDir, password string, currentVersion version.Version, ...@@ -212,6 +219,11 @@ func Load(baseDir, password string, currentVersion version.Version,
s.reception = reception.LoadStore(s.kv) s.reception = reception.LoadStore(s.kv)
s.unknownRounds, err = rounds.LoadUnknownRoundsStore(s.kv, rounds.DefaultUnknownRoundsParams())
if err != nil {
return nil, errors.WithMessage(err, "Failed to load unknown rounds")
}
return s, nil return s, nil
} }
...@@ -282,6 +294,12 @@ func (s *Session) Partition() *partition.Store { ...@@ -282,6 +294,12 @@ func (s *Session) Partition() *partition.Store {
return s.partition return s.partition
} }
func (s *Session) UnknownRounds() *rounds.UnknownRoundsStore {
s.mux.RUnlock()
defer s.mux.RUnlock()
return s.unknownRounds
}
// Get an object from the session // Get an object from the session
func (s *Session) Get(key string) (*versioned.Object, error) { func (s *Session) Get(key string) (*versioned.Object, error) {
return s.kv.Get(key, currentSessionVersion) return s.kv.Get(key, currentSessionVersion)
...@@ -363,5 +381,10 @@ func InitTestingSession(i interface{}) *Session { ...@@ -363,5 +381,10 @@ func InitTestingSession(i interface{}) *Session {
s.partition = partition.New(s.kv) s.partition = partition.New(s.kv)
s.reception = reception.NewStore(s.kv) s.reception = reception.NewStore(s.kv)
s.unknownRounds, err = rounds.NewUnknownRoundsStore(s.kv, rounds.DefaultUnknownRoundsParams())
if err != nil {
jww.FATAL.Panicf("Failed to create unknown rounds store: %+v", err)
}
return s return s
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment