gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-mdb] branch master updated (8361874 -> 9afe2f0)


From: gnunet
Subject: [taler-taler-mdb] branch master updated (8361874 -> 9afe2f0)
Date: Sat, 13 Jan 2024 15:26:47 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository taler-mdb.

    from 8361874  fix build for 0.9.4 api
     new 7fec3a3  add advertising logic
     new 9afe2f0  have script to show error diagnostics

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Makefile.am                        |   8 +-
 configure.ac                       |   1 +
 contrib/Makefile.am                |   9 ++
 contrib/taler-mdb-network-check.sh | 187 +++++++++++++++++++++++++++++++++++++
 src/.gitignore                     |   1 +
 src/taler-mdb.c                    | 133 ++++++++++++++++++--------
 taler.conf                         |   6 +-
 7 files changed, 296 insertions(+), 49 deletions(-)
 create mode 100644 contrib/Makefile.am
 create mode 100755 contrib/taler-mdb-network-check.sh

diff --git a/Makefile.am b/Makefile.am
index 40e718c..151a99c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,10 +1,6 @@
-SUBDIRS = src .
+SUBDIRS = contrib src .
 
 EXTRA_DIST = \
-  AUTHORS \
-  contrib/uncrustify.cfg \
-  contrib/uncrustify_precommit
+  AUTHORS
 
 ACLOCAL_AMFLAGS = -I m4
