|
|
@@ -136,6 +136,24 @@ pub enum BridgeTableError {
|
|
|
MissingBucket(u32),
|
|
|
}
|
|
|
|
|
|
+// Note: We do not use these constants for stats testing. Instead, we
|
|
|
+// distribute a random open invitation bucket to each user, regardless
|
|
|
+// of the number of users. This addresses the following issues:
|
|
|
+// 1. Number of users exceeds MAX_DAILY_BRIDGES
|
|
|
+// Workarounds for this issue include incrementing the date when
|
|
|
+// we're about to exceed MAX_DAILY_BRIDGES or increasing
|
|
|
+// MAX_DAILY_BRIDGES. However, see issue 3.
|
|
|
+// 2. Number of users exceeds OPENINV_K * number of bridges
|
|
|
+// A workaround for this issue is to increase OPENINV_K. However,
|
|
|
+// see issue 3.
|
|
|
+// 3. Non-uniform distribution of bridges to users
|
|
|
+// The current implementation distributes number of users /
|
|
|
+// OPENINV_K total open invitation buckets. This means that
|
|
|
+// increasing the number of bridges does not change anything. The
|
|
|
+// original Lox tests ran on a range of bridge pool sizes, so we
|
|
|
+// also want to vary this parameter and spread the users across the
|
|
|
+// increased number of bridges.
|
|
|
+
|
|
|
/// Number of times a given invitation is ditributed
|
|
|
pub const OPENINV_K: u32 = 10;
|
|
|
/// TODO: Decide on maximum daily number of invitations to be distributed
|
|
|
@@ -278,6 +296,7 @@ impl BridgeDb {
|
|
|
self.today = Utc::now();
|
|
|
self.daily_bridges_distributed = 0;
|
|
|
}
|
|
|
+ #[cfg(not(all(test, feature = "bridgeauth", feature = "test")))]
|
|
|
if self.daily_bridges_distributed < MAX_DAILY_BRIDGES {
|
|
|
if self.current_k < OPENINV_K && !self.distributed_buckets.is_empty() {
|
|
|
bucket_num = *self.distributed_buckets.last().unwrap();
|
|
|
@@ -303,6 +322,21 @@ impl BridgeDb {
|
|
|
} else {
|
|
|
Err(OpenInvitationError::ExceededMaxBridges)
|
|
|
}
|
|
|
+
|
|
|
+ // During stats testing, just choose a random open-invitation bucket.
|
|
|
+ #[cfg(all(test, feature = "bridgeauth", feature = "test"))]
|
|
|
+ {
|
|
|
+ let openinv_vec: Vec<&u32> = self.openinv_buckets.iter().collect();
|
|
|
+ bucket_num = *openinv_vec[rng.gen_range(0..openinv_vec.len())];
|
|
|
+ // Mark bucket as distributed but don't remove it from openinv_buckets
|
|
|
+ self.mark_distributed(bucket_num);
|
|
|
+ self.daily_bridges_distributed += 1;
|
|
|
+ res[32..(32 + 4)].copy_from_slice(&bucket_num.to_le_bytes());
|
|
|
+ // Sign the first 36 bytes and serialize it
|
|
|
+ let sig = self.keypair.sign(&res[0..(32 + 4)]);
|
|
|
+ res[(32 + 4)..].copy_from_slice(&sig.to_bytes());
|
|
|
+ Ok(res)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// Verify an open invitation. Returns the invitation id and the
|