deja-dup-team team mailing list archive
-
deja-dup-team team
-
Mailing list archive
-
Message #00413
[Merge] lp:~mterry/deja-dup/network-monitor into lp:deja-dup
Michael Terry has proposed merging lp:~mterry/deja-dup/network-monitor into lp:deja-dup.
Requested reviews:
Ken VanDine (ken-vandine)
For more details, see:
https://code.launchpad.net/~mterry/deja-dup/network-monitor/+merge/88240
Uses new GNetworkMonitor support in latest gio if available. The advantages are less code (no more talking to connman and networkmanager for us), more reliable (talks to netlink directly), and we can now easily ask if we can reach a given host which buys us better support for people that back up to local hostnames that aren't always available.
Note the new test is just a manual program tor run. It isn't part of the normal suite because it's results depend on whether you're online.
--
https://code.launchpad.net/~mterry/deja-dup/network-monitor/+merge/88240
Your team Déjà Dup Developers is subscribed to branch lp:deja-dup.
=== modified file 'common/Backend.vala'
--- common/Backend.vala 2011-07-14 20:25:19 +0000
+++ common/Backend.vala 2012-01-11 17:35:34 +0000
@@ -34,7 +34,7 @@
public abstract string? get_location() throws Error;
public abstract string? get_location_pretty() throws Error; // short description for user
- public virtual bool is_ready(out string when) {when = null; return true;} // must be callable when nothing is mounted, nothing is prepared
+ public virtual async bool is_ready(out string when) {when = null; return true;} // must be callable when nothing is mounted, nothing is prepared
public virtual async void get_envp() throws Error {
envp_ready(true, new List<string>());
=== modified file 'common/BackendAuto.vala'
--- common/BackendAuto.vala 2011-06-28 15:48:17 +0000
+++ common/BackendAuto.vala 2012-01-11 17:35:34 +0000
@@ -35,7 +35,7 @@
return null;
}
- public override bool is_ready(out string when) {
+ public override async bool is_ready(out string when) {
when = null;
return false;
}
=== modified file 'common/BackendFile.vala'
--- common/BackendFile.vala 2011-09-13 18:34:42 +0000
+++ common/BackendFile.vala 2012-01-11 17:35:34 +0000
@@ -109,7 +109,7 @@
return true; // default to yes?
}
- public override bool is_ready(out string when) {
+ public override async bool is_ready(out string when) {
when = null;
try {
var file = get_file_from_settings();
@@ -129,7 +129,7 @@
return true;
else {
when = _("Backup will begin when a network connection becomes available.");
- return Network.get().connected;
+ return yield Network.get().can_reach (file.get_uri ());
}
}
catch (Error e) {
=== modified file 'common/BackendRackspace.vala'
--- common/BackendRackspace.vala 2011-08-18 19:35:39 +0000
+++ common/BackendRackspace.vala 2012-01-11 17:35:34 +0000
@@ -45,9 +45,9 @@
return new ThemedIcon("deja-dup-cloud");
}
- public override bool is_ready(out string when) {
+ public override async bool is_ready(out string when) {
when = _("Backup will begin when a network connection becomes available.");
- return Network.get().connected;
+ return yield Network.get().can_reach ("http://%s/".printf(RACKSPACE_SERVER));
}
public override string? get_location() throws Error
=== modified file 'common/BackendS3.vala'
--- common/BackendS3.vala 2011-08-18 19:35:39 +0000
+++ common/BackendS3.vala 2012-01-11 17:35:34 +0000
@@ -55,9 +55,9 @@
return new ThemedIcon("deja-dup-cloud");
}
- public override bool is_ready(out string when) {
+ public override async bool is_ready(out string when) {
when = _("Backup will begin when a network connection becomes available.");
- return Network.get().connected;
+ return yield Network.get().can_reach ("http://%s/".printf(S3_SERVER));
}
public override string? get_location() throws Error
=== modified file 'common/BackendU1.vala'
--- common/BackendU1.vala 2011-09-26 05:15:03 +0000
+++ common/BackendU1.vala 2012-01-11 17:35:34 +0000
@@ -146,9 +146,9 @@
return new ThemedIcon.from_names({"ubuntuone", "ubuntuone-installer", "deja-dup-cloud"});
}
- public override bool is_ready(out string when) {
+ public override async bool is_ready(out string when) {
when = _("Backup will begin when a network connection becomes available.");
- return Network.get().connected;
+ return yield Network.get().can_reach ("https://one.ubuntu.com/");
}
public override string? get_location() throws Error
=== modified file 'common/Makefile.am'
--- common/Makefile.am 2011-12-22 17:45:30 +0000
+++ common/Makefile.am 2012-01-11 17:35:34 +0000
@@ -66,6 +66,7 @@
--library=libcommon \
-H common.h \
--vapidir=$(top_srcdir)/vapi \
+ $(NETWORKMONITOR_VALAFLAGS) \
--pkg gio-2.0 \
--pkg gio-unix-2.0 \
--pkg gnome-keyring-1 \
=== modified file 'common/Network.vala'
--- common/Network.vala 2011-07-14 20:25:19 +0000
+++ common/Network.vala 2012-01-11 17:35:34 +0000
@@ -21,6 +21,59 @@
namespace DejaDup {
+#if HAVE_NETWORKMONITOR
+
+public class Network : Object
+{
+ public bool connected {get; set; default = true;}
+
+ public new static Network get() {
+ if (singleton == null)
+ singleton = new Network();
+ return singleton;
+ }
+
+ public async static void ensure_status()
+ {
+ var network = Network.get();
+ network.update_status();
+ }
+
+ public async bool can_reach(string url)
+ {
+ var mon = NetworkMonitor.get_default();
+ try {
+ var socket = NetworkAddress.parse_uri(url, 0);
+ return yield mon.can_reach_async(socket);
+ }
+ catch (Error e) {
+ warning("%s", e.message);
+ return false;
+ }
+ }
+
+ construct {
+ var mon = NetworkMonitor.get_default();
+ mon.network_changed.connect(handle_changed);
+ }
+
+ void handle_changed(bool available)
+ {
+ update_status();
+ }
+
+ void update_status()
+ {
+ var mon = NetworkMonitor.get_default();
+ if (mon.network_available != connected)
+ connected = mon.network_available;
+ }
+
+ static Network singleton;
+}
+
+#else
+
abstract class StatusProvider : Object
{
public enum Status {ONLINE, OFFLINE, UNKNOWN, UNINITIALIZED}
@@ -181,6 +234,11 @@
}
}
+ public async bool can_reach(string url)
+ {
+ return connected; // naively, assume yes if connected
+ }
+
static Network singleton;
List<StatusProvider> providers;
@@ -221,4 +279,6 @@
}
}
+#endif
+
} // end namespace
=== modified file 'configure.ac'
--- configure.ac 2011-12-02 16:11:35 +0000
+++ configure.ac 2012-01-11 17:35:34 +0000
@@ -38,6 +38,7 @@
LT_PREREQ([2.2.6])
LT_INIT
+PKG_PROG_PKG_CONFIG([0.24])
DEJA_PROG_VALAC([0.14.0])
# Sets up gettext.
@@ -76,35 +77,31 @@
gnome-keyring-1
gmodule-2.0 >= $GLIB_REQ_VER
libnotify >= $NOTIFY_REQ_VER)
-AC_SUBST(DUP_CFLAGS)
-AC_SUBST(DUP_LIBS)
PKG_CHECK_MODULES(PREF,
$GTK_MODULE >= $GTK_REQ_VER
gio-2.0 >= $GIO_REQ_VER)
-AC_SUBST(PREF_CFLAGS)
-AC_SUBST(PREF_LIBS)
PKG_CHECK_MODULES(COMMON,
gio-2.0 >= $GIO_REQ_VER
gio-unix-2.0 >= $GIO_REQ_VER
gnome-keyring-1
gmodule-2.0 >= $GLIB_REQ_VER)
-AC_SUBST(COMMON_CFLAGS)
-AC_SUBST(COMMON_LIBS)
PKG_CHECK_MODULES(WIDGETS,
gmodule-2.0 >= $GLIB_REQ_VER
$GTK_MODULE >= $GTK_REQ_VER
libnotify >= $NOTIFY_REQ_VER)
-AC_SUBST(WIDGETS_CFLAGS)
-AC_SUBST(WIDGETS_LIBS)
PKG_CHECK_MODULES(MONITOR,
gio-2.0 >= $GIO_REQ_VER
libnotify >= $NOTIFY_REQ_VER)
-AC_SUBST(MONITOR_CFLAGS)
-AC_SUBST(MONITOR_LIBS)
+
+AH_TEMPLATE([HAVE_NETWORKMONITOR], [whether NetworkMonitor is available in gio])
+PKG_CHECK_EXISTS(gio-2.0 >= 2.31.6,
+ [AC_DEFINE(HAVE_NETWORKMONITOR)
+ AC_SUBST(NETWORKMONITOR_VALAFLAGS, ["--pkg networkmonitor -D HAVE_NETWORKMONITOR"])],
+ [])
AC_ARG_WITH([extensiondir],
[AS_HELP_STRING([--with-extensiondir],
@@ -119,13 +116,11 @@
[with_ccpanel=check])
AS_IF([test "x$with_ccpanel" != xno],
[PKG_CHECK_MODULES(CCPANEL, libgnome-control-center,
- [AC_SUBST(CCPANEL_CFLAGS)
- AC_SUBST(CCPANEL_LIBS)]
- dnl Get control center extensions directory
+ [dnl Get control center extensions directory
AS_IF([test "x$with_extensiondir" != xno],
[CCPANEL_DIR=`$PKG_CONFIG --variable=extensiondir libgnome-control-center`],
[CCPANEL_DIR="${PREFIX}/lib/control-center-1/panels"])
- AC_SUBST(CCPANEL_DIR),
+ AC_SUBST(CCPANEL_DIR)],
[if test "x$with_ccpanel" != xcheck; then
AC_MSG_FAILURE(
[--with-ccpanel was given, but test for libgnome-control-center failed])
@@ -143,13 +138,11 @@
AS_IF([test "x$with_nautilus" != xno],
[PKG_CHECK_MODULES(NAUTILUS, libnautilus-extension
glib-2.0 >= $GLIB_REQ_VER,
- [AC_SUBST(NAUTILUS_CFLAGS)
- AC_SUBST(NAUTILUS_LIBS)]
- dnl Get nautilus extensions directory
+ [dnl Get nautilus extensions directory
AS_IF([test "x$with_extensiondir" != xno],
[NAUTILUS_EXTENSION_DIR=`$PKG_CONFIG --variable=extensiondir libnautilus-extension`],
[NAUTILUS_EXTENSION_DIR="${PREFIX}/lib/nautilus/extensions-3.0"])
- AC_SUBST(NAUTILUS_EXTENSION_DIR),
+ AC_SUBST(NAUTILUS_EXTENSION_DIR)],
[if test "x$with_nautilus" != xcheck; then
AC_MSG_FAILURE(
[--with-nautilus was given, but test for libnautilus-extension failed])
@@ -168,9 +161,7 @@
AS_IF([test "x$with_unity" != xno],
[PKG_CHECK_MODULES(UNITY, unity >= 3.4.2,
[AC_DEFINE(HAVE_UNITY)
- AC_SUBST(UNITY_VALAFLAGS, ["--pkg unity -D HAVE_UNITY"])
- AC_SUBST(UNITY_CFLAGS)
- AC_SUBST(UNITY_LIBS)],
+ AC_SUBST(UNITY_VALAFLAGS, ["--pkg unity -D HAVE_UNITY"])],
[if test "x$with_unity" != xcheck; then
AC_MSG_FAILURE(
[--with-unity was given, but test for unity failed])
=== modified file 'monitor/monitor.vala'
--- monitor/monitor.vala 2011-09-18 02:41:30 +0000
+++ monitor/monitor.vala 2012-01-11 17:35:34 +0000
@@ -76,14 +76,14 @@
reactive_check = false;
}
-static bool is_ready(out string when)
+static async bool is_ready(out string when)
{
if (DejaDup.in_testing_mode() && testing_delay) {
testing_delay = false;
when = "Testing";
return false;
}
- return DejaDup.Backend.get_default().is_ready(out when);
+ return yield DejaDup.Backend.get_default().is_ready(out when);
}
static bool handle_options(out int status)
@@ -128,16 +128,16 @@
}
}
-static bool kickoff()
+static async void kickoff()
{
TimeSpan wait_time;
if (!time_until_next_run(out wait_time))
- return false;
+ return;
if (wait_time > 0) {
// Huh? Shouldn't have been called now.
prepare_next_run();
- return false;
+ return;
}
if (!reactive_check) {
@@ -149,19 +149,20 @@
}
string when;
- if (!is_ready(out when)) {
+ bool ready = yield is_ready(out when);
+ if (!ready) {
debug("Postponing the backup.");
if (!reactive_check && when != null)
notify_delay(_("Scheduled backup delayed"), when);
- return false;
+ return;
}
if (note != null) {
try {
note.close(); // no need to continue talking about the delay
}
- catch (Error e) {
- warning("%s\n", e.message);
+ catch (Error e2) {
+ warning("%s\n", e2.message);
}
note = null;
}
@@ -210,8 +211,6 @@
}
else
debug("Not rerunning deja-dup, already doing so.");
-
- return false;
}
static bool time_until_next_run(out TimeSpan time)
@@ -237,7 +236,10 @@
TimeSpan secs = wait_time / TimeSpan.SECOND + 1;
if (wait_time > 0 && secs > 0) {
debug("Waiting %ld seconds until next backup.", (long)secs);
- timeout_id = Timeout.add_seconds((uint)secs, kickoff);
+ timeout_id = Timeout.add_seconds((uint)secs, () => {
+ kickoff();
+ return false;
+ });
}
else {
debug("Late by %ld seconds. Backing up now.", (long)(secs * -1));
=== modified file 'tests/common/Makefile.am'
--- tests/common/Makefile.am 2011-12-23 05:21:48 +0000
+++ tests/common/Makefile.am 2012-01-11 17:35:34 +0000
@@ -16,18 +16,19 @@
# You should have received a copy of the GNU General Public License
# along with Déjà Dup. If not, see <http://www.gnu.org/licenses/>.
-noinst_PROGRAMS = common
-
-check:
- gtester $(noinst_PROGRAMS)
-
-common_CFLAGS = \
+noinst_PROGRAMS = \
+ common \
+ network
+
+TESTS = \
+ common
+
+AM_CFLAGS = \
-I$(top_srcdir)/common \
- $(MONITOR_CFLAGS) \
- $(DEBUG_CFLAGS)
+ $(DUP_CFLAGS)
-common_LDADD = \
- $(MONITOR_LIBS) \
+LDADD = \
+ $(DUP_LIBS) \
@INTLLIBS@ \
$(top_builddir)/common/libcommon.la
@@ -37,17 +38,28 @@
common_SOURCES = \
$(common_VALASOURCES)
+network_VALASOURCES = \
+ network.vala
+
+network_SOURCES = \
+ $(network_VALASOURCES)
+
AM_VALAFLAGS = \
--vapidir $(top_srcdir)/common \
--vapidir $(top_srcdir)/vapi \
+ $(NETWORKMONITOR_VALAFLAGS) \
--pkg config \
--pkg gio-2.0 \
+ --pkg gtk+-3.0 \
--pkg posix \
--pkg libcommon
common_vala.stamp: $(top_srcdir)/config.h
+network_vala.stamp: $(top_srcdir)/config.h
dist-hook:
cd $(distdir) && rm $(common_VALASOURCES:.vala=.c) \
common_vala.stamp
+ cd $(distdir) && rm $(network_VALASOURCES:.vala=.c) \
+ network_vala.stamp
=== added file 'tests/common/network.vala'
--- tests/common/network.vala 1970-01-01 00:00:00 +0000
+++ tests/common/network.vala 2012-01-11 17:35:34 +0000
@@ -0,0 +1,40 @@
+// -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
+/*
+ This file is part of Déjà Dup.
+ For copyright information, see AUTHORS.
+
+ Déjà Dup is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Déjà Dup 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Déjà Dup. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using GLib;
+
+async void check_status()
+{
+ yield DejaDup.Network.ensure_status();
+ var nw = DejaDup.Network.get();
+ var can_reach = yield nw.can_reach("https://one.ubuntu.com/");
+ var can_reach2 = yield nw.can_reach("http://nowhere.local/");
+ print("Connected: %d\n", (int)nw.connected);
+ print("Can reach U1: %d\n", (int)can_reach);
+ print("Can reach local server: %d\n", (int)can_reach2);
+ Gtk.main_quit();
+}
+
+int main(string[] args)
+{
+ Gtk.init(ref args);
+ check_status();
+ Gtk.main();
+ return 0;
+}
=== added file 'vapi/networkmonitor.vapi'
--- vapi/networkmonitor.vapi 1970-01-01 00:00:00 +0000
+++ vapi/networkmonitor.vapi 2012-01-11 17:35:34 +0000
@@ -0,0 +1,37 @@
+/* -*- Mode: Vala; indent-tabs-mode: t; tab-width: 2 -*- */
+/*
+ This file is part of Déjà Dup.
+ For copyright information, see AUTHORS.
+
+ Déjà Dup is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Déjà Dup 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Déjà Dup. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * vala-0.14 doesn't have vapi bindings for NetworkMonitor yet.
+ * So here we add it ourselves.
+ */
+
+[CCode (cprefix = "G", gir_namespace = "Gio", gir_version = "2.0", lower_case_cprefix = "g_")]
+namespace GLib {
+ [CCode (cheader_filename = "gio/gio.h", cname = "GNetworkMonitor")]
+ public class NetworkMonitor : GLib.Object {
+ [CCode (has_construct_function = false)]
+ protected NetworkMonitor ();
+ public static unowned NetworkMonitor get_default ();
+ public bool can_reach (GLib.SocketConnectable connectable, GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public async bool can_reach_async (GLib.SocketConnectable connectable, GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public bool network_available { get; }
+ public virtual signal void network_changed (bool available);
+ }
+}
Follow ups