[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] branch master updated: implement more of /config reduc
From: |
gnunet |
Subject: |
[taler-anastasis] branch master updated: implement more of /config reducer functionality |
Date: |
Tue, 16 Feb 2021 21:34:43 +0100 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository anastasis.
The following commit(s) were added to refs/heads/master by this push:
new 09beaca implement more of /config reducer functionality
09beaca is described below
commit 09beaca605da8765175584fc8ba369267e6d83fe
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Tue Feb 16 21:34:41 2021 +0100
implement more of /config reducer functionality
---
contrib/provider-list.json | 16 +--
src/backend/anastasis-httpd_config.c | 8 +-
src/reducer/anastasis_api_redux.c | 244 ++++++++++++++++++++++-------------
3 files changed, 162 insertions(+), 106 deletions(-)
diff --git a/contrib/provider-list.json b/contrib/provider-list.json
index 2b9bb5b..8d6c95e 100644
--- a/contrib/provider-list.json
+++ b/contrib/provider-list.json
@@ -1,27 +1,19 @@
{
"anastasis_provider": [
{
- "id" : "anastasis_01",
- "url" : "localhost:8086/",
- "name" : "Anastasis 1",
+ "url" : "http://localhost:8086/",
"currency" : "TESTKUDOS"
},
{
- "id" : "anastasis_02",
- "url" : "localhost:8087/",
- "name" : "Anastasis 2",
+ "url" : "http://localhost:8087/",
"currency" : "TESTKUDOS"
},
{
- "id" : "anastasis_03",
- "url" : "localhost:8088/",
- "name" : "Anastasis 3",
+ "url" : "http://localhost:8088/",
"currency" : "TESTKUDOS"
},
{
- "id" : "anastasis_04",
- "url" : "localhost:8089/",
- "name" : "Anastasis 4",
+ "url" : "http://localhost:8089/",
"currency" : "TESTKUDOS"
}
]
diff --git a/src/backend/anastasis-httpd_config.c
b/src/backend/anastasis-httpd_config.c
index e5419b7..0657a51 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -27,6 +27,7 @@
#include <taler/taler_json_lib.h>
#include "anastasis_authorization_lib.h"
+
/**
* Add enabled methods and their fees to the ``/config`` response.
*
@@ -74,13 +75,6 @@ add_methods (void *cls,
}
-/**
- * Manages a /config call.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @return MHD result code
- */
MHD_RESULT
AH_handler_config (struct AH_RequestHandler *rh,
struct MHD_Connection *connection)
diff --git a/src/reducer/anastasis_api_redux.c
b/src/reducer/anastasis_api_redux.c
index 825e9b2..25dee20 100644
--- a/src/reducer/anastasis_api_redux.c
+++ b/src/reducer/anastasis_api_redux.c
@@ -148,7 +148,28 @@ struct ConfigReduxWaiting
/**
* Associated redux action.
*/
- struct ANASTASIS_ReduxAction *ra;
+ struct ANASTASIS_ReduxAction ra;
+
+ /**
+ * Config request we are waiting for.
+ */
+ struct ConfigRequest *cr;
+
+ /**
+ * State we are processing.
+ */
+ json_t *state;
+
+ /**
+ * Function to call with updated @e state.
+ */
+ ANASTASIS_ActionCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
};
@@ -266,6 +287,11 @@ struct ConfigRequest
* Task to timeout /config requests.
*/
struct GNUNET_SCHEDULER_Task *tt;
+
+ /**
+ * Status of the /config request.
+ */
+ enum TALER_ErrorCode ec;
};
@@ -417,6 +443,116 @@ ANASTASIS_redux_countries_init_ (void)
}
+/**
+ * Abort waiting for /config reply.
+ *
+ * @param cls a `struct ConfigReduxWaiting` handle.
+ */
+static void
+abort_provider_config_cb (void *cls)
+{
+ struct ConfigReduxWaiting *w = cls;
+ struct ConfigRequest *cr = w->cr;
+
+ GNUNET_CONTAINER_DLL_remove (cr->w_head,
+ cr->w_tail,
+ w);
+ json_decref (w->state);
+ GNUNET_free (w);
+}
+
+
+/**
+ * Notify anyone waiting on @a cr that the request is done
+ * (successful or failed).
+ *
+ * @param[in,out] cr request that completed
+ */
+static void
+notify_waiting (struct ConfigRequest *cr)
+{
+ struct ConfigReduxWaiting *w;
+
+ while (NULL != (w = cr->w_head))
+ {
+ json_t *provider_list;
+ json_t *prov;
+
+ if (NULL == (provider_list = json_object_get (w->state,
+ "authentication_providers")))
+ {
+ GNUNET_assert (0 ==
+ json_object_set_new (w->state,
+ "authentication_providers",
+ provider_list = json_object ()));
+ }
+ provider_list = json_object_get (w->state,
+ "authentication_providers");
+ GNUNET_assert (NULL != provider_list);
+
+ if (TALER_EC_NONE != cr->ec)
+ {
+ prov = json_pack ("{s:I, s:I}",
+ "error_code",
+ (json_int_t) cr->ec,
+ "http_status",
+ (json_int_t) cr->http_status);
+ }
+ else
+ {
+ json_t *methods_list;
+
+ methods_list = json_array ();
+ GNUNET_assert (NULL != methods_list);
+ for (unsigned int i = 0; i<cr->methods_length; i++)
+ {
+ struct AuthorizationMethodConfig *method = &cr->methods[i];
+ json_t *mj = json_pack ("{s:s, s:o}",
+ "method",
+ method->name,
+ "usage_fee",
+ TALER_JSON_from_amount (&method->usage_fee));
+
+ GNUNET_assert (NULL != mj);
+ GNUNET_assert (0 ==
+ json_array_append_new (methods_list,
+ mj));
+ }
+ prov = json_pack ("{s:o, s:o, s:o, s:o, s:o,"
+ " s:s, s:s, s:I, s:o}",
+ "methods",
+ methods_list,
+ "annual_fee",
+ TALER_JSON_from_amount (&cr->annual_fee),
+ "truth_upload_fee",
+ TALER_JSON_from_amount (&cr->truth_upload_fee),
+ "liability_limit",
+ TALER_JSON_from_amount (&cr->liability_limit),
+ "truth_lifetime",
+ GNUNET_JSON_from_time_rel (cr->truth_lifetime),
+ /* 6 */
+ "currency",
+ cr->currency,
+ "business_name",
+ cr->business_name,
+ "storage_limit_in_megabytes",
+ (json_int_t) cr->storage_limit_in_megabytes,
+ "salt",
+ GNUNET_JSON_from_data_auto (&cr->salt));
+ }
+ GNUNET_assert (0 ==
+ json_object_set_new (provider_list,
+ cr->url,
+ prov));
+ w->cb (w->cb_cls,
+ cr->ec,
+ w->state);
+ abort_provider_config_cb (w);
+ }
+
+}
+
+
/**
* Function called with the results of a #ANASTASIS_get_config().
*
@@ -435,13 +571,15 @@ config_cb (void *cls,
GNUNET_SCHEDULER_cancel (cr->tt);
cr->tt = NULL;
cr->http_status = http_status;
+ if (MHD_HTTP_OK != http_status)
+ cr->ec = TALER_EC_INVALID;
if ( (MHD_HTTP_OK == http_status) &&
(NULL == acfg) )
{
cr->http_status = MHD_HTTP_NOT_FOUND;
- return;
+ cr->ec = TALER_EC_INVALID;
}
- if (NULL != acfg)
+ else if (NULL != acfg)
{
cr->currency = GNUNET_strdup (acfg->currency);
cr->business_name = GNUNET_strdup (acfg->business_name);
@@ -460,6 +598,7 @@ config_cb (void *cls,
cr->liability_limit = acfg->liability_limit;
cr->salt = acfg->salt;
}
+ notify_waiting (cr);
}
@@ -476,6 +615,9 @@ config_request_timeout (void *cls)
cr->tt = NULL;
ANASTASIS_config_cancel (cr->co);
cr->co = NULL;
+ cr->http_status = 0;
+ cr->ec = TALER_EC_GENERIC_TIMEOUT;
+ notify_waiting (cr);
}
@@ -711,7 +853,6 @@ redux_id_attr_init (const char *country_code)
/**
* DispatchHandler/Callback function which is called for a
* "select_continent" action.
- * Returns an #ANASTASIS_ReduxAction if operation is async.
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
@@ -794,7 +935,6 @@ select_continent (json_t *state,
/**
* DispatchHandler/Callback function which is called for a
* "select_country" action.
- * Returns an #ANASTASIS_ReduxAction if operation is async.
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
@@ -896,7 +1036,6 @@ select_country (json_t *state,
/**
* DispatchHandler/Callback function which is called for a
* "unselect_country" action.
- * Returns an #ANASTASIS_ReduxAction if operation is async.
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
@@ -922,7 +1061,6 @@ unselect_country (json_t *state,
/**
* DispatchHandler/Callback function which is called for a
* "unselect_continent" action.
- * Returns an #ANASTASIS_ReduxAction if operation is async.
*
* @param state state to operate on
* @param arguments arguments to use for operation on state
@@ -945,20 +1083,6 @@ unselect_continent (json_t *state,
}
-#if 0
-
-static void
-config_finished (struct ConfigReduxWaiting *w,
- struct ConfigRequest *cr)
-{
- struct ANASTASIS_ReduxAction *ra = w->ra;
- GNUNET_CONTAINER_DLL_remove (cr->w_head,
- cr->w_tail,
- w);
- GNUNET_free (w);
-}
-
-
/**
* Adds the server configuration of the Anastasis provider
* at @a url to the json @a state. Checks if we have
@@ -981,81 +1105,27 @@ ANASTASIS_REDUX_add_provider_to_state_ (const char *url,
{
struct ConfigRequest *cr;
struct ConfigReduxWaiting *w;
- struct ANASTASIS_ReduxAction *ra;
- json_t *method;
- size_t index;
- json_t *provider_list;
- json_t *methods_list;
-
- for (cr = cr_head; NULL != cr; cr = cr->next)
- if (0 == strcmp (url,
- cr->url))
- break;
- if (NULL == cr)
- w = GNUNET_new (struct ConfigReduxWaiting);
+ cr = check_config (url);
+ w = GNUNET_new (struct ConfigReduxWaiting);
+ w->cr = cr;
+ w->state = json_incref (state);
+ w->cb = cb;
+ w->cb_cls = cb_cls;
+ w->ra.cleanup = &abort_provider_config_cb;
+ w->ra.cleanup_cls = w;
GNUNET_CONTAINER_DLL_insert (cr->w_head,
cr->w_tail,
w);
-
- methods_list = json_object_get (cr->backend_methods,
- "methods");
-
- if (NULL == (provider_list = json_object_get (state,
- "authentication_providers")))
- {
- GNUNET_assert (0 ==
- json_object_set_new (state,
- "authentication_providers",
- provider_list = json_object ()));
- }
- provider_list = json_object_get (state, "authentication_providers");
-
- GNUNET_assert (NULL != provider_list);
- json_array_foreach (methods_list, index, method)
+ if (NULL == cr->co)
{
- const char *method_type = json_string_value (json_object_get (method,
- "method"));
- json_t *ma_arr;
- json_t *prov;
- json_t *ma = json_object (); // FIXME: odd structure!
-
- if (NULL == (ma_arr = json_object_get (provider_list,
- method_type)))
- {
- GNUNET_assert (0 ==
- json_object_set_new (provider_list,
- method_type,
- ma_arr = json_array ()));
- }
- prov = json_pack ("{s:o, s:o, s:o, s:s, s:s, s:o}",
- "method_cost",
- json_object_get (method,
- "cost"), // FIXME: bad RC, bad idea!
- "annual_cost",
- TALER_JSON_from_amount (&cr->annual_fee),
- "insurance",
- TALER_JSON_from_amount (&cr->liability_limit),
- "provider_url",
- cr->url,
- "provider_name",
- cr->business_name,
- "provider_salt",
- GNUNET_JSON_from_data_auto (&cr->salt));
- GNUNET_assert (0 ==
- json_object_set_new (ma,
- cr->backend_id,
- prov));
- GNUNET_assert (0 ==
- json_array_append_new (ma_arr,
- ma));
+ notify_waiting (cr);
+ return NULL;
}
+ return &w->ra;
}
-#endif
-
-
/**
* DispatchHandler/Callback function which is called for a
* "enter_user_attributes" action.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-anastasis] branch master updated: implement more of /config reducer functionality,
gnunet <=