Skip to content
Snippets Groups Projects
Commit a8be1ca0 authored by Josh Brooks's avatar Josh Brooks
Browse files

Add logic to verify and retry sends

parent dc690f16
No related branches found
No related tags found
2 merge requests!117Release,!76Xx 3578/send with verification
......@@ -198,6 +198,7 @@ var rootCmd = &cobra.Command{
go func(i int) {
defer wg.Done()
fmt.Printf("Sending to %s: %s\n", recipientID, msgBody)
sendLoop:
var roundIDs []id.Round
var roundTimeout time.Duration
if unsafe {
......@@ -213,6 +214,37 @@ var rootCmd = &cobra.Command{
jww.FATAL.Panicf("%+v", err)
}
retryChan := make(chan struct{})
done := make(chan struct{}, 1)
if viper.GetBool("verify-sends") { // Verify message sends were successful
// Construct the callback function which
// verifies successful message send or retries
f := func(allRoundsSucceeded, timedOut bool,
rounds map[id.Round]api.RoundResult) {
if !allRoundsSucceeded {
retryChan <- struct{}{}
} else {
done <- struct{}{}
}
}
// Monitor rounds for results
err = client.GetRoundResults(roundIDs, roundTimeout, f)
if err != nil {
jww.DEBUG.Printf("Could not verify messages were sent successfully, resending messages...")
goto sendLoop
}
select {
case <-retryChan:
// On a retry, go to the top of the loop
jww.DEBUG.Printf("Could not verify messages were sent successfully, resending messages...")
goto sendLoop
case <-done:
break
}
} else { // Does not verify successful sends
// Construct the callback function which prints out the rounds' results
f := func(allRoundsSucceeded, timedOut bool,
rounds map[id.Round]api.RoundResult) {
......@@ -228,6 +260,11 @@ var rootCmd = &cobra.Command{
if err != nil {
jww.FATAL.Panicf("Message sending for send %d failed: %+v", i, err)
}
}
close(done)
close(retryChan)
}(i)
}
}()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment