From b7fc54414d69118fad94ce5a174bf9b78bf77e69 Mon Sep 17 00:00:00 2001
From: "Richard T. Carback III" <rick.carback@gmail.com>
Date: Wed, 29 Jun 2022 22:16:21 +0000
Subject: [PATCH] Add debugging and comments for rekey. Add special output for
 received messages which should not be printable on the command line

---
 cmd/root.go                            | 11 +++++++++--
 e2e/processor.go                       |  2 ++
 e2e/ratchet/partner/relationship.go    |  4 ++--
 e2e/ratchet/partner/session/session.go |  9 +++++----
 e2e/receive/switchboard.go             |  6 +++++-
 e2e/rekey/confirm.go                   |  3 +++
 e2e/rekey/rekey.go                     |  2 ++
 7 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/cmd/root.go b/cmd/root.go
index 2b5fbe29d..a5612bf92 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -479,8 +479,15 @@ var rootCmd = &cobra.Command{
 				done = true
 				break
 			case m := <-recvCh:
-				fmt.Printf("Message received: %s\n", string(
-					m.Payload))
+				strToPrint := string(m.Payload)
+				if m.MessageType != catalog.XxMessage {
+					strToPrint = fmt.Sprintf("type is %s",
+						m.MessageType)
+				}
+
+				fmt.Printf("Message received: %s\n",
+					strToPrint)
+
 				// fmt.Printf("%s", m.Timestamp)
 				receiveCnt++
 				if receiveCnt == expectedCnt {
diff --git a/e2e/processor.go b/e2e/processor.go
index 1b6620149..17e229340 100644
--- a/e2e/processor.go
+++ b/e2e/processor.go
@@ -2,6 +2,7 @@ package e2e
 
 import (
 	"fmt"
+
 	"gitlab.com/elixxir/client/e2e/ratchet/partner/session"
 
 	jww "github.com/spf13/jwalterweatherman"
@@ -18,6 +19,7 @@ type processor struct {
 func (p *processor) Process(ecrMsg format.Message,
 	receptionID receptionID.EphemeralIdentity,
 	round rounds.Round) {
+	jww.TRACE.Printf("[E2E] Process(ecrMsgDigest: %s)", ecrMsg.Digest())
 	// ensure the key will be marked used before returning
 	defer p.cy.Use()
 
diff --git a/e2e/ratchet/partner/relationship.go b/e2e/ratchet/partner/relationship.go
index ff321d04b..bd6f60cce 100644
--- a/e2e/ratchet/partner/relationship.go
+++ b/e2e/ratchet/partner/relationship.go
@@ -273,8 +273,8 @@ func (r *relationship) getSessionForSending() *session.Session {
 	for _, s := range sessions {
 		status := s.Status()
 		confirmed := s.IsConfirmed()
-		jww.TRACE.Printf("[REKEY] Session Status/Confirmed: %v, %v",
-			status, confirmed)
+		jww.TRACE.Printf("[REKEY] Session Status/Confirmed: (%v, %s), %v",
+			status, s.NegotiationStatus(), confirmed)
 		if status == session.Active && confirmed {
 			//always return the first confirmed active, happy path
 			return s
diff --git a/e2e/ratchet/partner/session/session.go b/e2e/ratchet/partner/session/session.go
index 58d1ca8ac..d0ee6ca19 100644
--- a/e2e/ratchet/partner/session/session.go
+++ b/e2e/ratchet/partner/session/session.go
@@ -11,6 +11,11 @@ import (
 	"encoding/binary"
 	"encoding/json"
 	"fmt"
+	"math"
+	"math/big"
+	"sync"
+	"testing"
+
 	"github.com/cloudflare/circl/dh/sidh"
 	"github.com/pkg/errors"
 	jww "github.com/spf13/jwalterweatherman"
@@ -23,10 +28,6 @@ import (
 	"gitlab.com/xx_network/crypto/randomness"
 	"gitlab.com/xx_network/primitives/id"
 	"gitlab.com/xx_network/primitives/netTime"
-	"math"
-	"math/big"
-	"sync"
-	"testing"
 )
 
 const currentSessionVersion = 0
diff --git a/e2e/receive/switchboard.go b/e2e/receive/switchboard.go
index ad214f53a..2b2160fd5 100644
--- a/e2e/receive/switchboard.go
+++ b/e2e/receive/switchboard.go
@@ -8,11 +8,12 @@
 package receive
 
 import (
+	"sync"
+
 	"github.com/golang-collections/collections/set"
 	jww "github.com/spf13/jwalterweatherman"
 	"gitlab.com/elixxir/client/catalog"
 	"gitlab.com/xx_network/primitives/id"
-	"sync"
 )
 
 type Switchboard struct {
@@ -139,6 +140,9 @@ func (sw *Switchboard) Speak(item Message) {
 	// well as those that do not care about certain criteria
 	matches := sw.matchListeners(item)
 
+	jww.TRACE.Printf("[E2E] Switchboard.Speak(SenderID: %s, MsgType: %s)",
+		item.Sender, item.MessageType)
+
 	//Execute hear on all matched listeners in a new goroutine
 	matches.Do(func(i interface{}) {
 		r := i.(Listener)
diff --git a/e2e/rekey/confirm.go b/e2e/rekey/confirm.go
index b6ae0a6dd..449aefddb 100644
--- a/e2e/rekey/confirm.go
+++ b/e2e/rekey/confirm.go
@@ -32,6 +32,9 @@ func startConfirm(ratchet *ratchet.Ratchet, c chan receive.Message,
 }
 
 func handleConfirm(ratchet *ratchet.Ratchet, confirmation receive.Message) {
+	jww.DEBUG.Printf("[REKEY] handleConfirm(partner: %s)",
+		confirmation.Sender)
+
 	//ensure the message was encrypted properly
 	if !confirmation.Encrypted {
 		jww.ERROR.Printf(
diff --git a/e2e/rekey/rekey.go b/e2e/rekey/rekey.go
index 8de7ef2da..960df918f 100644
--- a/e2e/rekey/rekey.go
+++ b/e2e/rekey/rekey.go
@@ -96,6 +96,8 @@ func trigger(instance *commsNetwork.Instance, grp *cyclic.Group, sendE2E E2eSend
 func negotiate(instance *commsNetwork.Instance, grp *cyclic.Group, sendE2E E2eSender,
 	param Params, sess *session.Session, sendTimeout time.Duration) error {
 
+	// Note: All new sending sessions are set to "Sending" status by default
+
 	//generate public key
 	pubKey := diffieHellman.GeneratePublicKey(sess.GetMyPrivKey(), grp)
 
-- 
GitLab