[geary/wip/conversation-polish: 21/22] Handle connectivity check errors for local remote endpoints better



commit 7cee7d01d17462cb4335d3953c43e697174e6d6b
Author: Michael Gratton <mike vee net>
Date:   Thu Jan 24 22:21:41 2019 +1100

    Handle connectivity check errors for local remote endpoints better

 src/engine/util/util-connectivity-manager.vala | 35 ++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/src/engine/util/util-connectivity-manager.vala b/src/engine/util/util-connectivity-manager.vala
index fdf61e0d..72cadd77 100644
--- a/src/engine/util/util-connectivity-manager.vala
+++ b/src/engine/util/util-connectivity-manager.vala
@@ -137,18 +137,21 @@ public class Geary.ConnectivityManager : BaseObject {
                       endpoint);
                                is_reachable = true;
             } else {
-                // The monitor throw an error, but only notify if it
+                // The monitor threw an error, but only notify if it
                 // looks like we *should* be able to connect
-                // (i.e. have full network connectivity), so we don't
-                // needlessly hassle the user with expected error messages.
+                // (i.e. have full network connectivity, or are
+                // connecting to a local service), so we don't
+                // needlessly hassle the user with expected error
+                // messages.
                 GLib.NetworkConnectivity connectivity = this.monitor.connectivity;
-                if (connectivity == GLib.NetworkConnectivity.FULL) {
+                if (connectivity == FULL ||
+                    (connectivity == LOCAL && is_local_address())) {
                     debug("Error checking %s [%s] reachable, treating unreachable: %s",
                           endpoint, connectivity.to_string(), err.message);
                     set_invalid();
                     remote_error_reported(err);
                 } else {
-                    debug("Error checking %s [%s] reachable, retrying: %s",
+                    debug("Error checking %s [%s] reachable, treating offline: %s",
                           endpoint, connectivity.to_string(), err.message);
                 }
             }
@@ -235,4 +238,26 @@ public class Geary.ConnectivityManager : BaseObject {
         }
     }
 
+    private bool is_local_address() {
+        GLib.NetworkAddress? name = this.remote as GLib.NetworkAddress;
+        if (name != null) {
+            return (
+                name.hostname == "localhost" ||
+                name.hostname.has_prefix("localhost.") ||
+                name.hostname == "127.0.0.1" ||
+                name.hostname == "::1"
+            );
+        }
+
+        GLib.InetSocketAddress? inet = this.remote as GLib.InetSocketAddress;
+        if (inet != null) {
+            return (
+                inet.address.is_loopback ||
+                inet.address.is_link_local
+            );
+        }
+
+        return false;
+    }
+
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]