gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-cashless2ecash] branch master updated: fix: last retry will be se


From: gnunet
Subject: [taler-cashless2ecash] branch master updated: fix: last retry will be set infinitely often
Date: Wed, 22 May 2024 00:08:04 +0200

This is an automated email from the git hooks/post-receive script.

joel-haeberli pushed a commit to branch master
in repository cashless2ecash.

The following commit(s) were added to refs/heads/master by this push:
     new a674251  fix: last retry will be set infinitely often
a674251 is described below

commit a6742512f6c0e20de02e7c19f94f7dde56b38d58
Author: Joel-Haeberli <haebu@rubigen.ch>
AuthorDate: Wed May 22 00:08:00 2024 +0200

    fix: last retry will be set infinitely often
---
 c2ec/exponential-backoff.go | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/c2ec/exponential-backoff.go b/c2ec/exponential-backoff.go
index 22fb28e..0ac070f 100644
--- a/c2ec/exponential-backoff.go
+++ b/c2ec/exponential-backoff.go
@@ -1,9 +1,10 @@
 package main
 
 import (
+       "crypto/rand"
        "fmt"
        "math"
-       "math/rand"
+       "math/big"
        "time"
 )
 
@@ -50,15 +51,26 @@ func randomizeBackoff(backoff int64) int64 {
 
        // it's about randomizing on millisecond base... we mustn't care about 
rounding
        threshold := 
int64(math.Floor(float64(backoff)*RANDOMIZATION_THRESHOLD_FACTOR)) + 1 // +1 to 
guarantee positive threshold
-       randomizedThreshold := rand.Int63n(threshold)
-       subtract := rand.Int31n(100) // upper boundary is exclusive (value is 
between 0 and 99)
+       randomizedThreshold, err := rand.Int(rand.Reader, 
big.NewInt(backoff+threshold))
+       if err != nil {
+               LogError("exponential-backoff", err)
+       }
+       subtract, err := rand.Int(rand.Reader, big.NewInt(100)) // upper 
boundary is exclusive (value is between 0 and 99)
+       if err != nil {
+               LogError("exponential-backoff", err)
+       }
+
+       if !randomizedThreshold.IsInt64() {
+               LogWarn("exponential-backoff", "the threshold is not int64")
+               return backoff
+       }
 
-       if subtract < 50 {
-               subtracted := backoff - randomizedThreshold
+       if subtract.Int64() < 50 {
+               subtracted := backoff - randomizedThreshold.Int64()
                if subtracted < 0 {
                        return 0
                }
                return subtracted
        }
-       return backoff + randomizedThreshold
+       return backoff + randomizedThreshold.Int64()
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]