Преглед изворни кода

replace last couple of ircd words

dasman пре 2 година
родитељ
комит
823db436e4
2 измењених фајлова са 125 додато и 124 уклоњено
  1. 2 2
      doc/src/dev/dev.md
  2. 123 122
      example/p2pdebug/src/proto/debugmsg.rs

+ 2 - 2
doc/src/dev/dev.md

@@ -68,9 +68,9 @@ This allows us to coordinate more effectively.
 | brb     | be right back      | If you are in a meeting and need to leave for a few mins. For example, maybe you need to grab a book. |
 | one sec | one second         | You need to search something on the web, or you are just doing the task (example: opening the file).  |
 
-\* once we have proper syncing implemented in ircd, these will become less relevant and not needed.
+\* once we have proper syncing implemented in darkirc, these will become less relevant and not needed.
 
-Another option is to run your ircd inside a persistent tmux session, and never miss messages.
+Another option is to run your darkirc inside a persistent tmux session, and never miss messages.
 
 ## Code coverage
 

+ 123 - 122
example/p2pdebug/src/proto/debugmsg.rs

@@ -16,125 +16,126 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-use std::sync::Arc;
-
-use async_channel::Sender;
-use async_executor::Executor;
-use async_std::sync::Mutex;
-use async_trait::async_trait;
-use fxhash::FxHashSet;
-use log::debug;
-
-use darkfi::{
-    net,
-    util::serial::{SerialDecodable, SerialEncodable},
-    Result,
-};
-
-pub type DebugmsgId = u32;
-
-#[derive(Debug, Clone, SerialEncodable, SerialDecodable)]
-pub struct Debugmsg {
-    pub id: DebugmsgId,
-    pub message: String,
-}
-
-impl net::Message for Debugmsg {
-    fn name() -> &'static str {
-        "debugmsg"
-    }
-}
-
-pub struct SeenDebugmsgIds {
-    ids: Mutex<FxHashSet<DebugmsgId>>,
-}
-
-pub type SeenDebugmsgIdsPtr = Arc<SeenDebugmsgIds>;
-
-impl SeenDebugmsgIds {
-    pub fn new() -> Arc<Self> {
-        Arc::new(Self { ids: Mutex::new(FxHashSet::default()) })
-    }
-
-    pub async fn add_seen(&self, id: u32) {
-        self.ids.lock().await.insert(id);
-    }
-
-    pub async fn is_seen(&self, id: u32) -> bool {
-        self.ids.lock().await.contains(&id)
-    }
-}
-
-pub struct ProtocolDebugmsg {
-    notify_queue_sender: Sender<Arc<Debugmsg>>,
-    debugmsg_sub: net::MessageSubscription<Debugmsg>,
-    jobsman: net::ProtocolJobsManagerPtr,
-    seen_ids: SeenDebugmsgIdsPtr,
-    p2p: net::P2pPtr,
-}
-
-#[async_trait]
-impl net::ProtocolBase for ProtocolDebugmsg {
-    /// Starts ping-pong keep-alive messages exchange. Runs ping-pong in the
-    /// protocol task manager, then queues the reply. Sends out a ping and
-    /// waits for pong reply. Waits for ping and replies with a pong.
-    async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
-        debug!(target: "ircd", "Protocoldebugmsg::start() [START]");
-        self.jobsman.clone().start(executor.clone());
-        self.jobsman.clone().spawn(self.clone().handle_receive_debugmsg(), executor.clone()).await;
-        debug!(target: "ircd", "ProtocolDebugmsg::start() [END]");
-        Ok(())
-    }
-
-    fn name(&self) -> &'static str {
-        "Protocoldebugmsg"
-    }
-}
-
-impl ProtocolDebugmsg {
-    pub async fn init(
-        channel: net::ChannelPtr,
-        notify_queue_sender: Sender<Arc<Debugmsg>>,
-        seen_ids: SeenDebugmsgIdsPtr,
-        p2p: net::P2pPtr,
-    ) -> net::ProtocolBasePtr {
-        let message_subsystem = channel.get_message_subsystem();
-        message_subsystem.add_dispatch::<Debugmsg>().await;
-
-        let sub = channel.subscribe_msg::<Debugmsg>().await.expect("Missing Debugmsg dispatcher!");
-
-        Arc::new(Self {
-            notify_queue_sender,
-            debugmsg_sub: sub,
-            jobsman: net::ProtocolJobsManager::new("DebugmsgProtocol", channel),
-            seen_ids,
-            p2p,
-        })
-    }
-
-    async fn handle_receive_debugmsg(self: Arc<Self>) -> Result<()> {
-        debug!(target: "ircd", "ProtocolDebugmsg::handle_receive_debugmsg() [START]");
-
-        loop {
-            let debugmsg = self.debugmsg_sub.receive().await?;
-
-            debug!(target: "ircd", "ProtocolDebugmsg::handle_receive_debugmsg() received {:?}", debugmsg);
-
-            // Do we already have this message?
-            if self.seen_ids.is_seen(debugmsg.id).await {
-                continue
-            }
-
-            self.seen_ids.add_seen(debugmsg.id).await;
-
-            // If not, then broadcast to network.
-            let debugmsg_copy = (*debugmsg).clone();
-            self.p2p.broadcast(debugmsg_copy).await?;
-
-            self.notify_queue_sender
-                .send(debugmsg)
-                .await
-                .expect("notify_queue_sender send failed!");
-        }
-    }
-}
+ use std::sync::Arc;
+
+ use async_channel::Sender;
+ use async_executor::Executor;
+ use async_std::sync::Mutex;
+ use async_trait::async_trait;
+ use fxhash::FxHashSet;
+ use log::debug;
+ 
+ use darkfi::{
+     net,
+     util::serial::{SerialDecodable, SerialEncodable},
+     Result,
+ };
+ 
+ pub type DebugmsgId = u32;
+ 
+ #[derive(Debug, Clone, SerialEncodable, SerialDecodable)]
+ pub struct Debugmsg {
+     pub id: DebugmsgId,
+     pub message: String,
+ }
+ 
+ impl net::Message for Debugmsg {
+     fn name() -> &'static str {
+         "debugmsg"
+     }
+ }
+ 
+ pub struct SeenDebugmsgIds {
+     ids: Mutex<FxHashSet<DebugmsgId>>,
+ }
+ 
+ pub type SeenDebugmsgIdsPtr = Arc<SeenDebugmsgIds>;
+ 
+ impl SeenDebugmsgIds {
+     pub fn new() -> Arc<Self> {
+         Arc::new(Self { ids: Mutex::new(FxHashSet::default()) })
+     }
+ 
+     pub async fn add_seen(&self, id: u32) {
+         self.ids.lock().await.insert(id);
+     }
+ 
+     pub async fn is_seen(&self, id: u32) -> bool {
+         self.ids.lock().await.contains(&id)
+     }
+ }
+ 
+ pub struct ProtocolDebugmsg {
+     notify_queue_sender: Sender<Arc<Debugmsg>>,
+     debugmsg_sub: net::MessageSubscription<Debugmsg>,
+     jobsman: net::ProtocolJobsManagerPtr,
+     seen_ids: SeenDebugmsgIdsPtr,
+     p2p: net::P2pPtr,
+ }
+ 
+ #[async_trait]
+ impl net::ProtocolBase for ProtocolDebugmsg {
+     /// Starts ping-pong keep-alive messages exchange. Runs ping-pong in the
+     /// protocol task manager, then queues the reply. Sends out a ping and
+     /// waits for pong reply. Waits for ping and replies with a pong.
+     async fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) -> Result<()> {
+         debug!(target: "dchat", "Protocoldebugmsg::start() [START]");
+         self.jobsman.clone().start(executor.clone());
+         self.jobsman.clone().spawn(self.clone().handle_receive_debugmsg(), executor.clone()).await;
+         debug!(target: "dchat", "ProtocolDebugmsg::start() [END]");
+         Ok(())
+     }
+ 
+     fn name(&self) -> &'static str {
+         "Protocoldebugmsg"
+     }
+ }
+ 
+ impl ProtocolDebugmsg {
+     pub async fn init(
+         channel: net::ChannelPtr,
+         notify_queue_sender: Sender<Arc<Debugmsg>>,
+         seen_ids: SeenDebugmsgIdsPtr,
+         p2p: net::P2pPtr,
+     ) -> net::ProtocolBasePtr {
+         let message_subsystem = channel.get_message_subsystem();
+         message_subsystem.add_dispatch::<Debugmsg>().await;
+ 
+         let sub = channel.subscribe_msg::<Debugmsg>().await.expect("Missing Debugmsg dispatcher!");
+ 
+         Arc::new(Self {
+             notify_queue_sender,
+             debugmsg_sub: sub,
+             jobsman: net::ProtocolJobsManager::new("DebugmsgProtocol", channel),
+             seen_ids,
+             p2p,
+         })
+     }
+ 
+     async fn handle_receive_debugmsg(self: Arc<Self>) -> Result<()> {
+         debug!(target: "dchat", "ProtocolDebugmsg::handle_receive_debugmsg() [START]");
+ 
+         loop {
+             let debugmsg = self.debugmsg_sub.receive().await?;
+ 
+             debug!(target: "dchat", "ProtocolDebugmsg::handle_receive_debugmsg() received {:?}", debugmsg);
+ 
+             // Do we already have this message?
+             if self.seen_ids.is_seen(debugmsg.id).await {
+                 continue
+             }
+ 
+             self.seen_ids.add_seen(debugmsg.id).await;
+ 
+             // If not, then broadcast to network.
+             let debugmsg_copy = (*debugmsg).clone();
+             self.p2p.broadcast(debugmsg_copy).await?;
+ 
+             self.notify_queue_sender
+                 .send(debugmsg)
+                 .await
+                 .expect("notify_queue_sender send failed!");
+         }
+     }
+ }
+