Merge branch 'main' of gitlab.hackers.town:veilid/veilid

This commit is contained in:
John Smith 2022-06-10 17:08:01 -04:00
commit 3f7dfa6c6a
33 changed files with 312 additions and 96 deletions

View File

@ -13,10 +13,10 @@ rustup target add aarch64-apple-darwin aarch64-apple-ios x86_64-apple-darwin x86
cargo install wasm-bindgen-cli cargo install wasm-bindgen-cli
# install bitcode compatible ios toolchain # install bitcode compatible ios toolchain
echo Manual Step: # echo Manual Step:
echo install +ios-arm64-1.57.0 toolchain for bitcode from https://github.com/getditto/rust-bitcode/releases/latest and unzip # echo install +ios-arm64-1.57.0 toolchain for bitcode from https://github.com/getditto/rust-bitcode/releases/latest and unzip
echo xattr -d -r com.apple.quarantine . # echo xattr -d -r com.apple.quarantine .
echo ./install.sh # echo ./install.sh
# ensure brew is installed # ensure brew is installed
if command -v brew &> /dev/null; then if command -v brew &> /dev/null; then
@ -39,8 +39,16 @@ xcode-select --install
# ensure packages are installed # ensure packages are installed
if [ "$BREW_USER" == "" ]; then if [ "$BREW_USER" == "" ]; then
if [ -d /opt/homebrew ]; then
BREW_USER=`ls -lad /opt/homebrew/. | cut -d\ -f4` BREW_USER=`ls -lad /opt/homebrew/. | cut -d\ -f4`
echo "Must sudo to homebrew user \"$BREW_USER\" to install capnp package:" echo "Must sudo to homebrew user \"$BREW_USER\" to install capnp package:"
elif [ -d /usr/local/Homebrew ]; then
BREW_USER=`ls -lad /usr/local/Homebrew/. | cut -d\ -f4`
echo "Must sudo to homebrew user \"$BREW_USER\" to install capnp package:"
else
echo "Homebrew is not installed in the normal place. Trying as current user"
BREW_USER=`whoami`
fi
fi fi
sudo -H -u $BREW_USER brew install capnp sudo -H -u $BREW_USER brew install capnp

View File

@ -15,8 +15,8 @@ do
if [ "$arch" == "arm64" ]; then if [ "$arch" == "arm64" ]; then
echo arm64 echo arm64
CARGO_TARGET=aarch64-apple-ios CARGO_TARGET=aarch64-apple-ios
CARGO_TOOLCHAIN=+ios-arm64-1.57.0 #CARGO_TOOLCHAIN=+ios-arm64-1.57.0
#CARGO_TOOLCHAIN= CARGO_TOOLCHAIN=
elif [ "$arch" == "x86_64" ]; then elif [ "$arch" == "x86_64" ]; then
echo x86_64 echo x86_64
CARGO_TARGET=x86_64-apple-ios CARGO_TARGET=x86_64-apple-ios

View File

