From 6dd00640173a279fd5c099bf29ae396c524adb15 Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Sun, 21 Jul 2024 22:34:02 -0700 Subject: [PATCH 1/9] wip: use dev branch in citadel protocol --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bb339b1..dbb7a60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ citadel-internal-service-macros = { path = "./citadel-internal-service-macros", # Avarok deps citadel_sdk = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } -citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } +citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol", branch = "utils-for-citadel-workspace" } citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } # Standard deps From e9bd60d8e9dfa997b056e302eb643cb600918110 Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Sun, 21 Jul 2024 22:53:28 -0700 Subject: [PATCH 2/9] fix: update other deps --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dbb7a60..befe287 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ citadel-internal-service-connector = { path = "./citadel-internal-service-connec citadel-internal-service-macros = { path = "./citadel-internal-service-macros", default-features = false, version = "0.1.0" } # Avarok deps -citadel_sdk = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } +citadel_sdk = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "utils-for-citadel-workspace" } citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol", branch = "utils-for-citadel-workspace" } -citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } +citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "utils-for-citadel-workspace" } # Standard deps serde = { version = "1.0.104", features = ["derive"] } From 4d6f489ae48bc6070d3ba10ed839d22bff03ef83 Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Sun, 21 Jul 2024 23:45:28 -0700 Subject: [PATCH 3/9] feat: `RequestId` trait for responses --- citadel-internal-service-macros/src/lib.rs | 44 +++++++++++++++++++++- citadel-internal-service-types/src/lib.rs | 8 +++- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/citadel-internal-service-macros/src/lib.rs b/citadel-internal-service-macros/src/lib.rs index 1bb4af3..c1b53f7 100644 --- a/citadel-internal-service-macros/src/lib.rs +++ b/citadel-internal-service-macros/src/lib.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, Data, DataEnum, DeriveInput, Ident}; +use syn::{parse_macro_input, Data, DataEnum, DeriveInput, Fields, Ident}; #[proc_macro_derive(IsError)] pub fn is_error_derive(input: TokenStream) -> TokenStream { @@ -66,3 +66,45 @@ fn generate_match_arms( }) .collect() } + + + +#[proc_macro_derive(RequestId)] +pub fn derive_request_id(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let name = input.ident; + + let request_id_impl = if let Data::Enum(data_enum) = &input.data { + let match_arms = data_enum.variants.iter().map(|variant| { + let variant_name = &variant.ident; + let request_id_field = if let Fields::Named(fields_named) = &variant.fields { + fields_named.named.iter().find(|field| field.ident.as_ref().unwrap() == "request_id") + } else { + None + }; + + if let Some(_) = request_id_field { + quote! { + #name::#variant_name { ref request_id, .. } => *request_id, + } + } else { + quote! {} + } + }); + + quote! { + impl RequestId for #name { + fn request_id(&self) -> u32 { + match self { + #(#match_arms)* + _ => panic!("Variant does not contain a request_id field"), + } + } + } + } + } else { + quote! {} + }; + + TokenStream::from(request_id_impl) +} \ No newline at end of file diff --git a/citadel-internal-service-types/src/lib.rs b/citadel-internal-service-types/src/lib.rs index 0d4b507..a0a9743 100644 --- a/citadel-internal-service-types/src/lib.rs +++ b/citadel-internal-service-types/src/lib.rs @@ -1,5 +1,5 @@ use bytes::BytesMut; -use citadel_internal_service_macros::{IsError, IsNotification}; +use citadel_internal_service_macros::{IsError, IsNotification, RequestId}; use citadel_sdk::prelude::PreSharedKey; pub use citadel_types::prelude::{ ConnectMode, MemberState, MessageGroupKey, ObjectTransferStatus, SecBuffer, SecurityLevel, @@ -565,7 +565,11 @@ pub struct FileTransferTickNotification { pub status: ObjectTransferStatus, } -#[derive(Serialize, Deserialize, Debug, Clone, IsError, IsNotification)] +pub trait RequestId { + fn request_id(&self) -> u32; +} + +#[derive(Serialize, Deserialize, Debug, Clone, IsError, IsNotification, RequestId)] pub enum InternalServiceResponse { ConnectSuccess(ConnectSuccess), ConnectFailure(ConnectFailure), From 16e6aaa44ffcfbfad9d1ec22dd9634117e8efd76 Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Mon, 22 Jul 2024 00:04:19 -0700 Subject: [PATCH 4/9] Revert "feat: `RequestId` trait for responses" This reverts commit 4d6f489ae48bc6070d3ba10ed839d22bff03ef83. --- citadel-internal-service-macros/src/lib.rs | 44 +--------------------- citadel-internal-service-types/src/lib.rs | 8 +--- 2 files changed, 3 insertions(+), 49 deletions(-) diff --git a/citadel-internal-service-macros/src/lib.rs b/citadel-internal-service-macros/src/lib.rs index c1b53f7..1bb4af3 100644 --- a/citadel-internal-service-macros/src/lib.rs +++ b/citadel-internal-service-macros/src/lib.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, Data, DataEnum, DeriveInput, Fields, Ident}; +use syn::{parse_macro_input, Data, DataEnum, DeriveInput, Ident}; #[proc_macro_derive(IsError)] pub fn is_error_derive(input: TokenStream) -> TokenStream { @@ -66,45 +66,3 @@ fn generate_match_arms( }) .collect() } - - - -#[proc_macro_derive(RequestId)] -pub fn derive_request_id(input: TokenStream) -> TokenStream { - let input = parse_macro_input!(input as DeriveInput); - let name = input.ident; - - let request_id_impl = if let Data::Enum(data_enum) = &input.data { - let match_arms = data_enum.variants.iter().map(|variant| { - let variant_name = &variant.ident; - let request_id_field = if let Fields::Named(fields_named) = &variant.fields { - fields_named.named.iter().find(|field| field.ident.as_ref().unwrap() == "request_id") - } else { - None - }; - - if let Some(_) = request_id_field { - quote! { - #name::#variant_name { ref request_id, .. } => *request_id, - } - } else { - quote! {} - } - }); - - quote! { - impl RequestId for #name { - fn request_id(&self) -> u32 { - match self { - #(#match_arms)* - _ => panic!("Variant does not contain a request_id field"), - } - } - } - } - } else { - quote! {} - }; - - TokenStream::from(request_id_impl) -} \ No newline at end of file diff --git a/citadel-internal-service-types/src/lib.rs b/citadel-internal-service-types/src/lib.rs index a0a9743..0d4b507 100644 --- a/citadel-internal-service-types/src/lib.rs +++ b/citadel-internal-service-types/src/lib.rs @@ -1,5 +1,5 @@ use bytes::BytesMut; -use citadel_internal_service_macros::{IsError, IsNotification, RequestId}; +use citadel_internal_service_macros::{IsError, IsNotification}; use citadel_sdk::prelude::PreSharedKey; pub use citadel_types::prelude::{ ConnectMode, MemberState, MessageGroupKey, ObjectTransferStatus, SecBuffer, SecurityLevel, @@ -565,11 +565,7 @@ pub struct FileTransferTickNotification { pub status: ObjectTransferStatus, } -pub trait RequestId { - fn request_id(&self) -> u32; -} - -#[derive(Serialize, Deserialize, Debug, Clone, IsError, IsNotification, RequestId)] +#[derive(Serialize, Deserialize, Debug, Clone, IsError, IsNotification)] pub enum InternalServiceResponse { ConnectSuccess(ConnectSuccess), ConnectFailure(ConnectFailure), From 17c42f942430a5a9425bfa79f7e0493d0bf0975e Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Mon, 22 Jul 2024 00:14:54 -0700 Subject: [PATCH 5/9] fix: better macro --- citadel-internal-service-types/src/lib.rs | 105 +++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/citadel-internal-service-types/src/lib.rs b/citadel-internal-service-types/src/lib.rs index 0d4b507..939f200 100644 --- a/citadel-internal-service-types/src/lib.rs +++ b/citadel-internal-service-types/src/lib.rs @@ -38,7 +38,9 @@ pub struct RegisterFailure { } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct ServiceConnectionAccepted; +pub struct ServiceConnectionAccepted { + pub request_id: Option, +} #[derive(Serialize, Deserialize, Debug, Clone)] pub struct MessageSendSuccess { @@ -546,6 +548,7 @@ pub struct FileTransferRequestNotification { pub cid: u64, pub peer_cid: u64, pub metadata: VirtualObjectMetadata, + pub request_id: Option, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -563,6 +566,11 @@ pub struct FileTransferTickNotification { pub cid: u64, pub peer_cid: Option, pub status: ObjectTransferStatus, + pub request_id: Option, +} + +pub trait ResponseId { + fn response_id() -> String; } #[derive(Serialize, Deserialize, Debug, Clone, IsError, IsNotification)] @@ -646,6 +654,101 @@ pub enum InternalServiceResponse { ListRegisteredPeersFailure(ListRegisteredPeersFailure), } +macro_rules! match_request_id { + ($val:expr, $($variant:ident),+) => { + match $val { + $( + InternalServiceResponse::$variant(x) => x.request_id, + )+ + } + } +} + +impl InternalServiceResponse { + pub fn request_id(&self) -> Option { + match_request_id!( + self, + ConnectSuccess, + ConnectFailure, + RegisterSuccess, + RegisterFailure, + ServiceConnectionAccepted, + MessageSendSuccess, + MessageSendFailure, + MessageNotification, + DisconnectNotification, + DisconnectFailure, + SendFileRequestSuccess, + SendFileRequestFailure, + FileTransferRequestNotification, + FileTransferStatusNotification, + FileTransferTickNotification, + DownloadFileSuccess, + DownloadFileFailure, + DeleteVirtualFileSuccess, + DeleteVirtualFileFailure, + PeerConnectSuccess, + PeerConnectFailure, + PeerConnectNotification, + PeerRegisterNotification, + PeerDisconnectSuccess, + PeerDisconnectFailure, + PeerRegisterSuccess, + PeerRegisterFailure, + GroupChannelCreateSuccess, + GroupChannelCreateFailure, + GroupBroadcastHandleFailure, + GroupCreateSuccess, + GroupCreateFailure, + GroupLeaveSuccess, + GroupLeaveFailure, + GroupLeaveNotification, + GroupEndSuccess, + GroupEndFailure, + GroupEndNotification, + GroupMessageNotification, + GroupMessageResponse, + GroupMessageSuccess, + GroupMessageFailure, + GroupInviteNotification, + GroupInviteSuccess, + GroupInviteFailure, + GroupRespondRequestSuccess, + GroupRespondRequestFailure, + GroupMembershipResponse, + GroupRequestJoinPendingNotification, + GroupDisconnectNotification, + GroupKickSuccess, + GroupKickFailure, + GroupListGroupsSuccess, + GroupListGroupsFailure, + GroupListGroupsResponse, + GroupJoinRequestNotification, + GroupRequestJoinAcceptResponse, + GroupRequestJoinDeclineResponse, + GroupRequestJoinSuccess, + GroupRequestJoinFailure, + GroupMemberStateChangeNotification, + LocalDBGetKVSuccess, + LocalDBGetKVFailure, + LocalDBSetKVSuccess, + LocalDBSetKVFailure, + LocalDBDeleteKVSuccess, + LocalDBDeleteKVFailure, + LocalDBGetAllKVSuccess, + LocalDBGetAllKVFailure, + LocalDBClearAllKVSuccess, + LocalDBClearAllKVFailure, + GetSessionsResponse, + GetAccountInformationResponse, + ListAllPeersResponse, + ListAllPeersFailure, + ListRegisteredPeersResponse, + ListRegisteredPeersFailure + ) + } +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub enum InternalServiceRequest { Connect { From 64d6065ff3b7a4c5c41ebe2ddc12a44494e22434 Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Mon, 22 Jul 2024 01:09:10 -0700 Subject: [PATCH 6/9] fix: add missing `request_id` fields --- citadel-internal-service/src/kernel/ext.rs | 4 +++- citadel-internal-service/src/kernel/mod.rs | 1 + .../src/kernel/responses/object_transfer_handle.rs | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/citadel-internal-service/src/kernel/ext.rs b/citadel-internal-service/src/kernel/ext.rs index b079cef..ecb168d 100644 --- a/citadel-internal-service/src/kernel/ext.rs +++ b/citadel-internal-service/src/kernel/ext.rs @@ -27,7 +27,9 @@ pub trait IOInterfaceExt: IOInterface { tokio::task::spawn(async move { let write_task = async move { let response = - InternalServiceResponse::ServiceConnectionAccepted(ServiceConnectionAccepted); + InternalServiceResponse::ServiceConnectionAccepted(ServiceConnectionAccepted { + request_id: None, + }); if let Err(err) = sink_send_payload::(response, &mut sink).await { error!(target: "citadel", "Failed to send to client: {err:?}"); diff --git a/citadel-internal-service/src/kernel/mod.rs b/citadel-internal-service/src/kernel/mod.rs index b0c56a4..6952faa 100644 --- a/citadel-internal-service/src/kernel/mod.rs +++ b/citadel-internal-service/src/kernel/mod.rs @@ -368,6 +368,7 @@ fn spawn_tick_updater( cid: implicated_cid, peer_cid, status: status_message, + request_id: None, }, ); match entry.send(message.clone()) { diff --git a/citadel-internal-service/src/kernel/responses/object_transfer_handle.rs b/citadel-internal-service/src/kernel/responses/object_transfer_handle.rs index 90c5b20..4c94330 100644 --- a/citadel-internal-service/src/kernel/responses/object_transfer_handle.rs +++ b/citadel-internal-service/src/kernel/responses/object_transfer_handle.rs @@ -53,6 +53,7 @@ pub async fn handle( cid: implicated_cid, peer_cid, metadata, + request_id: None, }, ); From 64ef75eb8a5a7b4c31a6010acf80e10ae68848c1 Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Fri, 2 Aug 2024 19:25:53 -0700 Subject: [PATCH 7/9] fix: rollback custom branch --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index befe287..c998f96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,9 @@ citadel-internal-service-connector = { path = "./citadel-internal-service-connec citadel-internal-service-macros = { path = "./citadel-internal-service-macros", default-features = false, version = "0.1.0" } # Avarok deps -citadel_sdk = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "utils-for-citadel-workspace" } -citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol", branch = "utils-for-citadel-workspace" } -citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "utils-for-citadel-workspace" } +citadel_sdk = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/"} +citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol"} +citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/"} # Standard deps serde = { version = "1.0.104", features = ["derive"] } From a99321a1baf07c94a1ee4f077ca08fb68960f458 Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Fri, 2 Aug 2024 19:28:24 -0700 Subject: [PATCH 8/9] fix: note on macro --- citadel-internal-service-types/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/citadel-internal-service-types/src/lib.rs b/citadel-internal-service-types/src/lib.rs index ef754af..dc173dc 100644 --- a/citadel-internal-service-types/src/lib.rs +++ b/citadel-internal-service-types/src/lib.rs @@ -661,6 +661,7 @@ pub enum InternalServiceResponse { ListRegisteredPeersFailure(ListRegisteredPeersFailure), } +/// Shortcut for getting `.request_id` attribute on all members macro_rules! match_request_id { ($val:expr, $($variant:ident),+) => { match $val { From a08957bd6ec3c9d413cd8dd307922102e5f7250c Mon Sep 17 00:00:00 2001 From: Kyle Tennison Date: Fri, 2 Aug 2024 19:34:04 -0700 Subject: [PATCH 9/9] lint toml --- Cargo.toml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c998f96..76e78d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,7 @@ members = [ "service", ] -exclude = [ - "./target/*" -] +exclude = ["./target/*"] [workspace.dependencies] @@ -22,9 +20,9 @@ citadel-internal-service-connector = { path = "./citadel-internal-service-connec citadel-internal-service-macros = { path = "./citadel-internal-service-macros", default-features = false, version = "0.1.0" } # Avarok deps -citadel_sdk = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/"} -citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol"} -citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/"} +citadel_sdk = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } +citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } +citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/" } # Standard deps serde = { version = "1.0.104", features = ["derive"] } @@ -33,13 +31,13 @@ tokio-util = { version = "0.7.8", default-features = false } bincode2 = { version = "2.0.1", default-features = false } futures = { version = "0.3.28", default-features = false } bytes = { version = "1.4.0", default-features = false } -uuid = { version="1.3.3", features = [ +uuid = { version = "1.3.3", features = [ "v4", # Lets you generate random UUIDs "fast-rng", # Use a faster (but still sufficiently random) RNG "macro-diagnostics", # Enable better diagnostics for compile-time UUIDs -]} +] } anyhow = "1.0.71" async-recursion = { version = "1.0.4" } parking_lot = { version = "0.12.1" } structopt = { version = "0.3.26" } -lazy_static = "1.4.0" \ No newline at end of file +lazy_static = "1.4.0"