gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] branch master updated (04827aa -> e715a2d)


From: gnunet
Subject: [taler-anastasis] branch master updated (04827aa -> e715a2d)
Date: Sat, 13 Mar 2021 19:23:22 +0100

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

grothoff pushed a change to branch master
in repository anastasis.

    from 04827aa  fix db name
     new 2f92dc0  fix #6572
     new 893d5b8  fix #6752
     new bb6ccd8  add long polling support for payment on challenge solving
     new b1adb96  remove bogus unique constraint
     new a3c1a10  fix index
     new e715a2d  fix #6748

The 6 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/anastasis-httpd.c                  | 21 +++++-
 src/backend/anastasis-httpd_policy_upload.c    | 28 ++++++--
 src/backend/anastasis-httpd_truth.c            | 95 ++++++++++++++++++++++----
 src/backend/anastasis-httpd_truth_upload.c     |  1 -
 src/include/anastasis.h                        |  6 ++
 src/include/anastasis_service.h                |  3 +
 src/lib/anastasis_recovery.c                   |  6 ++
 src/reducer/anastasis_api_recovery_redux.c     | 25 +++++++
 src/restclient/anastasis_api_keyshare_lookup.c | 55 +++++++++++----
 src/restclient/anastasis_api_truth_store.c     |  1 -
 src/stasis/stasis-0001.sql                     | 15 +++-
 src/testing/testing_api_cmd_keyshare_lookup.c  |  1 +
 src/testing/testing_cmd_challenge_answer.c     |  2 +
 13 files changed, 218 insertions(+), 41 deletions(-)

diff --git a/src/backend/anastasis-httpd.c b/src/backend/anastasis-httpd.c
index 6d3c60f..eca67a9 100644
--- a/src/backend/anastasis-httpd.c
+++ b/src/backend/anastasis-httpd.c
@@ -303,9 +303,14 @@ url_handler (void *cls,
     "<html><title>404: not found</title></html>", 0,
     &TMH_MHD_handler_static_response, MHD_HTTP_NOT_FOUND
   };
-
+  static struct AH_RequestHandler h405 = {
+    "", NULL, "text/html",
+    "<html><title>405: method not allowed</title></html>", 0,
+    &TMH_MHD_handler_static_response, MHD_HTTP_METHOD_NOT_ALLOWED
+  };
   struct TM_HandlerContext *hc = *con_cls;
   const char *correlation_id = NULL;
+  bool path_matched;
 
   if (NULL == hc)
   {
@@ -327,6 +332,9 @@ url_handler (void *cls,
     *con_cls = hc;
     hc->async_scope_id = aid;
   }
+  if (0 == strcasecmp (method,
+                       MHD_HTTP_METHOD_HEAD))
+    method = MHD_HTTP_METHOD_GET; /* MHD will throw away the body */
 
   GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id);
   if (NULL != correlation_id)
@@ -368,13 +376,14 @@ url_handler (void *cls,
     if (0 == strcmp (method,
                      MHD_HTTP_METHOD_POST))
     {
-      // FIXME: need to accumulate upload_data first!
       return AH_handler_policy_post (connection,
                                      hc,
                                      &account_pub,
                                      upload_data,
                                      upload_data_size);
     }
+    return TMH_MHD_handler_static_response (&h405,
+                                            connection);
   }
   if (0 == strncmp (url,
                     "/truth/",
@@ -413,7 +422,10 @@ url_handler (void *cls,
                                     upload_data,
                                     upload_data_size);
     }
+    return TMH_MHD_handler_static_response (&h405,
+                                            connection);
   }
+  path_matched = false;
   for (unsigned int i = 0; NULL != handlers[i].url; i++)
   {
     struct AH_RequestHandler *rh = &handlers[i];
@@ -421,6 +433,7 @@ url_handler (void *cls,
     if (0 == strcmp (url,
                      rh->url))
     {
+      path_matched = true;
       if (0 == strcasecmp (method,
                            MHD_HTTP_METHOD_OPTIONS))
       {
@@ -435,7 +448,9 @@ url_handler (void *cls,
       }
     }
   }
-  // FIXME: HTTP 405? METHOD_NOT_ALLOWED
+  if (path_matched)
+    return TMH_MHD_handler_static_response (&h405,
+                                            connection);
   return TMH_MHD_handler_static_response (&h404,
                                           connection);
 }
diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index 126a3a7..f0107b9 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -415,16 +415,32 @@ check_payment_cb (void *cls,
 
   /* refunds are not supported, verify */
   puc->cpo = NULL;
-  // FIXME: osr could be NULL! check hr first!
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "Payment status checked: %s\n",
-              osr->status ? "paid" : "unpaid");
   GNUNET_CONTAINER_DLL_remove (puc_head,
                                puc_tail,
                                puc);
   MHD_resume_connection (puc->con);
   AH_trigger_daemon (NULL);
-
+  switch (hr->http_status)
+  {
+  case MHD_HTTP_OK:
+    GNUNET_assert (NULL != osr);
+    break; /* processed below */
+  case MHD_HTTP_UNAUTHORIZED:
+    puc->resp = TALER_MHD_make_error (
+      TALER_EC_ANASTASIS_GENERIC_PAYMENT_CHECK_UNAUTHORIZED,
+      NULL);
+    puc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+    return;
+  default:
+    puc->resp = TALER_MHD_make_error (
+      TALER_EC_ANASTASIS_GENERIC_BACKEND_ERROR,
+      "failed to initiate payment");
+    puc->response_code = MHD_HTTP_BAD_GATEWAY;
+    return;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Payment status checked: %s\n",
+              osr->status ? "paid" : "unpaid");
   switch (osr->status)
   {
   case TALER_MERCHANT_OSC_PAID:
@@ -434,7 +450,7 @@ check_payment_cb (void *cls,
       qs = db->increment_lifetime (db->cls,
                                    &puc->account,
                                    &puc->payment_identifier,
-                                   GNUNET_TIME_UNIT_YEARS); /* FIXME: always 
annual ?*/
+                                   GNUNET_TIME_UNIT_YEARS);
       if (0 <= qs)
         return; /* continue as planned */
       GNUNET_break (0);
diff --git a/src/backend/anastasis-httpd_truth.c 
b/src/backend/anastasis-httpd_truth.c
index bf4b182..b02ac0c 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -30,6 +30,13 @@
 #include <taler/taler_merchant_service.h>
 #include <taler/taler_json_lib.h>
 
+/**
+ * What is the maximum frequency at which we allow
+ * clients to attempt to answer security questions?
+ */
+#define MAX_QUESTION_FREQ GNUNET_TIME_relative_multiply ( \
+    GNUNET_TIME_UNIT_SECONDS, 30)
+
 /**
  * How long do we hold an HTTP client connection if
  * we are awaiting payment before giving up?
@@ -110,6 +117,11 @@ struct GetContext
    */
   struct MHD_Response *resp;
 
+  /**
+   * How long do we wait at most for payment?
+   */
+  struct GNUNET_TIME_Absolute timeout;
+
   /**
    * Random authorization code we are using.
    */
@@ -485,12 +497,15 @@ begin_payment (struct GetContext *gc)
   if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
   {
     /* We already created the order, check if it was paid */
+    struct GNUNET_TIME_Relative timeout;
+
+    timeout = GNUNET_TIME_absolute_get_remaining (gc->timeout);
     gc->cpo = TALER_MERCHANT_merchant_order_get (AH_ctx,
                                                  AH_backend_url,
                                                  order_id,
                                                  NULL /* NOT session-bound */,
                                                  false,
-                                                 GNUNET_TIME_UNIT_ZERO,
+                                                 timeout,
                                                  &check_payment_cb,
                                                  gc);
   }
@@ -686,6 +701,38 @@ AH_handler_truth_get (
       gc->have_response = (NULL != challenge_response_s);
     }
 
+    {
+      const char *long_poll_timeout_ms;
+
+      long_poll_timeout_ms = MHD_lookup_connection_value (connection,
+                                                          
MHD_GET_ARGUMENT_KIND,
+                                                          "timeout_ms");
+      if (NULL != long_poll_timeout_ms)
+      {
+        unsigned int timeout;
+
+        if (1 != sscanf (long_poll_timeout_ms,
+                         "%u",
+                         &timeout))
+        {
+          GNUNET_break_op (0);
+          return TALER_MHD_reply_with_error (connection,
+                                             MHD_HTTP_BAD_REQUEST,
+                                             
TALER_EC_GENERIC_PARAMETER_MALFORMED,
+                                             "timeout_ms (must be non-negative 
number)");
+        }
+        gc->timeout
+          = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (
+                                                GNUNET_TIME_UNIT_MILLISECONDS,
+                                                timeout));
+      }
+      else
+      {
+        gc->timeout = GNUNET_TIME_relative_to_absolute (
+          GNUNET_TIME_UNIT_SECONDS);
+      }
+    }
+
   } /* end of first-time initialization (if NULL == gc) */
   else
   {
@@ -894,11 +941,40 @@ AH_handler_truth_get (
                                          
TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED,
                                          NULL);
     }
-    // FIXME: do something here to rate-limit
-    // brute force attempts (by checking against the timestamp
-    // from 'mark_challenge_sent' and refusing if the response
-    // is provided too quickly again!
 
+    {
+      enum GNUNET_DB_QueryStatus qs;
+      struct GNUNET_TIME_Absolute rt;
+      uint64_t code;
+
+      rt = GNUNET_TIME_UNIT_FOREVER_ABS;
+      qs = db->create_challenge_code (db->cls,
+                                      &gc->truth_uuid,
+                                      MAX_QUESTION_FREQ,
+                                      GNUNET_TIME_UNIT_HOURS,
+                                      UINT32_MAX,
+                                      &rt,
+                                      &code);
+      if (0 > qs)
+      {
+        GNUNET_break (0 < qs);
+        GNUNET_free (decrypted_truth);
+        GNUNET_free (truth_mime);
+        return TALER_MHD_reply_with_error (connection,
+                                           MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                           TALER_EC_GENERIC_DB_FETCH_FAILED,
+                                           "create_challenge_code (for rate 
limiting)");
+      }
+      if (0 != rt.abs_value_us)
+      {
+        GNUNET_free (decrypted_truth);
+        GNUNET_free (truth_mime);
+        return TALER_MHD_reply_with_error (connection,
+                                           MHD_HTTP_TOO_MANY_REQUESTS,
+                                           
TALER_EC_ANASTASIS_TRUTH_RATE_LIMITED,
+                                           NULL);
+      }
+    }
     if ( (decrypted_truth_size != sizeof (challenge_response)) ||
          (0 != memcmp (&challenge_response,
                        decrypted_truth,
@@ -910,15 +986,6 @@ AH_handler_truth_get (
                   (unsigned int) sizeof (challenge_response));
       GNUNET_free (decrypted_truth);
       GNUNET_free (truth_mime);
-      /* for rate-limiting... */
-#if 0
-      enum GNUNET_DB_QueryStatus qs;
-      // FIXME: fails: this is an UPDATE statement, we need to possibly INSERT 
_or_ UPDATE
-      qs = db->mark_challenge_sent (db->cls,
-                                    &gc->truth_uuid,
-                                    0);
-      GNUNET_break (0 < qs);
-#endif
       return TALER_MHD_reply_with_error (connection,
                                          MHD_HTTP_FORBIDDEN,
                                          
TALER_EC_ANASTASIS_TRUTH_CHALLENGE_FAILED,
diff --git a/src/backend/anastasis-httpd_truth_upload.c 
b/src/backend/anastasis-httpd_truth_upload.c
index 575ff1f..dec029f 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -546,7 +546,6 @@ AH_handler_truth_post (
       }
     }
 
-
   } /* end 'if (NULL == tuc)' */
 
   if (NULL != tuc->resp)
diff --git a/src/include/anastasis.h b/src/include/anastasis.h
index c7b356b..81e2547 100644
--- a/src/include/anastasis.h
+++ b/src/include/anastasis.h
@@ -244,6 +244,7 @@ typedef void
  *
  * @param c reference to the escrow challenge which is started
  * @param psp payment secret, NULL if no payment was yet made
+ * @param timeout how long to wait for payment
  * @param hashed_answer answer to the challenge, NULL if we have none yet
  * @param af reference to the answerfeedback which is passed back to the user
  * @param af_cls closure for @a af
@@ -252,6 +253,7 @@ typedef void
 int
 ANASTASIS_challenge_start (struct ANASTASIS_Challenge *c,
                            const struct ANASTASIS_PaymentSecretP *psp,
+                           struct GNUNET_TIME_Relative timeout,
                            const struct GNUNET_HashCode *hashed_answer,
                            ANASTASIS_AnswerFeedback af,
                            void *af_cls);
@@ -264,6 +266,7 @@ ANASTASIS_challenge_start (struct ANASTASIS_Challenge *c,
  *
  * @param c reference to the challenge which is answered
  * @param psp information about payment made for the recovery
+ * @param timeout how long to wait for payment
  * @param answer user input instruction defines which input is needed
  * @param af reference to the answerfeedback which is passed back to the user
  * @param af_cls closure for @a af
@@ -272,6 +275,7 @@ ANASTASIS_challenge_start (struct ANASTASIS_Challenge *c,
 int
 ANASTASIS_challenge_answer (struct ANASTASIS_Challenge *c,
                             const struct ANASTASIS_PaymentSecretP *psp,
+                            struct GNUNET_TIME_Relative timeout,
                             const char *answer,
                             ANASTASIS_AnswerFeedback af,
                             void *af_cls);
@@ -285,6 +289,7 @@ ANASTASIS_challenge_answer (struct ANASTASIS_Challenge *c,
  *
  * @param c reference to the challenge which is answered
  * @param psp information about payment made for the recovery
+ * @param timeout how long to wait for payment
  * @param answer user input instruction defines which input is needed
  * @param af reference to the answerfeedback which is passed back to the user
  * @param af_cls closure for @a af
@@ -293,6 +298,7 @@ ANASTASIS_challenge_answer (struct ANASTASIS_Challenge *c,
 int
 ANASTASIS_challenge_answer2 (struct ANASTASIS_Challenge *c,
                              const struct ANASTASIS_PaymentSecretP *psp,
+                             struct GNUNET_TIME_Relative timeout,
                              uint64_t answer,
                              ANASTASIS_AnswerFeedback af,
                              void *af_cls);
diff --git a/src/include/anastasis_service.h b/src/include/anastasis_service.h
index 2d9bd90..15f5d19 100644
--- a/src/include/anastasis_service.h
+++ b/src/include/anastasis_service.h
@@ -578,6 +578,8 @@ typedef void
  * @param truth_public_key identification of the Truth
  * @param truth_key Key used to Decrypt the Truth on the Server
  * @param payment_secret secret from the previously done payment NULL to 
trigger payment
+ * @param payment_timeout how long to wait for the payment, use
+ *           #GNUNET_TIME_UNIT_ZERO to let the server pick
  * @param hashed_answer hashed answer to the challenge
  * @param cb callback which will work the response gotten from the backend
  * @param cb_cls closure to pass to the callback
@@ -590,6 +592,7 @@ ANASTASIS_keyshare_lookup (
   const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
   const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key,
   const struct ANASTASIS_PaymentSecretP *payment_secret,
+  struct GNUNET_TIME_Relative timeout,
   const struct GNUNET_HashCode *hashed_answer,
   ANASTASIS_KeyShareLookupCallback cb,
   void *cb_cls);
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index f0bf097..a504a97 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -418,6 +418,7 @@ ANASTASIS_challenge_get_details (struct ANASTASIS_Challenge 
*challenge)
 int
 ANASTASIS_challenge_start (struct ANASTASIS_Challenge *c,
                            const struct ANASTASIS_PaymentSecretP *psp,
+                           struct GNUNET_TIME_Relative timeout,
                            const struct GNUNET_HashCode *hashed_answer,
                            ANASTASIS_AnswerFeedback af,
                            void *af_cls)
@@ -439,6 +440,7 @@ ANASTASIS_challenge_start (struct ANASTASIS_Challenge *c,
                                        &c->ci.uuid,
                                        &c->truth_key,
                                        psp,
+                                       timeout,
                                        hashed_answer,
                                        &keyshare_lookup_cb,
                                        c);
@@ -455,6 +457,7 @@ int
 ANASTASIS_challenge_answer (
   struct ANASTASIS_Challenge *c,
   const struct ANASTASIS_PaymentSecretP *psp,
+  struct GNUNET_TIME_Relative timeout,
   const char *answer_str,
   ANASTASIS_AnswerFeedback af,
   void *af_cls)
@@ -477,6 +480,7 @@ ANASTASIS_challenge_answer (
                    0));
   return ANASTASIS_challenge_start (c,
                                     psp,
+                                    timeout,
                                     &hashed_answer,
                                     af,
                                     af_cls);
@@ -486,6 +490,7 @@ ANASTASIS_challenge_answer (
 int
 ANASTASIS_challenge_answer2 (struct ANASTASIS_Challenge *c,
                              const struct ANASTASIS_PaymentSecretP *psp,
+                             struct GNUNET_TIME_Relative timeout,
                              uint64_t answer,
                              ANASTASIS_AnswerFeedback af,
                              void *af_cls)
@@ -498,6 +503,7 @@ ANASTASIS_challenge_answer2 (struct ANASTASIS_Challenge *c,
                    (unsigned long long) answer);
   return ANASTASIS_challenge_answer (c,
                                      psp,
+                                     timeout,
                                      answer_s,
                                      af,
                                      af_cls);
diff --git a/src/reducer/anastasis_api_recovery_redux.c 
b/src/reducer/anastasis_api_recovery_redux.c
index 4d23e24..934afa6 100644
--- a/src/reducer/anastasis_api_recovery_redux.c
+++ b/src/reducer/anastasis_api_recovery_redux.c
@@ -109,6 +109,11 @@ struct SelectChallengeContext
    */
   struct ANASTASIS_CRYPTO_TruthUUIDP uuid;
 
+  /**
+   * Which timeout was set for the operation?
+   */
+  struct GNUNET_TIME_Relative timeout;
+
   /**
    * Overall recovery action.
    */
@@ -520,7 +525,11 @@ run_challenge_cb (void *cls,
   struct SelectChallengeContext *sctx = cls;
   const struct ANASTASIS_PaymentSecretP *psp = NULL;
   struct ANASTASIS_PaymentSecretP ps;
+  struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
   struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_relative_time ("timeout",
+                                      &timeout)),
     GNUNET_JSON_spec_fixed_auto ("payment_secret",
                                  &ps),
     GNUNET_JSON_spec_end ()
@@ -615,6 +624,7 @@ run_challenge_cb (void *cls,
                                       janswer));
       ret = ANASTASIS_challenge_answer (ci,
                                         psp,
+                                        timeout,
                                         answer,
                                         &answer_feedback_cb,
                                         sctx);
@@ -632,6 +642,7 @@ run_challenge_cb (void *cls,
 
         ret = ANASTASIS_challenge_answer2 (ci,
                                            psp,
+                                           timeout,
                                            ianswer,
                                            &answer_feedback_cb,
                                            sctx);
@@ -659,6 +670,7 @@ run_challenge_cb (void *cls,
         }
         ret = ANASTASIS_challenge_start (ci,
                                          psp,
+                                         timeout,
                                          &hashed_answer,
                                          &answer_feedback_cb,
                                          sctx);
@@ -668,6 +680,7 @@ run_challenge_cb (void *cls,
         /* no answer provided */
         ret = ANASTASIS_challenge_start (ci,
                                          psp,
+                                         timeout,
                                          NULL,   /* no answer */
                                          &answer_feedback_cb,
                                          sctx);
@@ -780,6 +793,7 @@ pay_challenge_cb (void *cls,
       }
       ret = ANASTASIS_challenge_answer (ci,
                                         &sctx->ps,
+                                        sctx->timeout,
                                         answer,
                                         &answer_feedback_cb,
                                         sctx);
@@ -788,6 +802,7 @@ pay_challenge_cb (void *cls,
     {
       ret = ANASTASIS_challenge_start (ci,
                                        &sctx->ps,
+                                       sctx->timeout,
                                        NULL,   /* no answer yet */
                                        &answer_feedback_cb,
                                        sctx);
@@ -913,12 +928,16 @@ pay_challenge (json_t *state,
   struct SelectChallengeContext *sctx
     = GNUNET_new (struct SelectChallengeContext);
   json_t *rd;
+  struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
   struct GNUNET_JSON_Specification spec[] = {
     GNUNET_JSON_spec_fixed_auto ("selected_challenge_uuid",
                                  &sctx->uuid),
     GNUNET_JSON_spec_end ()
   };
   struct GNUNET_JSON_Specification aspec[] = {
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_relative_time ("timeout",
+                                      &timeout)),
     GNUNET_JSON_spec_fixed_auto ("payment_secret",
                                  &sctx->ps),
     GNUNET_JSON_spec_end ()
@@ -965,6 +984,7 @@ pay_challenge (json_t *state,
                            "pay_challenge");
     return NULL;
   }
+  sctx->timeout = timeout;
   sctx->cb = cb;
   sctx->cb_cls = cb_cls;
   sctx->state = json_incref (state);
@@ -1011,7 +1031,11 @@ select_challenge_cb (void *cls,
   struct SelectChallengeContext *sctx = cls;
   const struct ANASTASIS_PaymentSecretP *psp = NULL;
   struct ANASTASIS_PaymentSecretP ps;
+  struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
   struct GNUNET_JSON_Specification spec[] = {
+    GNUNET_JSON_spec_mark_optional (
+      GNUNET_JSON_spec_relative_time ("timeout",
+                                      &timeout)),
     GNUNET_JSON_spec_fixed_auto ("payment_secret",
                                  &ps),
     GNUNET_JSON_spec_end ()
@@ -1104,6 +1128,7 @@ select_challenge_cb (void *cls,
     /* trigger challenge */
     ret = ANASTASIS_challenge_start (ci,
                                      psp,
+                                     timeout,
                                      NULL,   /* no answer */
                                      &answer_feedback_cb,
                                      sctx);
diff --git a/src/restclient/anastasis_api_keyshare_lookup.c 
b/src/restclient/anastasis_api_keyshare_lookup.c
index 3868642..3d41009 100644
--- a/src/restclient/anastasis_api_keyshare_lookup.c
+++ b/src/restclient/anastasis_api_keyshare_lookup.c
@@ -344,6 +344,7 @@ ANASTASIS_keyshare_lookup (
   const struct ANASTASIS_CRYPTO_TruthUUIDP *truth_uuid,
   const struct ANASTASIS_CRYPTO_TruthKeyP *truth_key,
   const struct ANASTASIS_PaymentSecretP *payment_secret,
+  struct GNUNET_TIME_Relative timeout,
   const struct GNUNET_HashCode *hashed_answer,
   ANASTASIS_KeyShareLookupCallback cb,
   void *cb_cls)
@@ -353,7 +354,10 @@ ANASTASIS_keyshare_lookup (
   struct curl_slist *job_headers;
   char *path;
   char *answer_s;
+  unsigned long long tms;
 
+  tms = (unsigned long long) (timeout.rel_value_us
+                              / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us);
   job_headers = NULL;
   {
     struct curl_slist *ext;
@@ -417,28 +421,49 @@ ANASTASIS_keyshare_lookup (
                      uuid_str);
     GNUNET_free (uuid_str);
   }
-  if (NULL != hashed_answer)
   {
-    answer_s = GNUNET_STRINGS_data_to_string_alloc (hashed_answer,
-                                                    sizeof (*hashed_answer));
-    kslo->url = TALER_url_join (backend_url,
-                                path,
-                                "response",
-                                answer_s,
-                                NULL);
-    GNUNET_free (answer_s);
-  }
-  else
-  {
-    kslo->url = TALER_url_join (backend_url,
-                                path,
-                                NULL);
+    char timeout_ms[32];
+
+    GNUNET_snprintf (timeout_ms,
+                     sizeof (timeout_ms),
+                     "%llu",
+                     tms);
+    if (NULL != hashed_answer)
+    {
+      answer_s = GNUNET_STRINGS_data_to_string_alloc (hashed_answer,
+                                                      sizeof (*hashed_answer));
+      kslo->url = TALER_url_join (backend_url,
+                                  path,
+                                  "response",
+                                  answer_s,
+                                  "timeout_ms",
+                                  (0 != timeout.rel_value_us)
+                                ? timeout_ms
+                                : NULL,
+                                  NULL);
+      GNUNET_free (answer_s);
+    }
+    else
+    {
+      kslo->url = TALER_url_join (backend_url,
+                                  path,
+                                  "timeout_ms",
+                                  (0 != timeout.rel_value_us)
+                                ? timeout_ms
+                                : NULL,
+                                  NULL);
+    }
   }
   kslo->display_url = TALER_url_join (backend_url,
                                       path,
                                       NULL);
   GNUNET_free (path);
   eh = ANASTASIS_curl_easy_get_ (kslo->url);
+  if (0 != tms)
+    GNUNET_assert (CURLE_OK ==
+                   curl_easy_setopt (eh,
+                                     CURLOPT_TIMEOUT_MS,
+                                     (long) tms));
   GNUNET_assert (CURLE_OK ==
                  curl_easy_setopt (eh,
                                    CURLOPT_HEADERFUNCTION,
diff --git a/src/restclient/anastasis_api_truth_store.c 
b/src/restclient/anastasis_api_truth_store.c
index e465678..bc4d2ce 100644
--- a/src/restclient/anastasis_api_truth_store.c
+++ b/src/restclient/anastasis_api_truth_store.c
@@ -259,7 +259,6 @@ ANASTASIS_truth_store (
   char *json_str;
   unsigned long long tms;
 
-  /* Finished setting up headers */
   tms = (unsigned long long) (payment_timeout.rel_value_us
                               / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us);
   tso = GNUNET_new (struct ANASTASIS_TruthStoreOperation);
diff --git a/src/stasis/stasis-0001.sql b/src/stasis/stasis-0001.sql
index 8bca886..8d998ca 100644
--- a/src/stasis/stasis-0001.sql
+++ b/src/stasis/stasis-0001.sql
@@ -150,7 +150,7 @@ COMMENT ON COLUMN anastasis_recoverydocument.recovery_data
 
 
 CREATE TABLE IF NOT EXISTS anastasis_challengecode
-  (truth_uuid BYTEA PRIMARY KEY CHECK(LENGTH(truth_uuid)=32) NOT NULL,
+  (truth_uuid BYTEA CHECK(LENGTH(truth_uuid)=32) NOT NULL,
    code INT8 NOT NULL,
    creation_date INT8 NOT NULL,
    expiration_date INT8 NOT NULL,
@@ -171,5 +171,18 @@ COMMENT ON COLUMN anastasis_challengecode.expiration_date
 COMMENT ON COLUMN anastasis_challengecode.retry_counter
   IS 'How many tries are left for this code must be > 0';
 
+CREATE INDEX IF NOT EXISTS anastasis_challengecode_uuid_index
+  ON anastasis_challengecode
+  (truth_uuid,expiration_date);
+COMMENT ON INDEX anastasis_challengecode_uuid_index
+  IS 'for challenge lookup';
+
+CREATE INDEX IF NOT EXISTS anastasis_challengecode_expiration_index
+  ON anastasis_challengecode
+  (truth_uuid,expiration_date);
+COMMENT ON INDEX anastasis_challengecode_expiration_index
+  IS 'for challenge garbage collection';
+
+
 -- Complete transaction
 COMMIT;
diff --git a/src/testing/testing_api_cmd_keyshare_lookup.c 
b/src/testing/testing_api_cmd_keyshare_lookup.c
index ad8527f..f86feac 100644
--- a/src/testing/testing_api_cmd_keyshare_lookup.c
+++ b/src/testing/testing_api_cmd_keyshare_lookup.c
@@ -351,6 +351,7 @@ keyshare_lookup_run (void *cls,
                                             truth_uuid,
                                             truth_key,
                                             payment_secret,
+                                            GNUNET_TIME_UNIT_ZERO,
                                             (NULL != answer)
                                             ? &h_answer
                                             : NULL,
diff --git a/src/testing/testing_cmd_challenge_answer.c 
b/src/testing/testing_cmd_challenge_answer.c
index 6b6e9f1..22af2dc 100644
--- a/src/testing/testing_cmd_challenge_answer.c
+++ b/src/testing/testing_cmd_challenge_answer.c
@@ -261,6 +261,7 @@ challenge_answer_run (void *cls,
   if (GNUNET_OK !=
       ANASTASIS_challenge_answer (cs->c,
                                   ps,
+                                  GNUNET_TIME_UNIT_ZERO,
                                   answer,
                                   &challenge_answer_cb,
                                   cs))
@@ -338,6 +339,7 @@ challenge_start_run (void *cls,
   if (GNUNET_OK !=
       ANASTASIS_challenge_start ((struct ANASTASIS_Challenge *) c,
                                  ps,
+                                 GNUNET_TIME_UNIT_ZERO,
                                  NULL,
                                  &challenge_answer_cb,
                                  cs))

-- 
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]