Procházet zdrojové kódy

bin/ircd2: add net::Settings to Args struct & add demo config file

ghassmo před 4 roky
rodič
revize
7ddd2e32d7
5 změnil soubory, kde provedl 175 přidání a 155 odebrání
  1. 2 0
      Cargo.lock
  2. 135 130
      Cargo.toml
  3. 19 0
      bin/ircd2/ircd_config.toml
  4. 8 13
      bin/ircd2/src/main.rs
  5. 11 12
      bin/ircd2/src/settings.rs

+ 2 - 0
Cargo.lock

@@ -1149,6 +1149,8 @@ dependencies = [
  "smol",
  "socket2",
  "sqlx",
+ "structopt",
+ "structopt-toml",
  "subtle",
  "termion",
  "thiserror",

+ 135 - 130
Cargo.toml

@@ -18,25 +18,25 @@ name = "darkfi"
 
 [workspace]
 members = [
-    "bin/zkas",
-    #"bin/cashierd",
-    #"bin/darkfid",
-    "bin/darkfid2",
-    "bin/drk",
-    "bin/faucetd",
-    #"bin/gatewayd",
-    "bin/ircd",
-    "bin/ircd2",
-    "bin/dnetview",
-    "bin/daod",
-    "bin/dao-cli",
-    "bin/tau/taud",
-    "bin/tau/tau-cli",
-    "bin/vanityaddr",
-
-    "src/sdk",
-    "src/util/derive",
-    "src/util/derive-internal",
+	"bin/zkas",
+	#"bin/cashierd",
+	#"bin/darkfid",
+	"bin/darkfid2",
+	"bin/drk",
+	"bin/faucetd",
+	#"bin/gatewayd",
+	"bin/ircd",
+	"bin/ircd2",
+	"bin/dnetview",
+	"bin/daod",
+	"bin/dao-cli",
+	"bin/tau/taud",
+	"bin/tau/tau-cli",
+	"bin/vanityaddr",
+
+	"src/sdk",
+	"src/util/derive",
+	"src/util/derive-internal",
 ]
 
 [dependencies]
@@ -75,6 +75,8 @@ bincode = {version = "1.3.3", optional = true}
 num-bigint = {version = "0.4.3", features = ["serde"], optional = true}
 serde_json = {version = "1.0.79", optional = true}
 serde = {version = "1.0.136", features = ["derive"], optional = true}
+structopt = {version= "0.3.26", optional = true}
+structopt-toml = {version = "0.5.0", optional = true}
 
 # Utilities
 url = {version = "2.2.2", features = ["serde"], optional = true}
@@ -98,7 +100,7 @@ simplelog = {version = "0.12.0", optional = true}
 tungstenite = {version = "0.17.2", optional = true}
 async-tungstenite = {version = "0.17.2", optional = true}
 
-# socks5 
+# socks5
 fast-socks5 = {git = "https://github.com/ghassmo/fast-socks5", optional = true}
 
 # Crypto
@@ -133,168 +135,171 @@ clap = {version = "3.1.12", features = ["derive"]}
 
 [features]
 async-runtime = [
-    "async-std",
-    "async-channel",
-    "async-executor",
-    "async-trait",
-    "futures",
-    "smol",
+	"async-std",
+	"async-channel",
+	"async-executor",
+	"async-trait",
+	"futures",
+	"smol",
 ]
 
 async-net = [
-    "async-native-tls",
-    "native-tls",
+	"async-native-tls",
+	"native-tls",
 ]
 
 websockets = [
-    "async-tungstenite",
-    "tungstenite",
+	"async-tungstenite",
+	"tungstenite",
 ]
 
 util = [
-    "hex",
-    "bincode",
-    "serde",
-    "toml",
-    "url",
-    "simplelog",
-    "serde_json",
-    "dirs",
-    "num-bigint",
-    "fxhash",
-
-    "darkfi-derive",
-    "darkfi-derive-internal",
+	"hex",
+	"bincode",
+	"serde",
+	"toml",
+	"url",
+	"simplelog",
+	"serde_json",
+	"dirs",
+	"num-bigint",
+	"fxhash",
+
+
+	"darkfi-derive",
+	"darkfi-derive-internal",
 ]
 
 rpc = [
-    "rand",
-    "url",
-    "fast-socks5",
-
-    "async-net",
-    "async-runtime",
-    "websockets",
-    "util",
+	"rand",
+	"url",
+	"fast-socks5",
+
+	"async-net",
+	"async-runtime",
+	"websockets",
+	"util",
 	"net",
 ]
 
 blockchain = [
-    "blake3",
-    "chrono",
-    "indexmap",
-    "sled",
-
-    "crypto",
-    "tx",
-    "net",
-    "util",
+	"blake3",
+	"chrono",
+	"indexmap",
+	"sled",
+
+	"crypto",
+	"tx",
+	"net",
+	"util",
 ]
 
 system = [
-    "fxhash",
-    "rand",
+	"fxhash",
+	"rand",
 
-    "async-runtime",
+	"async-runtime",
 ]
 
 net = [
-    "fxhash",
-    "socket2",
-    "futures-rustls",
-    "fast-socks5",
-    "ed25519-compact",
-    "rcgen",
-    "regex",
-    "rustls-pemfile",
-
-    "util",
-    "system",
+	"fxhash",
+	"socket2",
+	"futures-rustls",
+	"fast-socks5",
+	"ed25519-compact",
+	"rcgen",
+	"regex",
+	"rustls-pemfile",
+	"structopt",
+	"structopt-toml",
+
+	"util",
+	"system",
 ]
 
 net2 = [
-    "fxhash",
-    "socket2",
-    "futures-rustls",
-    "fast-socks5",
-    "ed25519-compact",
-    "rcgen",
-    "regex",
-    "rustls-pemfile",
-
-    "util",
-    "system",
+	"fxhash",
+	"socket2",
+	"futures-rustls",
+	"fast-socks5",
+	"ed25519-compact",
+	"rcgen",
+	"regex",
+	"rustls-pemfile",
+
+	"util",
+	"system",
 ]
 
 crypto = [
-    "bitvec",
-    "blake3",
-    "rand",
-    "pasta_curves",
-    "blake2b_simd",
-    "incrementalmerkletree",
-    "halo2_proofs",
-    "halo2_gadgets",
-    "subtle",
-    "lazy_static",
-    "group",
-    "arrayvec",
-    "crypto_api_chachapoly",
-    "sha2",
-    "bs58",
-
-    "util",
-    "zkas",
+	"bitvec",
+	"blake3",
+	"rand",
+	"pasta_curves",
+	"blake2b_simd",
+	"incrementalmerkletree",
+	"halo2_proofs",
+	"halo2_gadgets",
+	"subtle",
+	"lazy_static",
+	"group",
+	"arrayvec",
+	"crypto_api_chachapoly",
+	"sha2",
+	"bs58",
+
+	"util",
+	"zkas",
 ]
 
 wallet = [
-    "sqlx",
-    "libsqlite3-sys",
+	"sqlx",
+	"libsqlite3-sys",
 
-    "crypto",
-    "util",
+	"crypto",
+	"util",
 ]
 
 wasm-runtime = [
-    "drk-sdk",
-    "wasmer",
-    "wasmer-compiler-singlepass",
-    "wasmer-middlewares",
+	"drk-sdk",
+	"wasmer",
+	"wasmer-compiler-singlepass",
+	"wasmer-middlewares",
 ]
 
 node = [
-    "url",
-    "bytes",
-    "lazy-init",
-
-    "async-runtime",
-    "blockchain",
-    "crypto",
-    "wallet",
-    "util",
-    "net",
+	"url",
+	"bytes",
+	"lazy-init",
+
+	"async-runtime",
+	"blockchain",
+	"crypto",
+	"wallet",
+	"util",
+	"net",
 ]
 
 zkas = [
-    "termion",
-    "indexmap",
-    "itertools",
+	"termion",
+	"indexmap",
+	"itertools",
 
-    "util",
+	"util",
 ]
 
 raft = [
-    "blake3",
+	"blake3",
 	"sled",
 
 	"util",
-    "net",
-    "rpc",
+	"net",
+	"rpc",
 ]
 
 tx = [
-    "crypto",
-    "util",
+	"crypto",
+	"util",
 ]
 
 [[example]]

+ 19 - 0
bin/ircd2/ircd_config.toml

@@ -1 +1,20 @@
+# JSON-RPC listen URL
+rpc_listen="127.0.0.1:8857"
+# IRC listen URL
+irc_listen="127.0.0.1:8855"
+# Sets Datastore Path
+datastore="~/.config/tau"
 
+# Raft net settings
+type="Net"
+[args]
+inbound="127.0.0.1:11002"
+outbound_connections=0
+manual_attempt_limit=0
+seed_query_timeout_seconds=8
+connect_timeout_seconds=10
+channel_handshake_seconds=4
+channel_heartbeat_seconds=10
+external_addr="127.0.0.1:11002"
+peers=["127.0.0.1:11003"]
+seeds=["127.0.0.1:11001"]

+ 8 - 13
bin/ircd2/src/main.rs

@@ -11,7 +11,7 @@ use smol::future;
 use structopt_toml::StructOptToml;
 
 use darkfi::{
-    async_daemonize, net,
+    async_daemonize,
     raft::Raft,
     rpc::rpcserver::{listen_and_serve, RpcServerConfig},
     util::{
@@ -30,7 +30,7 @@ use crate::{
     privmsg::Privmsg,
     rpc::JsonRpcInterface,
     server::IrcServerConnection,
-    settings::{Args, CONFIG_FILE, CONFIG_FILE_CONTENTS},
+    settings::{Args, Command, CONFIG_FILE, CONFIG_FILE_CONTENTS},
 };
 
 async fn process_user_input(
@@ -103,23 +103,18 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     let local_addr = listener.local_addr()?;
     info!("Listening on {}", local_addr);
 
-    let p2p_settings = net::Settings {
-        inbound: settings.accept,
-        outbound_connections: settings.slots,
-        external_addr: settings.accept,
-        peers: settings.connect.clone(),
-        seeds: settings.seeds.clone(),
-        ..Default::default()
-    };
-
     let datastore_path = PathBuf::from(&settings.datastore);
 
+    let net_settings = match settings.command {
+        Command::Net(s) => s,
+    };
+
     //
     //Raft
     //
     let datastore_raft = datastore_path.join("ircd.db");
 
-    let mut raft = Raft::<Privmsg>::new(settings.accept, datastore_raft)?;
+    let mut raft = Raft::<Privmsg>::new(net_settings.inbound, datastore_raft)?;
 
     let raft_sender = raft.get_broadcast();
     let commits = raft.get_commits();
@@ -173,7 +168,7 @@ async fn realmain(settings: Args, executor: Arc<Executor<'_>>) -> Result<()> {
     .unwrap();
 
     // blocking
-    raft.start(p2p_settings.clone(), executor.clone(), shutdown.clone()).await?;
+    raft.start(net_settings, executor.clone(), shutdown.clone()).await?;
 
     Ok(())
 }

+ 11 - 12
bin/ircd2/src/settings.rs

@@ -4,6 +4,8 @@ use serde::Deserialize;
 use structopt::StructOpt;
 use structopt_toml::StructOptToml;
 
+use darkfi::net;
+
 pub const CONFIG_FILE: &str = "ircd_config.toml";
 pub const CONFIG_FILE_CONTENTS: &str = include_str!("../ircd_config.toml");
 
@@ -24,19 +26,16 @@ pub struct Args {
     /// Sets Datastore Path
     #[structopt(long, default_value = "~/.config/tau")]
     pub datastore: String,
-    /// Raft Accept address
-    #[structopt(short, long)]
-    pub accept: Option<SocketAddr>,
-    /// Raft Seed nodes (repeatable)
-    #[structopt(short, long)]
-    pub seeds: Vec<SocketAddr>,
-    /// Raft Manual connection (repeatable)
-    #[structopt(short, long)]
-    pub connect: Vec<SocketAddr>,
-    /// Raft Connection slots
-    #[structopt(long, default_value = "0")]
-    pub slots: u32,
+    #[structopt(subcommand)]
+    pub command: Command,
     /// Increase verbosity
     #[structopt(short, parse(from_occurrences))]
     pub verbose: u8,
 }
+
+#[derive(Clone, Debug, Deserialize, StructOpt)]
+#[serde(tag = "type", content = "args")]
+pub enum Command {
+    /// Raft net settings
+    Net(net::Settings),
+}