Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
9f3cefec
Commit
9f3cefec
authored
4 years ago
by
Josh Brooks
Browse files
Options
Downloads
Patches
Plain Diff
Integrate unknownRounds with session in storage
parent
9051d5de
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
storage/rounds/unknownRounds.go
+8
-3
8 additions, 3 deletions
storage/rounds/unknownRounds.go
storage/rounds/unknownRounds_test.go
+12
-3
12 additions, 3 deletions
storage/rounds/unknownRounds_test.go
storage/session.go
+23
-0
23 additions, 0 deletions
storage/session.go
with
43 additions
and
6 deletions
storage/rounds/unknownRounds.go
+
8
−
3
View file @
9f3cefec
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
storage/rounds/unknownRounds_test.go
+
12
−
3
View file @
9f3cefec
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
storage/session.go
+
23
−
0
View file @
9f3cefec
...
@@ -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
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment