gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 03/05: worked on policy upload payment


From: gnunet
Subject: [taler-anastasis] 03/05: worked on policy upload payment
Date: Mon, 21 Dec 2020 11:42:11 +0100

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

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit 668b727c9db1e96104cfeb01a5165c78fdbe03de
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Fri Dec 18 15:14:48 2020 +0100

    worked on policy upload payment
---
 src/cli/Makefile.am                                |   2 +-
 .../test_anastasis_reducer_add_authentication.sh   |   6 +-
 .../test_anastasis_reducer_done_authentication.sh  |   6 +-
 .../test_anastasis_reducer_done_policy_review.sh   |   6 +-
 src/cli/test_anastasis_reducer_enter_secret.sh     | 132 +++++--
 ...test_anastasis_reducer_enter_user_attributes.sh |   6 +-
 src/cli/test_anastasis_reducer_select_country.sh   |   4 +-
 src/cli/test_reducer.conf                          |  18 +-
 src/lib/Makefile.am                                |   1 +
 src/lib/anastasis_api_backup_redux.c               | 403 +++++++++++++++++----
 src/lib/anastasis_api_policy_store.c               |   5 +
 src/lib/test_anastasis_api.conf                    |   4 +
 12 files changed, 464 insertions(+), 129 deletions(-)

diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am
index 0eabb1b..5973356 100644
--- a/src/cli/Makefile.am
+++ b/src/cli/Makefile.am
@@ -32,7 +32,7 @@ EXTRA_DIST = \
   test_anastasis_reducer_1.conf \
   test_anastasis_reducer_2.conf \
   test_anastasis_reducer_3.conf \
-  test_reducer_home/ressources
+  test_reducer_home/resources
 
 anastasis_reducer_SOURCES = \
   anastasis-cli-redux.c
diff --git a/src/cli/test_anastasis_reducer_add_authentication.sh 
b/src/cli/test_anastasis_reducer_add_authentication.sh
index 01dc872..6968e39 100755
--- a/src/cli/test_anastasis_reducer_add_authentication.sh
+++ b/src/cli/test_anastasis_reducer_add_authentication.sh
@@ -28,9 +28,9 @@ function cleanup()
 # Install cleanup handler (except for kill -9)
 SFILE=`mktemp test_reducer_stateXXXXXX`
 TFILE=`mktemp test_reducer_stateXXXXXX`
-UFILE=ressources/test_reducer_stateAESTATE
+UFILE=resources/test_reducer_stateAESTATE
 # Tempfile used by other test
-VFILE=ressources/test_reducer_stateAESTATE_FINAL
+VFILE=resources/test_reducer_stateAESTATE_FINAL
 
 
 trap cleanup EXIT
@@ -91,7 +91,7 @@ then
 fi
 
 #Third method
-mkdir -p ressources
+mkdir -p resources
 touch $VFILE
 ./anastasis-reducer -a \
   '{"authentication_method": {
diff --git a/src/cli/test_anastasis_reducer_done_authentication.sh 
b/src/cli/test_anastasis_reducer_done_authentication.sh
index 10aabf3..b85ced1 100755
--- a/src/cli/test_anastasis_reducer_done_authentication.sh
+++ b/src/cli/test_anastasis_reducer_done_authentication.sh
@@ -25,9 +25,9 @@ function cleanup()
 }
 
 # Install cleanup handler (except for kill -9)
-UFILE=ressources/test_reducer_stateAESTATE_FINAL
+UFILE=resources/test_reducer_stateAESTATE_FINAL
 # Tempfile used by other test
-VFILE=ressources/test_reducer_statePRSTATE
+VFILE=resources/test_reducer_statePRSTATE
 
 
 trap cleanup EXIT
@@ -43,7 +43,7 @@ echo "Beginning with actual reducer test"
 # Test done authentication in a backup state
 echo " "
 echo "Test done authentication (next) in a backup state"
-mkdir -p ressources
+mkdir -p resources
 touch $VFILE
 ./anastasis-reducer -a \
   '{}' \
diff --git a/src/cli/test_anastasis_reducer_done_policy_review.sh 
b/src/cli/test_anastasis_reducer_done_policy_review.sh
index 7f463c3..963fcc3 100755
--- a/src/cli/test_anastasis_reducer_done_policy_review.sh
+++ b/src/cli/test_anastasis_reducer_done_policy_review.sh
@@ -25,9 +25,9 @@ function cleanup()
 }
 
 # Install cleanup handler (except for kill -9)
-UFILE=ressources/test_reducer_statePRSTATE
+UFILE=resources/test_reducer_statePRSTATE
 # Tempfile used by other test
-VFILE=ressources/test_reducer_stateSESTATE
+VFILE=resources/test_reducer_stateSESTATE
 
 
 trap cleanup EXIT
