gnunet-svn
[Top][All Lists]
Advanced

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

[taler-sync] branch master updated: upload api skeleton


From: gnunet
Subject: [taler-sync] branch master updated: upload api skeleton
Date: Sun, 24 Nov 2019 22:58:08 +0100

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

grothoff pushed a commit to branch master
in repository sync.

The following commit(s) were added to refs/heads/master by this push:
     new 50fdeaa  upload api skeleton
50fdeaa is described below

commit 50fdeaaaf49f43f5625d5a3aca4692b4661bc613
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Nov 24 22:58:04 2019 +0100

    upload api skeleton
---
 src/include/sync_service.h | 21 ++++++++++-
 src/lib/sync_api_upload.c  | 91 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 109 insertions(+), 3 deletions(-)

diff --git a/src/include/sync_service.h b/src/include/sync_service.h
index e0651f2..bb67481 100644
--- a/src/include/sync_service.h
+++ b/src/include/sync_service.h
@@ -232,6 +232,8 @@ struct SYNC_UploadOperation;
  * @param priv private key of an account with the server
  * @param prev_backup_hash hash of the previous backup, NULL for the first 
upload ever
  * @param backup_size number of bytes in @a backup
+ * @param backup the encrypted backup, must remain in
+ *         memory until we are done with the operation!
  * @param payment_requested #GNUNET_YES if the client wants to pay more for 
the account now
  * @param paid_order_id order ID of a recent payment made, or NULL for none
  * @param cb function to call with the result
@@ -262,17 +264,34 @@ void
 SYNC_upload_cancel (struct SYNC_UploadOperation *uo);
 
 
+/**
+ * Detailed results from the successful download.
+ */
 struct SYNC_DownloadDetails
 {
-
+  /**
+   * Signature (already verified).
+   */
   struct SYNC_AccountSignatureP sig;
 
+  /**
+   * Hash of the previous version.
+   */
   struct GNUNET_HashCode prev_backup_hash;
 
+  /**
+   * Hash over @e backup and @e backup_size.
+   */
   struct GNUNET_HashCode curr_backup_hash;
 
+  /**
+   * The backup we downloaded.
+   */
   const void *backup;
 
+  /**
+   * Number of bytes in @e backup.
+   */
   size_t backup_size;
 
 };
diff --git a/src/lib/sync_api_upload.c b/src/lib/sync_api_upload.c
index 84be034..a218d7b 100644
--- a/src/lib/sync_api_upload.c
+++ b/src/lib/sync_api_upload.c
@@ -28,7 +28,9 @@
 #include <microhttpd.h> /* just for HTTP status codes */
 #include <gnunet/gnunet_util_lib.h>
 #include <gnunet/gnunet_curl_lib.h>
+#include <taler/taler_signatures.h>
 #include "sync_service.h"
+#include "sync_api_curl_defaults.h"
 
 
 /**
@@ -65,6 +67,46 @@ struct SYNC_UploadOperation
 };
 
 
+/**
+ * Function called when we're done processing the
+ * HTTP /backup request.
+ *
+ * @param cls the `struct SYNC_UploadOperation`
+ * @param response_code HTTP response code, 0 on error
+ * @param response
+ */
+static void
+handle_upload_finished (void *cls,
+                        long response_code,
+                        const void *data,
+                        size_t data_size)
+{
+  struct SYNC_UploadOperation *uo = cls;
+  enum TALER_ErrorCode ec = TALER_EC_INVALID;
+
+  uo->job = NULL;
+  switch (response_code)
+  {
+  case 0:
+    break;
+  case MHD_HTTP_OK:
+    break;
+    // FIXME: handle all cases...
+  }
+
+  if (NULL != uo->cb)
+  {
+    uo->cb (uo->cb_cls,
+            ec,
+            response_code,
+            NULL);
+    uo->cb = NULL;
+  }
+  SYNC_upload_cancel (uo);
+}
+
+
+
 /**
  * Upload a @a backup to a Sync server. Note that @a backup must
  * have already been compressed, padded and encrypted by the
@@ -106,8 +148,46 @@ SYNC_upload (struct GNUNET_CURL_Context *ctx,
              SYNC_UploadCallback cb,
              void *cb_cls)
 {
-  GNUNET_break (0);
-  return NULL;
+  struct SYNC_UploadSignaturePS usp;
+  struct SYNC_AccountSignatureP account_sig;
+  struct SYNC_UploadOperation *uo;
+  CURL *eh;
+
+  usp.purpose.purpose = htonl (TALER_SIGNATURE_SYNC_BACKUP_UPLOAD);
+  usp.purpose.size = htonl (sizeof (usp));
+  usp.old_backup_hash = *prev_backup_hash;
+  GNUNET_CRYPTO_hash (backup,
+                      backup_size,
+                      &usp.new_backup_hash);
+  if (GNUNET_OK !=
+      GNUNET_CRYPTO_eddsa_sign (&priv->eddsa_priv,
+                                &usp.purpose,
+                                &account_sig.eddsa_sig))
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  uo = GNUNET_new (struct SYNC_UploadOperation);
+  // FIXME: build uo->url
+  uo->ctx = ctx;
+  uo->cb = cb;
+  uo->cb_cls = cb_cls;
+  eh = SYNC_curl_easy_get_ (uo->url);
+  // FIXME: set headers!
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_POSTFIELDS,
+                                   backup));
+  GNUNET_assert (CURLE_OK ==
+                 curl_easy_setopt (eh,
+                                   CURLOPT_POSTFIELDSIZE,
+                                   (long) backup_size));
+  uo->job = GNUNET_CURL_job_add_raw (ctx,
+                                     eh,
+                                     GNUNET_NO,
+                                     &handle_upload_finished,
+                                     uo);
+  return uo;
 }
 
 
@@ -121,6 +201,13 @@ SYNC_upload (struct GNUNET_CURL_Context *ctx,
 void
 SYNC_upload_cancel (struct SYNC_UploadOperation *uo)
 {
+  if (NULL != uo->job)
+  {
+    GNUNET_CURL_job_cancel (uo->job);
+    uo->job = NULL;
+  }
+  GNUNET_free (uo->url);
+  GNUNET_free (uo);
 }
 
 

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



reply via email to

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