From fb64f67146f5236b3b25752dcc9fcf7ef2dc1be2 Mon Sep 17 00:00:00 2001 From: Tjemmmic Date: Wed, 19 Jun 2024 23:47:39 -0500 Subject: [PATCH 1/3] List peers includes name --- Cargo.toml | 6 +-- citadel-internal-service-types/src/lib.rs | 13 ++++-- .../src/kernel/requests/peer/list_all.rs | 13 +++--- .../kernel/requests/peer/list_registered.rs | 42 ++++++------------- citadel-internal-service/tests/service.rs | 8 ++-- 5 files changed, 37 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bb339b1..a06b690 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_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/", branch = "donovan/peer-info" } +citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "donovan/peer-info" } +citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "donovan/peer-info" } # Standard deps serde = { version = "1.0.104", features = ["derive"] } diff --git a/citadel-internal-service-types/src/lib.rs b/citadel-internal-service-types/src/lib.rs index 0d4b507..a9a0446 100644 --- a/citadel-internal-service-types/src/lib.rs +++ b/citadel-internal-service-types/src/lib.rs @@ -498,10 +498,18 @@ pub struct LocalDBClearAllKVSuccess { pub request_id: Option, } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct PeerInformation { + pub cid: u64, + pub online_status: bool, + pub name: Option, + pub username: Option, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ListAllPeersResponse { pub cid: u64, - pub online_status: HashMap, + pub peer_information: HashMap, pub request_id: Option, } @@ -522,8 +530,7 @@ pub struct ListRegisteredPeersFailure { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ListRegisteredPeersResponse { pub cid: u64, - pub peers: HashMap, - pub online_status: HashMap, + pub peers: HashMap, pub request_id: Option, } diff --git a/citadel-internal-service/src/kernel/requests/peer/list_all.rs b/citadel-internal-service/src/kernel/requests/peer/list_all.rs index 685df84..ce070e2 100644 --- a/citadel-internal-service/src/kernel/requests/peer/list_all.rs +++ b/citadel-internal-service/src/kernel/requests/peer/list_all.rs @@ -1,9 +1,7 @@ use crate::kernel::requests::HandledRequestResult; use crate::kernel::CitadelWorkspaceService; use citadel_internal_service_connector::io_interface::IOInterface; -use citadel_internal_service_types::{ - InternalServiceRequest, InternalServiceResponse, ListAllPeersFailure, ListAllPeersResponse, -}; +use citadel_internal_service_types::{InternalServiceRequest, InternalServiceResponse, ListAllPeersFailure, ListAllPeersResponse, PeerInformation}; use citadel_sdk::prelude::ProtocolRemoteExt; use uuid::Uuid; @@ -21,10 +19,15 @@ pub async fn handle( Ok(peers) => { let peers = ListAllPeersResponse { cid, - online_status: peers + peer_information: peers .into_iter() .filter(|peer| peer.cid != cid) - .map(|peer| (peer.cid, peer.is_online)) + .map(|peer| (peer.cid, PeerInformation { + cid: peer.cid, + online_status: peer.is_online, + name: peer.full_name, + username: peer.username, + })) .collect(), request_id: Some(request_id), }; diff --git a/citadel-internal-service/src/kernel/requests/peer/list_registered.rs b/citadel-internal-service/src/kernel/requests/peer/list_registered.rs index 064b0c7..92f2b52 100644 --- a/citadel-internal-service/src/kernel/requests/peer/list_registered.rs +++ b/citadel-internal-service/src/kernel/requests/peer/list_registered.rs @@ -1,12 +1,8 @@ use crate::kernel::requests::HandledRequestResult; use crate::kernel::CitadelWorkspaceService; use citadel_internal_service_connector::io_interface::IOInterface; -use citadel_internal_service_types::{ - InternalServiceRequest, InternalServiceResponse, ListRegisteredPeersFailure, - ListRegisteredPeersResponse, PeerSessionInformation, -}; -use citadel_sdk::prelude::{ProtocolRemoteExt, TargetLockedRemote}; -use std::collections::HashMap; +use citadel_internal_service_types::{InternalServiceRequest, InternalServiceResponse, ListRegisteredPeersFailure, ListRegisteredPeersResponse, PeerInformation}; +use citadel_sdk::prelude::ProtocolRemoteExt; use uuid::Uuid; pub async fn handle( @@ -21,32 +17,18 @@ pub async fn handle( match remote.get_local_group_mutual_peers(cid).await { Ok(peers) => { - let mut accounts = HashMap::new(); - for peer in &peers { - // TOOD: Do not unwrap below - let peer_username = remote - .find_target(cid, peer.cid) - .await - .unwrap() - .target_username() - .cloned() - .unwrap_or_default(); - accounts.insert( - peer.cid, - PeerSessionInformation { - cid, - peer_cid: peer.cid, - peer_username, - }, - ); - } - let peers = ListRegisteredPeersResponse { cid, - peers: accounts, - online_status: peers - .iter() - .map(|peer| (peer.cid, peer.is_online)) + peers: peers + .clone() + .into_iter() + .filter(|peer| peer.cid != cid) + .map(|peer| (peer.cid, PeerInformation { + cid, + online_status: peer.is_online, + name: peer.full_name, + username: peer.username, + })) .collect(), request_id: Some(request_id), }; diff --git a/citadel-internal-service/tests/service.rs b/citadel-internal-service/tests/service.rs index cc80edf..87d04ad 100644 --- a/citadel-internal-service/tests/service.rs +++ b/citadel-internal-service/tests/service.rs @@ -502,8 +502,8 @@ mod tests { let resp = from_service.recv().await.unwrap(); if let InternalServiceResponse::ListAllPeersResponse(list) = resp { - assert_eq!(list.online_status.len(), 1); - assert!(list.online_status.contains_key(&peer_cid)) + assert_eq!(list.peer_information.len(), 1); + assert!(list.peer_information.contains_key(&peer_cid)) } else { panic!("Invalid ListAllPeers response") } @@ -517,8 +517,8 @@ mod tests { let resp = from_service.recv().await.unwrap(); if let InternalServiceResponse::ListRegisteredPeersResponse(list) = resp { - assert_eq!(list.online_status.len(), 1); - assert!(list.online_status.contains_key(&peer_cid)) + assert_eq!(list.peers.len(), 1); + assert!(list.peers.contains_key(&peer_cid)) } else { panic!("Invalid ListAllPeers response") } From b8601fe431ccc9c9ff1362547bb6281a042fb31b Mon Sep 17 00:00:00 2001 From: Tjemmmic Date: Tue, 25 Jun 2024 10:04:57 -0500 Subject: [PATCH 2/3] clippy and fmt --- .../src/kernel/requests/mod.rs | 7 ++++-- .../src/kernel/requests/peer/list_all.rs | 22 +++++++++++++------ .../kernel/requests/peer/list_registered.rs | 22 +++++++++++++------ citadel-internal-service/tests/common/mod.rs | 6 ++--- 4 files changed, 38 insertions(+), 19 deletions(-) diff --git a/citadel-internal-service/src/kernel/requests/mod.rs b/citadel-internal-service/src/kernel/requests/mod.rs index 806713b..cd72fda 100644 --- a/citadel-internal-service/src/kernel/requests/mod.rs +++ b/citadel-internal-service/src/kernel/requests/mod.rs @@ -31,11 +31,14 @@ mod local_db; mod peer; #[async_recursion] -pub async fn handle_request( +pub async fn handle_request( this: &CitadelWorkspaceService, uuid: Uuid, command: InternalServiceRequest, -) -> Option { +) -> Option +where + T: IOInterface, +{ match &command { InternalServiceRequest::GetAccountInformation { .. } => { return get_account_information::handle(this, uuid, command).await diff --git a/citadel-internal-service/src/kernel/requests/peer/list_all.rs b/citadel-internal-service/src/kernel/requests/peer/list_all.rs index ce070e2..a843350 100644 --- a/citadel-internal-service/src/kernel/requests/peer/list_all.rs +++ b/citadel-internal-service/src/kernel/requests/peer/list_all.rs @@ -1,7 +1,10 @@ use crate::kernel::requests::HandledRequestResult; use crate::kernel::CitadelWorkspaceService; use citadel_internal_service_connector::io_interface::IOInterface; -use citadel_internal_service_types::{InternalServiceRequest, InternalServiceResponse, ListAllPeersFailure, ListAllPeersResponse, PeerInformation}; +use citadel_internal_service_types::{ + InternalServiceRequest, InternalServiceResponse, ListAllPeersFailure, ListAllPeersResponse, + PeerInformation, +}; use citadel_sdk::prelude::ProtocolRemoteExt; use uuid::Uuid; @@ -22,12 +25,17 @@ pub async fn handle( peer_information: peers .into_iter() .filter(|peer| peer.cid != cid) - .map(|peer| (peer.cid, PeerInformation { - cid: peer.cid, - online_status: peer.is_online, - name: peer.full_name, - username: peer.username, - })) + .map(|peer| { + ( + peer.cid, + PeerInformation { + cid: peer.cid, + online_status: peer.is_online, + name: peer.full_name, + username: peer.username, + }, + ) + }) .collect(), request_id: Some(request_id), }; diff --git a/citadel-internal-service/src/kernel/requests/peer/list_registered.rs b/citadel-internal-service/src/kernel/requests/peer/list_registered.rs index 92f2b52..b9cc0cd 100644 --- a/citadel-internal-service/src/kernel/requests/peer/list_registered.rs +++ b/citadel-internal-service/src/kernel/requests/peer/list_registered.rs @@ -1,7 +1,10 @@ use crate::kernel::requests::HandledRequestResult; use crate::kernel::CitadelWorkspaceService; use citadel_internal_service_connector::io_interface::IOInterface; -use citadel_internal_service_types::{InternalServiceRequest, InternalServiceResponse, ListRegisteredPeersFailure, ListRegisteredPeersResponse, PeerInformation}; +use citadel_internal_service_types::{ + InternalServiceRequest, InternalServiceResponse, ListRegisteredPeersFailure, + ListRegisteredPeersResponse, PeerInformation, +}; use citadel_sdk::prelude::ProtocolRemoteExt; use uuid::Uuid; @@ -23,12 +26,17 @@ pub async fn handle( .clone() .into_iter() .filter(|peer| peer.cid != cid) - .map(|peer| (peer.cid, PeerInformation { - cid, - online_status: peer.is_online, - name: peer.full_name, - username: peer.username, - })) + .map(|peer| { + ( + peer.cid, + PeerInformation { + cid, + online_status: peer.is_online, + name: peer.full_name, + username: peer.username, + }, + ) + }) .collect(), request_id: Some(request_id), }; diff --git a/citadel-internal-service/tests/common/mod.rs b/citadel-internal-service/tests/common/mod.rs index 10c1a12..1239833 100644 --- a/citadel-internal-service/tests/common/mod.rs +++ b/citadel-internal-service/tests/common/mod.rs @@ -517,13 +517,13 @@ pub fn server_info_skip_cert_verification_with_password<'a>( server_test_node_skip_cert_verification_with_password(EmptyKernel, server_password, |_| {}) } -pub fn server_info_reactive_skip_cert_verification<'a, F: 'a, Fut: 'a>( +pub fn server_info_reactive_skip_cert_verification<'a, F, Fut>( f: F, opts: impl FnOnce(&mut NodeBuilder), ) -> (NodeFuture<'a, Box>, SocketAddr) where - F: Fn(ConnectionSuccess, ClientServerRemote) -> Fut + Send + Sync, - Fut: Future> + Send + Sync, + F: Fn(ConnectionSuccess, ClientServerRemote) -> Fut + Send + Sync + 'a, + Fut: Future> + Send + Sync + 'a, { server_test_node_skip_cert_verification( Box::new(ClientConnectListenerKernel::new(f)) as Box, From a06cca463eb2aef2cea9ac486cd7364a9745f6a3 Mon Sep 17 00:00:00 2001 From: Tjemmmic Date: Mon, 22 Jul 2024 08:55:47 -0500 Subject: [PATCH 3/3] Use Protocol Master branch --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a06b690..bb339b1 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 = "donovan/peer-info" } -citadel_types = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "donovan/peer-info" } -citadel_logging = { git = "https://github.com/Avarok-Cybersecurity/Citadel-Protocol/", branch = "donovan/peer-info" } +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"] }