diff --git a/cmd/root.go b/cmd/root.go index 79c914a57f885692ff0a1952efc5673098564a3a..6638de8cf339e9575e549480098b2ce96ac4c176 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -198,73 +198,78 @@ 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 { - roundIDs, err = client.SendUnsafe(msg, - paramsUnsafe) - roundTimeout = paramsUnsafe.Timeout - } else { - roundIDs, _, _, err = client.SendE2E(msg, - paramsE2E) - roundTimeout = paramsE2E.Timeout - } - if err != nil { - 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{}{} - } + for { + // Send messages + var roundIDs []id.Round + var roundTimeout time.Duration + if unsafe { + roundIDs, err = client.SendUnsafe(msg, + paramsUnsafe) + roundTimeout = paramsUnsafe.Timeout + } else { + roundIDs, _, _, err = client.SendE2E(msg, + paramsE2E) + roundTimeout = paramsE2E.Timeout } - - // 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 + jww.FATAL.Panicf("%+v", err) } - } 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) { - printRoundResults(allRoundsSucceeded, timedOut, rounds, roundIDs, msg) - } + if viper.GetBool("verify-sends") { // Verify message sends were successful + retryChan := make(chan struct{}) + done := make(chan struct{}, 1) + + // 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{}{} + } + } - // Have the client report back the round results - err = errors.New("derp") - for j := 0; j < 5 && err != nil; j++ { + // 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...") + continue + } - if err != nil { - jww.FATAL.Panicf("Message sending for send %d failed: %+v", i, err) - } - } + select { + case <-retryChan: + // On a retry, go to the top of the loop + jww.DEBUG.Printf("Messages were not sent successfully, resending messages...") + continue + case <-done: + // Close channels on verification success + close(retryChan) + close(done) + break + } - close(done) - close(retryChan) + } 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) { + printRoundResults(allRoundsSucceeded, timedOut, rounds, roundIDs, msg) + } + + // Have the client report back the round results + err = errors.New("derp") + for j := 0; j < 5 && err != nil; j++ { + err = client.GetRoundResults(roundIDs, roundTimeout, f) + } + if err != nil { + jww.FATAL.Panicf("Message sending for send %d failed: %+v", i, err) + } + + } + + break + } }(i) } }()