فهرست منبع

p2pnet: optional channel log implemented

aggstam 3 سال پیش
والد
کامیت
a5dc158f90

+ 3 - 0
bin/darkfid/darkfid_config.toml

@@ -69,6 +69,9 @@
 # Enable localnet hosts
 #localnet = true
 
+# Enable channel log
+#channel_log = true
+
 # Whitelisted cashier addresses
 #cashier_pub = []
 

+ 6 - 0
bin/darkfid/src/main.rs

@@ -140,6 +140,10 @@ struct Args {
     /// Enable localnet hosts
     localnet: bool,
 
+    #[structopt(long)]
+    /// Enable channel log
+    channel_log: bool,
+
     #[structopt(long)]
     /// Whitelisted cashier address (repeatable flag)
     cashier_pub: Vec<String>,
@@ -341,6 +345,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
             seeds: args.sync_p2p_seed.clone(),
             outbound_transports: net::settings::get_outbound_transports(args.sync_p2p_transports),
             localnet: args.localnet,
+            channel_log: args.channel_log,
             ..Default::default()
         };
 
@@ -386,6 +391,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
                     args.consensus_p2p_transports,
                 ),
                 localnet: args.localnet,
+                channel_log: args.channel_log,
                 ..Default::default()
             };
             let p2p = net::P2p::new(consensus_network_settings).await;

+ 3 - 0
bin/faucetd/faucetd_config.toml

@@ -42,6 +42,9 @@
 # Enable localnet hosts
 #localnet = true
 
+# Enable channel log
+#channel_log = true
+
 # Airdrop timeout limit in seconds
 #airdrop_timeout = 600
 

+ 5 - 0
bin/faucetd/src/main.rs

@@ -104,6 +104,10 @@ struct Args {
     /// Enable localnet hosts
     localnet: bool,
 
+    #[structopt(long)]
+    /// Enable channel log
+    channel_log: bool,
+
     #[structopt(long)]
     /// Whitelisted cashier address (repeatable flag)
     cashier_pub: Vec<String>,
@@ -371,6 +375,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
         seeds: args.sync_p2p_seed.clone(),
         outbound_transports: net::settings::get_outbound_transports(args.sync_p2p_transports),
         localnet: args.localnet,
+        channel_log: args.channel_log,
         ..Default::default()
     };
 

+ 4 - 0
bin/lilith/lilith_config.toml

@@ -21,21 +21,25 @@
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true
 
 #[network."darkfid_consensus"]
 #port = 33033
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true
 
 #[network."ircd"]
 #port = 25551
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true
 
 #[network."taud"]
 #port = 23331
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true

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

@@ -44,6 +44,8 @@ pub struct NetInfo {
     pub peers: Vec<Url>,
     /// Enable localnet hosts
     pub localnet: bool,
+    /// Enable channel log
+    pub channel_log: bool,
 }
 
 /// Parse a TOML string for any configured network and return
@@ -103,7 +105,13 @@ pub fn parse_configured_networks(data: &str) -> Result<FxHashMap<String, NetInfo
                     false
                 };
 
-                let net_info = NetInfo { port, seeds, peers, localnet };
+                let channel_log = if table.contains_key("channel_log") {
+                    table["channel_log"].as_bool().unwrap()
+                } else {
+                    false
+                };
+
+                let net_info = NetInfo { port, seeds, peers, localnet, channel_log };
                 ret.insert(name, net_info);
             }
         }

+ 1 - 0
bin/lilith/src/main.rs

@@ -149,6 +149,7 @@ async fn spawn_network(
         peers: info.peers,
         outbound_connections: 0,
         localnet: info.localnet,
+        channel_log: info.channel_log,
         app_version: None,
         ..Default::default()
     };

+ 3 - 0
contrib/localnet/darkfid/darkfid0.toml

@@ -64,6 +64,9 @@ sync_p2p_seed = ["tcp://127.0.0.1:33032"]
 # Enable localnet hosts
 localnet = true
 
+# Enable channel log
+channel_log = true
+
 # Whitelisted faucet public key
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
 

+ 3 - 0
contrib/localnet/darkfid/darkfid1.toml

@@ -69,6 +69,9 @@ sync_p2p_seed = ["tcp://127.0.0.1:33032"]
 # Enable localnet hosts
 localnet = true
 
+# Enable channel log
+channel_log = true
+
 # Whitelisted faucet public key
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
 

+ 3 - 0
contrib/localnet/darkfid/darkfid2.toml

@@ -63,6 +63,9 @@ sync_p2p_seed = ["tcp://127.0.0.1:33032"]
 # Enable localnet hosts
 localnet = true
 
+# Enable channel log
+channel_log = true
+
 # Whitelisted faucet public key
 faucet_pub = ["1z3JuN456MieHtpoF4cr5a1ntFF87L8Z3m2E5ACppFodFcjnLS"]
 

+ 3 - 0
contrib/localnet/darkfid/faucetd.toml

@@ -42,6 +42,9 @@ sync_p2p_seed = ["tcp://127.0.0.1:33032"]
 # Enable localnet hosts
 localnet = true
 
