From f6ec12553e39c41496a4f94c6edc5424ff97d130 Mon Sep 17 00:00:00 2001
From: Benjamin Wenger <ben@elixxir.ioo>
Date: Tue, 23 Feb 2021 18:23:47 -0800
Subject: [PATCH] fixed UD tests and improved logging print sin historical
 rounds and critical messages

---
 network/message/critical.go | 44 ++++++++++++++++++++++++++-----------
 network/message/garbled.go  |  5 +++++
 ud/addFact.go               |  3 +--
 ud/manager.go               |  6 ++++-
 ud/remove.go                |  2 +-
 ud/remove_test.go           |  1 +
 6 files changed, 44 insertions(+), 17 deletions(-)

diff --git a/network/message/critical.go b/network/message/critical.go
index 0ba2fa1e2..800c93ef7 100644
--- a/network/message/critical.go
+++ b/network/message/critical.go
@@ -50,17 +50,19 @@ func (m *Manager) criticalMessages() {
 	//critical messages
 	for msg, param, has := critMsgs.Next(); has; msg, param, has = critMsgs.Next() {
 		go func(msg message.Send, param params.E2E) {
+			jww.INFO.Printf("Resending critical message to %s ",
+				msg.Recipient)
 			//send the message
 			rounds, _, err := m.SendE2E(msg, param)
 			//if the message fail to send, notify the buffer so it can be handled
 			//in the future and exit
 			if err != nil {
-				jww.ERROR.Printf("Failed to send critical message on "+
-					"notification of healthy network: %+v", err)
+				jww.ERROR.Printf("Failed to send critical message to %s " +
+					" on notification of healthy network: %+v", msg.Recipient,
+					err)
 				critMsgs.Failed(msg)
 				return
 			}
-			jww.INFO.Printf("critical RoundIDs: %v", rounds)
 			//wait on the results to make sure the rounds were successful
 			sendResults := make(chan ds.EventReturn, len(rounds))
 			roundEvents := m.Instance.GetRoundEvents()
@@ -70,12 +72,16 @@ func (m *Manager) criticalMessages() {
 			}
 			success, numTimeOut, numRoundFail := utility.TrackResults(sendResults, len(rounds))
 			if !success {
-				jww.ERROR.Printf("critical message send failed to transmit "+
-					"transmit %v/%v paritions: %v round failures, %v timeouts",
-					numRoundFail+numTimeOut, len(rounds), numRoundFail, numTimeOut)
+				jww.ERROR.Printf("critical message send to %s failed " +
+					"to transmit transmit %v/%v paritions on rounds %d: %v " +
+					"round failures, %v timeouts", msg.Recipient,
+					numRoundFail+numTimeOut, len(rounds), rounds, numRoundFail, numTimeOut)
 				critMsgs.Failed(msg)
 				return
 			}
+
+			jww.INFO.Printf("Sucesfull resend of critical message " +
+				"to %s on rounds %d", msg.Recipient, rounds)
 			critMsgs.Succeeded(msg)
 		}(msg, param)
 	}
@@ -86,33 +92,45 @@ func (m *Manager) criticalMessages() {
 	for msg, rid, has := critRawMsgs.Next(); has; msg, rid, has = critRawMsgs.Next() {
 		localRid := rid.DeepCopy()
 		go func(msg format.Message, rid *id.ID) {
+			jww.INFO.Printf("Resending critical raw message to %s " +
+				"(msgDigest: %s)", rid, msg.Digest())
 			//send the message
 			round, _, err := m.SendCMIX(msg, rid, param)
 			//if the message fail to send, notify the buffer so it can be handled
 			//in the future and exit
 			if err != nil {
-				jww.ERROR.Printf("Failed to send critical message on "+
+				jww.ERROR.Printf("Failed to send critical raw message on "+
 					"notification of healthy network: %+v", err)
 				critRawMsgs.Failed(msg, rid)
 				return
 			}
-			jww.INFO.Printf("critical healthy RoundIDs: %v", round)
 
-			//wait on the results to make sure the rounds were sucesfull
+			//wait on the results to make sure the rounds were successful
 			sendResults := make(chan ds.EventReturn, 1)
 			roundEvents := m.Instance.GetRoundEvents()
 
 			roundEvents.AddRoundEventChan(round, sendResults, 1*time.Minute,
 				states.COMPLETED, states.FAILED)
 
-			success, numTimeOut, numRoundFail := utility.TrackResults(sendResults, 1)
+			success, numTimeOut, _ := utility.TrackResults(sendResults, 1)
 			if !success {
-				jww.ERROR.Printf("critical message send failed to transmit "+
-					"transmit %v/%v paritions: %v round failures, %v timeouts",
-					numRoundFail+numTimeOut, 1, numRoundFail, numTimeOut)
+				if numTimeOut>0{
+					jww.ERROR.Printf("critical raw message resend to %s " +
+						"(msgDigest: %s) on round %d failed to transmit due to " +
+						"timeout", rid, msg.Digest(), round)
+				}else{
+					jww.ERROR.Printf("critical raw message resend to %s " +
+						"(msgDigest: %s) on round %d failed to transmit due to " +
+						"send failure", rid, msg.Digest(), round)
+				}
+
 				critRawMsgs.Failed(msg, rid)
 				return
 			}
+
+			jww.INFO.Printf("Sucesfull resend of critical raw message " +
+				"to %s (msgDigest: %s) on round %d", rid, msg.Digest(), round)
+
 			critRawMsgs.Succeeded(msg, rid)
 		}(msg, localRid)
 	}
diff --git a/network/message/garbled.go b/network/message/garbled.go
index 6ae13f50e..b8b10bf2b 100644
--- a/network/message/garbled.go
+++ b/network/message/garbled.go
@@ -11,6 +11,7 @@ import (
 	"gitlab.com/elixxir/client/interfaces/message"
 	"gitlab.com/elixxir/primitives/format"
 	"time"
+	jww "github.com/spf13/jwalterweatherman"
 )
 
 // Messages can arrive in the network out of order. When message handling fails
@@ -59,6 +60,10 @@ func (m *Manager) handleGarbledMessages() {
 				sender := key.GetSession().GetPartner()
 				//remove from the buffer if decryption is successful
 				garbledMsgs.Remove(grbldMsg)
+
+				jww.INFO.Printf("Garbled message decoded as E2E from " +
+					"%s, msgDigest: %s", sender, grbldMsg.Digest())
+
 				//handle the successfully decrypted message
 				xxMsg, ok := m.partitioner.HandlePartition(sender, message.E2E,
 					msg.GetContents(),
diff --git a/ud/addFact.go b/ud/addFact.go
index 41d3e8451..a32668f71 100644
--- a/ud/addFact.go
+++ b/ud/addFact.go
@@ -26,8 +26,7 @@ type addFactComms interface {
 // called along with the code to finalize the fact.
 func (m *Manager) SendRegisterFact(fact fact.Fact) (string, error) {
 	jww.INFO.Printf("ud.SendRegisterFact(%s)", fact.Stringify())
-	uid := m.storage.User().GetCryptographicIdentity().GetReceptionID()
-	return m.addFact(fact, uid, m.comms)
+	return m.addFact(fact, m.myID, m.comms)
 }
 
 func (m *Manager) addFact(inFact fact.Fact, uid *id.ID, aFC addFactComms) (string, error) {
diff --git a/ud/manager.go b/ud/manager.go
index ad7519969..08f67f821 100644
--- a/ud/manager.go
+++ b/ud/manager.go
@@ -38,9 +38,11 @@ type Manager struct {
 	privKey   *rsa.PrivateKey
 	grp       *cyclic.Group
 
-	// Internal maps
+	// internal structures
 	host   *connect.Host
 	single SingleInterface
+	myID *id.ID
+
 
 	registered *uint32
 }
@@ -94,6 +96,8 @@ func NewManager(client *api.Client, single *single.Manager) (*Manager, error) {
 			"not be constructed.")
 	}
 
+	m.myID = m.storage.User().GetCryptographicIdentity().GetReceptionID()
+
 	// Get the commonly used data from storage
 	m.privKey = m.storage.GetUser().ReceptionRSA
 
diff --git a/ud/remove.go b/ud/remove.go
index d46b8b872..44c4a03dc 100644
--- a/ud/remove.go
+++ b/ud/remove.go
@@ -35,7 +35,7 @@ func (m *Manager) removeFact(fact fact.Fact, rFC removeFactComms) error {
 
 	// Create our Fact Removal Request message data
 	remFactMsg := mixmessages.FactRemovalRequest{
-		UID:        m.storage.GetUser().GetContact().ID.Marshal(),
+		UID:         m.myID.Marshal(),
 		RemovalData: &mmFact,
 	}
 
diff --git a/ud/remove_test.go b/ud/remove_test.go
index cedc4a53c..c8c46b901 100644
--- a/ud/remove_test.go
+++ b/ud/remove_test.go
@@ -36,6 +36,7 @@ func TestRemoveFact(t *testing.T) {
 		host:    h,
 		privKey: cpk,
 		registered: &isReg,
+		myID: &id.ID{},
 	}
 
 	f := fact.Fact{
-- 
GitLab