gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-merchant] branch master updated (c6e834b -> 48de114)


From: gnunet
Subject: [GNUnet-SVN] [taler-merchant] branch master updated (c6e834b -> 48de114)
Date: Wed, 29 Mar 2017 00:25:41 +0200

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

marcello pushed a change to branch master
in repository merchant.

    from c6e834b  adding option to use a remote exchange in the payments 
generator.
     new ab7198d  renaming variables
     new 48de114  stubs for #4781

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/backend/taler-merchant-httpd_pay.c     | 27 ++++++++----
 src/backenddb/plugin_merchantdb_postgres.c |  3 +-
 src/mitm/README                            | 14 ++++++
 src/mitm/mitm.py                           | 69 ++++++++++++++++++++++++++++++
 4 files changed, 104 insertions(+), 9 deletions(-)
 create mode 100644 src/mitm/README
 create mode 100644 src/mitm/mitm.py

diff --git a/src/backend/taler-merchant-httpd_pay.c 
b/src/backend/taler-merchant-httpd_pay.c
index c3203ef..8e835f1 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -269,7 +269,7 @@ struct PayContext
    * #GNUNET_SYSERR if the transaction ID is used for a different
    * transaction in our database.
    */
-  int transaction_exits;
+  int transaction_exists;
 
   /**
    * Instance of the payment's instance (in JSON format)
@@ -883,14 +883,23 @@ check_coin_paid (void *cls,
   for (i=0;i<pc->coins_cnt;i++)
   {
     struct DepositConfirmation *dc = &pc->dc[i];
-
+    /* Get matching coin from results*/
     if ( (0 != memcmp (coin_pub,
                        &dc->coin_pub,
                        sizeof (struct TALER_CoinSpendPublicKeyP))) ||
          (0 != TALER_amount_cmp (amount_with_fee,
                                  &dc->amount_with_fee)) )
       continue;
+
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Coin (%s) already found in our DB.\n",
+                TALER_b2s (coin_pub, sizeof (*coin_pub)));
+
     dc->found_in_db = GNUNET_YES;
+    /**
+     * What happens if a (mad) wallet sends new coins on a
+     * contract that it already paid for?
+     */
     pc->pending--;
   }
 }
@@ -898,7 +907,7 @@ check_coin_paid (void *cls,
 
 /**
  * Check if the existing transaction matches our transaction.
- * Update `transaction_exits` accordingly.
+ * Update `transaction_exists` accordingly.
  *
  * @param cls closure with the `struct PayContext`
  * @param transaction_id of the contract
@@ -932,12 +941,12 @@ check_transaction_exists (void *cls,
        (0 == TALER_amount_cmp (total_amount,
                               &pc->amount) ) )
   {
-    pc->transaction_exits = GNUNET_YES;
+    pc->transaction_exists = GNUNET_YES;
   }
   else
   {
     GNUNET_break_op (0);
-    pc->transaction_exits = GNUNET_SYSERR;
+    pc->transaction_exists = GNUNET_SYSERR;
   }
 }
 
@@ -949,7 +958,6 @@ get_instance (struct json_t *json);
 
 /**
  * Try to parse the pay request into the given pay context.
- *
  * Schedules an error response in the connection on failure.
  *
  *
@@ -1254,6 +1262,9 @@ handler_pay_json (struct MHD_Connection *connection,
   {
     struct MHD_Response *resp;
     int ret;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Payment succeeded in the past; take short cut"
+                " and accept immediately.\n");
 
     /* Payment succeeded in the past; take short cut
        and accept immediately */
@@ -1279,14 +1290,14 @@ handler_pay_json (struct MHD_Connection *connection,
                                              
TALER_EC_PAY_DB_FETCH_TRANSACTION_ERROR,
                                                "Merchant database error");
   }
