add veilid_api logging to debug calls through the api

This commit is contained in:
Christien Rioux 2024-02-29 21:18:31 -05:00
parent 380ac1883f
commit 292664f3fe
5 changed files with 47 additions and 10 deletions

View File

@ -91,7 +91,7 @@ pub fn veilid_version() -> (u32, u32, u32) {
#[cfg(target_os = "android")]
pub use intf::android::veilid_core_setup_android;
pub static DEFAULT_LOG_IGNORE_LIST: [&str; 23] = [
pub static DEFAULT_LOG_IGNORE_LIST: [&str; 24] = [
"mio",
"h2",
"hyper",
@ -115,6 +115,7 @@ pub static DEFAULT_LOG_IGNORE_LIST: [&str; 23] = [
"attohttpc",
"ws_stream_wasm",
"keyvaluedb_web",
"veilid_api",
];
use cfg_if::*;

View File

@ -39,7 +39,7 @@ pub struct VeilidAPI {
}
impl VeilidAPI {
#[instrument(skip_all)]
#[instrument(target = "veilid_api", level = "debug", skip_all)]
pub(crate) fn new(context: VeilidCoreContext) -> Self {
Self {
inner: Arc::new(Mutex::new(VeilidAPIInner {
@ -49,7 +49,7 @@ impl VeilidAPI {
}
/// Shut down Veilid and terminate the API
#[instrument(skip_all)]
#[instrument(target = "veilid_api", level = "debug", skip_all)]
pub async fn shutdown(self) {
let context = { self.inner.lock().context.take() };
if let Some(context) = context {
@ -168,6 +168,7 @@ impl VeilidAPI {
}
/// Connect to the network
#[instrument(target = "veilid_api", level = "debug", skip_all)]
pub async fn attach(&self) -> VeilidAPIResult<()> {
let attachment_manager = self.attachment_manager()?;
if !attachment_manager.attach().await {
@ -177,6 +178,7 @@ impl VeilidAPI {
}
/// Disconnect from the network
#[instrument(target = "veilid_api", level = "debug", skip_all)]
pub async fn detach(&self) -> VeilidAPIResult<()> {
let attachment_manager = self.attachment_manager()?;
if !attachment_manager.detach().await {
@ -189,6 +191,7 @@ impl VeilidAPI {
// Routing Context
/// Get a new `RoutingContext` object to use to send messages over the Veilid network.
#[instrument(target = "veilid_api", level = "debug", skip_all, err, ret)]
pub fn routing_context(&self) -> VeilidAPIResult<RoutingContext> {
RoutingContext::try_new(self.clone())
}
@ -200,6 +203,7 @@ impl VeilidAPI {
/// `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`)
#[instrument(target = "veilid_api", level = "debug", skip(self), fields(s=s.to_string()), ret, err)]
pub async fn parse_as_target<S: ToString>(&self, s: S) -> VeilidAPIResult<Target> {
let s = s.to_string();
@ -231,6 +235,7 @@ impl VeilidAPI {
///
/// Returns a route id and 'blob' that can be published over some means (DHT or otherwise) to be
/// imported by another Veilid node.
//#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub async fn new_private_route(&self) -> VeilidAPIResult<(RouteId, Vec<u8>)> {
self.new_custom_private_route(
&VALID_CRYPTO_KINDS,
@ -246,6 +251,7 @@ impl VeilidAPI {
///
/// Returns a route id and 'blob' that can be published over some means (DHT or otherwise) to be
/// imported by another Veilid node.
#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub async fn new_custom_private_route(
&self,
crypto_kinds: &[CryptoKind],
@ -293,6 +299,7 @@ impl VeilidAPI {
/// Import a private route blob as a remote private route.
///
/// Returns a route id that can be used to send private messages to the node creating this route.
#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> VeilidAPIResult<RouteId> {
let rss = self.routing_table()?.route_spec_store();
rss.import_remote_private_route_blob(blob)
@ -302,6 +309,7 @@ impl VeilidAPI {
///
/// This will deactivate the route and free its resources and it can no longer be sent to
/// or received from.
#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub fn release_private_route(&self, route_id: RouteId) -> VeilidAPIResult<()> {
let rss = self.routing_table()?.route_spec_store();
if !rss.release_route(route_id) {
@ -317,6 +325,7 @@ impl VeilidAPI {
///
/// * `call_id` - specifies which call to reply to, and it comes from a [VeilidUpdate::AppCall], specifically the [VeilidAppCall::id()] value.
/// * `message` - is an answer blob to be returned by the remote node's [RoutingContext::app_call()] function, and may be up to 32768 bytes
#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub async fn app_call_reply(
&self,
call_id: OperationId,
@ -333,6 +342,7 @@ impl VeilidAPI {
// Tunnel Building
#[cfg(feature = "unstable-tunnels")]
#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub async fn start_tunnel(
&self,
_endpoint_mode: TunnelMode,
@ -342,6 +352,7 @@ impl VeilidAPI {
}
#[cfg(feature = "unstable-tunnels")]
#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub async fn complete_tunnel(
&self,
_endpoint_mode: TunnelMode,
@ -352,6 +363,7 @@ impl VeilidAPI {
}
#[cfg(feature = "unstable-tunnels")]
#[instrument(target = "veilid_api", level = "debug", skip(self), ret, err)]
pub async fn cancel_tunnel(&self, _tunnel_id: TunnelId) -> VeilidAPIResult<bool> {
panic!("unimplemented");
}

View File

@ -32,6 +32,15 @@ pub struct RoutingContext {
unlocked_inner: Arc<RoutingContextUnlockedInner>,
}
impl fmt::Debug for RoutingContext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("RoutingContext")
.field("ptr", &format!("{:p}", Arc::as_ptr(&self.unlocked_inner)))
.field("safety_selection", &self.unlocked_inner.safety_selection)
.finish()
}
}
impl RoutingContext {
////////////////////////////////////////////////////////////////
@ -63,6 +72,7 @@ impl RoutingContext {
/// * Sequencing default is to prefer ordered before unordered message delivery
///
/// To customize the safety selection in use, use [RoutingContext::with_safety()].
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub fn with_default_safety(self) -> VeilidAPIResult<Self> {
let config = self.api.config()?;
let c = config.get();
@ -76,6 +86,7 @@ impl RoutingContext {
}
/// Use a custom [SafetySelection]. Can be used to disable safety via [SafetySelection::Unsafe]
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub fn with_safety(self, safety_selection: SafetySelection) -> VeilidAPIResult<Self> {
Ok(Self {
api: self.api.clone(),
@ -85,6 +96,7 @@ impl RoutingContext {
}
/// Use a specified [Sequencing] preference, with or without privacy
#[instrument(target = "veilid_api", level = "debug", ret)]
pub fn with_sequencing(self, sequencing: Sequencing) -> Self {
Self {
api: self.api.clone(),
@ -120,6 +132,7 @@ impl RoutingContext {
self.api.clone()
}
#[instrument(target = "veilid_api", level = "debug", ret, err)]
async fn get_destination(&self, target: Target) -> VeilidAPIResult<rpc_processor::Destination> {
let rpc_processor = self.api.rpc_processor()?;
rpc_processor
@ -139,6 +152,7 @@ impl RoutingContext {
/// * `message` - an arbitrary message blob of up to 32768 bytes
///
/// Returns an answer blob of up to 32768 bytes
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn app_call(&self, target: Target, message: Vec<u8>) -> VeilidAPIResult<Vec<u8>> {
let rpc_processor = self.api.rpc_processor()?;
@ -169,6 +183,7 @@ impl RoutingContext {
///
/// * `target` - can be either a direct node id or a private route
/// * `message` - an arbitrary message blob of up to 32768 bytes
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn app_message(&self, target: Target, message: Vec<u8>) -> VeilidAPIResult<()> {
let rpc_processor = self.api.rpc_processor()?;
@ -200,6 +215,7 @@ impl RoutingContext {
/// The record is considered 'open' after the create operation succeeds.
///
/// Returns the newly allocated DHT record's key if successful.
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn create_dht_record(
&self,
schema: DHTSchema,
@ -224,6 +240,7 @@ impl RoutingContext {
/// safety selection.
///
/// Returns the DHT record descriptor for the opened record if successful
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn open_dht_record(
&self,
key: TypedKey,
@ -239,6 +256,7 @@ impl RoutingContext {
/// Closes a DHT record at a specific key that was opened with create_dht_record or open_dht_record.
///
/// Closing a record allows you to re-open it with a different routing context
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn close_dht_record(&self, key: TypedKey) -> VeilidAPIResult<()> {
Crypto::validate_crypto_kind(key.kind)?;
let storage_manager = self.api.storage_manager()?;
@ -250,6 +268,7 @@ impl RoutingContext {
/// If the record is opened, it must be closed before it is deleted.
/// Deleting a record does not delete it from the network, but will remove the storage of the record
/// locally, and will prevent its value from being refreshed on the network by this node.
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn delete_dht_record(&self, key: TypedKey) -> VeilidAPIResult<()> {
Crypto::validate_crypto_kind(key.kind)?;
let storage_manager = self.api.storage_manager()?;
@ -262,6 +281,7 @@ impl RoutingContext {
///
/// Returns `None` if the value subkey has not yet been set
/// Returns `Some(data)` if the value subkey has valid data
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn get_dht_value(
&self,
key: TypedKey,
@ -280,6 +300,7 @@ impl RoutingContext {
///
/// Returns `None` if the value was successfully put
/// Returns `Some(data)` if the value put was older than the one available on the network
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn set_dht_value(
&self,
key: TypedKey,
@ -311,6 +332,7 @@ impl RoutingContext {
/// * If a member (either the owner or a SMPL schema member) has opened the key for writing (even if no writing is performed) then the watch will be signed and guaranteed network.dht.member_watch_limit per writer
///
/// Members can be specified via the SMPL schema and do not need to allocate writable subkeys in order to offer a member watch capability.
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn watch_dht_values(
&self,
key: TypedKey,
@ -330,6 +352,7 @@ impl RoutingContext {
/// This is a convenience function that cancels watching all subkeys in a range
/// Returns Ok(true) if there is any remaining watch for this record
/// Returns Ok(false) if the entire watch has been cancelled
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn cancel_dht_watch(
&self,
key: TypedKey,
@ -344,11 +367,13 @@ impl RoutingContext {
/// Block Store
#[cfg(feature = "unstable-blockstore")]
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn find_block(&self, _block_id: PublicKey) -> VeilidAPIResult<Vec<u8>> {
panic!("unimplemented");
}
#[cfg(feature = "unstable-blockstore")]
#[instrument(target = "veilid_api", level = "debug", ret, err)]
pub async fn supply_block(&self, _block_id: PublicKey) -> VeilidAPIResult<bool> {
panic!("unimplemented");
}

View File

@ -14,7 +14,7 @@ cfg_if::cfg_if! {
use self::windows::PlatformSupportWindows as PlatformSupport;
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
use self::apple::PlatformSupportApple as PlatformSupport;
} else if #[cfg(any(target_os = "openbsd"))] {
} else if #[cfg(target_os = "openbsd")] {
use self::openbsd::PlatformSupportOpenBSD as PlatformSupport;
} else {
compile_error!("No network interfaces support for this platform!");

View File

@ -1,11 +1,11 @@
#![cfg(any(target_os = "openbsd"))]
#![cfg(target_os = "openbsd")]
#![allow(non_camel_case_types)]
use super::*;
use libc::{
close, freeifaddrs, getifaddrs, if_nametoindex, ifaddrs, ioctl, pid_t, sockaddr, sockaddr_in6, c_short,
socket, sysctl, time_t, AF_INET6, CTL_NET, IFF_BROADCAST, IFF_LOOPBACK, IFF_POINTOPOINT,
IFF_RUNNING, IFNAMSIZ, NET_RT_FLAGS, PF_ROUTE, SOCK_DGRAM,
c_short, close, freeifaddrs, getifaddrs, if_nametoindex, ifaddrs, ioctl, pid_t, sockaddr,
sockaddr_in6, socket, sysctl, time_t, AF_INET6, CTL_NET, IFF_BROADCAST, IFF_LOOPBACK,
IFF_POINTOPOINT, IFF_RUNNING, IFNAMSIZ, NET_RT_FLAGS, PF_ROUTE, SOCK_DGRAM,
};
use sockaddr_tools::SockAddr;
use std::ffi::CStr;
@ -29,7 +29,6 @@ const RTA_DST: c_int = 1;
const RTA_GATEWAY: c_int = 2;
const RTF_GATEWAY: c_int = 2;
macro_rules! set_name {
($name_field:expr, $name_str:expr) => {{
let name_c = &::std::ffi::CString::new($name_str.to_owned()).map_err(|_| {