This commit is contained in:
John Smith 2021-11-28 20:08:50 -05:00
parent 4ffe259ad1
commit 1c576876ef
6 changed files with 41 additions and 64 deletions

View File

@ -18,22 +18,13 @@ pub enum ConnectionState {
}
impl ConnectionState {
pub fn is_disconnected(&self) -> bool {
match *self {
Self::Disconnected => true,
_ => false,
}
matches!(*self, Self::Disconnected)
}
pub fn is_connected(&self) -> bool {
match *self {
Self::Connected(_, _) => true,
_ => false,
}
matches!(*self, Self::Connected(_, _))
}
pub fn is_retrying(&self) -> bool {
match *self {
Self::Retrying(_, _) => true,
_ => false,
}
matches!(*self, Self::Retrying(_, _))
}
}

View File

@ -13,13 +13,12 @@ mod command_processor;
mod settings;
mod ui;
#[allow(clippy::all)]
pub mod veilid_client_capnp {
include!(concat!(env!("OUT_DIR"), "/proto/veilid_client_capnp.rs"));
}
fn parse_command_line<'a>(
default_config_path: &'a OsStr,
) -> Result<clap::ArgMatches<'a>, clap::Error> {
fn parse_command_line(default_config_path: &OsStr) -> Result<clap::ArgMatches, clap::Error> {
let matches = App::new("veilid-cli")
.version("0.1")
.about("Veilid Console Client")

View File

@ -158,13 +158,14 @@ impl veilid_server::Server for VeilidServerImpl {
// --- Client API Server-Side ---------------------------------
type ClientApiAllFuturesJoinHandle =
async_std::task::JoinHandle<Result<Vec<()>, Box<(dyn std::error::Error + 'static)>>>;
struct ClientApiInner {
veilid_api: veilid_core::VeilidAPI,
registration_map: Rc<RefCell<RegistrationMap>>,
stop: Eventual,
join_handle: Option<
async_std::task::JoinHandle<Result<Vec<()>, Box<(dyn std::error::Error + 'static)>>>,
>,
join_handle: Option<ClientApiAllFuturesJoinHandle>,
}
pub struct ClientApi {
@ -283,10 +284,11 @@ impl ClientApi {
let registration_map2 = registration_map1.clone();
async_std::task::spawn_local(request.send().promise.map(move |r| match r {
Ok(_) => {
if let Some(ref mut s) = registration_map2
.borrow_mut()
.registrations
.get_mut(&id) { s.requests_in_flight -= 1; }
if let Some(ref mut s) =
registration_map2.borrow_mut().registrations.get_mut(&id)
{
s.requests_in_flight -= 1;
}
}
Err(e) => {
debug!("Got error: {:?}. Dropping registation.", e);

View File

@ -4,6 +4,7 @@
mod client_api;
mod settings;
#[allow(clippy::all)]
pub mod veilid_client_capnp {
include!(concat!(env!("OUT_DIR"), "/proto/veilid_client_capnp.rs"));
}

View File

@ -276,13 +276,13 @@ pub struct Logging {
}
#[derive(Debug, Deserialize)]
pub struct HTTPS {
pub struct Https {
pub enabled: bool,
pub listen_address: NamedSocketAddrs,
}
#[derive(Debug, Deserialize)]
pub struct HTTP {
pub struct Http {
pub enabled: bool,
pub listen_address: NamedSocketAddrs,
}
@ -290,12 +290,12 @@ pub struct HTTP {
#[derive(Debug, Deserialize)]
pub struct Application {
pub path: PathBuf,
pub https: HTTPS,
pub http: HTTP,
pub https: Https,
pub http: Http,
}
#[derive(Debug, Deserialize)]
pub struct UDP {
pub struct Udp {
pub enabled: bool,
pub socket_pool_size: u32,
pub listen_address: NamedSocketAddrs,
@ -303,7 +303,7 @@ pub struct UDP {
}
#[derive(Debug, Deserialize)]
pub struct TCP {
pub struct Tcp {
pub connect: bool,
pub listen: bool,
pub max_connections: u32,
@ -312,7 +312,7 @@ pub struct TCP {
}
#[derive(Debug, Deserialize)]
pub struct WS {
pub struct Ws {
pub connect: bool,
pub listen: bool,
pub max_connections: u32,
@ -322,7 +322,7 @@ pub struct WS {
}
#[derive(Debug, Deserialize)]
pub struct WSS {
pub struct Wss {
pub connect: bool,
pub listen: bool,
pub max_connections: u32,
@ -333,21 +333,21 @@ pub struct WSS {
#[derive(Debug, Deserialize)]
pub struct Protocol {
pub udp: UDP,
pub tcp: TCP,
pub ws: WS,
pub wss: WSS,
pub udp: Udp,
pub tcp: Tcp,
pub ws: Ws,
pub wss: Wss,
}
#[derive(Debug, Deserialize)]
pub struct TLS {
pub struct Tls {
pub certificate_path: PathBuf,
pub private_key_path: PathBuf,
pub connection_initial_timeout: u64,
}
#[derive(Debug, Deserialize)]
pub struct RPC {
pub struct Rpc {
pub concurrency: u32,
pub queue_size: u32,
pub max_timestamp_behind: Option<u64>,
@ -357,7 +357,7 @@ pub struct RPC {
}
#[derive(Debug, Deserialize)]
pub struct DHT {
pub struct Dht {
pub resolve_node_timeout: Option<u64>,
pub resolve_node_count: u32,
pub resolve_node_fanout: u32,
@ -388,13 +388,13 @@ pub struct Network {
pub node_id: veilid_core::DHTKey,
pub node_id_secret: veilid_core::DHTKeySecret,
pub bootstrap: Vec<ParsedURL>,
pub rpc: RPC,
pub dht: DHT,
pub rpc: Rpc,
pub dht: Dht,
pub upnp: bool,
pub natpmp: bool,
pub address_filter: bool,
pub restricted_nat_retries: u32,
pub tls: TLS,
pub tls: Tls,
pub application: Application,
pub protocol: Protocol,
pub leases: Leases,

View File

@ -16,9 +16,7 @@ use std::str::FromStr;
use std::sync::Arc;
use veilid_core::xx::SingleShotEventual;
fn parse_command_line<'a>(
default_config_path: &'a OsStr,
) -> Result<clap::ArgMatches<'a>, clap::Error> {
fn parse_command_line(default_config_path: &OsStr) -> Result<clap::ArgMatches, clap::Error> {
let matches = App::new("veilid-server")
.version("0.1")
.about("Veilid Server")
@ -158,10 +156,7 @@ pub async fn main() -> Result<(), String> {
settingsrw.logging.file.level = settings::LogLevel::Trace;
}
if matches.is_present("attach") {
settingsrw.auto_attach = match matches.value_of("attach") {
Some("false") => false,
_ => true,
};
settingsrw.auto_attach = !matches!(matches.value_of("attach"), Some("false"));
}
if matches.occurrences_of("bootstrap") != 0 {
let bootstrap = match matches.value_of("bootstrap") {
@ -284,18 +279,10 @@ pub async fn main() -> Result<(), String> {
// Handle state changes on main thread for capnproto rpc
let capi2 = capi.clone();
let capi_jh = async_std::task::spawn_local(async move {
loop {
let change = match receiver.recv().await {
Ok(change) => change,
Err(_) => {
break;
}
};
let c = match capi2.borrow_mut().as_mut() {
Some(some_capi) => some_capi.clone(),
None => continue,
};
c.handle_state_change(change);
while let Ok(change) = receiver.recv().await {
if let Some(c) = capi2.borrow_mut().as_mut().cloned() {
c.handle_state_change(change);
}
}
});
@ -315,11 +302,8 @@ pub async fn main() -> Result<(), String> {
}
// Stop the client api if we have one
match capi.borrow_mut().as_mut().cloned() {
Some(some_capi) => {
some_capi.stop().await;
}
None => (),
if let Some(c) = capi.borrow_mut().as_mut().cloned() {
c.stop().await;
}
// Shut down Veilid API