From 38c64e54be0374a2e437d1880cc82c2eb20fee74 Mon Sep 17 00:00:00 2001 From: awiouy Date: Mon, 5 Feb 2018 09:31:09 +0100 Subject: [PATCH] modularize discovery (wip) --- Cargo.toml | 6 +++--- discovery/Cargo.toml | 23 +++++++++++++++++++++++ {src => discovery/src}/discovery.rs | 20 +++++++++----------- src/lib.rs | 1 + 4 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 discovery/Cargo.toml rename {src => discovery/src}/discovery.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 6e3a798d..79961dff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,8 @@ doc = false path = "audio" [dependencies.librespot-core] path = "core" +[dependencies.librespot-discovery] +path = "discovery" [dependencies.librespot-metadata] path = "metadata" [dependencies.librespot-protocol] @@ -36,7 +38,6 @@ futures = "0.1.8" getopts = "0.2.14" hyper = "0.11.2" log = "0.3.5" -mdns = { git = "https://github.com/plietar/rust-mdns" } num-bigint = "0.1.35" protobuf = "1.1" rand = "0.3.13" @@ -55,7 +56,6 @@ portaudio-rs = { version = "0.3.0", optional = true } libpulse-sys = { version = "0.0.0", optional = true } jack = { version = "0.5.3", optional = true } libc = { version = "0.2", optional = true } -dns-sd = { version = "0.1.3", optional = true } [build-dependencies] rand = "0.3.13" @@ -71,7 +71,7 @@ jackaudio-backend = ["jack"] with-tremor = ["librespot-audio/with-tremor"] with-lewton = ["librespot-audio/with-lewton"] -with-dns-sd = ["dns-sd"] +with-dns-sd = ["librespot-discovery/with-dns-sd"] default = ["portaudio-backend"] diff --git a/discovery/Cargo.toml b/discovery/Cargo.toml new file mode 100644 index 00000000..69063f23 --- /dev/null +++ b/discovery/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "librespot-discovery" +version = "0.1.0" +authors = ["Paul Lietar "] + +[dependencies.librespot-core] +path = "../core" + +[dependencies] +base64 = "0.5.0" +futures = "0.1.8" +num-bigint = "0.1.35" +rand = "0.3.13" +rust-crypto = { git = "https://github.com/awmath/rust-crypto.git", branch = "avx2" } +tokio-core = "0.1.2" +url = "1.3" + +dns-sd = { version = "0.1.3", optional = true } +mdns = { git = "https://github.com/plietar/rust-mdns", optional = true } + +[features] +with-dns-sd = ["dns-sd"] +with-mdns = ["mdns"] diff --git a/src/discovery.rs b/discovery/src/discovery.rs similarity index 99% rename from src/discovery.rs rename to discovery/src/discovery.rs index e29a798a..771e96b0 100644 --- a/src/discovery.rs +++ b/discovery/src/discovery.rs @@ -1,4 +1,8 @@ use base64; +use core::diffie_hellman::{DH_GENERATOR, DH_PRIME}; +use core::authentication::Credentials; +use core::util; +use core::config::ConnectConfig; use crypto::digest::Digest; use crypto::mac::Mac; use crypto; @@ -6,13 +10,6 @@ use futures::sync::mpsc; use futures::{Future, Stream, Poll}; use hyper::server::{Service, Request, Response, Http}; use hyper::{self, Get, Post, StatusCode}; - -#[cfg(feature = "with-dns-sd")] -use dns_sd::DNSService; - -#[cfg(not(feature = "with-dns-sd"))] -use mdns; - use num_bigint::BigUint; use rand; use std::collections::BTreeMap; @@ -21,10 +18,11 @@ use std::sync::Arc; use tokio_core::reactor::Handle; use url; -use core::diffie_hellman::{DH_GENERATOR, DH_PRIME}; -use core::authentication::Credentials; -use core::util; -use core::config::ConnectConfig; +#[cfg(feature = "with-dns-sd")] +use dns_sd::DNSService; + +#[cfg(not(feature = "with-dns-sd"))] +use mdns; #[derive(Clone)] struct Discovery(Arc); diff --git a/src/lib.rs b/src/lib.rs index 09398162..830ac6b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ extern crate url; pub extern crate librespot_audio as audio; pub extern crate librespot_core as core; +pub extern crate librespot_discovery as discovery; pub extern crate librespot_protocol as protocol; pub extern crate librespot_metadata as metadata;