Reformat according to new rustfmt rules

This commit is contained in:
Johan Anderholm 2018-03-23 06:13:01 +01:00
parent cb61e222d7
commit 612978908f
18 changed files with 54 additions and 131 deletions

View file

@ -1,8 +1,8 @@
use bit_set::BitSet; use bit_set::BitSet;
use byteorder::{BigEndian, ByteOrder, WriteBytesExt}; use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use futures::{Async, Future, Poll};
use futures::Stream; use futures::Stream;
use futures::sync::{mpsc, oneshot}; use futures::sync::{mpsc, oneshot};
use futures::{Async, Future, Poll};
use std::cmp::min; use std::cmp::min;
use std::fs; use std::fs;
use std::io::{self, Read, Seek, SeekFrom, Write}; use std::io::{self, Read, Seek, SeekFrom, Write};
@ -288,20 +288,12 @@ impl Future for AudioFileFetch {
Ok(Async::Ready(Some(data))) => { Ok(Async::Ready(Some(data))) => {
progress = true; progress = true;
self.output self.output.as_mut().unwrap().write_all(data.as_ref()).unwrap();
.as_mut()
.unwrap()
.write_all(data.as_ref())
.unwrap();
} }
Ok(Async::Ready(None)) => { Ok(Async::Ready(None)) => {
progress = true; progress = true;
trace!( trace!("chunk {} / {} complete", self.index, self.shared.chunk_count);
"chunk {} / {} complete",
self.index,
self.shared.chunk_count
);
let full = { let full = {
let mut bitmap = self.shared.bitmap.lock().unwrap(); let mut bitmap = self.shared.bitmap.lock().unwrap();

View file

@ -2,10 +2,10 @@ use base64;
use crypto; use crypto;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::mac::Mac; use crypto::mac::Mac;
use futures::{Future, Poll, Stream};
use futures::sync::mpsc; use futures::sync::mpsc;
use hyper::{self, Get, Post, StatusCode}; use futures::{Future, Poll, Stream};
use hyper::server::{Http, Request, Response, Service}; use hyper::server::{Http, Request, Response, Service};
use hyper::{self, Get, Post, StatusCode};
#[cfg(feature = "with-dns-sd")] #[cfg(feature = "with-dns-sd")]
use dns_sd::DNSService; use dns_sd::DNSService;

View file

@ -1,6 +1,6 @@
use futures::{Async, Future, Poll, Sink, Stream};
use futures::future; use futures::future;
use futures::sync::{mpsc, oneshot}; use futures::sync::{mpsc, oneshot};
use futures::{Async, Future, Poll, Sink, Stream};
use protobuf::{self, Message}; use protobuf::{self, Message};
use core::config::ConnectConfig; use core::config::ConnectConfig;
@ -442,8 +442,7 @@ impl SpircTask {
self.update_tracks(&frame); self.update_tracks(&frame);
if self.state.get_track().len() > 0 { if self.state.get_track().len() > 0 {
self.state self.state.set_position_ms(frame.get_state().get_position_ms());
.set_position_ms(frame.get_state().get_position_ms());
self.state.set_position_measured_at(now_ms() as u64); self.state.set_position_measured_at(now_ms() as u64);
let play = frame.get_state().get_status() == PlayStatus::kPlayStatusPlay; let play = frame.get_state().get_status() == PlayStatus::kPlayStatusPlay;
@ -530,10 +529,8 @@ impl SpircTask {
MessageType::kMessageTypeVolume => { MessageType::kMessageTypeVolume => {
self.device.set_volume(frame.get_volume()); self.device.set_volume(frame.get_volume());
self.mixer.set_volume(volume_to_mixer( self.mixer
frame.get_volume() as u16, .set_volume(volume_to_mixer(frame.get_volume() as u16, self.linear_volume));
self.linear_volume,
));
self.notify(None); self.notify(None);
} }

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ByteOrder, WriteBytesExt}; use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use bytes::Bytes; use bytes::Bytes;
use futures::{Async, Future, Poll};
use futures::sync::oneshot; use futures::sync::oneshot;
use futures::{Async, Future, Poll};
use std::collections::HashMap; use std::collections::HashMap;
use std::io::Write; use std::io::Write;
@ -35,11 +35,7 @@ impl AudioKeyManager {
let _ = sender.send(Ok(AudioKey(key))); let _ = sender.send(Ok(AudioKey(key)));
} }
0xe => { 0xe => {
warn!( warn!("error audio key {:x} {:x}", data.as_ref()[0], data.as_ref()[1]);
"error audio key {:x} {:x}",
data.as_ref()[0],
data.as_ref()[1]
);
let _ = sender.send(Err(AudioKeyError)); let _ = sender.send(Err(AudioKeyError));
} }
_ => (), _ => (),

View file

@ -88,11 +88,8 @@ impl Credentials {
let blob = { let blob = {
// Anyone know what this block mode is ? // Anyone know what this block mode is ?
let mut data = vec![0u8; encrypted_blob.len()]; let mut data = vec![0u8; encrypted_blob.len()];
let mut cipher = aes::ecb_decryptor( let mut cipher =
aes::KeySize::KeySize192, aes::ecb_decryptor(aes::KeySize::KeySize192, &key, crypto::blockmodes::NoPadding);
&key,
crypto::blockmodes::NoPadding,
);
cipher cipher
.decrypt( .decrypt(
&mut crypto::buffer::RefReadBuffer::new(&encrypted_blob), &mut crypto::buffer::RefReadBuffer::new(&encrypted_blob),
@ -193,10 +190,9 @@ pub fn get_credentials<F: FnOnce(&String) -> String>(
Some(credentials.clone()) Some(credentials.clone())
} }
(Some(username), None, _) => Some(Credentials::with_password( (Some(username), None, _) => {
username.clone(), Some(Credentials::with_password(username.clone(), prompt(&username)))
prompt(&username), }
)),
(None, _, Some(credentials)) => Some(credentials), (None, _, Some(credentials)) => Some(credentials),

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use bytes::Bytes; use bytes::Bytes;
use futures::{Async, Poll, Stream};
use futures::sync::{mpsc, BiLock}; use futures::sync::{mpsc, BiLock};
use futures::{Async, Poll, Stream};
use std::collections::HashMap; use std::collections::HashMap;
use util::SeqGenerator; use util::SeqGenerator;

View file

@ -88,8 +88,7 @@ impl Decoder for APCodec {
let mut payload = buf.split_to(size + MAC_SIZE); let mut payload = buf.split_to(size + MAC_SIZE);
self.decode_cipher self.decode_cipher.decrypt(&mut payload.get_mut(..size).unwrap());
.decrypt(&mut payload.get_mut(..size).unwrap());
let mac = payload.split_off(size); let mac = payload.split_off(size);
self.decode_cipher.check_mac(mac.as_ref())?; self.decode_cipher.check_mac(mac.as_ref())?;

View file

@ -7,9 +7,9 @@ use protobuf::{self, Message, MessageStatic};
use rand::thread_rng; use rand::thread_rng;
use std::io::{self, Read}; use std::io::{self, Read};
use std::marker::PhantomData; use std::marker::PhantomData;
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_io::codec::Framed; use tokio_io::codec::Framed;
use tokio_io::io::{read_exact, write_all, ReadExact, Window, WriteAll}; use tokio_io::io::{read_exact, write_all, ReadExact, Window, WriteAll};
use tokio_io::{AsyncRead, AsyncWrite};
use super::codec::APCodec; use super::codec::APCodec;
use diffie_hellman::DHLocalKeys; use diffie_hellman::DHLocalKeys;
@ -93,10 +93,7 @@ fn client_hello<T: AsyncWrite>(connection: T, gc: Vec<u8>) -> WriteAll<T, Vec<u8
packet packet
.mut_cryptosuites_supported() .mut_cryptosuites_supported()
.push(protocol::keyexchange::Cryptosuite::CRYPTO_SUITE_SHANNON); .push(protocol::keyexchange::Cryptosuite::CRYPTO_SUITE_SHANNON);
packet packet.mut_login_crypto_hello().mut_diffie_hellman().set_gc(gc);
.mut_login_crypto_hello()
.mut_diffie_hellman()
.set_gc(gc);
packet packet
.mut_login_crypto_hello() .mut_login_crypto_hello()
.mut_diffie_hellman() .mut_diffie_hellman()

View file

@ -37,22 +37,14 @@ pub fn authenticate(
use protocol::keyexchange::APLoginFailed; use protocol::keyexchange::APLoginFailed;
let mut packet = ClientResponseEncrypted::new(); let mut packet = ClientResponseEncrypted::new();
packet packet.mut_login_credentials().set_username(credentials.username);
.mut_login_credentials() packet.mut_login_credentials().set_typ(credentials.auth_type);
.set_username(credentials.username);
packet
.mut_login_credentials()
.set_typ(credentials.auth_type);
packet packet
.mut_login_credentials() .mut_login_credentials()
.set_auth_data(credentials.auth_data); .set_auth_data(credentials.auth_data);
packet packet.mut_system_info().set_cpu_family(CpuFamily::CPU_UNKNOWN);
.mut_system_info()
.set_cpu_family(CpuFamily::CPU_UNKNOWN);
packet.mut_system_info().set_os(Os::OS_UNKNOWN); packet.mut_system_info().set_os(Os::OS_UNKNOWN);
packet packet.mut_system_info().set_system_information_string(format!(
.mut_system_info()
.set_system_information_string(format!(
"librespot_{}_{}", "librespot_{}_{}",
version::short_sha(), version::short_sha(),
version::build_id() version::build_id()

View file

@ -7,17 +7,13 @@ use util;
lazy_static! { lazy_static! {
pub static ref DH_GENERATOR: BigUint = BigUint::from_u64(0x2).unwrap(); pub static ref DH_GENERATOR: BigUint = BigUint::from_u64(0x2).unwrap();
pub static ref DH_PRIME: BigUint = BigUint::from_bytes_be(&[ pub static ref DH_PRIME: BigUint = BigUint::from_bytes_be(&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34,
0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, 0xcc, 0x74,
0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x02, 0x0b, 0xbe, 0xa6, 0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd,
0x08, 0x8a, 0x67, 0xcc, 0x74, 0x02, 0x0b, 0xbe, 0xa6, 0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d, 0xf2, 0x5f, 0x14, 0x37,
0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45, 0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6,
0x34, 0x04, 0xdd, 0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 0xf4, 0x4c, 0x42, 0xe9, 0xa6, 0x3a, 0x36, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d, 0xf2, 0x5f, 0x14, ]);
0x37, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45,
0xe4, 0x85, 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6, 0xf4,
0x4c, 0x42, 0xe9, 0xa6, 0x3a, 0x36, 0x20, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff ]);
} }
pub struct DHLocalKeys { pub struct DHLocalKeys {
@ -43,11 +39,7 @@ impl DHLocalKeys {
} }
pub fn shared_secret(&self, remote_key: &[u8]) -> Vec<u8> { pub fn shared_secret(&self, remote_key: &[u8]) -> Vec<u8> {
let shared_key = util::powm( let shared_key = util::powm(&BigUint::from_bytes_be(remote_key), &self.private_key, &DH_PRIME);
&BigUint::from_bytes_be(remote_key),
&self.private_key,
&DH_PRIME,
);
shared_key.to_bytes_be() shared_key.to_bytes_be()
} }
} }

View file

@ -1,7 +1,7 @@
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use bytes::Bytes; use bytes::Bytes;
use futures::{Async, Future, Poll};
use futures::sync::{mpsc, oneshot}; use futures::sync::{mpsc, oneshot};
use futures::{Async, Future, Poll};
use protobuf; use protobuf;
use protocol; use protocol;
use std::collections::HashMap; use std::collections::HashMap;

View file

@ -1,9 +1,9 @@
use bytes::Bytes; use bytes::Bytes;
use futures::{Async, Future, IntoFuture, Poll, Stream};
use futures::sync::mpsc; use futures::sync::mpsc;
use futures::{Async, Future, IntoFuture, Poll, Stream};
use std::io; use std::io;
use std::sync::{Arc, RwLock, Weak};
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT}; use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
use std::sync::{Arc, RwLock, Weak};
use tokio_core::reactor::{Handle, Remote}; use tokio_core::reactor::{Handle, Remote};
use apresolve::apresolve_or_fallback; use apresolve::apresolve_or_fallback;
@ -124,11 +124,7 @@ impl Session {
.map(|_| ()); .map(|_| ());
let receiver_task = DispatchTask(stream, session.weak()); let receiver_task = DispatchTask(stream, session.weak());
let task = Box::new( let task = Box::new((receiver_task, sender_task).into_future().map(|((), ())| ()));
(receiver_task, sender_task)
.into_future()
.map(|((), ())| ()),
);
(session, task) (session, task)
} }

View file

@ -36,9 +36,7 @@ fn main() {
let session = core.run(Session::connect(session_config, credentials, None, handle)) let session = core.run(Session::connect(session_config, credentials, None, handle))
.unwrap(); .unwrap();
let player = Player::new(player_config, session.clone(), None, move || { let player = Player::new(player_config, session.clone(), None, move || (backend)(None));
(backend)(None)
});
println!("Playing..."); println!("Playing...");
core.run(player.load(track, true, 0)).unwrap(); core.run(player.load(track, true, 0)).unwrap();

View file

@ -44,12 +44,8 @@ impl Open for JackSink {
let client_name = client_name.unwrap_or("librespot".to_string()); let client_name = client_name.unwrap_or("librespot".to_string());
let (client, _status) = Client::new(&client_name[..], client_options::NO_START_SERVER).unwrap(); let (client, _status) = Client::new(&client_name[..], client_options::NO_START_SERVER).unwrap();
let ch_r = client let ch_r = client.register_port("out_0", AudioOutSpec::default()).unwrap();
.register_port("out_0", AudioOutSpec::default()) let ch_l = client.register_port("out_1", AudioOutSpec::default()).unwrap();
.unwrap();
let ch_l = client
.register_port("out_1", AudioOutSpec::default())
.unwrap();
// buffer for samples from librespot (~10ms) // buffer for samples from librespot (~10ms)
let (tx, rx) = sync_channel(2 * 1024 * 4); let (tx, rx) = sync_channel(2 * 1024 * 4);
let jack_data = JackData { let jack_data = JackData {

View file

@ -28,10 +28,7 @@ impl Sink for StdoutSink {
fn write(&mut self, data: &[i16]) -> io::Result<()> { fn write(&mut self, data: &[i16]) -> io::Result<()> {
let data: &[u8] = unsafe { let data: &[u8] = unsafe {
slice::from_raw_parts( slice::from_raw_parts(data.as_ptr() as *const u8, data.len() * mem::size_of::<i16>())
data.as_ptr() as *const u8,
data.len() * mem::size_of::<i16>(),
)
}; };
self.0.write_all(data)?; self.0.write_all(data)?;

View file

@ -1,7 +1,7 @@
use byteorder::{LittleEndian, ReadBytesExt}; use byteorder::{LittleEndian, ReadBytesExt};
use futures; use futures;
use futures::{future, Future};
use futures::sync::oneshot; use futures::sync::oneshot;
use futures::{future, Future};
use std; use std;
use std::borrow::Cow; use std::borrow::Cow;
use std::io::{Read, Result, Seek, SeekFrom}; use std::io::{Read, Result, Seek, SeekFrom};
@ -93,10 +93,8 @@ impl NormalisationData {
} }
fn get_factor(config: &PlayerConfig, data: NormalisationData) -> f32 { fn get_factor(config: &PlayerConfig, data: NormalisationData) -> f32 {
let mut normalisation_factor = f32::powf( let mut normalisation_factor =
10.0, f32::powf(10.0, (data.track_gain_db + config.normalisation_pregain) / 20.0);
(data.track_gain_db + config.normalisation_pregain) / 20.0,
);
if normalisation_factor * data.track_peak > 1.0 { if normalisation_factor * data.track_peak > 1.0 {
warn!("Reducing normalisation factor to prevent clipping. Please add negative pregain to avoid."); warn!("Reducing normalisation factor to prevent clipping. Please add negative pregain to avoid.");
@ -231,12 +229,7 @@ impl PlayerState {
use self::PlayerState::*; use self::PlayerState::*;
match *self { match *self {
Stopped | EndOfTrack { .. } => None, Stopped | EndOfTrack { .. } => None,
Paused { Paused { ref mut decoder, .. } | Playing { ref mut decoder, .. } => Some(decoder),
ref mut decoder, ..
}
| Playing {
ref mut decoder, ..
} => Some(decoder),
Invalid => panic!("invalid state"), Invalid => panic!("invalid state"),
} }
} }
@ -525,10 +518,7 @@ impl PlayerInternal {
.map(|alt_id| Track::get(&self.session, *alt_id)); .map(|alt_id| Track::get(&self.session, *alt_id));
let alternatives = future::join_all(alternatives).wait().unwrap(); let alternatives = future::join_all(alternatives).wait().unwrap();
alternatives alternatives.into_iter().find(|alt| alt.available).map(Cow::Owned)
.into_iter()
.find(|alt| alt.available)
.map(Cow::Owned)
} }
} }
@ -558,10 +548,7 @@ impl PlayerInternal {
let file_id = match track.files.get(&format) { let file_id = match track.files.get(&format) {
Some(&file_id) => file_id, Some(&file_id) => file_id,
None => { None => {
warn!( warn!("Track \"{}\" is not available in format {:?}", track.name, format);
"Track \"{}\" is not available in format {:?}",
track.name, format
);
return None; return None;
} }
}; };

View file

@ -7,10 +7,7 @@ fn main() {
for &(path, expected_checksum) in files::FILES { for &(path, expected_checksum) in files::FILES {
let actual = cksum_file(path).unwrap(); let actual = cksum_file(path).unwrap();
if expected_checksum != actual { if expected_checksum != actual {
panic!( panic!("Checksum for {:?} does not match. Try running build.sh", path);
"Checksum for {:?} does not match. Try running build.sh",
path
);
} }
} }
} }

View file

@ -13,8 +13,8 @@ extern crate tokio_signal;
use crypto::digest::Digest; use crypto::digest::Digest;
use crypto::sha1::Sha1; use crypto::sha1::Sha1;
use env_logger::LogBuilder; use env_logger::LogBuilder;
use futures::{Async, Future, Poll, Stream};
use futures::sync::mpsc::UnboundedReceiver; use futures::sync::mpsc::UnboundedReceiver;
use futures::{Async, Future, Poll, Stream};
use std::env; use std::env;
use std::io::{self, stderr, Write}; use std::io::{self, stderr, Write};
use std::mem; use std::mem;
@ -108,11 +108,7 @@ fn setup(args: &[String]) -> Setup {
"cache", "cache",
"Path to a directory where files will be cached.", "Path to a directory where files will be cached.",
"CACHE", "CACHE",
).optflag( ).optflag("", "disable-audio-cache", "Disable caching of the audio data.")
"",
"disable-audio-cache",
"Disable caching of the audio data.",
)
.reqopt("n", "name", "Device name", "NAME") .reqopt("n", "name", "Device name", "NAME")
.optopt("", "device-type", "Displayed device type", "DEVICE_TYPE") .optopt("", "device-type", "Displayed device type", "DEVICE_TYPE")
.optopt( .optopt(
@ -176,12 +172,7 @@ fn setup(args: &[String]) -> Setup {
let matches = match opts.parse(&args[1..]) { let matches = match opts.parse(&args[1..]) {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => {
writeln!( writeln!(stderr(), "error: {}\n{}", f.to_string(), usage(&args[0], &opts)).unwrap();
stderr(),
"error: {}\n{}",
f.to_string(),
usage(&args[0], &opts)
).unwrap();
exit(1); exit(1);
} }
}; };