+# Enable channel log
+channel_log = true
+
 # Airdrop timeout limit in seconds
 airdrop_timeout = 10
 

+ 2 - 0
contrib/localnet/darkfid/lilith_config.toml

@@ -21,12 +21,14 @@ port = 33032
 #seeds = []
 #peers = []
 localnet = true
+channel_log = true
 
 [network."darkfid_consensus"]
 port = 33033
 #seeds = []
 #peers = []
 localnet = true
+channel_log = true
 
 #[network."ircd"]
 #port = 25551

+ 2 - 0
contrib/localnet/ircd-five-peers/ircd_a.toml

@@ -8,6 +8,8 @@ inbound = ["tls://127.0.0.1:25560"]
 external_addr = ["tls://127.0.0.1:25560"]
 seeds = []
 peers = []
+localnet = true
+channel_log = true
 
 [channel."#plain"]
 topic = "Plain unencrypted channel"

+ 2 - 1
contrib/localnet/ircd-five-peers/ircd_b.toml

@@ -1,5 +1,4 @@
 # Node B
-
 rpc_listen = "tcp://127.0.0.1:25551"
 irc_listen = "tcp://127.0.0.1:25571"
 
@@ -9,6 +8,8 @@ inbound = ["tls://127.0.0.1:25561"]
 external_addr = ["tls://127.0.0.1:25561"]
 seeds = []
 peers = ["tls://127.0.0.1:25560"]
+localnet = true
+channel_log = true
 
 [channel."#encrypted"]
 topic ="Encrypted channel"

+ 2 - 0
contrib/localnet/ircd-five-peers/ircd_c.toml

@@ -8,6 +8,8 @@ inbound = ["tls://127.0.0.1:25562"]
 external_addr = ["tls://127.0.0.1:25562"]
 seeds = []
 peers = ["tls://127.0.0.1:25560"]
+localnet = true
+channel_log = true
 
 [channel."#encrypted"]
 topic ="Encrypted channel"

+ 2 - 0
contrib/localnet/ircd-five-peers/ircd_d.toml

@@ -8,6 +8,8 @@ inbound = ["tls://127.0.0.1:25563"]
 external_addr = ["tls://127.0.0.1:25563"]
 seeds = []
 peers = ["tls://127.0.0.1:25560"]
+localnet = true
+channel_log = true
 
 [channel."#encrypted"]
 topic ="Encrypted channel"

+ 2 - 0
contrib/localnet/ircd-five-peers/ircd_e.toml

@@ -8,6 +8,8 @@ inbound = ["tls://127.0.0.1:25564"]
 external_addr = ["tls://127.0.0.1:25564"]
 seeds = []
 peers = ["tls://127.0.0.1:25561"]
+localnet = true
+channel_log = true
 
 [channel."#encrypted"]
 topic ="Encrypted channel"

+ 1 - 1
script/research/fud/fud/Cargo.toml

@@ -15,7 +15,7 @@ async-std = "1.12.0"
 async-trait = "0.1.57"
 blake3 = "1.3.1"
 ctrlc = { version = "3.2.3", features = ["termination"] }
-darkfi = {path = "../../../../", features = ["dht"]}
+darkfi = {path = "../../../../", features = ["dht", "rpc"]}
 easy-parallel = "3.2.0"
 futures-lite = "1.12.0"
 log = "0.4.17"

+ 3 - 0
script/research/fud/fud/fud_config.toml

@@ -32,3 +32,6 @@ seeds = ["tls://lilith0.dark.fi:13337", "tls://lilith1.dark.fi:13337"]
 
 # Enable localnet hosts
 #localnet = true
+
+# Enable channel log
+#channel_log = true

+ 8 - 4
script/research/fud/fud/src/main.rs

@@ -21,11 +21,10 @@ use darkfi::{
         },
         server::{listen_and_serve, RequestHandler},
     },
+    serial::serialize,
     util::{
         cli::{get_log_config, get_log_level, spawn_config},
-        expand_path,
-        path::get_config_path,
-        serial::serialize,
+        path::{expand_path, get_config_path},
     },
     Result,
 };
@@ -74,11 +73,15 @@ struct Args {
     #[structopt(long)]
     /// Prefered transports for outbound connections (repeatable flag)
     transports: Vec<String>,
-    
+
     #[structopt(long)]
     /// Enable localnet hosts
     localnet: bool,
 
+    #[structopt(long)]
+    /// Enable channel log
+    channel_log: bool,
+
     #[structopt(short, parse(from_occurrences))]
     /// Increase verbosity (-vvv supported)
     verbose: u8,
@@ -388,6 +391,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
         seeds: args.seeds.clone(),
         outbound_transports: net::settings::get_outbound_transports(args.transports),
         localnet: args.localnet,
+        channel_log: args.channel_log,
         ..Default::default()
     };
 

+ 3 - 0
script/research/fud/localnet/fud_config0.toml

@@ -32,3 +32,6 @@ seeds = ["tcp://127.0.0.1:13337"]
 
 # Enable localnet hosts
 localnet = true
