gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] 01/05: towards building auditor-lib (not y


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] 01/05: towards building auditor-lib (not yet finished)
Date: Sat, 27 Oct 2018 19:26:47 +0200

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

grothoff pushed a commit to branch master
in repository exchange.

commit bfd8a6fa682e383c77ae2270191e689aa273effa
Author: Christian Grothoff <address@hidden>
AuthorDate: Sat Oct 27 18:38:43 2018 +0200

    towards building auditor-lib (not yet finished)
---
 configure.ac                                       |  1 +
 src/auditor-lib/Makefile.am                        |  5 +-
 src/auditor-lib/auditor_api_deposit_confirmation.c | 92 +++++++---------------
 src/auditor-lib/auditor_api_handle.c               | 12 +--
 src/auditor-lib/backoff.h                          | 38 +++++++++
 src/auditor-lib/curl_defaults.h                    | 41 ++++++++++
 6 files changed, 119 insertions(+), 70 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7763378a..02d86ccd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -546,6 +546,7 @@ AC_CONFIG_FILES([Makefile
                  src/Makefile
                  src/auditor/Makefile
                  src/auditordb/Makefile
+                 src/auditor-lib/Makefile
                  src/bank-lib/Makefile
                  src/exchange/Makefile
                  src/exchangedb/Makefile
diff --git a/src/auditor-lib/Makefile.am b/src/auditor-lib/Makefile.am
index 45ae881d..1e7c87a4 100644
--- a/src/auditor-lib/Makefile.am
+++ b/src/auditor-lib/Makefile.am
@@ -1,5 +1,5 @@
 # This Makefile.am is in the public domain
-AM_CPPFLAGS = -I$(top_srcdir)/src/include 
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
 
 if USE_COVERAGE
   AM_CFLAGS = --coverage -O0
@@ -7,7 +7,7 @@ if USE_COVERAGE
 endif
 
 lib_LTLIBRARIES = \
-  libtalerauditor
+  libtalerauditor.la
 
 libtalerauditor_la_LDFLAGS = \
   -version-info 0:0:0 \
@@ -32,4 +32,3 @@ if HAVE_LIBGNURL
 libtalerauditor_la_LIBADD += -lgnurl
 endif
 endif
-
diff --git a/src/auditor-lib/auditor_api_deposit_confirmation.c 
b/src/auditor-lib/auditor_api_deposit_confirmation.c
index 5b094c2a..8dd65489 100644
--- a/src/auditor-lib/auditor_api_deposit_confirmation.c
+++ b/src/auditor-lib/auditor_api_deposit_confirmation.c
@@ -77,16 +77,15 @@ struct TALER_AUDITOR_DepositConfirmationHandle
  *
  * @param cls the `struct TALER_AUDITOR_DepositConfirmationHandle`
  * @param response_code HTTP response code, 0 on error
- * @param json parsed JSON result, NULL on error
+ * @param djson parsed JSON result, NULL on error
  */
 static void
 handle_deposit_confirmation_finished (void *cls,
                                      long response_code,
-                                     const json_t *json)
+                                     const void *djson)
 {
+  const json_t *json = djson;
   struct TALER_AUDITOR_DepositConfirmationHandle *dh = cls;
-  struct TALER_AuditorPublicKeyP auditor_pub;
-  struct TALER_AuditorPublicKeyP *ep = NULL;
 
   dh->job = NULL;
   switch (response_code)
@@ -95,8 +94,6 @@ handle_deposit_confirmation_finished (void *cls,
     break;
   case MHD_HTTP_OK:
     break;
-  case MHD_HTTP_NOT_FOUND:
-    break;
   case MHD_HTTP_BAD_REQUEST:
     /* This should never happen, either us or the auditor is buggy
        (or API version conflict); just pass JSON reply to the application */
@@ -153,59 +150,43 @@ verify_signatures (const struct TALER_Amount *amount,
                    struct GNUNET_TIME_Absolute timestamp,
                    const struct TALER_MerchantPublicKeyP *merchant_pub,
                    struct GNUNET_TIME_Absolute refund_deadline,
-                   const struct TALER_CoinSpendSignatureP *coin_sig)
+                   const struct TALER_ExchangePublicKeyP *exchange_pub,
+                   const struct TALER_CoinSpendSignatureP *exchange_sig,
+                   const struct TALER_MasterPublicKeyP *master_pub,
+                   struct GNUNET_TIME_AbsoluteNBO ep_start,
+                   struct GNUNET_TIME_AbsoluteNBO ep_expire,
+                   struct GNUNET_TIME_AbsoluteNBO ep_end,
+                   const struct TALER_MasterSignatureP *master_sig)
 {
-  struct TALER_DepositConfirmationRequestPS dr;
-  struct TALER_CoinPublicInfo coin_info;
+  struct TALER_DepositConfirmationPS dc;
 
-  dr.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_DEPOSIT_CONFIRMATION);
-  dr.purpose.size = htonl (sizeof (struct TALER_DepositConfirmationRequestPS));
-  dr.h_contract_terms = *h_contract_terms;
-  dr.h_wire = *h_wire;
-  dr.timestamp = GNUNET_TIME_absolute_hton (timestamp);
-  dr.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
-  TALER_amount_hton (&dr.amount_with_fee,
+  dc.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT);
+  dc.purpose.size = htonl (sizeof (struct TALER_DepositConfirmationPS));
+  dc.h_contract_terms = *h_contract_terms;
+  dc.h_wire = *h_wire;
+  dc.timestamp = GNUNET_TIME_absolute_hton (timestamp);
+  dc.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
+  TALER_amount_hton (&dc.amount_without_fee,
                      amount);
-  TALER_amount_hton (&dr.deposit_confirmation_fee,
-                     &dki->fee_deposit_confirmation);
-  dr.merchant = *merchant_pub;
-  dr.coin_pub = *coin_pub;
+  dc.coin_pub = *coin_pub;
+  dc.merchant = *merchant_pub;
   if (GNUNET_OK !=
-      GNUNET_CRYPTO_eddsa_verify 
(TALER_SIGNATURE_WALLET_COIN_DEPOSIT_CONFIRMATION,
-                                  &dr.purpose,
+      GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT,
+                                  &dc.purpose,
                                   &coin_sig->eddsa_signature,
                                   &coin_pub->eddsa_pub))
   {
     GNUNET_break_op (0);
     TALER_LOG_WARNING ("Invalid coin signature on /deposit-confirmation 
request!\n");
     {
-      TALER_LOG_DEBUG ("... amount_with_fee was %s\n",
+      TALER_LOG_DEBUG ("... amount_without_fee was %s\n",
                        TALER_amount2s (amount));
-      TALER_LOG_DEBUG ("... deposit-confirmation_fee was %s\n",
-                       TALER_amount2s (&dki->fee_deposit_confirmation));
     }
 
     return GNUNET_SYSERR;
   }
 
-  /* check coin signature */
-  coin_info.coin_pub = *coin_pub;
-  coin_info.denom_pub = *denom_pub;
-  coin_info.denom_sig = *denom_sig;
-  if (GNUNET_YES !=
-      TALER_test_coin_valid (&coin_info))
-  {
-    GNUNET_break_op (0);
-    TALER_LOG_WARNING ("Invalid coin passed for /deposit-confirmation\n");
-    return GNUNET_SYSERR;
-  }
-  if (0 < TALER_amount_cmp (&dki->fee_deposit_confirmation,
-                            amount))
-  {
-    GNUNET_break_op (0);
-    TALER_LOG_WARNING ("DepositConfirmation amount smaller than fee\n");
-    return GNUNET_SYSERR;
-  }
+
   return GNUNET_OK;
 }
 
@@ -252,16 +233,15 @@ TALER_AUDITOR_deposit_confirmation (struct 
TALER_AUDITOR_Handle *auditor,
   struct GNUNET_CURL_Context *ctx;
   json_t *deposit_confirmation_obj;
   CURL *eh;
-  struct TALER_Amount amount_without_fee;
 
-  (void) GNUNET_TIME_round_abs (&wire_deadline);
+  (void) GNUNET_TIME_round_abs (&timestamp);
   (void) GNUNET_TIME_round_abs (&refund_deadline);
   GNUNET_assert (refund_deadline.abs_value_us <= wire_deadline.abs_value_us);
   GNUNET_assert (GNUNET_YES ==
                 MAH_handle_is_ready (auditor));
   if (GNUNET_OK !=
-      verify_signatures (amount,
-                         &h_wire,
+      verify_signatures (amount_without_fees,
+                         h_wire,
                          h_contract_terms,
                          coin_pub,
                          timestamp,
@@ -281,7 +261,7 @@ TALER_AUDITOR_deposit_confirmation (struct 
TALER_AUDITOR_Handle *auditor,
                 " s:o," /* merchant_pub */
                 " s:o, s:o," /* refund_deadline, wire_deadline */
                 " s:o}",     /* coin_sig */
-                "contribution", TALER_JSON_from_amount (amount),
+                "amount_without_fees", TALER_JSON_from_amount 
(amount_without_fees),
                 "H_wire", GNUNET_JSON_from_data_auto (&h_wire),
                 "h_contract_terms", GNUNET_JSON_from_data_auto 
(h_contract_terms),
                 "coin_pub", GNUNET_JSON_from_data_auto (coin_pub),
@@ -302,20 +282,8 @@ TALER_AUDITOR_deposit_confirmation (struct 
TALER_AUDITOR_Handle *auditor,
   dh->cb = cb;
   dh->cb_cls = cb_cls;
   dh->url = MAH_path_to_url (auditor, "/deposit-confirmation");
-  dh->depconf.purpose.size = htonl (sizeof (struct 
TALER_DepositConfirmationConfirmationPS));
-  dh->depconf.purpose.purpose = htonl 
(TALER_SIGNATURE_EXCHANGE_DEPOSIT_CONFIRMATION);
-  dh->depconf.h_contract_terms = *h_contract_terms;
-  dh->depconf.h_wire = h_wire;
-  dh->depconf.timestamp = GNUNET_TIME_absolute_hton (timestamp);
-  dh->depconf.refund_deadline = GNUNET_TIME_absolute_hton (refund_deadline);
-  TALER_amount_hton (&dh->depconf.amount_without_fee,
-                     &amount_without_fee);
-  dh->depconf.coin_pub = *coin_pub;
-  dh->depconf.merchant = *merchant_pub;
-  dh->amount_with_fee = *amount;
-  dh->coin_value = dki->value;
 
-  eh = TEL_curl_easy_get (dh->url);
+  eh = TAL_curl_easy_get (dh->url);
   GNUNET_assert (NULL != (dh->json_enc =
                           json_dumps (deposit_confirmation_obj,
                                       JSON_COMPACT)));
@@ -335,7 +303,7 @@ TALER_AUDITOR_deposit_confirmation (struct 
TALER_AUDITOR_Handle *auditor,
   dh->job = GNUNET_CURL_job_add (ctx,
                                 eh,
                                 GNUNET_YES,
-                                (GC_JCC) &handle_deposit_confirmation_finished,
+                                &handle_deposit_confirmation_finished,
                                 dh);
   return dh;
 }
diff --git a/src/auditor-lib/auditor_api_handle.c 
b/src/auditor-lib/auditor_api_handle.c
index b3557c26..26eca74e 100644
--- a/src/auditor-lib/auditor_api_handle.c
+++ b/src/auditor-lib/auditor_api_handle.c
@@ -206,13 +206,13 @@ decode_version_json (const json_t *resp_obj,
                      struct TALER_AUDITOR_VersionInformation *vi,
                      enum TALER_AUDITOR_VersionCompatibility *vc)
 {
-  struct TALER_AuditorPublicKeyP pub;
   unsigned int age;
   unsigned int revision;
   unsigned int current;
+  const char *ver;
   struct GNUNET_JSON_Specification spec[] = {
     GNUNET_JSON_spec_string ("version",
-                            &vi->version),
+                            &ver),
     GNUNET_JSON_spec_fixed_auto ("master_public_key",
                                 &vi->auditor_pub),
     GNUNET_JSON_spec_end()
@@ -242,6 +242,7 @@ decode_version_json (const json_t *resp_obj,
     free_version_info (vi);
     return GNUNET_SYSERR;
   }
+  vi->version = GNUNET_strdup (ver);
   *vc = TALER_AUDITOR_VC_MATCH;
   if (TALER_PROTOCOL_CURRENT < current)
   {
@@ -279,8 +280,9 @@ request_version (void *cls);
 static void
 version_completed_cb (void *cls,
                      long response_code,
-                     const json_t *resp_obj)
+                     const void *gresp_obj)
 {
+  const json_t *resp_obj = gresp_obj;
   struct VersionRequest *vr = cls;
   struct TALER_AUDITOR_Handle *auditor = vr->auditor;
   enum TALER_AUDITOR_VersionCompatibility vc;
@@ -475,7 +477,7 @@ request_version (void *cls)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Requesting version with URL `%s'.\n",
               vr->url);
-  eh = TEL_curl_easy_get (vr->url);
+  eh = TAL_curl_easy_get (vr->url);
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_VERBOSE,
@@ -491,7 +493,7 @@ request_version (void *cls)
   vr->job = GNUNET_CURL_job_add (auditor->ctx,
                                  eh,
                                  GNUNET_NO,
-                                 (GC_JCC) &version_completed_cb,
+                                 &version_completed_cb,
                                  vr);
   auditor->vr = vr;
 }
diff --git a/src/auditor-lib/backoff.h b/src/auditor-lib/backoff.h
new file mode 100644
index 00000000..523a6b9e
--- /dev/null
+++ b/src/auditor-lib/backoff.h
@@ -0,0 +1,38 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2018 GNUnet e.V.
+
+  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/>
+*/
+
+/**
+ * @file auditor-lib/backoff.h
+ * @brief backoff computation for the auditor lib
+ * @author Florian Dold
+ */
+
+
+#ifndef _TALER_BACKOFF_H
+#define _TALER_BACKOFF_H
+
+#include "platform.h"
+#include <gnunet/gnunet_time_lib.h>
+
+/**
+ * Random exponential backoff used in the auditor lib.
+ */
+#define AUDITOR_LIB_BACKOFF(r) GNUNET_TIME_randomized_backoff ( \
+    (r), \
+    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2));
+
+#endif
diff --git a/src/auditor-lib/curl_defaults.h b/src/auditor-lib/curl_defaults.h
new file mode 100644
index 00000000..815472c8
--- /dev/null
+++ b/src/auditor-lib/curl_defaults.h
@@ -0,0 +1,41 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2018 GNUnet e.V.
+
+  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/>
+*/
+
+/**
+ * @file auditor-lib/curl_defaults.h
+ * @brief curl easy handle defaults
+ * @author Florian Dold
+ */
+
+#ifndef _TALER_CURL_DEFAULTS_H
+#define _TALER_CURL_DEFAULTS_H
+
+
+#include "platform.h"
+#include <gnunet/gnunet_curl_lib.h>
+
+
+/**
+ * Get a curl handle with the right defaults
+ * for the auditor lib.  In the future, we might manage a pool of connections 
here.
+ *
+ * @param url URL to query
+ */
+CURL *
+TAL_curl_easy_get (char *url);
+
+#endif /* _TALER_CURL_DEFAULTS_H */

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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