diff --git a/Cargo.toml b/Cargo.toml index bb339b1..76e78d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,7 @@ members = [ "service", ] -exclude = [ - "./target/*" -] +exclude = ["./target/*"] [workspace.dependencies] @@ -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" diff --git a/citadel-internal-service-types/src/lib.rs b/citadel-internal-service-types/src/lib.rs index a9a0446..dc173dc 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 { @@ -553,6 +555,7 @@ pub struct FileTransferRequestNotification { pub cid: u64, pub peer_cid: u64, pub metadata: VirtualObjectMetadata, + pub request_id: Option, } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -570,6 +573,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)] @@ -653,6 +661,102 @@ 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 { + $( + 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 { 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, }, );