Bladeren bron

Merge pull request #112 from librespot-org/feature_dns

Feature flag for selecting dns service
Sasha Hilton 7 jaren geleden
bovenliggende
commit
932441db45
4 gewijzigde bestanden met toevoegingen van 52 en 3 verwijderingen
  1. 11 0
      Cargo.lock
  2. 5 2
      Cargo.toml
  3. 30 0
      src/discovery.rs
  4. 6 1
      src/lib.rs

+ 11 - 0
Cargo.lock

@@ -106,6 +106,15 @@ dependencies = [
  "quick-error 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "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]]
 [[package]]
 name = "dtoa"
 name = "dtoa"
 version = "0.4.2"
 version = "0.4.2"
@@ -272,6 +281,7 @@ version = "0.1.0"
 dependencies = [
 dependencies = [
  "alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)",
  "alsa 0.0.1 (git+https://github.com/plietar/rust-alsa)",
  "base64 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "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)",
  "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)",
  "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)",
  "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 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 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-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 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 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"
 "checksum error-chain 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e92ecf0a508c8e074c0e6fa8fe0fa38414848ad4dfc4db6f74c5e9753330b248"

+ 5 - 2
Cargo.toml

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

+ 30 - 0
src/discovery.rs

@@ -6,7 +6,13 @@ use futures::sync::mpsc;
 use futures::{Future, Stream, Poll};
 use futures::{Future, Stream, Poll};
 use hyper::server::{Service, Request, Response, Http};
 use hyper::server::{Service, Request, Response, Http};
 use hyper::{self, Get, Post, StatusCode};
 use hyper::{self, Get, Post, StatusCode};
+
+#[cfg(feature = "with-dns-sd")]
+use dns_sd::DNSService;
+
+#[cfg(not(feature = "with-dns-sd"))]
 use mdns;
 use mdns;
+
 use num_bigint::BigUint;
 use num_bigint::BigUint;
 use rand;
 use rand;
 use std::collections::BTreeMap;
 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 {
 pub struct DiscoveryStream {
     credentials: mpsc::UnboundedReceiver<Credentials>,
     credentials: mpsc::UnboundedReceiver<Credentials>,
     _svc: mdns::Service,
     _svc: mdns::Service,
@@ -204,7 +217,13 @@ pub fn discovery(handle: &Handle, config: ConnectConfig, device_id: String, port
         debug!("Zeroconf server listening on 0.0.0.0:{}", port);
         debug!("Zeroconf server listening on 0.0.0.0:{}", port);
         http.serve_addr_handle(&format!("0.0.0.0:{}", port).parse().unwrap(), &handle, move || Ok(discovery.clone())).unwrap()
         http.serve_addr_handle(&format!("0.0.0.0:{}", port).parse().unwrap(), &handle, move || Ok(discovery.clone())).unwrap()
     };
     };
+
+    #[cfg(feature = "with-dns-sd")]
+    let port = serve.incoming_ref().local_addr().port();
+
+    #[cfg(not(feature = "with-dns-sd"))]
     let addr = serve.incoming_ref().local_addr();
     let addr = serve.incoming_ref().local_addr();
+
     let server_future = {
     let server_future = {
         let handle = handle.clone();
         let handle = handle.clone();
         serve.for_each(move |connection| {
         serve.for_each(move |connection| {
@@ -215,7 +234,18 @@ pub fn discovery(handle: &Handle, config: ConnectConfig, device_id: String, port
     };
     };
     handle.spawn(server_future);
     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 responder = mdns::Responder::spawn(&handle)?;
     let responder = mdns::Responder::spawn(&handle)?;
+    
+    #[cfg(not(feature = "with-dns-sd"))]
     let svc = responder.register(
     let svc = responder.register(
         "_spotify-connect._tcp".to_owned(),
         "_spotify-connect._tcp".to_owned(),
         config.name,
         config.name,

+ 6 - 1
src/lib.rs

@@ -10,7 +10,6 @@ extern crate base64;
 extern crate crypto;
 extern crate crypto;
 extern crate futures;
 extern crate futures;
 extern crate hyper;
 extern crate hyper;
-extern crate mdns;
 extern crate num_bigint;
 extern crate num_bigint;
 extern crate protobuf;
 extern crate protobuf;
 extern crate rand;
 extern crate rand;
@@ -34,6 +33,12 @@ extern crate libpulse_sys;
 #[cfg(feature = "libc")]
 #[cfg(feature = "libc")]
 extern crate 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 audio_backend;
 pub mod discovery;
 pub mod discovery;
 pub mod keymaster;
 pub mod keymaster;