Update to NAT detection

This commit is contained in:
John Smith
2021-12-08 03:09:45 +00:00
parent 57e64413b5
commit fba3f5b5f3
25 changed files with 254 additions and 202 deletions

View File

@@ -107,8 +107,10 @@ impl veilid_server::Server for VeilidServerImpl {
// Send state update
let veilid_api = self.veilid_api.clone();
Promise::from_future(async move {
veilid_api.send_state_update().await;
Ok(())
veilid_api
.send_state_update()
.await
.map_err(|e| ::capnp::Error::failed(format!("{:?}", e)))
})
}
@@ -120,8 +122,10 @@ impl veilid_server::Server for VeilidServerImpl {
trace!("VeilidServerImpl::attach");
let veilid_api = self.veilid_api.clone();
Promise::from_future(async move {
veilid_api.attach().await;
Ok(())
veilid_api
.attach()
.await
.map_err(|e| ::capnp::Error::failed(format!("{:?}", e)))
})
}
fn detach(
@@ -132,8 +136,10 @@ impl veilid_server::Server for VeilidServerImpl {
trace!("VeilidServerImpl::detach");
let veilid_api = self.veilid_api.clone();
Promise::from_future(async move {
veilid_api.detach().await;
Ok(())
veilid_api
.detach()
.await
.map_err(|e| ::capnp::Error::failed(format!("{:?}", e)))
})
}
fn shutdown(

View File

@@ -1,5 +1,5 @@
#![forbid(unsafe_code)]
#![warn(clippy::all)]
#![deny(clippy::all)]
mod client_api;
mod settings;

View File

@@ -89,8 +89,8 @@ lazy_static! {
}
pub fn shutdown() {
let mut shutdown_switch_locked = SHUTDOWN_SWITCH.lock();
if let Some(shutdown_switch) = shutdown_switch_locked.take() {
let shutdown_switch = SHUTDOWN_SWITCH.lock().take();
if let Some(shutdown_switch) = shutdown_switch {
shutdown_switch.resolve(());
}
}
@@ -279,17 +279,22 @@ pub async fn main() -> Result<(), String> {
// Handle state changes on main thread for capnproto rpc
let capi2 = capi.clone();
let capi_jh = async_std::task::spawn_local(async move {
trace!("state change processing started");
while let Ok(change) = receiver.recv().await {
if let Some(c) = capi2.borrow_mut().as_mut().cloned() {
c.handle_state_change(change);
}
}
trace!("state change processing stopped");
});
// Auto-attach if desired
if auto_attach {
info!("Auto-attach to the Veilid network");
veilid_api.attach().await;
if let Err(e) = veilid_api.attach().await {
error!("Auto-attaching to the Veilid network failed: {:?}", e);
shutdown();
}
}
// Idle while waiting to exit