diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-11-24 22:58:04 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-11-24 22:58:04 +0100 |
commit | 50fdeaaaf49f43f5625d5a3aca4692b4661bc613 (patch) | |
tree | a23405de101e4ccf2d5434c321c8705ce1df169f | |
parent | fc9d4a99a1488a6313f661258e455fb8f443a4d1 (diff) | |
download | sync-50fdeaaaf49f43f5625d5a3aca4692b4661bc613.tar.gz sync-50fdeaaaf49f43f5625d5a3aca4692b4661bc613.tar.bz2 sync-50fdeaaaf49f43f5625d5a3aca4692b4661bc613.zip |
upload api skeleton
-rw-r--r-- | src/include/sync_service.h | 21 | ||||
-rw-r--r-- | 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" /** @@ -66,6 +68,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 * client. @@ -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); } |