@ -52,6 +52,7 @@ impl ApiTracingLayer {
} }
} }
#[instrument(level = "debug", skip(update_callback))]
pub async fn init(max_level: Option<VeilidLogLevel>, update_callback: UpdateCallback) { pub async fn init(max_level: Option<VeilidLogLevel>, update_callback: UpdateCallback) {
let api_logger = API_LOGGER.get_or_init(|| ApiTracingLayer { let api_logger = API_LOGGER.get_or_init(|| ApiTracingLayer {
inner: Arc::new(Mutex::new(None)), inner: Arc::new(Mutex::new(None)),
@ -60,6 +61,7 @@ impl ApiTracingLayer {
*api_logger.inner.lock() = apilogger_inner; *api_logger.inner.lock() = apilogger_inner;
} }
#[instrument(level = "debug")]
pub async fn terminate() { pub async fn terminate() {
if let Some(api_logger) = API_LOGGER.get() { if let Some(api_logger) = API_LOGGER.get() {
let mut inner = api_logger.inner.lock(); let mut inner = api_logger.inner.lock();
@ -75,6 +77,7 @@ impl ApiTracingLayer {
.clone() .clone()
} }
#[instrument(level = "trace")]
pub fn change_api_log_level(max_level: Option<VeilidLogLevel>) { pub fn change_api_log_level(max_level: Option<VeilidLogLevel>) {
if let Some(api_logger) = API_LOGGER.get() { if let Some(api_logger) = API_LOGGER.get() {
if let Some(inner) = &mut *api_logger.inner.lock() { if let Some(inner) = &mut *api_logger.inner.lock() {

View File

@ -221,6 +221,7 @@ impl AttachmentManager {
} }
} }
#[instrument(level = "debug", skip(self))]
async fn attachment_maintainer(self) { async fn attachment_maintainer(self) {
trace!("attachment starting"); trace!("attachment starting");
let netman = { let netman = {
@ -229,7 +230,6 @@ impl AttachmentManager {
inner.network_manager.clone() inner.network_manager.clone()
}; };
trace!("starting network");
let mut started = true; let mut started = true;
if let Err(err) = netman.startup().await { if let Err(err) = netman.startup().await {
error!("network startup failed: {}", err); error!("network startup failed: {}", err);
@ -266,6 +266,7 @@ impl AttachmentManager {
self.inner.lock().attach_timestamp = None; self.inner.lock().attach_timestamp = None;
} }
#[instrument(level = "debug", skip_all, err)]
pub async fn init(&self, update_callback: UpdateCallback) -> Result<(), String> { pub async fn init(&self, update_callback: UpdateCallback) -> Result<(), String> {
trace!("init"); trace!("init");
let network_manager = { let network_manager = {
@ -286,6 +287,8 @@ impl AttachmentManager {
Ok(()) Ok(())
} }
#[instrument(level = "debug", skip(self))]
pub async fn terminate(&self) { pub async fn terminate(&self) {
// Ensure we detached // Ensure we detached
self.detach().await; self.detach().await;
@ -298,8 +301,8 @@ impl AttachmentManager {
inner.update_callback = None; inner.update_callback = None;
} }
#[instrument(level = "trace", skip(self))]
fn attach(&self) { fn attach(&self) {
trace!("attach");
// Create long-running connection maintenance routine // Create long-running connection maintenance routine
let this = self.clone(); let this = self.clone();
self.inner.lock().maintain_peers = true; self.inner.lock().maintain_peers = true;
@ -307,8 +310,8 @@ impl AttachmentManager {
Some(intf::spawn(this.attachment_maintainer())); Some(intf::spawn(this.attachment_maintainer()));
} }
#[instrument(level = "trace", skip(self))]
async fn detach(&self) { async fn detach(&self) {
trace!("detach");
let attachment_maintainer_jh = self.inner.lock().attachment_maintainer_jh.take(); let attachment_maintainer_jh = self.inner.lock().attachment_maintainer_jh.take();
if let Some(jh) = attachment_maintainer_jh { if let Some(jh) = attachment_maintainer_jh {
// Terminate long-running connection maintenance routine // Terminate long-running connection maintenance routine
@ -343,16 +346,18 @@ impl AttachmentManager {
} }
} }
#[instrument(level = "trace", skip(self), err)]
pub async fn request_attach(&self) -> Result<(), String> { pub async fn request_attach(&self) -> Result<(), String> {
self.process_input(&AttachmentInput::AttachRequested) self.process_input(&AttachmentInput::AttachRequested)
.await .await
.map_err(|e| format!("Attach request failed: {}", e)) .map_err(|e| format!("Attach request failed: {}", e))
} }
#[instrument(level = "trace", skip(self), err)]
pub async fn request_detach(&self) -> Result<(), String> { pub async fn request_detach(&self) -> Result<(), String> {
self.process_input(&AttachmentInput::DetachRequested) self.process_input(&AttachmentInput::DetachRequested)
.await .await
.map_err(|e| format!("Attach request failed: {}", e)) .map_err(|e| format!("Detach request failed: {}", e))
} }
pub fn get_state(&self) -> AttachmentState { pub fn get_state(&self) -> AttachmentState {

View File

@ -10,7 +10,6 @@ cfg_if! {
if #[cfg(target_arch = "wasm32")] { if #[cfg(target_arch = "wasm32")] {
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate)>; pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate)>;
} else { } else {
pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>; pub type UpdateCallback = Arc<dyn Fn(VeilidUpdate) + Send + Sync>;
} }
} }
@ -59,6 +58,7 @@ impl ServicesContext {
} }
} }
#[instrument(err, skip_all)]
pub async fn startup(&mut self) -> Result<(), VeilidAPIError> { pub async fn startup(&mut self) -> Result<(), VeilidAPIError> {
let api_log_level: VeilidConfigLogLevel = self.config.get().api_log_level; let api_log_level: VeilidConfigLogLevel = self.config.get().api_log_level;
if api_log_level != VeilidConfigLogLevel::Off { if api_log_level != VeilidConfigLogLevel::Off {
@ -131,6 +131,7 @@ impl ServicesContext {
Ok(()) Ok(())
} }
#[instrument(skip_all)]
pub async fn shutdown(&mut self) { pub async fn shutdown(&mut self) {
info!("Veilid API shutting down"); info!("Veilid API shutting down");
@ -179,6 +180,7 @@ pub struct VeilidCoreContext {
} }
impl VeilidCoreContext { impl VeilidCoreContext {
#[instrument(err, skip_all)]
async fn new_with_config_callback( async fn new_with_config_callback(
update_callback: UpdateCallback, update_callback: UpdateCallback,
config_callback: ConfigCallback, config_callback: ConfigCallback,
@ -193,6 +195,7 @@ impl VeilidCoreContext {
Self::new_common(update_callback, config).await Self::new_common(update_callback, config).await
} }
#[instrument(err, skip(update_callback))]
async fn new_with_config_json( async fn new_with_config_json(
update_callback: UpdateCallback, update_callback: UpdateCallback,
config_json: String, config_json: String,
@ -206,6 +209,7 @@ impl VeilidCoreContext {
Self::new_common(update_callback, config).await Self::new_common(update_callback, config).await
} }
#[instrument(err, skip(update_callback))]
async fn new_common( async fn new_common(
update_callback: UpdateCallback, update_callback: UpdateCallback,
config: VeilidConfig, config: VeilidConfig,
@ -233,6 +237,7 @@ impl VeilidCoreContext {
}) })
} }
#[instrument(skip_all)]
async fn shutdown(self) { async fn shutdown(self) {
let mut sc = ServicesContext::new_full( let mut sc = ServicesContext::new_full(
self.config.clone(), self.config.clone(),
@ -251,6 +256,7 @@ impl VeilidCoreContext {
static INITIALIZED: AsyncMutex<bool> = AsyncMutex::new(false); static INITIALIZED: AsyncMutex<bool> = AsyncMutex::new(false);
#[instrument(err, skip_all)]
pub async fn api_startup( pub async fn api_startup(
update_callback: UpdateCallback, update_callback: UpdateCallback,
config_callback: ConfigCallback, config_callback: ConfigCallback,
@ -273,6 +279,7 @@ pub async fn api_startup(
Ok(veilid_api) Ok(veilid_api)
} }
#[instrument(err, skip(update_callback))]
pub async fn api_startup_json( pub async fn api_startup_json(
update_callback: UpdateCallback, update_callback: UpdateCallback,
config_json: String, config_json: String,
@ -294,6 +301,7 @@ pub async fn api_startup_json(
Ok(veilid_api) Ok(veilid_api)
} }
#[instrument(skip_all)]
pub(crate) async fn api_shutdown(context: VeilidCoreContext) { pub(crate) async fn api_shutdown(context: VeilidCoreContext) {
let mut initialized_lock = INITIALIZED.lock().await; let mut initialized_lock = INITIALIZED.lock().await;
context.shutdown().await; context.shutdown().await;

View File

@ -29,6 +29,7 @@ impl ProtectedStore {
} }
} }
#[instrument(level = "trace", skip(self), err)]
pub async fn delete_all(&self) -> Result<(), String> { pub async fn delete_all(&self) -> Result<(), String> {
// Delete all known keys // Delete all known keys
if self.remove_user_secret_string("node_id").await? { if self.remove_user_secret_string("node_id").await? {
@ -43,6 +44,7 @@ impl ProtectedStore {
Ok(()) Ok(())
} }
#[instrument(level = "debug", skip(self), err)]
pub async fn init(&self) -> Result<(), String> { pub async fn init(&self) -> Result<(), String> {
let delete = { let delete = {
let c = self.config.get(); let c = self.config.get();
@ -95,6 +97,7 @@ impl ProtectedStore {
Ok(()) Ok(())
} }
#[instrument(level = "debug", skip(self))]
pub async fn terminate(&self) { pub async fn terminate(&self) {
*self.inner.lock() = Self::new_inner(); *self.inner.lock() = Self::new_inner();
} }
@ -108,6 +111,7 @@ impl ProtectedStore {
} }
} }
#[instrument(level = "trace", skip(self, value), ret, err)]
pub async fn save_user_secret_string(&self, key: &str, value: &str) -> Result<bool, String> { pub async fn save_user_secret_string(&self, key: &str, value: &str) -> Result<bool, String> {
let inner = self.inner.lock(); let inner = self.inner.lock();
inner inner
@ -124,6 +128,7 @@ impl ProtectedStore {
.map_err(logthru_pstore!()) .map_err(logthru_pstore!())
} }
#[instrument(level = "trace", skip(self), err)]
pub async fn load_user_secret_string(&self, key: &str) -> Result<Option<String>, String> { pub async fn load_user_secret_string(&self, key: &str) -> Result<Option<String>, String> {
let inner = self.inner.lock(); let inner = self.inner.lock();
match inner match inner
@ -139,6 +144,7 @@ impl ProtectedStore {
} }
} }
#[instrument(level = "trace", skip(self), ret, err)]
pub async fn remove_user_secret_string(&self, key: &str) -> Result<bool, String> { pub async fn remove_user_secret_string(&self, key: &str) -> Result<bool, String> {
let inner = self.inner.lock(); let inner = self.inner.lock();
match inner match inner
@ -154,6 +160,7 @@ impl ProtectedStore {
} }
} }
#[instrument(level = "trace", skip(self, value), ret, err)]
pub async fn save_user_secret(&self, key: &str, value: &[u8]) -> Result<bool, String> { pub async fn save_user_secret(&self, key: &str, value: &[u8]) -> Result<bool, String> {
let mut s = BASE64URL_NOPAD.encode(value); let mut s = BASE64URL_NOPAD.encode(value);
s.push('!'); s.push('!');
@ -161,6 +168,7 @@ impl ProtectedStore {
self.save_user_secret_string(key, s.as_str()).await self.save_user_secret_string(key, s.as_str()).await
} }
#[instrument(level = "trace", skip(self), err)]
pub async fn load_user_secret(&self, key: &str) -> Result<Option<Vec<u8>>, String> { pub async fn load_user_secret(&self, key: &str) -> Result<Option<Vec<u8>>, String> {
let mut s = match self.load_user_secret_string(key).await? { let mut s = match self.load_user_secret_string(key).await? {
Some(s) => s, Some(s) => s,
@ -191,6 +199,7 @@ impl ProtectedStore {
} }
} }
#[instrument(level = "trace", skip(self), ret, err)]
pub async fn remove_user_secret(&self, key: &str) -> Result<bool, String> { pub async fn remove_user_secret(&self, key: &str) -> Result<bool, String> {
self.remove_user_secret_string(key).await self.remove_user_secret_string(key).await
} }

View File

@ -233,6 +233,7 @@ impl NetworkManager {
self.inner.lock().relay_node.clone() self.inner.lock().relay_node.clone()
} }
#[instrument(level = "debug", skip_all, err)]
pub async fn init(&self, update_callback: UpdateCallback) -> Result<(), String> { pub async fn init(&self, update_callback: UpdateCallback) -> Result<(), String> {
let routing_table = RoutingTable::new(self.clone()); let routing_table = RoutingTable::new(self.clone());
routing_table.init().await?; routing_table.init().await?;
@ -240,6 +241,8 @@ impl NetworkManager {
self.inner.lock().update_callback = Some(update_callback); self.inner.lock().update_callback = Some(update_callback);
Ok(()) Ok(())
} }
#[instrument(level = "debug", skip_all)]
pub async fn terminate(&self) { pub async fn terminate(&self) {
let routing_table = { let routing_table = {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
@ -251,6 +254,7 @@ impl NetworkManager {
self.inner.lock().update_callback = None; self.inner.lock().update_callback = None;
} }
#[instrument(level = "debug", skip_all, err)]
pub async fn internal_startup(&self) -> Result<(), String> { pub async fn internal_startup(&self) -> Result<(), String> {
trace!("NetworkManager::internal_startup begin"); trace!("NetworkManager::internal_startup begin");
if self.inner.lock().components.is_some() { if self.inner.lock().components.is_some() {
@ -281,6 +285,7 @@ impl NetworkManager {
Ok(()) Ok(())
} }
#[instrument(level = "debug", skip_all, err)]
pub async fn startup(&self) -> Result<(), String> { pub async fn startup(&self) -> Result<(), String> {
if let Err(e) = self.internal_startup().await { if let Err(e) = self.internal_startup().await {
self.shutdown().await; self.shutdown().await;
@ -292,6 +297,7 @@ impl NetworkManager {
Ok(()) Ok(())
} }
#[instrument(level = "debug", skip_all)]
pub async fn shutdown(&self) { pub async fn shutdown(&self) {
trace!("NetworkManager::shutdown begin"); trace!("NetworkManager::shutdown begin");
@ -339,6 +345,7 @@ impl NetworkManager {
} }
} }
#[instrument(level = "trace", skip(self), ret)]
pub fn check_client_whitelist(&self, client: DHTKey) -> bool { pub fn check_client_whitelist(&self, client: DHTKey) -> bool {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
@ -351,6 +358,7 @@ impl NetworkManager {
} }
} }
#[instrument(level = "trace", skip(self))]
pub fn purge_client_whitelist(&self) { pub fn purge_client_whitelist(&self) {
let timeout_ms = self.config.get().network.client_whitelist_timeout_ms; let timeout_ms = self.config.get().network.client_whitelist_timeout_ms;
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
@ -366,6 +374,15 @@ impl NetworkManager {
} }
} }
#[instrument(level = "debug", skip_all, err)]
async fn restart_net(&self, net: Network) -> Result<(), String> {
net.shutdown().await;
self.send_network_update();
net.startup().await?;
self.send_network_update();
Ok(())
}
pub async fn tick(&self) -> Result<(), String> { pub async fn tick(&self) -> Result<(), String> {
let (routing_table, net, receipt_manager) = { let (routing_table, net, receipt_manager) = {
let inner = self.inner.lock(); let inner = self.inner.lock();
@ -380,10 +397,7 @@ impl NetworkManager {
// If the network needs to be reset, do it // If the network needs to be reset, do it
// if things can't restart, then we fail out of the attachment manager // if things can't restart, then we fail out of the attachment manager
if net.needs_restart() { if net.needs_restart() {
net.shutdown().await; self.restart_net(net.clone()).await?;
self.send_network_update();
net.startup().await?;
self.send_network_update();
} }
// Run the rolling transfers task // Run the rolling transfers task
@ -448,6 +462,7 @@ impl NetworkManager {
} }
// Generates a multi-shot/normal receipt // Generates a multi-shot/normal receipt
#[instrument(level = "trace", skip(self, extra_data, callback), err)]
pub fn generate_receipt<D: AsRef<[u8]>>( pub fn generate_receipt<D: AsRef<[u8]>>(
&self, &self,
expiration_us: u64, expiration_us: u64,
@ -473,6 +488,7 @@ impl NetworkManager {
} }
// Generates a single-shot/normal receipt // Generates a single-shot/normal receipt
#[instrument(level = "trace", skip(self, extra_data), err)]
pub fn generate_single_shot_receipt<D: AsRef<[u8]>>( pub fn generate_single_shot_receipt<D: AsRef<[u8]>>(
&self, &self,
expiration_us: u64, expiration_us: u64,
@ -498,6 +514,7 @@ impl NetworkManager {
} }
// Process a received out-of-band receipt // Process a received out-of-band receipt
#[instrument(level = "trace", skip(self, receipt_data), err)]
pub async fn handle_out_of_band_receipt<R: AsRef<[u8]>>( pub async fn handle_out_of_band_receipt<R: AsRef<[u8]>>(
&self, &self,
receipt_data: R, receipt_data: R,
@ -511,6 +528,7 @@ impl NetworkManager {
} }
// Process a received in-band receipt // Process a received in-band receipt
#[instrument(level = "trace", skip(self, receipt_data), err)]
pub async fn handle_in_band_receipt<R: AsRef<[u8]>>( pub async fn handle_in_band_receipt<R: AsRef<[u8]>>(
&self, &self,
receipt_data: R, receipt_data: R,
@ -527,6 +545,7 @@ impl NetworkManager {
} }
// Process a received signal // Process a received signal
#[instrument(level = "trace", skip(self), err)]
pub async fn handle_signal(&self, signal_info: SignalInfo) -> Result<(), String> { pub async fn handle_signal(&self, signal_info: SignalInfo) -> Result<(), String> {
match signal_info { match signal_info {
SignalInfo::ReverseConnect { receipt, peer_info } => { SignalInfo::ReverseConnect { receipt, peer_info } => {
@ -588,6 +607,7 @@ impl NetworkManager {
} }
// Builds an envelope for sending over the network // Builds an envelope for sending over the network
#[instrument(level = "trace", skip(self, body), err)]
fn build_envelope<B: AsRef<[u8]>>( fn build_envelope<B: AsRef<[u8]>>(
&self, &self,
dest_node_id: DHTKey, dest_node_id: DHTKey,
@ -614,6 +634,7 @@ impl NetworkManager {
// node_ref is the direct destination to which the envelope will be sent // node_ref is the direct destination to which the envelope will be sent
// If 'node_id' is specified, it can be different than node_ref.node_id() // If 'node_id' is specified, it can be different than node_ref.node_id()
// which will cause the envelope to be relayed // which will cause the envelope to be relayed
#[instrument(level = "trace", skip(self, body), ret, err)]
pub async fn send_envelope<B: AsRef<[u8]>>( pub async fn send_envelope<B: AsRef<[u8]>>(
&self, &self,
node_ref: NodeRef, node_ref: NodeRef,
@ -665,6 +686,7 @@ impl NetworkManager {
} }
// Called by the RPC handler when we want to issue an direct receipt // Called by the RPC handler when we want to issue an direct receipt
#[instrument(level = "trace", skip(self, rcpt_data), err)]
pub async fn send_out_of_band_receipt( pub async fn send_out_of_band_receipt(
&self, &self,
dial_info: DialInfo, dial_info: DialInfo,
@ -683,6 +705,7 @@ impl NetworkManager {
} }
// Figure out how to reach a node // Figure out how to reach a node
#[instrument(level = "trace", skip(self), ret, err)]
fn get_contact_method(&self, mut target_node_ref: NodeRef) -> Result<ContactMethod, String> { fn get_contact_method(&self, mut target_node_ref: NodeRef) -> Result<ContactMethod, String> {
let routing_table = self.routing_table(); let routing_table = self.routing_table();
@ -802,6 +825,7 @@ impl NetworkManager {
// Send a reverse connection signal and wait for the return receipt over it // Send a reverse connection signal and wait for the return receipt over it
// Then send the data across the new connection // Then send the data across the new connection
#[instrument(level = "trace", skip(self, data), err)]
pub async fn do_reverse_connect( pub async fn do_reverse_connect(
&self, &self,
relay_nr: NodeRef, relay_nr: NodeRef,
@ -872,6 +896,7 @@ impl NetworkManager {
// Send a hole punch signal and do a negotiating ping and wait for the return receipt // Send a hole punch signal and do a negotiating ping and wait for the return receipt
// Then send the data across the new connection // Then send the data across the new connection
#[instrument(level = "trace", skip(self, data), err)]
pub async fn do_hole_punch( pub async fn do_hole_punch(
&self, &self,
relay_nr: NodeRef, relay_nr: NodeRef,
@ -1036,6 +1061,7 @@ impl NetworkManager {
// Called when a packet potentially containing an RPC envelope is received by a low-level // Called when a packet potentially containing an RPC envelope is received by a low-level
// network protocol handler. Processes the envelope, authenticates and decrypts the RPC message // network protocol handler. Processes the envelope, authenticates and decrypts the RPC message
// and passes it to the RPC handler // and passes it to the RPC handler
#[instrument(level="trace", err, skip(self, data), fields(data.len = data.len()))]
async fn on_recv_envelope( async fn on_recv_envelope(
&self, &self,
data: &[u8], data: &[u8],
@ -1175,6 +1201,7 @@ impl NetworkManager {
} }
// Keep relays assigned and accessible // Keep relays assigned and accessible
#[instrument(level = "trace", skip(self), err)]
async fn relay_management_task_routine(self, _last_ts: u64, cur_ts: u64) -> Result<(), String> { async fn relay_management_task_routine(self, _last_ts: u64, cur_ts: u64) -> Result<(), String> {
// log_net!("--- network manager relay_management task"); // log_net!("--- network manager relay_management task");
@ -1227,6 +1254,7 @@ impl NetworkManager {
} }
// Compute transfer statistics for the low level network // Compute transfer statistics for the low level network
#[instrument(level = "trace", skip(self), err)]
async fn rolling_transfers_task_routine(self, last_ts: u64, cur_ts: u64) -> Result<(), String> { async fn rolling_transfers_task_routine(self, last_ts: u64, cur_ts: u64) -> Result<(), String> {
// log_net!("--- network manager rolling_transfers task"); // log_net!("--- network manager rolling_transfers task");
{ {

View File

@ -267,6 +267,7 @@ impl Network {
// This creates a short-lived connection in the case of connection-oriented protocols // This creates a short-lived connection in the case of connection-oriented protocols
// for the purpose of sending this one message. // for the purpose of sending this one message.
// This bypasses the connection table as it is not a 'node to node' connection. // This bypasses the connection table as it is not a 'node to node' connection.
#[instrument(level="trace", err, skip(self, data), fields(data.len = data.len()))]
pub async fn send_data_unbound_to_dial_info( pub async fn send_data_unbound_to_dial_info(
&self, &self,
dial_info: DialInfo, dial_info: DialInfo,
@ -300,6 +301,7 @@ impl Network {
res res
} }
#[instrument(level="trace", err, skip(self, data), fields(data.len = data.len()))]
pub async fn send_data_to_existing_connection( pub async fn send_data_to_existing_connection(
&self, &self,
descriptor: ConnectionDescriptor, descriptor: ConnectionDescriptor,
@ -357,6 +359,7 @@ impl Network {
} }
// Send data directly to a dial info, possibly without knowing which node it is going to // Send data directly to a dial info, possibly without knowing which node it is going to
#[instrument(level="trace", err, skip(self, data), fields(data.len = data.len()))]
pub async fn send_data_to_dial_info( pub async fn send_data_to_dial_info(
&self, &self,
dial_info: DialInfo, dial_info: DialInfo,
@ -404,9 +407,8 @@ impl Network {
self.inner.lock().protocol_config self.inner.lock().protocol_config
} }
#[instrument(level = "debug", err, skip_all)]
pub async fn startup(&self) -> Result<(), String> { pub async fn startup(&self) -> Result<(), String> {
trace!("startup network");
// initialize interfaces // initialize interfaces
let mut interfaces = NetworkInterfaces::new(); let mut interfaces = NetworkInterfaces::new();
interfaces.refresh().await?; interfaces.refresh().await?;
@ -492,10 +494,12 @@ impl Network {
self.inner.lock().network_started self.inner.lock().network_started
} }
#[instrument(level = "debug", skip_all)]
pub fn restart_network(&self) { pub fn restart_network(&self) {
self.inner.lock().network_needs_restart = true; self.inner.lock().network_needs_restart = true;
} }
#[instrument(level = "debug", skip_all)]
pub async fn shutdown(&self) { pub async fn shutdown(&self) {
info!("stopping network"); info!("stopping network");
@ -524,6 +528,7 @@ impl Network {
inner.network_class inner.network_class
} }
#[instrument(level = "debug", skip_all)]
pub fn reset_network_class(&self) { pub fn reset_network_class(&self) {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
inner.network_class = None; inner.network_class = None;

View File

@ -51,30 +51,30 @@ impl DiscoveryContext {
// Pick the best network class we have seen so far // Pick the best network class we have seen so far
pub fn set_detected_network_class(&self, network_class: NetworkClass) { pub fn set_detected_network_class(&self, network_class: NetworkClass) {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
log_net!( debug debug!(target: "net",
"=== set_detected_network_class {:?} {:?}: {:?} ===", protocol_type=?inner.protocol_type,
inner.protocol_type, address_type=?inner.address_type,
inner.address_type, ?network_class,
network_class "set_detected_network_class"
); );
inner.detected_network_class = Some(network_class); inner.detected_network_class = Some(network_class);
} }
pub fn set_detected_public_dial_info(&self, dial_info: DialInfo, class: DialInfoClass) { pub fn set_detected_public_dial_info(&self, dial_info: DialInfo, class: DialInfoClass) {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
log_net!( debug debug!(target: "net",
"=== set_detected_public_dial_info {:?} {:?}: {} {:?} ===", protocol_type=?inner.protocol_type,
inner.protocol_type, address_type=?inner.address_type,
inner.address_type, ?dial_info,
dial_info, ?class,
class "set_detected_public_dial_info"
); );
inner.detected_public_dial_info = Some(DetectedPublicDialInfo { dial_info, class }); inner.detected_public_dial_info = Some(DetectedPublicDialInfo { dial_info, class });
} }
// Ask for a public address check from a particular noderef // Ask for a public address check from a particular noderef
// This is done over the normal port using RPC // This is done over the normal port using RPC
#[instrument(level = "trace", skip(self), ret)]
async fn request_public_address(&self, node_ref: NodeRef) -> Option<SocketAddress> { async fn request_public_address(&self, node_ref: NodeRef) -> Option<SocketAddress> {
let rpc = self.routing_table.rpc_processor(); let rpc = self.routing_table.rpc_processor();
rpc.rpc_call_status(node_ref.clone()) rpc.rpc_call_status(node_ref.clone())
@ -93,6 +93,7 @@ impl DiscoveryContext {
// find fast peers with a particular address type, and ask them to tell us what our external address is // find fast peers with a particular address type, and ask them to tell us what our external address is
// This is done over the normal port using RPC // This is done over the normal port using RPC
#[instrument(level = "trace", skip(self), ret)]
async fn discover_external_address( async fn discover_external_address(
&self, &self,
protocol_type: ProtocolType, protocol_type: ProtocolType,
@ -122,6 +123,7 @@ impl DiscoveryContext {
} }
// This pulls the already-detected local interface dial info from the routing table // This pulls the already-detected local interface dial info from the routing table
#[instrument(level = "trace", skip(self), ret)]
fn get_local_addresses( fn get_local_addresses(
&self, &self,
protocol_type: ProtocolType, protocol_type: ProtocolType,
@ -143,6 +145,7 @@ impl DiscoveryContext {
.collect() .collect()
} }
#[instrument(level = "trace", skip(self), ret)]
async fn validate_dial_info( async fn validate_dial_info(
&self, &self,
node_ref: NodeRef, node_ref: NodeRef,
@ -165,6 +168,7 @@ impl DiscoveryContext {
.unwrap_or(false) .unwrap_or(false)
} }
#[instrument(level = "trace", skip(self), ret)]
async fn try_port_mapping(&self) -> Option<DialInfo> { async fn try_port_mapping(&self) -> Option<DialInfo> {
//xxx //xxx
None None
@ -189,6 +193,7 @@ impl DiscoveryContext {
/////// ///////
// Per-protocol discovery routines // Per-protocol discovery routines
#[instrument(level = "trace", skip(self))]
pub fn protocol_begin(&self, protocol_type: ProtocolType, address_type: AddressType) { pub fn protocol_begin(&self, protocol_type: ProtocolType, address_type: AddressType) {
// Get our interface addresses // Get our interface addresses
let intf_addrs = self.get_local_addresses(protocol_type, address_type); let intf_addrs = self.get_local_addresses(protocol_type, address_type);
@ -203,6 +208,7 @@ impl DiscoveryContext {
} }
// Get our first node's view of our external IP address via normal RPC // Get our first node's view of our external IP address via normal RPC
#[instrument(level = "trace", skip(self), ret)]
pub async fn protocol_get_external_address_1(&self) -> bool { pub async fn protocol_get_external_address_1(&self) -> bool {
let (protocol_type, address_type) = { let (protocol_type, address_type) = {
let inner = self.inner.lock(); let inner = self.inner.lock();
@ -234,6 +240,7 @@ impl DiscoveryContext {
} }
// If we know we are not behind NAT, check our firewall status // If we know we are not behind NAT, check our firewall status
#[instrument(level = "trace", skip(self), err)]
pub async fn protocol_process_no_nat(&self) -> Result<(), String> { pub async fn protocol_process_no_nat(&self) -> Result<(), String> {
let (node_1, external_1_dial_info) = { let (node_1, external_1_dial_info) = {
let inner = self.inner.lock(); let inner = self.inner.lock();
@ -264,6 +271,7 @@ impl DiscoveryContext {
} }
// If we know we are behind NAT check what kind // If we know we are behind NAT check what kind
#[instrument(level = "trace", skip(self), ret, err)]
pub async fn protocol_process_nat(&self) -> Result<bool, String> { pub async fn protocol_process_nat(&self) -> Result<bool, String> {
let (node_1, external_1_dial_info, external_1_address, protocol_type, address_type) = { let (node_1, external_1_dial_info, external_1_address, protocol_type, address_type) = {
let inner = self.inner.lock(); let inner = self.inner.lock();
@ -353,6 +361,7 @@ impl DiscoveryContext {
} }
impl Network { impl Network {
#[instrument(level = "trace", skip(self, context), err)]
pub async fn update_ipv4_protocol_dialinfo( pub async fn update_ipv4_protocol_dialinfo(
&self, &self,
context: &DiscoveryContext, context: &DiscoveryContext,
@ -414,6 +423,7 @@ impl Network {
Ok(()) Ok(())
} }
#[instrument(level = "trace", skip(self, context), err)]
pub async fn update_ipv6_protocol_dialinfo( pub async fn update_ipv6_protocol_dialinfo(
&self, &self,
context: &DiscoveryContext, context: &DiscoveryContext,
@ -454,9 +464,8 @@ impl Network {
Ok(()) Ok(())
} }
#[instrument(level = "trace", skip(self), err)]
pub async fn update_network_class_task_routine(self, _l: u64, _t: u64) -> Result<(), String> { pub async fn update_network_class_task_routine(self, _l: u64, _t: u64) -> Result<(), String> {
log_net!("--- updating network class");
// Ensure we aren't trying to update this without clearing it first // Ensure we aren't trying to update this without clearing it first
let old_network_class = self.inner.lock().network_class; let old_network_class = self.inner.lock().network_class;
assert_eq!(old_network_class, None); assert_eq!(old_network_class, None);

View File

@ -51,6 +51,7 @@ impl Network {
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
#[instrument(level="trace", err, skip(self, data), fields(data.len = data.len()))]
pub async fn send_data_unbound_to_dial_info( pub async fn send_data_unbound_to_dial_info(
&self, &self,
dial_info: DialInfo, dial_info: DialInfo,
@ -79,6 +80,7 @@ impl Network {
res res
} }
#[instrument(level="trace", err, skip(self, data), fields(data.len = data.len()))]
pub async fn send_data_to_existing_connection( pub async fn send_data_to_existing_connection(
&self, &self,
descriptor: ConnectionDescriptor, descriptor: ConnectionDescriptor,
@ -115,6 +117,7 @@ impl Network {
} }
} }
#[instrument(level="trace", err, skip(self, data), fields(data.len = data.len()))]
pub async fn send_data_to_dial_info( pub async fn send_data_to_dial_info(
&self, &self,
dial_info: DialInfo, dial_info: DialInfo,

View File

@ -234,6 +234,7 @@ impl ReceiptManager {
} }
} }
#[instrument(level = "trace", skip(self))]
pub async fn timeout_task_routine(self, now: u64) { pub async fn timeout_task_routine(self, now: u64) {
// Go through all receipts and build a list of expired nonces // Go through all receipts and build a list of expired nonces
let mut new_next_oldest_ts: Option<u64> = None; let mut new_next_oldest_ts: Option<u64> = None;

View File

@ -730,6 +730,7 @@ impl RoutingTable {
best_inbound_relay.map(|(k, e)| NodeRef::new(self.clone(), *k, e, None)) best_inbound_relay.map(|(k, e)| NodeRef::new(self.clone(), *k, e, None))
} }
#[instrument(level = "trace", skip(self), ret, err)]
pub fn register_find_node_answer(&self, fna: FindNodeAnswer) -> Result<Vec<NodeRef>, String> { pub fn register_find_node_answer(&self, fna: FindNodeAnswer) -> Result<Vec<NodeRef>, String> {
let node_id = self.node_id(); let node_id = self.node_id();
@ -755,6 +756,7 @@ impl RoutingTable {
Ok(out) Ok(out)
} }
#[instrument(level = "trace", skip(self), ret, err)]
pub async fn find_node( pub async fn find_node(
&self, &self,
node_ref: NodeRef, node_ref: NodeRef,
@ -773,26 +775,24 @@ impl RoutingTable {
.await .await
.map_err(map_to_string) .map_err(map_to_string)
.map_err(logthru_rtab!())?; .map_err(logthru_rtab!())?;
log_rtab!(
"find_self for at {:?} answered in {}ms",
&node_ref,
timestamp_to_secs(res.latency) * 1000.0f64
);
// register nodes we'd found // register nodes we'd found
self.register_find_node_answer(res) self.register_find_node_answer(res)
} }
#[instrument(level = "trace", skip(self), ret, err)]
pub async fn find_self(&self, node_ref: NodeRef) -> Result<Vec<NodeRef>, String> { pub async fn find_self(&self, node_ref: NodeRef) -> Result<Vec<NodeRef>, String> {
let node_id = self.node_id(); let node_id = self.node_id();
self.find_node(node_ref, node_id).await self.find_node(node_ref, node_id).await
} }
#[instrument(level = "trace", skip(self), ret, err)]
pub async fn find_target(&self, node_ref: NodeRef) -> Result<Vec<NodeRef>, String> { pub async fn find_target(&self, node_ref: NodeRef) -> Result<Vec<NodeRef>, String> {
let node_id = node_ref.node_id(); let node_id = node_ref.node_id();
self.find_node(node_ref, node_id).await self.find_node(node_ref, node_id).await
} }
#[instrument(level = "trace", skip(self))]
pub async fn reverse_find_node(&self, node_ref: NodeRef, wide: bool) { pub async fn reverse_find_node(&self, node_ref: NodeRef, wide: bool) {
// Ask bootstrap node to 'find' our own node so we can get some more nodes near ourselves // Ask bootstrap node to 'find' our own node so we can get some more nodes near ourselves
// and then contact those nodes to inform -them- that we exist // and then contact those nodes to inform -them- that we exist
@ -827,6 +827,7 @@ impl RoutingTable {
} }
// Bootstrap lookup process // Bootstrap lookup process
#[instrument(level = "trace", skip(self), ret, err)]
async fn resolve_bootstrap( async fn resolve_bootstrap(
&self, &self,
bootstrap: Vec<String>, bootstrap: Vec<String>,
@ -990,6 +991,7 @@ impl RoutingTable {
Ok(bsmap) Ok(bsmap)
} }
#[instrument(level = "trace", skip(self), err)]
async fn bootstrap_task_routine(self) -> Result<(), String> { async fn bootstrap_task_routine(self) -> Result<(), String> {
let (bootstrap, bootstrap_nodes) = { let (bootstrap, bootstrap_nodes) = {
let c = self.config.get(); let c = self.config.get();
@ -1092,9 +1094,8 @@ impl RoutingTable {
// Ask our remaining peers to give us more peers before we go // Ask our remaining peers to give us more peers before we go
// back to the bootstrap servers to keep us from bothering them too much // back to the bootstrap servers to keep us from bothering them too much
#[instrument(level = "trace", skip(self), err)]
async fn peer_minimum_refresh_task_routine(self) -> Result<(), String> { async fn peer_minimum_refresh_task_routine(self) -> Result<(), String> {
// log_rtab!("--- peer_minimum_refresh task");
// get list of all peers we know about, even the unreliable ones, and ask them to find nodes close to our node too // get list of all peers we know about, even the unreliable ones, and ask them to find nodes close to our node too
let noderefs = { let noderefs = {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
@ -1125,6 +1126,7 @@ impl RoutingTable {
// Ping each node in the routing table if they need to be pinged // Ping each node in the routing table if they need to be pinged
// to determine their reliability // to determine their reliability
#[instrument(level = "trace", skip(self), err)]
async fn ping_validator_task_routine(self, _last_ts: u64, cur_ts: u64) -> Result<(), String> { async fn ping_validator_task_routine(self, _last_ts: u64, cur_ts: u64) -> Result<(), String> {
// log_rtab!("--- ping_validator task"); // log_rtab!("--- ping_validator task");
@ -1149,6 +1151,7 @@ impl RoutingTable {
} }
// Compute transfer statistics to determine how 'fast' a node is // Compute transfer statistics to determine how 'fast' a node is
#[instrument(level = "trace", skip(self), err)]
async fn rolling_transfers_task_routine(self, last_ts: u64, cur_ts: u64) -> Result<(), String> { async fn rolling_transfers_task_routine(self, last_ts: u64, cur_ts: u64) -> Result<(), String> {
// log_rtab!("--- rolling_transfers task"); // log_rtab!("--- rolling_transfers task");
let inner = &mut *self.inner.lock(); let inner = &mut *self.inner.lock();

View File

@ -1742,6 +1742,7 @@ pub struct VeilidAPI {
} }
impl VeilidAPI { impl VeilidAPI {
#[instrument(skip_all)]
pub(crate) fn new(context: VeilidCoreContext) -> Self { pub(crate) fn new(context: VeilidCoreContext) -> Self {
Self { Self {
inner: Arc::new(Mutex::new(VeilidAPIInner { inner: Arc::new(Mutex::new(VeilidAPIInner {
@ -1750,6 +1751,7 @@ impl VeilidAPI {
} }
} }
#[instrument(skip_all)]
pub async fn shutdown(self) { pub async fn shutdown(self) {
let context = { self.inner.lock().context.take() }; let context = { self.inner.lock().context.take() };
if let Some(context) = context { if let Some(context) = context {
@ -1840,6 +1842,7 @@ impl VeilidAPI {
// get network connectedness // get network connectedness
// connect to the network // connect to the network
#[instrument(level = "debug", err, skip_all)]
pub async fn attach(&self) -> Result<(), VeilidAPIError> { pub async fn attach(&self) -> Result<(), VeilidAPIError> {
let attachment_manager = self.attachment_manager()?; let attachment_manager = self.attachment_manager()?;
attachment_manager attachment_manager
@ -1849,6 +1852,7 @@ impl VeilidAPI {
} }
// disconnect from the network // disconnect from the network
#[instrument(level = "debug", err, skip_all)]
pub async fn detach(&self) -> Result<(), VeilidAPIError> { pub async fn detach(&self) -> Result<(), VeilidAPIError> {
let attachment_manager = self.attachment_manager()?; let attachment_manager = self.attachment_manager()?;
attachment_manager attachment_manager
@ -1858,6 +1862,7 @@ impl VeilidAPI {
} }
// Change api logging level if it is enabled // Change api logging level if it is enabled
#[instrument(skip(self))]
pub async fn change_api_log_level(&self, log_level: VeilidConfigLogLevel) { pub async fn change_api_log_level(&self, log_level: VeilidConfigLogLevel) {
ApiTracingLayer::change_api_log_level(log_level.to_veilid_log_level()); ApiTracingLayer::change_api_log_level(log_level.to_veilid_log_level());
} }
@ -1865,6 +1870,7 @@ impl VeilidAPI {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Direct Node Access (pretty much for testing only) // Direct Node Access (pretty much for testing only)
#[instrument(level = "debug", err, skip(self))]
pub async fn status(&self, node_id: NodeId) -> Result<StatusAnswer, VeilidAPIError> { pub async fn status(&self, node_id: NodeId) -> Result<StatusAnswer, VeilidAPIError> {
let rpc = self.rpc_processor()?; let rpc = self.rpc_processor()?;
let routing_table = rpc.routing_table(); let routing_table = rpc.routing_table();
@ -1879,6 +1885,7 @@ impl VeilidAPI {
Ok(status_answer) Ok(status_answer)
} }
#[instrument(level = "debug", err, skip(self))]
pub async fn validate_dial_info( pub async fn validate_dial_info(
&self, &self,
node_id: NodeId, node_id: NodeId,
@ -1896,6 +1903,7 @@ impl VeilidAPI {
.map_err(map_rpc_error!()) .map_err(map_rpc_error!())
} }
#[instrument(level = "debug", err, skip(self))]
pub async fn search_dht(&self, node_id: NodeId) -> Result<PeerInfo, VeilidAPIError> { pub async fn search_dht(&self, node_id: NodeId) -> Result<PeerInfo, VeilidAPIError> {
let rpc_processor = self.rpc_processor()?; let rpc_processor = self.rpc_processor()?;
let config = self.config()?; let config = self.config()?;
@ -1923,6 +1931,7 @@ impl VeilidAPI {
} }
} }
#[instrument(level = "debug", err, skip(self))]
pub async fn search_dht_multi(&self, node_id: NodeId) -> Result<Vec<PeerInfo>, VeilidAPIError> { pub async fn search_dht_multi(&self, node_id: NodeId) -> Result<Vec<PeerInfo>, VeilidAPIError> {
let rpc_processor = self.rpc_processor()?; let rpc_processor = self.rpc_processor()?;
let config = self.config()?; let config = self.config()?;
@ -1948,6 +1957,7 @@ impl VeilidAPI {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Safety / Private Route Handling // Safety / Private Route Handling
#[instrument(level = "debug", err, skip(self))]
pub async fn new_safety_route_spec( pub async fn new_safety_route_spec(
&self, &self,
_hops: u8, _hops: u8,
@ -1955,6 +1965,7 @@ impl VeilidAPI {
panic!("unimplemented"); panic!("unimplemented");
} }
#[instrument(level = "debug", err, skip(self))]
pub async fn new_private_route_spec( pub async fn new_private_route_spec(
&self, &self,
_hops: u8, _hops: u8,
@ -1968,6 +1979,7 @@ impl VeilidAPI {
// Safety route specified here is for _this_ node's anonymity as a sender, used via the 'route' operation // Safety route specified here is for _this_ node's anonymity as a sender, used via the 'route' operation
// Private route specified here is for _this_ node's anonymity as a receiver, passed out via the 'respond_to' field for replies // Private route specified here is for _this_ node's anonymity as a receiver, passed out via the 'respond_to' field for replies
#[instrument(skip(self))]
pub async fn safe_private( pub async fn safe_private(
&self, &self,
safety_route_spec: SafetyRouteSpec, safety_route_spec: SafetyRouteSpec,
@ -1980,6 +1992,7 @@ impl VeilidAPI {
.await .await
} }
#[instrument(level = "debug", skip(self))]
pub async fn safe_public(&self, safety_route_spec: SafetyRouteSpec) -> RoutingContext { pub async fn safe_public(&self, safety_route_spec: SafetyRouteSpec) -> RoutingContext {
self.routing_context(RoutingContextOptions { self.routing_context(RoutingContextOptions {
safety_route_spec: Some(safety_route_spec), safety_route_spec: Some(safety_route_spec),
@ -1988,6 +2001,7 @@ impl VeilidAPI {
.await .await
} }
#[instrument(level = "debug", skip(self))]
pub async fn unsafe_private(&self, private_route_spec: PrivateRouteSpec) -> RoutingContext { pub async fn unsafe_private(&self, private_route_spec: PrivateRouteSpec) -> RoutingContext {
self.routing_context(RoutingContextOptions { self.routing_context(RoutingContextOptions {
safety_route_spec: None, safety_route_spec: None,
@ -1996,6 +2010,7 @@ impl VeilidAPI {
.await .await
} }
#[instrument(level = "debug", skip(self))]
pub async fn unsafe_public(&self) -> RoutingContext { pub async fn unsafe_public(&self) -> RoutingContext {
self.routing_context(RoutingContextOptions { self.routing_context(RoutingContextOptions {
safety_route_spec: None, safety_route_spec: None,
@ -2003,6 +2018,8 @@ impl VeilidAPI {
}) })
.await .await
} }
#[instrument(level = "debug", skip(self))]
pub async fn routing_context(&self, options: RoutingContextOptions) -> RoutingContext { pub async fn routing_context(&self, options: RoutingContextOptions) -> RoutingContext {
RoutingContext::new(self.clone(), options) RoutingContext::new(self.clone(), options)
} }
@ -2010,6 +2027,7 @@ impl VeilidAPI {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// Tunnel Building // Tunnel Building
#[instrument(level = "debug", err, skip(self))]
pub async fn start_tunnel( pub async fn start_tunnel(
&self, &self,
_endpoint_mode: TunnelMode, _endpoint_mode: TunnelMode,
@ -2018,6 +2036,7 @@ impl VeilidAPI {
panic!("unimplemented"); panic!("unimplemented");
} }
#[instrument(level = "debug", err, skip(self))]
pub async fn complete_tunnel( pub async fn complete_tunnel(
&self, &self,
_endpoint_mode: TunnelMode, _endpoint_mode: TunnelMode,
@ -2027,6 +2046,7 @@ impl VeilidAPI {
panic!("unimplemented"); panic!("unimplemented");
} }
#[instrument(level = "debug", err, skip(self))]
pub async fn cancel_tunnel(&self, _tunnel_id: TunnelId) -> Result<bool, VeilidAPIError> { pub async fn cancel_tunnel(&self, _tunnel_id: TunnelId) -> Result<bool, VeilidAPIError> {
panic!("unimplemented"); panic!("unimplemented");
} }

View File

@ -1,24 +1,40 @@
use super::*; use super::*;
use core::fmt::Debug;
pub fn deserialize_json<'a, T: de::Deserialize<'a>>( #[instrument(level = "trace", ret, err)]
pub fn deserialize_json<'a, T: de::Deserialize<'a> + Debug>(
arg: &'a str, arg: &'a str,
) -> Result<T, super::VeilidAPIError> { ) -> Result<T, VeilidAPIError> {
serde_json::from_str(arg).map_err(|e| VeilidAPIError::ParseError { serde_json::from_str(arg).map_err(|e| VeilidAPIError::ParseError {
message: e.to_string(), message: e.to_string(),
value: String::new(), value: format!(
"deserialize_json:\n---\n{}\n---\n to type {}",
arg,
std::any::type_name::<T>()
),
}) })
} }
pub fn deserialize_opt_json<T: de::DeserializeOwned>( #[instrument(level = "trace", ret, err)]
pub fn deserialize_opt_json<T: de::DeserializeOwned + Debug>(
arg: Option<String>, arg: Option<String>,
) -> Result<T, VeilidAPIError> { ) -> Result<T, VeilidAPIError> {
let arg = arg.ok_or_else(|| VeilidAPIError::ParseError { let arg = arg.as_ref().ok_or_else(|| VeilidAPIError::ParseError {
message: "invalid null string".to_owned(), message: "invalid null string".to_owned(),
value: String::new(), value: format!(
"deserialize_json_opt: null to type {}",
std::any::type_name::<T>()
),
})?; })?;
deserialize_json(&arg) deserialize_json(arg)
} }
pub fn serialize_json<T: Serialize>(val: T) -> String { #[instrument(level = "trace", ret)]
serde_json::to_string(&val).expect("failed to serialize json value") pub fn serialize_json<T: Serialize + Debug>(val: T) -> String {
match serde_json::to_string(&val) {
Ok(v) => v,
Err(e) => {
panic!("failed to serialize json value: {}\nval={:?}", e, val);
}
}
} }

View File

@ -237,6 +237,15 @@ pub struct VeilidConfig {
inner: Arc<RwLock<VeilidConfigInner>>, inner: Arc<RwLock<VeilidConfigInner>>,
} }
impl fmt::Debug for VeilidConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let inner = self.inner.read();
f.debug_struct("VeilidConfig")
.field("inner", &*inner)
.finish()
}
}
impl Default for VeilidConfig { impl Default for VeilidConfig {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new()

View File

@ -7,7 +7,7 @@ Future<VeilidConfig> getDefaultVeilidConfig() async {
return VeilidConfig( return VeilidConfig(
programName: "Veilid Plugin Test", programName: "Veilid Plugin Test",
namespace: "", namespace: "",
logLevel: VeilidConfigLogLevel.info, apiLogLevel: VeilidConfigLogLevel.info,
capabilities: VeilidConfigCapabilities( capabilities: VeilidConfigCapabilities(
protocolUDP: !kIsWeb, protocolUDP: !kIsWeb,
protocolConnectTCP: !kIsWeb, protocolConnectTCP: !kIsWeb,

View File

@ -36,8 +36,28 @@ LogOptions getLogOptions(LogLevel? level) {
); );
} }
VeilidConfigLogLevel convertToVeilidConfigLogLevel(LogLevel? level) {
if (level == null) {
return VeilidConfigLogLevel.off;
}
switch (level) {
case LogLevel.error:
return VeilidConfigLogLevel.error;
case LogLevel.warning:
return VeilidConfigLogLevel.warn;
case LogLevel.info:
return VeilidConfigLogLevel.info;
case LogLevel.debug:
return VeilidConfigLogLevel.debug;
case traceLevel:
return VeilidConfigLogLevel.trace;
}
return VeilidConfigLogLevel.off;
}
void setRootLogLevel(LogLevel? level) { void setRootLogLevel(LogLevel? level) {
Loggy('').level = getLogOptions(level); Loggy('').level = getLogOptions(level);
Veilid.instance.changeApiLogLevel(convertToVeilidConfigLogLevel(level));
} }
void initLoggy() { void initLoggy() {
@ -138,7 +158,7 @@ class _MyAppState extends State<MyApp> with UiLoggy {
if (update is VeilidUpdateLog) { if (update is VeilidUpdateLog) {
await processUpdateLog(update); await processUpdateLog(update);
} else { } else {
loggy.trace("Update: " + update.toString()); loggy.trace("Update: " + update.json.toString());
} }
} }
} }

View File

@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
veilid veilid
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST
)
set(PLUGIN_BUNDLED_LIBRARIES) set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST}) foreach(plugin ${FLUTTER_PLUGIN_LIST})
@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>) list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin) endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)

View File

@ -21,8 +21,8 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424
path_provider_macos: 160cab0d5461f0c0e02995469a98f24bdb9a3f1f path_provider_macos: 160cab0d5461f0c0e02995469a98f24bdb9a3f1f
veilid: f6b04d095ac7058ddf9c00215eb2699de8cc4673 veilid: 6bed3adec63fd8708a2ace498e0e17941c9fc32b
PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c
COCOAPODS: 1.11.2 COCOAPODS: 1.11.3

View File

@ -49,7 +49,7 @@ packages:
name: collection name: collection
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0" version: "1.16.0"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -63,7 +63,7 @@ packages:
name: fake_async name: fake_async
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" version: "1.3.0"
ffi: ffi:
dependency: transitive dependency: transitive
description: description:
@ -113,7 +113,7 @@ packages:
name: js name: js
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.6.3" version: "0.6.4"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@ -141,7 +141,7 @@ packages:
name: material_color_utilities name: material_color_utilities
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.3" version: "0.1.4"
meta: meta:
dependency: transitive dependency: transitive
description: description:
@ -155,7 +155,7 @@ packages:
name: path name: path
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.1"
path_provider: path_provider:
dependency: transitive dependency: transitive
description: description:
@ -244,7 +244,7 @@ packages:
name: source_span name: source_span
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.2"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -279,21 +279,14 @@ packages:
name: test_api name: test_api
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.8" version: "0.4.9"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:
name: vector_math name: vector_math
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.1" version: "2.1.2"
veilid: veilid:
dependency: "direct main" dependency: "direct main"
description: description:
@ -316,5 +309,5 @@ packages:
source: hosted source: hosted
version: "0.2.0+1" version: "0.2.0+1"
sdks: sdks:
dart: ">=2.16.1 <3.0.0" dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.8.0" flutter: ">=2.8.0"

View File

@ -6,6 +6,9 @@ list(APPEND FLUTTER_PLUGIN_LIST
veilid veilid
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST
)
set(PLUGIN_BUNDLED_LIBRARIES) set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST}) foreach(plugin ${FLUTTER_PLUGIN_LIST})
@ -14,3 +17,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>) list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin) endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)

View File

@ -33,8 +33,8 @@ Veilid Network Plugin
s.script_phase = { s.script_phase = {
:name => 'Cargo Build', :name => 'Cargo Build',
:script => File.join(File.dirname(__dir__), 'rust', 'ios_build.sh'), :script => File.join(File.dirname(__dir__), 'rust', 'ios_build.sh'),
:execution_position => :before_compile, :execution_position => :before_compile
:output_files => [ File.join(cargo_target_dir, 'ios_lib', 'libveilid_flutter.a') ] # :output_files => [ File.join(cargo_target_dir, 'ios_lib', 'libveilid_flutter.a') ]
} }
end end

View File

@ -815,6 +815,7 @@ abstract class VeilidUpdate {
} }
} }
} }
Map<String, dynamic> get json;
} }
class VeilidUpdateLog implements VeilidUpdate { class VeilidUpdateLog implements VeilidUpdate {
@ -822,12 +823,29 @@ class VeilidUpdateLog implements VeilidUpdate {
final String message; final String message;
// //
VeilidUpdateLog(this.logLevel, this.message); VeilidUpdateLog(this.logLevel, this.message);
@override
Map<String, dynamic> get json {
return {
'kind': "Log",
'log_level': logLevel.json,
'message': message,
};
}
} }
class VeilidUpdateAttachment implements VeilidUpdate { class VeilidUpdateAttachment implements VeilidUpdate {
final AttachmentState state; final AttachmentState state;
// //
VeilidUpdateAttachment(this.state); VeilidUpdateAttachment(this.state);
@override
Map<String, dynamic> get json {
return {
'kind': "Attachment",
'state': state.json,
};
}
} }
class VeilidUpdateNetwork implements VeilidUpdate { class VeilidUpdateNetwork implements VeilidUpdate {
@ -836,6 +854,16 @@ class VeilidUpdateNetwork implements VeilidUpdate {
final int bpsUp; final int bpsUp;
// //
VeilidUpdateNetwork(this.started, this.bpsDown, this.bpsUp); VeilidUpdateNetwork(this.started, this.bpsDown, this.bpsUp);
@override
Map<String, dynamic> get json {
return {
'kind': "Network",
'started': started,
'bps_down': bpsDown,
'bps_up': bpsUp
};
}
} }
////////////////////////////////////// //////////////////////////////////////

View File

@ -300,7 +300,9 @@ class VeilidFFI implements Veilid {
@override @override
Future<void> changeApiLogLevel(VeilidConfigLogLevel logLevel) async { Future<void> changeApiLogLevel(VeilidConfigLogLevel logLevel) async {
var nativeLogLevel = logLevel.json.toNativeUtf8(); var nativeLogLevel =
jsonEncode(logLevel.json, toEncodable: veilidApiToEncodable)
.toNativeUtf8();
final recvPort = ReceivePort("change_api_log_level"); final recvPort = ReceivePort("change_api_log_level");
final sendPort = recvPort.sendPort; final sendPort = recvPort.sendPort;
_changeApiLogLevel(sendPort.nativePort, nativeLogLevel); _changeApiLogLevel(sendPort.nativePort, nativeLogLevel);

View File

@ -27,8 +27,8 @@ Veilid Network Plugin
s.script_phase = { s.script_phase = {
:name => 'Cargo Build', :name => 'Cargo Build',
:script => File.join(File.dirname(__dir__), 'rust', 'macos_build.sh'), :script => File.join(File.dirname(__dir__), 'rust', 'macos_build.sh'),
:execution_position => :before_compile, :execution_position => :before_compile
:output_files => [ File.join(cargo_target_dir, 'macos_lib', 'libveilid_flutter.dylib') ] #:output_files => [ File.join(cargo_target_dir, 'macos_lib', 'libveilid_flutter.dylib') ]
} }
end end

View File

@ -1,11 +1,13 @@
#!/bin/bash #!/bin/bash
set -e
echo Running veilid-flutter rust iOS build script
# Setup varaiables # Setup varaiables
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FLUTTER_DIR=$(dirname `which flutter`) FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`) HOMEBREW_DIR=$(dirname `which brew`)
CARGO_DIR=$(dirname `which cargo`) CARGO_DIR=$(dirname `which cargo`)
CARGO_MANIFEST_PATH=$(python -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))") CARGO_MANIFEST_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
# Configure outputs # Configure outputs
@ -30,7 +32,8 @@ do
if [ "$arch" == "arm64" ]; then if [ "$arch" == "arm64" ]; then
echo arm64 echo arm64
CARGO_TARGET=aarch64-apple-ios CARGO_TARGET=aarch64-apple-ios
CARGO_TOOLCHAIN=+ios-arm64-1.57.0 #CARGO_TOOLCHAIN=+ios-arm64-1.57.0
CARGO_TOOLCHAIN=
elif [ "$arch" == "x86_64" ]; then elif [ "$arch" == "x86_64" ]; then
echo x86_64 echo x86_64
CARGO_TARGET=x86_64-apple-ios CARGO_TARGET=x86_64-apple-ios

View File

@ -1,11 +1,13 @@
#!/bin/bash #!/bin/bash
set -e
echo Running veilid-flutter rust MacOS build script
# Setup varaiables # Setup varaiables
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FLUTTER_DIR=$(dirname `which flutter`) FLUTTER_DIR=$(dirname `which flutter`)
HOMEBREW_DIR=$(dirname `which brew`) HOMEBREW_DIR=$(dirname `which brew`)
CARGO_DIR=$(dirname `which cargo`) CARGO_DIR=$(dirname `which cargo`)
CARGO_MANIFEST_PATH=$(python -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))") CARGO_MANIFEST_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target TARGET_DIR=$(dirname `cargo locate-project --message-format plain`)/target
# Configure outputs # Configure outputs

View File

@ -54,6 +54,7 @@ macro_rules! check_err_json {
///////////////////////////////////////// /////////////////////////////////////////
// Initializer // Initializer
#[no_mangle] #[no_mangle]
#[instrument]
pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPostCObjectFnType) { pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPostCObjectFnType) {
unsafe { unsafe {
store_dart_post_cobject(dart_post_c_object_ptr); store_dart_post_cobject(dart_post_c_object_ptr);
@ -91,6 +92,7 @@ pub extern "C" fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPos
/// C-compatible FFI Functions /// C-compatible FFI Functions
#[no_mangle] #[no_mangle]
#[instrument]
pub extern "C" fn startup_veilid_core(port: i64, config: FfiStr) { pub extern "C" fn startup_veilid_core(port: i64, config: FfiStr) {
let config = config.into_opt_string(); let config = config.into_opt_string();
let stream = DartIsolateStream::new(port); let stream = DartIsolateStream::new(port);
@ -141,6 +143,7 @@ pub extern "C" fn get_veilid_state(port: i64) {
} }
#[no_mangle] #[no_mangle]
#[instrument(level = "debug")]
pub extern "C" fn change_api_log_level(port: i64, log_level: FfiStr) { pub extern "C" fn change_api_log_level(port: i64, log_level: FfiStr) {
let log_level = log_level.into_opt_string(); let log_level = log_level.into_opt_string();
DartIsolateWrapper::new(port).spawn_result_json(async move { DartIsolateWrapper::new(port).spawn_result_json(async move {
@ -153,6 +156,7 @@ pub extern "C" fn change_api_log_level(port: i64, log_level: FfiStr) {
} }
#[no_mangle] #[no_mangle]
#[instrument]
pub extern "C" fn shutdown_veilid_core(port: i64) { pub extern "C" fn shutdown_veilid_core(port: i64) {
DartIsolateWrapper::new(port).spawn_result_json(async move { DartIsolateWrapper::new(port).spawn_result_json(async move {
let veilid_api = take_veilid_api().await?; let veilid_api = take_veilid_api().await?;
@ -184,6 +188,7 @@ pub struct VeilidVersion {
} }
#[no_mangle] #[no_mangle]
#[instrument]
pub extern "C" fn veilid_version() -> VeilidVersion { pub extern "C" fn veilid_version() -> VeilidVersion {
let (major, minor, patch) = veilid_core::veilid_version(); let (major, minor, patch) = veilid_core::veilid_version();
VeilidVersion { VeilidVersion {

View File

@ -1,6 +1,7 @@
pub use allo_isolate::ffi::DartCObject; pub use allo_isolate::ffi::DartCObject;
pub use allo_isolate::IntoDart; pub use allo_isolate::IntoDart;
use allo_isolate::Isolate; use allo_isolate::Isolate;
use core::fmt::Debug;
use core::future::Future; use core::future::Future;
use parking_lot::Mutex; use parking_lot::Mutex;
use serde::*; use serde::*;
@ -31,8 +32,8 @@ impl DartIsolateWrapper {
pub fn spawn_result<F, T, E>(self, future: F) pub fn spawn_result<F, T, E>(self, future: F)
where where
F: Future<Output = Result<T, E>> + Send + 'static, F: Future<Output = Result<T, E>> + Send + 'static,
T: IntoDart, T: IntoDart + Debug,
E: Serialize, E: Serialize + Debug,
{ {
async_std::task::spawn(async move { async_std::task::spawn(async move {
self.result(future.await); self.result(future.await);
@ -42,21 +43,24 @@ impl DartIsolateWrapper {
pub fn spawn_result_json<F, T, E>(self, future: F) pub fn spawn_result_json<F, T, E>(self, future: F)
where where
F: Future<Output = Result<T, E>> + Send + 'static, F: Future<Output = Result<T, E>> + Send + 'static,
T: Serialize, T: Serialize + Debug,
E: Serialize, E: Serialize + Debug,
{ {
async_std::task::spawn(async move { async_std::task::spawn(async move {
self.result_json(future.await); self.result_json(future.await);
}); });
} }
pub fn result<T: IntoDart, E: Serialize>(self, result: Result<T, E>) -> bool { pub fn result<T: IntoDart + Debug, E: Serialize + Debug>(self, result: Result<T, E>) -> bool {
match result { match result {
Ok(v) => self.ok(v), Ok(v) => self.ok(v),
Err(e) => self.err_json(e), Err(e) => self.err_json(e),
} }
} }
pub fn result_json<T: Serialize, E: Serialize>(self, result: Result<T, E>) -> bool { pub fn result_json<T: Serialize + Debug, E: Serialize + Debug>(
self,
result: Result<T, E>,
) -> bool {
match result { match result {
Ok(v) => self.ok_json(v), Ok(v) => self.ok_json(v),
Err(e) => self.err_json(e), Err(e) => self.err_json(e),
@ -67,19 +71,19 @@ impl DartIsolateWrapper {
.post(vec![MESSAGE_OK.into_dart(), value.into_dart()]) .post(vec![MESSAGE_OK.into_dart(), value.into_dart()])
} }
pub fn ok_json<T: Serialize>(self, value: T) -> bool { pub fn ok_json<T: Serialize + Debug>(self, value: T) -> bool {
self.isolate.post(vec![ self.isolate.post(vec![
MESSAGE_OK_JSON.into_dart(), MESSAGE_OK_JSON.into_dart(),
veilid_core::serialize_json(value).into_dart(), veilid_core::serialize_json(value).into_dart(),
]) ])
} }
// pub fn err<E: IntoDart>(self, error: E) -> bool { // pub fn err<E: IntoDart + Debug>(self, error: E) -> bool {
// self.isolate // self.isolate
// .post(vec![MESSAGE_ERR.into_dart(), error.into_dart()]) // .post(vec![MESSAGE_ERR.into_dart(), error.into_dart()])
// } // }
pub fn err_json<E: Serialize>(self, error: E) -> bool { pub fn err_json<E: Serialize + Debug>(self, error: E) -> bool {
self.isolate.post(vec![ self.isolate.post(vec![
MESSAGE_ERR_JSON.into_dart(), MESSAGE_ERR_JSON.into_dart(),
veilid_core::serialize_json(error).into_dart(), veilid_core::serialize_json(error).into_dart(),
@ -122,7 +126,7 @@ impl DartIsolateStream {
// } // }
// } // }
pub fn item_json<T: Serialize>(&self, value: T) -> bool { pub fn item_json<T: Serialize + Debug>(&self, value: T) -> bool {
let inner = self.inner.lock(); let inner = self.inner.lock();
if let Some(isolate) = &inner.isolate { if let Some(isolate) = &inner.isolate {
isolate.post(vec![ isolate.post(vec![
@ -134,7 +138,7 @@ impl DartIsolateStream {
} }
} }
// pub fn abort<E: IntoDart>(self, error: E) -> bool { // pub fn abort<E: IntoDart + Debug>(self, error: E) -> bool {
// let mut inner = self.inner.lock(); // let mut inner = self.inner.lock();
// if let Some(isolate) = inner.isolate.take() { // if let Some(isolate) = inner.isolate.take() {
// isolate.post(vec![MESSAGE_STREAM_ABORT.into_dart(), error.into_dart()]) // isolate.post(vec![MESSAGE_STREAM_ABORT.into_dart(), error.into_dart()])
@ -143,7 +147,7 @@ impl DartIsolateStream {
// } // }
// } // }
pub fn abort_json<E: Serialize>(self, error: E) -> bool { pub fn abort_json<E: Serialize + Debug>(self, error: E) -> bool {
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
if let Some(isolate) = inner.isolate.take() { if let Some(isolate) = inner.isolate.take() {
isolate.post(vec![ isolate.post(vec![

View File

@ -73,6 +73,7 @@ struct VeilidServerImpl {
} }
impl VeilidServerImpl { impl VeilidServerImpl {
#[instrument(level = "trace", skip_all)]
pub fn new(veilid_api: veilid_core::VeilidAPI) -> Self { pub fn new(veilid_api: veilid_core::VeilidAPI) -> Self {
Self { Self {
next_id: 0, next_id: 0,
@ -83,6 +84,7 @@ impl VeilidServerImpl {
} }
impl veilid_server::Server for VeilidServerImpl { impl veilid_server::Server for VeilidServerImpl {
#[instrument(level = "trace", skip_all)]
fn register( fn register(
&mut self, &mut self,
params: veilid_server::RegisterParams, params: veilid_server::RegisterParams,
@ -126,6 +128,7 @@ impl veilid_server::Server for VeilidServerImpl {
}) })
} }
#[instrument(level = "trace", skip_all)]
fn debug( fn debug(
&mut self, &mut self,
params: veilid_server::DebugParams, params: veilid_server::DebugParams,
@ -145,6 +148,7 @@ impl veilid_server::Server for VeilidServerImpl {
}) })
} }
#[instrument(level = "trace", skip_all)]
fn attach( fn attach(
&mut self, &mut self,
_params: veilid_server::AttachParams, _params: veilid_server::AttachParams,
@ -160,6 +164,7 @@ impl veilid_server::Server for VeilidServerImpl {
}) })
} }
#[instrument(level = "trace", skip_all)]
fn detach( fn detach(
&mut self, &mut self,
_params: veilid_server::DetachParams, _params: veilid_server::DetachParams,
@ -175,6 +180,7 @@ impl veilid_server::Server for VeilidServerImpl {
}) })
} }
#[instrument(level = "trace", skip_all)]
fn shutdown( fn shutdown(
&mut self, &mut self,
_params: veilid_server::ShutdownParams, _params: veilid_server::ShutdownParams,
@ -194,6 +200,7 @@ impl veilid_server::Server for VeilidServerImpl {
Promise::ok(()) Promise::ok(())
} }
#[instrument(level = "trace", skip_all)]
fn get_state( fn get_state(
&mut self, &mut self,
_params: veilid_server::GetStateParams, _params: veilid_server::GetStateParams,
@ -239,6 +246,7 @@ pub struct ClientApi {
} }
impl ClientApi { impl ClientApi {
#[instrument(level = "trace", skip_all)]
pub fn new(veilid_api: veilid_core::VeilidAPI) -> Rc<Self> { pub fn new(veilid_api: veilid_core::VeilidAPI) -> Rc<Self> {
Rc::new(Self { Rc::new(Self {
inner: RefCell::new(ClientApiInner { inner: RefCell::new(ClientApiInner {
@ -250,6 +258,7 @@ impl ClientApi {
}) })
} }
#[instrument(level = "trace", skip(self))]
pub async fn stop(self: Rc<Self>) { pub async fn stop(self: Rc<Self>) {
trace!("ClientApi::stop requested"); trace!("ClientApi::stop requested");
let jh = { let jh = {
@ -268,6 +277,7 @@ impl ClientApi {
trace!("ClientApi::stop: stopped"); trace!("ClientApi::stop: stopped");
} }
#[instrument(level = "trace", skip(self, client), err)]
async fn handle_incoming( async fn handle_incoming(
self: Rc<Self>, self: Rc<Self>,
bind_addr: SocketAddr, bind_addr: SocketAddr,
@ -301,6 +311,7 @@ impl ClientApi {
incoming_loop.await incoming_loop.await
} }
#[instrument(level = "trace", skip_all)]
fn send_request_to_all_clients<F, T>(self: Rc<Self>, request: F) fn send_request_to_all_clients<F, T>(self: Rc<Self>, request: F)
where where
F: Fn(u64, &mut RegistrationHandle) -> Option<::capnp::capability::RemotePromise<T>>, F: Fn(u64, &mut RegistrationHandle) -> Option<::capnp::capability::RemotePromise<T>>,
@ -338,6 +349,7 @@ impl ClientApi {
} }
} }
#[instrument(level = "trace", skip(self))]
pub fn handle_update(self: Rc<Self>, veilid_update: veilid_core::VeilidUpdate) { pub fn handle_update(self: Rc<Self>, veilid_update: veilid_core::VeilidUpdate) {
// serialize update // serialize update
let veilid_update = serialize_json(veilid_update); let veilid_update = serialize_json(veilid_update);
@ -360,6 +372,7 @@ impl ClientApi {
}); });
} }
#[instrument(level = "trace", skip(self))]
pub fn run(self: Rc<Self>, bind_addrs: Vec<SocketAddr>) { pub fn run(self: Rc<Self>, bind_addrs: Vec<SocketAddr>) {
// Create client api VeilidServer // Create client api VeilidServer
let veilid_server_impl = VeilidServerImpl::new(self.inner.borrow().veilid_api.clone()); let veilid_server_impl = VeilidServerImpl::new(self.inner.borrow().veilid_api.clone());

View File

@ -15,6 +15,7 @@ mod windows;
use async_std::task; use async_std::task;
use cfg_if::*; use cfg_if::*;
use server::*; use server::*;
use tracing::*;
use veilid_logs::*; use veilid_logs::*;
#[allow(clippy::all)] #[allow(clippy::all)]
@ -22,6 +23,7 @@ pub mod veilid_client_capnp {
include!(concat!(env!("OUT_DIR"), "/proto/veilid_client_capnp.rs")); include!(concat!(env!("OUT_DIR"), "/proto/veilid_client_capnp.rs"));
} }
#[instrument(err)]
fn main() -> Result<(), String> { fn main() -> Result<(), String> {
#[cfg(windows)] #[cfg(windows)]
let _ = ansi_term::enable_ansi_support(); let _ = ansi_term::enable_ansi_support();

View File

@ -8,7 +8,7 @@ use std::time::{Duration, Instant};
use tracing::*; use tracing::*;
use veilid_core::xx::SingleShotEventual; use veilid_core::xx::SingleShotEventual;
#[derive(Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ServerMode { pub enum ServerMode {
Normal, Normal,
ShutdownImmediate, ShutdownImmediate,
@ -20,6 +20,7 @@ lazy_static! {
Mutex::new(Some(SingleShotEventual::new(Some(())))); Mutex::new(Some(SingleShotEventual::new(Some(()))));
} }
#[instrument]
pub fn shutdown() { pub fn shutdown() {
let shutdown_switch = SHUTDOWN_SWITCH.lock().take(); let shutdown_switch = SHUTDOWN_SWITCH.lock().take();
if let Some(shutdown_switch) = shutdown_switch { if let Some(shutdown_switch) = shutdown_switch {
@ -28,13 +29,10 @@ pub fn shutdown() {
} }
pub async fn run_veilid_server(settings: Settings, server_mode: ServerMode) -> Result<(), String> { pub async fn run_veilid_server(settings: Settings, server_mode: ServerMode) -> Result<(), String> {
run_veilid_server_internal(settings, server_mode) run_veilid_server_internal(settings, server_mode).await
.await
.map_err(|e| {
error!("{}", e);
e
})
} }
#[instrument(err)]
pub async fn run_veilid_server_internal( pub async fn run_veilid_server_internal(
settings: Settings, settings: Settings,
server_mode: ServerMode, server_mode: ServerMode,

View File

@ -7,7 +7,9 @@ use clap::ArgMatches;
use signal_hook::consts::signal::*; use signal_hook::consts::signal::*;
use signal_hook_async_std::Signals; use signal_hook_async_std::Signals;
use std::io::Read; use std::io::Read;
use tracing::*;
#[instrument(skip(signals))]
async fn handle_signals(mut signals: Signals) { async fn handle_signals(mut signals: Signals) {
while let Some(signal) = signals.next().await { while let Some(signal) = signals.next().await {
match signal { match signal {
@ -23,6 +25,7 @@ async fn handle_signals(mut signals: Signals) {
} }
} }
#[instrument(err)]
pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> Result<(), String> { pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> Result<(), String> {
let daemon = { let daemon = {
let mut daemon = daemonize::Daemonize::new(); let mut daemon = daemonize::Daemonize::new();