Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH 0/4] RE: Propose patch for continuous online check for
      connected services ([email protected])
   2. [PATCH 1/4] gweb: added timeout to socket connections
      ([email protected])
   3. [PATCH 2/4] service: perform continuous online checks
      ([email protected])
   4. [PATCH 3/4] service: Added a compile config for online check
      ([email protected])
   5. [PATCH 4/4] doc: updated state diagram for services
      ([email protected])


----------------------------------------------------------------------

Message: 1
Date: Fri, 27 Sep 2019 15:44:44 +0300
From: [email protected]
To: [email protected]
Cc: Aleksandar Mitev <[email protected]>
Subject: [PATCH 0/4] RE: Propose patch for continuous online check for
        connected services
Message-ID: <[email protected]>

From: Aleksandar Mitev <[email protected]>

Hi Daniel,

Following your advice on every commit, I resubmit the patches again. I hope
I've got everything sorted out.
I agree with the name change, indeed "perpetual" sounds more epic but does
not have the necessary semantics.

The state diagram in the doc section is updated as well.

Best,
Aleksandar

Aleksandar Mitev (4):
  gweb: added timeout to socket connections
  service: perform continuous online checks
  service: Added a compile config for online check
  doc: updated state diagram for services

 README               | 10 ++++++
 configure.ac         |  6 ++++
 doc/overview-api.txt | 25 +++++++++-----
 gweb/gweb.c          | 27 +++++++++++++++
 src/service.c        | 78 +++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 133 insertions(+), 13 deletions(-)

-- 
2.17.1



------------------------------

Message: 2
Date: Fri, 27 Sep 2019 15:44:45 +0300
From: [email protected]
To: [email protected]
Cc: Aleksandar Mitev <[email protected]>
Subject: [PATCH 1/4] gweb: added timeout to socket connections
Message-ID: <[email protected]>

From: Aleksandar Mitev <[email protected]>

By default, sockets timeout after the system defined time which is
too much all the timers in connman.
This patch helps make online checks in a deterministic fashion.

SOCKET_TIMEOUT controls the amount of time spent in waiting for
the request to complete.
---
 gweb/gweb.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/gweb/gweb.c b/gweb/gweb.c
index 393afe0a..ea820bd7 100644
--- a/gweb/gweb.c
+++ b/gweb/gweb.c
@@ -44,6 +44,7 @@
 #include "gweb.h"
 
 #define DEFAULT_BUFFER_SIZE  2048
+#define SOCKET_TIMEOUT 20 /* in seconds */
 
 #define SESSION_FLAG_USE_TLS   (1 << 0)
 
@@ -77,6 +78,7 @@ struct web_session {
        GIOChannel *transport_channel;
        guint transport_watch;
        guint send_watch;
+       guint timeout_timer;
 
        guint resolv_action;
        guint address_action;
@@ -164,6 +166,8 @@ static void free_session(struct web_session *session)
 
        web = session->web;
 
+       debug(web, "freeing session %p", session);
+
        if (session->address_action > 0)
                g_source_remove(session->address_action);
 
@@ -176,6 +180,9 @@ static void free_session(struct web_session *session)
        if (session->send_watch > 0)
                g_source_remove(session->send_watch);
 
+       if (session->timeout_timer > 0)
+               g_source_remove(session->timeout_timer);
+
        if (session->transport_channel)
                g_io_channel_unref(session->transport_channel);
 
@@ -1032,6 +1039,22 @@ static inline int bind_socket(int sk, int index, int 
family)
        return err;
 }
 
+static gboolean socket_timeout_handler(gpointer user_data)
+{
+       struct web_session *session = user_data;
+       int fd;
+
+       if (session->transport_channel) {
+               debug(session->web, "No response, closing the socket");
+               fd = g_io_channel_unix_get_fd(session->transport_channel);
+               g_io_channel_shutdown(session->transport_channel, TRUE, NULL);
+               close(fd);
+       }
+
+       session->timeout_timer = 0;
+       return FALSE;
+}
+
 static int connect_session_transport(struct web_session *session)
 {
        GIOFlags flags;
@@ -1090,6 +1113,10 @@ static int connect_session_transport(struct web_session 
*session)
                                G_IO_OUT | G_IO_HUP | G_IO_NVAL | G_IO_ERR,
                                                send_data, session);
 
