Fixes last open invite bucket distribution
This commit is contained in:
parent
906577f6a8
commit
420d3be4bd
|
@ -156,6 +156,7 @@ pub struct BridgeDb {
|
||||||
pub pubkey: VerifyingKey,
|
pub pubkey: VerifyingKey,
|
||||||
/// The set of open-invitation buckets
|
/// The set of open-invitation buckets
|
||||||
openinv_buckets: HashSet<u32>,
|
openinv_buckets: HashSet<u32>,
|
||||||
|
/// The set of open invitation buckets that have been distributed
|
||||||
distributed_buckets: Vec<u32>,
|
distributed_buckets: Vec<u32>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
today: DateTime<Utc>,
|
today: DateTime<Utc>,
|
||||||
|
@ -229,14 +230,14 @@ impl BridgeDb {
|
||||||
self.today = Utc::now();
|
self.today = Utc::now();
|
||||||
self.daily_bridges_distributed = 0;
|
self.daily_bridges_distributed = 0;
|
||||||
}
|
}
|
||||||
if self.openinv_buckets.is_empty() {
|
|
||||||
return Err(OpenInvitationError::NoBridgesAvailable);
|
|
||||||
}
|
|
||||||
if self.daily_bridges_distributed < MAX_DAILY_BRIDGES {
|
if self.daily_bridges_distributed < MAX_DAILY_BRIDGES {
|
||||||
if self.current_k < OPENINV_K && !self.distributed_buckets.is_empty() {
|
if self.current_k < OPENINV_K && !self.distributed_buckets.is_empty() {
|
||||||
bucket_num = *self.distributed_buckets.last().unwrap();
|
bucket_num = *self.distributed_buckets.last().unwrap();
|
||||||
self.current_k += 1;
|
self.current_k += 1;
|
||||||
} else {
|
} else {
|
||||||
|
if self.openinv_buckets.is_empty() {
|
||||||
|
return Err(OpenInvitationError::NoBridgesAvailable);
|
||||||
|
}
|
||||||
// Choose a random bucket number (from the set of open
|
// Choose a random bucket number (from the set of open
|
||||||
// invitation buckets) and serialize it
|
// invitation buckets) and serialize it
|
||||||
let openinv_vec: Vec<&u32> = self.openinv_buckets.iter().collect();
|
let openinv_vec: Vec<&u32> = self.openinv_buckets.iter().collect();
|
||||||
|
|
Loading…
Reference in New Issue