pr work
This commit is contained in:
@@ -89,6 +89,9 @@ impl veilid_client::Server for VeilidClientImpl {
|
||||
VeilidUpdate::Network(network) => {
|
||||
self.comproc.update_network_status(network);
|
||||
}
|
||||
VeilidUpdate::Config(config) => {
|
||||
self.comproc.update_config(config);
|
||||
}
|
||||
VeilidUpdate::Shutdown => self.comproc.update_shutdown(),
|
||||
}
|
||||
|
||||
@@ -101,6 +104,7 @@ struct ClientApiConnectionInner {
|
||||
connect_addr: Option<SocketAddr>,
|
||||
disconnector: Option<Disconnector<rpc_twoparty_capnp::Side>>,
|
||||
server: Option<Rc<RefCell<veilid_server::Client>>>,
|
||||
server_settings: Option<String>,
|
||||
disconnect_requested: bool,
|
||||
cancel_eventual: Eventual,
|
||||
}
|
||||
@@ -120,6 +124,7 @@ impl ClientApiConnection {
|
||||
connect_addr: None,
|
||||
disconnector: None,
|
||||
server: None,
|
||||
server_settings: None,
|
||||
disconnect_requested: false,
|
||||
cancel_eventual: Eventual::new(),
|
||||
})),
|
||||
@@ -141,7 +146,7 @@ impl ClientApiConnection {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
inner.comproc.update_attachment(veilid_state.attachment);
|
||||
inner.comproc.update_network_status(veilid_state.network);
|
||||
|
||||
inner.comproc.update_config(veilid_state.config);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -209,6 +214,13 @@ impl ClientApiConnection {
|
||||
.map_err(|e| format!("failed to get deserialize veilid state: {}", e))?;
|
||||
self.process_veilid_state(veilid_state).await?;
|
||||
|
||||
// Save server settings
|
||||
let server_settings = response
|
||||
.get_settings()
|
||||
.map_err(|e| format!("failed to get initial veilid server settings: {}", e))?
|
||||
.to_owned();
|
||||
self.inner.borrow_mut().server_settings = Some(server_settings.clone());
|
||||
|
||||
// Don't drop the registration, doing so will remove the client
|
||||
// object mapping from the server which we need for the update backchannel
|
||||
|
||||
@@ -219,9 +231,10 @@ impl ClientApiConnection {
|
||||
res.map_err(|e| format!("client RPC system error: {}", e))
|
||||
}
|
||||
|
||||
async fn handle_connection(&mut self) -> Result<(), String> {
|
||||
async fn handle_connection(&mut self, connect_addr: SocketAddr) -> Result<(), String> {
|
||||
trace!("ClientApiConnection::handle_connection");
|
||||
let connect_addr = self.inner.borrow().connect_addr.unwrap();
|
||||
|
||||
self.inner.borrow_mut().connect_addr = Some(connect_addr);
|
||||
// Connect the TCP socket
|
||||
let stream = TcpStream::connect(connect_addr)
|
||||
.await
|
||||
@@ -263,9 +276,11 @@ impl ClientApiConnection {
|
||||
// Drop the server and disconnector too (if we still have it)
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let disconnect_requested = inner.disconnect_requested;
|
||||
inner.server_settings = None;
|
||||
inner.server = None;
|
||||
inner.disconnector = None;
|
||||
inner.disconnect_requested = false;
|
||||
inner.connect_addr = None;
|
||||
|
||||
if !disconnect_requested {
|
||||
// Connection lost
|
||||
@@ -456,9 +471,7 @@ impl ClientApiConnection {
|
||||
pub async fn connect(&mut self, connect_addr: SocketAddr) -> Result<(), String> {
|
||||
trace!("ClientApiConnection::connect");
|
||||
// Save the address to connect to
|
||||
self.inner.borrow_mut().connect_addr = Some(connect_addr);
|
||||
|
||||
self.handle_connection().await
|
||||
self.handle_connection(connect_addr).await
|
||||
}
|
||||
|
||||
// End Client API connection
|
||||
@@ -469,7 +482,6 @@ impl ClientApiConnection {
|
||||
Some(d) => {
|
||||
self.inner.borrow_mut().disconnect_requested = true;
|
||||
d.await.unwrap();
|
||||
self.inner.borrow_mut().connect_addr = None;
|
||||
}
|
||||
None => {
|
||||
debug!("disconnector doesn't exist");
|
||||
|
@@ -388,6 +388,7 @@ reply - reply to an AppCall not handled directly by the server
|
||||
// called by client_api_connection
|
||||
// calls into ui
|
||||
////////////////////////////////////////////
|
||||
|
||||
pub fn update_attachment(&mut self, attachment: veilid_core::VeilidStateAttachment) {
|
||||
self.inner_mut().ui.set_attachment_state(attachment.state);
|
||||
}
|
||||
@@ -400,6 +401,9 @@ reply - reply to an AppCall not handled directly by the server
|
||||
network.peers,
|
||||
);
|
||||
}
|
||||
pub fn update_config(&mut self, config: veilid_core::VeilidStateConfig) {
|
||||
self.inner_mut().ui.set_config(config.config)
|
||||
}
|
||||
|
||||
pub fn update_log(&mut self, log: veilid_core::VeilidLog) {
|
||||
self.inner().ui.add_node_event(format!(
|
||||
|
@@ -55,6 +55,7 @@ struct UIState {
|
||||
network_down_up: Dirty<(f32, f32)>,
|
||||
connection_state: Dirty<ConnectionState>,
|
||||
peers_state: Dirty<Vec<PeerTableData>>,
|
||||
node_id: Dirty<String>,
|
||||
}
|
||||
|
||||
impl UIState {
|
||||
@@ -65,6 +66,7 @@ impl UIState {
|
||||
network_down_up: Dirty::new((0.0, 0.0)),
|
||||
connection_state: Dirty::new(ConnectionState::Disconnected),
|
||||
peers_state: Dirty::new(Vec::new()),
|
||||
node_id: Dirty::new("".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -214,6 +216,11 @@ impl UI {
|
||||
});
|
||||
}
|
||||
|
||||
fn node_events_panel(
|
||||
s: &mut Cursive,
|
||||
) -> ViewRef<Panel<ResizedView<NamedView<ScrollView<FlexiLoggerView>>>>> {
|
||||
s.find_name("node-events-panel").unwrap()
|
||||
}
|
||||
fn command_line(s: &mut Cursive) -> ViewRef<EditView> {
|
||||
s.find_name("command-line").unwrap()
|
||||
}
|
||||
@@ -572,6 +579,12 @@ impl UI {
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_main_titlebar(s: &mut Cursive) {
|
||||
let mut main_window = UI::node_events_panel(s);
|
||||
let inner = Self::inner_mut(s);
|
||||
main_window.set_title(format!("Node: {}", inner.ui_state.node_id.get()));
|
||||
}
|
||||
|
||||
fn refresh_statusbar(s: &mut Cursive) {
|
||||
let mut statusbar = UI::status_bar(s);
|
||||
|
||||
@@ -634,6 +647,7 @@ impl UI {
|
||||
let mut refresh_button_attach = false;
|
||||
let mut refresh_connection_dialog = false;
|
||||
let mut refresh_peers = false;
|
||||
let mut refresh_main_titlebar = false;
|
||||
if inner.ui_state.attachment_state.take_dirty() {
|
||||
refresh_statusbar = true;
|
||||
refresh_button_attach = true;
|
||||
@@ -654,6 +668,9 @@ impl UI {
|
||||
if inner.ui_state.peers_state.take_dirty() {
|
||||
refresh_peers = true;
|
||||
}
|
||||
if inner.ui_state.node_id.take_dirty() {
|
||||
refresh_main_titlebar = true;
|
||||
}
|
||||
|
||||
drop(inner);
|
||||
|
||||
@@ -669,6 +686,9 @@ impl UI {
|
||||
if refresh_peers {
|
||||
Self::refresh_peers(s);
|
||||
}
|
||||
if refresh_main_titlebar {
|
||||
Self::refresh_main_titlebar(s);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
@@ -722,7 +742,8 @@ impl UI {
|
||||
.full_screen(),
|
||||
)
|
||||
.title_position(HAlign::Left)
|
||||
.title("Node Events");
|
||||
.title("Node Events")
|
||||
.with_name("node-events-panel");
|
||||
|
||||
let peers_table_view = PeersTableView::new()
|
||||
.column(PeerTableColumn::NodeId, "Node Id", |c| c.width(43))
|
||||
@@ -839,6 +860,16 @@ impl UI {
|
||||
inner.ui_state.peers_state.set(peers);
|
||||
let _ = inner.cb_sink.send(Box::new(UI::update_cb));
|
||||
}
|
||||
pub fn set_config(&mut self, config: VeilidConfigInner) {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
inner.ui_state.node_id.set(
|
||||
config
|
||||
.network
|
||||
.node_id
|
||||
.map(|x| x.encode())
|
||||
.unwrap_or("<unknown>".to_owned()),
|
||||
);
|
||||
}
|
||||
pub fn set_connection_state(&mut self, state: ConnectionState) {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
inner.ui_state.connection_state.set(state);
|
||||
|
Reference in New Issue
Block a user