From 68ee2d747d67f291cc0d959203e6eb59875d8d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Mon, 20 May 2024 11:53:00 +0200 Subject: [PATCH] Add timestamps to requests --- Cargo.lock | 1 + common/ip-packet-requests/Cargo.toml | 1 + common/ip-packet-requests/src/v7/request.rs | 24 +++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 555d3e03bb..7687b63437 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4770,6 +4770,7 @@ dependencies = [ "rand 0.8.5", "serde", "thiserror", + "time", "tokio", "tokio-util", ] diff --git a/common/ip-packet-requests/Cargo.toml b/common/ip-packet-requests/Cargo.toml index e4b1f7311a..d25578e87f 100644 --- a/common/ip-packet-requests/Cargo.toml +++ b/common/ip-packet-requests/Cargo.toml @@ -16,5 +16,6 @@ nym-sphinx = { path = "../nymsphinx" } rand = "0.8.5" serde = { workspace = true, features = ["derive"] } thiserror = { workspace = true } +time = { workspace = true } tokio = { workspace = true, features = ["time"] } tokio-util = { workspace = true, features = ["codec"] } diff --git a/common/ip-packet-requests/src/v7/request.rs b/common/ip-packet-requests/src/v7/request.rs index f10f5f507e..a73b884972 100644 --- a/common/ip-packet-requests/src/v7/request.rs +++ b/common/ip-packet-requests/src/v7/request.rs @@ -1,5 +1,6 @@ use nym_sphinx::addressing::clients::Recipient; use serde::{Deserialize, Serialize}; +use time::OffsetDateTime; use crate::{make_bincode_serializer, IpPair, CURRENT_VERSION}; @@ -35,6 +36,7 @@ impl IpPacketRequest { reply_to_hops, reply_to_avg_mix_delays, buffer_timeout, + timestamp: OffsetDateTime::now_utc(), }), signature: None, }, @@ -58,6 +60,7 @@ impl IpPacketRequest { reply_to_hops, reply_to_avg_mix_delays, buffer_timeout, + timestamp: OffsetDateTime::now_utc(), }), signature: None, }, @@ -73,6 +76,7 @@ impl IpPacketRequest { data: IpPacketRequestData::Disconnect(DisconnectRequest { request_id, reply_to, + timestamp: OffsetDateTime::now_utc(), }), signature: None, }, @@ -96,6 +100,7 @@ impl IpPacketRequest { data: IpPacketRequestData::Ping(PingRequest { request_id, reply_to, + timestamp: OffsetDateTime::now_utc(), }), signature: None, }, @@ -111,6 +116,7 @@ impl IpPacketRequest { data: IpPacketRequestData::Health(HealthRequest { request_id, reply_to, + timestamp: OffsetDateTime::now_utc(), }), signature: None, }, @@ -193,6 +199,9 @@ pub struct StaticConnectRequest { // The maximum time in milliseconds the IPR should wait when filling up a mix packet // with ip packets. pub buffer_timeout: Option, + + // Timestamp of when the request was sent by the client. + pub timestamp: OffsetDateTime, } // A dynamic connect request is when the client does not provide the internal IP address it will use @@ -215,6 +224,9 @@ pub struct DynamicConnectRequest { // The maximum time in milliseconds the IPR should wait when filling up a mix packet // with ip packets. pub buffer_timeout: Option, + + // Timestamp of when the request was sent by the client. + pub timestamp: OffsetDateTime, } // A disconnect request is when the client wants to disconnect from the ip packet router and free @@ -222,8 +234,12 @@ pub struct DynamicConnectRequest { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct DisconnectRequest { pub request_id: u64, + // The nym-address the response should be sent back to pub reply_to: Recipient, + + // Timestamp of when the request was sent by the client. + pub timestamp: OffsetDateTime, } // A data request is when the client wants to send an IP packet to a destination. @@ -236,15 +252,23 @@ pub struct DataRequest { #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct PingRequest { pub request_id: u64, + // The nym-address the response should be sent back to pub reply_to: Recipient, + + // Timestamp of when the request was sent by the client. + pub timestamp: OffsetDateTime, } #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct HealthRequest { pub request_id: u64, + // The nym-address the response should be sent back to pub reply_to: Recipient, + + // Timestamp of when the request was sent by the client. + pub timestamp: OffsetDateTime, } #[cfg(test)]