summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2022-04-13 22:33:46 +0200
committerChristian Grothoff <christian@grothoff.org>2022-04-13 22:33:46 +0200
commit2c1d49cddefd079798e9ba1ddcb8d08bfbab9dd9 (patch)
treedba0a6f146f1f6c99339a665e482c48a3f4145b9
parente3e3b0637264b6cbccf9c69b4546429187faa8e7 (diff)
downloadanastasis-2c1d49cddefd079798e9ba1ddcb8d08bfbab9dd9.tar.gz
anastasis-2c1d49cddefd079798e9ba1ddcb8d08bfbab9dd9.tar.bz2
anastasis-2c1d49cddefd079798e9ba1ddcb8d08bfbab9dd9.zip
-return ref to respective providers
-rw-r--r--src/cli/anastasis-cli-discover.c3
-rw-r--r--src/include/anastasis_redux.h4
-rw-r--r--src/reducer/anastasis_api_discovery.c61
3 files changed, 59 insertions, 9 deletions
diff --git a/src/cli/anastasis-cli-discover.c b/src/cli/anastasis-cli-discover.c
index 2731ee8..f614165 100644
--- a/src/cli/anastasis-cli-discover.c
+++ b/src/cli/anastasis-cli-discover.c
@@ -92,7 +92,8 @@ print_policy_cb (void *cls,
uint32_t version,
json_int_t attribute_mask,
struct GNUNET_TIME_Timestamp server_time,
- const char *secret_name)
+ const char *secret_name,
+ const json_t *providers)
{
if (NULL == hcpd)
{
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index a62b89e..2adb74b 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -135,6 +135,7 @@ struct ANASTASIS_PolicyDiscovery;
* present in the state that was used to locate this version
* @param server_time when did the provider receive the upload
* @param secret_name name the user assigned to the backup
+ * @param providers json array of providers with this policy
*/
typedef void
(*ANASTASIS_PolicyDiscoveryCallback)(void *cls,
@@ -143,7 +144,8 @@ typedef void
uint32_t version,
json_int_t attribute_mask,
struct GNUNET_TIME_Timestamp server_time,
- const char *secret_name);
+ const char *secret_name,
+ const json_t *providers);
/**
diff --git a/src/reducer/anastasis_api_discovery.c b/src/reducer/anastasis_api_discovery.c
index 76731ad..72b7ca6 100644
--- a/src/reducer/anastasis_api_discovery.c
+++ b/src/reducer/anastasis_api_discovery.c
@@ -92,7 +92,8 @@ struct ANASTASIS_PolicyDiscovery
/**
* Map for duplicate detection, maps hashes of policies we
- * have already seen to the value "dummy".
+ * have already seen to a json_array with all providers
+ * and versions corresponding to this policy hash.
*/
struct GNUNET_CONTAINER_MultiHashMap *dd_map;
@@ -130,6 +131,8 @@ meta_cb (void *cls,
{
struct ProviderOperation *po = cls;
struct ANASTASIS_PolicyDiscovery *pd = po->pd;
+ json_t *pa;
+ json_t *pe;
if (NULL == recdoc_id)
{
@@ -141,16 +144,32 @@ meta_cb (void *cls,
GNUNET_free (po);
return;
}
- if (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_contains (pd->dd_map,
- recdoc_id))
+ pe = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("version",
+ version),
+ GNUNET_JSON_pack_string ("url",
+ po->provider_url));
+
+ pa = GNUNET_CONTAINER_multihashmap_get (pd->dd_map,
+ recdoc_id);
+ if (NULL != pa)
+ {
+ GNUNET_break (0 ==
+ json_array_append_new (pa,
+ pe));
return;
+ }
+ pa = json_array ();
+ GNUNET_assert (NULL != pa);
+ GNUNET_break (0 ==
+ json_array_append_new (pa,
+ pe));
GNUNET_assert (
GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (
pd->dd_map,
recdoc_id,
- "dummy",
+ pa,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
pd->cb (pd->cb_cls,
recdoc_id,
@@ -158,7 +177,8 @@ meta_cb (void *cls,
version,
po->attribute_mask,
server_time,
- secret_name);
+ secret_name,
+ pe);
}
@@ -309,7 +329,9 @@ ANASTASIS_policy_discovery_start (const json_t *state,
size_t index;
json_t *required_attribute;
- json_array_foreach (required_attributes, index, required_attribute)
+ json_array_foreach (required_attributes,
+ index,
+ required_attribute)
{
const char *name;
int optional = false;
@@ -417,6 +439,28 @@ ANASTASIS_policy_discovery_more (struct ANASTASIS_PolicyDiscovery *pd,
}
+/**
+ * Free JSON Arrays from our hash map.
+ *
+ * @param cls NULL
+ * @param key ignored
+ * @param value `json_t *` to free
+ * @return #GNUNET_OK
+ */
+static enum GNUNET_GenericReturnValue
+free_dd_json (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ json_t *j = value;
+
+ (void) cls;
+ (void) key;
+ json_decref (j);
+ return GNUNET_OK;
+}
+
+
void
ANASTASIS_policy_discovery_stop (struct ANASTASIS_PolicyDiscovery *pd)
{
@@ -431,6 +475,9 @@ ANASTASIS_policy_discovery_stop (struct ANASTASIS_PolicyDiscovery *pd)
GNUNET_free (po->provider_url);
GNUNET_free (po);
}
+ GNUNET_CONTAINER_multihashmap_iterate (pd->dd_map,
+ &free_dd_json,
+ NULL);
GNUNET_CONTAINER_multihashmap_destroy (pd->dd_map);
json_decref (pd->state);
GNUNET_free (pd);