From 67ef1e1998b2c081429cd7bcacfe12e7e5165ef1 Mon Sep 17 00:00:00 2001 From: Ivan Arkhipov Date: Wed, 7 Feb 2024 15:51:46 +0300 Subject: [PATCH] Local vote protocol in synchronization --- src/connection.rs | 2 +- src/timer.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) 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; + } } }