From f55ed1c7b020b58cc2b42dfcda11892be26ffc5d Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Wed, 23 Mar 2022 13:41:24 -0700 Subject: [PATCH] more tracker implementation --- bindings/group.go | 2 +- interfaces/networkManager.go | 11 +- .../{ephemeral => address}/addressSpace.go | 26 +- .../addressSpace_test.go | 2 +- network/{ephemeral => address}/testutil.go | 2 +- network/ephemeral/tracker.go | 216 ------------ .../identity/receptionID}/IdentityUse.go | 2 +- .../identity/receptionID}/fake.go | 6 +- .../identity/receptionID}/fake_test.go | 8 +- .../identity/receptionID}/identity.go | 2 +- .../identity/receptionID}/identity_test.go | 2 +- .../identity/receptionID}/registration.go | 4 +- .../receptionID}/registration_test.go | 2 +- .../identity/receptionID}/store.go | 6 +- .../identity/receptionID}/store_test.go | 2 +- network/identity/tracker.go | 318 ++++++++++++++++++ .../{ephemeral => identity}/tracker_test.go | 11 +- network/manager.go | 11 +- network/message/triggers.go | 2 +- network/rounds/check.go | 4 +- network/rounds/historical.go | 4 +- network/rounds/retrieve.go | 6 +- network/rounds/retrieve_test.go | 30 +- network/rounds/unchecked.go | 10 +- network/rounds/unchecked_test.go | 2 +- network/sendCmixUtils.go | 8 +- single/manager.go | 6 +- single/manager_test.go | 6 +- single/receiveResponse_test.go | 2 +- single/response.go | 2 +- single/transmission.go | 24 +- single/transmission_test.go | 4 +- storage/e2e/store_test.go | 4 +- storage/rounds/roundIdentity.go | 2 +- storage/rounds/uncheckedRounds_test.go | 8 +- 35 files changed, 430 insertions(+), 327 deletions(-) rename network/{ephemeral => address}/addressSpace.go (83%) rename network/{ephemeral => address}/addressSpace_test.go (99%) rename network/{ephemeral => address}/testutil.go (99%) delete mode 100644 network/ephemeral/tracker.go rename {storage/reception => network/identity/receptionID}/IdentityUse.go (97%) rename {storage/reception => network/identity/receptionID}/fake.go (88%) rename {storage/reception => network/identity/receptionID}/fake_test.go (92%) rename {storage/reception => network/identity/receptionID}/identity.go (99%) rename {storage/reception => network/identity/receptionID}/identity_test.go (99%) rename {storage/reception => network/identity/receptionID}/registration.go (97%) rename {storage/reception => network/identity/receptionID}/registration_test.go (99%) rename {storage/reception => network/identity/receptionID}/store.go (98%) rename {storage/reception => network/identity/receptionID}/store_test.go (99%) create mode 100644 network/identity/tracker.go rename network/{ephemeral => identity}/tracker_test.go (93%) diff --git a/bindings/group.go b/bindings/group.go index aee0b0f7c..3f2976941 100644 --- a/bindings/group.go +++ b/bindings/group.go @@ -397,7 +397,7 @@ func (gmr *GroupMessageReceive) GetRecipientID() []byte { return gmr.RecipientID.Bytes() } -// GetEphemeralID returns the ephemeral ID of the recipient. +// GetEphemeralID returns the address ID of the recipient. func (gmr *GroupMessageReceive) GetEphemeralID() int64 { return gmr.EphemeralID.Int64() } diff --git a/interfaces/networkManager.go b/interfaces/networkManager.go index c950e11e3..8176ec464 100644 --- a/interfaces/networkManager.go +++ b/interfaces/networkManager.go @@ -73,9 +73,9 @@ type NetworkManager interface { // and Identity is Defined by a source ID and a current EphemeralID // In its IdentityParams, paremeters describing the properties // of the identity as well as how long it will last are described - AddIdentity(Identity, IdentityParams) + AddIdentity(id *id.ID, validUntil time.Time, persistent bool) error // RemoveIdentity removes a currently tracked identity. - RemoveIdentity(Identity) + RemoveIdentity(id *id.ID) /* Fingerprints are the primary mechanisim of identifying a picked up message over cMix. They are a unique one time use 255 bit vector generally @@ -84,8 +84,7 @@ type NetworkManager interface { The */ //AddFingerprint - Adds a fingerprint which will be handled by a specific processor - AddFingerprint(fingerprint format.Fingerprint, processor MessageProcessorFP) - AddFingerprints(fingerprints map[format.Fingerprint]MessageProcessorFP) + AddFingerprint(fingerprint format.Fingerprint, processor MessageProcessor) RemoveFingerprint(fingerprint format.Fingerprint) RemoveFingerprints(fingerprints []format.Fingerprint) CheckFingerprint(fingerprint format.Fingerprint) bool @@ -106,7 +105,7 @@ type NetworkManager interface { Due to the extra overhead of trial hashing, triggers are processed after fingerprints. If a fingerprint match occurs on the message, triggers will not be handled. - Triggers are ephemeral to the session. When starting a new client, all triggers must be + Triggers are address to the session. When starting a new client, all triggers must be re-added before StartNetworkFollower is called. */ @@ -152,7 +151,7 @@ type IdentityParams struct { EndValid time.Time // Timestamp when the ephID stops being valid // Makes the identity not store on disk - // When an ephemeral identity is deleted, all fingerprints & triggers + // When an address identity is deleted, all fingerprints & triggers // associated with it also delete. // TODO: This should not be confused with EphID for checking // when messages are for the the user. That's a different type diff --git a/network/ephemeral/addressSpace.go b/network/address/addressSpace.go similarity index 83% rename from network/ephemeral/addressSpace.go rename to network/address/addressSpace.go index f942df77d..986cc8f5a 100644 --- a/network/ephemeral/addressSpace.go +++ b/network/address/addressSpace.go @@ -1,4 +1,4 @@ -package ephemeral +package address import ( "github.com/pkg/errors" @@ -13,18 +13,18 @@ const ( initSize = 1 ) -// AddressSpace contains the current address space size used for creating -// ephemeral IDs and the infrastructure to alert other processes when an Update +// Space contains the current address space size used for creating +// address IDs and the infrastructure to alert other processes when an Update // occurs. -type AddressSpace struct { +type Space struct { size uint8 notifyMap map[string]chan uint8 cond *sync.Cond } // NewAddressSpace initialises a new AddressSpace and returns it. -func NewAddressSpace() *AddressSpace { - return &AddressSpace{ +func NewAddressSpace() *Space { + return &Space{ size: initSize, notifyMap: make(map[string]chan uint8), cond: sync.NewCond(&sync.Mutex{}), @@ -33,7 +33,7 @@ func NewAddressSpace() *AddressSpace { // Get returns the current address space size. It blocks until an address space // size is set. -func (as *AddressSpace) Get() uint8 { +func (as *Space) Get() uint8 { as.cond.L.Lock() defer as.cond.L.Unlock() @@ -50,7 +50,7 @@ func (as *AddressSpace) Get() uint8 { // GetWithoutWait returns the current address space size regardless if it has // been set yet. -func (as *AddressSpace) GetWithoutWait() uint8 { +func (as *Space) GetWithoutWait() uint8 { as.cond.L.Lock() defer as.cond.L.Unlock() return as.size @@ -60,7 +60,7 @@ func (as *AddressSpace) GetWithoutWait() uint8 { // each registered channel is notified of the Update. If this was the first time // that the address space size was set, then the conditional broadcasts to stop // blocking for all threads waiting on Get. -func (as *AddressSpace) Update(newSize uint8) { +func (as *Space) Update(newSize uint8) { as.cond.L.Lock() defer as.cond.L.Unlock() @@ -93,7 +93,7 @@ func (as *AddressSpace) Update(newSize uint8) { // RegisterNotification returns a channel that will trigger for every address // space size Update. The provided tag is the unique ID for the channel. // Returns an error if the tag is already used. -func (as *AddressSpace) RegisterNotification(tag string) (chan uint8, error) { +func (as *Space) RegisterNotification(tag string) (chan uint8, error) { as.cond.L.Lock() defer as.cond.L.Unlock() @@ -108,7 +108,7 @@ func (as *AddressSpace) RegisterNotification(tag string) (chan uint8, error) { // UnregisterNotification stops broadcasting address space size updates on the // channel with the specified tag. -func (as *AddressSpace) UnregisterNotification(tag string) { +func (as *Space) UnregisterNotification(tag string) { as.cond.L.Lock() defer as.cond.L.Unlock() @@ -117,7 +117,7 @@ func (as *AddressSpace) UnregisterNotification(tag string) { // NewTestAddressSpace initialises a new AddressSpace for testing with the given // size. -func NewTestAddressSpace(newSize uint8, x interface{}) *AddressSpace { +func NewTestAddressSpace(newSize uint8, x interface{}) *Space { switch x.(type) { case *testing.T, *testing.M, *testing.B, *testing.PB: break @@ -126,7 +126,7 @@ func NewTestAddressSpace(newSize uint8, x interface{}) *AddressSpace { "Got %T", x) } - as := &AddressSpace{ + as := &Space{ size: initSize, notifyMap: make(map[string]chan uint8), cond: sync.NewCond(&sync.Mutex{}), diff --git a/network/ephemeral/addressSpace_test.go b/network/address/addressSpace_test.go similarity index 99% rename from network/ephemeral/addressSpace_test.go rename to network/address/addressSpace_test.go index 98bfa6412..d6c0aa921 100644 --- a/network/ephemeral/addressSpace_test.go +++ b/network/address/addressSpace_test.go @@ -1,4 +1,4 @@ -package ephemeral +package address import ( "reflect" diff --git a/network/ephemeral/testutil.go b/network/address/testutil.go similarity index 99% rename from network/ephemeral/testutil.go rename to network/address/testutil.go index a1d0602ba..0c52b6329 100644 --- a/network/ephemeral/testutil.go +++ b/network/address/testutil.go @@ -5,7 +5,7 @@ // LICENSE file // /////////////////////////////////////////////////////////////////////////////// -package ephemeral +package address import ( "gitlab.com/elixxir/client/network/gateway" diff --git a/network/ephemeral/tracker.go b/network/ephemeral/tracker.go deleted file mode 100644 index 632a172d5..000000000 --- a/network/ephemeral/tracker.go +++ /dev/null @@ -1,216 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// 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 ( - "github.com/pkg/errors" - jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/interfaces" - "gitlab.com/elixxir/client/stoppable" - "gitlab.com/elixxir/client/storage" - "gitlab.com/elixxir/client/storage/reception" - "gitlab.com/elixxir/client/storage/versioned" - "gitlab.com/xx_network/primitives/id" - "gitlab.com/xx_network/primitives/id/ephemeral" - "gitlab.com/xx_network/primitives/netTime" - "time" -) - -const validityGracePeriod = 5 * time.Minute -const TimestampKey = "IDTrackingTimestamp" -const TimestampStoreVersion = 0 -const ephemeralStoppable = "EphemeralCheck" -const addressSpaceSizeChanTag = "ephemeralTracker" - -// Track runs a thread which checks for past and present ephemeral ID. -func Track(session *storage.Session, addrSpace *AddressSpace, ourId *id.ID) stoppable.Stoppable { - stop := stoppable.NewSingle(ephemeralStoppable) - - go track(session, addrSpace, ourId, stop) - - return stop -} - -// track is a thread which continuously processes ephemeral IDs. Panics if any -// error occurs. -func track(session *storage.Session, addrSpace *AddressSpace, ourId *id.ID, stop *stoppable.Single) { - - // Check that there is a timestamp in store at all - err := checkTimestampStore(session) - if err != nil { - jww.FATAL.Panicf("Could not store timestamp for ephemeral ID "+ - "tracking: %+v", err) - } - - // get the latest timestamp from store - lastTimestampObj, err := session.Get(TimestampKey) - if err != nil { - jww.FATAL.Panicf("Could not get timestamp: %+v", err) - } - - lastCheck, err := unmarshalTimestamp(lastTimestampObj) - if err != nil { - jww.FATAL.Panicf("Could not parse stored timestamp: %+v", err) - } - - // Wait until we get the ID size from the network - receptionStore := session.Reception() - addrSpace.UnregisterNotification(addressSpaceSizeChanTag) - addressSizeUpdate, err := addrSpace.RegisterNotification(addressSpaceSizeChanTag) - if err != nil { - jww.FATAL.Panicf("failed to register address size notification "+ - "channel: %+v", err) - } - addressSize := addrSpace.Get() - - for { - now := netTime.Now() - - // Hack for inconsistent time on android - if now.Before(lastCheck) || now.Equal(lastCheck) { - now = lastCheck.Add(time.Nanosecond) - } - - // Generates the IDs since the last track - protoIds, err := ephemeral.GetIdsByRange( - ourId, uint(addressSize), lastCheck, now.Add(validityGracePeriod).Sub(lastCheck)) - - jww.DEBUG.Printf("Now: %s, LastCheck: %s, Different: %s", - now, lastCheck, now.Sub(lastCheck)) - jww.DEBUG.Printf("protoIds Count: %d", len(protoIds)) - - if err != nil { - jww.FATAL.Panicf("Could not generate upcoming IDs: %+v", err) - } - - // Generate identities off of that list - identities := generateIdentities(protoIds, ourId, addressSize) - - jww.INFO.Printf("Number of Identities Generated: %d", len(identities)) - jww.INFO.Printf("Current Identity: %d (source: %s), Start: %s, End: %s", - identities[len(identities)-1].EphId.Int64(), - identities[len(identities)-1].Source, - identities[len(identities)-1].StartValid, - identities[len(identities)-1].EndValid) - - // Add identities to storage, if unique - for _, identity := range identities { - if err = receptionStore.AddIdentity(identity); err != nil { - jww.FATAL.Panicf("Could not insert identity: %+v", err) - } - } - - // Generate the timestamp for storage - vo, err := marshalTimestamp(now) - if err != nil { - jww.FATAL.Panicf("Could not marshal timestamp for storage: %+v", err) - - } - lastCheck = now - - // Store the timestamp - if err = session.Set(TimestampKey, vo); err != nil { - jww.FATAL.Panicf("Could not store timestamp: %+v", err) - } - - // Sleep until the last ID has expired - timeToSleep := calculateTickerTime(protoIds, now) - select { - case <-time.NewTimer(timeToSleep).C: - case addressSize = <-addressSizeUpdate: - receptionStore.SetToExpire(addressSize) - case <-stop.Quit(): - addrSpace.UnregisterNotification(addressSpaceSizeChanTag) - stop.ToStopped() - return - } - } -} - -// generateIdentities generates a list of identities off of the list of passed -// in ProtoIdentity. -func generateIdentities(protoIds []ephemeral.ProtoIdentity, ourId *id.ID, - addressSize uint8) []reception.Identity { - - identities := make([]reception.Identity, len(protoIds)) - - // Add identities for every ephemeral ID - for i, eid := range protoIds { - // Expand the grace period for both start and end - identities[i] = reception.Identity{ - EphId: eid.Id, - Source: ourId, - AddressSize: addressSize, - End: eid.End, - StartValid: eid.Start.Add(-validityGracePeriod), - EndValid: eid.End.Add(validityGracePeriod), - Ephemeral: false, - ExtraChecks: interfaces.DefaultExtraChecks, - } - - } - - return identities -} - -// checkTimestampStore performs a 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(TimestampKey); err != nil { - // Only generate from the last hour because this is a new ID; it could - // not yet receive messages - now, err := marshalTimestamp(netTime.Now().Add(-1 * time.Hour)) - if err != nil { - return errors.Errorf("Could not marshal new timestamp for "+ - "storage: %+v", err) - } - - return session.Set(TimestampKey, now) - } - - return nil -} - -// unmarshalTimestamp unmarshal the stored timestamp into a time.Time. -func unmarshalTimestamp(lastTimestampObj *versioned.Object) (time.Time, error) { - if lastTimestampObj == nil || lastTimestampObj.Data == nil { - return netTime.Now(), nil - } - - lastTimestamp := time.Time{} - err := lastTimestamp.UnmarshalBinary(lastTimestampObj.Data) - return lastTimestamp, err -} - -// marshalTimestamp marshals the timestamp and generates a storable object for -// ekv storage. -func marshalTimestamp(timeToStore time.Time) (*versioned.Object, error) { - data, err := timeToStore.MarshalBinary() - - return &versioned.Object{ - Version: TimestampStoreVersion, - Timestamp: netTime.Now(), - Data: data, - }, err -} - -// calculateTickerTime calculates the time for the ticker based off of the last -// ephemeral ID to expire. -func calculateTickerTime(baseIDs []ephemeral.ProtoIdentity, now time.Time) time.Duration { - if len(baseIDs) == 0 { - return time.Duration(0) - } - - // get the last identity in the list - lastIdentity := baseIDs[len(baseIDs)-1] - - // Factor out the grace period previously expanded upon - // Calculate and return that duration - gracePeriod := lastIdentity.End.Add(-1 * validityGracePeriod) - return gracePeriod.Sub(now) -} diff --git a/storage/reception/IdentityUse.go b/network/identity/receptionID/IdentityUse.go similarity index 97% rename from storage/reception/IdentityUse.go rename to network/identity/receptionID/IdentityUse.go index 92d1ed8c9..7b957be00 100644 --- a/storage/reception/IdentityUse.go +++ b/network/identity/receptionID/IdentityUse.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "fmt" diff --git a/storage/reception/fake.go b/network/identity/receptionID/fake.go similarity index 88% rename from storage/reception/fake.go rename to network/identity/receptionID/fake.go index 1e4e0a31c..17d45db7a 100644 --- a/storage/reception/fake.go +++ b/network/identity/receptionID/fake.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "github.com/pkg/errors" @@ -23,12 +23,12 @@ func generateFakeIdentity(rng io.Reader, addressSize uint8, copy(randID[:id.ArrIDLen-1], randIdBytes) randID.SetType(id.User) - // Generate the current ephemeral ID from the random identity + // Generate the current address ID from the random identity ephID, start, end, err := ephemeral.GetId( randID, uint(addressSize), now.UnixNano()) if err != nil { return IdentityUse{}, errors.WithMessage(err, "failed to generate an "+ - "ephemeral ID for random identity when none is available") + "address ID for random identity when none is available") } return IdentityUse{ diff --git a/storage/reception/fake_test.go b/network/identity/receptionID/fake_test.go similarity index 92% rename from storage/reception/fake_test.go rename to network/identity/receptionID/fake_test.go index af2cae004..14bfc0965 100644 --- a/storage/reception/fake_test.go +++ b/network/identity/receptionID/fake_test.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "encoding/json" @@ -54,14 +54,14 @@ func Test_generateFakeIdentity_RngError(t *testing.T) { } } -// Error path: fails to get the ephemeral ID. +// Error path: fails to get the address ID. func Test_generateFakeIdentity_GetEphemeralIdError(t *testing.T) { rng := rand.New(rand.NewSource(42)) timestamp := time.Date(2009, 11, 17, 20, 34, 58, 651387237, time.UTC) _, err := generateFakeIdentity(rng, math.MaxInt8, timestamp) - if err == nil || !strings.Contains(err.Error(), "ephemeral ID") { + if err == nil || !strings.Contains(err.Error(), "address ID") { t.Errorf("generateFakeIdentity() did not return the correct error on "+ - "failure to generate ephemeral ID: %+v", err) + "failure to generate address ID: %+v", err) } } diff --git a/storage/reception/identity.go b/network/identity/receptionID/identity.go similarity index 99% rename from storage/reception/identity.go rename to network/identity/receptionID/identity.go index 4ae3f9564..74ed55577 100644 --- a/storage/reception/identity.go +++ b/network/identity/receptionID/identity.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "encoding/json" diff --git a/storage/reception/identity_test.go b/network/identity/receptionID/identity_test.go similarity index 99% rename from storage/reception/identity_test.go rename to network/identity/receptionID/identity_test.go index 0993a0e2a..2fcb29fb3 100644 --- a/storage/reception/identity_test.go +++ b/network/identity/receptionID/identity_test.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "gitlab.com/elixxir/client/storage/versioned" diff --git a/storage/reception/registration.go b/network/identity/receptionID/registration.go similarity index 97% rename from storage/reception/registration.go rename to network/identity/receptionID/registration.go index 611a6c0ba..92e93e3f5 100644 --- a/storage/reception/registration.go +++ b/network/identity/receptionID/registration.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "github.com/pkg/errors" @@ -55,7 +55,7 @@ func newRegistration(reg Identity, kv *versioned.KV) (*registration, error) { } r.CR = cr - // If this is not ephemeral, then store everything + // If this is not address, then store everything if !reg.Ephemeral { // Store known rounds var err error diff --git a/storage/reception/registration_test.go b/network/identity/receptionID/registration_test.go similarity index 99% rename from storage/reception/registration_test.go rename to network/identity/receptionID/registration_test.go index ccf210f5e..3da5dc71f 100644 --- a/storage/reception/registration_test.go +++ b/network/identity/receptionID/registration_test.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "gitlab.com/elixxir/client/storage/versioned" diff --git a/storage/reception/store.go b/network/identity/receptionID/store.go similarity index 98% rename from storage/reception/store.go rename to network/identity/receptionID/store.go index a73d941ed..ccea69da7 100644 --- a/storage/reception/store.go +++ b/network/identity/receptionID/store.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "encoding/json" @@ -117,7 +117,7 @@ func (s *Store) save() error { return nil } -// makeStoredReferences generates a reference of any non-ephemeral identities +// makeStoredReferences generates a reference of any non-address identities // for storage. func (s *Store) makeStoredReferences() []storedReference { identities := make([]storedReference, len(s.active)) @@ -249,7 +249,6 @@ func (s *Store) SetToExpire(addressSize uint8) { func (s *Store) prune(now time.Time) { lengthBefore := len(s.active) var pruned []int64 - // Prune the list for i := 0; i < len(s.active); i++ { inQuestion := s.active[i] @@ -268,6 +267,7 @@ func (s *Store) prune(now time.Time) { // Save the list if it changed if lengthBefore != len(s.active) { + jww.INFO.Printf("Pruned %d identities [%+v]", lengthBefore-len(s.active), pruned) if err := s.save(); err != nil { jww.FATAL.Panicf("Failed to store reception storage: %+v", err) diff --git a/storage/reception/store_test.go b/network/identity/receptionID/store_test.go similarity index 99% rename from storage/reception/store_test.go rename to network/identity/receptionID/store_test.go index 87e00d162..cfed1582d 100644 --- a/storage/reception/store_test.go +++ b/network/identity/receptionID/store_test.go @@ -1,4 +1,4 @@ -package reception +package receptionID import ( "bytes" diff --git a/network/identity/tracker.go b/network/identity/tracker.go new file mode 100644 index 000000000..6716cf821 --- /dev/null +++ b/network/identity/tracker.go @@ -0,0 +1,318 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright © 2020 xx network SEZC // +// // +// Use of this source code is governed by a license that can be found in the // +// LICENSE file // +/////////////////////////////////////////////////////////////////////////////// + +package identity + +import ( + "encoding/json" + "github.com/pkg/errors" + jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/interfaces" + "gitlab.com/elixxir/client/network/address" + "gitlab.com/elixxir/client/network/identity/receptionID" + "gitlab.com/elixxir/client/stoppable" + "gitlab.com/elixxir/client/storage" + "gitlab.com/elixxir/client/storage/versioned" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/xx_network/primitives/netTime" + "sort" + "sync" + "time" +) + +const validityGracePeriod = 5 * time.Minute +const TrackerListKey = "TrackerListKey" +const TrackerListVersion = 0 +const TimestampKey = "IDTrackingTimestamp" +const TimestampStoreVersion = 0 +const ephemeralStoppable = "EphemeralCheck" +const addressSpaceSizeChanTag = "ephemeralTracker" +var Forever time.Time = time.Time{} + + +type Tracker struct{ + tracked []trackedID + store *receptionID.Store + session *storage.Session + newIdentity chan trackedID + deleteIdentity chan *id.ID +} + +type trackedID struct{ + NextGeneration time.Time + LastGeneration time.Time + Source *id.ID + ValidUntil time.Time + Persistent bool +} + +func NewTracker(session *storage.Session, addrSpace *address.Space)*Tracker{ + //intilization + //loading + //if load fails, make a new + //check if there is an old timestamp, recreate the basic ID from it + //initilize the ephemeral identiies system +} + +//make the GetIdentities call on the ephemerals system public on this + +// Track runs a thread which checks for past and present address ID. +func (tracker Tracker)StartProcessies() stoppable.Stoppable { + stop := stoppable.NewSingle(ephemeralStoppable) + + go track(session, addrSpace, ourId, stop) + + return stop +} + + + +// AddIdentity adds an identity to be tracked +func (tracker *Tracker)AddIdentity(id *id.ID, validUntil time.Time, persistent bool){ + tracker.newIdentity<-trackedID{ + NextGeneration: netTime.Now().Add(-time.Second), + LastGeneration: time.Time{}, + Source: id, + ValidUntil: validUntil, + Persistent: persistent, + } +} + +// RemoveIdentity removes a currently tracked identity. +func (tracker *Tracker) RemoveIdentity(id *id.ID){ + tracker.deleteIdentity<-id +} + +func (tracker *Tracker)track(session *storage.Session, addrSpace *address.Space, ourId *id.ID, stop *stoppable.Single) { + + // Wait until we get the ID size from the network + addressSize := addrSpace.Get() + + /*wait for next event*/ + trackerLoop: + for { + edits := false + var toRemove map[int]struct{} + nextEvent := tracker.tracked[0].ValidUntil + + //loop through every tracked ID and see if any operatrions are needed + for i := range tracker.tracked { + inQuestion := tracker.tracked[i] + + //generate new ephmerals if is time for it + if netTime.Now().After(inQuestion.NextGeneration) { + edits = true + + //ensure that ephemerals will not be generated after the identity is invalid + generateUntil := inQuestion.NextGeneration + if inQuestion.ValidUntil !=Forever && generateUntil.After(inQuestion.ValidUntil){ + generateUntil = inQuestion.ValidUntil + } + //generate all not yet existing ephemerals + identities, nextNextGeneration := generateIdentitiesOverRange(inQuestion.LastGeneration, + inQuestion.NextGeneration, inQuestion.Source, addressSize) + //add all ephemerals to the ephemeral handler + for _, identity := range identities { + // move up the end time if the source identity is invalid before the natural end + // of the ephemeral identity. + if inQuestion.ValidUntil != Forever && identity.End.After(inQuestion.ValidUntil) { + identity.End = inQuestion.ValidUntil + } + if err := tracker.store.AddIdentity(identity); err != nil { + jww.FATAL.Panicf("Could not insert identity: %+v", err) + } + } + //move forward the tracking of when generation should occur + inQuestion.LastGeneration = inQuestion.NextGeneration + inQuestion.NextGeneration = nextNextGeneration.Add(time.Millisecond) + } + + // if it is time to delete the id, process the delete + if inQuestion.ValidUntil != Forever && netTime.Now().After(inQuestion.ValidUntil) { + edits = true + toRemove[i] = struct{}{} + } else { + // otherwise see if it is responsible for the next event + if inQuestion.NextGeneration.Before(nextEvent){ + nextEvent = inQuestion.NextGeneration + } + if inQuestion.ValidUntil.Before(nextEvent){ + nextEvent = inQuestion.ValidUntil + } + } + } + + //process any deletions + if len(toRemove)>0{ + newTracked := make([]trackedID,len(tracker.tracked)) + for i := range tracker.tracked{ + if _, remove := toRemove[i]; !remove { + newTracked = append(newTracked, tracker.tracked[i]) + } + } + tracker.tracked=newTracked + } + + if edits{ + tracker.save() + } + + // trigger events early. this will cause generations to happen + // early as well as message pickup. As a result, if there + // are time sync issues between clients and they begin sending + // to ephemerals early, messages will still be picked up + nextUpdate := nextEvent.Add(-validityGracePeriod) + + // Sleep until the last ID has expired + select { + case <-time.NewTimer(nextUpdate.Sub(nextUpdate)).C: + case newIdentity := <- tracker.newIdentity: + // if the identity is old, just update its properties + for i := range tracker.tracked{ + inQuestion := tracker.tracked[i] + if inQuestion.Source.Cmp(newIdentity.Source){ + inQuestion.Persistent = newIdentity.Persistent + inQuestion.ValidUntil = newIdentity.ValidUntil + tracker.save() + continue trackerLoop + } + } + //otherwise, add it to the list and run + tracker.tracked = append(tracker.tracked,newIdentity) + tracker.save() + continue trackerLoop + case deleteID := <- tracker.deleteIdentity: + for i := range tracker.tracked{ + inQuestion := tracker.tracked[i] + if inQuestion.Source.Cmp(deleteID){ + tracker.tracked = append(tracker.tracked[:i], tracker.tracked[i+1:]...) + tracker.save() + break + } + } + case <-stop.Quit(): + addrSpace.UnregisterNotification(addressSpaceSizeChanTag) + stop.ToStopped() + return + } + } +} + +// checkTimestampStore performs a 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(TimestampKey); err != nil { + // Only generate from the last hour because this is a new ID; it could + // not yet receive messages + now, err := marshalTimestamp(netTime.Now().Add(-1 * time.Hour)) + if err != nil { + return errors.Errorf("Could not marshal new timestamp for "+ + "storage: %+v", err) + } + + return session.Set(TimestampKey, now) + } + + return nil +} + +// unmarshalTimestamp unmarshal the stored timestamp into a time.Time. +func unmarshalTimestamp(lastTimestampObj *versioned.Object) (time.Time, error) { + if lastTimestampObj == nil || lastTimestampObj.Data == nil { + return netTime.Now(), nil + } + + lastTimestamp := time.Time{} + err := lastTimestamp.UnmarshalBinary(lastTimestampObj.Data) + return lastTimestamp, err +} + +// marshalTimestamp marshals the timestamp and generates a storable object for +// ekv storage. +func marshalTimestamp(timeToStore time.Time) (*versioned.Object, error) { + data, err := timeToStore.MarshalBinary() + + return &versioned.Object{ + Version: TimestampStoreVersion, + Timestamp: netTime.Now(), + Data: data, + }, err +} + +func generateIdentitiesOverRange(lastGeneration, generateThrough time.Time, + source *id.ID, addressSize uint8 )([]receptionID.Identity, time.Time){ + protoIds, err := ephemeral.GetIdsByRange( + source, uint(addressSize), lastGeneration, generateThrough.Sub(lastGeneration)) + + jww.DEBUG.Printf("Now: %s, LastCheck: %s, Different: %s", + generateThrough, generateThrough, generateThrough.Sub(lastGeneration)) + jww.DEBUG.Printf("protoIds Count: %d", len(protoIds)) + + if err != nil { + jww.FATAL.Panicf("Could not generate upcoming IDs: %+v", err) + } + + // Generate identities off of that list + identities := make([]receptionID.Identity, len(protoIds)) + + // Add identities for every address ID + for i, eid := range protoIds { + // Expand the grace period for both start and end + identities[i] = receptionID.Identity{ + EphId: eid.Id, + Source: source, + AddressSize: addressSize, + End: eid.End, + StartValid: eid.Start.Add(-validityGracePeriod), + EndValid: eid.End.Add(validityGracePeriod), + Ephemeral: false, + ExtraChecks: interfaces.DefaultExtraChecks, + } + + } + + jww.INFO.Printf("Number of Identities Generated: %d", len(identities)) + jww.INFO.Printf("Current Identity: %d (source: %s), Start: %s, End: %s", + identities[len(identities)-1].EphId.Int64(), + identities[len(identities)-1].Source, + identities[len(identities)-1].StartValid, + identities[len(identities)-1].EndValid) + + return identities, identities[len(identities)-1].End +} + +func (tracker *Tracker)save(){ + persistant := make([]trackedID, 0, len(tracker.tracked)) + + for i := range tracker.tracked{ + if tracker.tracked[i].Persistent{ + persistant = append(persistant, tracker.tracked[i]) + } + } + + if len(persistant)==0{ + return + } + + + data, err := json.Marshal(&persistant) + if err!=nil{ + jww.FATAL.Panicf("Failed to marshal the tracked users") + } + + obj := &versioned.Object{ + Version: , + Timestamp: netTime.Now(), + Data: data, + } + + err = tracker.session.GetKV().Set(TrackerListKey, TrackerListVersion, obj) + if err!=nil{ + jww.FATAL.Panicf("Failed to store the tracked users") + } +} \ No newline at end of file diff --git a/network/ephemeral/tracker_test.go b/network/identity/tracker_test.go similarity index 93% rename from network/ephemeral/tracker_test.go rename to network/identity/tracker_test.go index 4a946a3fc..7ddddd598 100644 --- a/network/ephemeral/tracker_test.go +++ b/network/identity/tracker_test.go @@ -5,11 +5,12 @@ // LICENSE file // /////////////////////////////////////////////////////////////////////////////// -package ephemeral +package identity import ( "github.com/pkg/errors" "gitlab.com/elixxir/client/interfaces" + ephemeral2 "gitlab.com/elixxir/client/network/address" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/comms/mixmessages" @@ -27,7 +28,7 @@ import ( // Smoke test for Track function func TestCheck(t *testing.T) { session := storage.InitTestingSession(t) - instance := NewTestNetworkManager(t) + instance := ephemeral2.NewTestNetworkManager(t) if err := setupInstance(instance); err != nil { t.Errorf("Could not set up instance: %+v", err) } @@ -46,7 +47,7 @@ func TestCheck(t *testing.T) { } ourId := id.NewIdFromBytes([]byte("Sauron"), t) - stop := Track(session, NewTestAddressSpace(15, t), ourId) + stop := Track(session, ephemeral2.NewTestAddressSpace(15, t), ourId) err = stop.Close() if err != nil { @@ -58,7 +59,7 @@ func TestCheck(t *testing.T) { // Unit test for track. func TestCheck_Thread(t *testing.T) { session := storage.InitTestingSession(t) - instance := NewTestNetworkManager(t) + instance := ephemeral2.NewTestNetworkManager(t) if err := setupInstance(instance); err != nil { t.Errorf("Could not set up instance: %v", err) } @@ -80,7 +81,7 @@ func TestCheck_Thread(t *testing.T) { // Run the tracker go func() { - track(session, NewTestAddressSpace(15, t), ourId, stop) + track(session, ephemeral2.NewTestAddressSpace(15, t), ourId, stop) }() time.Sleep(3 * time.Second) diff --git a/network/manager.go b/network/manager.go index 3c8540f34..42ddc1b3a 100644 --- a/network/manager.go +++ b/network/manager.go @@ -18,9 +18,10 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/params" - "gitlab.com/elixxir/client/network/ephemeral" + "gitlab.com/elixxir/client/network/address" "gitlab.com/elixxir/client/network/gateway" "gitlab.com/elixxir/client/network/health" + "gitlab.com/elixxir/client/network/identity" "gitlab.com/elixxir/client/network/message" "gitlab.com/elixxir/client/network/nodes" "gitlab.com/elixxir/client/network/rounds" @@ -79,7 +80,7 @@ type manager struct { verboseRounds *RoundTracker // Address space size - addrSpace *ephemeral.AddressSpace + addrSpace *address.AddressSpace // Event reporting api events interfaces.EventManager @@ -104,7 +105,7 @@ func NewManager(session *storage.Session, m := manager{ param: params, tracker: &tracker, - addrSpace: ephemeral.NewAddressSpace(), + addrSpace: address.NewAddressSpace(), events: events, earliestRound: &earliest, session: session, @@ -170,7 +171,7 @@ func NewManager(session *storage.Session, // - health Tracker (/network/health) // - Garbled Messages (/network/message/inProgress.go) // - Critical Messages (/network/message/critical.go) -// - Ephemeral ID tracking (network/ephemeral/tracker.go) +// - Ephemeral ID tracking (network/address/tracker.go) func (m *manager) Follow(report interfaces.ClientErrorReport) (stoppable.Stoppable, error) { multi := stoppable.NewMulti("networkManager") @@ -196,7 +197,7 @@ func (m *manager) Follow(report interfaces.ClientErrorReport) (stoppable.Stoppab // Round processing multi.Add(m.round.StartProcessors()) - multi.Add(ephemeral.Track(m.session, m.addrSpace, m.ReceptionID)) + multi.Add(identity.Track(m.session, m.addrSpace, m.ReceptionID)) return multi, nil } diff --git a/network/message/triggers.go b/network/message/triggers.go index 2f0a8afea..7106f40ef 100644 --- a/network/message/triggers.go +++ b/network/message/triggers.go @@ -32,7 +32,7 @@ Due to the extra overhead of trial hashing, triggers are processed after fingerprints. If a fingerprint match occurs on the message, triggers will not be handled. -Triggers are ephemeral to the session. When starting a new client, all triggers +Triggers are address to the session. When starting a new client, all triggers must be re-added before StartNetworkFollower is called. */ diff --git a/network/rounds/check.go b/network/rounds/check.go index afcd20f1d..c88794697 100644 --- a/network/rounds/check.go +++ b/network/rounds/check.go @@ -10,7 +10,7 @@ package rounds import ( "encoding/binary" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/storage/reception" + "gitlab.com/elixxir/client/network/identity/receptionID" "gitlab.com/elixxir/client/storage/rounds" "gitlab.com/xx_network/primitives/id" ) @@ -53,7 +53,7 @@ func serializeRound(roundId id.Round) []byte { return b } -func (m *Manager) GetMessagesFromRound(roundID id.Round, identity reception.IdentityUse) { +func (m *Manager) GetMessagesFromRound(roundID id.Round, identity receptionID.IdentityUse) { ri, err := m.Instance.GetRound(roundID) if err != nil || m.params.ForceHistoricalRounds { if m.params.ForceHistoricalRounds { diff --git a/network/rounds/historical.go b/network/rounds/historical.go index c3b9b4b9b..756dfd917 100644 --- a/network/rounds/historical.go +++ b/network/rounds/historical.go @@ -10,8 +10,8 @@ package rounds import ( "fmt" jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/network/identity/receptionID" "gitlab.com/elixxir/client/stoppable" - "gitlab.com/elixxir/client/storage/reception" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" @@ -36,7 +36,7 @@ type historicalRoundsComms interface { //structure which contains a historical round lookup type historicalRoundRequest struct { rid id.Round - identity reception.IdentityUse + identity receptionID.IdentityUse numAttempts uint } diff --git a/network/rounds/retrieve.go b/network/rounds/retrieve.go index ce9d63fce..f5436bcde 100644 --- a/network/rounds/retrieve.go +++ b/network/rounds/retrieve.go @@ -12,9 +12,9 @@ import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/network/gateway" + "gitlab.com/elixxir/client/network/identity/receptionID" "gitlab.com/elixxir/client/network/message" "gitlab.com/elixxir/client/stoppable" - "gitlab.com/elixxir/client/storage/reception" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/crypto/shuffle" "gitlab.com/elixxir/primitives/format" @@ -31,7 +31,7 @@ type messageRetrievalComms interface { type roundLookup struct { roundInfo *pb.RoundInfo - identity reception.IdentityUse + identity receptionID.IdentityUse } const noRoundError = "does not have round %d" @@ -148,7 +148,7 @@ func (m *Manager) processMessageRetrieval(comms messageRetrievalComms, // getMessagesFromGateway attempts to get messages from their assigned // gateway host in the round specified. If successful func (m *Manager) getMessagesFromGateway(roundID id.Round, - identity reception.IdentityUse, comms messageRetrievalComms, gwIds []*id.ID, + identity receptionID.IdentityUse, comms messageRetrievalComms, gwIds []*id.ID, stop *stoppable.Single) (message.Bundle, error) { start := time.Now() // Send to the gateways using backup proxies diff --git a/network/rounds/retrieve_test.go b/network/rounds/retrieve_test.go index 856fa05fa..c6498f508 100644 --- a/network/rounds/retrieve_test.go +++ b/network/rounds/retrieve_test.go @@ -9,9 +9,9 @@ package rounds import ( "bytes" "gitlab.com/elixxir/client/network/gateway" + ephemeral2 "gitlab.com/elixxir/client/network/identity/receptionID" "gitlab.com/elixxir/client/network/message" "gitlab.com/elixxir/client/stoppable" - "gitlab.com/elixxir/client/storage/reception" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/xx_network/crypto/csprng" @@ -64,8 +64,8 @@ func TestManager_ProcessMessageRetrieval(t *testing.T) { requestGateway := id.NewIdFromString(ReturningGateway, id.Gateway, t) // Construct the round lookup - iu := reception.IdentityUse{ - Identity: reception.Identity{ + iu := ephemeral2.IdentityUse{ + Identity: ephemeral2.Identity{ EphId: expectedEphID, Source: requestGateway, }, @@ -107,13 +107,13 @@ func TestManager_ProcessMessageRetrieval(t *testing.T) { } if testBundle.Identity.EphId.Int64() != expectedEphID.Int64() { - t.Errorf("Unexpected ephemeral ID in bundle."+ + t.Errorf("Unexpected address ID in bundle."+ "\n\tExpected: %v"+ "\n\tReceived: %v", expectedEphID, testBundle.Identity.EphId) } if !bytes.Equal(expectedPayload, testBundle.Messages[0].GetPayloadA()) { - t.Errorf("Unexpected ephemeral ID in bundle."+ + t.Errorf("Unexpected address ID in bundle."+ "\n\tExpected: %v"+ "\n\tReceived: %v", expectedPayload, testBundle.Messages[0].GetPayloadA()) @@ -157,8 +157,8 @@ func TestManager_ProcessMessageRetrieval_NoRound(t *testing.T) { go func() { // Construct the round lookup - iu := reception.IdentityUse{ - Identity: reception.Identity{ + iu := ephemeral2.IdentityUse{ + Identity: ephemeral2.Identity{ EphId: expectedEphID, Source: dummyGateway, }, @@ -236,8 +236,8 @@ func TestManager_ProcessMessageRetrieval_FalsePositive(t *testing.T) { go func() { // Construct the round lookup - iu := reception.IdentityUse{ - Identity: reception.Identity{ + iu := ephemeral2.IdentityUse{ + Identity: ephemeral2.Identity{ EphId: expectedEphID, Source: id.NewIdFromString("Source", id.User, t), }, @@ -314,8 +314,8 @@ func TestManager_ProcessMessageRetrieval_Quit(t *testing.T) { go func() { // Construct the round lookup - iu := reception.IdentityUse{ - Identity: reception.Identity{ + iu := ephemeral2.IdentityUse{ + Identity: ephemeral2.Identity{ EphId: expectedEphID, }, } @@ -391,8 +391,8 @@ func TestManager_ProcessMessageRetrieval_MultipleGateways(t *testing.T) { requestGateway := id.NewIdFromString(ReturningGateway, id.Gateway, t) errorGateway := id.NewIdFromString(ErrorGateway, id.Gateway, t) // Construct the round lookup - iu := reception.IdentityUse{ - Identity: reception.Identity{ + iu := ephemeral2.IdentityUse{ + Identity: ephemeral2.Identity{ EphId: expectedEphID, Source: requestGateway, }, @@ -435,13 +435,13 @@ func TestManager_ProcessMessageRetrieval_MultipleGateways(t *testing.T) { } if testBundle.Identity.EphId.Int64() != expectedEphID.Int64() { - t.Errorf("Unexpected ephemeral ID in bundle."+ + t.Errorf("Unexpected address ID in bundle."+ "\n\tExpected: %v"+ "\n\tReceived: %v", expectedEphID, testBundle.Identity.EphId) } if !bytes.Equal(expectedPayload, testBundle.Messages[0].GetPayloadA()) { - t.Errorf("Unexpected ephemeral ID in bundle."+ + t.Errorf("Unexpected address ID in bundle."+ "\n\tExpected: %v"+ "\n\tReceived: %v", expectedPayload, testBundle.Messages[0].GetPayloadA()) diff --git a/network/rounds/unchecked.go b/network/rounds/unchecked.go index a73bf6eb2..c8ce4d000 100644 --- a/network/rounds/unchecked.go +++ b/network/rounds/unchecked.go @@ -9,8 +9,8 @@ package rounds import ( jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/network/identity/receptionID" "gitlab.com/elixxir/client/stoppable" - "gitlab.com/elixxir/client/storage/reception" "gitlab.com/elixxir/client/storage/rounds" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/netTime" @@ -65,8 +65,8 @@ func (m *Manager) processUncheckedRounds(checkInterval time.Duration, backoffTab // If we didn't find it, send to Historical Rounds Retrieval m.historicalRounds <- historicalRoundRequest{ rid: rnd.Id, - identity: reception.IdentityUse{ - Identity: reception.Identity{ + identity: receptionID.IdentityUse{ + Identity: receptionID.Identity{ EphId: rnd.EpdId, Source: rnd.Source, }, @@ -79,8 +79,8 @@ func (m *Manager) processUncheckedRounds(checkInterval time.Duration, backoffTab // Construct roundLookup object to send rl := roundLookup{ roundInfo: rnd.Info, - identity: reception.IdentityUse{ - Identity: reception.Identity{ + identity: receptionID.IdentityUse{ + Identity: receptionID.Identity{ EphId: rnd.EpdId, Source: rnd.Source, }, diff --git a/network/rounds/unchecked_test.go b/network/rounds/unchecked_test.go index 0bf7c09a6..ae865d92c 100644 --- a/network/rounds/unchecked_test.go +++ b/network/rounds/unchecked_test.go @@ -91,7 +91,7 @@ func TestUncheckedRoundScheduler(t *testing.T) { } if testBundle.Identity.EphId.Int64() != expectedEphID.Int64() { - t.Errorf("Unexpected ephemeral ID in bundle."+ + t.Errorf("Unexpected address ID in bundle."+ "\n\tExpected: %v"+ "\n\tReceived: %v", expectedEphID, testBundle.Identity.EphId) } diff --git a/network/sendCmixUtils.go b/network/sendCmixUtils.go index 6b0a59d19..cfd2e6b49 100644 --- a/network/sendCmixUtils.go +++ b/network/sendCmixUtils.go @@ -110,7 +110,7 @@ func processRound(nodes nodes.Registrar, bestRound *pb.RoundInfo, } // buildSlotMessage is a helper function which forms a slotted message to send -// to a gateway. It encrypts passed in message and generates an ephemeral ID for +// to a gateway. It encrypts passed in message and generates an address ID for // the recipient. func buildSlotMessage(msg format.Message, recipient *id.ID, target *id.ID, stream *fastRNG.Stream, senderId *id.ID, bestRound *pb.RoundInfo, @@ -118,12 +118,12 @@ func buildSlotMessage(msg format.Message, recipient *id.ID, target *id.ID, format.Message, ephemeral.Id, error) { - // Set the ephemeral ID + // Set the address ID ephID, _, _, err := ephemeral.GetId(recipient, uint(bestRound.AddressSpaceSize), int64(bestRound.Timestamps[states.QUEUED])) if err != nil { - jww.FATAL.Panicf("Failed to generate ephemeral ID when sending to %s "+ + jww.FATAL.Panicf("Failed to generate address ID when sending to %s "+ "(msgDigest: %s): %+v", err, recipient, msg.Digest()) } @@ -237,7 +237,7 @@ func messagesToDigestString(msgs []format.Message) string { return strings.Join(msgDigests, ", ") } -// ephemeralIdListToString serializes a list of ephemeral IDs into a string of +// ephemeralIdListToString serializes a list of address IDs into a string of // comma seperated integer representations. Intended for use in printing to log. func ephemeralIdListToString(idList []ephemeral.Id) string { idStrings := make([]string, len(idList)) diff --git a/single/manager.go b/single/manager.go index 9562137bb..65577dca5 100644 --- a/single/manager.go +++ b/single/manager.go @@ -12,9 +12,9 @@ import ( "gitlab.com/elixxir/client/api" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/network/identity/receptionID" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" - "gitlab.com/elixxir/client/storage/reception" "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/xx_network/primitives/id" ) @@ -33,7 +33,7 @@ type Manager struct { // Client and its field client *api.Client store *storage.Session - reception *reception.Store + reception *receptionID.Store swb interfaces.Switchboard net interfaces.NetworkManager rng *fastRNG.StreamGenerator @@ -54,7 +54,7 @@ func NewManager(client *api.Client) *Manager { return newManager(client, client.GetStorage().Reception()) } -func newManager(client *api.Client, reception *reception.Store) *Manager { +func newManager(client *api.Client, reception *receptionID.Store) *Manager { return &Manager{ client: client, store: client.GetStorage(), diff --git a/single/manager_test.go b/single/manager_test.go index ca93b42b2..7dba96cc0 100644 --- a/single/manager_test.go +++ b/single/manager_test.go @@ -15,9 +15,9 @@ import ( "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/network/gateway" + ephemeral2 "gitlab.com/elixxir/client/network/identity/receptionID" "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" - "gitlab.com/elixxir/client/storage/reception" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/client/switchboard" "gitlab.com/elixxir/comms/network" @@ -47,7 +47,7 @@ func Test_newManager(t *testing.T) { client: client, p: newPending(), } - m := newManager(client, &reception.Store{}) + m := newManager(client, &ephemeral2.Store{}) if e.client != m.client || e.store != m.store || e.net != m.net || e.rng != m.rng || !reflect.DeepEqual(e.p, m.p) { @@ -245,7 +245,7 @@ func newTestManager(timeout time.Duration, cmixErr bool, t *testing.T) *Manager return &Manager{ client: nil, store: storage.InitTestingSession(t), - reception: reception.NewStore(versioned.NewKV(make(ekv.Memstore))), + reception: ephemeral2.NewStore(versioned.NewKV(make(ekv.Memstore))), swb: switchboard.New(), net: newTestNetworkManager(timeout, cmixErr, t), rng: fastRNG.NewStreamGenerator(1, 1, csprng.NewSystemRNG), diff --git a/single/receiveResponse_test.go b/single/receiveResponse_test.go index ea75c5e3e..bed0f9053 100644 --- a/single/receiveResponse_test.go +++ b/single/receiveResponse_test.go @@ -138,7 +138,7 @@ func TestManager_processesResponse(t *testing.T) { rid := id.NewIdFromString("test RID", id.User, t) ephID, _, _, err := ephemeral.GetId(rid, id.ArrIDLen, netTime.Now().UnixNano()) if err != nil { - t.Fatalf("Failed to create ephemeral ID: %+v", err) + t.Fatalf("Failed to create address ID: %+v", err) } dhKey := getGroup().NewInt(5) maxMsgs := uint8(6) diff --git a/single/response.go b/single/response.go index 4486690e7..3a6dbfa01 100644 --- a/single/response.go +++ b/single/response.go @@ -82,7 +82,7 @@ func (m *Manager) respondSingleUse(partner Contact, payload []byte, "message part %d: %+v", j, err) } jww.DEBUG.Printf("Sending single-use response CMIX message part "+ - "%d on round %d to ephemeral ID %d.", j, round, ephID.Int64()) + "%d on round %d to address ID %d.", j, round, ephID.Int64()) rounds[j] = round roundEvents.AddRoundEventChan(round, sendResults, timeout, diff --git a/single/transmission.go b/single/transmission.go index d145aa1fb..267f04780 100644 --- a/single/transmission.go +++ b/single/transmission.go @@ -13,7 +13,7 @@ import ( jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/interfaces" "gitlab.com/elixxir/client/interfaces/params" - "gitlab.com/elixxir/client/storage/reception" + ephemeral2 "gitlab.com/elixxir/client/network/identity/receptionID" ds "gitlab.com/elixxir/comms/network/dataStructures" contact2 "gitlab.com/elixxir/crypto/contact" "gitlab.com/elixxir/crypto/cyclic" @@ -63,7 +63,7 @@ type roundEvents interface { func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, tag string, MaxMsgs uint8, rng io.Reader, callback ReplyComm, timeout time.Duration) error { - // get ephemeral ID address space size; this blocks until the address space + // get address ID address space size; this blocks until the address space // size is set for the first time addressSize := m.net.GetAddressSize() timeStart := netTime.Now() @@ -87,7 +87,7 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, } // Add identity for newly generated ID - err = m.reception.AddIdentity(reception.Identity{ + err = m.reception.AddIdentity(ephemeral2.Identity{ EphId: ephID, Source: rid, AddressSize: addressSize, @@ -139,7 +139,7 @@ func (m *Manager) transmitSingleUse(partner contact2.Contact, payload []byte, return } jww.DEBUG.Printf("Sent single-use transmission CMIX "+ - "message to %s and ephemeral ID %d on round %d.", + "message to %s and address ID %d on round %d.", partner.ID, ephID.Int64(), round) }() @@ -177,7 +177,7 @@ func (m *Manager) makeTransmitCmixMessage(partner contact2.Contact, msgPayload.SetMaxParts(maxMsgs) msgPayload.SetContents(payload) - // Generate new user ID and ephemeral ID + // Generate new user ID and address ID rid, ephID, err := makeIDs(&msgPayload, publicKey, addressSize, timeout, timeNow, rng) if err != nil { @@ -224,9 +224,9 @@ func generateDhKeys(grp *cyclic.Group, dhPubKey *cyclic.Int, return dhKey, publicKey, nil } -// makeIDs generates a new user ID and ephemeral ID with a start and end within +// makeIDs generates a new user ID and address ID with a start and end within // the given timout. The ID is generated from the unencrypted msg payload, which -// contains a nonce. If the generated ephemeral ID has a window that is not +// contains a nonce. If the generated address ID has a window that is not // within +/- the given 2*timeout from now, then the IDs are generated again // using a new nonce. func makeIDs(msg *transmitMessagePayload, publicKey *cyclic.Int, @@ -235,11 +235,11 @@ func makeIDs(msg *transmitMessagePayload, publicKey *cyclic.Int, var rid *id.ID var ephID ephemeral.Id - // Generate acceptable window for the ephemeral ID to exist in + // Generate acceptable window for the address ID to exist in windowStart, windowEnd := timeNow.Add(-2*timeout), timeNow.Add(2*timeout) start, end := timeNow, timeNow - // Loop until the ephemeral ID's start and end are within bounds + // Loop until the address ID's start and end are within bounds for windowStart.Before(start) || windowEnd.After(end) { // Generate new nonce err := msg.SetNonce(rng) @@ -251,13 +251,13 @@ func makeIDs(msg *transmitMessagePayload, publicKey *cyclic.Int, // Generate ID from unencrypted payload rid = msg.GetRID(publicKey) - // Generate the ephemeral ID + // Generate the address ID ephID, start, end, err = ephemeral.GetId(rid, uint(addressSize), timeNow.UnixNano()) if err != nil { return nil, ephemeral.Id{}, errors.Errorf("failed to generate "+ - "ephemeral ID from newly generated ID: %+v", err) + "address ID from newly generated ID: %+v", err) } - jww.DEBUG.Printf("ephemeral.GetId(%s, %d, %d) = %d", rid, addressSize, timeNow.UnixNano(), ephID.Int64()) + jww.DEBUG.Printf("address.GetId(%s, %d, %d) = %d", rid, addressSize, timeNow.UnixNano(), ephID.Int64()) } jww.INFO.Printf("generated by singe use sender reception id for single use: %s, "+ diff --git a/single/transmission_test.go b/single/transmission_test.go index 15c557e60..fbd2cf985 100644 --- a/single/transmission_test.go +++ b/single/transmission_test.go @@ -397,11 +397,11 @@ func Test_makeIDs_Consistency(t *testing.T) { expectedEphID, _, _, err := ephemeral.GetId(expectedPayload.GetRID(publicKey), uint(addressSize), timeNow.UnixNano()) if err != nil { - t.Fatalf("Failed to generate expected ephemeral ID: %+v", err) + t.Fatalf("Failed to generate expected address ID: %+v", err) } if expectedEphID != ephID { - t.Errorf("makeIDs() did not return the expected ephemeral ID."+ + t.Errorf("makeIDs() did not return the expected address ID."+ "\nexpected: %d\nreceived: %d", expectedEphID.Int64(), ephID.Int64()) } } diff --git a/storage/e2e/store_test.go b/storage/e2e/store_test.go index 8009a22a1..7a209321d 100644 --- a/storage/e2e/store_test.go +++ b/storage/e2e/store_test.go @@ -103,7 +103,7 @@ func TestStore_AddPartner(t *testing.T) { pubKey := diffieHellman.GeneratePublicKey(s.dhPrivateKey, s.grp) p := params.GetDefaultE2ESessionParams() // NOTE: e2e store doesn't contain a private SIDH key, that's - // because they're completely ephemeral as part of the + // because they're completely address as part of the // initiation of the connection. _, pubSIDHKey := genSidhKeys(rng, sidh.KeyVariantSidhA) privSIDHKey, _ := genSidhKeys(rng, sidh.KeyVariantSidhB) @@ -138,7 +138,7 @@ func TestStore_DeletePartner(t *testing.T) { pubKey := diffieHellman.GeneratePublicKey(s.dhPrivateKey, s.grp) p := params.GetDefaultE2ESessionParams() // NOTE: e2e store doesn't contain a private SIDH key, that's - // because they're completely ephemeral as part of the + // because they're completely address as part of the // initiation of the connection. _, pubSIDHKey := genSidhKeys(rng, sidh.KeyVariantSidhA) privSIDHKey, _ := genSidhKeys(rng, sidh.KeyVariantSidhB) diff --git a/storage/rounds/roundIdentity.go b/storage/rounds/roundIdentity.go index 4148ec014..04b083574 100644 --- a/storage/rounds/roundIdentity.go +++ b/storage/rounds/roundIdentity.go @@ -15,7 +15,7 @@ const roundIdentitySize = 32 type roundIdentity [roundIdentitySize]byte // newRoundIdentity generates a new unique round identifier for the round ID, -// recipient ID, and ephemeral ID. +// recipient ID, and address ID. func newRoundIdentity(rid id.Round, recipient *id.ID, ephID ephemeral.Id) roundIdentity { h, _ := hash.NewCMixHash() ridBytes := make([]byte, 8) diff --git a/storage/rounds/uncheckedRounds_test.go b/storage/rounds/uncheckedRounds_test.go index 4afecef15..7be9d4493 100644 --- a/storage/rounds/uncheckedRounds_test.go +++ b/storage/rounds/uncheckedRounds_test.go @@ -107,7 +107,7 @@ func TestLoadUncheckedStore(t *testing.T) { // Check if set values are expected if !bytes.Equal(rnd.EpdId[:], ephId[:]) || !source.Cmp(rnd.Source) { t.Fatalf("Values in loaded round %d are not expected."+ - "\nexpected ephemeral: %d\nreceived ephemeral: %d"+ + "\nexpected address: %d\nreceived address: %d"+ "\nexpected source: %s\nreceived source: %s", rid, ephId.Int64(), rnd.EpdId.Int64(), source, rnd.Source) } @@ -165,7 +165,7 @@ func TestUncheckedRoundStore_GetRound(t *testing.T) { } if !bytes.Equal(retrievedRound.EpdId[:], ephId[:]) { - t.Fatalf("Retrieved ephemeral ID for round %d does not match expected."+ + t.Fatalf("Retrieved address ID for round %d does not match expected."+ "\nexpected: %d\nreceived: %d", rid, ephId.Int64(), retrievedRound.EpdId.Int64()) } @@ -231,7 +231,7 @@ func TestUncheckedRoundStore_GetRound_TwoIDs(t *testing.T) { } if !bytes.Equal(retrievedRound.EpdId[:], ephId1[:]) { - t.Fatalf("Retrieved ephemeral ID for round %d does not match expected."+ + t.Fatalf("Retrieved address ID for round %d does not match expected."+ "\nexpected: %d\nreceived: %d", rid, ephId1.Int64(), retrievedRound.EpdId.Int64()) } @@ -247,7 +247,7 @@ func TestUncheckedRoundStore_GetRound_TwoIDs(t *testing.T) { } if !bytes.Equal(retrievedRound.EpdId[:], ephId2[:]) { - t.Fatalf("Retrieved ephemeral ID for round %d does not match expected."+ + t.Fatalf("Retrieved address ID for round %d does not match expected."+ "\nexpected: %d\nreceived: %d", rid, ephId2.Int64(), retrievedRound.EpdId.Int64()) } -- GitLab