@@ -43,7 +43,7 @@ echo "Beginning with actual reducer test"
 # Test done policy review in a backup state
 echo " "
 echo "Test done policy review (next) in a backup state"
-mkdir -p ressources
+mkdir -p resources
 touch $VFILE
 ./anastasis-reducer -a \
   '{}' \
diff --git a/src/cli/test_anastasis_reducer_enter_secret.sh 
b/src/cli/test_anastasis_reducer_enter_secret.sh
index ef6e28f..7f50c25 100755
--- a/src/cli/test_anastasis_reducer_enter_secret.sh
+++ b/src/cli/test_anastasis_reducer_enter_secret.sh
@@ -39,8 +39,9 @@ CONF_1=`mktemp test_reducerXXXXXX_1.conf`
 CONF_2=`mktemp test_reducerXXXXXX_2.conf`
 CONF_3=`mktemp test_reducerXXXXXX_3.conf`
 CONF_4=`mktemp test_reducerXXXXXX_4.conf`
-SFILE=ressources/test_reducer_stateSESTATE
-TFILE=ressources/test_reducer_statePPSTATE
+SFILE=resources/test_reducer_stateSESTATE
+TFILE=resources/test_reducer_statePPSTATE
+UFILE=resources/test_reducer_stateBFSTATE
 
 trap cleanup EXIT
 
@@ -68,14 +69,14 @@ echo " FOUND"
 if [ -e $SFILE ]
 then
     echo " "
-    echo "Ressources existing"
+    echo "Resources existing"
 else
     echo " "
-    echo "Ressources not existing..."
-    echo "Setting up ressources..."
-    # run other tests before to set up ressources
+    echo "Resources not existing..."
+    echo "Setting up resources..."
+    # run other tests before to set up resources
     make check 
-    echo "Ressources created"
+    echo "Resources created"
 fi
 
 # Name of the Postgres database we will use for the script.
@@ -126,6 +127,11 @@ MERCHANT_URL=http://localhost:${MERCHANT_PORT}/
 BANK_PORT=`taler-config -c $CONF -s BANK -o HTTP_PORT`
 BANK_URL=http://localhost:${BANK_PORT}/
 AUDITOR_URL=http://localhost:8083/
+AUDITOR_PRIV_FILE=`taler-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE`
+AUDITOR_PRIV_DIR=`dirname $AUDITOR_PRIV_FILE`
+mkdir -p $AUDITOR_PRIV_DIR
+gnunet-ecc -g1 $AUDITOR_PRIV_FILE > /dev/null
+AUDITOR_PUB=`gnunet-ecc -p $AUDITOR_PRIV_FILE`
 
 # patch configuration
 taler-config -c $CONF -s exchange -o MASTER_PUBLIC_KEY -V $MASTER_PUB
@@ -135,32 +141,33 @@ taler-config -c $CONF -s auditordb-postgres -o CONFIG -V 
postgres:///$TALER_DB
 taler-config -c $CONF -s merchantdb-postgres -o CONFIG -V postgres:///$TALER_DB
 taler-config -c $CONF -s bank -o database -V postgres:///$TALER_DB
 taler-config -c $CONF -s exchange -o KEYDIR -V "${TMP_DIR}/keydir/"
+taler-config -c $CONF -s exchange -o REVOCATION_DIR -V "${TMP_DIR}/revdir/"
 
 # setup exchange
 echo "Setting up exchange"
 taler-exchange-dbinit -c $CONF
-taler-exchange-wire -c $CONF 2> taler-exchange-wire.log
-taler-exchange-keyup -L INFO -c $CONF -o e2a.dat 2> taler-exchange-keyup.log
 
 # setup auditor
 echo "Setting up auditor"
 taler-auditor-dbinit -c $CONF
 taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL
-taler-auditor-sign -c $CONF -u $AUDITOR_URL -r e2a.dat -o a2e.dat -m 
$MASTER_PUB
-rm -f e2a.dat
-
-# provide auditor's signature to exchange
-ABD=`taler-config -c $CONF -s EXCHANGEDB -o AUDITOR_BASE_DIR -f`
-mkdir -p $ABD
-mv a2e.dat $ABD
 
 # Launch services
 echo "Launching taler service"
 taler-bank-manage-testing $CONF postgres:///$TALER_DB serve &
+TFN=`which taler-exchange-httpd`
+TBINPFX=`dirname $TFN`
+TLIBEXEC=${TBINPFX}/../lib/taler/libexec/
+$TLIBEXEC/taler-helper-crypto-eddsa -c $CONF 2> taler-helper-crypto-eddsa.log &
+SIGNKEY_HELPER_PID=$!
+$TLIBEXEC/taler-helper-crypto-rsa -c $CONF 2> taler-helper-crypto-rsa.log &
+DENOM_HELPER_PID=$!
 taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log &
