Skip to content

Commit

Permalink
fix timestamp warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
XAMPPRocky committed Sep 18, 2023
1 parent 225d8a8 commit 6c67939
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cli/qcmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Ping {
}
};

let recv_time = chrono::Utc::now().timestamp_nanos();
let recv_time = chrono::Utc::now().timestamp_nanos_opt().unwrap();
let reply = Protocol::parse(&buf[..size]).unwrap().unwrap();

if ping.nonce() != reply.nonce() {
Expand Down
6 changes: 3 additions & 3 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub async fn spawn(port: u16) -> crate::Result<()> {

match socket.recv_from(&mut v4_buf, &mut v6_buf).await {
Ok((size, source)) => {
let received_at = chrono::Utc::now().timestamp_nanos();
let received_at = chrono::Utc::now().timestamp_nanos_opt().unwrap();
let contents = match source {
SocketAddr::V4(_) => &v4_buf[..size],
SocketAddr::V6(_) => &v6_buf[..size],
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Protocol {
pub fn ping_with_nonce(nonce: u8) -> Self {
Self::Ping {
nonce,
client_timestamp: chrono::Utc::now().timestamp_nanos(),
client_timestamp: chrono::Utc::now().timestamp_nanos_opt().unwrap(),
}
}

Expand All @@ -145,7 +145,7 @@ impl Protocol {
nonce,
client_timestamp,
server_start_timestamp,
server_transmit_timestamp: chrono::Utc::now().timestamp_nanos(),
server_transmit_timestamp: chrono::Utc::now().timestamp_nanos_opt().unwrap(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl DownstreamReceiveWorkerConfig {
match socket.recv_from(&mut buf).await {
Ok((size, source)) => {
let packet = DownstreamPacket {
received_at: chrono::Utc::now().timestamp_nanos(),
received_at: chrono::Utc::now().timestamp_nanos_opt().unwrap(),
asn_info: crate::maxmind_db::MaxmindDb::lookup(source.ip()),
contents: buf[..size].to_vec(),
source,
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl Session {
tracing::error!(%error, %source, dest = ?endpoint, "Error receiving packet");
},
Ok((size, recv_addr)) => {
let received_at = chrono::Utc::now().timestamp_nanos();
let received_at = chrono::Utc::now().timestamp_nanos_opt().unwrap();
if let Some(last_received_at) = last_received_at {
crate::metrics::packet_jitter(crate::metrics::WRITE, asn_info).set(received_at - last_received_at);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/qcmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn ping(port: u16) {
.await
.unwrap()
.unwrap();
let recv_time = chrono::Utc::now().timestamp_nanos();
let recv_time = chrono::Utc::now().timestamp_nanos_opt().unwrap();
let reply = Protocol::parse(&buf[..size]).unwrap().unwrap();

assert_eq!(ping.nonce(), reply.nonce());
Expand Down

0 comments on commit 6c67939

Please sign in to comment.