diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-11-24 17:44:06 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-11-24 17:44:06 +0100 |
commit | c4b5ac29367dd1d845c19851504784bdbdbc1fd5 (patch) | |
tree | abd0928b4d798e1fddefb61420aeb2b31e621eb5 | |
parent | d6108a63b016ebe8410049ca1292b0d7fef73291 (diff) | |
download | sync-c4b5ac29367dd1d845c19851504784bdbdbc1fd5.tar.gz sync-c4b5ac29367dd1d845c19851504784bdbdbc1fd5.tar.bz2 sync-c4b5ac29367dd1d845c19851504784bdbdbc1fd5.zip |
lib skeleton
-rw-r--r-- | src/include/sync_service.h | 3 | ||||
-rw-r--r-- | src/lib/Makefile.am | 3 | ||||
-rw-r--r-- | src/lib/sync_api_download.c | 101 | ||||
-rw-r--r-- | src/lib/sync_api_upload.c | 74 | ||||
-rw-r--r-- | src/sync/sync-httpd.c | 1 |
5 files changed, 178 insertions, 4 deletions
diff --git a/src/include/sync_service.h b/src/include/sync_service.h index 627be51..47dfdb4 100644 --- a/src/include/sync_service.h +++ b/src/include/sync_service.h @@ -318,4 +318,7 @@ void SYNC_download_cancel (struct SYNC_DownloadOperation *download); +/* TODO: API for /terms! */ + + #endif /* SYNC_SERVICE_H */ diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 5f05c26..b1b1d92 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -14,7 +14,8 @@ libsync_la_LDFLAGS = \ -no-undefined libsync_la_SOURCES = \ - sync_api_upload.c + sync_api_download.c \ + sync_api_upload.c libsync_la_LIBADD = \ -lgnunetcurl \ diff --git a/src/lib/sync_api_download.c b/src/lib/sync_api_download.c new file mode 100644 index 0000000..e9780e1 --- /dev/null +++ b/src/lib/sync_api_download.c @@ -0,0 +1,101 @@ +/* + This file is part of TALER + Copyright (C) 2014-2019 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1, + or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with TALER; see the file COPYING.LGPL. If not, + see <http://www.gnu.org/licenses/> +*/ + +/** + * @file lib/sync_api_download.c + * @brief Implementation of the download + * @author Christian Grothoff + */ +#include "platform.h" +#include <curl/curl.h> +#include <jansson.h> +#include <microhttpd.h> /* just for HTTP status codes */ +#include <gnunet/gnunet_util_lib.h> +#include <gnunet/gnunet_curl_lib.h> +#include "sync_service.h" + + +/** + * @brief Handle for a download operation. + */ +struct SYNC_DownloadOperation +{ + + /** + * The url for this request. + */ + char *url; + + /** + * Handle for the request. + */ + struct GNUNET_CURL_Job *job; + + /** + * Reference to the execution context. + */ + struct GNUNET_CURL_Context *ctx; + + /** + * Function to call with the result. + */ + SYNC_DownloadCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + +}; + + +/** + * Download the latest version of a backup for account @a pub. + * + * @param ctx for HTTP client request processing + * @param base_url base URL of the Sync server + * @param pub account public key + * @param cb function to call with the backup + * @param cb_cls closure for @a cb + * @return handle for the operation + */ +struct SYNC_DownloadOperation * +SYNC_download (struct GNUNET_CURL_Context *ctx, + const char *base_url, + const struct SYNC_AccountPublicKeyP *pub, + SYNC_DownloadCallback cb, + void *cb_cls) +{ + GNUNET_break (0); + return NULL; +} + + +/** + * Cancel the download. + * + * @param do operation to cancel. + */ +void +SYNC_download_cancel (struct SYNC_DownloadOperation *download) +{ +} + + +/* end of sync_api_download.c */ diff --git a/src/lib/sync_api_upload.c b/src/lib/sync_api_upload.c index b09b01d..84be034 100644 --- a/src/lib/sync_api_upload.c +++ b/src/lib/sync_api_upload.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2017 GNUnet e.V. and INRIA + Copyright (C) 2014-2019 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -32,7 +32,7 @@ /** - * @brief + * @brief Handle for an upload operation. */ struct SYNC_UploadOperation { @@ -52,6 +52,76 @@ struct SYNC_UploadOperation */ struct GNUNET_CURL_Context *ctx; + /** + * Function to call with the result. + */ + SYNC_UploadCallback cb; + + /** + * Closure for @e cb. + */ + void *cb_cls; + }; + +/** + * 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, + struct SYNC_AccountPrivateKeyP *priv, + const struct GNUNET_HashCode *prev_backup_hash, + size_t backup_size, + const void *backup, + int payment_requested, + const char *paid_order_id, + SYNC_UploadCallback cb, + void *cb_cls) +{ + GNUNET_break (0); + return NULL; +} + + +/** + * Cancel the upload. Note that aborting an upload does NOT guarantee + * that it did not complete, it is possible that the server did + * receive the full request before the upload is aborted. + * + * @param uo operation to cancel. + */ +void +SYNC_upload_cancel (struct SYNC_UploadOperation *uo) +{ +} + + /* end of sync_api_upload.c */ diff --git a/src/sync/sync-httpd.c b/src/sync/sync-httpd.c index 1918d42..982a317 100644 --- a/src/sync/sync-httpd.c +++ b/src/sync/sync-httpd.c @@ -33,7 +33,6 @@ #define UNIX_BACKLOG 500 - /** * Should a "Connection: close" header be added to each HTTP response? */ |