Skip to content
Snippets Groups Projects
Commit 1e7552fe authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

added support for base NDF

parent 021ceb27
No related branches found
No related tags found
No related merge requests found
package storage
import (
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/storage/utility"
"gitlab.com/xx_network/primitives/ndf"
)
const baseNdfKey = "baseNdf"
func (s *Session) SetBaseNDF(def *ndf.NetworkDefinition) {
err := utility.SaveNDF(s.kv, baseNdfKey, def)
if err != nil {
jww.FATAL.Printf("Failed to dave the base NDF: %s", err)
}
s.baseNdf = def
}
func (s *Session) GetBaseNDF() *ndf.NetworkDefinition {
if s.baseNdf != nil {
return s.baseNdf
}
def, err := utility.LoadNDF(s.kv, baseNdfKey)
if err != nil {
jww.FATAL.Printf("Could not load the base NDF: %s", err)
}
s.baseNdf = def
return def
}
...@@ -24,6 +24,7 @@ import ( ...@@ -24,6 +24,7 @@ import (
"gitlab.com/elixxir/ekv" "gitlab.com/elixxir/ekv"
"gitlab.com/xx_network/crypto/signature/rsa" "gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
"sync" "sync"
"testing" "testing"
) )
...@@ -36,7 +37,9 @@ type Session struct { ...@@ -36,7 +37,9 @@ type Session struct {
kv *versioned.KV kv *versioned.KV
mux sync.RWMutex mux sync.RWMutex
//memoized data
regStatus RegistrationStatus regStatus RegistrationStatus
baseNdf *ndf.NetworkDefinition
//sub-stores //sub-stores
e2e *e2e.Store e2e *e2e.Store
......
package utility
import (
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/xx_network/primitives/ndf"
"time"
)
const currentNDFVersion = 0
func LoadNDF(kv *versioned.KV, key string) (*ndf.NetworkDefinition, error) {
vo, err := kv.Get(key)
if err != nil {
return nil, err
}
ndf, _, err := ndf.DecodeNDF(string(vo.Data))
if err != nil {
return nil, err
}
return ndf, err
}
func SaveNDF(kv *versioned.KV, key string, ndf *ndf.NetworkDefinition) error {
marshaled, err := ndf.Marshal()
if err != nil {
return err
}
now := time.Now()
obj := versioned.Object{
Version: currentNDFVersion,
Timestamp: now,
Data: marshaled,
}
return kv.Set(key, &obj)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment