Skip to content

Commit

Permalink
libostree: Add support for finding remote URIs by ref name
Browse files Browse the repository at this point in the history
WIP work to add an OstreeRepoFinder interface and implementations which
find remote URIs by ref names, which we consider to be globally unique.
This is an API preview. It compiles, but has not been tested beyond
that, and the implementation is unfinished in various places, and
unpolished everywhere else. It is intended as a strawman for the
proposed API.

The new API is used in a new ostree_repo_find_updates() function, which
resolves a list of ref names to update into a set of remote URIs to pull
them from, which can be treated as mirrors.

A major feature this adds is the ability to automatically pull from
other machines on the local network (as long as they are running an
OSTree server and appropriate Avahi DNS-SD adverts, support for which
will be added separately). Similarly, it adds the ability to pull from
removable file systems without needing further configuration.

This bumps the GLib dependency to 2.50, and adds an optional dependency
on Avahi.

Signed-off-by: Philip Withnall <[email protected]>
  • Loading branch information
pwithnall committed Apr 11, 2017
1 parent 94c47cd commit aec1f6c
Show file tree
Hide file tree
Showing 27 changed files with 5,112 additions and 5 deletions.
20 changes: 20 additions & 0 deletions Makefile-libostree.am
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ CLEANFILES += $(BUILT_SOURCES)

libostree_1_la_SOURCES = \
src/libostree/ostree-async-progress.c \
src/libostree/ostree-bloom.c \
src/libostree/ostree-bloom-private.h \
src/libostree/ostree-cmdprivate.h \
src/libostree/ostree-cmdprivate.c \
src/libostree/ostree-core-private.h \
Expand Down Expand Up @@ -106,6 +108,12 @@ libostree_1_la_SOURCES = \
src/libostree/ostree-repo-file.c \
src/libostree/ostree-repo-file-enumerator.c \
src/libostree/ostree-repo-file-enumerator.h \
src/libostree/ostree-repo-finder.c \
src/libostree/ostree-repo-finder.h \
src/libostree/ostree-repo-finder-config.c \
src/libostree/ostree-repo-finder-config.h \
src/libostree/ostree-repo-finder-mount.c \
src/libostree/ostree-repo-finder-mount.h \
src/libostree/ostree-sepolicy.c \
src/libostree/ostree-sysroot-private.h \
src/libostree/ostree-sysroot.c \
Expand Down Expand Up @@ -145,6 +153,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 @@ -162,6 +177,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
27 changes: 25 additions & 2 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ endif
test_programs = tests/test-varint tests/test-ot-unix-utils tests/test-bsdiff tests/test-mutable-tree \
tests/test-keyfile-utils tests/test-ot-opt-utils tests/test-ot-tool-util \
tests/test-gpg-verify-result tests/test-checksum tests/test-lzma tests/test-rollsum \
tests/test-basic-c tests/test-sysroot-c tests/test-pull-c
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 All @@ -192,7 +197,7 @@ common_tests_cflags = $(ostree_bin_shared_cflags) $(OT_INTERNAL_GIO_UNIX_CFLAGS)
common_tests_ldadd = $(ostree_bin_shared_ldadd) $(OT_INTERNAL_GIO_UNIX_LIBS)

noinst_LTLIBRARIES += libostreetest.la
libostreetest_la_SOURCES = tests/libostreetest.c
libostreetest_la_SOURCES = tests/libostreetest.c tests/test-mock-gio.c tests/test-mock-gio.h
libostreetest_la_CFLAGS = $(common_tests_cflags) -I $(srcdir)/tests
libostreetest_la_LIBADD = $(common_tests_ldadd)

Expand All @@ -207,6 +212,24 @@ tests_test_rollsum_SOURCES = src/libostree/ostree-rollsum.c tests/test-rollsum.c
tests_test_rollsum_CFLAGS = $(TESTS_CFLAGS) $(OT_DEP_ZLIB_CFLAGS)
tests_test_rollsum_LDADD = $(bupsplitpath) $(TESTS_LDADD) $(OT_DEP_ZLIB_LIBS)

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)

tests_test_repo_finder_mount_SOURCES = tests/test-repo-finder-mount.c
tests_test_repo_finder_mount_CFLAGS = $(TESTS_CFLAGS)
tests_test_repo_finder_mount_LDADD = $(TESTS_LDADD)

