fix attachment update
This commit is contained in:
parent
05a9ee754e
commit
98a20f5921
@ -126,8 +126,6 @@ impl CommandProcessor {
|
|||||||
exit/quit exit the client
|
exit/quit exit the client
|
||||||
disconnect disconnect the client from the Veilid node
|
disconnect disconnect the client from the Veilid node
|
||||||
shutdown shut the server down
|
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
|
change_log_level <layer> <level> change the log level for a tracing layer
|
||||||
layers include:
|
layers include:
|
||||||
all, terminal, system, api, file, otlp
|
all, terminal, system, api, file, otlp
|
||||||
@ -169,32 +167,6 @@ Server Debug Commands:
|
|||||||
Ok(())
|
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> {
|
pub fn cmd_disconnect(&self, callback: UICallback) -> Result<(), String> {
|
||||||
trace!("CommandProcessor::cmd_disconnect");
|
trace!("CommandProcessor::cmd_disconnect");
|
||||||
let capi = self.capi();
|
let capi = self.capi();
|
||||||
@ -315,8 +287,6 @@ Server Debug Commands:
|
|||||||
"quit" => self.cmd_exit(callback),
|
"quit" => self.cmd_exit(callback),
|
||||||
"disconnect" => self.cmd_disconnect(callback),
|
"disconnect" => self.cmd_disconnect(callback),
|
||||||
"shutdown" => self.cmd_shutdown(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),
|
"change_log_level" => self.cmd_change_log_level(rest, callback),
|
||||||
"enable" => self.cmd_enable(rest, callback),
|
"enable" => self.cmd_enable(rest, callback),
|
||||||
"disable" => self.cmd_disable(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))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
async fn attachment_maintainer(self) {
|
async fn attachment_maintainer(self) {
|
||||||
{
|
debug!("attachment starting");
|
||||||
let mut inner = self.inner.lock();
|
self.update_attaching_detaching_state(AttachmentState::Attaching);
|
||||||
inner.last_attachment_state = AttachmentState::Attaching;
|
|
||||||
inner.attach_ts = Some(get_aligned_timestamp());
|
|
||||||
debug!("attachment starting");
|
|
||||||
}
|
|
||||||
let netman = self.network_manager();
|
let netman = self.network_manager();
|
||||||
|
|
||||||
let mut restart;
|
let mut restart;
|
||||||
@ -226,8 +248,7 @@ impl AttachmentManager {
|
|||||||
debug!("stopped maintaining peers");
|
debug!("stopped maintaining peers");
|
||||||
|
|
||||||
if !restart {
|
if !restart {
|
||||||
let mut inner = self.inner.lock();
|
self.update_attaching_detaching_state(AttachmentState::Detaching);
|
||||||
inner.last_attachment_state = AttachmentState::Detaching;
|
|
||||||
debug!("attachment stopping");
|
debug!("attachment stopping");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,12 +264,8 @@ impl AttachmentManager {
|
|||||||
sleep(1000).await;
|
sleep(1000).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
self.update_attaching_detaching_state(AttachmentState::Detached);
|
||||||
let mut inner = self.inner.lock();
|
debug!("attachment stopped");
|
||||||
inner.last_attachment_state = AttachmentState::Detached;
|
|
||||||
inner.attach_ts = None;
|
|
||||||
debug!("attachment stopped");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all, err)]
|
#[instrument(level = "debug", skip_all, err)]
|
||||||
|
Loading…
Reference in New Issue
Block a user