This commit is contained in:
John Smith 2021-11-27 21:31:01 -05:00
parent ea8c75a29f
commit 1cecacd8fd
13 changed files with 50 additions and 74 deletions

2
external/cursive vendored

@ -1 +1 @@
Subproject commit c6e775311417fbd1cb57aab313cc2f0504d74627 Subproject commit 298b12545798d6b6a9e1a469467b89a15106cf7e

@ -1 +1 @@
Subproject commit bdfdcb0b962cc28651e3c205393da1a3b330e739 Subproject commit 7f998c82d171e6de783b3250006ae8e2b6316597

@ -1 +1 @@
Subproject commit f254ffdf8a84ff714844fd7d27e57deab2be00e3 Subproject commit 70c55412ea1ee97f9d60eb25e3a514b6968caa35

2
external/if-addrs vendored

@ -1 +1 @@
Subproject commit d16e76ce1f6edb03300e3f9ee264fcd611799fdb Subproject commit 5a9754fee6e92a7c6e8d8e93738d252acf58cb1c

View File

@ -16,7 +16,7 @@ struct VeilidClientImpl {
impl VeilidClientImpl { impl VeilidClientImpl {
pub fn new(comproc: CommandProcessor) -> Self { pub fn new(comproc: CommandProcessor) -> Self {
Self { comproc: comproc } Self { comproc }
} }
} }
@ -64,7 +64,7 @@ impl ClientApiConnection {
pub fn new(comproc: CommandProcessor) -> Self { pub fn new(comproc: CommandProcessor) -> Self {
Self { Self {
inner: Rc::new(RefCell::new(ClientApiConnectionInner { inner: Rc::new(RefCell::new(ClientApiConnectionInner {
comproc: comproc, comproc,
connect_addr: None, connect_addr: None,
disconnector: None, disconnector: None,
server: None, server: None,
@ -75,9 +75,9 @@ impl ClientApiConnection {
async fn handle_connection(&mut self) -> Result<()> { async fn handle_connection(&mut self) -> Result<()> {
trace!("ClientApiConnection::handle_connection"); trace!("ClientApiConnection::handle_connection");
let connect_addr = self.inner.borrow().connect_addr.unwrap().clone(); let connect_addr = self.inner.borrow().connect_addr.unwrap();
// Connect the TCP socket // Connect the TCP socket
let stream = async_std::net::TcpStream::connect(connect_addr.clone()).await?; let stream = async_std::net::TcpStream::connect(connect_addr).await?;
// If it succeed, disable nagle algorithm // If it succeed, disable nagle algorithm
stream.set_nodelay(true)?; stream.set_nodelay(true)?;

View File

@ -59,7 +59,7 @@ impl CommandProcessor {
pub fn new(ui: UI, settings: &Settings) -> Self { pub fn new(ui: UI, settings: &Settings) -> Self {
Self { Self {
inner: Rc::new(RefCell::new(CommandProcessorInner { inner: Rc::new(RefCell::new(CommandProcessorInner {
ui: ui, ui,
capi: None, capi: None,
reconnect: settings.autoreconnect, reconnect: settings.autoreconnect,
finished: false, finished: false,
@ -205,7 +205,7 @@ detach - detach the server from the Veilid network
// Loop while we want to keep the connection // Loop while we want to keep the connection
let mut first = true; let mut first = true;
while self.inner().reconnect { while self.inner().reconnect {
let server_addr_opt = self.inner_mut().server_addr.clone(); let server_addr_opt = self.inner_mut().server_addr;
let server_addr = match server_addr_opt { let server_addr = match server_addr_opt {
None => break, None => break,
Some(addr) => addr, Some(addr) => addr,
@ -213,15 +213,15 @@ detach - detach the server from the Veilid network
if first { if first {
info!("Connecting to server at {}", server_addr); info!("Connecting to server at {}", server_addr);
self.set_connection_state(ConnectionState::Retrying( self.set_connection_state(ConnectionState::Retrying(
server_addr.clone(), server_addr,
SystemTime::now(), SystemTime::now(),
)); ));
} else { } else {
debug!("Retrying connection to {}", server_addr); debug!("Retrying connection to {}", server_addr);
} }
let mut capi = self.capi(); let mut capi = self.capi();
let res = capi.connect(server_addr.clone()).await; let res = capi.connect(server_addr).await;
if let Ok(_) = res { if res.is_ok() {
info!( info!(
"Connection to server at {} terminated normally", "Connection to server at {} terminated normally",
server_addr server_addr
@ -234,7 +234,7 @@ detach - detach the server from the Veilid network
} }
self.set_connection_state(ConnectionState::Retrying( self.set_connection_state(ConnectionState::Retrying(
server_addr.clone(), server_addr,
SystemTime::now(), SystemTime::now(),
)); ));
@ -260,7 +260,7 @@ detach - detach the server from the Veilid network
self.inner_mut().server_addr = server_addr; self.inner_mut().server_addr = server_addr;
} }
pub fn get_server_address(&self) -> Option<SocketAddr> { pub fn get_server_address(&self) -> Option<SocketAddr> {
self.inner().server_addr.clone() self.inner().server_addr
} }
// called by client_api_connection // called by client_api_connection
// calls into ui // calls into ui

View File

@ -70,7 +70,7 @@ async fn main() -> Result<()> {
matches.occurrences_of("config-file") == 0, matches.occurrences_of("config-file") == 0,
matches.value_of_os("config-file").unwrap(), matches.value_of_os("config-file").unwrap(),
) )
.map_err(|x| Box::new(x))?; .map_err(Box::new)?;
// Set config from command line // Set config from command line
if matches.occurrences_of("debug") != 0 { if matches.occurrences_of("debug") != 0 {

View File

@ -1,7 +1,7 @@
use config;
use directories::*; use directories::*;
use log;
use serde;
use serde_derive::*; use serde_derive::*;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::net::{SocketAddr, ToSocketAddrs}; use std::net::{SocketAddr, ToSocketAddrs};
@ -118,7 +118,7 @@ impl<'de> serde::Deserialize<'de> for NamedSocketAddrs {
let s = String::deserialize(deserializer)?; let s = String::deserialize(deserializer)?;
let addr_iter = s let addr_iter = s
.to_socket_addrs() .to_socket_addrs()
.map_err(|x| serde::de::Error::custom(x))?; .map_err(serde::de::Error::custom)?;
Ok(NamedSocketAddrs { Ok(NamedSocketAddrs {
name: s, name: s,
addrs: addr_iter.collect(), addrs: addr_iter.collect(),

View File

@ -26,7 +26,7 @@ struct Dirty<T> {
impl<T> Dirty<T> { impl<T> Dirty<T> {
pub fn new(value: T) -> Self { pub fn new(value: T) -> Self {
Self { Self {
value: value, value,
dirty: true, dirty: true,
} }
} }
@ -122,7 +122,7 @@ impl UI {
cmd_history_position: 0, cmd_history_position: 0,
cmd_history_max_size: settings.interface.command_line.history_size, cmd_history_max_size: settings.interface.command_line.history_size,
connection_dialog_state: None, connection_dialog_state: None,
cb_sink: cb_sink, cb_sink,
})), })),
}; };
@ -203,7 +203,7 @@ impl UI {
siv.add_fullscreen_layer(mainlayout); siv.add_fullscreen_layer(mainlayout);
UI::setup_colors(&mut siv, &mut inner, &settings); UI::setup_colors(&mut siv, &mut inner, settings);
UI::setup_quit_handler(&mut siv); UI::setup_quit_handler(&mut siv);
drop(inner); drop(inner);
@ -347,7 +347,7 @@ impl UI {
} }
pub fn add_node_event(&mut self, event: &str) { pub fn add_node_event(&mut self, event: &str) {
let inner = self.inner.borrow_mut(); let inner = self.inner.borrow_mut();
let color = inner.log_colors.get(&Level::Info).unwrap().clone(); let color = *inner.log_colors.get(&Level::Info).unwrap();
for line in event.lines() { for line in event.lines() {
cursive_flexi_logger_view::push_to_log(StyledString::styled(line, color)); cursive_flexi_logger_view::push_to_log(StyledString::styled(line, color));
} }
@ -470,11 +470,10 @@ impl UI {
match Self::run_command(s, text) { match Self::run_command(s, text) {
Ok(_) => {} Ok(_) => {}
Err(e) => { Err(e) => {
let color = Self::inner_mut(s) let color = *Self::inner_mut(s)
.log_colors .log_colors
.get(&Level::Error) .get(&Level::Error)
.unwrap() .unwrap();
.clone();
cursive_flexi_logger_view::push_to_log(StyledString::styled( cursive_flexi_logger_view::push_to_log(StyledString::styled(
format!("> {}", text), format!("> {}", text),
@ -668,7 +667,7 @@ impl UI {
return true; return true;
} }
return false; false
} }
fn refresh_connection_dialog(s: &mut Cursive) { fn refresh_connection_dialog(s: &mut Cursive) {
@ -686,13 +685,13 @@ impl UI {
}; };
debug!("address is {}", addr); debug!("address is {}", addr);
let mut edit = s.find_name::<EditView>("connection-address").unwrap(); let mut edit = s.find_name::<EditView>("connection-address").unwrap();
edit.set_content(addr.to_string()); edit.set_content(addr);
edit.set_enabled(true); edit.set_enabled(true);
let mut dlg = s.find_name::<Dialog>("connection-dialog").unwrap(); let mut dlg = s.find_name::<Dialog>("connection-dialog").unwrap();
dlg.add_button("Connect", Self::submit_connection_address); dlg.add_button("Connect", Self::submit_connection_address);
} }
ConnectionState::Connected(_, _) => { ConnectionState::Connected(_, _) => {
return;
} }
ConnectionState::Retrying(addr, _) => { ConnectionState::Retrying(addr, _) => {
// //
@ -717,7 +716,7 @@ impl UI {
match inner.ui_state.connection_state.get() { match inner.ui_state.connection_state.get() {
ConnectionState::Disconnected => { ConnectionState::Disconnected => {
status.append_styled(format!("Disconnected "), ColorStyle::highlight_inactive()); status.append_styled("Disconnected ".to_string(), ColorStyle::highlight_inactive());
status.append_styled("|", ColorStyle::highlight_inactive()); status.append_styled("|", ColorStyle::highlight_inactive());
} }
ConnectionState::Retrying(addr, _) => { ConnectionState::Retrying(addr, _) => {

View File

@ -44,7 +44,7 @@ struct RegistrationImpl {
impl RegistrationImpl { impl RegistrationImpl {
fn new(id: u64, registrations: Rc<RefCell<RegistrationMap>>) -> Self { fn new(id: u64, registrations: Rc<RefCell<RegistrationMap>>) -> Self {
Self { Self {
id: id, id,
registration_map: registrations, registration_map: registrations,
} }
} }
@ -75,7 +75,7 @@ impl VeilidServerImpl {
Self { Self {
next_id: 0, next_id: 0,
registration_map: Rc::new(RefCell::new(RegistrationMap::new())), registration_map: Rc::new(RefCell::new(RegistrationMap::new())),
veilid_api: veilid_api, veilid_api,
} }
} }
} }
@ -175,7 +175,7 @@ impl ClientApi {
pub fn new(veilid_api: veilid_core::VeilidAPI) -> Rc<Self> { pub fn new(veilid_api: veilid_core::VeilidAPI) -> Rc<Self> {
Rc::new(Self { Rc::new(Self {
inner: RefCell::new(ClientApiInner { inner: RefCell::new(ClientApiInner {
veilid_api: veilid_api, veilid_api,
registration_map: Rc::new(RefCell::new(RegistrationMap::new())), registration_map: Rc::new(RefCell::new(RegistrationMap::new())),
stop: Eventual::new(), stop: Eventual::new(),
join_handle: None, join_handle: None,
@ -283,13 +283,10 @@ impl ClientApi {
let registration_map2 = registration_map1.clone(); let registration_map2 = registration_map1.clone();
async_std::task::spawn_local(request.send().promise.map(move |r| match r { async_std::task::spawn_local(request.send().promise.map(move |r| match r {
Ok(_) => { Ok(_) => {
registration_map2 if let Some(ref mut s) = registration_map2
.borrow_mut() .borrow_mut()
.registrations .registrations
.get_mut(&id) .get_mut(&id) { s.requests_in_flight -= 1; }
.map(|ref mut s| {
s.requests_in_flight -= 1;
});
} }
Err(e) => { Err(e) => {
debug!("Got error: {:?}. Dropping registation.", e); debug!("Got error: {:?}. Dropping registation.", e);
@ -309,7 +306,7 @@ impl ClientApi {
let bind_futures = bind_addrs let bind_futures = bind_addrs
.iter() .iter()
.map(|addr| self.clone().handle_incoming(addr.clone(), client.clone())); .map(|addr| self.clone().handle_incoming(*addr, client.clone()));
let bind_futures_join = futures::future::try_join_all(bind_futures); let bind_futures_join = futures::future::try_join_all(bind_futures);
self.inner.borrow_mut().join_handle = Some(async_std::task::spawn_local(bind_futures_join)); self.inner.borrow_mut().join_handle = Some(async_std::task::spawn_local(bind_futures_join));
} }

View File

@ -7,7 +7,7 @@ pub mod veilid_client_capnp {
include!(concat!(env!("OUT_DIR"), "/proto/veilid_client_capnp.rs")); include!(concat!(env!("OUT_DIR"), "/proto/veilid_client_capnp.rs"));
} }
use cfg_if;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(windows)] { if #[cfg(windows)] {

View File

@ -1,8 +1,8 @@
use config;
use directories::*; use directories::*;
use log::*; use log::*;
use parking_lot::*; use parking_lot::*;
use serde;
use serde_derive::*; use serde_derive::*;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::net::{SocketAddr, ToSocketAddrs}; use std::net::{SocketAddr, ToSocketAddrs};
@ -184,7 +184,7 @@ impl FromStr for ParsedURL {
Ok(Self { Ok(Self {
urlstring: s.to_string(), urlstring: s.to_string(),
url: url, url,
}) })
} }
} }
@ -195,7 +195,7 @@ impl<'de> serde::Deserialize<'de> for ParsedURL {
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
let s = String::deserialize(deserializer)?; let s = String::deserialize(deserializer)?;
Ok(ParsedURL::from_str(s.as_str()).map_err(|x| serde::de::Error::custom(x))?) ParsedURL::from_str(s.as_str()).map_err(serde::de::Error::custom)
} }
} }
@ -222,7 +222,7 @@ impl<'de> serde::Deserialize<'de> for NamedSocketAddrs {
D: serde::Deserializer<'de>, D: serde::Deserializer<'de>,
{ {
let s = String::deserialize(deserializer)?; let s = String::deserialize(deserializer)?;
Ok(NamedSocketAddrs::from_str(s.as_str()).map_err(|x| serde::de::Error::custom(x))?) NamedSocketAddrs::from_str(s.as_str()).map_err(serde::de::Error::custom)
} }
} }
@ -709,11 +709,7 @@ impl Settings {
inner.core.network.protocol.udp.listen_address.name.clone(), inner.core.network.protocol.udp.listen_address.name.clone(),
)), )),
"network.protocol.udp.public_address" => Ok(Box::new( "network.protocol.udp.public_address" => Ok(Box::new(
if let Some(a) = &inner.core.network.protocol.udp.public_address { inner.core.network.protocol.udp.public_address.as_ref().map(|a| a.name.clone()),
Some(a.name.clone())
} else {
None
},
)), )),
"network.protocol.tcp.connect" => { "network.protocol.tcp.connect" => {
Ok(Box::new(inner.core.network.protocol.tcp.connect)) Ok(Box::new(inner.core.network.protocol.tcp.connect))
@ -728,11 +724,7 @@ impl Settings {
inner.core.network.protocol.tcp.listen_address.name.clone(), inner.core.network.protocol.tcp.listen_address.name.clone(),
)), )),
"network.protocol.tcp.public_address" => Ok(Box::new( "network.protocol.tcp.public_address" => Ok(Box::new(
if let Some(a) = &inner.core.network.protocol.tcp.public_address { inner.core.network.protocol.tcp.public_address.as_ref().map(|a| a.name.clone()),
Some(a.name.clone())
} else {
None
},
)), )),
"network.protocol.ws.connect" => { "network.protocol.ws.connect" => {
Ok(Box::new(inner.core.network.protocol.ws.connect)) Ok(Box::new(inner.core.network.protocol.ws.connect))
@ -748,11 +740,7 @@ impl Settings {
Ok(Box::new(inner.core.network.protocol.ws.path.clone())) Ok(Box::new(inner.core.network.protocol.ws.path.clone()))
} }
"network.protocol.ws.public_address" => Ok(Box::new( "network.protocol.ws.public_address" => Ok(Box::new(
if let Some(a) = &inner.core.network.protocol.ws.public_address { inner.core.network.protocol.ws.public_address.as_ref().map(|a| a.name.clone()),
Some(a.name.clone())
} else {
None
},
)), )),
"network.protocol.wss.connect" => { "network.protocol.wss.connect" => {
Ok(Box::new(inner.core.network.protocol.wss.connect)) Ok(Box::new(inner.core.network.protocol.wss.connect))
@ -770,11 +758,7 @@ impl Settings {
Ok(Box::new(inner.core.network.protocol.wss.path.clone())) Ok(Box::new(inner.core.network.protocol.wss.path.clone()))
} }
"network.protocol.wss.public_address" => Ok(Box::new( "network.protocol.wss.public_address" => Ok(Box::new(
if let Some(a) = &inner.core.network.protocol.wss.public_address { inner.core.network.protocol.wss.public_address.as_ref().map(|a| a.name.clone()),
Some(a.name.clone())
} else {
None
},
)), )),
"network.leases.max_server_signal_leases" => { "network.leases.max_server_signal_leases" => {
Ok(Box::new(inner.core.network.leases.max_server_signal_leases)) Ok(Box::new(inner.core.network.leases.max_server_signal_leases))
@ -845,7 +829,7 @@ mod tests {
veilid_core::DHTKeySecret::default() veilid_core::DHTKeySecret::default()
); );
// //
assert!(s.core.network.bootstrap.len() == 0); assert!(s.core.network.bootstrap.is_empty());
// //
assert_eq!(s.core.network.rpc.concurrency, 0); assert_eq!(s.core.network.rpc.concurrency, 0);
assert_eq!(s.core.network.rpc.queue_size, 1024); assert_eq!(s.core.network.rpc.queue_size, 1024);

View File

@ -168,7 +168,7 @@ pub async fn main() -> Result<(), String> {
Some(x) => { Some(x) => {
println!("Overriding bootstrap with: "); println!("Overriding bootstrap with: ");
let mut out: Vec<settings::ParsedURL> = Vec::new(); let mut out: Vec<settings::ParsedURL> = Vec::new();
for x in x.split(",") { for x in x.split(',') {
println!(" {}", x); println!(" {}", x);
out.push( out.push(
settings::ParsedURL::from_str(x) settings::ParsedURL::from_str(x)
@ -251,7 +251,7 @@ pub async fn main() -> Result<(), String> {
move |change: veilid_core::VeilidStateChange| -> veilid_core::SystemPinBoxFuture<()> { move |change: veilid_core::VeilidStateChange| -> veilid_core::SystemPinBoxFuture<()> {
let sender = sender.clone(); let sender = sender.clone();
Box::pin(async move { Box::pin(async move {
if let Err(_) = sender.send(change).await { if sender.send(change).await.is_err() {
error!("error sending state change callback"); error!("error sending state change callback");
} }
}) })
@ -308,11 +308,7 @@ pub async fn main() -> Result<(), String> {
// Idle while waiting to exit // Idle while waiting to exit
let shutdown_switch = { let shutdown_switch = {
let shutdown_switch_locked = SHUTDOWN_SWITCH.lock(); let shutdown_switch_locked = SHUTDOWN_SWITCH.lock();
if let Some(ss) = &*shutdown_switch_locked { (*shutdown_switch_locked).as_ref().map(|ss| ss.instance())
Some(ss.instance())
} else {
None
}
}; };
if let Some(shutdown_switch) = shutdown_switch { if let Some(shutdown_switch) = shutdown_switch {
shutdown_switch.await; shutdown_switch.await;