+EXCHANGE_PID=$!
 taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log &
+MERCHANT_PID=$!
 taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log &
-taler-auditor-httpd -c $CONF 2> taler-auditor-httpd.log &
+taler-auditor-httpd -L INFO -c $CONF 2> taler-auditor-httpd.log &
 
 echo "Launching anastasis service"
 valgrind anastasis-httpd -c $CONF_1 2> anastasis-httpd_1.log &
@@ -168,21 +175,79 @@ valgrind anastasis-httpd -c $CONF_2 2> 
anastasis-httpd_2.log &
 valgrind anastasis-httpd -c $CONF_3 2> anastasis-httpd_3.log &
 valgrind anastasis-httpd -c $CONF_4 2> anastasis-httpd_4.log &
 
-# Wait for anastasis service to be available
-for n in `seq 1 100`
+# Wait for bank to be available (usually the slowest)
+for n in `seq 1 50`
+do
+    echo -n "."
+    sleep 0.2
+    OK=0
+    # bank
+    wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    OK=1
+    break
+done
+
+if [ 1 != $OK ]
+then
+    exit_skip "Failed to launch services (bank)"
+fi
+
+# Wait for all other taler services to be available
+for n in `seq 1 50`
 do
     echo -n "."
     sleep 0.1
     OK=0
     # exchange
-    wget http://localhost:8081/ -o /dev/null -O /dev/null >/dev/null || 
continue
+    wget http://localhost:8081/seed -o /dev/null -O /dev/null >/dev/null || 
continue
     # merchant
     wget http://localhost:9966/ -o /dev/null -O /dev/null >/dev/null || 
continue
-    # bank
-    wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || 
continue
-    # Auditor
+    # auditor
     wget http://localhost:8083/ -o /dev/null -O /dev/null >/dev/null || 
continue
-    # anastasis_01
+    OK=1
+    break
+done
+
+if [ 1 != $OK ]
+then
+    exit_skip "Failed to launch taler services"
+fi
+
+echo -n "Setting up keys"
+taler-exchange-offline -c $CONF \
+  download sign \
+  enable-account payto://x-taler-bank/localhost/Exchange \
+  enable-auditor $AUDITOR_PUB $AUDITOR_URL "TESTKUDOS Auditor" \
+  wire-fee now x-taler-bank TESTKUDOS:0.01 TESTKUDOS:0.01 \
+  upload &> taler-exchange-offline.log
+
+echo -n "."
+
+for n in `seq 1 2`
+do
+    echo -n "."
+    OK=0
+    # bank
+    wget --timeout=1 http://localhost:8081/keys -o /dev/null -O /dev/null 
>/dev/null || continue
+    OK=1
+    break
+done
+
+if [ 1 != $OK ]
+then
+    exit_skip "Failed to setup keys"
+fi
+
+taler-auditor-offline -c $CONF \
+  download sign upload &> taler-auditor-offline.log
+
+# Wait for anastasis services to be available
+for n in `seq 1 50`
+do
+    echo -n "."
+    sleep 0.1
+    OK=0
+   # anastasis_01
     wget http://localhost:8086/ -o /dev/null -O /dev/null >/dev/null || 
continue
     # anastasis_02
     wget http://localhost:8087/ -o /dev/null -O /dev/null >/dev/null || 
continue
@@ -213,7 +278,7 @@ echo -e $COLOR$BOLD"Beginning with actual reducer 
test"$NORM$NOCOLOR
 # Test enter secret in a backup state
 echo " "
 echo -e $COLOR$BOLD"Test enter secret in a backup state"$NORM$NOCOLOR
-mkdir -p ressources
+mkdir -p resources
 touch $TFILE
 ./anastasis-reducer -a \
   '{"secret": "veryhardtoguesssecret",
@@ -223,7 +288,7 @@ touch $TFILE
 STATE=`jq -r -e .backup_state < $TFILE`
 if test "$STATE" != "POLICIES_PAYING"
 then
-    exit_fail "Expected new state to be BACKUP_FINISHED, got $STATE"
+    exit_fail "Expected new state to be POLICIES_PAYING, got $STATE"
 fi
 
 ARRAY_LENGTH=`jq -r -e '.truth_uploads | length' < $TFILE`
@@ -271,4 +336,19 @@ echo " "
 echo -e $COLOR$BOLD"Running wallet run-pending"$NORM$NOCOLOR
 taler-wallet-cli --wallet-db=$WALLET_DB run-pending
 
+echo -e $COLOR$BOLD"Payment done"$NORM$NOCOLOR
+echo " "
+echo " "
+echo -e $COLOR$BOLD"Try to upload again"$NORM$NOCOLOR
+touch $UFILE
+./anastasis-reducer -a \
+  '{}' \
+  pay $TFILE $UFILE
+
+STATE=`jq -r -e .backup_state < $UFILE`
+if test "$STATE" != "BACKUP_FINISHED"
+then
+    exit_fail "Expected new state to be BACKUP_FINISHED, got $STATE"
+fi
+
 exit 0
diff --git a/src/cli/test_anastasis_reducer_enter_user_attributes.sh 
b/src/cli/test_anastasis_reducer_enter_user_attributes.sh
index c29fdf5..1cf50aa 100755
--- a/src/cli/test_anastasis_reducer_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_enter_user_attributes.sh
@@ -25,9 +25,9 @@ function cleanup()
 }
 
 # Install cleanup handler (except for kill -9)
-UFILE=ressources/test_reducer_stateUACSTATE
+UFILE=resources/test_reducer_stateUACSTATE
 # Tempfile used other test
-VFILE=ressources/test_reducer_stateAESTATE
+VFILE=resources/test_reducer_stateAESTATE
 
 trap cleanup EXIT
 
@@ -42,7 +42,7 @@ echo "Beginning with actual reducer test"
 # Test user attributes collection in a backup state
 echo " "
 echo "Test user attributes collection in a backup state"
-mkdir -p ressources
+mkdir -p resources
 touch $VFILE
 ./anastasis-reducer -a \
   '{"identity_attributes": {
diff --git a/src/cli/test_anastasis_reducer_select_country.sh 
b/src/cli/test_anastasis_reducer_select_country.sh
index dfa8593..03a79ff 100755
--- a/src/cli/test_anastasis_reducer_select_country.sh
+++ b/src/cli/test_anastasis_reducer_select_country.sh
@@ -33,7 +33,7 @@ CONF_4=`mktemp test_reducerXXXXXX_4.conf`
 SFILE=`mktemp test_reducer_stateXXXXXX`
 TFILE=`mktemp test_reducer_stateXXXXXX`
 # Tempfile used by other test
-UFILE=ressources/test_reducer_stateUACSTATE
+UFILE=resources/test_reducer_stateUACSTATE
 
 trap cleanup EXIT
 
@@ -113,7 +113,7 @@ echo " "
 echo "Test country selection in a backup state"
 ./anastasis-reducer -b $SFILE
 ./anastasis-reducer -a '{"continent": "Europe"}' select_continent $SFILE $TFILE
-mkdir -p ressources
+mkdir -p resources
 touch $UFILE
 ./anastasis-reducer -a \
   '{"country": "Switzerland", 
diff --git a/src/cli/test_reducer.conf b/src/cli/test_reducer.conf
index fb6aec0..32e91a0 100644
--- a/src/cli/test_reducer.conf
+++ b/src/cli/test_reducer.conf
@@ -8,9 +8,14 @@ UNIXPATH_MODE = 660
 PORT = 8081
 BASE_URL = http://localhost:8081/
 SIGNKEY_DURATION = 4 weeks
+SIGNKEY_LEGAL_DURATION = 2 years
 LEGAL_DURATION = 2 years
 LOOKAHEAD_SIGN = 32 weeks 1 day
 LOOKAHEAD_PROVIDE = 4 weeks 1 day
+KEYDIR = ${TALER_DATA_HOME}/exchange/live-keys/
+REVOCATION_DIR = ${TALER_DATA_HOME}/exchange/revocations/
+TERMS_ETAG = 0
+PRIVACY_ETAG = 0
 
 [merchant]
 SERVE = tcp
@@ -41,6 +46,7 @@ PORT = 8083
 AUDITOR_URL = http://localhost:8083/
 TINY_AMOUNT = TESTKUDOS:0.01
 AUDITOR_PRIV_FILE = ${TALER_DATA_HOME}/auditor/offline-keys/auditor.priv
+BASE_URL = "http://localhost:8083/";
 
 [PATHS]
 TALER_HOME = ${PWD}/test_reducer_home/
@@ -60,17 +66,9 @@ ALLOW_REGISTRATIONS = YES
 SERVE = http
 
 [exchangedb]
-AUDITOR_BASE_DIR = ${TALER_DATA_HOME}/auditors/
-WIREFEE_BASE_DIR = ${TALER_DATA_HOME}/exchange/wirefees/
 IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
 LEGAL_RESERVE_EXPIRATION_TIME = 7 years
 
-[exchange_keys]
-signkey_duration = 4 weeks
-legal_duration = 2 years
-lookahead_sign = 32 weeks 1 day
-lookahead_provide = 4 weeks 1 day
-
 [taler]
 CURRENCY = TESTKUDOS
 CURRENCY_ROUND_UNIT = TESTKUDOS:0.01