-
-
diff --git a/configure.ac b/configure.ac
index 7732561..f26711d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -274,6 +274,7 @@ LIBS=$LIBS_SAVE
 
 
 AC_CONFIG_FILES([Makefile
+                 contrib/Makefile
                  src/Makefile])
 AC_OUTPUT
 
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
new file mode 100644
index 0000000..ade84a2
--- /dev/null
+++ b/contrib/Makefile.am
@@ -0,0 +1,9 @@
+SUBDIRS = .
+
+bin_SCRIPTS = \
+  taler-mdb-network-check.sh
+
+EXTRA_DIST = \
+  $(bin_SCRIPTS) \
+  uncrustify.cfg \
+  uncrustify_precommit
diff --git a/contrib/taler-mdb-network-check.sh 
b/contrib/taler-mdb-network-check.sh
new file mode 100755
index 0000000..1c809e9
--- /dev/null
+++ b/contrib/taler-mdb-network-check.sh
@@ -0,0 +1,187 @@
+#!/bin/bash
+#
+# This file is part of TALER
+# Copyright (C) 2023, 2024 Taler Systems SA
+#
+# TALER 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, or
+# (at your option) any later version.
+#
+# TALER 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 TALER; see the file COPYING.  If not, see
+# <http://www.gnu.org/licenses/>
+#
+# Author: Christian Grothoff
+#
+# Script to test for network connectivity, and if
+# successful launch some "main" application. If
+# the network goes down, stop the "main" application
+# and show an error message.
+#
+
+set -eu
+
+EXIT_STATUS=0
+CHILD_PID=-1
+
+# Exit, with error message (hard failure)
+function exit_fail() {
+    echo " FAILURE:" "$@" >&2
+    EXIT_STATUS=1
+    exit "$EXIT_STATUS"
+}
+
+CONF="$HOME/.config/taler.conf"
+FAIL_PROG="echo"
+
+# Parse command-line options
+while getopts ':c:f:ht:' OPTION; do
+    case "$OPTION" in
+        c)
+            CONF="$OPTARG"
+            ;;
+        f)
+            FAIL_PROG="$OPTARG"
+            ;;
+        h)
+            echo 'Supported options:'
+            # shellcheck disable=SC2016
+            echo '  -c $CONF     -- set configuration'
+            # shellcheck disable=SC2016
+            echo '  -f $CMD      -- command to run to display failures'
+            # shellcheck disable=SC2016
+            echo '  -t $HOSTNAME -- target hostname (required)'
+            ;;
+        t)
+            BACKEND_HOSTNAME="$OPTARG"
+            ;;
+        ?)
+            exit_fail "Unrecognized command line option"
+            ;;
+    esac
+done
+shift $((OPTIND - 1))
+
+if [[ "${BACKEND_HOSTNAME:-}" == "" ]]
+then
+    exit_fail "Specifying '-t' is required"
+fi
+
+dig -h > /dev/null || exit_fail "'dig' is required"
+
+
+# Cleanup to run whenever we exit
+function cleanup()
+{
+    echo "network-check terminating!" >&2
+
+    for n in $(jobs -p)
+    do
+        kill "$n" 2> /dev/null || true
+    done
+    wait
+    exit "$EXIT_STATUS"
+}
+
+# Function called with the short-hand of a detected
+# Failure. Stop our child (if any) and show it.
+function show_failure()
+{
+    if [ "$CHILD_PID" != "-1" ]
+    then
+        kill -TERM "$CHILD_PID"
+        wait
+        CHILD_PID="-1"
+    fi
+    ${FAIL_PROG} "$1" >&2
+}
+
+# Function to run when our child died.
+function childdeath()
+{
+    wait ${CHILD_PID}
+    CHILD_PID="-1"
+    show_failure child-died
+}
+
+# Install cleanup handler (except for kill -9)
+trap cleanup EXIT
+trap childdeath SIGCHLD
+
+# shellcheck disable=SC2120
+function check_network()
+{
+    DNS_HOST=$(grep nameserver /etc/resolv.conf | awk '{print $2}')
+    if ! ping -c1 "$DNS_HOST" &> /dev/null
+    then
+        show_failure no-ip
+        return
+    fi
+    if ! dig "$BACKEND_HOSTNAME" &> /dev/null
+    then
+        show_failure backend-dns-resolution-failure
+        return
+    fi
+    if ! ping -c1 "$BACKEND_HOSTNAME" &> /dev/null
+    then
+        show_failure backend-unreachable
+        return
+    fi
+
+    DEF_BACKEND=$(taler-config -c "$CONF" -s "taler-mdb" -o "BACKEND_BASE_URL")
+    if echo "$DEF_BACKEND" | grep "https://"; > /dev/null
+    then
+        if ! wget --no-check-certificate "${DEF_BACKEND}config" -O /dev/null 
&> /dev/null
+        then
+            show_failure backend-no-web-server
+            return
+        fi
+    fi
+
+    if ! wget "${DEF_BACKEND}config" -O /dev/null &> /dev/null
+    then
+        show_failure backend-x509-cert-bad
+        return
+    fi
+
+    HAVE_PRODUCT=0
+    for PS in $(taler-config -c "$CONF" -S | grep "product-" | head -n1)
+    do
+        URL=$(taler-config -c "$CONF" -s "$PS" -o "INSTANCE" 2> /dev/null || 
echo "$DEF_BACKEND")
+        AUTH=$(taler-config -c "$CONF" -s "$PS" -o "BACKEND_AUTHORIZATION")
+
+        if ! wget --header "Authorization: $AUTH" "${URL}private/orders" -O 
/dev/null &> /dev/null
+        then
+            echo "Failed to access backend for product '$PS'" >&2
+        else
+            HAVE_PRODUCT=1
+        fi
+    done
+    if [ "$HAVE_PRODUCT" = 0 ]
+    then
+        show_failure backend-auth-failure
+        return
+    fi
+    echo "Network OK, starting child"
+
+    if [ "${CHILD_PID}" = "-1" ]
+    then
+        # shellcheck disable=SC2068
+        $@ &
+        CHILD_PID=$!
+    fi
+}
+
+
+# Check network status
+while true
+do
+    check_network
+    sleep 30
+done
diff --git a/src/.gitignore b/src/.gitignore
index 7639f69..f66074a 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,2 +1,3 @@
 *.o
 taler-nfc
+taler-coin-acceptor
diff --git a/src/taler-mdb.c b/src/taler-mdb.c
index 0f5df48..1d34207 100644
--- a/src/taler-mdb.c
+++ b/src/taler-mdb.c
@@ -1,6 +1,6 @@
 /*
  This file is part of TALER
- Copyright (C) 2019, 2020, 2022 Taler Systems SA
+ Copyright (C) 2019, 2020, 2022, 2024 Taler Systems SA
 
  TALER 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
@@ -17,17 +17,17 @@ along with
  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 */
 /**
-* @file main.c
-* @brief runs the payment logic for a Taler-enabled snack machine
-* @author Marco Boss
-* @author Christian Grothoff
-* @author Dominik Hofer
-*
-*/
+ * @file taler-mdb.c
+ * @brief runs the payment logic for a Taler-enabled snack machine
+ * @author Marco Boss
+ * @author Christian Grothoff
+ * @author Dominik Hofer
+ */
 #include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <signal.h>
 #include <unistd.h>
 #include <sys/socket.h>
 #if HAVE_SYS_UN_H
@@ -633,6 +633,18 @@ static struct GNUNET_SCHEDULER_Task *keyboard_task;
  */
 static struct GNUNET_SCHEDULER_Task *cancelbutton_task;
 
