docs and tests work

This commit is contained in:
Christien Rioux
2023-08-29 15:15:47 -05:00
parent d3407998f5
commit e302b764d0
27 changed files with 156 additions and 74 deletions
+59 -14
View File
@@ -20,6 +20,19 @@ impl Drop for VeilidAPIInner {
}
}
/// The primary developer entrypoint into `veilid-core` functionality
///
/// From [VeilidAPI] one can access:
///
/// * [VeilidConfig] - The Veilid configuration specified by at startup time
/// * [Crypto] - The available set of cryptosystems provided by Veilid
/// * [TableStore] - The Veilid table-based encrypted persistent key-value store
/// * [ProtectedStore] - The Veilid abstract of the device's low-level 'protected secret storage'
/// * [VeilidState] - The current state of the Veilid node this API accesses
/// * [RoutingContext] - Communication methods between Veilid nodes and private routes
/// * Attach and detach from the network
/// * Create and import private routes
/// * Reply to `AppCall` RPCs
#[derive(Clone, Debug)]
pub struct VeilidAPI {
inner: Arc<Mutex<VeilidAPIInner>>,
@@ -48,7 +61,8 @@ impl VeilidAPI {
}
////////////////////////////////////////////////////////////////
// Accessors
// Public Accessors
pub fn config(&self) -> VeilidAPIResult<VeilidConfig> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
@@ -70,14 +84,6 @@ impl VeilidAPI {
}
Err(VeilidAPIError::not_initialized())
}
#[cfg(feature = "unstable-blockstore")]
pub fn block_store(&self) -> VeilidAPIResult<BlockStore> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
return Ok(context.block_store.clone());
}
Err(VeilidAPIError::not_initialized())
}
pub fn protected_store(&self) -> VeilidAPIResult<ProtectedStore> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
@@ -85,41 +91,52 @@ impl VeilidAPI {
}
Err(VeilidAPIError::not_initialized())
}
pub fn attachment_manager(&self) -> VeilidAPIResult<AttachmentManager> {
////////////////////////////////////////////////////////////////
// Internal Accessors
pub(crate) fn attachment_manager(&self) -> VeilidAPIResult<AttachmentManager> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
return Ok(context.attachment_manager.clone());
}
Err(VeilidAPIError::not_initialized())
}
pub fn network_manager(&self) -> VeilidAPIResult<NetworkManager> {
pub(crate) fn network_manager(&self) -> VeilidAPIResult<NetworkManager> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
return Ok(context.attachment_manager.network_manager());
}
Err(VeilidAPIError::not_initialized())
}
pub fn rpc_processor(&self) -> VeilidAPIResult<RPCProcessor> {
pub(crate) fn rpc_processor(&self) -> VeilidAPIResult<RPCProcessor> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
return Ok(context.attachment_manager.network_manager().rpc_processor());
}
Err(VeilidAPIError::NotInitialized)
}
pub fn routing_table(&self) -> VeilidAPIResult<RoutingTable> {
pub(crate) fn routing_table(&self) -> VeilidAPIResult<RoutingTable> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
return Ok(context.attachment_manager.network_manager().routing_table());
}
Err(VeilidAPIError::NotInitialized)
}
pub fn storage_manager(&self) -> VeilidAPIResult<StorageManager> {
pub(crate) fn storage_manager(&self) -> VeilidAPIResult<StorageManager> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
return Ok(context.storage_manager.clone());
}
Err(VeilidAPIError::NotInitialized)
}
#[cfg(feature = "unstable-blockstore")]
pub(crate) fn block_store(&self) -> VeilidAPIResult<BlockStore> {
let inner = self.inner.lock();
if let Some(context) = &inner.context {
return Ok(context.block_store.clone());
}
Err(VeilidAPIError::not_initialized())
}
////////////////////////////////////////////////////////////////
// Attach/Detach
@@ -162,10 +179,38 @@ impl VeilidAPI {
////////////////////////////////////////////////////////////////
// Routing Context
/// Get a new `RoutingContext` object to use to send messages over the Veilid network.
pub fn routing_context(&self) -> RoutingContext {
RoutingContext::new(self.clone())
}
/// Parse a string into a target object that can be used in a [RoutingContext]
///
/// Strings are in base64url format and can either be a remote route id or a node id.
/// Strings may have a [CryptoKind] [FourCC] prefix separated by a colon, such as:
/// `VLD0:XmnGyJrjMJBRC5ayJZRPXWTBspdX36-pbLb98H3UMeE` but if the prefix is left off
/// `XmnGyJrjMJBRC5ayJZRPXWTBspdX36-pbLb98H3UMeE` will be parsed with the 'best' cryptosystem
/// available (at the time of this writing this is `VLD0`)
pub async fn parse_as_target<S: AsRef<str>>(&self, s: S) -> VeilidAPIResult<Target> {
// Is this a route id?
if let Ok(rrid) = RouteId::from_str(s.as_ref()) {
let routing_table = self.routing_table()?;
let rss = routing_table.route_spec_store();
// Is this a valid remote route id? (can't target allocated routes)
if rss.is_route_id_remote(&rrid) {
return Ok(Target::PrivateRoute(rrid));
}
}
// Is this a node id?
if let Ok(nid) = TypedKey::from_str(s.as_ref()) {
return Ok(Target::NodeId(nid));
}
Err(VeilidAPIError::invalid_target())
}
////////////////////////////////////////////////////////////////
// Private route allocation
+3 -2
View File
@@ -8,6 +8,7 @@ mod serialize_helpers;
mod types;
pub mod json_api;
#[doc(hidden)]
pub mod tests;
pub use api::*;
@@ -18,19 +19,19 @@ pub use serialize_helpers::*;
pub use types::*;
pub use alloc::string::ToString;
pub use attachment_manager::AttachmentManager;
pub use core::str::FromStr;
pub use crypto::*;
#[cfg(feature = "unstable-blockstore")]
pub use intf::BlockStore;
pub use intf::ProtectedStore;
pub use network_manager::NetworkManager;
pub use routing_table::{NodeRef, NodeRefBase};
pub use table_store::{TableDB, TableDBTransaction, TableStore};
use crate::*;
use attachment_manager::AttachmentManager;
use core::fmt;
use core_context::{api_shutdown, VeilidCoreContext};
use network_manager::NetworkManager;
use routing_table::{Direction, RouteSpecStore, RoutingTable};
use rpc_processor::*;
use storage_manager::StorageManager;
+1
View File
@@ -1,4 +1,5 @@
mod fixtures;
#[doc(hidden)]
pub mod test_serialize_json;
mod test_types;
mod test_types_dht;