diff --git a/go.mod b/go.mod index 567d1fd78d9a8d5d4d040b18afcfdad750d1aa54..b3347e50950d5c2fb5dd4a831676ef0a7c7fb9bc 100644 --- a/go.mod +++ b/go.mod @@ -20,10 +20,10 @@ require ( github.com/ugorji/go v1.1.4 // indirect github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 - gitlab.com/elixxir/comms v0.0.4-0.20210121222442-b714136536e9 - gitlab.com/elixxir/crypto v0.0.7-0.20210121204803-2caab60ff687 + gitlab.com/elixxir/comms v0.0.3 + gitlab.com/elixxir/crypto v0.0.7-0.20210114172156-b576829ba7d8 gitlab.com/elixxir/ekv v0.1.4 - gitlab.com/elixxir/primitives v0.0.3-0.20210122185056-ad244787d961 + gitlab.com/elixxir/primitives v0.0.3-0.20210127201240-6a42ad925e8a gitlab.com/xx_network/comms v0.0.4-0.20210121204701-7a1eb0542424 gitlab.com/xx_network/crypto v0.0.5-0.20210121204626-b251b926e4f7 gitlab.com/xx_network/primitives v0.0.4-0.20210201180820-639f0a366d52 diff --git a/go.sum b/go.sum index 0c6eefea51c6f1a490a482a0e42de313c7142dbc..c5b42fc9cbf19d5d53c78883af50a2a007b680c6 100644 --- a/go.sum +++ b/go.sum @@ -265,6 +265,7 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA= gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= +gitlab.com/elixxir/comms v0.0.3/go.mod h1:5p7oz4yFrK037rPap6ooaWrloJrzuVZ4jnzOdvgyqnU= gitlab.com/elixxir/comms v0.0.4-0.20201217200754-6259dc49e6f1 h1:4iuAA/I8/aQ1Jn3gBguuR1u+LVy3YyShxpoNcqApaVg= gitlab.com/elixxir/comms v0.0.4-0.20201217200754-6259dc49e6f1/go.mod h1:2sNUHm725vQG4pG1RtvMd7kJ5CNqFb7Rl9cenuQCa2c= gitlab.com/elixxir/comms v0.0.4-0.20201229200853-c403d72e877c h1:YjTlUbZiNiJdL7Fy4TIUoWlHNK4dFOtuJ40YgsG7fac= @@ -283,10 +284,14 @@ gitlab.com/elixxir/comms v0.0.4-0.20210121204920-12c3111eff14 h1:/5w3IE06wUF35/h gitlab.com/elixxir/comms v0.0.4-0.20210121204920-12c3111eff14/go.mod h1:oJPQZEobUQwmype16+Hl9s2l+k3luL4ViUKxj0S4Dp8= gitlab.com/elixxir/comms v0.0.4-0.20210121222442-b714136536e9 h1:9jQb6bynSFVw9jDKX8t71V7EEwKkDtxzDxMaxw7+hYc= gitlab.com/elixxir/comms v0.0.4-0.20210121222442-b714136536e9/go.mod h1:oJPQZEobUQwmype16+Hl9s2l+k3luL4ViUKxj0S4Dp8= +gitlab.com/elixxir/comms v0.0.4-0.20210126185553-8ccfd64bf81b h1:ENB2YHpF72bbVHA6GG8BrMXEb+si9JHhO39vx7vk7hA= +gitlab.com/elixxir/comms v0.0.4-0.20210126185553-8ccfd64bf81b/go.mod h1:5hxGwa/8BEpo4cZrbxhxyXPpXmwzMPunKE/H141+rPU= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3 h1:znCt/x2bL4y8czTPaaFkwzdgSgW3BJc/1+dxyf1jqVw= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= +gitlab.com/elixxir/crypto v0.0.4/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= +gitlab.com/elixxir/crypto v0.0.6 h1:c94CGzBTV7LgInGHfmeJHrqq9nIc/WEOLUd9OeQBN74= gitlab.com/elixxir/crypto v0.0.7-0.20201217200352-0ba771a66932/go.mod h1:nqSNe486j6ua96nv1et6x2ESl/qXevkx7f31GowMRh4= gitlab.com/elixxir/crypto v0.0.7-0.20201222203132-9b4cc1ae3da6 h1:Vyf2wJ1/CoHLznATpI+z84OJQ+sgAbpVLT9P1CNjSVI= gitlab.com/elixxir/crypto v0.0.7-0.20201222203132-9b4cc1ae3da6/go.mod h1:NsIzH+TN592lMcmJGVzxUE64dObXuci7jo0qajyGahI= @@ -296,10 +301,14 @@ gitlab.com/elixxir/crypto v0.0.7-0.20210107184400-5c3e52a35758 h1:h2l8SZbdgcyMVw gitlab.com/elixxir/crypto v0.0.7-0.20210107184400-5c3e52a35758/go.mod h1:JDC7EFs5V97qourZyiSHBiiXHGUoKWX9XtJVhfEvpC4= gitlab.com/elixxir/crypto v0.0.7-0.20210113224347-cc4926b30fba h1:GtjhegVf6L9MZ6gp2oeBo/oVYUVB/IO91xBycF/jcNo= gitlab.com/elixxir/crypto v0.0.7-0.20210113224347-cc4926b30fba/go.mod h1:JDC7EFs5V97qourZyiSHBiiXHGUoKWX9XtJVhfEvpC4= +gitlab.com/elixxir/crypto v0.0.7-0.20210114172156-b576829ba7d8 h1:KhhsuPn+aPzZ66jdbbRF55SurogvQ/X9KuMWkXtmq+U= +gitlab.com/elixxir/crypto v0.0.7-0.20210114172156-b576829ba7d8/go.mod h1:4AumkGNppiEaMo6bIpFBrV6wZtaIjpbvkpA5+FBisA8= gitlab.com/elixxir/crypto v0.0.7-0.20210115231025-5d9b0dbc6985 h1:Csf3dIhwA6D293aURIHKuvwZr4HgIRzJ4FpCklmXEmA= gitlab.com/elixxir/crypto v0.0.7-0.20210115231025-5d9b0dbc6985/go.mod h1:JDC7EFs5V97qourZyiSHBiiXHGUoKWX9XtJVhfEvpC4= gitlab.com/elixxir/crypto v0.0.7-0.20210121204803-2caab60ff687 h1:tBlYA/jUOquWpe7bGZBQtvngbfbHsyt11aKZ761++8k= gitlab.com/elixxir/crypto v0.0.7-0.20210121204803-2caab60ff687/go.mod h1:7egP0+qiVyZnqcBlRr4rL0FhGNkqDCNEygungCAp7NM= +gitlab.com/elixxir/crypto v0.0.7-0.20210125231257-b52a556be893 h1:0NjQOwdGO/xBvgBMzRLSFXpSpnluzjT16obl5AcGfmI= +gitlab.com/elixxir/crypto v0.0.7-0.20210125231257-b52a556be893/go.mod h1:BoYrgHnTJPvvd4f/f4A+y22wwgZ7IxkYtGC8x9WiwxA= gitlab.com/elixxir/ekv v0.1.4-0.20201217220111-9c7e8be21577 h1:qT3ZO9GbKv7PcmakATsXsUdzn/hlm817ETOT/csDIak= gitlab.com/elixxir/ekv v0.1.4-0.20201217220111-9c7e8be21577/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4= gitlab.com/elixxir/ekv v0.1.4 h1:NLVMwsFEKArWcsDHu2DbXlm9374iSgn7oIA3rVSsvjc= @@ -309,6 +318,7 @@ gitlab.com/elixxir/primitives v0.0.0-20200804170709-a1896d262cd9/go.mod h1:p0Vel gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc= gitlab.com/elixxir/primitives v0.0.1 h1:q61anawANlNAExfkeQEE1NCsNih6vNV1FFLoUQX6txQ= gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE= +gitlab.com/elixxir/primitives v0.0.2/go.mod h1:3fxFHSlQhkV4vs+S0dZEz3Om3m+40WX8L806yvSnNFc= gitlab.com/elixxir/primitives v0.0.3-0.20201217193438-8ebfc882f1de/go.mod h1:H1OZ6ZXzTB3G4nOEdJzBJ7BySRnivpJTkTphxazFCl4= gitlab.com/elixxir/primitives v0.0.3-0.20201222171449-bdfe30389bb5 h1:BUV1ouY+9NA5+ZF+QfTpIBL1vO5zk31I68N7DX9bKj8= gitlab.com/elixxir/primitives v0.0.3-0.20201222171449-bdfe30389bb5/go.mod h1:5Z8fce94mks0aFhMvzftx2jJpDx4/pzDU20G2oTiU9w= @@ -324,7 +334,13 @@ gitlab.com/elixxir/primitives v0.0.3-0.20210121204717-e15ada7f0a73 h1:9h+pCc1ceI gitlab.com/elixxir/primitives v0.0.3-0.20210121204717-e15ada7f0a73/go.mod h1:bGYfAGerVVZhNzh+PxOMZVG7iYAUfInYvtdAkAqgiY8= gitlab.com/elixxir/primitives v0.0.3-0.20210122185056-ad244787d961 h1:BUN6bUBmTeebwYvTQ5yVi1iJlNAhjR7kEndcsV339dE= gitlab.com/elixxir/primitives v0.0.3-0.20210122185056-ad244787d961/go.mod h1:bGYfAGerVVZhNzh+PxOMZVG7iYAUfInYvtdAkAqgiY8= +gitlab.com/elixxir/primitives v0.0.3-0.20210125225949-9469ce6b08fc/go.mod h1:bGYfAGerVVZhNzh+PxOMZVG7iYAUfInYvtdAkAqgiY8= +gitlab.com/elixxir/primitives v0.0.3-0.20210126180712-bfbfb725c75a h1:3jq90Nmn8Ew9vfUuizV4mvj6py5LOmX3wkuBc+ywJ0w= +gitlab.com/elixxir/primitives v0.0.3-0.20210126180712-bfbfb725c75a/go.mod h1:bGYfAGerVVZhNzh+PxOMZVG7iYAUfInYvtdAkAqgiY8= +gitlab.com/elixxir/primitives v0.0.3-0.20210127201240-6a42ad925e8a h1:ZQncDfITNE12EdJK+shh6UzHlALhNU4Zjvv4hid2krs= +gitlab.com/elixxir/primitives v0.0.3-0.20210127201240-6a42ad925e8a/go.mod h1:Ph6isHUDVjmRUd9DioyKpd8W9J52gKBiDeue4DCygXA= gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw= +gitlab.com/xx_network/comms v0.0.3/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8= gitlab.com/xx_network/comms v0.0.4-0.20201130190834-365ddae56e7b/go.mod h1:YViGbRj7FjJYoaO4NpALGEd9dK/l8uUT000FEBbUTL8= gitlab.com/xx_network/comms v0.0.4-0.20201217200138-87075d5b4ffd h1:4LjS3UuBNA/AaglIJ+k1IBoxYgCWt+FM1MPYxjAFfaQ= gitlab.com/xx_network/comms v0.0.4-0.20201217200138-87075d5b4ffd/go.mod h1:/vIk6tSrDqk/7HZOdrbSXZT+kEL43HIoz60AoZTzTXg= @@ -556,6 +572,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/network/ephemeral/check_test.go b/network/ephemeral/check_test.go deleted file mode 100644 index 847b63ea2a6d25bc7a1fd04fb7f967044a416617..0000000000000000000000000000000000000000 --- a/network/ephemeral/check_test.go +++ /dev/null @@ -1 +0,0 @@ -package ephemeral diff --git a/network/ephemeral/identity.go b/network/ephemeral/identity.go index ce5a277f15bf4b0aa8574924436f9fb63ad6e7d2..965fdeee2343f9faa814dede9bd07633e218a5f1 100644 --- a/network/ephemeral/identity.go +++ b/network/ephemeral/identity.go @@ -10,7 +10,7 @@ package ephemeral import "gitlab.com/elixxir/client/storage/reception" type IdentityStoreInterface interface { - IsNewIdentity(identity reception.Identity) bool + IsAlreadyIdentity(identity reception.Identity) bool AddIdentity(identity reception.Identity) error InsertIdentity(identity reception.Identity) error } @@ -20,14 +20,14 @@ type IdentityStore struct { tracker map[reception.Identity]bool } -func newTracker(store *reception.Store) *IdentityStore { +func NewTracker(store *reception.Store) *IdentityStore { return &IdentityStore{ tracker: make(map[reception.Identity]bool), Store: store, } } -func (is *IdentityStore) IsNewIdentity(identity reception.Identity) bool { +func (is *IdentityStore) IsAlreadyIdentity(identity reception.Identity) bool { return is.tracker[identity] } diff --git a/network/ephemeral/check.go b/network/ephemeral/tracker.go similarity index 80% rename from network/ephemeral/check.go rename to network/ephemeral/tracker.go index 1bfe34dec949db0f353a8aafbc09181f34862e88..fd615bcc57ae040265d9c1e5fcc3c987590c8575 100644 --- a/network/ephemeral/check.go +++ b/network/ephemeral/tracker.go @@ -23,38 +23,35 @@ const validityGracePeriod = 5 * time.Minute const TimestampKey = "IDTrackingTimestamp" const ephemeralStoppable = "EphemeralCheck" -// Check runs a thread which checks for past and present ephemeral ids -func Check(session *storage.Session, ourId *id.ID) stoppable.Stoppable { +// Track runs a thread which checks for past and present ephemeral ids +func Track(session *storage.Session, ourId *id.ID, identityStore *IdentityStore) stoppable.Stoppable { stop := stoppable.NewSingle(ephemeralStoppable) - go check(session, ourId, stop) + go track(session, ourId, stop, identityStore) return stop } -// check is a thread which continuously processes ephemeral ids. +// track is a thread which continuously processes ephemeral ids. // If any error occurs, the thread crashes -func check(session *storage.Session, ourId *id.ID, stop *stoppable.Single) { +func track(session *storage.Session, ourId *id.ID, stop *stoppable.Single, identityStore *IdentityStore) { // Get the latest timestamp from store - identityStore := newTracker(session.Reception()) lastTimestampObj, err := session.Get(TimestampKey) if err != nil { globals.Log.FATAL.Panicf("Could not get timestamp: %v", err) - return } lastCheck, err := unmarshalTimestamp(lastTimestampObj) if err != nil { globals.Log.FATAL.Panicf("Could not parse stored timestamp: %v", err) - return } for true { - // Generates the IDs since the last check + // Generates the IDs since the last track now := time.Now() protoIds, err := getUpcomingIDs(ourId, now, lastCheck) if err != nil { - globals.Log.FATAL.Panicf("Could not generate " + + globals.Log.FATAL.Panicf("Could not generate "+ "upcoming IDs: %v", err) } @@ -63,11 +60,12 @@ func check(session *storage.Session, ourId *id.ID, stop *stoppable.Single) { // Add identities to storage if unique for _, identity := range identities { - // Check if identity has been generated already - if !identityStore.IsNewIdentity(identity) { + // Track if identity has been generated already + if !identityStore.IsAlreadyIdentity(identity) { + globals.Log.FATAL.Printf("inserting identity: %v\n", identity) // If not not, insert identity into store if err = identityStore.InsertIdentity(identity); err != nil { - globals.Log.FATAL.Panicf("Could not insert " + + globals.Log.FATAL.Panicf("Could not insert "+ "identity: %v", err) } } @@ -75,9 +73,9 @@ func check(session *storage.Session, ourId *id.ID, stop *stoppable.Single) { } // Generate the time stamp for storage - vo, err := marshalTimestamp(now) + vo, err := MarshalTimestamp(now) if err != nil { - globals.Log.FATAL.Panicf("Could not marshal " + + globals.Log.FATAL.Panicf("Could not marshal "+ "timestamp for storage: %v", err) } @@ -136,7 +134,7 @@ func unmarshalTimestamp(lastTimestampObj *versioned.Object) (time.Time, error) { } // Marshals the timestamp for ekv storage. Generates a storable object -func marshalTimestamp(timeToStore time.Time) (*versioned.Object, error) { +func MarshalTimestamp(timeToStore time.Time) (*versioned.Object, error) { data, err := timeToStore.MarshalBinary() return &versioned.Object{ @@ -147,7 +145,7 @@ func marshalTimestamp(timeToStore time.Time) (*versioned.Object, error) { } // Wrapper for GetIdsByRange. Generates ephemeral ids in the time period -// since the last check +// since the last track func getUpcomingIDs(ourId *id.ID, now, lastCheck time.Time) ([]ephemeral.ProtoIdentity, error) { return ephemeral.GetIdsByRange(ourId, ephemeralIdSie, @@ -159,10 +157,14 @@ func getUpcomingIDs(ourId *id.ID, now, // off of the last ephemeral ID to expire func calculateTickerTime(baseIDs []ephemeral.ProtoIdentity) time.Duration { // Get the last identity in the list - lastIdentity := baseIDs[len(baseIDs)-1] + indx := 0 + if len(baseIDs)-1 >= 0 { + indx = len(baseIDs) - 1 + } + lastIdentity := baseIDs[indx] // Factor out the grace period previously expanded upon. // Calculate and return that duration - gracePeriod := lastIdentity.End.Add(-2 * validityGracePeriod) + gracePeriod := lastIdentity.End.Add(-validityGracePeriod) return lastIdentity.End.Sub(gracePeriod) } diff --git a/network/ephemeral/tracker_test.go b/network/ephemeral/tracker_test.go new file mode 100644 index 0000000000000000000000000000000000000000..0a2288b519da4f31ad2d74bb9e0d9708bf7456c7 --- /dev/null +++ b/network/ephemeral/tracker_test.go @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +/////////////////////////////////////////////////////////////////////////////// + +package ephemeral + +import ( + "gitlab.com/elixxir/client/stoppable" + "gitlab.com/elixxir/client/storage" + "gitlab.com/xx_network/primitives/id" + "testing" + "time" +) + +// Smoke test for Track function +func TestCheck(t *testing.T) { + session := storage.InitTestingSession(t) + identityStore := NewTracker(session.Reception()) + + ourId := id.NewIdFromBytes([]byte("Sauron"), t) + Track(session, ourId, identityStore) +} + +// Unit test for track +func TestCheck_Thread(t *testing.T) { + + session := storage.InitTestingSession(t) + ourId := id.NewIdFromBytes([]byte("Sauron"), t) + stop := stoppable.NewSingle(ephemeralStoppable) + identityStore := NewTracker(session.Reception()) + + now := time.Now() + twoDaysAgo := now.Add(-2 * 24 * time.Hour) + twoDaysTimestamp, err := MarshalTimestamp(twoDaysAgo) + if err != nil { + t.Errorf("Could not marshal timestamp for test setup: %v", err) + } + err = session.Set(TimestampKey, twoDaysTimestamp) + if err != nil { + t.Errorf("Could not set mock timestamp for test setup: %v", err) + } + go func() { + track(session, ourId, stop, identityStore) + t.Errorf("Thread should not close") + }() + + time.Sleep(1 * time.Second) + + // Manually generate identities + eids, err := getUpcomingIDs(ourId, time.Now(), twoDaysAgo) + if err != nil { + t.Errorf("Could not generate upcoming ids: %v", err) + } + + identities := generateIdentities(eids, ourId) + + // Check if store has been updated for new identities + if !identityStore.IsAlreadyIdentity(identities[0]) { + t.Errorf("Store was not updated for newly generated identies") + } + +} diff --git a/network/manager.go b/network/manager.go index b1537afe68fd57fa5381452e4b434efcd24d765c..00e03f3358df215605de72b9a749f4966c6165ac 100644 --- a/network/manager.go +++ b/network/manager.go @@ -7,7 +7,7 @@ package network -// check.go controls access to network resources. Interprocess communications +// tracker.go controls access to network resources. Interprocess communications // and intraclient state are accessible through the context object. import ( @@ -96,6 +96,7 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, // - Health Tracker (/network/health) // - Garbled Messages (/network/message/garbled.go) // - Critical Messages (/network/message/critical.go) +// - Ephemeral ID tracking (network/ephemeral/tracker.go) func (m *manager) Follow() (stoppable.Stoppable, error) { if !atomic.CompareAndSwapUint32(m.running, 0, 1) { return nil, errors.Errorf("network routines are already running") @@ -126,8 +127,15 @@ func (m *manager) Follow() (stoppable.Stoppable, error) { // Round processing multi.Add(m.round.StartProcessors()) + // Ephemeral ID tracking - multi.Add(ephemeral.Check(m.Session, m.Comms.Id)) + err = checkTimestampStore(m.Session) + if err != nil { + return nil, errors.Errorf("Could not store timestamp " + + "for ephemeral ID tracking: %v", err) + } + identityStore := ephemeral.NewTracker(m.Session.Reception()) + multi.Add(ephemeral.Track(m.Session, m.Comms.Id, identityStore)) //set the running status back to 0 so it can be started again closer := stoppable.NewCleanup(multi, func(time.Duration) error { @@ -140,6 +148,20 @@ func (m *manager) Follow() (stoppable.Stoppable, error) { return closer, nil } +// Sanitation check of timestamp store. If a value has not been stored yet +// then the current time is stored +func checkTimestampStore(session *storage.Session) error { + if _, err := session.Get(ephemeral.TimestampKey); err != nil { + now, err := ephemeral.MarshalTimestamp(time.Now()) + if err != nil { + return errors.Errorf("Could not marshal new timestamp for storage: %v", err) + } + return session.Set(ephemeral.TimestampKey, now) + } + + return nil +} + // GetHealthTracker returns the health tracker func (m *manager) GetHealthTracker() interfaces.HealthTracker { return m.Health diff --git a/storage/session.go b/storage/session.go index 2a0b6889bbfc68654d269e749bf0a889fc19e6e2..f9a40fb6f495cbb79496bb52bfc098180c7efa8f 100644 --- a/storage/session.go +++ b/storage/session.go @@ -132,11 +132,6 @@ func New(baseDir, password string, u userInterface.User, cmixGrp, s.conversations = conversation.NewStore(s.kv) s.partition = partition.New(s.kv) - s.ephemeral, err = ephemeral.NewStore(s.kv) - if err != nil { - return nil, errors.WithMessage(err, "Failed to ephemeralId tracking store") - } - s.reception = reception.NewStore(s.kv) return s, nil @@ -200,11 +195,6 @@ func Load(baseDir, password string, rng *fastRNG.StreamGenerator) (*Session, err s.conversations = conversation.NewStore(s.kv) s.partition = partition.New(s.kv) - s.ephemeral, err = ephemeral.LoadStore(s.kv) - if err != nil { - return nil, errors.WithMessage(err, "Failed to ephemeral store") - } - return s, nil } @@ -358,10 +348,6 @@ func InitTestingSession(i interface{}) *Session { s.conversations = conversation.NewStore(s.kv) s.partition = partition.New(s.kv) - s.ephemeral, err = ephemeral.NewStore(s.kv) - if err != nil { - globals.Log.FATAL.Panicf("Failed to create ephemeral store: %+v", err) - } - + s.reception = reception.NewStore(s.kv) return s }