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" }
parking_lot = { optional = true, version = "0.12" }
pin-project = "1"
rand = { optional = true, version = "0.8" }
rand = { optional = true, version = "0.9" }
reqwest = { default-features = false, features = [
"stream",
], 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-core = { optional = true, version = "0.5.2" }
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 = [
"client",
"fastrand",

View File

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

View File

@@ -9,4 +9,16 @@ compile_error!(
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() {}

View File

@@ -7,7 +7,9 @@ edition = "2021"
[dependencies]
futures = "0.3"
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 }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, default-features = true }

View File

@@ -423,7 +423,7 @@ impl CryptoState {
match self {
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::Aes256Gcm(ref mut i)

View File

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

View File

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

View File

@@ -1,5 +1,6 @@
use crate::{error::JsonError, model::Event};
use bytes::Bytes;
use futures::{SinkExt, StreamExt, TryStreamExt};
use tokio::{
net::TcpStream,
@@ -27,12 +28,6 @@ use tokio_websockets::{
use tracing::{debug, instrument};
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>>);
impl WsStream {
@@ -41,11 +36,11 @@ impl WsStream {
#[cfg(feature = "tungstenite")]
let (stream, _) = tokio_tungstenite::connect_async_with_config::<Url>(
url,
Some(Config {
max_message_size: None,
max_frame_size: None,
..Default::default()
}),
Some(
Config::default()
.max_message_size(None)
.max_frame_size(None),
),
true,
)
.await?;
@@ -78,9 +73,6 @@ impl WsStream {
pub(crate) async fn send_json(&mut self, value: &Event) -> Result<()> {
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);
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.
/// As a result, only text messages are expected.
UnexpectedBinaryMessage(Vec<u8>),
UnexpectedBinaryMessage(Bytes),
#[cfg(feature = "tungstenite")]
Ws(TungsteniteError),
@@ -102,7 +94,7 @@ pub enum Error {
Ws(TwsError),
#[cfg(feature = "tungstenite")]
WsClosed(Option<CloseFrame<'static>>),
WsClosed(Option<CloseFrame>),
#[cfg(feature = "tws")]
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() => {
return Err(Error::UnexpectedBinaryMessage(
message.into_payload().to_vec(),
message.into_payload().into(),
));
},
Some(message) if message.is_close() => {