gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (06e2297 -> 819ce6c)


From: gnunet
Subject: [taler-anastasis] branch master updated (06e2297 -> 819ce6c)
Date: Mon, 21 Dec 2020 11:42:08 +0100

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

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

    from 06e2297  remove dead/redundant options
     new be8da86  fix temp config creation
     new 5a6f1fa  Merge branch 'master' of ssh://git.taler.net/anastasis
     new 668b727  worked on policy upload payment
     new e111fa6  worked on re-upload after payment
     new 819ce6c  Merge branch 'master' of ssh://git.taler.net/anastasis

The 5 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/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     | 134 +++++--
 ...test_anastasis_reducer_enter_user_attributes.sh |   6 +-
 src/cli/test_anastasis_reducer_select_continent.sh |   1 -
 src/cli/test_anastasis_reducer_select_country.sh   |   4 +-
 src/cli/test_reducer.conf                          |  18 +-
 src/include/anastasis.h                            |  13 +
 src/lib/Makefile.am                                |   1 +
 src/lib/anastasis.c                                |  33 +-
 src/lib/anastasis_api_backup_redux.c               | 395 +++++++++++++++++----
 src/lib/anastasis_api_policy_store.c               |   5 +
 src/lib/test_anastasis_api.conf                    |   4 +
 15 files changed, 502 insertions(+), 132 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..88b5c98 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,9 +278,9 @@ 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 \
+valgrind .libs/anastasis-reducer -a \
   '{"secret": "veryhardtoguesssecret",
     "type": "password"}' \
   enter_secret $SFILE $TFILE
@@ -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
+valgrind .libs/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_continent.sh 
b/src/cli/test_anastasis_reducer_select_continent.sh
index 404c58c..946686c 100755
--- a/src/cli/test_anastasis_reducer_select_continent.sh
+++ b/src/cli/test_anastasis_reducer_select_continent.sh
@@ -26,7 +26,6 @@ function cleanup()
 }
 
 # Install cleanup handler (except for kill -9)
-CONF=`mktemp test_reducerXXXXXX.conf`
 SFILE=`mktemp test_reducer_stateXXXXXX`
 TFILE=`mktemp test_reducer_stateXXXXXX`
 
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/include/anastasis.h b/src/include/anastasis.h
index f65d52b..028f9fd 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -376,6 +376,19 @@ ANASTASIS_truth_upload_cancel (struct 
ANASTASIS_TruthUpload *tu);
 void
 ANASTASIS_truth_free (struct ANASTASIS_Truth *t);
 
+/**
+* Converts a truth object from string format.
+* @param t object to return size of
+*/
+struct ANASTASIS_Truth *
+ANASTASIS_truth_from_string (const char*t_str);
+
+/**
+* Returns the string format of a truth object.
+* @param t object to return string of
+*/
+char *
+ANASTASIS_truth_to_string (struct ANASTASIS_Truth *t);
 
 /**
 * Policy object to upload
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.c b/src/lib/anastasis.c
index 2cb7703..2458aa1 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -1320,6 +1320,36 @@ ANASTASIS_truth_free (struct ANASTASIS_Truth *t)
 }
 
 
+/**
+* Returns the size of a truth object.
+* @param t object to return size of
+*/
+char *
+ANASTASIS_truth_to_string (struct ANASTASIS_Truth *t)
+{
+  return GNUNET_STRINGS_data_to_string_alloc (t,
+                                              sizeof (*t));
+}
+
+
+/**
+* Converts a truth object from string format.
+* @param t object to return size of
+*/
+struct ANASTASIS_Truth *
+ANASTASIS_truth_from_string (const char*t_str)
+{
+  struct ANASTASIS_Truth *t = GNUNET_new (struct ANASTASIS_Truth);
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_STRINGS_string_to_data (
+                   t_str,
+                   strlen (t_str),
+                   t,
+                   sizeof (struct ANASTASIS_Truth)));
+  return t;
+}
+
+
 /**
 * Policy object to upload
 */
@@ -1794,7 +1824,6 @@ ANASTASIS_get_num_urls (const struct ANASTASIS_Policy 
*policies[],
                                                      * strlen (
                                                        policies[l]->truths[j]->
                                                        url) + 1);
-          // provider[unique_urls_len] = policies[l]->truths[j]->url;
           strcpy (provider[unique_urls_len], policies[l]->truths[j]->url);
           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                       "At %s:%d unique provider url is %s\n", __FILE__,
@@ -1834,6 +1863,8 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
                         size_t core_secret_size)
 {
   struct ANASTASIS_SecretShare *ss;
+
+  GNUNET_assert (policies_len > 0);
   unsigned int pss_length = ANASTASIS_get_num_urls (policies,
                                                     policies_len);
   struct PolicyStoreState *pss[pss_length];
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 5e3efe9..a3e1bd9 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,9 +1292,14 @@ 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));
+
   json_array_foreach (json_policies, p_index, json_policy)
   {
     size_t index;
@@ -1245,14 +1313,29 @@ 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)
+        {
+          const char *t_str = json_string_value (
+            json_object_get (tu,
+                             "truth_string"));
+          truths[truth_index] = ANASTASIS_truth_from_string (t_str);
+          truth_index++;
+          break;
+        }
+      }
       {
         // initialize recovery document uploads array
         bool existing = false;
@@ -1521,6 +1604,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 +1642,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 +1653,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 +1709,12 @@ truth_upload_cb (void *cls,
                                   "status",
                                   json_integer ((json_int_t) 204)));
   tus->truth = t;
+  char *truth_string = ANASTASIS_truth_to_string (tus->truth);
+  GNUNET_assert (0 ==
+                 json_object_set (truth_upload,
+                                  "truth_string",
+                                  json_string (truth_string)));
+  GNUNET_free (truth_string);
 
   if (check_uploads (truth_uploads, true) &&
       (json_array_size (
@@ -1681,71 +1778,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 +1939,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 +1969,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 +1989,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 +2010,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 +2212,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 b13ff85..3be46e4 100644
--- a/src/lib/test_anastasis_api.conf
+++ b/src/lib/test_anastasis_api.conf
@@ -166,6 +166,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]