LCOV - code coverage report
Current view: top level - bank-lib - taler-fakebank-run.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 28 36 77.8 %
Date: 2021-08-30 06:43:37 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2016, 2017 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,
      11             :   but 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             : /**
      21             :  * @file bank-lib/taler-fakebank-run.c
      22             :  * @brief Launch the fakebank, for testing the fakebank itself.
      23             :  * @author Marcello Stanisci
      24             :  * @author Christian Grothoff
      25             :  */
      26             : #include "platform.h"
      27             : #include "taler_fakebank_lib.h"
      28             : #include "taler_mhd_lib.h"
      29             : 
      30             : /**
      31             :  * Number of threads to use (-n)
      32             :  */
      33             : static unsigned int num_threads;
      34             : 
      35             : /**
      36             :  * Force connection close after each request (-C)
      37             :  */
      38             : static int connection_close;
      39             : 
      40             : /**
      41             :  * Global return value.
      42             :  */
      43             : static int ret;
      44             : 
      45             : /**
      46             :  * Handle for the service.
      47             :  */
      48             : static struct TALER_FAKEBANK_Handle *fb;
      49             : 
      50             : 
      51             : /**
      52             :  * Stop the process.
      53             :  *
      54             :  * @param cls NULL
      55             :  */
      56             : static void
      57           1 : do_shutdown (void *cls)
      58             : {
      59             :   (void) cls;
      60           1 :   TALER_FAKEBANK_stop (fb);
      61           1 :   fb = NULL;
      62           1 : }
      63             : 
      64             : 
      65             : /**
      66             :  * Main function that will be run.
      67             :  *
      68             :  * @param cls closure
      69             :  * @param args remaining command-line arguments
      70             :  * @param cfgfile name of the configuration file used
      71             :  *        (for saving, can be NULL!)
      72             :  * @param cfg configuration
      73             :  */
      74             : static void
      75           1 : run (void *cls,
      76             :      char *const *args,
      77             :      const char *cfgfile,
      78             :      const struct GNUNET_CONFIGURATION_Handle *cfg)
      79             : {
      80           1 :   unsigned long long port = 8082;
      81           1 :   unsigned long long ram = 1024 * 1024 * 128; /* 128 M entries */
      82             :   char *currency_string;
      83             : 
      84             :   (void) cls;
      85             :   (void) args;
      86             :   (void) cfgfile;
      87           1 :   if (GNUNET_OK !=
      88           1 :       TALER_config_get_currency (cfg,
      89             :                                  &currency_string))
      90             :   {
      91           0 :     ret = EXIT_NOTCONFIGURED;
      92           0 :     return;
      93             :   }
      94           1 :   if (GNUNET_OK !=
      95           1 :       GNUNET_CONFIGURATION_get_value_number (cfg,
      96             :                                              "bank",
      97             :                                              "HTTP_PORT",
      98             :                                              &port))
      99             :   {
     100           0 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     101             :                 "Listening on default port %llu\n",
     102             :                 port);
     103             :   }
     104           1 :   if (GNUNET_OK !=
     105           1 :       GNUNET_CONFIGURATION_get_value_number (cfg,
     106             :                                              "bank",
     107             :                                              "RAM_LIMIT",
     108             :                                              &ram))
     109             :   {
     110           0 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     111             :                 "Maximum transaction history in RAM set to default of %llu\n",
     112             :                 ram);
     113             :   }
     114             :   {
     115             :     enum TALER_MHD_GlobalOptions go;
     116             : 
     117           1 :     go = TALER_MHD_GO_NONE;
     118           1 :     if (0 != connection_close)
     119           0 :       go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
     120           1 :     TALER_MHD_setup (go);
     121             :   }
     122           1 :   fb = TALER_FAKEBANK_start2 ((uint16_t) port,
     123             :                               currency_string,
     124             :                               ram,
     125             :                               num_threads);
     126           1 :   if (NULL == fb)
     127             :   {
     128           0 :     ret = EXIT_FAILURE;
     129           0 :     return;
     130             :   }
     131           1 :   GNUNET_free (currency_string);
     132           1 :   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
     133             :                                  NULL);
     134           1 :   ret = EXIT_SUCCESS;
     135             : }
     136             : 
     137             : 
     138             : /**
     139             :  * The main function.
     140             :  *
     141             :  * @param argc number of arguments from the command line
     142             :  * @param argv command line arguments
     143             :  * @return 0 ok, 1 on error
     144             :  */
     145             : int
     146           1 : main (int argc,
     147             :       char *const *argv)
     148             : {
     149           1 :   const struct GNUNET_GETOPT_CommandLineOption options[] = {
     150           1 :     GNUNET_GETOPT_option_flag ('C',
     151             :                                "connection-close",
     152             :                                "force HTTP connections to be closed after each request",
     153             :                                &connection_close),
     154           1 :     GNUNET_GETOPT_option_uint ('n',
     155             :                                "num-threads",
     156             :                                "NUM_THREADS",
     157             :                                "size of the thread pool",
     158             :                                &num_threads),
     159             :     GNUNET_GETOPT_OPTION_END
     160             :   };
     161             : 
     162           1 :   if (GNUNET_OK !=
     163           1 :       GNUNET_PROGRAM_run (argc, argv,
     164             :                           "taler-fakebank-run",
     165             :                           "Runs the fakebank",
     166             :                           options,
     167             :                           &run,
     168             :                           NULL))
     169           0 :     return EXIT_INVALIDARGUMENT;
     170           1 :   return ret;
     171             : }

Generated by: LCOV version 1.14