Browse Source

bin/ircd: remove AtomicBool from channel info

ghassmo 4 years ago
parent
commit
da5a5c1d2d
3 changed files with 8 additions and 13 deletions
  1. 2 2
      bin/ircd/src/main.rs
  2. 3 5
      bin/ircd/src/server.rs
  3. 3 6
      bin/ircd/src/settings.rs

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

@@ -9,7 +9,7 @@ use async_executor::Executor;
 
 
 use futures::{io::BufReader, AsyncBufReadExt, AsyncReadExt, FutureExt};
 use futures::{io::BufReader, AsyncBufReadExt, AsyncReadExt, FutureExt};
 use fxhash::FxHashMap;
 use fxhash::FxHashMap;
-use log::{debug, error, info, warn};
+use log::{error, info, warn};
 use rand::rngs::OsRng;
 use rand::rngs::OsRng;
 use smol::future;
 use smol::future;
 use structopt_toml::StructOptToml;
 use structopt_toml::StructOptToml;
@@ -116,7 +116,7 @@ impl Ircd {
                         // Try to potentially decrypt the incoming message.
                         // Try to potentially decrypt the incoming message.
                         if conn.configured_chans.contains_key(&msg.channel) {
                         if conn.configured_chans.contains_key(&msg.channel) {
                             let chan_info = conn.configured_chans.get(&msg.channel).unwrap();
                             let chan_info = conn.configured_chans.get(&msg.channel).unwrap();
-                            if !chan_info.joined.load(Ordering::Relaxed) {
+                            if !chan_info.joined {
                                 continue
                                 continue
                             }
                             }
                             if let Some(salt_box) = &chan_info.salt_box {
                             if let Some(salt_box) = &chan_info.salt_box {

+ 3 - 5
bin/ircd/src/server.rs

@@ -1,5 +1,3 @@
-use std::sync::atomic::Ordering;
-
 use async_std::net::TcpStream;
 use async_std::net::TcpStream;
 use futures::{io::WriteHalf, AsyncWriteExt};
 use futures::{io::WriteHalf, AsyncWriteExt};
 use fxhash::FxHashMap;
 use fxhash::FxHashMap;
@@ -93,7 +91,7 @@ impl IrcServerConnection {
                         self.configured_chans.insert(chan.to_string(), ChannelInfo::new()?);
                         self.configured_chans.insert(chan.to_string(), ChannelInfo::new()?);
                     } else {
                     } else {
                         let chan_info = self.configured_chans.get_mut(chan).unwrap();
                         let chan_info = self.configured_chans.get_mut(chan).unwrap();
-                        chan_info.joined.store(true, Ordering::Relaxed);
+                        chan_info.joined = true;
                     }
                     }
                 }
                 }
             }
             }
@@ -104,7 +102,7 @@ impl IrcServerConnection {
                     self.reply(&part_reply).await?;
                     self.reply(&part_reply).await?;
                     if self.configured_chans.contains_key(chan) {
                     if self.configured_chans.contains_key(chan) {
                         let chan_info = self.configured_chans.get_mut(chan).unwrap();
                         let chan_info = self.configured_chans.get_mut(chan).unwrap();
-                        chan_info.joined.store(false, Ordering::Relaxed);
+                        chan_info.joined = false;
                     }
                     }
                 }
                 }
             }
             }
@@ -156,7 +154,7 @@ impl IrcServerConnection {
 
 
                 if self.configured_chans.contains_key(channel) {
                 if self.configured_chans.contains_key(channel) {
                     let channel_info = self.configured_chans.get(channel).unwrap();
                     let channel_info = self.configured_chans.get(channel).unwrap();
-                    if channel_info.joined.load(Ordering::Relaxed) {
+                    if channel_info.joined {
                         let message = if let Some(salt_box) = &channel_info.salt_box {
                         let message = if let Some(salt_box) = &channel_info.salt_box {
                             let encrypted = encrypt_message(salt_box, message);
                             let encrypted = encrypt_message(salt_box, message);
                             info!("(Encrypted) PRIVMSG {} :{}", channel, encrypted);
                             info!("(Encrypted) PRIVMSG {} :{}", channel, encrypted);

+ 3 - 6
bin/ircd/src/settings.rs

@@ -1,7 +1,4 @@
-use std::{
-    path::PathBuf,
-    sync::{atomic::AtomicBool, Arc},
-};
+use std::path::PathBuf;
 
 
 use fxhash::FxHashMap;
 use fxhash::FxHashMap;
 use log::info;
 use log::info;
@@ -69,12 +66,12 @@ pub struct ChannelInfo {
     /// Optional NaCl box for the channel, used for {en,de}cryption.
     /// Optional NaCl box for the channel, used for {en,de}cryption.
     pub salt_box: Option<crypto_box::Box>,
     pub salt_box: Option<crypto_box::Box>,
     /// Flag indicates whether the user has joined the channel or not
     /// Flag indicates whether the user has joined the channel or not
-    pub joined: Arc<AtomicBool>,
+    pub joined: bool,
 }
 }
 
 
 impl ChannelInfo {
 impl ChannelInfo {
     pub fn new() -> Result<Self> {
     pub fn new() -> Result<Self> {
-        Ok(Self { topic: None, salt_box: None, joined: Arc::new(AtomicBool::new(true)) })
+        Ok(Self { topic: None, salt_box: None, joined: true })
     }
     }
 }
 }