+/**
+ * Handle to the process showing messages/advertisements
+ * while we are inactive.
+ */
+static struct GNUNET_OS_Process *adv_child;
+
+/**
+ * Name of the process to run when advertising is enabled.
+ * Can be NULL.
+ */
+static char *adv_process_filename;
+
 /**
  * Taler Backend url read from configuration file
  */
@@ -804,6 +816,41 @@ static const uint8_t get_data[] = { 0x00, 0xCA, 0x01, 
0x00, 0x00, 0x00 };
 static struct Display qrDisplay;
 
 
+/**
+ * Stop the advertising process.
+ */
+static void
+stop_advertising (void)
+{
+  if (NULL == adv_child)
+    return;
+  GNUNET_break (0 ==
+                GNUNET_OS_process_kill (adv_child,
+                                        SIGTERM));
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_OS_process_wait (adv_child));
+  GNUNET_OS_process_destroy (adv_child);
+  adv_child = NULL;
+}
+
+
+/**
+ * Start the advertising process.
+ */
+static void
+start_advertising (void)
+{
+  stop_advertising (); /* just to be sure */
+  adv_child = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_NONE,
+                                       NULL,
+                                       NULL,
+                                       NULL,
+                                       adv_process_filename,
+                                       adv_process_filename,
+                                       NULL);
+}
+
+
 #if HAVE_QRENCODE_H
 #include <qrencode.h>
 
@@ -824,6 +871,7 @@ show_qrcode (const char *uri)
   size_t yOff;
   const char *dddash;
 
+  stop_advertising ();
   if (0 > qrDisplay.devicefd)
     return; /* no display, no dice */
   /* find the fourth '/' in the payto://pay/hostname/-uri */
@@ -926,7 +974,7 @@ show_qrcode (const char *uri)
   QRcode_free (qrc);
   QRinput_free (qri);
 
-  /* turn on backlight if supported */
+  /* Turn on backlight if supported */
   if (0 < qrDisplay.backlightfd)
     (void) ! write (qrDisplay.backlightfd,
                     &backlight_on,
@@ -957,6 +1005,7 @@ async_pa_cleanup_job (void *cls)
   if (NULL != pa->rc)
     GNUNET_CURL_gnunet_rc_destroy (pa->rc);
   GNUNET_free (pa);
+  start_advertising ();
 }
 
 
@@ -1098,6 +1147,7 @@ mdb_shutdown (void)
     GNUNET_SCHEDULER_cancel (mdb.wtask);
     mdb.wtask = NULL;
   }
+  stop_advertising ();
   if (disable_mdb)
     return;
   /* restore UART */
@@ -1131,6 +1181,7 @@ shutdown_task (void *cls)
   (void) cls;
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Shutdown initiated\n");
+  stop_advertising ();
   while (NULL != (r = refund_head))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -2816,12 +2867,12 @@ read_products (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "description",
+                                             "DESCRIPTION",
                                              &tmpProduct.description))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                section,
-                               "description");
+                               "DESCRIPTION");
     return;
   }
   if (sold_out_enabled)
@@ -2851,7 +2902,7 @@ read_products (void *cls,
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "key",
+                                             "KEY",
                                              &tmpKey))
   {
     tmpProduct.key = tmpKey[0];
@@ -2865,14 +2916,14 @@ read_products (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "instance",
+                                             "INSTANCE",
                                              &tmpProduct.instance))
     tmpProduct.instance = NULL;
   tmpProduct.preview = NULL;
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              section,
-                                             "thumbnail",
+                                             "THUMBNAIL",
                                              &thumbnail_fn))
   {
     struct GNUNET_DISK_FileHandle *fh;
@@ -2964,12 +3015,12 @@ read_products (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (cfg,
                                              section,
-                                             "number",
+                                             "NUMBER",
                                              &tmpProduct.number))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                section,
-                               "number");
+                               "NUMBER");
     GNUNET_free (tmpProduct.description);
     GNUNET_free (tmpProduct.instance);
     GNUNET_free (tmpProduct.preview);
@@ -2982,17 +3033,17 @@ read_products (void *cls,
     if ( (GNUNET_OK !=
           GNUNET_CONFIGURATION_get_value_string (cfg,
                                                  section,
-                                                 "BACKEND-AUTHORIZATION",
+                                                 "BACKEND_AUTHORIZATION",
                                                  &auth)) &&
          (GNUNET_OK !=
           GNUNET_CONFIGURATION_get_value_string (cfg,
                                                  "taler-mdb",
-                                                 "BACKEND-AUTHORIZATION",
+                                                 "BACKEND_AUTHORIZATION",
                                                  &auth)) )
     {
       GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                  section,
-                                 "BACKEND-AUTHORIZATION");
+                                 "BACKEND_AUTHORIZATION");
       GNUNET_free (tmpProduct.description);
       GNUNET_free (tmpProduct.instance);
       GNUNET_free (tmpProduct.preview);
@@ -3120,7 +3171,7 @@ run (void *cls,
                                                "FRAMEBUFFER_DEVICE",
                                                &framebuffer_device_filename))
   {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
                                "taler-mdb",
                                "FRAMEBUFFER_DEVICE");
     framebuffer_device_filename = GNUNET_strdup ("/dev/fb1");
@@ -3141,35 +3192,37 @@ run (void *cls,
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              "taler-mdb",
-                                             "backend-base-url",
+                                             "BACKEND_BASE_URL",
                                              &backend_base_url))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                "taler-mdb",
-                               "backend-base-url");
+                               "BACKEND_BASE_URL");
     global_ret = EXIT_FAILURE;
     return;
   }
+  (void) GNUNET_CONFIGURATION_get_value_filename (cfg,
+                                                  "taler-mdb",
+                                                  "ADVERTISEMENT_BINARY",
+                                                  &adv_process_filename);
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cfg,
+                                             "taler-mdb",
+                                             "ESSID",
+                                             &essid))
   {
-    if (GNUNET_OK !=
-        GNUNET_CONFIGURATION_get_value_string (cfg,
-                                               "taler-mdb",
-                                               "essid",
-                                               &essid))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                  "No ESSID specified, will not advertise WLAN\n");
-    }
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "No ESSID specified, will not advertise WLAN\n");
   }
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              "taler-mdb",
-                                             "fulfillment-msg",
+                                             "FULFILLMENT_MSG",
                                              &fulfillment_msg))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
                                "taler-mdb",
-                               "fulfillment-msg");
+                               "FULFILLMENT_MSG");
     global_ret = EXIT_FAILURE;
     return;
   }
@@ -3361,6 +3414,7 @@ run (void *cls,
                               framebuffer_device_filename);
   }
 #endif
+  start_advertising ();
   if (! disable_tty)
     start_read_keyboard ();
 }
@@ -3425,16 +3479,19 @@ int
 main (int argc,
       char*const*argv)
 {
-  struct termios tty_opts_backup, tty_opts_raw;
+  struct termios tty_opts_backup;
+  struct termios tty_opts_raw;
   int have_tty;
   int ret;
-
-  /* the available command line options */
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_option_flag ('d',
                                "disable-mdb",
                                "disable all interactions with the MDB (for 
testing without machine)",
                                &disable_mdb),
+    GNUNET_GETOPT_option_flag ('i',
+                               "backlight-invert",
+                               "invert the backlight on/off values (standard 
on = 1)",
+                               &backlight_invert),
     GNUNET_GETOPT_option_flag ('s',
                                "enable-soldout",
                                "enable detection of sold-out products, 
preventing vend operations of the respective product until the process is 
restarted",
@@ -3443,10 +3500,6 @@ main (int argc,
                                "disable-tty",
                                "disable all keyboard interactions (for running 
from systemd)",
                                &disable_tty),
-    GNUNET_GETOPT_option_flag ('i',
-                               "backlight-invert",
-                               "invert the backlight on/off values (standard 
on = 1)",
-                               &backlight_invert),
     GNUNET_GETOPT_OPTION_END
   };
 
diff --git a/taler.conf b/taler.conf
index b133ec5..984faf2 100644
--- a/taler.conf
+++ b/taler.conf
@@ -1,8 +1,8 @@
 [taler-mdb]
-BACKEND-BASE-URL = https://backend.demo.taler.net/instances/Taler/
-BACKEND-AUTHORIZATION = Bearer secret-token:secret
+BACKEND_BASE_URL = https://backend.demo.taler.net/instances/Taler/
+BACKEND_AUTHORIZATION = Bearer secret-token:secret
 # Message to diplay after purchase is completed,
-fulfillment-msg = Enjoy your ${PRODUCT_DESCRIPTION}
+FULFILLMENT_MSG = Enjoy your ${PRODUCT_DESCRIPTION}
 
 # Name of the UART where the MDB connector is reachable.
 UART_DEVICE = /dev/ttyAMA0

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]