pr work
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::settings::*;
|
||||
use crate::tools::*;
|
||||
use crate::veilid_client_capnp::*;
|
||||
use crate::veilid_logs::VeilidLogs;
|
||||
@@ -81,18 +82,24 @@ impl registration::Server for RegistrationImpl {}
|
||||
struct VeilidServerImpl {
|
||||
veilid_api: veilid_core::VeilidAPI,
|
||||
veilid_logs: VeilidLogs,
|
||||
settings: Settings,
|
||||
next_id: u64,
|
||||
pub registration_map: Rc<RefCell<RegistrationMap>>,
|
||||
}
|
||||
|
||||
impl VeilidServerImpl {
|
||||
#[instrument(level = "trace", skip_all)]
|
||||
pub fn new(veilid_api: veilid_core::VeilidAPI, veilid_logs: VeilidLogs) -> Self {
|
||||
pub fn new(
|
||||
veilid_api: veilid_core::VeilidAPI,
|
||||
veilid_logs: VeilidLogs,
|
||||
settings: Settings,
|
||||
) -> Self {
|
||||
Self {
|
||||
next_id: 0,
|
||||
registration_map: Rc::new(RefCell::new(RegistrationMap::new())),
|
||||
veilid_api,
|
||||
veilid_logs,
|
||||
settings,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,6 +122,7 @@ impl veilid_server::Server for VeilidServerImpl {
|
||||
);
|
||||
|
||||
let veilid_api = self.veilid_api.clone();
|
||||
let settings = self.settings.clone();
|
||||
let registration = capnp_rpc::new_client(RegistrationImpl::new(
|
||||
self.next_id,
|
||||
self.registration_map.clone(),
|
||||
@@ -132,6 +140,14 @@ impl veilid_server::Server for VeilidServerImpl {
|
||||
res.set_registration(registration);
|
||||
res.set_state(&state);
|
||||
|
||||
let settings = &*settings.read();
|
||||
let settings_json_string = serialize_json(settings);
|
||||
let mut settings_json = json::parse(&settings_json_string)
|
||||
.map_err(|e| ::capnp::Error::failed(format!("{:?}", e)))?;
|
||||
settings_json["core"]["network"].remove("node_id_secret");
|
||||
let safe_settings_json = settings_json.to_string();
|
||||
res.set_settings(&safe_settings_json);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -265,6 +281,7 @@ type ClientApiAllFuturesJoinHandle =
|
||||
struct ClientApiInner {
|
||||
veilid_api: veilid_core::VeilidAPI,
|
||||
veilid_logs: VeilidLogs,
|
||||
settings: Settings,
|
||||
registration_map: Rc<RefCell<RegistrationMap>>,
|
||||
stop: Option<StopSource>,
|
||||
join_handle: Option<ClientApiAllFuturesJoinHandle>,
|
||||
@@ -276,11 +293,16 @@ pub struct ClientApi {
|
||||
|
||||
impl ClientApi {
|
||||
#[instrument(level = "trace", skip_all)]
|
||||
pub fn new(veilid_api: veilid_core::VeilidAPI, veilid_logs: VeilidLogs) -> Rc<Self> {
|
||||
pub fn new(
|
||||
veilid_api: veilid_core::VeilidAPI,
|
||||
veilid_logs: VeilidLogs,
|
||||
settings: Settings,
|
||||
) -> Rc<Self> {
|
||||
Rc::new(Self {
|
||||
inner: RefCell::new(ClientApiInner {
|
||||
veilid_api,
|
||||
veilid_logs,
|
||||
settings,
|
||||
registration_map: Rc::new(RefCell::new(RegistrationMap::new())),
|
||||
stop: Some(StopSource::new()),
|
||||
join_handle: None,
|
||||
@@ -427,6 +449,7 @@ impl ClientApi {
|
||||
let veilid_server_impl = VeilidServerImpl::new(
|
||||
self.inner.borrow().veilid_api.clone(),
|
||||
self.inner.borrow().veilid_logs.clone(),
|
||||
self.inner.borrow().settings.clone(),
|
||||
);
|
||||
self.inner.borrow_mut().registration_map = veilid_server_impl.registration_map.clone();
|
||||
|
||||
|
@@ -301,6 +301,7 @@ pub fn process_command_line() -> EyreResult<(Settings, ArgMatches)> {
|
||||
settingsrw.core.network.bootstrap_nodes = bootstrap_list;
|
||||
}
|
||||
|
||||
#[cfg(feature = "rt-tokio")]
|
||||
if matches.occurrences_of("console") != 0 {
|
||||
settingsrw.logging.console.enabled = true;
|
||||
}
|
||||
|
@@ -4,6 +4,8 @@ use crate::tools::*;
|
||||
use crate::veilid_logs::*;
|
||||
use crate::*;
|
||||
use flume::{unbounded, Receiver, Sender};
|
||||
use futures_util::select;
|
||||
use futures_util::FutureExt;
|
||||
use lazy_static::*;
|
||||
use parking_lot::Mutex;
|
||||
use std::sync::Arc;
|
||||
@@ -70,7 +72,8 @@ pub async fn run_veilid_server_internal(
|
||||
|
||||
// Start client api if one is requested
|
||||
let mut capi = if settingsr.client_api.enabled && matches!(server_mode, ServerMode::Normal) {
|
||||
let some_capi = client_api::ClientApi::new(veilid_api.clone(), veilid_logs.clone());
|
||||
let some_capi =
|
||||
client_api::ClientApi::new(veilid_api.clone(), veilid_logs.clone(), settings.clone());
|
||||
some_capi
|
||||
.clone()
|
||||
.run(settingsr.client_api.listen_address.addrs.clone());
|
||||
@@ -85,12 +88,29 @@ pub async fn run_veilid_server_internal(
|
||||
|
||||
// Process all updates
|
||||
let capi2 = capi.clone();
|
||||
let mut shutdown_switch = {
|
||||
let shutdown_switch_locked = SHUTDOWN_SWITCH.lock();
|
||||
(*shutdown_switch_locked).as_ref().map(|ss| ss.instance())
|
||||
}
|
||||
.unwrap()
|
||||
.fuse();
|
||||
let update_receiver_jh = spawn_local(async move {
|
||||
while let Ok(change) = receiver.recv_async().await {
|
||||
if let Some(capi) = &capi2 {
|
||||
// Handle state changes on main thread for capnproto rpc
|
||||
capi.clone().handle_update(change);
|
||||
}
|
||||
loop {
|
||||
select! {
|
||||
res = receiver.recv_async() => {
|
||||
if let Ok(change) = res {
|
||||
if let Some(capi) = &capi2 {
|
||||
// Handle state changes on main thread for capnproto rpc
|
||||
capi.clone().handle_update(change);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_ = shutdown_switch => {
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user