Skip to content

Commit

Permalink
libostree: Add Avahi-file based OstreeRepoFinder implementation
Browse files Browse the repository at this point in the history
This is a more complex implementation of OstreeRepoFinder which resolves
ref names to remote URIs by looking for refs advertised by peers on the
local network using DNS-SD records and mDNS (Avahi). The idea is to
allow OS and app updates to be propagated over local networks, without
the internet.

It requires an OSTree server and code to generate the DNS-SD adverts in
order to be fully functional — support for this will be added
separately.

This commit is unpolished and not ready to be merged. It is intended as
a strawman for feedback.

Unit tests are included.

Signed-off-by: Philip Withnall <[email protected]>
  • Loading branch information
pwithnall committed Apr 28, 2017
1 parent 2fd35e5 commit c8ab171
Show file tree
Hide file tree
Showing 11 changed files with 1,444 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Makefile-libostree.am
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ libostree_1_la_SOURCES += \
src/libostree/ostree-tls-cert-interaction.h \
$(NULL)
endif
if USE_AVAHI
libostree_1_la_SOURCES += \
src/libostree/ostree-repo-finder-avahi.c \
src/libostree/ostree-repo-finder-avahi.h \
src/libostree/ostree-repo-finder-avahi-private.h \
$(NULL)
endif

libostree_1_la_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/bsdiff -I$(srcdir)/libglnx -I$(srcdir)/src/libotutil -I$(srcdir)/src/libostree -I$(builddir)/src/libostree \
$(OT_INTERNAL_GIO_UNIX_CFLAGS) $(OT_INTERNAL_GPGME_CFLAGS) $(OT_DEP_LZMA_CFLAGS) $(OT_DEP_ZLIB_CFLAGS) $(OT_DEP_OPENSSL_CFLAGS) \
Expand All @@ -173,6 +180,11 @@ libostree_1_la_CFLAGS += $(OT_DEP_LIBARCHIVE_CFLAGS)
libostree_1_la_LIBADD += $(OT_DEP_LIBARCHIVE_LIBS)
endif

if USE_AVAHI
libostree_1_la_CFLAGS += $(OT_DEP_AVAHI_CFLAGS)
libostree_1_la_LIBADD += $(OT_DEP_AVAHI_LIBS)
endif

if BUILDOPT_LIBSYSTEMD
libostree_1_la_CFLAGS += $(LIBSYSTEMD_CFLAGS)
libostree_1_la_LIBADD += $(LIBSYSTEMD_LIBS)
Expand Down
10 changes: 10 additions & 0 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ test_programs = tests/test-varint tests/test-ot-unix-utils tests/test-bsdiff tes
tests/test-basic-c tests/test-sysroot-c tests/test-pull-c tests/test-bloom \
tests/test-repo-finder-config tests/test-repo-finder-mount

if USE_AVAHI
test_programs += tests/test-repo-finder-avahi
endif

# An interactive tool
noinst_PROGRAMS += tests/test-rollsum-cli

Expand Down Expand Up @@ -216,6 +220,12 @@ tests_test_bloom_SOURCES = src/libostree/ostree-bloom.c tests/test-bloom.c
tests_test_bloom_CFLAGS = $(TESTS_CFLAGS)
tests_test_bloom_LDADD = $(TESTS_LDADD)

if USE_AVAHI
tests_test_repo_finder_avahi_SOURCES = src/libostree/ostree-bloom.c src/libostree/ostree-repo-finder-avahi.c tests/test-repo-finder-avahi.c
tests_test_repo_finder_avahi_CFLAGS = $(TESTS_CFLAGS) $(OT_INTERNAL_SOUP_CFLAGS)
tests_test_repo_finder_avahi_LDADD = $(TESTS_LDADD) $(OT_INTERNAL_SOUP_LIBS)
endif

tests_test_repo_finder_config_SOURCES = tests/test-repo-finder-config.c
tests_test_repo_finder_config_CFLAGS = $(TESTS_CFLAGS)
tests_test_repo_finder_config_LDADD = $(TESTS_LDADD)
Expand Down
10 changes: 10 additions & 0 deletions apidoc/ostree-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,16 @@ ostree_repo_finder_result_compare
ostree_repo_finder_get_type
</SECTION>

<SECTION>
<FILE>ostree-repo-finder-avahi</FILE>
OstreeRepoFinderAvahi
ostree_repo_finder_avahi_new
ostree_repo_finder_avahi_start
ostree_repo_finder_avahi_stop
<SUBSECTION Standard>
ostree_repo_finder_avahi_get_type
</SECTION>

<SECTION>
<FILE>ostree-repo-finder-config</FILE>
OstreeRepoFinderConfig
Expand Down
25 changes: 25 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,31 @@ if test x$with_openssl != xno; then OSTREE_FEATURES="$OSTREE_FEATURES openssl";
AM_CONDITIONAL(USE_OPENSSL, test $with_openssl != no)
dnl end openssl

dnl Avahi dependency for finding repos
AVAHI_DEPENDENCY="avahi-client >= 0.6.31 avahi-glib >= 0.6.31"

AC_ARG_WITH(avahi,
AS_HELP_STRING([--without-avahi], [Do not use Avahi]),
:, with_avahi=maybe)

AS_IF([ test x$with_avahi != xno ], [
AC_MSG_CHECKING([for $AVAHI_DEPENDENCY])
PKG_CHECK_EXISTS($AVAHI_DEPENDENCY, have_avahi=yes, have_avahi=no)
AC_MSG_RESULT([$have_avahi])
AS_IF([ test x$have_avahi = xno && test x$with_avahi != xmaybe ], [
AC_MSG_ERROR([Avahi is enabled but could not be found])
])
AS_IF([ test x$have_avahi = xyes], [
AC_DEFINE([HAVE_AVAHI], 1, [Define if we have avahi-client.pc and avahi-glib.pc])
PKG_CHECK_MODULES(OT_DEP_AVAHI, $AVAHI_DEPENDENCY)
with_avahi=yes
], [
with_avahi=no
])
], [ with_avahi=no ])
if test x$with_avahi != xno; then OSTREE_FEATURES="$OSTREE_FEATURES avahi"; fi
AM_CONDITIONAL(USE_AVAHI, test $with_avahi != no)

dnl This is what is in RHEL7.2 right now, picking it arbitrarily
LIBMOUNT_DEPENDENCY="mount >= 2.23.0"

Expand Down
5 changes: 5 additions & 0 deletions src/libostree/libostree.sym
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ global:
ostree_remote_unref;
ostree_repo_find_remotes_async;
ostree_repo_find_remotes_finish;
/* TODO: What if we compile without Avahi? */
ostree_repo_finder_avahi_get_type;
ostree_repo_finder_avahi_new;
ostree_repo_finder_avahi_start;
ostree_repo_finder_avahi_stop;
ostree_repo_finder_config_get_type;
ostree_repo_finder_config_new;
ostree_repo_finder_get_type;
Expand Down
39 changes: 39 additions & 0 deletions src/libostree/ostree-repo-finder-avahi-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
*
* Copyright © 2017 Endless Mobile, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors:
* - Philip Withnall <[email protected]>
*/

#pragma once

#include <avahi-common/strlst.h>
#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>

G_BEGIN_DECLS

GHashTable *_ostree_txt_records_parse (AvahiStringList *txt);

GVariant *_ostree_txt_records_lookup_variant (GHashTable *attributes,
const gchar *key,
const GVariantType *value_type);

G_END_DECLS
Loading

0 comments on commit c8ab171

Please sign in to comment.