From 388bd0e83b228bd2213813f586f00edb2a8bdd5e Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Sun, 12 May 2024 06:17:20 +0300 Subject: [PATCH] cleanup of inline rust documentation --- nextgraph/src/lib.rs | 3 +- ng-app/src-tauri/src/lib.rs | 2 +- ng-net/src/actor.rs | 3 +- ng-net/src/actors/mod.rs | 4 +++ ng-net/src/broker.rs | 40 +++++++++++++++----------- ng-net/src/lib.rs | 1 + ng-net/src/utils.rs | 2 ++ ng-sdk-js/src/lib.rs | 2 +- ng-verifier/src/lib.rs | 11 +++---- ng-verifier/src/site.rs | 5 ++-- ng-verifier/src/types.rs | 9 ++++-- ng-verifier/src/user_storage/branch.rs | 2 ++ ng-verifier/src/user_storage/repo.rs | 2 ++ ng-verifier/src/verifier.rs | 28 +++++++++--------- ngcli/src/main.rs | 2 ++ ngd/src/main.rs | 2 ++ ngone/src/main.rs | 1 + 17 files changed, 75 insertions(+), 44 deletions(-) diff --git a/nextgraph/src/lib.rs b/nextgraph/src/lib.rs index f03accb..dfc70b6 100644 --- a/nextgraph/src/lib.rs +++ b/nextgraph/src/lib.rs @@ -56,7 +56,8 @@ pub mod net { } pub mod verifier { - pub use ng_verifier::*; + pub use ng_verifier::site::*; + pub use ng_verifier::types::*; } pub mod wallet { diff --git a/ng-app/src-tauri/src/lib.rs b/ng-app/src-tauri/src/lib.rs index 56729dd..0476b26 100644 --- a/ng-app/src-tauri/src/lib.rs +++ b/ng-app/src-tauri/src/lib.rs @@ -28,7 +28,7 @@ use ng_wallet::types::*; use ng_wallet::*; use nextgraph::local_broker::*; -use nextgraph::verifier::types::*; +use nextgraph::verifier::*; #[cfg(mobile)] mod mobile; diff --git a/ng-net/src/actor.rs b/ng-net/src/actor.rs index fc12102..f216b50 100644 --- a/ng-net/src/actor.rs +++ b/ng-net/src/actor.rs @@ -32,6 +32,7 @@ impl TryFrom for () { } } +#[doc(hidden)] #[async_trait::async_trait] pub trait EActor: Send + Sync + std::fmt::Debug { async fn respond( @@ -44,7 +45,7 @@ pub trait EActor: Send + Sync + std::fmt::Debug { } #[derive(Debug)] -pub struct Actor< +pub(crate) struct Actor< 'a, A: Into + std::fmt::Debug, B: TryFrom + std::fmt::Debug + Sync, diff --git a/ng-net/src/actors/mod.rs b/ng-net/src/actors/mod.rs index 523308e..f67b561 100644 --- a/ng-net/src/actors/mod.rs +++ b/ng-net/src/actors/mod.rs @@ -1,14 +1,18 @@ //! List of actors, each one for a specific Protocol message +#[doc(hidden)] pub mod noise; pub use noise::*; +#[doc(hidden)] pub mod start; pub use start::*; +#[doc(hidden)] pub mod probe; pub use probe::*; +#[doc(hidden)] pub mod connecting; pub use connecting::*; diff --git a/ng-net/src/broker.rs b/ng-net/src/broker.rs index 1eaa888..da7d9d0 100644 --- a/ng-net/src/broker.rs +++ b/ng-net/src/broker.rs @@ -35,14 +35,14 @@ use crate::utils::spawn_and_log_error; use crate::utils::{Receiver, ResultSend, Sender}; #[derive(Debug)] -pub enum PeerConnection { +enum PeerConnection { Core(BindAddress), Client(ConnectionBase), NONE, } #[derive(Debug)] -pub struct BrokerPeerInfo { +struct BrokerPeerInfo { #[allow(dead_code)] last_peer_advert: Option, //FIXME: remove Option connected: PeerConnection, @@ -50,7 +50,7 @@ pub struct BrokerPeerInfo { #[derive(Debug)] #[allow(dead_code)] -pub struct DirectConnection { +struct DirectConnection { addr: BindAddress, remote_peer_id: X25519PrivKey, tp: TransportProtocol, @@ -69,6 +69,7 @@ pub struct ServerConfig { pub bootstrap: BootstrapContent, } +#[doc(hidden)] #[async_trait::async_trait] pub trait ILocalBroker: Send + Sync + EActor { async fn deliver(&mut self, event: Event, overlay: OverlayId, user: UserId); @@ -122,28 +123,30 @@ impl Broker { // } // } - pub fn get_config(&self) -> Option<&ServerConfig> { + pub(crate) fn get_config(&self) -> Option<&ServerConfig> { self.config.as_ref() } - pub fn get_registration_url(&self) -> Option<&String> { + pub(crate) fn get_registration_url(&self) -> Option<&String> { self.config .as_ref() .and_then(|c| c.registration_url.as_ref()) } - pub fn get_bootstrap(&self) -> Result<&BootstrapContent, ProtocolError> { + pub(crate) fn get_bootstrap(&self) -> Result<&BootstrapContent, ProtocolError> { self.config .as_ref() .map(|c| &c.bootstrap) .ok_or(ProtocolError::BrokerError) } + #[doc(hidden)] pub fn set_server_broker(&mut self, broker: impl IServerBroker + 'static) { //log_debug!("set_server_broker"); self.server_broker = Some(Box::new(broker)); } + #[doc(hidden)] pub fn set_local_broker(&mut self, broker: Arc>) { //log_debug!("set_local_broker"); self.local_broker = Some(broker); @@ -171,7 +174,7 @@ impl Broker { (copy_listeners, copy_bind_addresses) } - pub fn get_server_broker( + pub(crate) fn get_server_broker( &self, ) -> Result<&Box, ProtocolError> { //log_debug!("GET STORAGE {:?}", self.server_storage); @@ -180,7 +183,7 @@ impl Broker { .ok_or(ProtocolError::BrokerError) } - pub fn get_server_broker_mut( + pub(crate) fn get_server_broker_mut( &mut self, ) -> Result<&mut Box, ProtocolError> { //log_debug!("GET STORAGE {:?}", self.server_storage); @@ -199,7 +202,7 @@ impl Broker { } #[cfg(not(target_arch = "wasm32"))] - pub fn authorize( + pub(crate) fn authorize( &self, bind_addresses: &(BindAddress, BindAddress), auth: Authorization, @@ -306,7 +309,7 @@ impl Broker { } } - pub fn reconnecting(&mut self, peer_id: X25519PrivKey, user: Option) { + fn reconnecting(&mut self, peer_id: X25519PrivKey, user: Option) { let peerinfo = self.peers.get_mut(&(user, peer_id)); match peerinfo { Some(info) => match &info.connected { @@ -351,7 +354,8 @@ impl Broker { } } - pub fn remove_anonymous( + #[cfg(not(target_arch = "wasm32"))] + fn remove_anonymous( &mut self, remote_bind_address: BindAddress, local_bind_address: BindAddress, @@ -380,7 +384,7 @@ impl Broker { // } // } - pub fn new() -> Self { + fn new() -> Self { let (shutdown_sender, shutdown_receiver) = mpsc::unbounded::(); let mut random_buf = [0u8; 4]; getrandom::getrandom(&mut random_buf).unwrap(); @@ -496,7 +500,9 @@ impl Broker { } } - pub async fn shutdown(&mut self) { + #[allow(dead_code)] + #[cfg(not(target_arch = "wasm32"))] + async fn shutdown(&mut self) { if self.closing { return; } @@ -505,6 +511,7 @@ impl Broker { let _ = self.shutdown_sender.send(ProtocolError::Closing).await; } + #[doc(hidden)] #[cfg(not(target_arch = "wasm32"))] pub async fn accept( &mut self, @@ -600,7 +607,7 @@ impl Broker { } #[cfg(not(target_arch = "wasm32"))] - pub async fn attach_and_authorize_peer_id( + pub(crate) async fn attach_and_authorize_peer_id( &mut self, remote_bind_address: BindAddress, local_bind_address: BindAddress, @@ -883,7 +890,7 @@ impl Broker { } #[cfg(not(target_arch = "wasm32"))] - pub async fn dispatch_event( + pub(crate) async fn dispatch_event( &mut self, overlay: &OverlayId, event: Event, @@ -951,7 +958,7 @@ impl Broker { .await } - pub async fn close_anonymous( + async fn close_anonymous( &mut self, remote_bind_address: BindAddress, local_bind_address: BindAddress, @@ -964,6 +971,7 @@ impl Broker { } } + #[doc(hidden)] pub fn print_status(&self) { self.peers.iter().for_each(|(peer_id, peer_info)| { log_info!("PEER in BROKER {:?} {:?}", peer_id, peer_info); diff --git a/ng-net/src/lib.rs b/ng-net/src/lib.rs index f534a60..cb5cbf8 100644 --- a/ng-net/src/lib.rs +++ b/ng-net/src/lib.rs @@ -15,6 +15,7 @@ pub mod broker; pub mod server_broker; +#[doc(hidden)] pub mod connection; pub mod actor; diff --git a/ng-net/src/utils.rs b/ng-net/src/utils.rs index 4e15931..76d9ae6 100644 --- a/ng-net/src/utils.rs +++ b/ng-net/src/utils.rs @@ -29,6 +29,7 @@ use crate::types::*; #[cfg(target_arch = "wasm32")] use crate::NG_BOOTSTRAP_LOCAL_PATH; +#[doc(hidden)] #[cfg(target_arch = "wasm32")] pub fn spawn_and_log_error(fut: F) -> task::JoinHandle<()> where @@ -46,6 +47,7 @@ pub type ResultSend = std::result::Result = std::result::Result>; +#[doc(hidden)] #[cfg(not(target_arch = "wasm32"))] pub fn spawn_and_log_error(fut: F) -> task::JoinHandle<()> where diff --git a/ng-sdk-js/src/lib.rs b/ng-sdk-js/src/lib.rs index 3142a3d..ea762b9 100644 --- a/ng-sdk-js/src/lib.rs +++ b/ng-sdk-js/src/lib.rs @@ -41,7 +41,7 @@ use ng_wallet::types::*; use ng_wallet::*; use nextgraph::local_broker::*; -use nextgraph::verifier::types::*; +use nextgraph::verifier::*; #[wasm_bindgen] pub async fn get_local_bootstrap(location: String, invite: JsValue) -> JsValue { diff --git a/ng-verifier/src/lib.rs b/ng-verifier/src/lib.rs index af4d60f..b712eea 100644 --- a/ng-verifier/src/lib.rs +++ b/ng-verifier/src/lib.rs @@ -1,14 +1,15 @@ pub mod types; -pub mod user_storage; +pub mod site; +#[doc(hidden)] pub mod verifier; -pub mod site; +mod user_storage; -pub mod commits; +mod commits; -pub mod request_processor; +mod request_processor; #[cfg(not(target_family = "wasm"))] -pub mod rocksdb_user_storage; +mod rocksdb_user_storage; diff --git a/ng-verifier/src/site.rs b/ng-verifier/src/site.rs index 41db34b..05e515f 100644 --- a/ng-verifier/src/site.rs +++ b/ng-verifier/src/site.rs @@ -19,7 +19,6 @@ use ng_repo::utils::generate_keypair; use crate::verifier::Verifier; -/// Site V0 #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct SiteV0 { pub site_type: SiteType, @@ -37,8 +36,10 @@ pub struct SiteV0 { // Identity::OrgPrivateStore or Identity::IndividualPrivateStore pub private: SiteStore, - /// Only for IndividualSite: TODO reorganize those 2 fields + // Only for IndividualSite: TODO reorganize those 2 fields + #[doc(hidden)] pub cores: Vec<(PubKey, Option<[u8; 32]>)>, + #[doc(hidden)] pub bootstraps: Vec, } diff --git a/ng-verifier/src/types.rs b/ng-verifier/src/types.rs index 0ca4358..9f538cd 100644 --- a/ng-verifier/src/types.rs +++ b/ng-verifier/src/types.rs @@ -22,6 +22,7 @@ use ng_repo::{errors::NgError, types::*}; use ng_net::types::*; +#[doc(hidden)] #[derive(Clone, Debug, Serialize, Deserialize)] pub enum SessionPeerLastSeq { V0(u64), @@ -65,17 +66,18 @@ impl VerifierType { } } } - +#[doc(hidden)] //type LastSeqFn = fn(peer_id: PubKey, qty: u16) -> Result; pub type LastSeqFn = dyn Fn(PubKey, u16) -> Result + 'static + Sync + Send; - +#[doc(hidden)] // peer_id: PubKey, seq_num:u64, event_ser: vec, pub type OutboxWriteFn = dyn Fn(PubKey, u64, Vec) -> Result<(), NgError> + 'static + Sync + Send; - +#[doc(hidden)] // peer_id: PubKey, pub type OutboxReadFn = dyn Fn(PubKey) -> Result>, NgError> + 'static + Sync + Send; +#[doc(hidden)] pub struct JsSaveSessionConfig { pub last_seq_function: Box, pub outbox_write_function: Box, @@ -142,6 +144,7 @@ pub struct VerifierConfig { pub protected_store_id: Option, } +#[doc(hidden)] pub type CancelFn = Box; // diff --git a/ng-verifier/src/user_storage/branch.rs b/ng-verifier/src/user_storage/branch.rs index c0f6784..6007f67 100644 --- a/ng-verifier/src/user_storage/branch.rs +++ b/ng-verifier/src/user_storage/branch.rs @@ -9,6 +9,8 @@ //! Branch Storage (Object Key/Col/Value Mapping) +#![allow(dead_code)] + use serde_bare::from_slice; use serde_bare::to_vec; diff --git a/ng-verifier/src/user_storage/repo.rs b/ng-verifier/src/user_storage/repo.rs index eafb51e..90fc2f9 100644 --- a/ng-verifier/src/user_storage/repo.rs +++ b/ng-verifier/src/user_storage/repo.rs @@ -9,6 +9,8 @@ //! Repo Storage (Object Key/Col/Value Mapping) +#![allow(dead_code)] + use std::collections::HashMap; use std::collections::HashSet; use std::sync::{Arc, RwLock}; diff --git a/ng-verifier/src/verifier.rs b/ng-verifier/src/verifier.rs index 7855391..c08b84c 100644 --- a/ng-verifier/src/verifier.rs +++ b/ng-verifier/src/verifier.rs @@ -75,8 +75,8 @@ use crate::user_storage::UserStorage; // } pub struct Verifier { - pub config: VerifierConfig, - pub connected_server_id: Option, + pub(crate) config: VerifierConfig, + pub(crate) connected_server_id: Option, #[allow(dead_code)] graph_dataset: Option, pub(crate) user_storage: Option>>, @@ -116,7 +116,7 @@ struct EventOutboxStorage { } impl Verifier { - pub fn user_privkey(&self) -> &PrivKey { + pub(crate) fn user_privkey(&self) -> &PrivKey { &self.config.user_priv_key } @@ -329,7 +329,7 @@ impl Verifier { )) } - pub fn get_store_or_load(&mut self, store_repo: &StoreRepo) -> Arc { + fn get_store_or_load(&mut self, store_repo: &StoreRepo) -> Arc { let overlay_id = store_repo.overlay_id_for_storage_purpose(); let block_storage = self .get_arc_block_storage() @@ -349,7 +349,7 @@ impl Verifier { Arc::clone(store) } - pub fn complete_site_store( + fn complete_site_store( &mut self, store_repo: &StoreRepo, mut repo: Repo, @@ -386,7 +386,7 @@ impl Verifier { Ok(repo) } - pub fn complete_site_store_already_inserted( + fn complete_site_store_already_inserted( &mut self, store_repo: StoreRepo, ) -> Result<(), NgError> { @@ -417,7 +417,7 @@ impl Verifier { Ok(()) } - pub fn get_store(&self, store_repo: &StoreRepo) -> Result, VerifierError> { + fn get_store(&self, store_repo: &StoreRepo) -> Result, VerifierError> { let overlay_id = store_repo.overlay_id_for_storage_purpose(); let store = self .stores @@ -426,7 +426,7 @@ impl Verifier { Ok(Arc::clone(store)) } - pub fn get_repo_mut( + pub(crate) fn get_repo_mut( &mut self, id: &RepoId, _store_repo: &StoreRepo, @@ -449,7 +449,7 @@ impl Verifier { repo_ref } - pub fn add_store(&mut self, store: Arc) { + fn add_store(&mut self, store: Arc) { let overlay_id = store.get_store_repo().overlay_id_for_storage_purpose(); if self.stores.contains_key(&overlay_id) { return; @@ -1132,7 +1132,7 @@ impl Verifier { Ok(()) } - pub async fn verify_commit( + pub(crate) async fn verify_commit( &mut self, commit: &Commit, branch_id: &BranchId, @@ -1284,7 +1284,7 @@ impl Verifier { repo_ref } - pub async fn bootstrap(&mut self) -> Result<(), NgError> { + async fn bootstrap(&mut self) -> Result<(), NgError> { if let Err(e) = self.bootstrap_from_remote().await { log_warn!("bootstrap_from_remote failed with {}", e); // maybe it failed because the 3P stores are still in the outbox and haven't been sent yet. @@ -1779,7 +1779,7 @@ impl Verifier { // ret // } - pub async fn send_outbox(&mut self) -> Result<(), NgError> { + async fn send_outbox(&mut self) -> Result<(), NgError> { let ret = self.take_events_from_outbox(); // if ret.is_err() { // log_err!("send_outbox {:}", ret.as_ref().unwrap_err()); @@ -2114,7 +2114,7 @@ impl Verifier { Ok(()) } - pub async fn new_store_default<'a>( + pub(crate) async fn new_store_default<'a>( &'a mut self, creator: &UserId, creator_priv_key: &PrivKey, @@ -2158,7 +2158,7 @@ impl Verifier { } /// returns the Repo and the last seq_num of the peer - pub async fn new_repo_default<'a>( + async fn new_repo_default<'a>( &'a mut self, creator: &UserId, creator_priv_key: &PrivKey, diff --git a/ngcli/src/main.rs b/ngcli/src/main.rs index 1cebe1d..9b42ca0 100644 --- a/ngcli/src/main.rs +++ b/ngcli/src/main.rs @@ -7,6 +7,8 @@ // notice may not be copied, modified, or distributed except // according to those terms. +#![doc(hidden)] + use core::fmt; use std::error::Error; use std::fs::{read_to_string, write}; diff --git a/ngd/src/main.rs b/ngd/src/main.rs index 285f7c3..1be8c2d 100644 --- a/ngd/src/main.rs +++ b/ngd/src/main.rs @@ -7,6 +7,8 @@ // notice may not be copied, modified, or distributed except // according to those terms. +#![doc(hidden)] + pub mod types; mod cli; diff --git a/ngone/src/main.rs b/ngone/src/main.rs index 37961f3..36b9bd1 100644 --- a/ngone/src/main.rs +++ b/ngone/src/main.rs @@ -24,6 +24,7 @@ use ng_repo::log::*; use ng_repo::types::*; use ng_repo::utils::verify; +#[cfg(not(debug_assertions))] use ng_net::types::{APP_NG_ONE_URL, NG_ONE_URL}; use ng_wallet::types::*;