2.2.4-dev.1
- Updated librespot to latest commits + login5 PR merged - Fix non premium account shutting down bot - Add additional timeouts to credential retrieval - Add message for if AP connection dropsmain
parent
c05624fc76
commit
41d75a956c
|
@ -1,5 +1,12 @@
|
|||
# Changelog
|
||||
|
||||
## 2.2.4 | TBD
|
||||
|
||||
- Added a message for if the Spotify AP connection drops
|
||||
- Added additional timeouts to credential retrieval
|
||||
- Removed multiple points of failure in `librespot` that could shut down the bot
|
||||
- Fixed an issue where non-premium users could crash the bot for everyone (See point 3)
|
||||
|
||||
## 2.2.3 | September 20th 2024
|
||||
|
||||
- Made backend changes to librespot to prevent deadlocking by not waiting for thread shutdowns
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
rust-version = "1.80.0"
|
||||
|
||||
|
@ -39,6 +39,7 @@ poise = "0.6.1"
|
|||
serenity = "0.12.2"
|
||||
songbird = { version = "0.4.3", features = ["simd-json"] }
|
||||
tokio = { version = "1.39.3", features = ["full"] }
|
||||
rustls = { version = "0.23.13", features = ["aws-lc-rs"] }
|
||||
|
||||
[profile.release]
|
||||
opt-level = 3
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord_audio"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord_config"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord_database"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord_player"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord_session"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -106,7 +106,7 @@ impl Session {
|
|||
Err(why) => {
|
||||
error!("Failed to retrieve credentials: {why}");
|
||||
|
||||
return Err(why.into());
|
||||
return Err(why);
|
||||
}
|
||||
};
|
||||
let device_name = match session_manager.database().get_user(owner.to_string()).await {
|
||||
|
@ -616,7 +616,7 @@ async fn retrieve_credentials(database: &Database, owner: impl AsRef<str>) -> Re
|
|||
None => {
|
||||
let access_token = database.get_access_token(&account.user_id).await?;
|
||||
let credentials = spotify::request_session_token(Credentials {
|
||||
username: account.username.clone(),
|
||||
username: Some(account.username.to_string()),
|
||||
auth_type: AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN,
|
||||
auth_data: access_token.into_bytes(),
|
||||
})
|
||||
|
@ -632,7 +632,7 @@ async fn retrieve_credentials(database: &Database, owner: impl AsRef<str>) -> Re
|
|||
};
|
||||
|
||||
Ok(Credentials {
|
||||
username: account.username,
|
||||
username: Some(account.username),
|
||||
auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS,
|
||||
auth_data: BASE64.decode(token)?,
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord_stats"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "spoticord_utils"
|
||||
version = "2.2.3"
|
||||
version = "2.2.4"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use anyhow::Result;
|
||||
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
|
||||
use librespot::{
|
||||
core::{connection::AuthenticationError, Session, SessionConfig},
|
||||
core::{Session, SessionConfig},
|
||||
discovery::Credentials,
|
||||
protocol::{authentication::AuthenticationType, keyexchange::ErrorCode},
|
||||
protocol::authentication::AuthenticationType,
|
||||
};
|
||||
use log::debug;
|
||||
use std::time::Duration;
|
||||
|
@ -15,17 +15,17 @@ pub async fn validate_token(
|
|||
let auth_data = BASE64.decode(token.into())?;
|
||||
|
||||
let credentials = Credentials {
|
||||
username: username.into(),
|
||||
username: Some(username.into()),
|
||||
auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS,
|
||||
auth_data,
|
||||
};
|
||||
|
||||
debug!("Validating session token for {}", credentials.username);
|
||||
debug!("Validating session token for {:?}", credentials.username);
|
||||
|
||||
let new_credentials = request_session_token(credentials.clone()).await?;
|
||||
|
||||
if credentials.auth_data != new_credentials.auth_data {
|
||||
debug!("New session token retrieved for {}", credentials.username);
|
||||
debug!("New session token retrieved for {:?}", credentials.username);
|
||||
|
||||
return Ok(Some(BASE64.encode(new_credentials.auth_data)));
|
||||
}
|
||||
|
@ -34,54 +34,45 @@ pub async fn validate_token(
|
|||
}
|
||||
|
||||
pub async fn request_session_token(credentials: Credentials) -> Result<Credentials> {
|
||||
debug!("Requesting session token for {}", credentials.username);
|
||||
debug!("Requesting session token for {:?}", credentials.username);
|
||||
|
||||
let session = Session::new(SessionConfig::default(), None);
|
||||
let mut tries = 0;
|
||||
|
||||
Ok(loop {
|
||||
let (host, port) = session.apresolver().resolve("accesspoint").await?;
|
||||
|
||||
let mut transport = match librespot::core::connection::connect(&host, port, None).await {
|
||||
Ok(transport) => transport,
|
||||
Err(why) => {
|
||||
// Retry
|
||||
|
||||
match connect(&session, credentials.clone()).await {
|
||||
Ok(creds) => break creds,
|
||||
Err(e) => {
|
||||
tries += 1;
|
||||
if tries > 3 {
|
||||
return Err(why.into());
|
||||
return Err(e);
|
||||
}
|
||||
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
|
||||
continue;
|
||||
}
|
||||
};
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
match librespot::core::connection::authenticate(
|
||||
/// Wrapper around session connecting that times out if an operation is still busy after 3 seconds
|
||||
async fn connect(session: &Session, credentials: Credentials) -> Result<Credentials> {
|
||||
const TIMEOUT: Duration = Duration::from_secs(3);
|
||||
|
||||
let (host, port) =
|
||||
tokio::time::timeout(TIMEOUT, session.apresolver().resolve("accesspoint")).await??;
|
||||
|
||||
// `connect` already has a 3 second timeout internally
|
||||
let mut transport = librespot::core::connection::connect(&host, port, None).await?;
|
||||
|
||||
let creds = tokio::time::timeout(
|
||||
TIMEOUT,
|
||||
librespot::core::connection::authenticate(
|
||||
&mut transport,
|
||||
credentials.clone(),
|
||||
&session.config().device_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(creds) => break creds,
|
||||
Err(e) => {
|
||||
if let Some(AuthenticationError::LoginFailed(ErrorCode::TryAnotherAP)) =
|
||||
e.error.downcast_ref::<AuthenticationError>()
|
||||
{
|
||||
tries += 1;
|
||||
if tries > 3 {
|
||||
return Err(e.into());
|
||||
}
|
||||
),
|
||||
)
|
||||
.await??;
|
||||
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
|
||||
continue;
|
||||
} else {
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
Ok(creds)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
mod bot;
|
||||
mod commands;
|
||||
// mod session;
|
||||
// mod utils;
|
||||
|
||||
use log::{error, info};
|
||||
use poise::Framework;
|
||||
|
@ -11,6 +9,11 @@ use spoticord_database::Database;
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
// Force aws-lc-rs as default crypto provider
|
||||
// Since multiple dependencies either enable aws_lc_rs or ring, they cause a clash, so we have to
|
||||
// explicitly tell rustls to use the aws-lc-rs provider
|
||||
_ = rustls::crypto::aws_lc_rs::default_provider().install_default();
|
||||
|
||||
// Setup logging
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
#[cfg(debug_assertions)]
|
||||
|
|
Loading…
Reference in New Issue