exchange

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

taler-exchange-httpd_db.h (4254B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2017 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13   You should have received a copy of the GNU General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file exchange/taler-exchange-httpd_db.h
     18  * @brief High-level (transactional-layer) database operations for the exchange
     19  * @author Chrisitan Grothoff
     20  */
     21 #ifndef TALER_EXCHANGE_HTTPD_DB_H
     22 #define TALER_EXCHANGE_HTTPD_DB_H
     23 
     24 #include <microhttpd.h>
     25 #include "exchangedb_lib.h"
     26 #include "taler-exchange-httpd_get-metrics.h"
     27 #include <gnunet/gnunet_mhd_compat.h>
     28 
     29 
     30 /**
     31  * How often should we retry a transaction before giving up
     32  * (for transactions resulting in serialization/dead locks only).
     33  *
     34  * The current value is likely too high for production. We might want to
     35  * benchmark good values once we have a good database setup.  The code is
     36  * expected to work correctly with any positive value, albeit inefficiently if
     37  * we too aggressively force clients to retry the HTTP request merely because
     38  * we have database serialization issues.
     39  */
     40 #define MAX_TRANSACTION_COMMIT_RETRIES 100
     41 
     42 
     43 /**
     44  * Ensure coin is known in the database, and handle conflicts and errors.
     45  *
     46  * @param coin the coin to make known
     47  * @param connection MHD request context
     48  * @param[out] known_coin_id set to the unique ID for the coin in the DB
     49  * @param[out] mhd_ret set to MHD status on error
     50  * @return transaction status, negative on error (@a mhd_ret will be set in this case)
     51  */
     52 enum GNUNET_DB_QueryStatus
     53 TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
     54                      struct MHD_Connection *connection,
     55                      uint64_t *known_coin_id,
     56                      enum MHD_Result *mhd_ret);
     57 
     58 
     59 /**
     60  * Function implementing a database transaction.  Runs the transaction
     61  * logic; IF it returns a non-error code, the transaction logic MUST
     62  * NOT queue a MHD response.  IF it returns an hard error, the
     63  * transaction logic MUST queue a MHD response and set @a mhd_ret.  IF
     64  * it returns the soft error code, the function MAY be called again to
     65  * retry and MUST not queue a MHD response.
     66  *
     67  * @param cls closure
     68  * @param connection MHD request which triggered the transaction
     69  * @param[out] mhd_ret set to MHD response status for @a connection,
     70  *             if transaction failed (!)
     71  * @return transaction status
     72  */
     73 typedef enum GNUNET_DB_QueryStatus
     74 (*TEH_DB_TransactionCallback)(void *cls,
     75                               struct MHD_Connection *connection,
     76                               enum MHD_Result *mhd_ret);
     77 
     78 
     79 /**
     80  * Run a database transaction for @a connection.
     81  * Starts a transaction and calls @a cb.  Upon success,
     82  * attempts to commit the transaction.  Upon soft failures,
     83  * retries @a cb a few times.  Upon hard or persistent soft
     84  * errors, generates an error message for @a connection.
     85  *
     86  * @param connection MHD connection to run @a cb for, can be NULL
     87  * @param name name of the transaction (for debugging)
     88  * @param mt type of the requests, for metric generation
     89  * @param[out] mhd_ret set to MHD response code, if transaction failed (returned #GNUNET_SYSERR);
     90  *             NULL if we are not running with a @a connection and thus
     91  *             must not queue MHD replies
     92  * @param cb callback implementing transaction logic
     93  * @param cb_cls closure for @a cb, must be read-only!
     94  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
     95  */
     96 enum GNUNET_GenericReturnValue
     97 TEH_DB_run_transaction (struct MHD_Connection *connection,
     98                         const char *name,
     99                         enum TEH_MetricTypeRequest mt,
    100                         enum MHD_Result *mhd_ret,
    101                         TEH_DB_TransactionCallback cb,
    102                         void *cb_cls);
    103 
    104 
    105 #endif
    106 /* TALER_EXCHANGE_HTTPD_DB_H */