From 70d37576f40e4408fa6b18f45bc6bdd8c7b1cb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Wed, 20 Mar 2024 10:49:24 +0100 Subject: [PATCH] Add new constructor methods to IPR request/responses (#4486) * Add function to create ping request * Add more constructor methods --- common/ip-packet-requests/src/request.rs | 28 ++++++++++++++++++++++ common/ip-packet-requests/src/response.rs | 29 +++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/common/ip-packet-requests/src/request.rs b/common/ip-packet-requests/src/request.rs index 9f59b8ba0e..3bf1cd5d98 100644 --- a/common/ip-packet-requests/src/request.rs +++ b/common/ip-packet-requests/src/request.rs @@ -83,6 +83,34 @@ impl IpPacketRequest { } } + pub fn new_ping(reply_to: Recipient) -> (Self, u64) { + let request_id = generate_random(); + ( + Self { + version: CURRENT_VERSION, + data: IpPacketRequestData::Ping(PingRequest { + request_id, + reply_to, + }), + }, + request_id, + ) + } + + pub fn new_health_request(reply_to: Recipient) -> (Self, u64) { + let request_id = generate_random(); + ( + Self { + version: CURRENT_VERSION, + data: IpPacketRequestData::Health(HealthRequest { + request_id, + reply_to, + }), + }, + request_id, + ) + } + pub fn id(&self) -> Option { match &self.data { IpPacketRequestData::StaticConnect(request) => Some(request.request_id), diff --git a/common/ip-packet-requests/src/response.rs b/common/ip-packet-requests/src/response.rs index d2baf16f6e..c788a8974e 100644 --- a/common/ip-packet-requests/src/response.rs +++ b/common/ip-packet-requests/src/response.rs @@ -144,6 +144,35 @@ impl IpPacketResponse { } } + pub fn new_pong(request_id: u64, reply_to: Recipient) -> Self { + Self { + version: CURRENT_VERSION, + data: IpPacketResponseData::Pong(PongResponse { + request_id, + reply_to, + }), + } + } + + pub fn new_health_response( + request_id: u64, + reply_to: Recipient, + build_info: nym_bin_common::build_information::BinaryBuildInformationOwned, + routable: Option, + ) -> Self { + Self { + version: CURRENT_VERSION, + data: IpPacketResponseData::Health(HealthResponse { + request_id, + reply_to, + reply: HealthResponseReply { + build_info, + routable, + }, + }), + } + } + pub fn id(&self) -> Option { match &self.data { IpPacketResponseData::StaticConnect(response) => Some(response.request_id),