diff --git a/api/client.go b/api/client.go index 7901d1fef5d4d30f8a265d50e145dbad36fe0c65..c9f2bf336194b5cf4dd7169bbc6ca43b5a05bfa0 100644 --- a/api/client.go +++ b/api/client.go @@ -33,6 +33,7 @@ import ( "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/xx_network/comms/connect" goio "io" + "path/filepath" "strings" "testing" "time" @@ -164,7 +165,8 @@ func (cl *Client) Login(password string) (*id.ID, error) { // TODO: FIX ME // While the old session is still valid, we are using the LocA storage to initialize the session locA, _ := cl.storage.GetLocation() - io.SessionV2, err = storage.Init(locA, password) + dirname := filepath.Dir(locA) + io.SessionV2, err = storage.Init(dirname, password) if err != nil { return nil, errors.Wrap(err, "Login: could not initialize v2 storage") } diff --git a/api/mockserver_test.go b/api/mockserver_test.go index dd965339190ffd88e468fad5c0a04c3fdef36c0d..8be4e116dbbbb69eb87a2472e208d957c2aff9e7 100644 --- a/api/mockserver_test.go +++ b/api/mockserver_test.go @@ -10,6 +10,8 @@ package api import ( "fmt" jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/io" + "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/comms/gateway" pb "gitlab.com/elixxir/comms/mixmessages" @@ -58,6 +60,7 @@ func TestMain(m *testing.M) { // Set logging params jww.SetLogThreshold(jww.LevelTrace) jww.SetStdoutThreshold(jww.LevelTrace) + io.SessionV2, _ = storage.Init(".ekvapi", "test") os.Exit(testMainWrapper(m)) } diff --git a/bindings/client_test.go b/bindings/client_test.go index ff10688c3c935363c975c2aa1d358917894b8bd0..cddfb41381e04481f5e9fbca3deae8a47b761dee 100644 --- a/bindings/client_test.go +++ b/bindings/client_test.go @@ -15,7 +15,9 @@ import ( "fmt" "gitlab.com/elixxir/client/cmixproto" "gitlab.com/elixxir/client/globals" + "gitlab.com/elixxir/client/io" "gitlab.com/elixxir/client/parse" + "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/user" "gitlab.com/elixxir/comms/gateway" pb "gitlab.com/elixxir/comms/mixmessages" @@ -81,6 +83,7 @@ func (i *MockRegistration) CheckRegistration(msg *pb.RegisteredNodeCheck) (*pb.R // Setups general testing params and calls test wrapper func TestMain(m *testing.M) { + io.SessionV2, _ = storage.Init(".ekvbindings", "test") os.Exit(testMainWrapper(m)) } diff --git a/go.mod b/go.mod index 43fa3c28f428245437410fe9e8834fa007de97f8..02a7a34737a3d0ef3fa7cd400f9e46016bebd9a7 100644 --- a/go.mod +++ b/go.mod @@ -17,10 +17,11 @@ require ( github.com/spf13/viper v1.6.2 gitlab.com/elixxir/comms v0.0.0-20200803223713-26b69d6adff9 gitlab.com/elixxir/crypto v0.0.0-20200803223738-661ca14b6470 - gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842 + gitlab.com/elixxir/ekv v0.1.0 gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d gitlab.com/xx_network/comms v0.0.0-20200803203304-a7a1c5e4239d - golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 + golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de + golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 // indirect gopkg.in/ini.v1 v1.52.0 // indirect ) diff --git a/go.sum b/go.sum index 969da48272806ca6d1096f8f7bf99c16c296afc0..c9189bcbdf590bdc80400c5ba85e43cc3e3d1eba 100644 --- a/go.sum +++ b/go.sum @@ -172,6 +172,8 @@ gitlab.com/elixxir/crypto v0.0.0-20200803223738-661ca14b6470 h1:WGECBA9PtyUk9Rfk gitlab.com/elixxir/crypto v0.0.0-20200803223738-661ca14b6470/go.mod h1:LHBAaEf48a0/AjU118rjoworH0LgXifhAqmNX3ZRvME= gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842 h1:m1zDQ6UadpuMnV7nvnyR+DUXE3AisRnVjajTb1xZE4c= gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s= +gitlab.com/elixxir/ekv v0.1.0 h1:CXYdlWzR2MmT54WaVw3REdWayuSxYuGOQoAHL2YTWTA= +gitlab.com/elixxir/ekv v0.1.0/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s= gitlab.com/elixxir/primitives v0.0.0-20200706165052-9fe7a4fb99a3 h1:GTfflZBNLeBq3UApYog0J3+hytdkoRsDduGQji2wyEU= gitlab.com/elixxir/primitives v0.0.0-20200706165052-9fe7a4fb99a3/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d h1:OKWTmYN5q8XVHo8JXThIH0TCuvl/fLXR7MGVacpqfRg= @@ -195,6 +197,8 @@ golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0 h1:eIYIE7EC5/Wv5Kbz8bJPaq golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg= golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig= +golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= @@ -225,6 +229,8 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7 golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642 h1:B6caxRw+hozq68X2MY7jEpZh/cr4/aHLv9xU8Kkadrw= +golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/io/receive.go b/io/receive.go index 6c6e5bd9dc4a445208db5bb34b4f992778062b02..b371bf1da05783320dcecd19545bbd8a258df54c 100644 --- a/io/receive.go +++ b/io/receive.go @@ -174,8 +174,15 @@ func (rm *ReceptionManager) receiveMessagesFromGateway(session user.Session, pollingMessage *pb.ClientRequest, receiveGateway *connect.Host) ([]*format.Message, error) { // Get the last message ID received var err error + + // FIXME: Cleanup after user.Session is removed and replaced. + if SessionV2 == nil { + globals.Log.WARN.Printf("SessionV2 is nil") + return nil, errors.New("SessionV2 is nil") + } pollingMessage.LastMessageID, err = SessionV2.GetLastMessageId() if err != nil { + globals.Log.WARN.Printf("Could not get LastMessageID: %+v", err) return nil, err } // FIXME: dont do this over an over diff --git a/storage/session.go b/storage/session.go index e433fff3fe82b30e49be5c316a75f043f0cda8cf..35ec1722881edb985f19fa2460144aa6aa0afdd3 100644 --- a/storage/session.go +++ b/storage/session.go @@ -4,6 +4,8 @@ // All rights reserved. / //////////////////////////////////////////////////////////////////////////////// +// Session object definition + package storage import ( @@ -15,10 +17,12 @@ import ( "time" ) +// Session object, backed by encrypted filestore type Session struct { kv *VersionedKV } +// Initialize a new Session object func Init(baseDir, password string) (*Session, error) { fs, err := ekv.NewFilestore(baseDir, password) var s *Session @@ -31,10 +35,12 @@ func Init(baseDir, password string) (*Session, error) { return s, err } +// Get an object from the session func (s *Session) Get(key string) (*VersionedObject, error) { return s.kv.Get(key) } +// Set a value in the session func (s *Session) Set(key string, object *VersionedObject) error { return s.kv.Set(key, object) } @@ -42,8 +48,8 @@ func (s *Session) Set(key string, object *VersionedObject) error { // Obtain the LastMessageID from the Session func (s *Session) GetLastMessageId() (string, error) { v, err := s.kv.Get("LastMessageID") - if err != nil { - return "", err + if v == nil || err != nil { + return "", nil } return string(v.Data), nil } diff --git a/storage/versionedkv.go b/storage/versionedkv.go index edd315658655e27a0c4a278ed9781615db5ce9d0..e36de9351881c5e91ab241ebe910f35228d1de13 100644 --- a/storage/versionedkv.go +++ b/storage/versionedkv.go @@ -113,6 +113,11 @@ func (v *VersionedKV) Get(key string) (*VersionedObject, error) { return &result, nil } +// Delete removes a given key from the data store +func (v *VersionedKV) Delete(key string) error { + return v.data.Delete(key) +} + // Set upserts new data into the storage // When calling this, you are responsible for prefixing the key with the correct // type and version! Call MakeKeyPrefix() to do so.