@@ -84,10 +82,6 @@ WIRE_GATEWAY_AUTH_METHOD = basic
 USERNAME = Exchange
 PASSWORD = x
 
-[exchange-offline]
-MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
-SECM_TOFU_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
-
 [merchant-exchange-default]
 EXCHANGE_BASE_URL = http://localhost:8081/
 CURRENCY = TESTKUDOS
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 44fae35..91e5e1f 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -118,6 +118,7 @@ libanastasisredux_la_LIBADD = \
   -lgnunetutil \
   -ltalermhd \
   -ltalerutil \
+  -ltalerexchange \
   -ltalermerchant \
   -ltalerjson \
   -ljansson \
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 5e3efe9..ea0a363 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -1215,6 +1215,69 @@ check_uploads (json_t *uploads,
 }
 
 
+/**
+ * Initialize payment details array.
+ *
+ * @param state state to operate on
+ * @param pds[OUT] payment details array
+ */
+static unsigned int
+initialize_payment_details (json_t *state,
+                            struct ANASTASIS_PaymentDetails *pds)
+{
+  size_t index;
+  json_t *upload;
+  json_t *rec_doc_uploads = json_object_get (state,
+                                             "recovery_document_uploads");
+  unsigned int pds_len = 0;
+
+  if (json_array_size (rec_doc_uploads) > 0)
+  {
+    json_array_foreach (rec_doc_uploads, index, upload)
+    {
+      struct ANASTASIS_PaymentDetails p_details;
+
+      const char *pay_uri = json_string_value (
+        json_object_get (upload,
+                         "pay_url"));
+      const char *provider_url = json_string_value (
+        json_object_get (upload,
+                         "provider_url"));
+      if ((NULL != pay_uri) &&
+          (NULL != provider_url))
+      {
+        struct TALER_MERCHANT_PayUriData pd;
+
+        if (GNUNET_OK !=
+            TALER_MERCHANT_parse_pay_uri (pay_uri,
+                                          &pd))
+        {
+          GNUNET_break (0);
+          return 0;
+        }
+        if (GNUNET_OK !=
+            GNUNET_STRINGS_string_to_data (pd.order_id,
+                                           strlen (pd.order_id),
+                                           &p_details.payment_secret,
+                                           sizeof (struct
+                                                   ANASTASIS_PaymentSecretP)))
+        {
+          GNUNET_break (0);
+          TALER_MERCHANT_parse_pay_uri_free (&pd);
+          return 0;
+        }
+        TALER_MERCHANT_parse_pay_uri_free (&pd);
+        p_details.provider_url = GNUNET_strdup (provider_url);
+
+        GNUNET_array_append (pds,
+                             pds_len,
+                             p_details);
+      }
+    }
+  }
+  return pds_len;
+}
+
 /**
  * Initialize policies for recovery document.
  *
@@ -1229,6 +1292,10 @@ initialize_policies (json_t *state)
                                            "policies");
 
   GNUNET_assert (json_is_array (json_policies));
+  json_t *truth_uploads = json_object_get (state,
+                                           "truth_uploads");
+
+  GNUNET_assert (json_is_array (truth_uploads));
   json_t *rec_doc_uploads = json_array ();
 
   GNUNET_assert (json_is_array (rec_doc_uploads));
@@ -1245,14 +1312,36 @@ initialize_policies (json_t *state)
                         index,
                         auth_method)
     {
+      size_t tu_index;
+      json_t *tu;
       unsigned int auth_method_index = json_integer_value (json_object_get (
                                                              auth_method,
                                                              
"authentication_method"));
-      GNUNET_assert (NULL != tus_arr[0]->truth);
-      GNUNET_assert (NULL != tus_arr[auth_method_index]->truth);
-      truths[truth_index] = tus_arr[auth_method_index]->truth;
-      truth_index++;
-
+      json_array_foreach (truth_uploads, tu_index, tu)
+      {
+        json_t *json_truth
+          = json_array_get (json_object_get (state, "truths"),
+                            json_integer_value (
+                              json_object_get (tu, "truth_index")));
+        if (json_integer_value (
+              json_object_get (json_truth, "auth_method_index"))
+            == auth_method_index)
+        {
+          struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
+          const char *tus_str = json_string_value (
+            json_object_get (tu,
+                             "tus_string"));
+          GNUNET_assert (GNUNET_OK ==
+                         GNUNET_STRINGS_string_to_data (
+                           tus_str,
+                           strlen (tus_str),
+                           tus,
+                           sizeof (struct TruthUploadState)));
+          truths[truth_index] = tus->truth;
+          truth_index++;
+          break;
+        }
+      }
       {
         // initialize recovery document uploads array
         bool existing = false;
@@ -1521,6 +1610,8 @@ upload_rec_documents (json_t *state,
     initialize_policies (state);
   }
   struct SecretShareState *sss = GNUNET_new (struct SecretShareState);
+  unsigned int pds_len;
+  struct ANASTASIS_PaymentDetails *pds = NULL;
 
   sss->cb = cb;
   sss->cb_cls = cb_cls;
@@ -1557,6 +1648,10 @@ upload_rec_documents (json_t *state,
                                    (void *) sss->core_secret,
                                    sss->core_secret_size);
   }
+
+  pds_len = initialize_payment_details (state,
+                                        pds);
+
   sss->state = json_incref (state);
   // FIXME: implement PaymentDetails
   sss->sso = ANASTASIS_secret_share (ctx,
@@ -1564,8 +1659,10 @@ upload_rec_documents (json_t *state,
                                      NULL,
                                      policy_arr,
                                      policy_arr_length,
-                                     NULL, // FIXME: payment details
-                                     0, // FIXME: payment details
+                                     (pds_len > 0)
+                                     ? pds
+                                     : NULL,
+                                     pds_len,
                                      &secret_share_payment_cb,
                                      sss,
                                      &secret_share_result_cb,
@@ -1618,6 +1715,14 @@ truth_upload_cb (void *cls,
                                   "status",
                                   json_integer ((json_int_t) 204)));
   tus->truth = t;
+  char *tus_string =
+    GNUNET_STRINGS_data_to_string_alloc (tus,
+                                         sizeof (struct TruthUploadState));
+  GNUNET_assert (0 ==
+                 json_object_set (truth_upload,
+                                  "tus_string",
+                                  json_string (tus_string)));
+  GNUNET_free (tus_string);
 
   if (check_uploads (truth_uploads, true) &&
       (json_array_size (
@@ -1681,71 +1786,131 @@ truth_payment_cb (void *cls,
 
 
 /**
- * DispatchHandler/Callback function which is called for a
- * "enter_secret" action.
- * Returns an #ANASTASIS_ReduxAction if operation is async.
+ * Function to upload truths.
  *
  * @param state state to operate on
- * @param arguments arguments to use for operation on state
+ * @param truth_indices indices of truths to upload explicitly
  * @param ctx CURL context
- * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb callback (#ANASTASIS_ActionCallback) to call after upload
  * @param cb_cls callback closure
- * @return NULL
  */
-static struct ANASTASIS_ReduxAction *
-enter_secret (json_t *state,
-              const json_t *arguments,
-              struct GNUNET_CURL_Context *ctx,
-              ANASTASIS_ActionCallback cb,
-              void *cb_cls)
+static void
+upload_truths (json_t *state,
+               json_t *truth_indices,
+               struct GNUNET_CURL_Context *ctx,
+               ANASTASIS_ActionCallback cb,
+               void *cb_cls)
 {
-  if (NULL != ra)
-    GNUNET_free (ra);
+  size_t truth_index;
+  size_t truth_indices_size;
+  json_t *truth;
+  json_t *truths = json_object_get (state,
+                                    "truths");
 
-  if (NULL == arguments)
-  {
-    json_t *error = json_pack ("{s:I, s:s}",
-                               "code",
-                               (json_int_t) ANASTASIS_EC_INVALID,
-                               "hint",
-                               "Arguments missing!");
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID,
-        error);
-    return NULL;
-  }
-  GNUNET_assert (NULL != state);
+  GNUNET_assert (json_is_array (truths));
+  json_t *truth_uploads = json_object_get (state,
+                                           "truth_uploads");
 
-  if ((NULL == json_object_get (arguments,"secret"))
-      || (NULL == json_object_get (arguments, "type")))
+  GNUNET_assert (json_is_array (truth_uploads));
+  size_t truth_uploads_size = json_array_size (truth_uploads);
+  size_t truths_size = json_array_size (truths);
+
+  if (NULL != truth_indices)
+    truth_indices_size = json_array_size (truth_indices);
+
+  if (truth_uploads_size == truths_size)
   {
-    json_t *error = json_pack ("{s:I, s:s}",
-                               "code",
-                               (json_int_t)
-                               ANASTASIS_EC_GENERIC_PARAMETER_MALFORMED,
-                               "hint",
-                               "Secret is malformed!");
-    cb (cb_cls,
-        ANASTASIS_EC_INVALID,
-        error);
-    return NULL;
+    if (! check_uploads (truth_uploads, true))
+    {
+      json_array_foreach (truths, truth_index, truth)
+      {
+        for (unsigned int i = 0; i < tus_arr_length; i++)
+        {
+          if (truth_index == tus_arr[i]->index)
+          {
+            tus_arr[i]->tuo = ANASTASIS_truth_upload (tus_arr[i]->ctx,
+                                                      &tus_arr[i]->user_id,
+                                                      
tus_arr[i]->anastasis_url,
+                                                      tus_arr[i]->method,
+                                                      tus_arr[i]->instructions,
+                                                      tus_arr[i]->mime_type,
+                                                      
&tus_arr[i]->backend_salt,
+                                                      tus_arr[i]->truth_data,
+                                                      tus_arr[i]->
+                                                      truth_data_size,
+                                                      &truth_payment_cb,
+                                                      tus_arr[i],
+                                                      &truth_upload_cb,
+                                                      tus_arr[i]);
+            if (NULL == tus_arr[i]->tuo)
+            {
+              GNUNET_break (0);
+              return;
+            }
+            break;
+          }
+        }
+      }
+    }
+    return;
   }
