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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
a0f024eb
Commit
a0f024eb
authored
Aug 5, 2020
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
add nodekeys impl
parent
d9125b57
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
storage/session.go
+64
-1
64 additions, 1 deletion
storage/session.go
with
64 additions
and
1 deletion
storage/session.go
+
64
−
1
View file @
a0f024eb
...
@@ -7,7 +7,11 @@
...
@@ -7,7 +7,11 @@
package
storage
package
storage
import
(
import
(
"encoding/json"
"gitlab.com/elixxir/client/user"
"gitlab.com/elixxir/ekv"
"gitlab.com/elixxir/ekv"
"gitlab.com/elixxir/primitives/id"
"gitlab.com/xx_network/comms/connect"
"time"
"time"
)
)
...
@@ -38,7 +42,10 @@ func (s *Session) Set(key string, object *VersionedObject) error {
...
@@ -38,7 +42,10 @@ func (s *Session) Set(key string, object *VersionedObject) error {
// Obtain the LastMessageID from the Session
// Obtain the LastMessageID from the Session
func
(
s
*
Session
)
GetLastMessageId
()
(
string
,
error
)
{
func
(
s
*
Session
)
GetLastMessageId
()
(
string
,
error
)
{
v
,
err
:=
s
.
kv
.
Get
(
"LastMessageID"
)
v
,
err
:=
s
.
kv
.
Get
(
"LastMessageID"
)
return
string
(
v
.
Data
),
err
if
err
!=
nil
{
return
""
,
err
}
return
string
(
v
.
Data
),
nil
}
}
// Set the LastMessageID in the Session
// Set the LastMessageID in the Session
...
@@ -53,3 +60,59 @@ func (s *Session) SetLastMessageId(id string) error {
...
@@ -53,3 +60,59 @@ func (s *Session) SetLastMessageId(id string) error {
}
}
return
s
.
kv
.
Set
(
"LastMessageID"
,
vo
)
return
s
.
kv
.
Set
(
"LastMessageID"
,
vo
)
}
}
// Helper for obtaining NodeKeys map
func
(
s
*
Session
)
getNodeKeys
()
(
map
[
id
.
ID
]
user
.
NodeKeys
,
error
)
{
v
,
err
:=
s
.
kv
.
Get
(
"NodeKeys"
)
if
err
!=
nil
{
return
nil
,
err
}
var
nodeKeys
map
[
id
.
ID
]
user
.
NodeKeys
err
=
json
.
Unmarshal
(
v
.
Data
,
&
nodeKeys
)
return
nodeKeys
,
err
}
// Obtain NodeKeys from the Session
func
(
s
*
Session
)
GetNodeKeys
(
topology
*
connect
.
Circuit
)
([]
user
.
NodeKeys
,
error
)
{
nodeKeys
,
err
:=
s
.
getNodeKeys
()
if
err
!=
nil
{
return
nil
,
err
}
keys
:=
make
([]
user
.
NodeKeys
,
topology
.
Len
())
for
i
:=
0
;
i
<
topology
.
Len
();
i
++
{
keys
[
i
]
=
nodeKeys
[
*
topology
.
GetNodeAtIndex
(
i
)]
}
return
keys
,
nil
}
// Set NodeKeys in the Session
func
(
s
*
Session
)
PushNodeKey
(
id
*
id
.
ID
,
key
user
.
NodeKeys
)
error
{
// Obtain NodeKeys map
nodeKeys
,
err
:=
s
.
getNodeKeys
()
if
err
!=
nil
{
return
err
}
// Set new value inside of map
nodeKeys
[
*
id
]
=
key
// Marshal the map
pushValue
,
err
:=
json
.
Marshal
(
nodeKeys
)
if
err
!=
nil
{
return
err
}
// Insert the map back into the Session
ts
,
err
:=
time
.
Now
()
.
MarshalText
()
if
err
!=
nil
{
return
err
}
vo
:=
&
VersionedObject
{
Timestamp
:
ts
,
Data
:
pushValue
,
}
return
s
.
kv
.
Set
(
"NodeKeys"
,
vo
)
}
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