Add with-dns-sd feature flag

This commit is contained in:
Sasha Hilton 2018-01-31 12:00:53 +01:00
parent fddcbbcd82
commit d923f3bad3
4 changed files with 51 additions and 4 deletions

11
Cargo.lock generated
View file

@ -106,6 +106,15 @@ dependencies = [
"quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dns-sd"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.2"
@ -272,6 +281,7 @@ version = "0.1.0"
dependencies = [
"alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)",
"base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dns-sd 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1108,6 +1118,7 @@ dependencies = [
"checksum bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1b7db437d718977f6dc9b2e3fd6fc343c02ac6b899b73fdd2179163447bd9ce9"
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
"checksum dns-parser 0.3.2 (git+https://github.com/plietar/dns-parser)" = "<none>"
"checksum dns-sd 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d748509dea20228f63ba519bf142ce2593396386125b01f5b0d6412dab972087"
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b"
"checksum error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e92ecf0a508c8e074c0e6fa8fe0fa38414848ad4dfc4db6f74c5e9753330b248"

View file

@ -54,6 +54,7 @@ alsa = { git = "https://github.com/plietar/rust-alsa", optional = tru
portaudio-rs = { version = "0.3.0", optional = true }
libpulse-sys = { version = "0.0.0", optional = true }
libc = { version = "0.2", optional = true }
dns-sd = { version = "0.1.3", optional = true }
[build-dependencies]
rand = "0.3.13"
@ -68,11 +69,13 @@ pulseaudio-backend = ["libpulse-sys", "libc"]
with-tremor = ["librespot-audio/with-tremor"]
with-lewton = ["librespot-audio/with-lewton"]
with-dns-sd = ["dns-sd"]
default = ["portaudio-backend"]
[package.metadata.deb]
maintainer = "nobody"
copyright = "2016 Paul Liétar"
maintainer = "librespot-org"
copyright = "2018 Paul Liétar"
license_file = ["LICENSE", "4"]
depends = "$auto"
extended_description = """\

View file

@ -6,7 +6,13 @@ 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;
@ -189,6 +195,13 @@ impl Service for Discovery {
}
}
#[cfg(feature = "with-dns-sd")]
pub struct DiscoveryStream {
credentials: mpsc::UnboundedReceiver<Credentials>,
_svc: DNSService,
}
#[cfg(not(feature = "with-dns-sd"))]
pub struct DiscoveryStream {
credentials: mpsc::UnboundedReceiver<Credentials>,
_svc: mdns::Service,
@ -203,7 +216,10 @@ pub fn discovery(handle: &Handle, config: ConnectConfig, device_id: String)
let http = Http::new();
http.serve_addr_handle(&"0.0.0.0:0".parse().unwrap(), &handle, move || Ok(discovery.clone())).unwrap()
};
let addr = serve.incoming_ref().local_addr();
#[cfg(feature = "with-dns-sd")]
let port = serve.incoming_ref().local_addr().port();
let server_future = {
let handle = handle.clone();
serve.for_each(move |connection| {
@ -214,7 +230,19 @@ pub fn discovery(handle: &Handle, config: ConnectConfig, device_id: String)
};
handle.spawn(server_future);
#[cfg(feature = "with-dns-sd")]
let svc = DNSService::register(Some(&*config.name),
"_spotify-connect._tcp",
None,
None,
port,
&["VERSION=1.0", "CPath=/"]).unwrap();
#[cfg(not(feature = "with-dns-sd"))]
let addr = serve.incoming_ref().local_addr();
#[cfg(not(feature = "with-dns-sd"))]
let responder = mdns::Responder::spawn(&handle)?;
#[cfg(not(feature = "with-dns-sd"))]
let svc = responder.register(
"_spotify-connect._tcp".to_owned(),
config.name,

View file

@ -10,7 +10,6 @@ extern crate base64;
extern crate crypto;
extern crate futures;
extern crate hyper;
extern crate mdns;
extern crate num_bigint;
extern crate protobuf;
extern crate rand;
@ -34,6 +33,12 @@ extern crate libpulse_sys;
#[cfg(feature = "libc")]
extern crate libc;
#[cfg(feature = "with-dns-sd")]
extern crate dns_sd;
#[cfg(not(feature = "with-dns-sd"))]
extern crate mdns;
pub mod audio_backend;
pub mod discovery;
pub mod keymaster;