tests_test_mutable_tree_CFLAGS = $(TESTS_CFLAGS)
tests_test_mutable_tree_LDADD = $(TESTS_LDADD)

Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ AM_CPPFLAGS += -DDATADIR='"$(datadir)"' -DLIBEXECDIR='"$(libexecdir)"' \
-DOSTREE_COMPILATION \
-DG_LOG_DOMAIN=\"OSTree\" \
-DOSTREE_GITREV='"$(OSTREE_GITREV)"' \
-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_40 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_40 \
-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_50 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_50 \
-DSOUP_VERSION_MIN_REQUIRED=SOUP_VERSION_2_40 -DSOUP_VERSION_MAX_ALLOWED=SOUP_VERSION_2_48
AM_CFLAGS += -std=gnu99 $(WARN_CFLAGS)
AM_DISTCHECK_CONFIGURE_FLAGS += \
Expand Down
43 changes: 43 additions & 0 deletions apidoc/ostree-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,11 @@ ostree_repo_prune
ostree_repo_prune_static_deltas
ostree_repo_prune_from_reachable
OstreeRepoPullFlags
ostree_repo_find_remotes
ostree_repo_pull
ostree_repo_pull_one_dir
ostree_repo_pull_with_options
ostree_repo_pull_from_remotes
ostree_repo_pull_default_console_progress_changed
ostree_repo_sign_commit
ostree_repo_append_gpg_signature
Expand Down Expand Up @@ -422,6 +424,47 @@ OstreeRepoFileClass
ostree_repo_file_get_type
</SECTION>

<SECTION>
<FILE>ostree-repo-finder</FILE>
OstreeRepoFinder
ostree_repo_finder_resolve_async
ostree_repo_finder_resolve_finish
ostree_repo_finder_resolve_all_async
ostree_repo_finder_resolve_all_finish
OstreeRepoFinderResult
ostree_repo_finder_result_new
ostree_repo_finder_result_free
ostree_repo_finder_result_compare
<SUBSECTION Standard>
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
ostree_repo_finder_config_new
<SUBSECTION Standard>
ostree_repo_finder_config_get_type
</SECTION>

<SECTION>
<FILE>ostree-repo-finder-mount</FILE>
OstreeRepoFinderMount
ostree_repo_finder_mount_new
<SUBSECTION Standard>
ostree_repo_finder_mount_get_type
</SECTION>

<SECTION>
<FILE>ostree-sepolicy</FILE>
OstreeSePolicy
Expand Down
27 changes: 26 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ AM_PATH_GLIB_2_0(,,AC_MSG_ERROR([GLib not found]))
dnl When bumping the gio-unix-2.0 dependency (or glib-2.0 in general),
dnl remember to bump GLIB_VERSION_MIN_REQUIRED and
dnl GLIB_VERSION_MAX_ALLOWED in Makefile.am
GIO_DEPENDENCY="gio-unix-2.0 >= 2.40.0"
GIO_DEPENDENCY="gio-unix-2.0 >= 2.50.0"
PKG_CHECK_MODULES(OT_DEP_GIO_UNIX, $GIO_DEPENDENCY)

dnl 5.1.0 is an arbitrary version here
Expand Down Expand Up @@ -315,6 +315,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
19 changes: 19 additions & 0 deletions src/libostree/libostree.sym
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,25 @@ LIBOSTREE_2017.4 {
global:
ostree_check_version;
ostree_diff_dirs_with_options;
ostree_repo_find_remotes;
/* 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;
ostree_repo_finder_mount_get_type;
ostree_repo_finder_mount_new;
ostree_repo_finder_resolve_async;
ostree_repo_finder_resolve_all_async;
ostree_repo_finder_resolve_all_finish;
ostree_repo_finder_resolve_finish;
ostree_repo_finder_result_compare;
ostree_repo_finder_result_free;
ostree_repo_finder_result_new;
ostree_repo_pull_from_remotes;
} LIBOSTREE_2017.3;

/* Stub section for the stable release *after* this development one; don't
Expand Down
78 changes: 78 additions & 0 deletions src/libostree/ostree-bloom-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* -*- 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 <gio/gio.h>
#include <glib.h>
#include <glib-object.h>

G_BEGIN_DECLS

/* TODO: Docs */
typedef struct _OstreeBloom OstreeBloom;

/* TODO: Docs */
typedef guint64 (*OstreeBloomHashFunc) (gconstpointer element,
guint8 k);

#define OSTREE_TYPE_BLOOM (ostree_bloom_get_type ())

G_GNUC_INTERNAL
GType ostree_bloom_get_type (void);

G_GNUC_INTERNAL
OstreeBloom *ostree_bloom_new (gsize n_bytes,
guint8 k,
OstreeBloomHashFunc hash);

G_GNUC_INTERNAL
OstreeBloom *ostree_bloom_new_from_bytes (GBytes *bytes,
guint8 k,
OstreeBloomHashFunc hash);

G_GNUC_INTERNAL
OstreeBloom *ostree_bloom_ref (OstreeBloom *bloom);
G_GNUC_INTERNAL
void ostree_bloom_unref (OstreeBloom *bloom);

G_DEFINE_AUTOPTR_CLEANUP_FUNC (OstreeBloom, ostree_bloom_unref)

G_GNUC_INTERNAL
gboolean ostree_bloom_maybe_contains (OstreeBloom *bloom,
gconstpointer element);

G_GNUC_INTERNAL
GBytes *ostree_bloom_seal (OstreeBloom *bloom);

G_GNUC_INTERNAL
void ostree_bloom_add_element (OstreeBloom *bloom,
gconstpointer element);

G_GNUC_INTERNAL
guint64 ostree_str_bloom_hash (gconstpointer element,
guint8 k);

/* TODO: Building functions */

G_END_DECLS
Loading

0 comments on commit aec1f6c

Please sign in to comment.