Skip to content

Commit

Permalink
Local vote protocol in synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanArkhipov1999 committed Feb 7, 2024
1 parent 442c4f2 commit 67ef1e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
16 changes: 8 additions & 8 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<TickType>) {
// 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;
}
}
}

0 comments on commit 67ef1e1

Please sign in to comment.