소스 검색

Clean up async_daemonize for less imports and use smol.

Luther Blissett 3 년 전
부모
커밋
47dbf1363f

+ 4 - 22
Cargo.lock

@@ -1246,8 +1246,6 @@ dependencies = [
 name = "darkfid"
 version = "0.3.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-std",
  "async-trait",
  "blake3",
@@ -1256,7 +1254,6 @@ dependencies = [
  "ctrlc",
  "darkfi",
  "easy-parallel",
- "futures-lite",
  "fxhash",
  "incrementalmerkletree",
  "lazy-init",
@@ -1264,10 +1261,10 @@ dependencies = [
  "pasta_curves",
  "rand",
  "serde",
- "serde_derive",
  "serde_json",
  "simplelog",
  "sled",
+ "smol",
  "structopt",
  "structopt-toml",
  "url",
@@ -1753,8 +1750,6 @@ dependencies = [
 name = "faucetd"
 version = "0.3.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-std",
  "async-trait",
  "blake3",
@@ -1763,16 +1758,15 @@ dependencies = [
  "ctrlc",
  "darkfi",
  "easy-parallel",
- "futures-lite",
  "hex",
  "lazy-init",
  "log",
  "rand",
  "serde",
- "serde_derive",
  "serde_json",
  "simplelog",
  "sled",
+ "smol",
  "structopt",
  "structopt-toml",
  "url",
@@ -1920,20 +1914,17 @@ dependencies = [
 name = "fud"
 version = "0.3.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-std",
  "async-trait",
  "blake3",
  "ctrlc",
  "darkfi",
  "easy-parallel",
- "futures-lite",
  "log",
  "serde",
- "serde_derive",
  "serde_json",
  "simplelog",
+ "smol",
  "structopt",
  "structopt-toml",
  "url",
@@ -2390,8 +2381,6 @@ dependencies = [
 name = "ircd"
 version = "0.4.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-recursion",
  "async-std",
  "async-trait",
@@ -2424,8 +2413,6 @@ dependencies = [
 name = "ircd2"
 version = "0.4.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-std",
  "async-trait",
  "bs58",
@@ -2547,20 +2534,17 @@ dependencies = [
 name = "lilith"
 version = "0.3.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-std",
  "async-trait",
  "ctrlc",
  "darkfi",
  "easy-parallel",
- "futures-lite",
  "fxhash",
  "log",
  "serde",
- "serde_derive",
  "serde_json",
  "simplelog",
+ "smol",
  "structopt",
  "structopt-toml",
  "toml",
@@ -4137,8 +4121,6 @@ dependencies = [
 name = "taud"
 version = "0.4.0"
 dependencies = [
- "async-channel",
- "async-executor",
  "async-std",
  "async-trait",
  "bs58",

+ 2 - 5
bin/darkfid/Cargo.toml

@@ -9,8 +9,6 @@ license = "AGPL-3.0-only"
 edition = "2021"
 
 [dependencies]
-async-channel = "1.7.1"
-async-executor = "1.4.1"
 async-std = "1.12.0"
 async-trait = "0.1.57"
 blake3 = "1.3.1"
@@ -19,7 +17,6 @@ chrono = "0.4.22"
 ctrlc = { version = "3.2.3", features = ["termination"] }
 darkfi = {path = "../../", features = ["blockchain", "wallet", "rpc", "net", "node"]}
 easy-parallel = "3.2.0"
-futures-lite = "1.12.0"
 fxhash = "0.2.1"
 incrementalmerkletree = "0.3.0"
 lazy-init = "0.5.1"
@@ -29,10 +26,10 @@ rand = "0.8.5"
 serde_json = "1.0.85"
 simplelog = "0.12.0"
 sled = "0.34.7"
+smol = "1.2.5"
 url = "2.3.1"
 
 # Argument parsing
-serde = "1.0.145"
-serde_derive = "1.0.145"
+serde = {version = "1.0.145", features = ["derive"]}
 structopt = "0.3.26"
 structopt-toml = "0.5.1"

+ 4 - 11
bin/darkfid/src/main.rs

@@ -1,13 +1,9 @@
 use std::str::FromStr;
 
-use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use async_trait::async_trait;
-use futures_lite::future;
 use log::{debug, error, info};
-use serde_derive::Deserialize;
-use structopt::StructOpt;
-use structopt_toml::StructOptToml;
+use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
 use url::Url;
 
 use darkfi::{
@@ -34,10 +30,7 @@ use darkfi::{
         },
         server::{listen_and_serve, RequestHandler},
     },
-    util::{
-        cli::{get_log_config, get_log_level, spawn_config},
-        path::{expand_path, get_config_path},
-    },
+    util::path::expand_path,
     wallet::walletdb::init_wallet,
     Error, Result,
 };
@@ -260,7 +253,7 @@ impl Darkfid {
 }
 
 async_daemonize!(realmain);
-async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
     if args.consensus && args.clock_sync {
         // We verify that if peer/seed nodes are configured, their rpc config also exists
         if ((!args.consensus_p2p_peer.is_empty() && args.consensus_peer_rpc.is_empty()) ||
@@ -284,7 +277,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
     // We use this handler to block this function after detaching all
     // tasks, and to catch a shutdown signal, where we can clean up and
     // exit gracefully.
-    let (signal, shutdown) = async_channel::bounded::<()>(1);
+    let (signal, shutdown) = smol::channel::bounded::<()>(1);
     ctrlc::set_handler(move || {
         async_std::task::block_on(signal.send(())).unwrap();
     })

+ 1 - 4
bin/darkwiki/darkwikid/src/main.rs

@@ -5,7 +5,6 @@ use std::{
     process::exit,
 };
 
-use async_executor::Executor;
 use async_std::{
     stream::StreamExt,
     sync::{Arc, Mutex, RwLock},
@@ -18,7 +17,6 @@ use lazy_static::lazy_static;
 use log::{debug, error, info, warn};
 use signal_hook::consts::{SIGHUP, SIGINT, SIGQUIT, SIGTERM};
 use signal_hook_async_std::Signals;
-use smol::future;
 use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
 use url::Url;
 
@@ -27,7 +25,6 @@ use darkfi::{
     raft::{NetMsg, ProtocolRaft, Raft, RaftSettings},
     rpc::server::listen_and_serve,
     util::{
-        cli::{get_log_config, get_log_level, spawn_config},
         file::{load_file, load_json_file, save_file, save_json_file},
         path::{expand_path, get_config_path},
     },
@@ -515,7 +512,7 @@ async fn handle_signals(
 }
 
 async_daemonize!(realmain);
-async fn realmain(args: Args, executor: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(args: Args, executor: Arc<smol::Executor<'_>>) -> Result<()> {
     let cfg_path = get_config_path(args.config, CONFIG_FILE)?;
     let docs_path = expand_path(&args.docs)?;
     let store_path = expand_path(docs_path.join(".log").to_str().unwrap())?;

+ 2 - 5
bin/faucetd/Cargo.toml

@@ -9,8 +9,6 @@ license = "AGPL-3.0-only"
 edition = "2021"
 
 [dependencies]
-async-channel = "1.7.1"
-async-executor = "1.4.1"
 async-std = "1.12.0"
 async-trait = "0.1.57"
 blake3 = "1.3.1"
@@ -19,7 +17,6 @@ chrono = "0.4.22"
 ctrlc = { version = "3.2.3", features = ["termination"] }
 darkfi = {path = "../../", features = ["blockchain", "wallet", "rpc", "net", "node"]}
 easy-parallel = "3.2.0"
-futures-lite = "1.12.0"
 hex = "0.4.3"
 lazy-init = "0.5.1"
 log = "0.4.17"
@@ -27,10 +24,10 @@ rand = "0.8.5"
 serde_json = "1.0.85"
 simplelog = "0.12.0"
 sled = "0.34.7"
+smol = "1.2.5"
 url = "2.3.1"
 
 # Argument parsing
-serde = "1.0.145"
-serde_derive = "1.0.145"
+serde = {version = "1.0.145", features = ["derive"]}
 structopt = "0.3.26"
 structopt-toml = "0.5.1"

+ 4 - 13
bin/faucetd/src/main.rs

@@ -1,15 +1,11 @@
 use std::{collections::HashMap, str::FromStr};
 
-use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use async_trait::async_trait;
 use chrono::Utc;
-use futures_lite::future;
 use log::{debug, error, info};
-use serde_derive::Deserialize;
 use serde_json::{json, Value};
-use structopt::StructOpt;
-use structopt_toml::StructOptToml;
+use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
 use url::Url;
 
 use darkfi::{
@@ -32,12 +28,7 @@ use darkfi::{
         server::{listen_and_serve, RequestHandler},
     },
     serial::serialize,
-    util::{
-        async_util::sleep,
-        cli::{get_log_config, get_log_level, spawn_config},
-        parse::decode_base10,
-        path::{expand_path, get_config_path},
-    },
+    util::{async_util::sleep, parse::decode_base10, path::expand_path},
     wallet::walletdb::init_wallet,
     Error, Result,
 };
@@ -307,11 +298,11 @@ async fn prune_airdrop_map(map: Arc<Mutex<HashMap<Address, i64>>>, timeout: i64)
 }
 
 async_daemonize!(realmain);
-async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
     // We use this handler to block this function after detaching all
     // tasks, and to catch a shutdown signal, where we can clean up and
     // exit gracefully.
-    let (signal, shutdown) = async_channel::bounded::<()>(1);
+    let (signal, shutdown) = smol::channel::bounded::<()>(1);
     ctrlc::set_handler(move || {
         async_std::task::block_on(signal.send(())).unwrap();
     })

+ 2 - 5
bin/fud/fud/Cargo.toml

@@ -14,13 +14,11 @@ categories = []
 darkfi = {path = "../../../", features = ["dht", "rpc"]}
 
 # Async
-async-channel = "1.7.1"
-async-executor = "1.4.1"
 async-std = "1.12.0"
 async-trait = "0.1.57"
 ctrlc = { version = "3.2.3", features = ["termination"] }
 easy-parallel = "3.2.0"
-futures-lite = "1.12.0"
+smol = "1.2.5"
 
 # Misc
 blake3 = "1.3.1"
@@ -30,7 +28,6 @@ simplelog = "0.12.0"
 url = "2.3.1"
 
 # Argument parsing
-serde = "1.0.145"
-serde_derive = "1.0.145"
+serde = {version = "1.0.145", features = ["derive"]}
 structopt = "0.3.26"
 structopt-toml = "0.5.1"

+ 7 - 12
bin/fud/fud/src/main.rs

@@ -1,13 +1,10 @@
-use async_executor::Executor;
+use std::{collections::HashSet, fs, path::PathBuf};
+
 use async_std::sync::Arc;
 use async_trait::async_trait;
-use futures_lite::future;
 use log::{debug, error, info, warn};
-use serde_derive::Deserialize;
 use serde_json::{json, Value};
-use std::{collections::HashSet, fs, path::PathBuf};
-use structopt::StructOpt;
-use structopt_toml::StructOptToml;
+use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
 use url::Url;
 
 use darkfi::{
@@ -22,15 +19,13 @@ use darkfi::{
         server::{listen_and_serve, RequestHandler},
     },
     serial::serialize,
-    util::{
-        cli::{get_log_config, get_log_level, spawn_config},
-        path::{expand_path, get_config_path},
-    },
+    util::path::expand_path,
     Result,
 };
 
 mod error;
 use error::{server_error, RpcError};
+
 const CONFIG_FILE: &str = "fud_config.toml";
 const CONFIG_FILE_CONTENTS: &str = include_str!("../fud_config.toml");
 
@@ -372,11 +367,11 @@ impl RequestHandler for Fud {
 }
 
 async_daemonize!(realmain);
-async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
     // We use this handler to block this function after detaching all
     // tasks, and to catch a shutdown signal, where we can clean up and
     // exit gracefully.
-    let (signal, shutdown) = async_channel::bounded::<()>(1);
+    let (signal, shutdown) = smol::channel::bounded::<()>(1);
     ctrlc::set_handler(move || {
         async_std::task::block_on(signal.send(())).unwrap();
     })

+ 0 - 3
bin/ircd/Cargo.toml

@@ -20,12 +20,9 @@ futures-rustls = "0.22.2"
 rustls-pemfile = "1.0.1"
 async-std = "1.12.0"
 async-trait = "0.1.57"
-async-channel = "1.7.1"
-async-executor = "1.4.1"
 easy-parallel = "3.2.0"
 async-recursion = "1.0.0"
 
-
 # Crypto
 crypto_box = "0.8.1"
 rand = "0.8.5"

+ 1 - 1
bin/ircd/src/irc/mod.rs

@@ -1,6 +1,5 @@
 use std::{fs::File, net::SocketAddr};
 
-use async_executor::Executor;
 use async_std::{
     net::TcpListener,
     sync::{Arc, Mutex},
@@ -9,6 +8,7 @@ use futures::{io::BufReader, AsyncRead, AsyncReadExt, AsyncWrite};
 use futures_rustls::{rustls, TlsAcceptor};
 use fxhash::FxHashMap;
 use log::{error, info};
+use smol::Executor;
 
 use darkfi::{
     net::P2pPtr,

+ 7 - 13
bin/ircd/src/main.rs

@@ -1,22 +1,16 @@
-use async_channel::Receiver;
-use async_executor::Executor;
-use async_std::sync::{Arc, Mutex};
 use std::fmt;
 
+use async_std::sync::{Arc, Mutex};
 use log::{info, warn};
 use rand::rngs::OsRng;
-use smol::future;
+use smol::channel::Receiver;
 use structopt_toml::StructOptToml;
 
 use darkfi::{
     async_daemonize, net,
     rpc::server::listen_and_serve,
     system::{Subscriber, SubscriberPtr},
-    util::{
-        cli::{get_log_config, get_log_level, spawn_config},
-        file::save_json_file,
-        path::{expand_path, get_config_path},
-    },
+    util::{file::save_json_file, path::expand_path},
     Result,
 };
 
@@ -68,7 +62,7 @@ impl Ircd {
         seen: Arc<Mutex<SeenIds>>,
         p2p: net::P2pPtr,
         p2p_receiver: Receiver<Privmsg>,
-        executor: Arc<Executor<'_>>,
+        executor: Arc<smol::Executor<'_>>,
     ) -> Result<()> {
         let notify_clients = self.notify_clients.clone();
         executor
@@ -98,7 +92,7 @@ impl Ircd {
 }
 
 async_daemonize!(realmain);
-async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(settings: Args, executor: Arc<smol::Executor<'_>>) -> Result<()> {
     let seen = Arc::new(Mutex::new(SeenIds::new()));
 
     if settings.gen_secret {
@@ -131,7 +125,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     //
     let mut net_settings = settings.net.clone();
     net_settings.app_version = Some(option_env!("CARGO_PKG_VERSION").unwrap_or("").to_string());
-    let (p2p_send_channel, p2p_recv_channel) = async_channel::unbounded::<Privmsg>();
+    let (p2p_send_channel, p2p_recv_channel) = smol::channel::unbounded::<Privmsg>();
 
     let p2p = net::P2p::new(net_settings.into()).await;
     let p2p2 = p2p.clone();
@@ -167,7 +161,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     ircd.start(&settings, seen, p2p, p2p_recv_channel, executor.clone()).await?;
 
     // Run once receive exit signal
-    let (signal, shutdown) = async_channel::bounded::<()>(1);
+    let (signal, shutdown) = smol::channel::bounded::<()>(1);
     ctrlc::set_handler(move || {
         warn!(target: "ircd", "ircd start Exit Signal");
         // cleaning up tasks running in the background

+ 2 - 2
bin/ircd/src/model.rs

@@ -14,11 +14,11 @@ use crate::settings::get_current_time;
 pub type EventId = [u8; 32];
 pub type EventsQueueArc = Arc<EventsQueue>;
 
-pub struct EventsQueue(async_channel::Sender<Event>, async_channel::Receiver<Event>);
+pub struct EventsQueue(smol::channel::Sender<Event>, smol::channel::Receiver<Event>);
 
 impl EventsQueue {
     pub fn new() -> EventsQueueArc {
-        let (sn, rv) = async_channel::unbounded();
+        let (sn, rv) = smol::channel::unbounded();
         Arc::new(Self(sn, rv))
     }
 

+ 3 - 3
bin/ircd/src/protocol_privmsg.rs

@@ -1,7 +1,7 @@
-use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use async_trait::async_trait;
 use log::debug;
+use smol::Executor;
 
 use darkfi::{
     net,
@@ -16,7 +16,7 @@ struct InvObject(String);
 
 pub struct ProtocolPrivmsg {
     jobsman: net::ProtocolJobsManagerPtr,
-    notify: async_channel::Sender<Privmsg>,
+    notify: smol::channel::Sender<Privmsg>,
     msg_sub: net::MessageSubscription<Privmsg>,
     p2p: net::P2pPtr,
     channel: net::ChannelPtr,
@@ -26,7 +26,7 @@ pub struct ProtocolPrivmsg {
 impl ProtocolPrivmsg {
     pub async fn init(
         channel: net::ChannelPtr,
-        notify: async_channel::Sender<Privmsg>,
+        notify: smol::channel::Sender<Privmsg>,
         p2p: net::P2pPtr,
         seen: Arc<Mutex<SeenIds>>,
     ) -> net::ProtocolBasePtr {

+ 1 - 1
bin/ircd/src/protocol_privmsg2.rs

@@ -1,11 +1,11 @@
 use std::collections::VecDeque;
 
-use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use async_trait::async_trait;
 use fxhash::FxHashMap;
 use log::debug;
 use rand::{rngs::OsRng, RngCore};
+use smol::Executor;
 
 use darkfi::{
     net,

+ 0 - 3
bin/ircd2/Cargo.toml

@@ -20,11 +20,8 @@ futures-rustls = "0.22.2"
 rustls-pemfile = "1.0.1"
 async-std = "1.12.0"
 async-trait = "0.1.57"
-async-channel = "1.7.1"
-async-executor = "1.4.1"
 easy-parallel = "3.2.0"
 
-
 # Crypto
 crypto_box = "0.8.1"
 rand = "0.8.5"

+ 3 - 3
bin/ircd2/src/events_queue.rs

@@ -1,4 +1,4 @@
-use std::sync::Arc;
+use async_std::sync::Arc;
 
 use darkfi::{Error, Result};
 
@@ -6,11 +6,11 @@ use crate::model::Event;
 
 pub type EventsQueuePtr = Arc<EventsQueue>;
 
-pub struct EventsQueue(async_channel::Sender<Event>, async_channel::Receiver<Event>);
+pub struct EventsQueue(smol::channel::Sender<Event>, smol::channel::Receiver<Event>);
 
 impl EventsQueue {
     pub fn new() -> EventsQueuePtr {
-        let (sn, rv) = async_channel::unbounded();
+        let (sn, rv) = smol::channel::unbounded();
         Arc::new(Self(sn, rv))
     }
 

+ 2 - 2
bin/ircd2/src/irc/client.rs

@@ -28,7 +28,7 @@ pub struct IrcClient<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> {
     // irc config
     irc_config: IrcConfig,
 
-    server_notifier: async_channel::Sender<(NotifierMsg, u64)>,
+    server_notifier: smol::channel::Sender<(NotifierMsg, u64)>,
     subscription: Subscription<ClientSubMsg>,
 }
 
@@ -38,7 +38,7 @@ impl<C: AsyncRead + AsyncWrite + Send + Unpin + 'static> IrcClient<C> {
         read_stream: BufReader<ReadHalf<C>>,
         address: SocketAddr,
         irc_config: IrcConfig,
-        server_notifier: async_channel::Sender<(NotifierMsg, u64)>,
+        server_notifier: smol::channel::Sender<(NotifierMsg, u64)>,
         subscription: Subscription<ClientSubMsg>,
     ) -> Self {
         Self { write_stream, read_stream, address, irc_config, subscription, server_notifier }

+ 8 - 9
bin/ircd2/src/irc/mod.rs

@@ -1,7 +1,6 @@
-use async_std::{net::TcpListener, sync::Arc};
 use std::{collections::HashMap, fs::File, net::SocketAddr};
 
-use async_executor::Executor;
+use async_std::{net::TcpListener, sync::Arc};
 use futures::{io::BufReader, AsyncRead, AsyncReadExt, AsyncWrite};
 use futures_rustls::{rustls, TlsAcceptor};
 use log::{error, info};
@@ -94,8 +93,8 @@ impl IrcServer {
     ) -> Result<Self> {
         Ok(Self { settings, clients_subscriptions })
     }
-    pub async fn start(&self, executor: Arc<Executor<'_>>) -> Result<()> {
-        let (msg_notifier, msg_recv) = async_channel::unbounded();
+    pub async fn start(&self, executor: Arc<smol::Executor<'_>>) -> Result<()> {
+        let (msg_notifier, msg_recv) = smol::channel::unbounded();
 
         // Listen to msgs from clients
         executor.spawn(Self::listen_to_msgs(msg_recv, self.clients_subscriptions.clone())).detach();
@@ -108,7 +107,7 @@ impl IrcServer {
 
     /// Start listening to msgs from irc clients
     pub async fn listen_to_msgs(
-        recv: async_channel::Receiver<(NotifierMsg, u64)>,
+        recv: smol::channel::Receiver<(NotifierMsg, u64)>,
         clients_subscriptions: SubscriberPtr<ClientSubMsg>,
     ) -> Result<()> {
         loop {
@@ -143,8 +142,8 @@ impl IrcServer {
     /// Start listening to new connections from irc clients
     pub async fn listen(
         &self,
-        notifier: async_channel::Sender<(NotifierMsg, u64)>,
-        executor: Arc<Executor<'_>>,
+        notifier: smol::channel::Sender<(NotifierMsg, u64)>,
+        executor: Arc<smol::Executor<'_>>,
     ) -> Result<()> {
         let (listener, acceptor) = self.setup_listener().await?;
         info!("[IRC SERVER] listening on {}", self.settings.irc_listen);
@@ -187,8 +186,8 @@ impl IrcServer {
         &self,
         stream: C,
         peer_addr: SocketAddr,
-        notifier: async_channel::Sender<(NotifierMsg, u64)>,
-        executor: Arc<Executor<'_>>,
+        notifier: smol::channel::Sender<(NotifierMsg, u64)>,
+        executor: Arc<smol::Executor<'_>>,
     ) -> Result<()> {
         let (reader, writer) = stream.split();
         let reader = BufReader::new(reader);

+ 3 - 10
bin/ircd2/src/main.rs

@@ -1,20 +1,13 @@
-use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
-
 use log::{info, warn};
 use rand::rngs::OsRng;
-use smol::future;
 use structopt_toml::StructOptToml;
 
 use darkfi::{
     async_daemonize, net,
     rpc::server::listen_and_serve,
     system::Subscriber,
-    util::{
-        cli::{get_log_config, get_log_level, spawn_config},
-        file::save_json_file,
-        path::{expand_path, get_config_path},
-    },
+    util::{file::save_json_file, path::expand_path},
     Result,
 };
 
@@ -40,7 +33,7 @@ use crate::{
 };
 
 async_daemonize!(realmain);
-async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(settings: Args, executor: Arc<smol::Executor<'_>>) -> Result<()> {
     ////////////////////
     // Generate new keypair and exit
     ////////////////////
@@ -129,7 +122,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     ////////////////////
     // Wait for SIGINT
     ////////////////////
-    let (signal, shutdown) = async_channel::bounded::<()>(1);
+    let (signal, shutdown) = smol::channel::bounded::<()>(1);
     ctrlc::set_handler(move || {
         warn!(target: "ircd", "ircd start Exit Signal");
         // cleaning up tasks running in the background

+ 1 - 2
bin/ircd2/src/protocol_event.rs

@@ -1,6 +1,5 @@
 use std::collections::VecDeque;
 
-use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use async_trait::async_trait;
 use fxhash::FxHashMap;
@@ -334,7 +333,7 @@ impl ProtocolEvent {
 
 #[async_trait]
 impl net::ProtocolBase for ProtocolEvent {
-    async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
+    async fn start(self: Arc<Self>, executor: Arc<smol::Executor<'_>>) -> Result<()> {
         debug!(target: "ircd", "ProtocolEvent::start() [START]");
         self.jobsman.clone().start(executor.clone());
         self.jobsman.clone().spawn(self.clone().handle_receive_event(), executor.clone()).await;

+ 2 - 5
bin/lilith/Cargo.toml

@@ -14,13 +14,11 @@ categories = []
 darkfi = {path = "../../", features = ["net", "rpc"]}
 
 # Async
-async-channel = "1.7.1"
-async-executor = "1.4.1"
 async-std = "1.12.0"
 async-trait = "0.1.57"
 ctrlc = { version = "3.2.3", features = ["termination"] }
 easy-parallel = "3.2.0"
-futures-lite = "1.12.0"
+smol = "1.2.5"
 
 # Misc
 fxhash = "0.2.1"
@@ -30,8 +28,7 @@ simplelog = "0.12.0"
 url = "2.3.1"
 
 # Argument parsing
-serde = "1.0.145"
-serde_derive = "1.0.145"
+serde = {version = "1.0.145", features = ["derive"]}
 structopt = "0.3.26"
 structopt-toml = "0.5.1"
 toml = "0.5.9"

+ 1 - 3
bin/lilith/src/config.rs

@@ -1,8 +1,6 @@
 use fxhash::FxHashMap;
 use log::{info, warn};
-use serde_derive::Deserialize;
-use structopt::StructOpt;
-use structopt_toml::StructOptToml;
+use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
 use toml::Value;
 use url::Url;
 

+ 3 - 6
bin/lilith/src/main.rs

@@ -1,9 +1,7 @@
 use std::path::Path;
 
-use async_executor::Executor;
 use async_std::sync::Arc;
 use async_trait::async_trait;
-use futures_lite::future;
 use fxhash::{FxHashMap, FxHashSet};
 use log::{error, info, warn};
 use serde_json::{json, Value};
@@ -21,7 +19,6 @@ use darkfi::{
         server::{listen_and_serve, RequestHandler},
     },
     util::{
-        cli::{get_log_config, get_log_level, spawn_config},
         file::{load_file, save_file},
         path::{expand_path, get_config_path},
     },
@@ -135,7 +132,7 @@ async fn spawn_network(
     info: NetInfo,
     urls: Vec<Url>,
     saved_hosts: Option<&FxHashSet<Url>>,
-    ex: Arc<Executor<'_>>,
+    ex: Arc<smol::Executor<'_>>,
 ) -> Result<Spawn> {
     let mut full_urls = Vec::new();
     for url in &urls {
@@ -243,11 +240,11 @@ fn save_hosts(path: &Path, spawns: FxHashMap<String, Vec<String>>) {
 }
 
 async_daemonize!(realmain);
-async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
     // We use this handler to block this function after detaching all
     // tasks, and to catch a shutdown signal, where we can clean up and
     // exit gracefully.
-    let (signal, shutdown) = async_channel::bounded::<()>(1);
+    let (signal, shutdown) = smol::channel::bounded::<()>(1);
     ctrlc::set_handler(move || {
         async_std::task::block_on(signal.send(())).unwrap();
     })

+ 0 - 2
bin/tau/taud/Cargo.toml

@@ -17,8 +17,6 @@ darkfi = { path = "../../../", features = ["rpc", "raft", "net", "bs58"]}
 smol = "1.2.5"
 async-std = {version = "1.12.0", features = ["attributes"]}
 async-trait = "0.1.57"
-async-channel = "1.7.1"
-async-executor = "1.4.1"
 easy-parallel = "3.2.0"
 futures = "0.3.24"
 

+ 2 - 2
bin/tau/taud/src/jsonrpc.rs

@@ -27,7 +27,7 @@ use crate::{
 
 pub struct JsonRpcInterface {
     dataset_path: PathBuf,
-    notify_queue_sender: async_channel::Sender<TaskInfo>,
+    notify_queue_sender: smol::channel::Sender<TaskInfo>,
     nickname: String,
     workspace: Mutex<String>,
     workspaces: FxHashMap<String, SalsaBox>,
@@ -78,7 +78,7 @@ impl RequestHandler for JsonRpcInterface {
 impl JsonRpcInterface {
     pub fn new(
         dataset_path: PathBuf,
-        notify_queue_sender: async_channel::Sender<TaskInfo>,
+        notify_queue_sender: smol::channel::Sender<TaskInfo>,
         nickname: String,
         workspaces: FxHashMap<String, SalsaBox>,
         p2p: net::P2pPtr,

+ 8 - 13
bin/tau/taud/src/main.rs

@@ -5,7 +5,6 @@ use std::{
     path::Path,
 };
 
-use async_executor::Executor;
 use async_std::sync::{Arc, Mutex};
 use crypto_box::{
     aead::{Aead, AeadCore},
@@ -14,7 +13,6 @@ use crypto_box::{
 use futures::{select, FutureExt};
 use fxhash::FxHashMap;
 use log::{debug, error, info, warn};
-use smol::future;
 use structopt_toml::StructOptToml;
 
 use darkfi::{
@@ -22,10 +20,7 @@ use darkfi::{
     raft::{NetMsg, ProtocolRaft, Raft, RaftSettings},
     rpc::server::listen_and_serve,
     serial::{deserialize, serialize, SerialDecodable, SerialEncodable},
-    util::{
-        cli::{get_log_config, get_log_level, spawn_config},
-        path::{expand_path, get_config_path},
-    },
+    util::path::expand_path,
     Error, Result,
 };
 
@@ -97,9 +92,9 @@ fn decrypt_task(encrypt_task: &EncryptedTask, salsa_box: &SalsaBox) -> TaudResul
 }
 
 async fn start_sync_loop(
-    broadcast_rcv: async_channel::Receiver<TaskInfo>,
-    raft_msgs_sender: async_channel::Sender<EncryptedTask>,
-    commits_recv: async_channel::Receiver<EncryptedTask>,
+    broadcast_rcv: smol::channel::Receiver<TaskInfo>,
+    raft_msgs_sender: smol::channel::Sender<EncryptedTask>,
+    commits_recv: smol::channel::Receiver<EncryptedTask>,
     datastore_path: std::path::PathBuf,
     workspaces: FxHashMap<String, SalsaBox>,
     mut rng: crypto_box::rand_core::OsRng,
@@ -145,7 +140,7 @@ async fn on_receive_task(
 }
 
 async_daemonize!(realmain);
-async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
+async fn realmain(settings: Args, executor: Arc<smol::Executor<'_>>) -> Result<()> {
     let datastore_path = expand_path(&settings.datastore)?;
 
     let nickname =
@@ -225,14 +220,14 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     let mut raft = Raft::<EncryptedTask>::new(raft_settings, seen_net_msgs.clone())?;
     let raft_id = raft.id();
 
-    let (broadcast_snd, broadcast_rcv) = async_channel::unbounded::<TaskInfo>();
+    let (broadcast_snd, broadcast_rcv) = smol::channel::unbounded::<TaskInfo>();
 
     //
     // P2p setup
     //
     let mut net_settings = settings.net.clone();
     net_settings.app_version = Some(option_env!("CARGO_PKG_VERSION").unwrap_or("").to_string());
-    let (p2p_send_channel, p2p_recv_channel) = async_channel::unbounded::<NetMsg>();
+    let (p2p_send_channel, p2p_recv_channel) = smol::channel::unbounded::<NetMsg>();
 
     let p2p = net::P2p::new(net_settings.into()).await;
     let p2p = p2p.clone();
@@ -268,7 +263,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     //
     // Waiting Exit signal
     //
-    let (signal, shutdown) = async_channel::bounded::<()>(1);
+    let (signal, shutdown) = smol::channel::bounded::<()>(1);
     ctrlc::set_handler(move || {
         warn!(target: "tau", "Catch exit signal");
         // cleaning up tasks running in the background

+ 15 - 27
src/util/cli.rs

@@ -89,36 +89,24 @@ pub fn get_log_config() -> simplelog::Config {
 ///
 /// The Cargo.toml dependencies needed for this are:
 /// ```text
-/// async-channel = "1.7.1"
-/// async-executor = "1.4.1"
 /// async-std = "1.12.0"
 /// darkfi = { path = "../../", features = ["util"] }
 /// easy-parallel = "3.2.0"
-/// futures-lite = "1.12.0"
 /// simplelog = "0.12.0"
+/// smol = "1.2.5"
 ///
 /// # Argument parsing
-/// serde = "1.0.135"
-/// serde_derive = "1.0.145"
+/// serde = {version = "1.0.135", features = ["derive"]}
 /// structopt = "0.3.26"
 /// structopt-toml = "0.5.1"
 /// ```
 ///
 /// Example usage:
-/// ```text
+/// ```no_run
 /// use async_std::sync::Arc;
-/// use futures_lite::future;
+//  use darkfi::{async_daemonize, cli_desc, Result};
 /// use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
 ///
-/// use darkfi::{
-///     async_daemonize, cli_desc,
-///     util::{
-///         cli::{get_log_config, get_log_level, spawn_config},
-///         path::get_config_path, expand_path
-///     },
-///     Result,
-/// };
-///
 /// const CONFIG_FILE: &str = "daemond_config.toml";
 /// const CONFIG_FILE_CONTENTS: &str = include_str!("../daemond_config.toml");
 ///
@@ -136,7 +124,7 @@ pub fn get_log_config() -> simplelog::Config {
 /// }
 ///
 /// async_daemonize!(realmain);
-/// async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
+/// async fn realmain(args: Args, ex: Arc<smol::Executor<'_>>) -> Result<()> {
 ///     println!("Hello, world!");
 ///     Ok(())
 /// }
@@ -147,12 +135,12 @@ macro_rules! async_daemonize {
     ($realmain:ident) => {
         fn main() -> Result<()> {
             let args = Args::from_args_with_toml("").unwrap();
-            let cfg_path = get_config_path(args.config, CONFIG_FILE)?;
-            spawn_config(&cfg_path, CONFIG_FILE_CONTENTS.as_bytes())?;
+            let cfg_path = darkfi::util::path::get_config_path(args.config, CONFIG_FILE)?;
+            darkfi::util::cli::spawn_config(&cfg_path, CONFIG_FILE_CONTENTS.as_bytes())?;
             let args = Args::from_args_with_toml(&std::fs::read_to_string(cfg_path)?).unwrap();
 
-            let log_level = get_log_level(args.verbose.into());
-            let log_config = get_log_config();
+            let log_level = darkfi::util::cli::get_log_level(args.verbose.into());
+            let log_config = darkfi::util::cli::get_log_config();
 
             let log_file_path = match std::env::var("DARKFI_LOG") {
                 Ok(p) => p,
@@ -162,12 +150,12 @@ macro_rules! async_daemonize {
                     } else {
                         "darkfi"
                     };
-                    std::fs::create_dir_all(expand_path("~/.local/darkfi")?)?;
+                    std::fs::create_dir_all(darkfi::util::path::expand_path("~/.local/darkfi")?)?;
                     format!("~/.local/darkfi/{}.log", bin_name)
                 }
             };
 
-            let log_file_path = expand_path(&log_file_path)?;
+            let log_file_path = darkfi::util::path::expand_path(&log_file_path)?;
             let log_file = std::fs::File::create(log_file_path)?;
 
             simplelog::CombinedLogger::init(vec![
@@ -181,14 +169,14 @@ macro_rules! async_daemonize {
             ])?;
 
             // https://docs.rs/smol/latest/smol/struct.Executor.html#examples
-            let ex = Arc::new(async_executor::Executor::new());
-            let (signal, shutdown) = async_channel::unbounded::<()>();
+            let ex = async_std::sync::Arc::new(smol::Executor::new());
+            let (signal, shutdown) = smol::channel::unbounded::<()>();
             let (_, result) = easy_parallel::Parallel::new()
                 // Run four executor threads
-                .each(0..4, |_| future::block_on(ex.run(shutdown.recv())))
+                .each(0..4, |_| smol::future::block_on(ex.run(shutdown.recv())))
                 // Run the main future on the current thread.
                 .finish(|| {
-                    future::block_on(async {
+                    smol::future::block_on(async {
                         $realmain(args, ex.clone()).await?;
                         drop(signal);
                         Ok::<(), darkfi::Error>(())