mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Use the fallback AP when apresolve fails.
This matches the desktop client’s behaviour. Fixes #136
This commit is contained in:
parent
c6327af2f3
commit
7fd8503f45
2 changed files with 14 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
|||
const APRESOLVE_ENDPOINT : &'static str = "http://apresolve.spotify.com/";
|
||||
const AP_FALLBACK : &'static str = "ap.spotify.com:80";
|
||||
|
||||
use hyper;
|
||||
use std::io::Read;
|
||||
|
@ -9,14 +10,17 @@ pub struct APResolveData {
|
|||
ap_list: Vec<String>
|
||||
}
|
||||
|
||||
pub fn apresolve() -> Result<Vec<String>, ()> {
|
||||
pub fn apresolve() -> String {
|
||||
let client = hyper::client::Client::new();
|
||||
(|| {
|
||||
let mut response = client.get(APRESOLVE_ENDPOINT).send().map_err(|_| ())?;
|
||||
let mut data = String::new();
|
||||
response.read_to_string(&mut data).map_err(|_| ())?;
|
||||
|
||||
let mut response = client.get(APRESOLVE_ENDPOINT).send().unwrap();
|
||||
let mut data = String::new();
|
||||
response.read_to_string(&mut data).unwrap();
|
||||
|
||||
let data : APResolveData = serde_json::from_str(&data).unwrap();
|
||||
|
||||
Ok(data.ap_list)
|
||||
let data : APResolveData = serde_json::from_str(&data).map_err(|_| ())?;
|
||||
data.ap_list.first().map(Clone::clone).ok_or(())
|
||||
})().unwrap_or_else(|_| {
|
||||
warn!("failed to resolve AP, using fallback");
|
||||
AP_FALLBACK.into()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ use eventual::Future;
|
|||
use eventual::Async;
|
||||
use protobuf::{self, Message};
|
||||
use rand::thread_rng;
|
||||
use rand::Rng;
|
||||
use std::io::{Read, Write, Cursor};
|
||||
use std::result::Result;
|
||||
use std::sync::{Mutex, RwLock, Arc, mpsc};
|
||||
|
@ -95,11 +94,10 @@ impl Session {
|
|||
fn connect(&self) -> CipherConnection {
|
||||
let local_keys = DHLocalKeys::random(&mut thread_rng());
|
||||
|
||||
let aps = apresolve().unwrap();
|
||||
let ap = thread_rng().choose(&aps).expect("No APs found");
|
||||
let ap = apresolve();
|
||||
|
||||
info!("Connecting to AP {}", ap);
|
||||
let mut connection = PlainConnection::connect(ap).unwrap();
|
||||
let mut connection = PlainConnection::connect(&ap).unwrap();
|
||||
|
||||
let request = protobuf_init!(protocol::keyexchange::ClientHello::new(), {
|
||||
build_info => {
|
||||
|
|
Loading…
Reference in a new issue