+
+# Enable channel log
+channel_log = true

+ 3 - 0
script/research/fud/localnet/fud_config1.toml

@@ -32,3 +32,6 @@ seeds = ["tcp://127.0.0.1:13337"]
 
 # Enable localnet hosts
 localnet = true
+
+# Enable channel log
+channel_log = true

+ 5 - 0
script/research/fud/localnet/lilith_config.toml

@@ -21,27 +21,32 @@ hosts_file="lilith_hosts.tsv"
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true
 
 #[network."darkfid_consensus"]
 #port = 33033
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true
 
 #[network."ircd"]
 #port = 25551
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true
 
 #[network."taud"]
 #port = 23331
 #seeds = []
 #peers = []
 #localnet = true
+#channel_log = true
 
 [network."fud"]
 port = 13337
 #seeds = []
 #peers = []
 localnet = true
+channel_log = true

+ 30 - 11
src/net/channel.rs

@@ -31,30 +31,43 @@ struct ChannelInfo {
     last_msg: String,
     last_status: String,
     // Message log which is cleared on querying get_info
-    log: Mutex<Vec<(NanoTimestamp, String, String)>>,
+    log: Option<Mutex<Vec<(NanoTimestamp, String, String)>>>,
 }
 
 impl ChannelInfo {
-    fn new() -> Self {
+    fn new(channel_log: bool) -> Self {
+        let log = match channel_log {
+            true => Some(Mutex::new(Vec::new())),
+            false => None,
+        };
+
         Self {
             random_id: rand::thread_rng().gen(),
             remote_node_id: String::new(),
             last_msg: String::new(),
             last_status: String::new(),
-            log: Mutex::new(Vec::new()),
+            log,
         }
     }
 
     async fn get_info(&self) -> serde_json::Value {
-        let result = json!({
+        let log = match &self.log {
+            Some(l) => {
+                let mut lock = l.lock().await;
+                let ret = lock.clone();
+                *lock = Vec::new();
+                ret
+            }
+            None => vec![],
+        };
+
+        json!({
             "random_id": self.random_id,
             "remote_node_id": self.remote_node_id,
             "last_msg": self.last_msg,
             "last_status": self.last_status,
-            "log": self.log.lock().await.clone(),
-        });
-        *self.log.lock().await = Vec::new();
-        result
+            "log": log,
+        })
     }
 }
 
@@ -87,6 +100,8 @@ impl Channel {
         let message_subsystem = MessageSubsystem::new();
         Self::setup_dispatchers(&message_subsystem).await;
 
+        let channel_log = session.upgrade().unwrap().p2p().settings().channel_log;
+
         Arc::new(Self {
             reader,
             writer,
@@ -95,7 +110,7 @@ impl Channel {
             stop_subscriber: Subscriber::new(),
             receive_task: StoppableTask::new(),
             stopped: Mutex::new(false),
-            info: Mutex::new(ChannelInfo::new()),
+            info: Mutex::new(ChannelInfo::new(channel_log)),
             session,
         })
     }
@@ -211,7 +226,9 @@ impl Channel {
 
         {
             let info = &mut *self.info.lock().await;
-            info.log.lock().await.push((time, "send".to_string(), packet.command.clone()));
+            if let Some(l) = &info.log {
+                l.lock().await.push((time, "send".to_string(), packet.command.clone()));
+            };
         }
 
         let stream = &mut *self.writer.lock().await;
@@ -302,7 +319,9 @@ impl Channel {
                 info.last_status = "recv".to_string();
                 let time = NanoTimestamp::current_time();
                 //let time = time::unix_timestamp()?;
-                info.log.lock().await.push((time, "recv".to_string(), packet.command.clone()));
+                if let Some(l) = &info.log {
+                    l.lock().await.push((time, "recv".to_string(), packet.command.clone()));
+                };
             }
 
             // Send result to our subscribers

+ 8 - 0
src/net/settings.rs

@@ -29,6 +29,7 @@ pub struct Settings {
     pub outbound_transports: Vec<TransportName>,
     pub localnet: bool,
     pub peer_discovery: bool,
+    pub channel_log: bool,
 }
 
 impl Default for Settings {
@@ -50,6 +51,7 @@ impl Default for Settings {
             outbound_transports: get_outbound_transports(vec![]),
             localnet: false,
             peer_discovery: true,
+            channel_log: false,
         }
     }
 }
@@ -117,6 +119,11 @@ pub struct SettingsOpt {
     #[serde(default = "default_as_true")]
     #[structopt(long)]
     pub peer_discovery: bool,
+
+    /// Enable channel log
+    #[serde(default)]
+    #[structopt(long)]
+    pub channel_log: bool,
 }
 
 impl From<SettingsOpt> for Settings {
@@ -138,6 +145,7 @@ impl From<SettingsOpt> for Settings {
             outbound_transports: get_outbound_transports(settings_opt.outbound_transports),
             localnet: settings_opt.localnet,
             peer_discovery: settings_opt.peer_discovery,
+            channel_log: settings_opt.channel_log,
         }
     }
 }