Issue 130 (#164)

* Core API: device_id

* Core API: u128
This commit is contained in:
Anton Voyl 2018-02-24 16:34:04 +01:00 committed by Paul Liétar
parent 685fb4e345
commit 58ea1baa98
4 changed files with 12 additions and 11 deletions

View file

@ -1,6 +1,4 @@
use bytes::Bytes; use bytes::Bytes;
use crypto::digest::Digest;
use crypto::sha1::Sha1;
use futures::{Async, Future, IntoFuture, Poll, Stream}; use futures::{Async, Future, IntoFuture, Poll, Stream};
use futures::sync::mpsc; use futures::sync::mpsc;
use std::io; use std::io;
@ -45,12 +43,6 @@ static SESSION_COUNTER: AtomicUsize = ATOMIC_USIZE_INIT;
#[derive(Clone)] #[derive(Clone)]
pub struct Session(Arc<SessionInternal>); pub struct Session(Arc<SessionInternal>);
pub fn device_id(name: &str) -> String {
let mut h = Sha1::new();
h.input_str(name);
h.result_str()
}
impl Session { impl Session {
pub fn connect( pub fn connect(
config: SessionConfig, config: SessionConfig,

View file

@ -2,7 +2,7 @@ use std;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub struct u128 { pub(crate) struct u128 {
high: u64, high: u64,
low: u64, low: u64,
} }

View file

@ -7,7 +7,7 @@ use std::ops::{Mul, Rem, Shr};
mod int128; mod int128;
pub use util::int128::u128; pub(crate) use util::int128::u128;
pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> { pub fn rand_vec<G: Rng, R: Rand>(rng: &mut G, size: usize) -> Vec<R> {
rng.gen_iter().take(size).collect() rng.gen_iter().take(size).collect()

View file

@ -6,6 +6,7 @@ extern crate librespot;
extern crate tokio_core; extern crate tokio_core;
extern crate tokio_io; extern crate tokio_io;
extern crate tokio_signal; extern crate tokio_signal;
extern crate crypto;
use env_logger::LogBuilder; use env_logger::LogBuilder;
use futures::{Future, Async, Poll, Stream}; use futures::{Future, Async, Poll, Stream};
@ -17,6 +18,8 @@ use std::str::FromStr;
use tokio_core::reactor::{Handle, Core}; use tokio_core::reactor::{Handle, Core};
use tokio_io::IoStream; use tokio_io::IoStream;
use std::mem; use std::mem;
use crypto::digest::Digest;
use crypto::sha1::Sha1;
use librespot::core::authentication::{get_credentials, Credentials}; use librespot::core::authentication::{get_credentials, Credentials};
use librespot::core::cache::Cache; use librespot::core::cache::Cache;
@ -31,6 +34,12 @@ use librespot::playback::mixer::{self, Mixer};
use librespot::playback::player::Player; use librespot::playback::player::Player;
use librespot::connect::spirc::{Spirc, SpircTask}; use librespot::connect::spirc::{Spirc, SpircTask};
fn device_id(name: &str) -> String {
let mut h = Sha1::new();
h.input_str(name);
h.result_str()
}
fn usage(program: &str, opts: &getopts::Options) -> String { fn usage(program: &str, opts: &getopts::Options) -> String {
let brief = format!("Usage: {} [options]", program); let brief = format!("Usage: {} [options]", program);
opts.usage(&brief) opts.usage(&brief)
@ -170,7 +179,7 @@ fn setup(args: &[String]) -> Setup {
}; };
let session_config = { let session_config = {
let device_id = librespot::core::session::device_id(&name); let device_id = device_id(&name);
SessionConfig { SessionConfig {
user_agent: version::version_string(), user_agent: version::version_string(),