gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: add request UID repetition detec


From: gnunet
Subject: [taler-exchange] branch master updated: add request UID repetition detection to fakebank
Date: Mon, 13 Jan 2020 22:27:59 +0100

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

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 5f6d8674 add request UID repetition detection to fakebank
5f6d8674 is described below

commit 5f6d867469bd5ae89be12dabd05e7457ba736c22
Author: Christian Grothoff <address@hidden>
AuthorDate: Mon Jan 13 22:27:49 2020 +0100

    add request UID repetition detection to fakebank
---
 src/bank-lib/fakebank.c          | 36 ++++++++++++++++++++++++++++++++----
 src/include/taler_fakebank_lib.h |  4 +++-
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 26720135..5b03648f 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -28,7 +28,7 @@
 #include "taler_mhd_lib.h"
 
 /**
- * Maximum POST request size (for /admin/add/incoming)
+ * Maximum POST request size (for /admin/add-incoming)
  */
 #define REQUEST_BUFFER_MAX (4 * 1024)
 
@@ -63,6 +63,11 @@ struct Transaction
    */
   char *credit_account;
 
+  /**
+   * Random unique identifier for the request.
+   */
+  struct GNUNET_HashCode request_uid;
+
   /**
    * What does the @e subject contain?
    */
@@ -346,6 +351,7 @@ TALER_FAKEBANK_check_credit (struct TALER_FAKEBANK_Handle 
*h,
  * @param amount amount to transfer
  * @param subject wire transfer subject to use
  * @param exchange_base_url exchange URL
+ * @param request_uid unique number to make the request unique, or NULL to 
create one
  * @return row_id of the transfer
  */
 uint64_t
@@ -355,10 +361,27 @@ TALER_FAKEBANK_make_transfer (struct 
TALER_FAKEBANK_Handle *h,
                               const struct TALER_Amount *amount,
                               const struct
                               TALER_WireTransferIdentifierRawP *subject,
-                              const char *exchange_base_url)
+                              const char *exchange_base_url,
+                              const struct GNUNET_HashCode *request_uid)
 {
   struct Transaction *t;
 
+  if (NULL != request_uid)
+  {
+    for (struct Transaction *t = h->transactions_head; NULL != t; t = t->next)
+      if ( (0 == GNUNET_memcmp (request_uid,
+                                &t->request_uid)) &&
+           (0 == strcasecmp (debit_account,
+                             t->debit_account)) &&
+           (0 == strcasecmp (credit_account,
+                             t->credit_account)) &&
+           (0 == TALER_amount_cmp (amount,
+                                   &t->amount)) &&
+           (T_DEBIT == t->type) &&
+           (0 == GNUNET_memcmp (subject,
+                                &t->subject.debit.wtid)) )
+        return t->row_id;
+  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Making transfer from %s to %s over %s and subject %s; for 
exchange: %s\n",
               debit_account,
@@ -375,6 +398,11 @@ TALER_FAKEBANK_make_transfer (struct TALER_FAKEBANK_Handle 
*h,
   t->type = T_DEBIT;
   t->subject.debit.exchange_base_url = GNUNET_strdup (exchange_base_url);
   t->subject.debit.wtid = *subject;
+  if (NULL == request_uid)
+    GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE,
+                                      &t->request_uid);
+  else
+    t->request_uid = *request_uid;
   GNUNET_TIME_round_abs (&t->date);
   GNUNET_CONTAINER_DLL_insert_tail (h->transactions_head,
                                     h->transactions_tail,
@@ -690,13 +718,13 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h,
       return MHD_NO;
     }
     {
-      // FIXME: use uuid here!!!
       row_id = TALER_FAKEBANK_make_transfer (h,
                                              account,
                                              credit_account,
                                              &amount,
                                              &wtid,
-                                             base_url);
+                                             base_url,
+                                             &uuid);
       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                   "Receiving incoming wire transfer: %s->%s, subject: %s, 
amount: %s, from %s\n",
                   account,
diff --git a/src/include/taler_fakebank_lib.h b/src/include/taler_fakebank_lib.h
index 25e04187..017ffd45 100644
--- a/src/include/taler_fakebank_lib.h
+++ b/src/include/taler_fakebank_lib.h
@@ -70,6 +70,7 @@ TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h);
  * @param amount amount to transfer
  * @param subject wire transfer subject to use
  * @param exchange_base_url exchange URL
+ * @param request_uid unique number to make the request unique, or NULL to 
create one
  * @return serial_id of the transfer
  */
 uint64_t
@@ -79,7 +80,8 @@ TALER_FAKEBANK_make_transfer (struct TALER_FAKEBANK_Handle *h,
                               const struct TALER_Amount *amount,
                               const struct
                               TALER_WireTransferIdentifierRawP *subject,
-                              const char *exchange_base_url);
+                              const char *exchange_base_url,
+                              const struct GNUNET_HashCode *request_uid);
 
 
 /**

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



reply via email to

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