From edd65b2fa2ee029fb670150f92513d20edce0bf1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 30 Sep 2021 14:42:53 +0200 Subject: allow providers to be enabled/disabled --- src/reducer/anastasis_api_backup_redux.c | 176 +++++++++++++++++++++++++------ 1 file changed, 144 insertions(+), 32 deletions(-) (limited to 'src/reducer/anastasis_api_backup_redux.c') diff --git a/src/reducer/anastasis_api_backup_redux.c b/src/reducer/anastasis_api_backup_redux.c index cfef852..27b5730 100644 --- a/src/reducer/anastasis_api_backup_redux.c +++ b/src/reducer/anastasis_api_backup_redux.c @@ -286,22 +286,28 @@ add_authentication (json_t *state, json_object_foreach (auth_providers, url, details) { - json_t *methods; + json_t *methods = NULL; json_t *method; size_t index; - uint32_t size_limit_in_mb; + uint32_t size_limit_in_mb = 0; + bool disabled = false; + uint32_t http_status = 0; struct GNUNET_JSON_Specification ispec[] = { - GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", - &size_limit_in_mb), - GNUNET_JSON_spec_json ("methods", - &methods), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", + &size_limit_in_mb)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("http_status", + &http_status)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("methods", + &methods)), GNUNET_JSON_spec_end () }; - if (MHD_HTTP_OK != - json_integer_value (json_object_get (details, - "http_status"))) - continue; /* skip providers that are down */ if (GNUNET_OK != GNUNET_JSON_parse (details, ispec, @@ -310,6 +316,16 @@ add_authentication (json_t *state, GNUNET_break (0); continue; } + if (disabled) + continue; + if (MHD_HTTP_OK != http_status) + continue; /* skip providers that are down */ + if ( (NULL == methods) || + (0 == size_limit_in_mb) ) + { + GNUNET_break (0); + continue; + } json_array_foreach (methods, index, method) { const char *type; @@ -1082,6 +1098,33 @@ provider_candidate (struct PolicyBuilder *pb, json_object_foreach (pb->providers, url, pconfig) { + bool disabled = false; + uint32_t http_status = 0; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("http_status", + &http_status)), + GNUNET_JSON_spec_end () + }; + + if (GNUNET_OK != + GNUNET_JSON_parse (pconfig, + spec, + NULL, NULL)) + { + GNUNET_break (0); + continue; + } + if ( (MHD_HTTP_OK != http_status) || + disabled) + { + GNUNET_JSON_parse_free (spec); + continue; + } + GNUNET_JSON_parse_free (spec); prov_sel[i] = url; if (i == pb->req_methods - 1) { @@ -1178,16 +1221,25 @@ method_candidate (struct PolicyBuilder *pb, * @param[out] salt value to extract * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue lookup_salt (const json_t *state, const char *provider_url, struct ANASTASIS_CRYPTO_ProviderSaltP *salt) { const json_t *aps; const json_t *cfg; + uint32_t http_status = 0; + bool disabled = false; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_fixed_auto ("salt", - salt), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("http_status", + &http_status)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_fixed_auto ("salt", + salt)), GNUNET_JSON_spec_end () }; @@ -1205,10 +1257,6 @@ lookup_salt (const json_t *state, GNUNET_break (0); return GNUNET_SYSERR; } - if (MHD_HTTP_OK != - json_integer_value (json_object_get (cfg, - "http_status"))) - return GNUNET_NO; /* skip providers that are down */ if (GNUNET_OK != GNUNET_JSON_parse (cfg, spec, @@ -1218,6 +1266,12 @@ lookup_salt (const json_t *state, GNUNET_break_op (0); return GNUNET_NO; } + if (disabled) + return GNUNET_NO; + if (NULL == + json_object_get (cfg, + "salt")) + return GNUNET_NO; return GNUNET_OK; } @@ -1904,7 +1958,15 @@ add_policy (json_t *state, { const json_t *prov_cfg; uint32_t limit; + bool disabled = false; + uint32_t http_status = 0; struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("http_status", + &http_status)), GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", &limit), GNUNET_JSON_spec_json ("methods", @@ -1924,10 +1986,6 @@ add_policy (json_t *state, "provider URL unknown"); return NULL; } - if (MHD_HTTP_OK != - json_integer_value (json_object_get (prov_cfg, - "http_status"))) - continue; if (GNUNET_OK != GNUNET_JSON_parse (prov_cfg, spec, @@ -1937,6 +1995,13 @@ add_policy (json_t *state, json_decref (methods); continue; } + if ( (MHD_HTTP_OK != http_status) || + disabled) + { + /* skip provider, disabled or down */ + json_decref (methods); + continue; + } if (! json_is_array (prov_methods)) { GNUNET_break (0); @@ -2373,17 +2438,21 @@ update_expiration_cost (json_t *state, json_object_foreach (providers, url, provider) { struct TALER_Amount annual_fee; + bool disabled = false; + uint32_t http_status = 0; struct GNUNET_JSON_Specification pspec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("http_status", + &http_status)), TALER_JSON_spec_amount_any ("annual_fee", &annual_fee), GNUNET_JSON_spec_end () }; struct TALER_Amount fee; - if (MHD_HTTP_OK != - json_integer_value (json_object_get (provider, - "http_status"))) - continue; /* skip providers that are down */ if (GNUNET_OK != GNUNET_JSON_parse (provider, pspec, @@ -2393,6 +2462,9 @@ update_expiration_cost (json_t *state, GNUNET_break_op (0); continue; } + if ( (MHD_HTTP_OK != http_status) || + disabled) + continue; /* skip providers that are down or disabled */ if (0 > TALER_amount_multiply (&fee, &annual_fee, @@ -2473,7 +2545,15 @@ update_expiration_cost (json_t *state, off++; { struct TALER_Amount upload_cost; + bool disabled = false; + uint32_t http_status = 0; struct GNUNET_JSON_Specification pspec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("http_status", + &http_status)), TALER_JSON_spec_amount_any ("truth_upload_fee", &upload_cost), GNUNET_JSON_spec_end () @@ -2491,6 +2571,12 @@ update_expiration_cost (json_t *state, GNUNET_break (0); return GNUNET_SYSERR; } + if ( (MHD_HTTP_OK != http_status) || + disabled) + { + GNUNET_break (0); + return GNUNET_SYSERR; + } if (0 > TALER_amount_multiply (&fee, &upload_cost, @@ -4111,17 +4197,22 @@ check_upload_size_limit (json_t *state, see #6760. */ json_object_foreach (aps, url, ap) { - uint32_t limit; + uint32_t limit = 0; + bool disabled = false; + uint32_t http_status = 0; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", - &limit), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("http_status", + &http_status)), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_uint32 ("storage_limit_in_megabytes", + &limit)), GNUNET_JSON_spec_end () }; - if (MHD_HTTP_OK != - json_integer_value (json_object_get (ap, - "http_status"))) - continue; /* skip providers that are down */ if (GNUNET_OK != GNUNET_JSON_parse (ap, spec, @@ -4131,6 +4222,9 @@ check_upload_size_limit (json_t *state, GNUNET_break_op (0); continue; } + if ( (MHD_HTTP_OK != http_status) || + disabled) + continue; if (0 == limit) return GNUNET_SYSERR; min_limit = GNUNET_MIN (min_limit, @@ -4935,7 +5029,25 @@ ANASTASIS_REDUX_backup_begin_ (json_t *state, json_object_foreach (provider_list, url, prov) { struct BackupStartStateProviderEntry *pe; json_t *istate; + bool disabled = false; + struct GNUNET_JSON_Specification spec[] = { + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_bool ("disabled", + &disabled)), + GNUNET_JSON_spec_end () + }; + if (GNUNET_OK != + GNUNET_JSON_parse (prov, + spec, + NULL, NULL)) + { + /* skip malformed provider entry */ + GNUNET_break_op (0); + continue; + } + if (disabled) + continue; pe = GNUNET_new (struct BackupStartStateProviderEntry); pe->bss = bss; istate = json_object (); -- cgit v1.2.3