summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-12-02 20:20:08 +0100
committerChristian Grothoff <christian@grothoff.org>2020-12-02 20:20:08 +0100
commit67e6d86c6ad7e4c487fff55bb7eb9c93114a3446 (patch)
tree6ae7d632be54e21161c5a95e398f24d87d36e5d9 /src
parent7ccc3fdf05adead935c1749553405f4a9d6b724a (diff)
downloadsync-67e6d86c6ad7e4c487fff55bb7eb9c93114a3446.tar.gz
sync-67e6d86c6ad7e4c487fff55bb7eb9c93114a3446.tar.bz2
sync-67e6d86c6ad7e4c487fff55bb7eb9c93114a3446.zip
implement fresh option also in client API
Diffstat (limited to 'src')
-rw-r--r--src/include/sync_service.h26
-rw-r--r--src/lib/sync_api_upload.c67
-rw-r--r--src/sync/sync-httpd_backup_post.c3
-rw-r--r--src/testing/testing_api_cmd_backup_upload.c4
4 files changed, 61 insertions, 39 deletions
diff --git a/src/include/sync_service.h b/src/include/sync_service.h
index 80d18ea..43d1757 100644
--- a/src/include/sync_service.h
+++ b/src/include/sync_service.h
@@ -208,6 +208,28 @@ typedef void
*/
struct SYNC_UploadOperation;
+/**
+ * Options for payment.
+ */
+enum SYNC_PaymentOptions
+{
+ /**
+ * No special options.
+ */
+ SYNC_PO_NONE = 0,
+
+ /**
+ * Trigger payment even if sync does not require it
+ * yet (forced payment).
+ */
+ SYNC_PO_FORCE_PAYMENT = 1,
+
+ /**
+ * Request a fresh order to be created, say because the
+ * existing one was claimed (but not paid) by another wallet.
+ */
+ SYNC_PO_FRESH_ORDER = 2
+};
/**
* Upload a @a backup to a Sync server. Note that @a backup must
@@ -235,7 +257,7 @@ struct SYNC_UploadOperation;
* @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 po payment options
* @param cb function to call with the result
* @param cb_cls closure for @a cb
* @return handle for the operation
@@ -247,7 +269,7 @@ SYNC_upload (struct GNUNET_CURL_Context *ctx,
const struct GNUNET_HashCode *prev_backup_hash,
size_t backup_size,
const void *backup,
- int payment_requested,
+ enum SYNC_PaymentOptions po,
const char *paid_order_id,
SYNC_UploadCallback cb,
void *cb_cls);
diff --git a/src/lib/sync_api_upload.c b/src/lib/sync_api_upload.c
index 100d10c..4ac5ee9 100644
--- a/src/lib/sync_api_upload.c
+++ b/src/lib/sync_api_upload.c
@@ -240,35 +240,6 @@ handle_header (char *buffer,
}
-/**
- * Upload a @a backup to a Sync server. Note that @a backup must
- * have already been compressed, padded and encrypted by the
- * client.
- *
- * While @a pub is theoretically protected by the HTTPS protocol and
- * required to access the backup, it should be assumed that an
- * adversary might be able to download the backups from the Sync
- * server -- or even run the Sync server. Thus, strong encryption
- * is essential and NOT implemented by this function.
- *
- * The use of Anastasis to safely store the Sync encryption keys and
- * @a pub is recommended. Storing @a priv in Anastasis depends on
- * your priorities: without @a priv, further updates to the backup are
- * not possible, and the user would have to pay for another
- * account. OTOH, without @a priv an adversary that compromised
- * Anastasis can only read the backups, but not alter or destroy them.
- *
- * @param ctx for HTTP client request processing
- * @param base_url base URL of the Sync server
- * @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 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
- * @param cb_cls closure for @a cb
- * @return handle for the operation
- */
struct SYNC_UploadOperation *
SYNC_upload (struct GNUNET_CURL_Context *ctx,
const char *base_url,
@@ -276,7 +247,7 @@ SYNC_upload (struct GNUNET_CURL_Context *ctx,
const struct GNUNET_HashCode *prev_backup_hash,
size_t backup_size,
const void *backup,
- int payment_requested,
+ enum SYNC_PaymentOptions po,
const char *paid_order_id,
SYNC_UploadCallback cb,
void *cb_cls)
@@ -382,16 +353,42 @@ SYNC_upload (struct GNUNET_CURL_Context *ctx,
"backups/%s",
account_s);
GNUNET_free (account_s);
- uo->url = (GNUNET_YES == payment_requested)
- ? TALER_url_join (base_url,
+ if (0 != (po & SYNC_PO_FRESH_ORDER))
+ {
+ uo->url = (0 != (po & SYNC_PO_FORCE_PAYMENT))
+ ? TALER_url_join (base_url,
+ path,
+ "fresh",
+ "y",
+ "pay",
+ "y",
+ (NULL != paid_order_id)
+ ? "paying"
+ : NULL,
+ paid_order_id,
+ NULL)
+ : TALER_url_join (base_url,
path,
- "pay",
+ "fresh",
"y",
(NULL != paid_order_id)
? "paying"
: NULL,
paid_order_id,
- NULL)
+ NULL);
+ }
+ else
+ {
+ uo->url = (0 != (po & SYNC_PO_FORCE_PAYMENT))
+ ? TALER_url_join (base_url,
+ path,
+ "pay",
+ "y",
+ (NULL != paid_order_id)
+ ? "paying"
+ : NULL,
+ paid_order_id,
+ NULL)
: TALER_url_join (base_url,
path,
(NULL != paid_order_id)
@@ -399,6 +396,8 @@ SYNC_upload (struct GNUNET_CURL_Context *ctx,
: NULL,
paid_order_id,
NULL);
+ }
+
GNUNET_free (path);
}
uo->ctx = ctx;
diff --git a/src/sync/sync-httpd_backup_post.c b/src/sync/sync-httpd_backup_post.c
index fb47ac0..4993e0f 100644
--- a/src/sync/sync-httpd_backup_post.c
+++ b/src/sync/sync-httpd_backup_post.c
@@ -684,8 +684,7 @@ SH_backup_post (struct MHD_Connection *connection,
fresh = MHD_lookup_connection_value (connection,
MHD_GET_ARGUMENT_KIND,
"fresh");
- if (0 == strcasecmp (fresh,
- "yes"))
+ if (NULL != fresh)
bc->force_fresh_order = true;
}
*con_cls = bc;
diff --git a/src/testing/testing_api_cmd_backup_upload.c b/src/testing/testing_api_cmd_backup_upload.c
index 6a37ffb..1491db0 100644
--- a/src/testing/testing_api_cmd_backup_upload.c
+++ b/src/testing/testing_api_cmd_backup_upload.c
@@ -339,7 +339,9 @@ backup_upload_run (void *cls,
: NULL,
bus->backup_size,
bus->backup,
- (0 != (SYNC_TESTING_UO_REQUEST_PAYMENT & bus->uopt)),
+ (0 != (SYNC_TESTING_UO_REQUEST_PAYMENT & bus->uopt))
+ ? SYNC_PO_FORCE_PAYMENT
+ : SYNC_PO_NONE,
bus->payment_order_req,
&backup_upload_cb,
bus);