Skip to content
Snippets Groups Projects
Commit ac0564dc authored by benjamin's avatar benjamin
Browse files

improved code quality on the selection of the identtiy range

parent bfbe7df8
No related branches found
No related tags found
Loading
...@@ -47,6 +47,11 @@ const ( ...@@ -47,6 +47,11 @@ const (
// NetworkRetention is how long messages are // NetworkRetention is how long messages are
// retained on the network // retained on the network
NetworkRetention = 500 * time.Hour NetworkRetention = 500 * time.Hour
// GenerationDelta is how far into the past
// to go in order to ensure all relevant
// ephemeral identities are generated
GenerationDelta = time.Duration(ephemeral.Period) + (5 * time.Second)
) )
type Tracker interface { type Tracker interface {
...@@ -133,7 +138,7 @@ func (t *manager) StartProcesses() stoppable.Stoppable { ...@@ -133,7 +138,7 @@ func (t *manager) StartProcesses() stoppable.Stoppable {
// AddIdentity adds an identity to be tracked. // AddIdentity adds an identity to be tracked.
func (t *manager) AddIdentity(id *id.ID, validUntil time.Time, persistent bool) { func (t *manager) AddIdentity(id *id.ID, validUntil time.Time, persistent bool) {
lastGeneration := netTime.Now().Add(-time.Duration(ephemeral.Period)) lastGeneration := netTime.Now().Add(-GenerationDelta)
t.newIdentity <- TrackedID{ t.newIdentity <- TrackedID{
NextGeneration: netTime.Now().Add(-time.Second), NextGeneration: netTime.Now().Add(-time.Second),
LastGeneration: lastGeneration, LastGeneration: lastGeneration,
...@@ -152,8 +157,8 @@ func (t *manager) AddIdentityWithHistory(id *id.ID, validUntil, historicalBeginn ...@@ -152,8 +157,8 @@ func (t *manager) AddIdentityWithHistory(id *id.ID, validUntil, historicalBeginn
} }
if now := time.Now(); historicalBeginning.After(now) || if now := time.Now(); historicalBeginning.After(now) ||
now.Sub(historicalBeginning) < time.Duration(ephemeral.Period) { now.Sub(historicalBeginning) < GenerationDelta {
historicalBeginning = now.Add(-time.Duration(ephemeral.Period)) historicalBeginning = now.Add(-GenerationDelta)
} }
t.newIdentity <- TrackedID{ t.newIdentity <- TrackedID{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment