gnunet-svn
[Top][All Lists]
Advanced

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

[taler-sync] branch master updated (d92b7d9 -> 778c222)


From: gnunet
Subject: [taler-sync] branch master updated (d92b7d9 -> 778c222)
Date: Fri, 29 Nov 2019 23:21:35 +0100

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

grothoff pushed a change to branch master
in repository sync.

    from d92b7d9  del
     new aa05313  expand logging, minor bugfixes
     new 778c222  fix issues

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


Summary of changes:
 src/include/sync_database_plugin.h      |   5 ++
 src/lib/sync_api_upload.c               |   8 ++-
 src/lib/test_sync_api.c                 |  10 ++-
 src/lib/test_sync_api.conf              |   5 +-
 src/lib/testing_api_cmd_backup_upload.c |   6 +-
 src/sync/sync-httpd.c                   |  36 +++++++---
 src/sync/sync-httpd.h                   |   7 ++
 src/sync/sync-httpd_backup.c            |  12 ++++
 src/sync/sync-httpd_backup_post.c       | 117 +++++++++++++++++++++++++++++---
 src/syncdb/plugin_syncdb_postgres.c     |   2 +-
 10 files changed, 186 insertions(+), 22 deletions(-)

diff --git a/src/include/sync_database_plugin.h 
b/src/include/sync_database_plugin.h
index 0321ce2..cf6a026 100644
--- a/src/include/sync_database_plugin.h
+++ b/src/include/sync_database_plugin.h
@@ -33,6 +33,11 @@
  */
 enum SYNC_DB_QueryStatus
 {
+  /**
+   * Client claimed to be updating an existing backup, but we have none.
+   */
+  SYNC_DB_OLD_BACKUP_MISSING = -5,
+
   /**
    * Update failed because the old backup hash does not match what we 
previously had in the DB.
    */
diff --git a/src/lib/sync_api_upload.c b/src/lib/sync_api_upload.c
index f3e3cf3..33ff381 100644
--- a/src/lib/sync_api_upload.c
+++ b/src/lib/sync_api_upload.c
@@ -158,6 +158,12 @@ handle_upload_finished (void *cls,
     ec = TALER_JSON_get_error_code2 (data,
                                      data_size);
     break;
+  case MHD_HTTP_INTERNAL_SERVER_ERROR:
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Internal server error: `%.*s\n",
+                (int) data_size,
+                (const char *) data);
+    break;
   }
   if (NULL != uo->cb)
   {
@@ -431,7 +437,7 @@ SYNC_upload_cancel (struct SYNC_UploadOperation *uo)
     GNUNET_CURL_job_cancel (uo->job);
     uo->job = NULL;
   }
-  GNUNET_free (uo->pay_uri);
+  GNUNET_free_non_null (uo->pay_uri);
   GNUNET_free (uo->url);
   GNUNET_free (uo);
 }
diff --git a/src/lib/test_sync_api.c b/src/lib/test_sync_api.c
index 9f18d39..6f6ac77 100644
--- a/src/lib/test_sync_api.c
+++ b/src/lib/test_sync_api.c
@@ -240,7 +240,15 @@ run (void *cls,
       "create-reserve-1",
       "EUR:5",
       MHD_HTTP_OK),
-
+    SYNC_TESTING_cmd_backup_nx ("backup-download-nx",
+                                sync_url),
+    SYNC_TESTING_cmd_backup_upload ("backup-upload-1",
+                                    sync_url,
+                                    NULL /* prev upload */,
+                                    SYNC_TESTING_UO_NONE,
+                                    MHD_HTTP_PAYMENT_REQUIRED,
+                                    "Test-1",
+                                    strlen ("Test-1")),
     TALER_TESTING_cmd_end ()
   };
 
diff --git a/src/lib/test_sync_api.conf b/src/lib/test_sync_api.conf
index 057420d..c767b72 100644
--- a/src/lib/test_sync_api.conf
+++ b/src/lib/test_sync_api.conf
@@ -12,9 +12,12 @@ CURRENCY = EUR
 # Sync config
 
 [sync]
-# Which port do we run the backend on? (HTTP server)
+# Which port do we run the *sync* backend on? (HTTP server)
 PORT = 8084
 
+# Where does our payment backend run?  Must match PORT under [merchant]
+PAYMENT_BACKEND_URL = http://localhost:8080/
+
 [syncdb-postgres]
 CONFIG = postgres:///synccheck
 
diff --git a/src/lib/testing_api_cmd_backup_upload.c 
b/src/lib/testing_api_cmd_backup_upload.c
index 9809942..02d66fb 100644
--- a/src/lib/testing_api_cmd_backup_upload.c
+++ b/src/lib/testing_api_cmd_backup_upload.c
@@ -303,7 +303,11 @@ backup_upload_run (void *cls,
   bus->uo = SYNC_upload (is->ctx,
                          bus->sync_url,
                          &bus->sync_priv,
-                         &bus->prev_hash,
+                         ( (NULL != bus->prev_upload) ||
+                           (0 != (SYNC_TESTING_UO_PREV_HASH_WRONG
+                                  & bus->uopt)) )
+                         ? &bus->prev_hash
+                         : NULL,
                          bus->backup_size,
                          bus->backup,
                          (0 != (SYNC_TESTING_UO_REQUEST_PAYMENT & bus->uopt)),
diff --git a/src/sync/sync-httpd.c b/src/sync/sync-httpd.c
index 975db92..8700a50 100644
--- a/src/sync/sync-httpd.c
+++ b/src/sync/sync-httpd.c
@@ -196,7 +196,7 @@ url_handler (void *cls,
     /* We only read the correlation ID on the first callback for every client 
*/
     correlation_id = MHD_lookup_connection_value (connection,
                                                   MHD_HEADER_KIND,
-                                                  "sync-Correlation-Id");
+                                                  "Sync-Correlation-Id");
     if ((NULL != correlation_id) &&
         (GNUNET_YES != is_valid_correlation_id (correlation_id)))
     {
@@ -249,11 +249,21 @@ url_handler (void *cls,
     if (0 == strcasecmp (method,
                          MHD_HTTP_METHOD_POST))
     {
-      return sync_handler_backup_post (connection,
-                                       con_cls,
-                                       &account_pub,
-                                       upload_data,
-                                       upload_data_size);
+      int ret;
+
+      ret = sync_handler_backup_post (connection,
+                                      con_cls,
+                                      &account_pub,
+                                      upload_data,
+                                      upload_data_size);
+      hc = *con_cls;
+      if (NULL != hc)
+      {
+        /* Store the async context ID, so we can restore it if
+         * we get another callack for this request. */
+        hc->async_scope_id = aid;
+      }
+      return ret;
     }
   }
   for (unsigned int i = 0; NULL != handlers[i].url; i++)
@@ -409,8 +419,8 @@ SH_trigger_daemon ()
   if (NULL != mhd_task)
   {
     GNUNET_SCHEDULER_cancel (mhd_task);
-    mhd_task = NULL;
-    run_daemon (NULL);
+    mhd_task = GNUNET_SCHEDULER_add_now (&run_daemon,
+                                         NULL);
   }
   else
   {
@@ -419,6 +429,16 @@ SH_trigger_daemon ()
 }
 
 
+/**
+ * Kick GNUnet Curl scheduler to begin curl interactions.
+ */
+void
+SH_trigger_curl ()
+{
+  GNUNET_CURL_gnunet_scheduler_reschedule (&rc);
+}
+
+
 /**
  * Function that queries MHD's select sets and
  * starts the task waiting for them.
diff --git a/src/sync/sync-httpd.h b/src/sync/sync-httpd.h
index a7279d5..989cd93 100644
--- a/src/sync/sync-httpd.h
+++ b/src/sync/sync-httpd.h
@@ -162,4 +162,11 @@ void
 SH_trigger_daemon (void);
 
 
+/**
+ * Kick GNUnet Curl scheduler to begin curl interactions.
+ */
+void
+SH_trigger_curl (void);
+
+
 #endif
diff --git a/src/sync/sync-httpd_backup.c b/src/sync/sync-httpd_backup.c
index d74f722..8f5facc 100644
--- a/src/sync/sync-httpd_backup.c
+++ b/src/sync/sync-httpd_backup.c
@@ -45,6 +45,12 @@ sync_handler_backup_get (struct MHD_Connection *connection,
                               &backup_hash);
   switch (qs)
   {
+  case SYNC_DB_OLD_BACKUP_MISSING:
+    GNUNET_break (0);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                       TALER_EC_INTERNAL_INVARIANT_FAILURE,
+                                       "unexpected return status (backup 
missing)");
   case SYNC_DB_OLD_BACKUP_MISSMATCH:
     GNUNET_break (0);
     return TALER_MHD_reply_with_error (connection,
@@ -170,6 +176,12 @@ SH_return_backup (struct MHD_Connection *connection,
                              &backup);
   switch (qs)
   {
+  case SYNC_DB_OLD_BACKUP_MISSING:
+    GNUNET_break (0);
+    return TALER_MHD_reply_with_error (connection,
+                                       MHD_HTTP_INTERNAL_SERVER_ERROR,
+                                       TALER_EC_INTERNAL_INVARIANT_FAILURE,
+                                       "unexpected return status (backup 
missing)");
   case SYNC_DB_OLD_BACKUP_MISSMATCH:
     GNUNET_break (0);
     return TALER_MHD_reply_with_error (connection,
diff --git a/src/sync/sync-httpd_backup_post.c 
b/src/sync/sync-httpd_backup_post.c
index ed6e35d..8137910 100644
--- a/src/sync/sync-httpd_backup_post.c
+++ b/src/sync/sync-httpd_backup_post.c
@@ -215,6 +215,9 @@ make_payment_request (const char *order_id)
   struct MHD_Response *resp;
 
   /* request payment via Taler */
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Creating payment request for order `%s'\n",
+              order_id);
   resp = MHD_create_response_from_buffer (0,
                                           NULL,
                                           MHD_RESPMEM_PERSISTENT);
@@ -265,7 +268,35 @@ proposal_cb (void *cls,
   GNUNET_CONTAINER_DLL_remove (bc_head,
                                bc_tail,
                                bc);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Resuming connection with order `%s'\n",
+              order_id);
   MHD_resume_connection (bc->con);
+  SH_trigger_daemon ();
+  if (MHD_HTTP_OK != http_status)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Backend returned status %u/%u\n",
+                http_status,
+                (unsigned int) ec);
+    GNUNET_break (0);
+    bc->resp = TALER_MHD_make_json_pack ("{s:I, s:s, s:I, s:I}",
+                                         "code",
+                                         (json_int_t)
+                                         
TALER_EC_SYNC_PAYMENT_CREATE_BACKEND_ERROR,
+                                         "hint",
+                                         "Failed to setup order with merchant 
backend",
+                                         "backend-ec", (json_int_t) ec,
+                                         "backend-http-status",
+                                         (json_int_t) http_status);
+    GNUNET_assert (NULL != bc->resp);
+    fprintf (stderr, "SET: %p - %p\n", bc, (NULL != bc) ? bc->resp : NULL);
+    bc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+    return;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+              "Storing payment request for order %s\n",
+              order_id);
   qs = db->store_payment_TR (db->cls,
                              &bc->account,
                              order_id,
@@ -275,11 +306,15 @@ proposal_cb (void *cls,
     GNUNET_break (0);
     bc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CREATE_DB_ERROR,
                                      "Failed to persist payment request in 
sync database");
+    GNUNET_assert (NULL != bc->resp);
     bc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
     return;
   }
-
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Obtained fresh order `%s'\n",
+              order_id);
   bc->resp = make_payment_request (order_id);
+  GNUNET_assert (NULL != bc->resp);
   bc->response_code = MHD_HTTP_PAYMENT_REQUIRED;
 }
 
@@ -344,7 +379,11 @@ check_payment_cb (void *cls,
 
   /* refunds are not supported, verify */
   bc->cpo = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Payment status checked: %s\n",
+              paid ? "paid" : "unpaid");
   MHD_resume_connection (bc->con);
+  SH_trigger_daemon ();
   GNUNET_break ( (GNUNET_NO == refunded) &&
                  (NULL == refund_amount) );
   if (paid)
@@ -360,18 +399,25 @@ check_payment_cb (void *cls,
     GNUNET_break (0);
     bc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_CONFIRM_DB_ERROR,
                                      "Failed to persist payment confirmation 
in sync database");
+    GNUNET_assert (NULL != bc->resp);
     bc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
     return; /* continue as planned */
   }
   if (NULL != bc->existing_order_id)
   {
     /* repeat payment request */
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Repeating payment request\n");
     bc->resp = make_payment_request (bc->existing_order_id);
+    GNUNET_assert (NULL != bc->resp);
     bc->response_code = MHD_HTTP_PAYMENT_REQUIRED;
     return;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Timeout waiting for payment\n");
   bc->resp = TALER_MHD_make_error (TALER_EC_SYNC_PAYMENT_TIMEOUT,
                                    "Timeout awaiting promised payment");
+  GNUNET_assert (NULL != bc->resp);
   bc->response_code = MHD_HTTP_REQUEST_TIMEOUT;
 }
 
@@ -401,6 +447,7 @@ await_payment (struct BackupContext *bc,
                                           timeout,
                                           &check_payment_cb,
                                           bc);
+  SH_trigger_curl ();
 }
 
 
@@ -436,11 +483,15 @@ begin_payment (struct BackupContext *bc,
     ret = MHD_queue_response (bc->con,
                               MHD_HTTP_INTERNAL_SERVER_ERROR,
                               resp);
+    GNUNET_break (MHD_YES == ret);
     MHD_destroy_response (resp);
     return ret;
   }
   if (NULL != bc->existing_order_id)
   {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Have existing order, waiting for `%s' to complete\n",
+                bc->existing_order_id);
     await_payment (bc,
                    GNUNET_TIME_UNIT_ZERO /* no long polling */,
                    bc->existing_order_id);
@@ -449,6 +500,9 @@ begin_payment (struct BackupContext *bc,
   GNUNET_CONTAINER_DLL_insert (bc_head,
                                bc_tail,
                                bc);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Suspending connection while creating order at `%s'\n",
+              SH_backend_url);
   MHD_suspend_connection (bc->con);
   order = json_pack ("{s:o, s:s, s:s}",
                      "amount", TALER_JSON_from_amount (&SH_annual_fee),
@@ -459,6 +513,7 @@ begin_payment (struct BackupContext *bc,
                                      order,
                                      &proposal_cb,
                                      bc);
+  SH_trigger_curl ();
   json_decref (order);
   return MHD_YES;
 }
@@ -479,7 +534,16 @@ handle_database_error (struct BackupContext *bc,
 {
   switch (qs)
   {
+  case SYNC_DB_OLD_BACKUP_MISSING:
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Update failed: no existing backup\n");
+    return TALER_MHD_reply_with_error (bc->con,
+                                       MHD_HTTP_NOT_FOUND,
+                                       TALER_EC_SYNC_PREVIOUS_BACKUP_UNKNOWN,
+                                       "Cannot update, no existing backup 
known");
   case SYNC_DB_OLD_BACKUP_MISSMATCH:
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Conflict detected, returning existing backup\n");
     return SH_return_backup (bc->con,
                              &bc->account,
                              MHD_HTTP_CONFLICT);
@@ -492,9 +556,14 @@ handle_database_error (struct BackupContext *bc,
                                               "paying");
       if (NULL == order_id)
       {
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Payment required, starting payment process\n");
         return begin_payment (bc,
                               GNUNET_NO);
       }
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Payment required, awaiting completion of `%s'\n",
+                  order_id);
       await_payment (bc,
                      CHECK_PAYMENT_TIMEOUT,
                      order_id);
@@ -540,6 +609,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
   struct BackupContext *bc;
 
   bc = *con_cls;
+  fprintf (stderr, "%p - %p\n", bc, (NULL != bc) ? bc->resp : NULL);
   if (NULL == bc)
   {
     /* first call, setup internals */
@@ -602,7 +672,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
             GNUNET_STRINGS_string_to_data (im,
                                            strlen (im),
                                            &bc->old_backup_hash,
-                                           sizeof (&bc->old_backup_hash))) )
+                                           sizeof (bc->old_backup_hash))) )
       {
         GNUNET_break_op (0);
         return TALER_MHD_reply_with_error (connection,
@@ -622,7 +692,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
             GNUNET_STRINGS_string_to_data (sig_s,
                                            strlen (sig_s),
                                            &bc->account_sig,
-                                           sizeof (&bc->account_sig))) )
+                                           sizeof (bc->account_sig))) )
       {
         GNUNET_break_op (0);
         return TALER_MHD_reply_with_error (connection,
@@ -642,7 +712,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
             GNUNET_STRINGS_string_to_data (etag,
                                            strlen (etag),
                                            &bc->new_backup_hash,
-                                           sizeof (&bc->new_backup_hash))) )
+                                           sizeof (bc->new_backup_hash))) )
       {
         GNUNET_break_op (0);
         return TALER_MHD_reply_with_error (connection,
@@ -705,6 +775,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
         ret = MHD_queue_response (connection,
                                   MHD_HTTP_NOT_MODIFIED,
                                   resp);
+        GNUNET_break (MHD_YES == ret);
         MHD_destroy_response (resp);
         return ret;
       }
@@ -712,6 +783,8 @@ sync_handler_backup_post (struct MHD_Connection *connection,
                               &bc->old_backup_hash))
       {
         /* Refuse upload: if-none-match failed! */
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Conflict detected, returning existing backup\n");
         return SH_return_backup (connection,
                                  account,
                                  MHD_HTTP_CONFLICT);
@@ -725,16 +798,23 @@ sync_handler_backup_post (struct MHD_Connection 
*connection,
                                                MHD_GET_ARGUMENT_KIND,
                                                "pay");
       if (NULL != order_req)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                    "Payment requested, starting payment process\n");
         return begin_payment (bc,
                               GNUNET_YES);
+      }
     }
     /* ready to begin! */
     return MHD_YES;
   }
   /* handle upload */
-  if (0 != upload_data_size)
+  if (0 != *upload_data_size)
   {
     /* check MHD invariant */
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Processing %u bytes of upload data\n",
+                (unsigned int) *upload_data_size);
     GNUNET_assert (bc->upload_off + *upload_data_size <= bc->upload_size);
     memcpy (&bc->upload[bc->upload_off],
             upload_data,
@@ -748,10 +828,19 @@ sync_handler_backup_post (struct MHD_Connection 
*connection,
   }
   if (NULL != bc->resp)
   {
+    int ret;
+
     /* We generated a response asynchronously, queue that */
-    return MHD_queue_response (connection,
-                               bc->response_code,
-                               bc->resp);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "Returning asynchronously generated response with HTTP status 
%u\n",
+                bc->response_code);
+    ret = MHD_queue_response (connection,
+                              bc->response_code,
+                              bc->resp);
+    GNUNET_break (MHD_YES == ret);
+    MHD_destroy_response (bc->resp);
+    bc->resp = NULL;
+    return ret;
   }
 
   /* finished with upload, check hash */
@@ -776,14 +865,21 @@ sync_handler_backup_post (struct MHD_Connection 
*connection,
   {
     enum SYNC_DB_QueryStatus qs;
 
-    if (GNUNET_is_zero (&bc->old_backup_hash))
+    if (0 == GNUNET_is_zero (&bc->old_backup_hash))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Uploading first backup to account\n");
       qs = db->store_backup_TR (db->cls,
                                 account,
                                 &bc->account_sig,
                                 &bc->new_backup_hash,
                                 bc->upload_size,
                                 bc->upload);
+    }
     else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Uploading existing backup of account\n");
       qs = db->update_backup_TR (db->cls,
                                  account,
                                  &bc->old_backup_hash,
@@ -791,6 +887,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
                                  &bc->new_backup_hash,
                                  bc->upload_size,
                                  bc->upload);
+    }
     if (qs < 0)
       return handle_database_error (bc,
                                     qs);
@@ -812,6 +909,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
       ret = MHD_queue_response (connection,
                                 MHD_HTTP_NOT_MODIFIED,
                                 resp);
+      GNUNET_break (MHD_YES == ret);
       MHD_destroy_response (resp);
       return ret;
     }
@@ -832,6 +930,7 @@ sync_handler_backup_post (struct MHD_Connection *connection,
     ret = MHD_queue_response (connection,
                               MHD_HTTP_NO_CONTENT,
                               resp);
+    GNUNET_break (MHD_YES == ret);
     MHD_destroy_response (resp);
     return ret;
   }
diff --git a/src/syncdb/plugin_syncdb_postgres.c 
b/src/syncdb/plugin_syncdb_postgres.c
index 475109f..61b192c 100644
--- a/src/syncdb/plugin_syncdb_postgres.c
+++ b/src/syncdb/plugin_syncdb_postgres.c
@@ -616,7 +616,7 @@ postgres_update_backup (void *cls,
     return SYNC_DB_SOFT_ERROR;
   case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
     GNUNET_break (0);
-    return SYNC_DB_NO_RESULTS;
+    return SYNC_DB_OLD_BACKUP_MISSING;
   case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
     return SYNC_DB_ONE_RESULT;
   case GNUNET_DB_STATUS_HARD_ERROR:

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



reply via email to

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