-  GNUNET_assert (0 ==
-                 json_object_set (state,
-                                  "core_secret",
-                                  json_deep_copy (arguments)));
+  else if ((NULL != truth_indices) &&
+           (truth_indices_size != truths_size))
   {
-    // upload truths
-    size_t truth_index;
-    json_t *truth;
-    json_t *truths = json_object_get (state,
-                                      "truths");
+    GNUNET_assert (json_is_array (truth_indices));
 
-    GNUNET_assert (json_is_array (truths));
-    GNUNET_assert (0 ==
-                   json_object_set_new (state,
-                                        "truth_uploads",
-                                        json_array ()));
+    json_array_foreach (truth_indices, truth_index, truth)
+    {
+      for (unsigned int i = 0; i < truths_size; i++)
+      {
+        if ((int) json_integer_value (truth) == tus_arr[i]->index)
+        {
+          tus_arr[i]->tuo = ANASTASIS_truth_upload (tus_arr[i]->ctx,
+                                                    &tus_arr[i]->user_id,
+                                                    tus_arr[i]->anastasis_url,
+                                                    tus_arr[i]->method,
+                                                    tus_arr[i]->instructions,
+                                                    tus_arr[i]->mime_type,
+                                                    &tus_arr[i]->backend_salt,
+                                                    tus_arr[i]->truth_data,
+                                                    
tus_arr[i]->truth_data_size,
+                                                    &truth_payment_cb,
+                                                    tus_arr[i],
+                                                    &truth_upload_cb,
+                                                    tus_arr[i]);
+          if (NULL == tus_arr[i]->tuo)
+          {
+            GNUNET_break (0);
+            return;
+          }
+          break;
+        }
+      }
+    }
+  }
+  else
+  {
+    // first run or full retry
+    if (0 != tus_arr_length)
+    {
+      for (unsigned int i = 0; i < tus_arr_length; i++)
+      {
+        if (NULL != tus_arr[i]->tuo)
+        {
+          ANASTASIS_truth_upload_cancel (tus_arr[i]->tuo);
+          tus_arr[i]->tuo = NULL;
+        }
+        GNUNET_free (tus_arr[i]);
+      }
+      tus_arr_length = 0;
+    }
+    if (0 != truth_uploads_size)
+    {
+      GNUNET_assert (0 ==
+                     json_object_set (state,
+                                      "truth_uploads",
+                                      json_array ()));
+    }
     json_array_foreach (truths, truth_index, truth)
     {
       struct TruthUploadState *tus = GNUNET_new (struct TruthUploadState);
@@ -1782,8 +1947,10 @@ enter_secret (json_t *state,
       }
       // FIXME: other method types
 
-      json_t *truth_upload = json_pack ("{s:I}",
-                                        "status", 0);
+      json_t *truth_upload = json_pack ("{s:I, s:I}",
+                                        "status", (json_int_t) 0,
+                                        "truth_index",
+                                        (json_int_t) truth_index);
       GNUNET_assert (0 ==
                      json_array_append_new (json_object_get (state,
                                                              "truth_uploads"),
@@ -1810,17 +1977,16 @@ enter_secret (json_t *state,
       if (NULL == tus->tuo)
       {
         GNUNET_break (0);
-        return NULL;
+        return;
       }
     }
   }
-  return ra;
 }
 
 
 /**
  * DispatchHandler/Callback function which is called for a
- * "pay_policy" action.
+ * "enter_secret" action.
  * Returns an #ANASTASIS_ReduxAction if operation is async.
  *
  * @param state state to operate on
@@ -1831,12 +1997,15 @@ enter_secret (json_t *state,
  * @return NULL
  */
 static struct ANASTASIS_ReduxAction *
-pay_policy (json_t *state,
-            const json_t *arguments,
-            struct GNUNET_CURL_Context *ctx,
-            ANASTASIS_ActionCallback cb,
-            void *cb_cls)
+enter_secret (json_t *state,
+              const json_t *arguments,
+              struct GNUNET_CURL_Context *ctx,
+              ANASTASIS_ActionCallback cb,
+              void *cb_cls)
 {
+  if (NULL != ra)
+    GNUNET_free (ra);
+
   if (NULL == arguments)
   {
     json_t *error = json_pack ("{s:I, s:s}",
@@ -1849,11 +2018,93 @@ pay_policy (json_t *state,
         error);
     return NULL;
   }
-  // FIXME: implement
-  cb (cb_cls,
-      ANASTASIS_EC_NONE,
-      state);
-  return NULL;
+  GNUNET_assert (NULL != state);
+
+  if ((NULL == json_object_get (arguments,"secret"))
+      || (NULL == json_object_get (arguments, "type")))
+  {
+    json_t *error = json_pack ("{s:I, s:s}",
+                               "code",
+                               (json_int_t)
+                               ANASTASIS_EC_GENERIC_PARAMETER_MALFORMED,
+                               "hint",
+                               "Secret is malformed!");
+    cb (cb_cls,
+        ANASTASIS_EC_INVALID,
+        error);
+    return NULL;
+  }
+  GNUNET_assert (0 ==
+                 json_object_set (state,
+                                  "core_secret",
+                                  json_deep_copy (arguments)));
+  json_t *truths = json_object_get (state,
+                                    "truths");
+  GNUNET_assert (0 ==
+                 json_object_set_new (state,
+                                      "truth_uploads",
+                                      json_array ()));
+  upload_truths (state,
+                 truths,
+                 ctx,
+                 cb,
+                 cb_cls);
+  return ra;
+}
+
+
+/**
+ * DispatchHandler/Callback function which is called for a
+ * "pay" action.
+ * Returns an #ANASTASIS_ReduxAction if operation is async.
+ *
+ * @param state state to operate on
+ * @param arguments arguments to use for operation on state
+ * @param ctx CURL context
+ * @param cb callback (#DispatchHandler) to call during/after operation
+ * @param cb_cls callback closure
+ * @return NULL
+ */
+static struct ANASTASIS_ReduxAction *
+pay_backup (json_t *state,
+            const json_t *arguments,
+            struct GNUNET_CURL_Context *ctx,
+            ANASTASIS_ActionCallback cb,
+            void *cb_cls)
+{
+  if (NULL != ra)
+    GNUNET_free (ra);
+
+  if (NULL != json_object_get (arguments,
+                               "provider_id"))
+  {
+    // FIXME: implement
+  }
+  else if (NULL != json_object_get (arguments,
+                                    "truth_index"))
+  {
+    // FIXME: implement
+  }
+  else
+  {
+    // try uploading all truths (if not paid) and policies again
+    json_t *truth_uploads = json_object_get (state,
+                                             "truth_uploads");
+
+    GNUNET_assert (json_is_array (truth_uploads));
+    if (check_uploads (truth_uploads, true))
+      upload_rec_documents (state,
+                            ctx,
+                            cb,
+                            cb_cls);
+    else
+      upload_truths (state,
+                     NULL,
+                     ctx,
+                     cb,
+                     cb_cls);
+  }
+  return ra;
 }
 
 
@@ -1969,7 +2220,7 @@ ANASTASIS_backup_action_ (struct GNUNET_CURL_Context *ctx,
     {
       ANASTASIS_BACKUP_STATE_POLICIES_PAYING,
       "pay",
-      &pay_policy
+      &pay_backup
     },
     {
       ANASTASIS_BACKUP_STATE_BACKUP_FINISHED,
diff --git a/src/lib/anastasis_api_policy_store.c 
b/src/lib/anastasis_api_policy_store.c
index d1418f6..190b2c1 100644
--- a/src/lib/anastasis_api_policy_store.c
+++ b/src/lib/anastasis_api_policy_store.c
@@ -191,6 +191,11 @@ handle_policy_store_finished (void *cls,
                 (const char *) data);
     break;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "At %s:%d Response code is: %i\n",
+              __FILE__,
+              __LINE__,
+              (int) response_code);
   if (NULL != pso->cb)
   {
     pso->cb (pso->cb_cls,
diff --git a/src/lib/test_anastasis_api.conf b/src/lib/test_anastasis_api.conf
index f956a38..fc8b4f5 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -183,6 +183,10 @@ MASTER_PUBLIC_KEY = 
T1VVFQZZARQ1CMF4BN58EE7SKTW5AV2BS18S87ZEGYS4S29J6DNG
 BASE_URL = "http://localhost:8081/";
 #BASE_URL = https://exchange.test.taler.net/
 
+KEYDIR = ${TALER_DATA_HOME}/exchange/live-keys/
+
+REVOCATION_DIR = ${TALER_DATA_HOME}/exchange/revocations/
+
 
 # Network configuration for the normal API/service HTTP server
 # serve via tcp socket (on PORT)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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