Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable avahi support for discovery #201

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ before_script:
- rustup target add armv7-unknown-linux-gnueabihf

script:
- cargo build --no-default-features
- cargo build --no-default-features --features "with-tremor"
- cargo build --no-default-features --features "portaudio-backend"
- cargo build --no-default-features --features "pulseaudio-backend"
- cargo build --no-default-features --features "alsa-backend"
- cargo build --no-default-features --target armv7-unknown-linux-gnueabihf
- cargo build --no-default-features --features "with-rust-mdns"
- cargo build --no-default-features --features "with-rust-mdns with-tremor"
- cargo build --no-default-features --features "with-rust-mdns portaudio-backend"
- cargo build --no-default-features --features "with-rust-mdns pulseaudio-backend"
- cargo build --no-default-features --features "with-rust-mdns alsa-backend"
- cargo build --no-default-features --target armv7-unknown-linux-gnueabihf --features "with-rust-mdns"

notifications:
email: false
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ alsa = { git = "https://github.com/plietar/rust-alsa", optional = tru
portaudio-rs = { version = "0.3.0", optional = true }
libpulse-sys = { git = "https://github.com/astro/libpulse-sys", optional = true }

mdns = { git = "https://github.com/plietar/rust-mdns" }
mdns = { git = "https://github.com/plietar/rust-mdns", optional = true }
dns-sd = { version = "~0.1.3", optional = true }

error-chain = { version = "0.9.0", default_features = false }
futures = "0.1.8"
Expand All @@ -71,8 +72,10 @@ portaudio-backend = ["portaudio-rs"]
pulseaudio-backend = ["libpulse-sys"]

with-tremor = ["tremor"]
with-rust-mdns = ["mdns"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the feature to with-internal-mdns

with-avahi = ["dns-sd"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, with-external-mdns.

dns-sd is actually Apple's API.
Avahi provides a compatibility layer between the two


default = ["portaudio-backend"]
default = ["portaudio-backend","with-rust-mdns"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there should be a space between the two items.


[package.metadata.deb]
maintainer = "nobody"
Expand Down
3 changes: 3 additions & 0 deletions contrib/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# The resulting image can be used to build librespot for linux x86_64, armhf and armel.
# $ docker run -v /tmp/librespot-build:/build librespot-cross
# To build librespot with avahi support
# $ docker run -v /tmp/librespot-build:/build librespot-cross /src/contrib/docker-build-avahi.sh
#
# The compiled binaries will be located in /tmp/librespot-build
#
Expand All @@ -23,6 +25,7 @@ RUN apt-get update

RUN apt-get install -y curl git build-essential crossbuild-essential-arm64 crossbuild-essential-armel crossbuild-essential-armhf crossbuild-essential-mipsel
RUN apt-get install -y libasound2-dev libasound2-dev:arm64 libasound2-dev:armel libasound2-dev:armhf libasound2-dev:mipsel
RUN apt-get install -y libavahi-compat-libdnssd-dev libavahi-compat-libdnssd-dev:arm64 libavahi-compat-libdnssd-dev:armel libavahi-compat-libdnssd-dev:armhf libavahi-compat-libdnssd-dev:mipsel

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin/:${PATH}"
Expand Down
24 changes: 24 additions & 0 deletions contrib/docker-build-avahi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -eux

cargo build --release --no-default-features --features "alsa-backend with-avahi"
cp /usr/lib/x86_64-linux-gnu/libdns_sd.so.1 /build/release

export PKG_CONFIG_ALLOW_CROSS=0

export PKG_CONFIG_PATH=/usr/lib/aarch64-unknown-linux-gnu/pkgconfig
cargo build --release --target aarch64-unknown-linux-gnu --no-default-features --features "alsa-backend with-avahi"
cp /usr/lib/aarch64-linux-gnu/libdns_sd.so.1 /build/aarch64-unknown-linux-gnu/release

export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabi/pkgconfig
cargo build --release --target arm-unknown-linux-gnueabi --no-default-features --features "alsa-backend with-avahi"
cp /usr/lib/arm-linux-gnueabi/libdns_sd.so.1 /build/arm-unknown-linux-gnueabi/release

export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig
cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features "alsa-backend with-avahi"
cp /usr/lib/arm-linux-gnueabihf/libdns_sd.so.1 /build/arm-unknown-linux-gnueabihf/release

export PKG_CONFIG_PATH=/usr/lib/mipsel-linux-gnu/pkgconfig
cargo build --release --target mipsel-unknown-linux-gnu --no-default-features --features "alsa-backend with-avahi"
cp /usr/libmipsel-linux-gnu/libdns_sd.so.1 /build/mipsel-unknown-linux-gnu/release

27 changes: 26 additions & 1 deletion src/authentication/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use futures::sync::mpsc;
use futures::{Future, Stream, BoxFuture, Poll, Async};
use hyper::server::{Service, NewService, Request, Response, Http};
use hyper::{self, Get, Post, StatusCode};
use mdns;
use num_bigint::BigUint;
use rand;
use std::collections::BTreeMap;
Expand All @@ -20,6 +19,12 @@ use url;
use authentication::Credentials;
use util;

#[cfg(feature = "with-rust-mdns")]
use mdns;

#[cfg(feature = "with-avahi")]
use dns_sd::DNSService;

#[derive(Clone)]
struct Discovery(Arc<DiscoveryInner>);
struct DiscoveryInner {
Expand Down Expand Up @@ -202,7 +207,10 @@ impl NewService for Discovery {

pub struct DiscoveryStream {
credentials: mpsc::UnboundedReceiver<Credentials>,
#[cfg(feature = "with-rust-mdns")]
_svc: mdns::Service,
#[cfg(feature = "with-avahi")]
_svc: DNSService,
task: Box<Future<Item=(), Error=io::Error>>,
}

Expand All @@ -212,22 +220,39 @@ pub fn discovery(handle: &Handle, device_name: String, device_id: String)
let (discovery, creds_rx) = Discovery::new(device_name.clone(), device_id);

let listener = TcpListener::bind(&"0.0.0.0:0".parse().unwrap(), handle)?;

#[cfg(feature = "with-rust-mdns")]
let addr = listener.local_addr()?;

#[cfg(feature = "with-avahi")]
let port = listener.local_addr().unwrap().port();

let http = Http::new();
let handle_ = handle.clone();
let task = Box::new(listener.incoming().for_each(move |(socket, addr)| {
http.bind_connection(&handle_, socket, addr, discovery.clone());
Ok(())
}));

#[cfg(feature = "with-rust-mdns")]
let responder = mdns::Responder::spawn(&handle)?;

#[cfg(feature = "with-rust-mdns")]
let svc = responder.register(
"_spotify-connect._tcp".to_owned(),
device_name,
addr.port(),
&["VERSION=1.0", "CPath=/"]);

#[cfg(feature = "with-avahi")]
let svc = DNSService::register(Some(&*device_name),
"_spotify-connect._tcp",
None,
None,
port,
&["VERSION=1.0", "CPath=/"])
.unwrap();

Ok(DiscoveryStream {
credentials: creds_rx,
_svc: svc,
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extern crate crypto;
extern crate getopts;
extern crate hyper;
extern crate linear_map;
extern crate mdns;
extern crate num_bigint;
extern crate num_integer;
extern crate num_traits;
Expand Down Expand Up @@ -50,6 +49,11 @@ extern crate portaudio_rs;
#[cfg(feature = "libpulse-sys")]
extern crate libpulse_sys;

#[cfg(feature = "with-rust-mdns")]
extern crate mdns;

#[cfg(feature = "with-avahi")]
extern crate dns_sd;

#[macro_use] mod component;
pub mod album_cover;
Expand Down