-  if (GNUNET_SYSERR == pc->transaction_exits)
+  if (GNUNET_SYSERR == pc->transaction_exists)
   {
     GNUNET_break (0);
     return TMH_RESPONSE_reply_external_error (connection,
                                               
TALER_EC_PAY_DB_TRANSACTION_ID_CONFLICT,
                                              "Transaction ID reused with 
different transaction details");
   }
-  if (GNUNET_NO == pc->transaction_exits)
+  if (GNUNET_NO == pc->transaction_exists)
   {
     struct GNUNET_TIME_Absolute now;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/backenddb/plugin_merchantdb_postgres.c 
b/src/backenddb/plugin_merchantdb_postgres.c
index cb05eeb..cad04cd 100644
--- a/src/backenddb/plugin_merchantdb_postgres.c
+++ b/src/backenddb/plugin_merchantdb_postgres.c
@@ -1098,7 +1098,8 @@ postgres_find_transaction (void *cls,
 
 
 /**
- * Lookup information about coin payments by transaction ID (and @a 
merchant_pub)
+ * Lookup information about coin payments by proposal data hash
+ * (and @a merchant_pub)
  *
  * @param cls closure
  * @param transaction_id key for the search
diff --git a/src/mitm/README b/src/mitm/README
new file mode 100644
index 0000000..1b23432
--- /dev/null
+++ b/src/mitm/README
@@ -0,0 +1,14 @@
+
+=== INTRODUCTION ===
+
+This directory contain a Web server that listens for
+requests addressed to the exchange, relays them to the
+exchange, and returns a modified response to the caller.
+
+The modifications are made to test error management in the
+merchant, and are driven by a HTTP header that instructs the
+proxy about the modifications to be made.
+
+=== INVOCATION ===
+
+FIXME
diff --git a/src/mitm/mitm.py b/src/mitm/mitm.py
new file mode 100644
index 0000000..0b6f9bc
--- /dev/null
+++ b/src/mitm/mitm.py
@@ -0,0 +1,69 @@
+#This file is part of TALER
+#Copyright (C) 2014, 2015, 2016, 2017 GNUnet e.V. and INRIA
+#
+#TALER is free software; you can redistribute it and/or modify it under the
+#terms of the GNU Lesser General Public License as published by the Free 
Software
+#Foundation; either version 2.1, 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 Lesser General Public License for more 
details.
+#
+#You should have received a copy of the GNU Lesser General Public License 
along with
+#TALER; see the file COPYING.LGPL.  If not, see <http://www.gnu.org/licenses/>
+
+# @author Marcello Stanisci
+# @brief Error generator for responses coming from the exchange
+
+from flask import (request,
+                   Flask,
+                   jsonify)
+import requests
+from urllib.parse import (urljoin,
+                          urlencode,
+                          urlparse,
+                          urlunparse)
+from pytaler import amount
+import base64
+import os
+import logging
+import json
+from random import randint
+from datetime import datetime
+
+# FIXME make this as a standalone executable, and accept
+# the exchange url as a cli option.
+
+app = Flask(__name__)
+app.secret_key = base64.b64encode(os.urandom(64)).decode('utf-8')
+logger = logging.getLogger(__name__)
+exchange_url = os.environ.get("TALER_EXCHANGE_URL")
+assert(None != exchange_url)
+
+def track_transaction(resp):
+    return resp
+
+def track_transfer(resp):
+    return resp
+
address@hidden('/', defaults={'path': ''})
address@hidden('/<path:path>', methods=["GET", "POST"])
+def all(path):
+    body = request.get_json()
+    url = list(urlparse(request.url))
+    xurl = urlparse(exchange_url)
+    url[0] = xurl[0]
+    url[1] = xurl[1]
+    url = urlunparse(url)
+    print("Querying " + url)
+    r = requests.post(urljoin(url, path), json=body)
+    resp = dict()
+    if "application/json" == r.headers["Content-Type"]:
+        resp = r.json()
+    dispatcher = {
+        "track_transaction": track_transaction,
+        "track_transfer": track_transfer
+    }
+    func = dispatcher.get(request.headers.get("X-Taler-Mitm"),
+                          lambda x: x)
+    return jsonify(func(resp)), r.status_code

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



reply via email to

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