bin/ircd: remove AtomicBool from channel info

This commit is contained in:
ghassmo
2022-06-18 08:29:17 +03:00
parent ec23379a0f
commit da5a5c1d2d
3 changed files with 8 additions and 13 deletions

View File

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

View File

@@ -1,5 +1,3 @@
use std::sync::atomic::Ordering;
use async_std::net::TcpStream;
use futures::{io::WriteHalf, AsyncWriteExt};
use fxhash::FxHashMap;
@@ -93,7 +91,7 @@ impl IrcServerConnection {
self.configured_chans.insert(chan.to_string(), ChannelInfo::new()?);
} else {
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?;
if self.configured_chans.contains_key(chan) {
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) {
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 encrypted = encrypt_message(salt_box, message);
info!("(Encrypted) PRIVMSG {} :{}", channel, encrypted);

View File

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