From 9d36ee60b209f09fe81aafe43554644a01c34a00 Mon Sep 17 00:00:00 2001
From: jbhusson <jonah@elixxir.io>
Date: Thu, 16 Dec 2021 17:08:47 -0500
Subject: [PATCH] Implement use of excluded rounds

---
 go.mod                          | 10 +++++-----
 go.sum                          | 19 ++++++++++---------
 interfaces/params/CMIX.go       | 19 ++++++++++++-------
 network/message/sendCmix.go     |  9 +++++++++
 network/message/sendManyCmix.go |  8 ++++++++
 5 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/go.mod b/go.mod
index da05d59a1..6f9084e26 100644
--- a/go.mod
+++ b/go.mod
@@ -17,12 +17,12 @@ require (
 	github.com/spf13/jwalterweatherman v1.1.0
 	github.com/spf13/viper v1.7.1
 	gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228
-	gitlab.com/elixxir/comms v0.0.4-0.20211215181643-55748529a237
-	gitlab.com/elixxir/crypto v0.0.7-0.20211215181538-688f96f4c4c0
+	gitlab.com/elixxir/comms v0.0.4-0.20211208211635-ad88fa2850b0
+	gitlab.com/elixxir/crypto v0.0.7-0.20211208211534-e1c1462d945f
 	gitlab.com/elixxir/ekv v0.1.5
-	gitlab.com/elixxir/primitives v0.0.3-0.20211208211148-752546cf2e46
-	gitlab.com/xx_network/comms v0.0.4-0.20211215181459-0918c1141509
-	gitlab.com/xx_network/crypto v0.0.5-0.20211215175729-3c916d3c5344
+	gitlab.com/elixxir/primitives v0.0.3-0.20211216205607-021a9c8c943a
+	gitlab.com/xx_network/comms v0.0.4-0.20211202195810-9dfc0b6cdb28
+	gitlab.com/xx_network/crypto v0.0.5-0.20211014163843-57b345890686
 	gitlab.com/xx_network/primitives v0.0.4-0.20211014163031-53405cf191fb
 	golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
 	golang.org/x/net v0.0.0-20210525063256-abc453219eb5
diff --git a/go.sum b/go.sum
index fdd31f767..42586cbc2 100644
--- a/go.sum
+++ b/go.sum
@@ -253,27 +253,28 @@ github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0=
 github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228 h1:Gi6rj4mAlK0BJIk1HIzBVMjWNjIUfstrsXC2VqLYPcA=
 gitlab.com/elixxir/bloomfilter v0.0.0-20200930191214-10e9ac31b228/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
-gitlab.com/elixxir/comms v0.0.4-0.20211215181643-55748529a237 h1:kVFSZaqeX3md7W/tADOXAzejuaAqy7QLoJEJMPH1Svg=
-gitlab.com/elixxir/comms v0.0.4-0.20211215181643-55748529a237/go.mod h1:Xsq9E5RDQ15CxsblsFeGd0gcOnRIVWTIgaufRHCRTfk=
+gitlab.com/elixxir/comms v0.0.4-0.20211208211635-ad88fa2850b0 h1:Xv0xV8zID5in8IqrJT0L6/QQiFEyQRgL6ibXCZlSIRA=
+gitlab.com/elixxir/comms v0.0.4-0.20211208211635-ad88fa2850b0/go.mod h1:Q/9VctYnyN1T92Q/WhrFXYGWu819cKX33iRPvf6I63U=
 gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
 gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
-gitlab.com/elixxir/crypto v0.0.7-0.20211215181538-688f96f4c4c0 h1:WUrLqko7VYPRtxjL0o++RHFpS5Xjtlxed7qHuMu1iAo=
-gitlab.com/elixxir/crypto v0.0.7-0.20211215181538-688f96f4c4c0/go.mod h1:SQHmwjgX9taGCbzrtHGbIcZmV5iPielNP7c5wzLCUhM=
+gitlab.com/elixxir/crypto v0.0.7-0.20211208211534-e1c1462d945f h1:owzmRi0kBBWUJIZ50XB9ZmxcVJB4ZTlnh3sbKOi3HJ8=
+gitlab.com/elixxir/crypto v0.0.7-0.20211208211534-e1c1462d945f/go.mod h1:ftTGW5CHKj1QyLpF7BniMw1awB27KWKYwIV1aBrO39k=
 gitlab.com/elixxir/ekv v0.1.5 h1:R8M1PA5zRU1HVnTyrtwybdABh7gUJSCvt1JZwUSeTzk=
 gitlab.com/elixxir/ekv v0.1.5/go.mod h1:e6WPUt97taFZe5PFLPb1Dupk7tqmDCTQu1kkstqJvw4=
 gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg=
 gitlab.com/elixxir/primitives v0.0.0-20200804170709-a1896d262cd9/go.mod h1:p0VelQda72OzoUckr1O+vPW0AiFe0nyKQ6gYcmFSuF8=
 gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc=
 gitlab.com/elixxir/primitives v0.0.1/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE=
-gitlab.com/elixxir/primitives v0.0.3-0.20211208211148-752546cf2e46 h1:KL/CVczLH7VXy9snvr7WJG2YtJRoHGfL9o9pY+CKzdw=
 gitlab.com/elixxir/primitives v0.0.3-0.20211208211148-752546cf2e46/go.mod h1:zZy8AlOISFm5IG4G4sylypnz7xNBfZ5mpXiibqJT8+8=
+gitlab.com/elixxir/primitives v0.0.3-0.20211216205607-021a9c8c943a h1:joGFEIC3+kMzXkHXDAPLqg8X2HaGi2rGn3/dFrn1wEs=
+gitlab.com/elixxir/primitives v0.0.3-0.20211216205607-021a9c8c943a/go.mod h1:vIelJqbvbhJ/dRqb+1AsICGliqcFJzPiNP+TpXsKBi8=
 gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023/go.mod h1:owEcxTRl7gsoM8c3RQ5KAm5GstxrJp5tn+6JfQ4z5Hw=
-gitlab.com/xx_network/comms v0.0.4-0.20211215181459-0918c1141509 h1:1z5LpSCTUDiocy8V4Ujbtpv6o6Emw873p3TdMdFek6o=
-gitlab.com/xx_network/comms v0.0.4-0.20211215181459-0918c1141509/go.mod h1:43s+Fb0F/q7MHH83YB5tJdLPzGeu2u7Y9dKxCm5Qsu0=
+gitlab.com/xx_network/comms v0.0.4-0.20211202195810-9dfc0b6cdb28 h1:CEZJfCiV6F6GQnWiYqoEjlzL2KpLipRy/ccV2smgf0E=
+gitlab.com/xx_network/comms v0.0.4-0.20211202195810-9dfc0b6cdb28/go.mod h1:wR9Vx0KZLrIs0g2Efcp0UwFPStjcDRWkg/DJLVQI2vw=
 gitlab.com/xx_network/crypto v0.0.3/go.mod h1:DF2HYvvCw9wkBybXcXAgQMzX+MiGbFPjwt3t17VRqRE=
 gitlab.com/xx_network/crypto v0.0.4/go.mod h1:+lcQEy+Th4eswFgQDwT0EXKp4AXrlubxalwQFH5O0Mk=
-gitlab.com/xx_network/crypto v0.0.5-0.20211215175729-3c916d3c5344 h1:mkLcKpSw7WX1uXrSZoHNH6UYNWRNPBkbk3tZj2MmtFg=
-gitlab.com/xx_network/crypto v0.0.5-0.20211215175729-3c916d3c5344/go.mod h1:GeUUB5eMlu7G1u7LXpClfOyUYsSDxAhiZBf+RZeGftc=
+gitlab.com/xx_network/crypto v0.0.5-0.20211014163843-57b345890686 h1:mEjKISxi9LrguYgz6evroFwsfxH78/hYmr32yws+WV0=
+gitlab.com/xx_network/crypto v0.0.5-0.20211014163843-57b345890686/go.mod h1:GeUUB5eMlu7G1u7LXpClfOyUYsSDxAhiZBf+RZeGftc=
 gitlab.com/xx_network/primitives v0.0.0-20200803231956-9b192c57ea7c/go.mod h1:wtdCMr7DPePz9qwctNoAUzZtbOSHSedcK++3Df3psjA=
 gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da/go.mod h1:OK9xevzWCaPO7b1wiluVJGk7R5ZsuC7pHY5hteZFQug=
 gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc=
diff --git a/interfaces/params/CMIX.go b/interfaces/params/CMIX.go
index ee735d1d9..60f10ee5b 100644
--- a/interfaces/params/CMIX.go
+++ b/interfaces/params/CMIX.go
@@ -9,14 +9,17 @@ package params
 
 import (
 	"encoding/json"
+	"gitlab.com/elixxir/primitives/excludedRounds"
 	"time"
 )
 
 type CMIX struct {
 	//maximum number of rounds to try and send on
-	RoundTries uint
-	Timeout    time.Duration
-	RetryDelay time.Duration
+	RoundTries     uint
+	Timeout        time.Duration
+	RetryDelay     time.Duration
+	UseExcluded    bool
+	ExcludedRounds *excludedRounds.ExcludedRounds
 	// an alternate identity preimage to use on send. If not set, the default
 	// for the sending identity will be used
 	IdentityPreimage []byte
@@ -24,9 +27,11 @@ type CMIX struct {
 
 func GetDefaultCMIX() CMIX {
 	return CMIX{
-		RoundTries: 10,
-		Timeout:    25 * time.Second,
-		RetryDelay: 1 * time.Second,
+		RoundTries:     10,
+		Timeout:        25 * time.Second,
+		RetryDelay:     1 * time.Second,
+		UseExcluded:    false,
+		ExcludedRounds: excludedRounds.New(),
 	}
 }
 
@@ -34,7 +39,7 @@ func (c CMIX) Marshal() ([]byte, error) {
 	return json.Marshal(c)
 }
 
-// Obtain default CMIX parameters, or override with given parameters if set
+// GetCMIXParameters func obtains default CMIX parameters, or overrides with given parameters if set
 func GetCMIXParameters(params string) (CMIX, error) {
 	p := GetDefaultCMIX()
 	if len(params) > 0 {
diff --git a/network/message/sendCmix.go b/network/message/sendCmix.go
index 5847e4e15..042a35757 100644
--- a/network/message/sendCmix.go
+++ b/network/message/sendCmix.go
@@ -110,6 +110,12 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message,
 		//add the round on to the list of attempted, so it is not tried again
 		attempted.Insert(bestRound)
 
+		// TODO: does this conflict with the attempted object?
+		// Check excluded rounds for the selected best round
+		if cmixParams.UseExcluded && cmixParams.ExcludedRounds != nil && cmixParams.ExcludedRounds.Has(bestRound.GetRoundId()) {
+			continue
+		}
+
 		// Determine whether the selected round contains any Nodes
 		// that are blacklisted by the params.Network object
 		containsBlacklisted := false
@@ -180,6 +186,9 @@ func sendCmixHelper(sender *gateway.Sender, msg format.Message,
 		// Return if it sends properly
 		gwSlotResp := result.(*pb.GatewaySlotResponse)
 		if gwSlotResp.Accepted {
+			if cmixParams.UseExcluded && cmixParams.ExcludedRounds != nil {
+				cmixParams.ExcludedRounds.Insert(bestRound.ID)
+			}
 			m := fmt.Sprintf("Successfully sent to EphID %v "+
 				"(source: %s) in round %d (msgDigest: %s), "+
 				"elapsed: %s numRoundTries: %d", ephID.Int64(),
diff --git a/network/message/sendManyCmix.go b/network/message/sendManyCmix.go
index 04b833344..d37d48342 100644
--- a/network/message/sendManyCmix.go
+++ b/network/message/sendManyCmix.go
@@ -100,6 +100,11 @@ func sendManyCmixHelper(sender *gateway.Sender,
 		// tried again
 		attempted.Insert(bestRound)
 
+		// Check excluded rounds for the selected best round
+		if param.UseExcluded && param.ExcludedRounds != nil && param.ExcludedRounds.Has(bestRound.GetRoundId()) {
+			continue
+		}
+
 		// Determine whether the selected round contains any nodes that are
 		// blacklisted by the params.Network object
 		containsBlacklisted := false
@@ -199,6 +204,9 @@ func sendManyCmixHelper(sender *gateway.Sender,
 		// Return if it sends properly
 		gwSlotResp := result.(*pb.GatewaySlotResponse)
 		if gwSlotResp.Accepted {
+			if param.UseExcluded && param.ExcludedRounds != nil {
+				param.ExcludedRounds.Insert(bestRound.ID)
+			}
 			m := fmt.Sprintf("Successfully sent to EphIDs %s (sources: [%s]) "+
 				"in round %d", ephemeralIDsString, recipientString, bestRound.ID)
 			jww.INFO.Print(m)
-- 
GitLab