diff --git a/src/connection.rs b/src/connection.rs index 2ecc6fa..b1493f0 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -13,5 +13,5 @@ pub fn send_timer_information(_timer_information: TimerInformation) { /// Gets timer information from neighbour timers. pub fn get_timers_information() -> TimersInformation { // TODO: Some code, receiving information from other timers. It may be hardware dependent. - vec![1, 2 ,3] + vec![10, 2, 3] } \ No newline at end of file diff --git a/src/timer.rs b/src/timer.rs index 262038c..c77c9d4 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -4,8 +4,8 @@ use std::time::Duration; use crate::connection; -/// Type for tick counting. -pub type TickType = u128; +/// Type for tick counting. It is signed for synchronization. It should be u128. +pub type TickType = i128; /// The definition of the timers themselves. pub struct Timer { @@ -57,13 +57,13 @@ impl Timer { *self.tick_counter.lock().unwrap() } - #[warn(unused_mut)] /// Synchronizes tick counter by information from other timers fn synchronize(_count: &mut MutexGuard) { - // TODO: Some synchronization code - // let timers_information = connection::get_timers_information(); - // for info in timers_information { - // **_count += info; - // } + let timers_information = connection::get_timers_information(); + // Local vote protocol. + let old_count = **_count; + for info in timers_information { + **_count += (0.1 * (old_count - info).abs() as f64).round() as TickType; + } } }