Skip to content
Snippets Groups Projects
Commit 726d2194 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Merge branch 'hotfix/regstatusSync' into 'project/HavenBeta'

Add Sync for Registration Status

See merge request !637
parents d12ab437 e0eecc78
No related branches found
No related tags found
2 merge requests!637Add Sync for Registration Status,!617Project/haven beta
...@@ -12,7 +12,11 @@ import ( ...@@ -12,7 +12,11 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand" "math/rand"
"sync"
"testing" "testing"
"github.com/stretchr/testify/require"
"gitlab.com/xx_network/primitives/netTime"
) )
const ( const (
...@@ -196,32 +200,52 @@ func TestGetChannelInfo(t *testing.T) { ...@@ -196,32 +200,52 @@ func TestGetChannelInfo(t *testing.T) {
// return txLog // return txLog
// } // }
// type mockRemote struct { type mockRemote struct {
// lck sync.Mutex lck sync.Mutex
// data map[string][]byte data map[string][]byte
// } t *testing.T
}
// func (m *mockRemote) Read(path string) ([]byte, error) { func (m *mockRemote) Read(path string) ([]byte, error) {
// m.lck.Lock() m.lck.Lock()
// defer m.lck.Unlock() defer m.lck.Unlock()
// return m.data[path], nil return m.data[path], nil
// } }
// func (m *mockRemote) Write(path string, data []byte) error { func (m *mockRemote) Write(path string, data []byte) error {
// m.lck.Lock() m.lck.Lock()
// defer m.lck.Unlock() defer m.lck.Unlock()
// m.data[path] = append(m.data[path], data...) m.data[path] = append(m.data[path], data...)
// return nil return nil
// } }
// func (m *mockRemote) ReadDir(path string) ([]string, error) { func (m *mockRemote) ReadDir(path string) ([]byte, error) {
// panic("unimplemented") dirs := []string{
// } "hello",
"these",
"are",
"directory",
"names",
}
// func (m mockRemote) GetLastModified(path string) (time.Time, error) { data, err := json.Marshal(dirs)
// return netTime.Now(), nil m.t.Logf("Data: %s", data)
// } return data, err
}
// func (m mockRemote) GetLastWrite() (time.Time, error) { func (m *mockRemote) GetLastModified(path string) ([]byte, error) {
// return netTime.Now(), nil return netTime.Now().MarshalBinary()
// } }
func (m *mockRemote) GetLastWrite() ([]byte, error) {
return netTime.Now().MarshalBinary()
}
func TestReadDir(t *testing.T) {
mRemote := newRemoteStoreFileSystemWrapper(
&mockRemote{t: t, data: make(map[string][]byte)})
dirs, err := mRemote.ReadDir("test")
require.NoError(t, err)
t.Logf("%+v", dirs)
}
...@@ -10,6 +10,7 @@ package storage ...@@ -10,6 +10,7 @@ package storage
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/elixxir/client/v4/storage/versioned"
"gitlab.com/xx_network/primitives/netTime" "gitlab.com/xx_network/primitives/netTime"
...@@ -67,7 +68,7 @@ func (s *session) newRegStatus() error { ...@@ -67,7 +68,7 @@ func (s *session) newRegStatus() error {
Data: s.regStatus.marshalBinary(), Data: s.regStatus.marshalBinary(),
} }
err := s.Set(registrationStatusKey, &obj) err := s.syncKV.Set(registrationStatusKey, &obj)
if err != nil { if err != nil {
return errors.WithMessagef(err, "Failed to store new "+ return errors.WithMessagef(err, "Failed to store new "+
"registration status") "registration status")
...@@ -78,7 +79,7 @@ func (s *session) newRegStatus() error { ...@@ -78,7 +79,7 @@ func (s *session) newRegStatus() error {
// loads registration status from disk. // loads registration status from disk.
func (s *session) loadRegStatus() error { func (s *session) loadRegStatus() error {
obj, err := s.Get(registrationStatusKey) obj, err := s.syncKV.Get(registrationStatusKey, currentSessionVersion)
if err != nil { if err != nil {
return errors.WithMessage(err, "Failed to load registration status") return errors.WithMessage(err, "Failed to load registration status")
} }
...@@ -105,8 +106,7 @@ func (s *session) ForwardRegistrationStatus(regStatus RegistrationStatus) error ...@@ -105,8 +106,7 @@ func (s *session) ForwardRegistrationStatus(regStatus RegistrationStatus) error
Timestamp: now, Timestamp: now,
Data: regStatus.marshalBinary(), Data: regStatus.marshalBinary(),
} }
err := s.syncKV.Set(registrationStatusKey, &obj)
err := s.Set(registrationStatusKey, &obj)
if err != nil { if err != nil {
return errors.WithMessagef(err, "Failed to store registration status") return errors.WithMessagef(err, "Failed to store registration status")
} }
......
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
"gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/crypto/diffieHellman"
"gitlab.com/elixxir/client/v4/collective"
"gitlab.com/elixxir/client/v4/storage/utility" "gitlab.com/elixxir/client/v4/storage/utility"
"gitlab.com/xx_network/crypto/large" "gitlab.com/xx_network/crypto/large"
...@@ -75,6 +76,7 @@ type Session interface { ...@@ -75,6 +76,7 @@ type Session interface {
type session struct { type session struct {
kv versioned.KV kv versioned.KV
syncKV versioned.KV
// memoized data // memoized data
mux sync.RWMutex mux sync.RWMutex
...@@ -95,11 +97,17 @@ func New(storage versioned.KV, u user.Info, ...@@ -95,11 +97,17 @@ func New(storage versioned.KV, u user.Info,
currentVersion version.Version, currentVersion version.Version,
cmixGrp, e2eGrp *cyclic.Group) (Session, error) { cmixGrp, e2eGrp *cyclic.Group) (Session, error) {
remote, err := storage.Prefix(collective.StandardRemoteSyncPrefix)
if err != nil {
return nil, errors.Wrapf(err, "create new session")
}
s := &session{ s := &session{
kv: storage, kv: storage,
syncKV: remote,
} }
err := s.newRegStatus() err = s.newRegStatus()
if err != nil { if err != nil {
return nil, errors.WithMessage(err, return nil, errors.WithMessage(err,
"Create new session") "Create new session")
...@@ -114,12 +122,15 @@ func New(storage versioned.KV, u user.Info, ...@@ -114,12 +122,15 @@ func New(storage versioned.KV, u user.Info,
} }
s.clientVersion, err = clientVersion.NewStore(currentVersion, s.kv) s.clientVersion, err = clientVersion.NewStore(currentVersion, s.kv)
if err != nil {
return nil, err
}
if err = utility.StoreGroup(s.kv, cmixGrp, cmixGroupKey); err != nil { if err = utility.StoreGroup(s.syncKV, cmixGrp, cmixGroupKey); err != nil {
return nil, err return nil, err
} }
if err = utility.StoreGroup(s.kv, e2eGrp, e2eGroupKey); err != nil { if err = utility.StoreGroup(s.syncKV, e2eGrp, e2eGroupKey); err != nil {
return nil, err return nil, err
} }
...@@ -132,11 +143,17 @@ func New(storage versioned.KV, u user.Info, ...@@ -132,11 +143,17 @@ func New(storage versioned.KV, u user.Info,
func Load(storage versioned.KV, func Load(storage versioned.KV,
currentVersion version.Version) (Session, error) { currentVersion version.Version) (Session, error) {
remote, err := storage.Prefix(collective.StandardRemoteSyncPrefix)
if err != nil {
return nil, errors.Wrapf(err, "create new session")
}
s := &session{ s := &session{
kv: storage, kv: storage,
syncKV: remote,
} }
err := s.loadRegStatus() err = s.loadRegStatus()
if err != nil { if err != nil {
if !ekv.Exists(err) { if !ekv.Exists(err) {
return nil, errors.Errorf( return nil, errors.Errorf(
...@@ -163,12 +180,12 @@ func Load(storage versioned.KV, ...@@ -163,12 +180,12 @@ func Load(storage versioned.KV,
return nil, errors.WithMessage(err, "Failed to load Session") return nil, errors.WithMessage(err, "Failed to load Session")
} }
s.cmixGroup, err = utility.LoadGroup(s.kv, cmixGroupKey) s.cmixGroup, err = utility.LoadGroup(s.syncKV, cmixGroupKey)
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "Failed to load Session") return nil, errors.WithMessage(err, "Failed to load Session")
} }
s.e2eGroup, err = utility.LoadGroup(s.kv, e2eGroupKey) s.e2eGroup, err = utility.LoadGroup(s.syncKV, e2eGroupKey)
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "Failed to load Session") return nil, errors.WithMessage(err, "Failed to load Session")
} }
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
package user package user
import ( import (
"gitlab.com/elixxir/client/v4/collective"
"sync" "sync"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/elixxir/client/v4/collective"
"gitlab.com/elixxir/client/v4/storage/versioned" "gitlab.com/elixxir/client/v4/storage/versioned"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
"gitlab.com/elixxir/crypto/rsa" "gitlab.com/elixxir/crypto/rsa"
...@@ -44,8 +44,10 @@ func NewUser(kv versioned.KV, transmissionID, receptionID *id.ID, transmissionSa ...@@ -44,8 +44,10 @@ func NewUser(kv versioned.KV, transmissionID, receptionID *id.ID, transmissionSa
return nil, err return nil, err
} }
ci := newCryptographicIdentity(transmissionID, receptionID, transmissionSalt, ci := newCryptographicIdentity(transmissionID, receptionID,
receptionSalt, transmissionRsa, receptionRsa, isPrecanned, e2eDhPrivateKey, e2eDhPublicKey, remote) transmissionSalt, receptionSalt, transmissionRsa,
receptionRsa, isPrecanned,
e2eDhPrivateKey, e2eDhPublicKey, remote)
return &User{CryptographicIdentity: ci, kv: remote}, nil return &User{CryptographicIdentity: ci, kv: remote}, nil
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment