exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_exec_aggregator.c (5147B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2018 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it
      6   under the terms of the GNU General Public License as published
      7   by the Free Software Foundation; either version 3, or (at your
      8   option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public
     16   License along with TALER; see the file COPYING.  If not,
     17   see <http://www.gnu.org/licenses/>
     18 */
     19 /**
     20  * @file testing/testing_api_cmd_exec_aggregator.c
     21  * @brief run the taler-exchange-aggregator command
     22  * @author Marcello Stanisci
     23  */
     24 #include "taler/platform.h"
     25 #include "taler/taler_json_lib.h"
     26 #include <gnunet/gnunet_curl_lib.h>
     27 #include "taler/taler_signatures.h"
     28 #include "taler/taler_testing_lib.h"
     29 
     30 
     31 /**
     32  * State for a "aggregator" CMD.
     33  */
     34 struct AggregatorState
     35 {
     36 
     37   /**
     38    * Aggregator process.
     39    */
     40   struct GNUNET_Process *aggregator_proc;
     41 
     42   /**
     43    * Configuration file used by the aggregator.
     44    */
     45   const char *config_filename;
     46 
     47   /**
     48    * Run with KYC restrictions on.
     49    */
     50   bool kyc_on;
     51 };
     52 
     53 
     54 /**
     55  * Run the command.  Use the `taler-exchange-aggregator` program.
     56  *
     57  * @param cls closure.
     58  * @param cmd command being run.
     59  * @param is interpreter state.
     60  */
     61 static void
     62 aggregator_run (void *cls,
     63                 const struct TALER_TESTING_Command *cmd,
     64                 struct TALER_TESTING_Interpreter *is)
     65 {
     66   struct AggregatorState *as = cls;
     67 
     68   (void) cmd;
     69   as->aggregator_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
     70   if (GNUNET_OK !=
     71       GNUNET_process_run_command_va (as->aggregator_proc,
     72                                      "taler-exchange-aggregator",
     73                                      "taler-exchange-aggregator",
     74                                      "-c", as->config_filename,
     75                                      "-L", "INFO",
     76                                      "-t",   /* exit when done */
     77                                      (as->kyc_on)
     78                                        ? NULL
     79                                        : "-y", /* skip KYC */
     80                                      NULL))
     81   {
     82     GNUNET_break (0);
     83     GNUNET_process_destroy (as->aggregator_proc);
     84     as->aggregator_proc = NULL;
     85     TALER_TESTING_interpreter_fail (is);
     86     return;
     87   }
     88   TALER_TESTING_wait_for_sigchld (is);
     89 }
     90 
     91 
     92 /**
     93  * Free the state of a "aggregator" CMD, and possibly kill its
     94  * process if it did not terminate correctly.
     95  *
     96  * @param cls closure.
     97  * @param cmd the command being freed.
     98  */
     99 static void
    100 aggregator_cleanup (void *cls,
    101                     const struct TALER_TESTING_Command *cmd)
    102 {
    103   struct AggregatorState *as = cls;
    104 
    105   (void) cmd;
    106   if (NULL != as->aggregator_proc)
    107   {
    108     GNUNET_break (GNUNET_OK ==
    109                   GNUNET_process_kill (as->aggregator_proc,
    110                                        SIGKILL));
    111     GNUNET_process_wait (as->aggregator_proc,
    112                          true,
    113                          NULL,
    114                          NULL);
    115     GNUNET_process_destroy (as->aggregator_proc);
    116     as->aggregator_proc = NULL;
    117   }
    118   GNUNET_free (as);
    119 }
    120 
    121 
    122 /**
    123  * Offer "aggregator" CMD internal data to other commands.
    124  *
    125  * @param cls closure.
    126  * @param[out] ret result.
    127  * @param trait name of the trait.
    128  * @param index index number of the object to offer.
    129  * @return #GNUNET_OK on success
    130  */
    131 static enum GNUNET_GenericReturnValue
    132 aggregator_traits (void *cls,
    133                    const void **ret,
    134                    const char *trait,
    135                    unsigned int index)
    136 {
    137   struct AggregatorState *as = cls;
    138   struct TALER_TESTING_Trait traits[] = {
    139     TALER_TESTING_make_trait_process (&as->aggregator_proc),
    140     TALER_TESTING_trait_end ()
    141   };
    142 
    143   return TALER_TESTING_get_trait (traits,
    144                                   ret,
    145                                   trait,
    146                                   index);
    147 }
    148 
    149 
    150 struct TALER_TESTING_Command
    151 TALER_TESTING_cmd_exec_aggregator (const char *label,
    152                                    const char *config_filename)
    153 {
    154   struct AggregatorState *as;
    155 
    156   as = GNUNET_new (struct AggregatorState);
    157   as->config_filename = config_filename;
    158   {
    159     struct TALER_TESTING_Command cmd = {
    160       .cls = as,
    161       .label = label,
    162       .run = &aggregator_run,
    163       .cleanup = &aggregator_cleanup,
    164       .traits = &aggregator_traits
    165     };
    166 
    167     return cmd;
    168   }
    169 }
    170 
    171 
    172 struct TALER_TESTING_Command
    173 TALER_TESTING_cmd_exec_aggregator_with_kyc (const char *label,
    174                                             const char *config_filename)
    175 {
    176   struct AggregatorState *as;
    177 
    178   as = GNUNET_new (struct AggregatorState);
    179   as->config_filename = config_filename;
    180   as->kyc_on = true;
    181   {
    182     struct TALER_TESTING_Command cmd = {
    183       .cls = as,
    184       .label = label,
    185       .run = &aggregator_run,
    186       .cleanup = &aggregator_cleanup,
    187       .traits = &aggregator_traits
    188     };
    189 
    190     return cmd;
    191   }
    192 }
    193 
    194 
    195 /* end of testing_api_cmd_exec_aggregator.c */