diff --git a/src/main.rs b/src/main.rs index db7f76d..60a6c00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ extern crate core; mod baseliner; mod cake; -mod clock; mod config; mod endian; mod log; @@ -12,6 +11,7 @@ mod pinger_icmp; mod pinger_icmp_ts; mod ratecontroller; mod reflector_selector; +mod time; use crate::baseliner::{Baseliner, ReflectorStats}; use ::log::debug; diff --git a/src/pinger_icmp.rs b/src/pinger_icmp.rs index 80e97e4..fa4d4e2 100644 --- a/src/pinger_icmp.rs +++ b/src/pinger_icmp.rs @@ -1,7 +1,7 @@ use std::net::IpAddr; -use crate::clock::Clock; use crate::pinger::{PingError, PingListener, PingReply, PingSender}; +use crate::time::Time; use byteorder::*; use etherparse::TransportSlice::{Icmpv4, Icmpv6}; use etherparse::{IcmpEchoHeader, Icmpv4Header, Icmpv4Type, SlicedPacket}; @@ -32,7 +32,7 @@ impl PingListener for PingerICMPEchoListener { .expect("Couldn't parse payload to time") as i64; - let clock = Clock::new(ClockId::Monotonic); + let clock = Time::new(ClockId::Monotonic); let time_ms = clock.to_milliseconds() as i64; let rtt: i64 = time_ms - time_sent; @@ -62,7 +62,7 @@ impl PingListener for PingerICMPEchoListener { impl PingSender for PingerICMPEchoSender { fn craft_packet(&self, id: u16, seq: u16) -> Vec { - let clock = Clock::new(ClockId::Monotonic); + let clock = Time::new(ClockId::Monotonic); let time_ms = clock.to_milliseconds(); let payload = time_ms.to_ne_bytes(); diff --git a/src/pinger_icmp_ts.rs b/src/pinger_icmp_ts.rs index 3093a2f..7650fe6 100644 --- a/src/pinger_icmp_ts.rs +++ b/src/pinger_icmp_ts.rs @@ -1,6 +1,6 @@ -use crate::clock::Clock; use crate::endian::ToNativeEndian; use crate::pinger::{PingError, PingListener, PingReply, PingSender}; +use crate::time::Time; use etherparse::icmpv4::TimestampMessage; use etherparse::TransportSlice::{Icmpv4, Icmpv6}; use etherparse::{Icmpv4Header, Icmpv4Type, SlicedPacket}; @@ -26,7 +26,7 @@ impl PingListener for PingerICMPTimestampListener { }); } - let time_now = Clock::new(ClockId::Realtime); + let time_now = Time::new(ClockId::Realtime); let time_since_midnight = time_now.get_time_since_midnight(); let originate_timestamp = reply.originate_timestamp.to_ne(); @@ -63,7 +63,7 @@ impl PingListener for PingerICMPTimestampListener { impl PingSender for PingerICMPTimestampSender { fn craft_packet(&self, id: u16, seq: u16) -> Vec { - let time_since_midnight = Clock::new(ClockId::Realtime).get_time_since_midnight(); + let time_since_midnight = Time::new(ClockId::Realtime).get_time_since_midnight(); let payload: [u8; 0] = []; diff --git a/src/ratecontroller.rs b/src/ratecontroller.rs index 3b15878..a4d925b 100644 --- a/src/ratecontroller.rs +++ b/src/ratecontroller.rs @@ -1,5 +1,5 @@ -use crate::clock::Clock; use crate::netlink::{Netlink, NetlinkError, Qdisc}; +use crate::time::Time; use crate::{Config, ReflectorStats}; use log::{debug, error, info, warn}; use rand::seq::SliceRandom; @@ -282,7 +282,7 @@ impl Ratecontroller { ) -> anyhow::Result<()> { let sleep_time = Duration::from_secs_f64(self.config.min_change_interval); - let time = Clock::new(ClockId::Monotonic); + let time = Time::new(ClockId::Monotonic); let start_s = time.get_seconds() as f64; let (mut lastchg_s, mut lastchg_ns) = (time.get_seconds() as f64, time.get_nanoseconds() as f64); @@ -334,7 +334,7 @@ impl Ratecontroller { loop { sleep(sleep_time); - let now = Clock::new(ClockId::Monotonic); + let now = Time::new(ClockId::Monotonic); let (mut now_s, now_ns) = (now.get_seconds() as f64, now.get_nanoseconds() as f64); let now_abstime = now_s + now_ns / 1e9; now_s -= start_s; diff --git a/src/clock.rs b/src/time.rs similarity index 95% rename from src/clock.rs rename to src/time.rs index c04f600..c7e69fd 100644 --- a/src/clock.rs +++ b/src/time.rs @@ -2,12 +2,12 @@ use rustix::fs::Timespec; use rustix::thread::ClockId; use rustix::time::clock_gettime; -pub struct Clock { +pub struct Time { time_s: u64, time_ns: u64, } -impl Clock { +impl Time { pub fn new(id: ClockId) -> Self { let time: Timespec = clock_gettime(id); Self {