Chore: Bump rand->0.9, tokio-tungstenite->0.26

This commit is contained in:
Kyle Simpson
2025-02-21 13:08:25 +00:00
parent b46a568fb5
commit b39ab98223
8 changed files with 34 additions and 27 deletions

View File

@@ -35,7 +35,7 @@ futures = "0.3"
nohash-hasher = { optional = true, version = "0.2.0" } nohash-hasher = { optional = true, version = "0.2.0" }
parking_lot = { optional = true, version = "0.12" } parking_lot = { optional = true, version = "0.12" }
pin-project = "1" pin-project = "1"
rand = { optional = true, version = "0.8" } rand = { optional = true, version = "0.9" }
reqwest = { default-features = false, features = [ reqwest = { default-features = false, features = [
"stream", "stream",
], optional = true, version = "0.12.2" } ], optional = true, version = "0.12.2" }
@@ -56,7 +56,7 @@ stream_lib = { default-features = false, optional = true, version = "0.5.2" }
symphonia = { default-features = false, optional = true, version = "0.5.2" } symphonia = { default-features = false, optional = true, version = "0.5.2" }
symphonia-core = { optional = true, version = "0.5.2" } symphonia-core = { optional = true, version = "0.5.2" }
tokio = { default-features = false, optional = true, version = "1.0" } tokio = { default-features = false, optional = true, version = "1.0" }
tokio-tungstenite = { optional = true, version = "0.24", features = ["url"] } tokio-tungstenite = { optional = true, version = "0.26", features = ["url"] }
tokio-websockets = { optional = true, version = "0.11", features = [ tokio-websockets = { optional = true, version = "0.11", features = [
"client", "client",
"fastrand", "fastrand",

View File

@@ -19,12 +19,12 @@ command = "cargo"
dependencies = ["format"] dependencies = ["format"]
[tasks.build-driver] [tasks.build-driver]
args = ["build", "--no-default-features", "--features", "driver,rustls"] args = ["build", "--no-default-features", "--features", "driver,rustls,tungstenite"]
command = "cargo" command = "cargo"
dependencies = ["format"] dependencies = ["format"]
[tasks.build-variants] [tasks.build-variants]
dependencies = ["build", "build-gateway", "build-driver", "build-simd"] dependencies = ["build", "build-gateway", "build-driver"]
[tasks.check] [tasks.check]
args = ["check", "--features", "full-doc"] args = ["check", "--features", "full-doc"]

View File

@@ -9,4 +9,16 @@ compile_error!(
If you are unsure, go with `rustls`." If you are unsure, go with `rustls`."
); );
#[cfg(any(
all(feature = "driver", feature = "tws", feature = "tungstenite"),
all(feature = "driver", not(feature = "tws"), not(feature = "tungstenite"))
))]
compile_error!(
"You have the `driver` feature enabled: \
this requires you specify either: \n\
- `tungstenite` (recommended with serenity)\n\
- or `tws` (recommended with twilight).\n\
You have either specified none, or both - choose exactly one."
);
fn main() {} fn main() {}

View File

@@ -7,7 +7,9 @@ edition = "2021"
[dependencies] [dependencies]
futures = "0.3" futures = "0.3"
reqwest = { workspace = true } reqwest = { workspace = true }
songbird = { workspace = true, features = ["driver", "gateway", "twilight", "rustls", "tws"] } # In an actual twilight project, use the "tws" feature as below.
# songbird = { workspace = true, features = ["driver", "gateway", "twilight", "rustls", "tws"] }
songbird = { workspace = true, features = ["driver", "gateway", "twilight", "rustls"] }
symphonia = { workspace = true } symphonia = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
tracing-subscriber = { workspace = true, default-features = true } tracing-subscriber = { workspace = true, default-features = true }

View File

