1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use lazy_static::lazy_static;
use serde::Deserialize;
use serde::Serialize;
use tofuri_core::*;
lazy_static! {
    static ref BPS: f32 = 0.5_f32 + (1_f32 / 2_f32.powf(BLOCK_TIME as f32));
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Sync {
    pub bps: f32,
    pub new: f32,
    pub completed: bool,
}
impl Sync {
    pub fn handler(&mut self) {
        self.bps += self.new;
        self.bps /= 2.0;
        self.new = 0.0;
        self.completed = !self.downloading();
    }
    pub fn downloading(&self) -> bool {
        self.bps > *BPS
    }
}