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
|
# 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
|
## 2.2.3 | September 20th 2024
|
||||||
|
|
||||||
- Made backend changes to librespot to prevent deadlocking by not waiting for thread shutdowns
|
- 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]
|
[package]
|
||||||
name = "spoticord"
|
name = "spoticord"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.80.0"
|
rust-version = "1.80.0"
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ poise = "0.6.1"
|
||||||
serenity = "0.12.2"
|
serenity = "0.12.2"
|
||||||
songbird = { version = "0.4.3", features = ["simd-json"] }
|
songbird = { version = "0.4.3", features = ["simd-json"] }
|
||||||
tokio = { version = "1.39.3", features = ["full"] }
|
tokio = { version = "1.39.3", features = ["full"] }
|
||||||
|
rustls = { version = "0.23.13", features = ["aws-lc-rs"] }
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord_audio"
|
name = "spoticord_audio"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord_config"
|
name = "spoticord_config"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord_database"
|
name = "spoticord_database"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord_player"
|
name = "spoticord_player"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord_session"
|
name = "spoticord_session"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -106,7 +106,7 @@ impl Session {
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
error!("Failed to retrieve credentials: {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 {
|
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 => {
|
None => {
|
||||||
let access_token = database.get_access_token(&account.user_id).await?;
|
let access_token = database.get_access_token(&account.user_id).await?;
|
||||||
let credentials = spotify::request_session_token(Credentials {
|
let credentials = spotify::request_session_token(Credentials {
|
||||||
username: account.username.clone(),
|
username: Some(account.username.to_string()),
|
||||||
auth_type: AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN,
|
auth_type: AuthenticationType::AUTHENTICATION_SPOTIFY_TOKEN,
|
||||||
auth_data: access_token.into_bytes(),
|
auth_data: access_token.into_bytes(),
|
||||||
})
|
})
|
||||||
|
@ -632,7 +632,7 @@ async fn retrieve_credentials(database: &Database, owner: impl AsRef<str>) -> Re
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Credentials {
|
Ok(Credentials {
|
||||||
username: account.username,
|
username: Some(account.username),
|
||||||
auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS,
|
auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS,
|
||||||
auth_data: BASE64.decode(token)?,
|
auth_data: BASE64.decode(token)?,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord_stats"
|
name = "spoticord_stats"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "spoticord_utils"
|
name = "spoticord_utils"
|
||||||
version = "2.2.3"
|
version = "2.2.4"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
|
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
|
||||||
use librespot::{
|
use librespot::{
|
||||||
core::{connection::AuthenticationError, Session, SessionConfig},
|
core::{Session, SessionConfig},
|
||||||
discovery::Credentials,
|
discovery::Credentials,
|
||||||
protocol::{authentication::AuthenticationType, keyexchange::ErrorCode},
|
protocol::authentication::AuthenticationType,
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -15,17 +15,17 @@ pub async fn validate_token(
|
||||||
let auth_data = BASE64.decode(token.into())?;
|
let auth_data = BASE64.decode(token.into())?;
|
||||||
|
|
||||||
let credentials = Credentials {
|
let credentials = Credentials {
|
||||||
username: username.into(),
|
username: Some(username.into()),
|
||||||
auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS,
|
auth_type: AuthenticationType::AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS,
|
||||||
auth_data,
|
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?;
|
let new_credentials = request_session_token(credentials.clone()).await?;
|
||||||
|
|
||||||
if credentials.auth_data != new_credentials.auth_data {
|
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)));
|
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> {
|
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 session = Session::new(SessionConfig::default(), None);
|
||||||
let mut tries = 0;
|
let mut tries = 0;
|
||||||
|
|
||||||
Ok(loop {
|
Ok(loop {
|
||||||
let (host, port) = session.apresolver().resolve("accesspoint").await?;
|
match connect(&session, credentials.clone()).await {
|
||||||
|
Ok(creds) => break creds,
|
||||||
let mut transport = match librespot::core::connection::connect(&host, port, None).await {
|
Err(e) => {
|
||||||
Ok(transport) => transport,
|
|
||||||
Err(why) => {
|
|
||||||
// Retry
|
|
||||||
|
|
||||||
tries += 1;
|
tries += 1;
|
||||||
if tries > 3 {
|
if tries > 3 {
|
||||||
return Err(why.into());
|
return Err(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
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,
|
&mut transport,
|
||||||
credentials.clone(),
|
credentials.clone(),
|
||||||
&session.config().device_id,
|
&session.config().device_id,
|
||||||
)
|
),
|
||||||
.await
|
)
|
||||||
{
|
.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());
|
|
||||||
}
|
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
Ok(creds)
|
||||||
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return Err(e.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
mod bot;
|
mod bot;
|
||||||
mod commands;
|
mod commands;
|
||||||
// mod session;
|
|
||||||
// mod utils;
|
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use poise::Framework;
|
use poise::Framework;
|
||||||
|
@ -11,6 +9,11 @@ use spoticord_database::Database;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn 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
|
// Setup logging
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
|
|
Loading…
Reference in New Issue