@@ -423,7 +423,7 @@ impl CryptoState {
match self { match self {
Self::Suffix => { Self::Suffix => {
rand::thread_rng().fill(&mut packet.payload_mut()[startpoint..endpoint]); rand::rng().fill(&mut packet.payload_mut()[startpoint..endpoint]);
}, },
Self::Lite(ref mut i) Self::Lite(ref mut i)
| Self::Aes256Gcm(ref mut i) | Self::Aes256Gcm(ref mut i)

View File

@@ -12,7 +12,7 @@ use crate::{
ConnectionInfo, ConnectionInfo,
}; };
use flume::Receiver; use flume::Receiver;
use rand::{distributions::Uniform, Rng}; use rand::{distr::Uniform, Rng};
#[cfg(feature = "receive")] #[cfg(feature = "receive")]
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
@@ -181,8 +181,9 @@ impl AuxNetwork {
// Discord have suddenly, mysteriously, started rejecting // Discord have suddenly, mysteriously, started rejecting
// ints-as-strings. Keep JS happy here, I suppose... // ints-as-strings. Keep JS happy here, I suppose...
const JS_MAX_INT: u64 = (1u64 << 53) - 1; const JS_MAX_INT: u64 = (1u64 << 53) - 1;
let nonce_range = Uniform::from(0..JS_MAX_INT); let nonce_range =
let nonce = rand::thread_rng().sample(nonce_range); Uniform::new(0, JS_MAX_INT).expect("uniform range is finite and nonempty");
let nonce = rand::rng().sample(nonce_range);
self.last_heartbeat_nonce = Some(nonce); self.last_heartbeat_nonce = Some(nonce);
trace!("Sent heartbeat {:?}", self.speaking); trace!("Sent heartbeat {:?}", self.speaking);

View File

@@ -140,7 +140,7 @@ impl<'a> YoutubeDl<'a> {
"--no-playlist", "--no-playlist",
]; ];
let mut output = Command::new(self.program) let output = Command::new(self.program)
.args(self.user_args.clone()) .args(self.user_args.clone())
.args(ytdl_args) .args(ytdl_args)
.output() .output()

View File

@@ -1,5 +1,6 @@
use crate::{error::JsonError, model::Event}; use crate::{error::JsonError, model::Event};
use bytes::Bytes;
use futures::{SinkExt, StreamExt, TryStreamExt}; use futures::{SinkExt, StreamExt, TryStreamExt};
use tokio::{ use tokio::{
net::TcpStream, net::TcpStream,
@@ -27,12 +28,6 @@ use tokio_websockets::{
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use url::Url; use url::Url;
#[cfg(any(
all(feature = "tws", feature = "tungstenite"),
all(not(feature = "tws"), not(feature = "tungstenite"))
))]
compile_error!("specify one of `features = [\"tungstenite\"]` (recommended w/ serenity) or `features = [\"tws\"]` (recommended w/ twilight)");
pub struct WsStream(WebSocketStream<MaybeTlsStream<TcpStream>>); pub struct WsStream(WebSocketStream<MaybeTlsStream<TcpStream>>);
impl WsStream { impl WsStream {
@@ -41,11 +36,11 @@ impl WsStream {
#[cfg(feature = "tungstenite")] #[cfg(feature = "tungstenite")]
let (stream, _) = tokio_tungstenite::connect_async_with_config::<Url>( let (stream, _) = tokio_tungstenite::connect_async_with_config::<Url>(
url, url,
Some(Config { Some(
max_message_size: None, Config::default()
max_frame_size: None, .max_message_size(None)
..Default::default() .max_frame_size(None),
}), ),
true, true,
) )
.await?; .await?;
@@ -78,9 +73,6 @@ impl WsStream {
pub(crate) async fn send_json(&mut self, value: &Event) -> Result<()> { pub(crate) async fn send_json(&mut self, value: &Event) -> Result<()> {
let res = crate::json::to_string(value); let res = crate::json::to_string(value);
#[cfg(feature = "tungstenite")]
let res = res.map(Message::Text);
#[cfg(feature = "tws")]
let res = res.map(Message::text); let res = res.map(Message::text);
Ok(res.map_err(Error::from).map(|m| self.0.send(m))?.await?) Ok(res.map_err(Error::from).map(|m| self.0.send(m))?.await?)
} }
@@ -94,7 +86,7 @@ pub enum Error {
/// The discord voice gateway does not support or offer zlib compression. /// The discord voice gateway does not support or offer zlib compression.
/// As a result, only text messages are expected. /// As a result, only text messages are expected.
UnexpectedBinaryMessage(Vec<u8>), UnexpectedBinaryMessage(Bytes),
#[cfg(feature = "tungstenite")] #[cfg(feature = "tungstenite")]
Ws(TungsteniteError), Ws(TungsteniteError),
@@ -102,7 +94,7 @@ pub enum Error {
Ws(TwsError), Ws(TwsError),
#[cfg(feature = "tungstenite")] #[cfg(feature = "tungstenite")]
WsClosed(Option<CloseFrame<'static>>), WsClosed(Option<CloseFrame>),
#[cfg(feature = "tws")] #[cfg(feature = "tws")]
WsClosed(Option<CloseCode>), WsClosed(Option<CloseCode>),
} }
@@ -151,7 +143,7 @@ pub(crate) fn convert_ws_message(message: Option<Message>) -> Result<Option<Even
}, },
Some(message) if message.is_binary() => { Some(message) if message.is_binary() => {
return Err(Error::UnexpectedBinaryMessage( return Err(Error::UnexpectedBinaryMessage(
message.into_payload().to_vec(), message.into_payload().into(),
)); ));
}, },
Some(message) if message.is_close() => { Some(message) if message.is_close() => {