Rename 'clock' to 'time'
This commit is contained in:
1 parent
befccc0d6f
commit
13ba3eaffe
5 files changed
+12
-12
No files matched your search
+1
-1
@@ -2,7 +2,6 @@ extern crate core;
|
|||||||
|
|
||||||
mod baseliner;
|
mod baseliner;
|
||||||
mod cake;
|
mod cake;
|
||||||
mod clock;
|
|
||||||
mod config;
|
mod config;
|
||||||
mod endian;
|
mod endian;
|
||||||
mod log;
|
mod log;
|
||||||
@@ -12,6 +11,7 @@ mod pinger_icmp;
|
|||||||
mod pinger_icmp_ts;
|
mod pinger_icmp_ts;
|
||||||
mod ratecontroller;
|
mod ratecontroller;
|
||||||
mod reflector_selector;
|
mod reflector_selector;
|
||||||
|
mod time;
|
||||||
|
|
||||||
use crate::baseliner::{Baseliner, ReflectorStats};
|
use crate::baseliner::{Baseliner, ReflectorStats};
|
||||||
use ::log::debug;
|
use ::log::debug;
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
use crate::clock::Clock;
|
|
||||||
use crate::pinger::{PingError, PingListener, PingReply, PingSender};
|
use crate::pinger::{PingError, PingListener, PingReply, PingSender};
|
||||||
|
use crate::time::Time;
|
||||||
use byteorder::*;
|
use byteorder::*;
|
||||||
use etherparse::TransportSlice::{Icmpv4, Icmpv6};
|
use etherparse::TransportSlice::{Icmpv4, Icmpv6};
|
||||||
use etherparse::{IcmpEchoHeader, Icmpv4Header, Icmpv4Type, SlicedPacket};
|
use etherparse::{IcmpEchoHeader, Icmpv4Header, Icmpv4Type, SlicedPacket};
|
||||||
@@ -32,7 +32,7 @@ impl PingListener for PingerICMPEchoListener {
|
|||||||
.expect("Couldn't parse payload to time")
|
.expect("Couldn't parse payload to time")
|
||||||
as i64;
|
as i64;
|
||||||
|
|
||||||
let clock = Clock::new(ClockId::Monotonic);
|
let clock = Time::new(ClockId::Monotonic);
|
||||||
let time_ms = clock.to_milliseconds() as i64;
|
let time_ms = clock.to_milliseconds() as i64;
|
||||||
|
|
||||||
let rtt: i64 = time_ms - time_sent;
|
let rtt: i64 = time_ms - time_sent;
|
||||||
@@ -62,7 +62,7 @@ impl PingListener for PingerICMPEchoListener {
|
|||||||
|
|
||||||
impl PingSender for PingerICMPEchoSender {
|
impl PingSender for PingerICMPEchoSender {
|
||||||
fn craft_packet(&self, id: u16, seq: u16) -> Vec<u8> {
|
fn craft_packet(&self, id: u16, seq: u16) -> Vec<u8> {
|
||||||
let clock = Clock::new(ClockId::Monotonic);
|
let clock = Time::new(ClockId::Monotonic);
|
||||||
let time_ms = clock.to_milliseconds();
|
let time_ms = clock.to_milliseconds();
|
||||||
let payload = time_ms.to_ne_bytes();
|
let payload = time_ms.to_ne_bytes();
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use crate::clock::Clock;
|
|
||||||
use crate::endian::ToNativeEndian;
|
use crate::endian::ToNativeEndian;
|
||||||
use crate::pinger::{PingError, PingListener, PingReply, PingSender};
|
use crate::pinger::{PingError, PingListener, PingReply, PingSender};
|
||||||
|
use crate::time::Time;
|
||||||
use etherparse::icmpv4::TimestampMessage;
|
use etherparse::icmpv4::TimestampMessage;
|
||||||
use etherparse::TransportSlice::{Icmpv4, Icmpv6};
|
use etherparse::TransportSlice::{Icmpv4, Icmpv6};
|
||||||
use etherparse::{Icmpv4Header, Icmpv4Type, SlicedPacket};
|
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 time_since_midnight = time_now.get_time_since_midnight();
|
||||||
|
|
||||||
let originate_timestamp = reply.originate_timestamp.to_ne();
|
let originate_timestamp = reply.originate_timestamp.to_ne();
|
||||||
@@ -63,7 +63,7 @@ impl PingListener for PingerICMPTimestampListener {
|
|||||||
|
|
||||||
impl PingSender for PingerICMPTimestampSender {
|
impl PingSender for PingerICMPTimestampSender {
|
||||||
fn craft_packet(&self, id: u16, seq: u16) -> Vec<u8> {
|
fn craft_packet(&self, id: u16, seq: u16) -> Vec<u8> {
|
||||||
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] = [];
|
let payload: [u8; 0] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::clock::Clock;
|
|
||||||
use crate::netlink::{Netlink, NetlinkError, Qdisc};
|
use crate::netlink::{Netlink, NetlinkError, Qdisc};
|
||||||
|
use crate::time::Time;
|
||||||
use crate::{Config, ReflectorStats};
|
use crate::{Config, ReflectorStats};
|
||||||
use log::{debug, error, info, warn};
|
use log::{debug, error, info, warn};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
@@ -282,7 +282,7 @@ impl Ratecontroller {
|
|||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let sleep_time = Duration::from_secs_f64(self.config.min_change_interval);
|
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 start_s = time.get_seconds() as f64;
|
||||||
let (mut lastchg_s, mut lastchg_ns) =
|
let (mut lastchg_s, mut lastchg_ns) =
|
||||||
(time.get_seconds() as f64, time.get_nanoseconds() as f64);
|
(time.get_seconds() as f64, time.get_nanoseconds() as f64);
|
||||||
@@ -334,7 +334,7 @@ impl Ratecontroller {
|
|||||||
loop {
|
loop {
|
||||||
sleep(sleep_time);
|
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 (mut now_s, now_ns) = (now.get_seconds() as f64, now.get_nanoseconds() as f64);
|
||||||
let now_abstime = now_s + now_ns / 1e9;
|
let now_abstime = now_s + now_ns / 1e9;
|
||||||
now_s -= start_s;
|
now_s -= start_s;
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ use rustix::fs::Timespec;
|
|||||||
use rustix::thread::ClockId;
|
use rustix::thread::ClockId;
|
||||||
use rustix::time::clock_gettime;
|
use rustix::time::clock_gettime;
|
||||||
|
|
||||||
pub struct Clock {
|
pub struct Time {
|
||||||
time_s: u64,
|
time_s: u64,
|
||||||
time_ns: u64,
|
time_ns: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clock {
|
impl Time {
|
||||||
pub fn new(id: ClockId) -> Self {
|
pub fn new(id: ClockId) -> Self {
|
||||||
let time: Timespec = clock_gettime(id);
|
let time: Timespec = clock_gettime(id);
|
||||||
Self {
|
Self {
|
||||||
Reference in new issue
Block a user