aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Remote
diff options
context:
space:
mode:
authorGravatar Gil <mcg@google.com>2017-11-27 12:05:23 -0800
committerGravatar GitHub <noreply@github.com>2017-11-27 12:05:23 -0800
commit8c4cd9d5413e7f458001016e5faace2b610a69ce (patch)
tree61f1ff95d2f9b830fbcf3e32aff0472cf7f779c6 /Firestore/Source/Remote
parent782408ff5850027898ebb0f9d16cbda8272e0d32 (diff)
Change FSTExponentialBackoff to use firestore::SecureRandom directly (#492)
* Migrate FSTExponentialBackoff to Objective-C++ * Change FSTExponentialBackoff to use firestore::SecureRandom directly
Diffstat (limited to 'Firestore/Source/Remote')
-rw-r--r--Firestore/Source/Remote/FSTExponentialBackoff.mm (renamed from Firestore/Source/Remote/FSTExponentialBackoff.m)13
1 files changed, 10 insertions, 3 deletions
diff --git a/Firestore/Source/Remote/FSTExponentialBackoff.m b/Firestore/Source/Remote/FSTExponentialBackoff.mm
index 2e06238..ad27c25 100644
--- a/Firestore/Source/Remote/FSTExponentialBackoff.m
+++ b/Firestore/Source/Remote/FSTExponentialBackoff.mm
@@ -16,9 +16,12 @@
#import "Firestore/Source/Remote/FSTExponentialBackoff.h"
+#include <random>
+
+#include "Firestore/src/support/secure_random.h"
+
#import "Firestore/Source/Util/FSTDispatchQueue.h"
#import "Firestore/Source/Util/FSTLogger.h"
-#import "Firestore/Source/Util/FSTUtil.h"
@interface FSTExponentialBackoff ()
- (instancetype)initWithDispatchQueue:(FSTDispatchQueue *)dispatchQueue
@@ -33,7 +36,9 @@
@property(nonatomic) NSTimeInterval currentBase;
@end
-@implementation FSTExponentialBackoff
+@implementation FSTExponentialBackoff {
+ firestore::SecureRandom _secureRandom;
+}
- (instancetype)initWithDispatchQueue:(FSTDispatchQueue *)dispatchQueue
initialDelay:(NSTimeInterval)initialDelay
@@ -90,7 +95,9 @@
/** Returns a random value in the range [-currentBase/2, currentBase/2] */
- (NSTimeInterval)jitterDelay {
- return ([FSTUtil randomDouble] - 0.5) * _currentBase;
+ std::uniform_real_distribution<double> dist;
+ double random_double = dist(_secureRandom);
+ return (random_double - 0.5) * _currentBase;
}
@end