+       debug(session->web, "Setting timeout to the socket to %ds", 
SOCKET_TIMEOUT);
+       session->timeout_timer = g_timeout_add_seconds(
+                               SOCKET_TIMEOUT, socket_timeout_handler, 
session);
+
        return 0;
 }
 
-- 
2.17.1



------------------------------

Message: 3
Date: Fri, 27 Sep 2019 15:44:46 +0300
From: [email protected]
To: [email protected]
Cc: Aleksandar Mitev <[email protected]>
Subject: [PATCH 2/4] service: perform continuous online checks
Message-ID: <[email protected]>

From: Aleksandar Mitev <[email protected]>

The feature activates when online state is reached and performs
regular checks whether online state is still maintained by the
services (default every 5 minutes). In the case then the
online check fails the serice state is downgrated to READY
to give the chance for a switchover to another service.
---
 src/service.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 69 insertions(+), 5 deletions(-)

diff --git a/src/service.c b/src/service.c
index 3202f26c..36a1911b 100644
--- a/src/service.c
+++ b/src/service.c
@@ -38,6 +38,7 @@
 #include "connman.h"
 
 #define CONNECT_TIMEOUT                120
+#define ONLINE_CHECK_REGULAR_INTERVAL 300 /* in seconds */
 
 static DBusConnection *connection = NULL;
 
