Blacklist ap-gew4 access point (#1026)

This commit is contained in:
Roderick van Domburg 2022-07-28 18:51:49 +02:00 committed by GitHub
parent e37fe22195
commit 7bd9186e94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View file

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [playback] `pipe`: Better error handling
### Added
- [core] `apresolve`: Blacklist ap-gew4 access point that causes channel errors
- [playback] `pipe`: Implement stop
### Fixed

View file

@ -8,6 +8,7 @@ use url::Url;
const APRESOLVE_ENDPOINT: &str = "http://apresolve.spotify.com:80";
const AP_FALLBACK: &str = "ap.spotify.com:443";
const AP_BLACKLIST: [&str; 1] = ["ap-gew4.spotify.com"];
#[derive(Clone, Debug, Deserialize)]
struct ApResolveData {
@ -42,8 +43,24 @@ async fn try_apresolve(
let body = hyper::body::to_bytes(response.into_body()).await?;
let data: ApResolveData = serde_json::from_slice(body.as_ref())?;
// filter APs that are known to cause channel errors
let aps: Vec<String> = data
.ap_list
.into_iter()
.filter_map(|ap| {
let host = ap.parse::<Uri>().ok()?.host()?.to_owned();
if !AP_BLACKLIST.iter().any(|&blacklisted| host == blacklisted) {
Some(ap)
} else {
warn!("Ignoring blacklisted access point {}", ap);
None
}
})
.collect();
let ap = if ap_port.is_some() || proxy.is_some() {
data.ap_list.into_iter().find_map(|ap| {
// filter on ports if specified on the command line...
aps.into_iter().find_map(|ap| {
if ap.parse::<Uri>().ok()?.port()? == port {
Some(ap)
} else {
@ -51,9 +68,10 @@ async fn try_apresolve(
}
})
} else {
data.ap_list.into_iter().next()
// ...or pick the first on the list
aps.into_iter().next()
}
.ok_or("empty AP List")?;
.ok_or("Unable to resolve any viable access points.")?;
Ok(ap)
}