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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,17 +7,13 @@ use util;
lazy_static! {
pub static ref DH_GENERATOR: BigUint = BigUint::from_u64(0x2).unwrap();
pub static ref DH_PRIME: BigUint = BigUint::from_bytes_be(&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9,
0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6,
0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e,
0x08, 0x8a, 0x67, 0xcc, 0x74, 0x02, 0x0b, 0xbe, 0xa6,
0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e,
0x34, 0x04, 0xdd, 0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a,
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 ]);
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34,
0xc4, 0xc6, 0x62, 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67, 0xcc, 0x74,
0x02, 0x0b, 0xbe, 0xa6, 0x3b, 0x13, 0x9b, 0x22, 0x51, 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd,
0xef, 0x95, 0x19, 0xb3, 0xcd, 0x3a, 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 {
@ -43,11 +39,7 @@ impl DHLocalKeys {
}
pub fn shared_secret(&self, remote_key: &[u8]) -> Vec<u8> {
let shared_key = util::powm(
&BigUint::from_bytes_be(remote_key),
&self.private_key,
&DH_PRIME,
);
let shared_key = util::powm(&BigUint::from_bytes_be(remote_key), &self.private_key, &DH_PRIME);
shared_key.to_bytes_be()
}
}

View file

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

View file

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

View file

@ -36,9 +36,7 @@ fn main() {
let session = core.run(Session::connect(session_config, credentials, None, handle))
.unwrap();
let player = Player::new(player_config, session.clone(), None, move || {
(backend)(None)
});
let player = Player::new(player_config, session.clone(), None, move || (backend)(None));
println!("Playing...");
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, _status) = Client::new(&client_name[..], client_options::NO_START_SERVER).unwrap();
let ch_r = client
.register_port("out_0", AudioOutSpec::default())
.unwrap();
let ch_l = client
.register_port("out_1", AudioOutSpec::default())
.unwrap();
let ch_r = client.register_port("out_0", AudioOutSpec::default()).unwrap();
let ch_l = client.register_port("out_1", AudioOutSpec::default()).unwrap();
// buffer for samples from librespot (~10ms)
let (tx, rx) = sync_channel(2 * 1024 * 4);
let jack_data = JackData {

View file

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

View file

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

View file

@ -7,10 +7,7 @@ fn main() {
for &(path, expected_checksum) in files::FILES {
let actual = cksum_file(path).unwrap();
if expected_checksum != actual {
panic!(
"Checksum for {:?} does not match. Try running build.sh",
path
);
panic!("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::sha1::Sha1;
use env_logger::LogBuilder;
use futures::{Async, Future, Poll, Stream};
use futures::sync::mpsc::UnboundedReceiver;
use futures::{Async, Future, Poll, Stream};
use std::env;
use std::io::{self, stderr, Write};
use std::mem;
@ -108,11 +108,7 @@ fn setup(args: &[String]) -> Setup {
"cache",
"Path to a directory where files will be cached.",
"CACHE",
).optflag(
"",
"disable-audio-cache",
"Disable caching of the audio data.",
)
).optflag("", "disable-audio-cache", "Disable caching of the audio data.")
.reqopt("n", "name", "Device name", "NAME")
.optopt("", "device-type", "Displayed device type", "DEVICE_TYPE")
.optopt(
@ -176,12 +172,7 @@ fn setup(args: &[String]) -> Setup {
let matches = match opts.parse(&args[1..]) {
Ok(m) => m,
Err(f) => {
writeln!(
stderr(),
"error: {}\n{}",
f.to_string(),
usage(&args[0], &opts)
).unwrap();
writeln!(stderr(), "error: {}\n{}", f.to_string(), usage(&args[0], &opts)).unwrap();
exit(1);
}
};