@@ -3440,17 +3441,23 @@ int __connman_service_reset_ipconfig(struct 
connman_service *service,
 #define ONLINE_CHECK_INITIAL_INTERVAL 1
 #define ONLINE_CHECK_MAX_INTERVAL 12
 
-void __connman_service_wispr_start(struct connman_service *service,
+static void reset_online_recheck_interval(struct connman_service *service,
                                        enum connman_ipconfig_type type)
 {
-       DBG("service %p type %s", service, 
__connman_ipconfig_type2string(type));
-
        if (type == CONNMAN_IPCONFIG_TYPE_IPV4)
                service->online_check_interval_ipv4 =
                                        ONLINE_CHECK_INITIAL_INTERVAL;
        else
                service->online_check_interval_ipv6 =
                                        ONLINE_CHECK_INITIAL_INTERVAL;
+}
+
+void __connman_service_wispr_start(struct connman_service *service,
+                                       enum connman_ipconfig_type type)
+{
+       DBG("service %p type %s", service, 
__connman_ipconfig_type2string(type));
+
+       reset_online_recheck_interval(service, type);
 
        __connman_wispr_start(service, type);
 }
@@ -6039,18 +6046,58 @@ static gboolean redo_wispr_ipv6(gpointer user_data)
        return FALSE;
 }
 
+static int start_periodic_online_check(struct connman_service *service,
+                                       enum connman_ipconfig_type type)
+{
+       GSourceFunc redo_func;
+       guint retry_interval = ONLINE_CHECK_REGULAR_INTERVAL;
+
+       if (service->online_timeout != 0)
+               return 0;
+
+       if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
+               redo_func = redo_wispr_ipv4;
+       } else {
+               redo_func = redo_wispr_ipv6;
+       }
+       reset_online_recheck_interval(service, type);
+
+       DBG("service %p (%s) will be rechecked for internet connectivity in 
%ds",
+               service, service ? service->identifier : NULL, retry_interval);
+
+       service->online_timeout =
+               g_timeout_add_seconds(retry_interval, redo_func, 
connman_service_ref(service));
+
+       return 0;
+}
+
+static gboolean downgrade_state_handler(gpointer user_data)
+{
+       struct connman_service *service = user_data;
+
+       connman_warn("Downgrading service %s for online check did not pass",
+               service ? service->identifier : NULL);
+
+       downgrade_state(service);
+
+       return FALSE;
+}
+
 int __connman_service_online_check_failed(struct connman_service *service,
                                        enum connman_ipconfig_type type)
 {
        GSourceFunc redo_func;
        int *interval;
+       enum connman_service_state curr_state;
 
        if (type == CONNMAN_IPCONFIG_TYPE_IPV4) {
                interval = &service->online_check_interval_ipv4;
                redo_func = redo_wispr_ipv4;
+               curr_state = service->state_ipv4;
        } else {
                interval = &service->online_check_interval_ipv6;
                redo_func = redo_wispr_ipv6;
+               curr_state = service->state_ipv6;
        }
 
        DBG("service %p type %s interval %d", service,
@@ -6059,11 +6106,18 @@ int __connman_service_online_check_failed(struct 
connman_service *service,
        service->online_timeout = g_timeout_add_seconds(*interval * *interval,
                                redo_func, connman_service_ref(service));
 
-       /* Increment the interval for the next time, set a maximum timeout of
+       /*
+        * Increment the interval for the next time, set a maximum timeout of
         * ONLINE_CHECK_MAX_INTERVAL * ONLINE_CHECK_MAX_INTERVAL seconds.
         */
        if (*interval < ONLINE_CHECK_MAX_INTERVAL)
                (*interval)++;
+       else {
+               if(curr_state == CONNMAN_SERVICE_STATE_ONLINE) {
+                       g_idle_add(downgrade_state_handler, service);
+                       return 0;
+               }
+       }
 
        return EAGAIN;
 }
@@ -6131,8 +6185,17 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
        }
 
        /* Any change? */
-       if (old_state == new_state)
+       if (old_state == new_state) {
+               /*
+                * continuous online check requires restart of the check
+                * at regular intervals
+                */
+               if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
+                       start_periodic_online_check(service, type);
+               }
+
                return -EALREADY;
+       }
 
        DBG("service %p (%s) old state %d (%s) new state %d (%s) type %d (%s)",
                service, service ? service->identifier : NULL,
@@ -6161,6 +6224,7 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
                set_mdns(service, service->mdns_config);
                break;
        case CONNMAN_SERVICE_STATE_ONLINE:
+               start_periodic_online_check(service, type);
                break;
        case CONNMAN_SERVICE_STATE_DISCONNECT:
                if (service->state == CONNMAN_SERVICE_STATE_IDLE)
-- 
2.17.1



------------------------------

Message: 4
Date: Fri, 27 Sep 2019 15:44:47 +0300
From: [email protected]
To: [email protected]
Cc: Aleksandar Mitev <[email protected]>
Subject: [PATCH 3/4] service: Added a compile config for online check
Message-ID: <[email protected]>

From: Aleksandar Mitev <[email protected]>

New flag is
    --enable-continuous-online-check
and is disabled by default, leaving the original behaviour
in place. Even if enabled the continuous check relies on:
    EnableOnlineCheck = true
Otherwise it will have no effect.
---
 README        | 10 ++++++++++
 configure.ac  |  6 ++++++
 src/service.c |  4 ++++
 3 files changed, 20 insertions(+)

diff --git a/README b/README
index f16b9ec0..34aef9ee 100644
--- a/README
+++ b/README
@@ -231,6 +231,16 @@ For a working system, certain configuration options need 
to be enabled:
                is selected, ConnMan configures systemd-resolved to do DNS
                resolving. The default value is "internal".
 
+       --enable-continuous-online-check
+
+               Enable continuously checking for Internet connection.
+
+               If enabled, services will conduct online state check
+               regularly once Online state is reached. When in Online state,
+               but due to lack of internet connectivity, the service will be
+               downgraded to a Ready state giving the chance for other
+               configured services to take over.
+               This feature depends on EnableOnlineCheck = true.
 
 Activating debugging
 ====================
diff --git a/configure.ac b/configure.ac
index ee49a22c..cb5be448 100644
--- a/configure.ac
+++ b/configure.ac
@@ -323,6 +323,12 @@ AC_ARG_ENABLE(selinux, AC_HELP_STRING([--enable-selinux],
                        [enable_selinux=${enableval}], [enable_selinux="no"])
 AM_CONDITIONAL(SELINUX, test "${enable_selinux}" != "no")
 
+AC_ARG_ENABLE(continuous-online-check, 
AC_HELP_STRING([--enable-continuous-online-check],
+                               [enable continuous online check in the online 
state]),
+                       [enable_cont_check="true"], [enable_cont_check="false"])
+AC_DEFINE_UNQUOTED([CONTIUOUS_ONLINE_CHECK_ENABLED], ${enable_cont_check},
+                       [enable continuous online check during the online 
state])
+
 AC_ARG_ENABLE(loopback, AC_HELP_STRING([--disable-loopback],
                                [disable loopback support]),
                                        [enable_loopback=${enableval}])
diff --git a/src/service.c b/src/service.c
index 36a1911b..8e3758fd 100644
--- a/src/service.c
+++ b/src/service.c
@@ -6186,6 +6186,7 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
 
        /* Any change? */
        if (old_state == new_state) {
+#if defined(CONTIUOUS_ONLINE_CHECK_ENABLED)
                /*
                 * continuous online check requires restart of the check
                 * at regular intervals
@@ -6193,6 +6194,7 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
                if (new_state == CONNMAN_SERVICE_STATE_ONLINE) {
                        start_periodic_online_check(service, type);
                }
+#endif
 
                return -EALREADY;
        }
@@ -6224,7 +6226,9 @@ int __connman_service_ipconfig_indicate_state(struct 
connman_service *service,
                set_mdns(service, service->mdns_config);
                break;
        case CONNMAN_SERVICE_STATE_ONLINE:
+#if defined(CONTIUOUS_ONLINE_CHECK_ENABLED)
                start_periodic_online_check(service, type);
+#endif
                break;
        case CONNMAN_SERVICE_STATE_DISCONNECT:
                if (service->state == CONNMAN_SERVICE_STATE_IDLE)
-- 
2.17.1



------------------------------

Message: 5
Date: Fri, 27 Sep 2019 15:44:48 +0300
From: [email protected]
To: [email protected]
Cc: Aleksandar Mitev <[email protected]>
Subject: [PATCH 4/4] doc: updated state diagram for services
Message-ID: <[email protected]>

From: Aleksandar Mitev <[email protected]>

---
 doc/overview-api.txt | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/doc/overview-api.txt b/doc/overview-api.txt
index fd51d706..c7c47a5b 100644
--- a/doc/overview-api.txt
+++ b/doc/overview-api.txt
@@ -257,6 +257,14 @@ to retrieve/configure IP settings.
 The "ready" state signals a successful connected device. This doesn't mean
 it has the default route, but basic IP operations will succeed.
 
+There is also the optional "online" state that is reached whenever
+an online check is perfomed and succeeds. This state is intended to point
+out that global IPs can be reached, i.e. there is Internet connectivity.
+More details on how the online check is performed can be found in README.
+Getting to this state is governed by config option "EnableOnlineCheck".
+Continuously checking for Internet connectivity is configured with
+"--enable-continuous-online-check" compile option.
+
 With the "disconnect" state a service indicates that it is going to terminate
 the current connection and will return to the "idle" state.
 
@@ -284,14 +292,15 @@ the "idle" state since the service is not connected.
                      | success                                  |
                      V                                          |
                +---------------+                                |
-               | ready         |                                |
-               +---------------+                                |
-                     |                                          |
-                     | success                                  |
-                     |                                          |
-                     V                                          |
-               +---------------+                                |
-               | online        |<----------------+              |
+               | ready         |<----------------+              |
+               +---------------+                 |              |
+                     |                           |              |
+                     | online check       continuous online     |
+                     | success              check fails         |
+                     V                           |              |
+               +---------------+                 |              |
+               | online        |-----------------+              |
+               | (optional)    |<----------------+              |
                +---------------+                 |              |
                      |                           |              |
                      | service.Disconnect()      |              |
-- 
2.17.1



------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 47, Issue 16
***************************************

Reply via email to