Skip to content
Snippets Groups Projects
Commit 0f0d9270 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Add test to make sure RoundTries > 0. If it's not return an error. Clean up formatting.

parent 2fff6efa
No related branches found
No related tags found
2 merge requests!510Release,!353Figure out why bindings is not passing parameters correctly
...@@ -109,6 +109,12 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID, ...@@ -109,6 +109,12 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID,
nodes nodes.Registrar, rng *fastRNG.StreamGenerator, events event.Reporter, nodes nodes.Registrar, rng *fastRNG.StreamGenerator, events event.Reporter,
senderId *id.ID, comms SendCmixCommsInterface) (id.Round, ephemeral.Id, error) { senderId *id.ID, comms SendCmixCommsInterface) (id.Round, ephemeral.Id, error) {
if cmixParams.RoundTries == 0 {
return 0, ephemeral.Id{},
errors.Errorf("invalid parameter set, "+
"RoundTries cannot be 0: %+v", cmixParams)
}
timeStart := netTime.Now() timeStart := netTime.Now()
maxTimeout := sender.GetHostParams().SendTimeout maxTimeout := sender.GetHostParams().SendTimeout
...@@ -120,7 +126,8 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID, ...@@ -120,7 +126,8 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID,
} }
jww.INFO.Printf("[Send-%s] Looking for round to send cMix message to "+ jww.INFO.Printf("[Send-%s] Looking for round to send cMix message to "+
"%s (msgDigest: %s)", cmixParams.DebugTag, recipient, msg.Digest()) "%s (msgDigest: %s)", cmixParams.DebugTag, recipient,
msg.Digest())
stream := rng.GetStream() stream := rng.GetStream()
defer stream.Close() defer stream.Close()
...@@ -129,7 +136,8 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID, ...@@ -129,7 +136,8 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID,
// See cmix.SetGroupBits for more info. // See cmix.SetGroupBits for more info.
cmix.SetGroupBits(msg, grp, stream) cmix.SetGroupBits(msg, grp, stream)
for numRoundTries := uint(0); numRoundTries < cmixParams.RoundTries; numRoundTries++ { for numRoundTries := uint(
0); numRoundTries < cmixParams.RoundTries; numRoundTries++ {
elapsed := netTime.Since(timeStart) elapsed := netTime.Since(timeStart)
jww.TRACE.Printf("[Send-%s] try %d, elapsed: %s", jww.TRACE.Printf("[Send-%s] try %d, elapsed: %s",
cmixParams.DebugTag, numRoundTries, elapsed) cmixParams.DebugTag, numRoundTries, elapsed)
...@@ -137,42 +145,50 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID, ...@@ -137,42 +145,50 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID,
if elapsed > cmixParams.Timeout { if elapsed > cmixParams.Timeout {
jww.INFO.Printf("[Send-%s] No rounds to send to %s "+ jww.INFO.Printf("[Send-%s] No rounds to send to %s "+
"(msgDigest: %s) were found before timeout %s", "(msgDigest: %s) were found before timeout %s",
cmixParams.DebugTag, recipient, msg.Digest(), cmixParams.Timeout) cmixParams.DebugTag, recipient, msg.Digest(),
return 0, ephemeral.Id{}, errors.New("Sending cmix message timed out") cmixParams.Timeout)
return 0, ephemeral.Id{}, errors.New(
"Sending cmix message timed out")
} }
if numRoundTries > 0 { if numRoundTries > 0 {
jww.INFO.Printf("[Send-%s] Attempt %d to find round to send "+ jww.INFO.Printf("[Send-%s] Attempt %d to find round"+
"message to %s (msgDigest: %s)", cmixParams.DebugTag, " to send message to %s (msgDigest: %s)",
cmixParams.DebugTag,
numRoundTries+1, recipient, msg.Digest()) numRoundTries+1, recipient, msg.Digest())
} }
// Find the best round to send to, excluding attempted rounds // Find the best round to send to, excluding attempted rounds
remainingTime := cmixParams.Timeout - elapsed remainingTime := cmixParams.Timeout - elapsed
bestRound, err := instance.GetWaitingRounds().GetUpcomingRealtime( waitingRounds := instance.GetWaitingRounds()
bestRound, err := waitingRounds.GetUpcomingRealtime(
remainingTime, attempted, sendTimeBuffer) remainingTime, attempted, sendTimeBuffer)
if err != nil { if err != nil {
jww.WARN.Printf("[Send-%s] Failed to GetUpcomingRealtime "+ jww.WARN.Printf("[Send-%s] GetUpcomingRealtime failed "+
"(msgDigest: %s): %+v", cmixParams.DebugTag, msg.Digest(), err) "(msgDigest: %s): %+v", cmixParams.DebugTag,
msg.Digest(), err)
} }
if bestRound == nil { if bestRound == nil {
jww.WARN.Printf( jww.WARN.Printf(
"[Send-%s] Best round on send is nil", cmixParams.DebugTag) "[Send-%s] Best round on send is nil",
cmixParams.DebugTag)
continue continue
} }
jww.TRACE.Printf("[Send-%s] Best round found: %+v", jww.TRACE.Printf("[Send-%s] Best round found: %+v",
cmixParams.DebugTag, bestRound) cmixParams.DebugTag, bestRound)
// Determine whether the selected round contains any nodes that are // Determine whether the selected round contains any
// blacklisted by the CMIXParams object // nodes that are blacklisted by the CMIXParams object
containsBlacklisted := false containsBlacklisted := false
if cmixParams.BlacklistedNodes != nil { if cmixParams.BlacklistedNodes != nil {
blacklist := cmixParams.BlacklistedNodes
for _, nodeId := range bestRound.Topology { for _, nodeId := range bestRound.Topology {
var nid id.ID var nid id.ID
copy(nid[:], nodeId) copy(nid[:], nodeId)
if _, isBlacklisted := cmixParams.BlacklistedNodes[nid]; isBlacklisted { _, isBlacklisted := blacklist[nid]
if isBlacklisted {
containsBlacklisted = true containsBlacklisted = true
break break
} }
...@@ -180,8 +196,10 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID, ...@@ -180,8 +196,10 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID,
} }
if containsBlacklisted { if containsBlacklisted {
jww.WARN.Printf("[Send-%s] Round %d contains blacklisted "+ jww.WARN.Printf("[Send-%s] Round %d "+
"nodes, skipping...", cmixParams.DebugTag, bestRound.ID) "contains blacklisted nodes, skipping...",
cmixParams.DebugTag,
bestRound.ID)
continue continue
} }
...@@ -290,5 +308,5 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID, ...@@ -290,5 +308,5 @@ func sendCmixHelper(sender gateway.Sender, msg format.Message, recipient *id.ID,
} }
return 0, ephemeral.Id{}, return 0, ephemeral.Id{},
errors.New("failed to send the message, unknown error") errors.New("failed to send the message, out of round retries")
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment