From e259a7270ef036df5c95d777fc29412b6efbcdb0 Mon Sep 17 00:00:00 2001
From: josh <josh@elixxir.io>
Date: Mon, 2 May 2022 11:18:30 -0700
Subject: [PATCH] Fix spamming ignoring identity print

---
 cmix/identity/tracker.go | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/cmix/identity/tracker.go b/cmix/identity/tracker.go
index a6162ff74..fc1fb2f2c 100644
--- a/cmix/identity/tracker.go
+++ b/cmix/identity/tracker.go
@@ -180,16 +180,19 @@ func (t *manager) track(stop *stoppable.Single) {
 	for {
 		// Process new and old identities
 		nextEvent := t.processIdentities(addressSize)
-
-		// 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 ephemeral IDs early, then
-		// messages will still be picked up.
-		nextUpdate := nextEvent.Add(-validityGracePeriod)
+		waitPeriod := nextEvent.Sub(netTime.Now())
+
+		if waitPeriod > validityGracePeriod {
+			// 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 ephemeral IDs early, then
+			// messages will still be picked up.
+			waitPeriod = waitPeriod - validityGracePeriod
+		}
 
 		// Sleep until the last ID has expired
 		select {
-		case <-time.After(nextUpdate.Sub(nextUpdate)):
+		case <-time.After(waitPeriod):
 		case newIdentity := <-t.newIdentity:
 			jww.DEBUG.Printf("Receiving new identity %s :%+v",
 				newIdentity.Source, newIdentity)
@@ -240,7 +243,9 @@ func (t *manager) track(stop *stoppable.Single) {
 func (t *manager) processIdentities(addressSize uint8) time.Time {
 	edits := false
 	toRemove := make(map[int]struct{})
-	nextEvent := t.tracked[0].ValidUntil
+	// Identities are rotated on a 24-hour time period. Set the event
+	// to the latest possible time so that any sooner times will overwrite this
+	nextEvent := netTime.Now().Add(time.Duration(ephemeral.Period))
 
 	// Loop through every tracked ID and see if any operations are needed
 	for i, inQuestion := range t.tracked {
@@ -263,13 +268,15 @@ func (t *manager) processIdentities(addressSize uint8) time.Time {
 			if inQuestion.NextGeneration.Before(nextEvent) {
 				nextEvent = inQuestion.NextGeneration
 			}
-			if inQuestion.ValidUntil.Before(nextEvent) {
+			if !inQuestion.ValidUntil.IsZero() && inQuestion.ValidUntil.Before(nextEvent) {
 				nextEvent = inQuestion.ValidUntil
 			}
 		}
 
 	}
 
+	jww.DEBUG.Printf("[TrackedIDS] NextEvent: %s", nextEvent)
+
 	// Process any deletions
 	if len(toRemove) > 0 {
 		newTracked := make([]TrackedID, 0, len(t.tracked))
-- 
GitLab