diff --git a/Cargo.toml b/Cargo.toml index 36a16b4..a91b7a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,10 @@ version = "0.2" optional = true version = "1" +[dependencies.dashmap] +optional = true +version = "4" + [dependencies.discortp] features = ["discord-full"] optional = true @@ -117,6 +121,7 @@ default = [ "gateway", ] gateway = [ + "dashmap", "flume", "parking_lot", "tokio/sync", diff --git a/src/driver/crypto.rs b/src/driver/crypto.rs index 1ef763b..143f62a 100644 --- a/src/driver/crypto.rs +++ b/src/driver/crypto.rs @@ -131,9 +131,9 @@ impl CryptoMode { let (tag_bytes, data_bytes) = body_remaining.split_at_mut(body_start); let tag = Tag::from_slice(tag_bytes); - Ok(cipher + cipher .decrypt_in_place_detached(nonce_slice, b"", data_bytes, tag) - .map(|_| (body_start, body_tail))?) + .map(|_| (body_start, body_tail)) } /// Encrypts a Discord RT(C)P packet using the given key. diff --git a/src/manager.rs b/src/manager.rs index b6fb296..2df38c8 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -9,6 +9,7 @@ use crate::{ }; #[cfg(feature = "serenity")] use async_trait::async_trait; +use dashmap::DashMap; #[cfg(feature = "serenity")] use futures::channel::mpsc::UnboundedSender as Sender; use parking_lot::RwLock as PRwLock; @@ -21,7 +22,7 @@ use serenity::{ voice::VoiceState, }, }; -use std::{collections::HashMap, sync::Arc}; +use std::sync::Arc; use tokio::sync::Mutex; #[cfg(feature = "twilight")] use twilight_gateway::Cluster; @@ -44,7 +45,7 @@ struct ClientData { #[derive(Debug)] pub struct Songbird { client_data: PRwLock, - calls: PRwLock>>>, + calls: DashMap>>, sharder: Sharder, #[cfg(feature = "driver")] @@ -117,8 +118,9 @@ impl Songbird { /// /// [`Call`]: Call pub fn get>(&self, guild_id: G) -> Option>> { - let map_read = self.calls.read(); - map_read.get(&guild_id.into()).cloned() + self.calls + .get(&guild_id.into()) + .map(|mapref| Arc::clone(&mapref)) } /// Retrieves a [`Call`] for the given guild, creating a new one if @@ -129,9 +131,7 @@ impl Songbird { /// [`Call`]: Call pub fn get_or_insert(&self, guild_id: GuildId) -> Arc> { self.get(guild_id).unwrap_or_else(|| { - let mut map_read = self.calls.write(); - - map_read + self.calls .entry(guild_id) .or_insert_with(|| { let info = self.manager_info(); @@ -301,8 +301,7 @@ impl Songbird { async fn _remove(&self, guild_id: GuildId) -> JoinResult<()> { self.leave(guild_id).await?; - let mut calls = self.calls.write(); - calls.remove(&guild_id); + self.calls.remove(&guild_id); Ok(()) } }