mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-11-21 16:37:39 -06:00
fix attachment update
This commit is contained in:
parent
05a9ee754e
commit
98a20f5921
@ -126,8 +126,6 @@ impl CommandProcessor {
|
||||
exit/quit exit the client
|
||||
disconnect disconnect the client from the Veilid node
|
||||
shutdown shut the server down
|
||||
attach attach the server to the Veilid network
|
||||
detach detach the server from the Veilid network
|
||||
change_log_level <layer> <level> change the log level for a tracing layer
|
||||
layers include:
|
||||
all, terminal, system, api, file, otlp
|
||||
@ -169,32 +167,6 @@ Server Debug Commands:
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_attach(&self, callback: UICallback) -> Result<(), String> {
|
||||
trace!("CommandProcessor::cmd_attach");
|
||||
let capi = self.capi();
|
||||
let ui = self.ui_sender();
|
||||
spawn_detached_local(async move {
|
||||
if let Err(e) = capi.server_attach().await {
|
||||
error!("Server command 'attach' failed: {}", e);
|
||||
}
|
||||
ui.send_callback(callback);
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_detach(&self, callback: UICallback) -> Result<(), String> {
|
||||
trace!("CommandProcessor::cmd_detach");
|
||||
let capi = self.capi();
|
||||
let ui = self.ui_sender();
|
||||
spawn_detached_local(async move {
|
||||
if let Err(e) = capi.server_detach().await {
|
||||
error!("Server command 'detach' failed: {}", e);
|
||||
}
|
||||
ui.send_callback(callback);
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_disconnect(&self, callback: UICallback) -> Result<(), String> {
|
||||
trace!("CommandProcessor::cmd_disconnect");
|
||||
let capi = self.capi();
|
||||
@ -315,8 +287,6 @@ Server Debug Commands:
|
||||
"quit" => self.cmd_exit(callback),
|
||||
"disconnect" => self.cmd_disconnect(callback),
|
||||
"shutdown" => self.cmd_shutdown(callback),
|
||||
"attach" => self.cmd_attach(callback),
|
||||
"detach" => self.cmd_detach(callback),
|
||||
"change_log_level" => self.cmd_change_log_level(rest, callback),
|
||||
"enable" => self.cmd_enable(rest, callback),
|
||||
"disable" => self.cmd_disable(rest, callback),
|
||||
|
@ -180,14 +180,36 @@ impl AttachmentManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn update_attaching_detaching_state(&self, state: AttachmentState) {
|
||||
let update_callback = {
|
||||
let mut inner = self.inner.lock();
|
||||
inner.last_attachment_state = state;
|
||||
if state == AttachmentState::Attaching {
|
||||
inner.attach_ts = Some(get_aligned_timestamp());
|
||||
} else if state == AttachmentState::Detached {
|
||||
inner.attach_ts = None;
|
||||
} else if state == AttachmentState::Detaching {
|
||||
// ok
|
||||
} else {
|
||||
unreachable!("don't use this for attached states, use update_attachment()");
|
||||
}
|
||||
inner.update_callback.clone()
|
||||
};
|
||||
|
||||
if let Some(update_callback) = update_callback {
|
||||
update_callback(VeilidUpdate::Attachment(VeilidStateAttachment {
|
||||
state,
|
||||
public_internet_ready: false,
|
||||
local_network_ready: false,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(self))]
|
||||
async fn attachment_maintainer(self) {
|
||||
{
|
||||
let mut inner = self.inner.lock();
|
||||
inner.last_attachment_state = AttachmentState::Attaching;
|
||||
inner.attach_ts = Some(get_aligned_timestamp());
|
||||
debug!("attachment starting");
|
||||
}
|
||||
debug!("attachment starting");
|
||||
self.update_attaching_detaching_state(AttachmentState::Attaching);
|
||||
|
||||
let netman = self.network_manager();
|
||||
|
||||
let mut restart;
|
||||
@ -226,8 +248,7 @@ impl AttachmentManager {
|
||||
debug!("stopped maintaining peers");
|
||||
|
||||
if !restart {
|
||||
let mut inner = self.inner.lock();
|
||||
inner.last_attachment_state = AttachmentState::Detaching;
|
||||
self.update_attaching_detaching_state(AttachmentState::Detaching);
|
||||
debug!("attachment stopping");
|
||||
}
|
||||
|
||||
@ -243,12 +264,8 @@ impl AttachmentManager {
|
||||
sleep(1000).await;
|
||||
}
|
||||
|
||||
{
|
||||
let mut inner = self.inner.lock();
|
||||
inner.last_attachment_state = AttachmentState::Detached;
|
||||
inner.attach_ts = None;
|
||||
debug!("attachment stopped");
|
||||
}
|
||||
self.update_attaching_detaching_state(AttachmentState::Detached);
|
||||
debug!("attachment stopped");
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip_all, err)]
|
||||
|
Loading…
Reference in New Issue
Block a user