diff options
Diffstat (limited to 'src/reducer/anastasis_api_discovery.c')
-rw-r--r-- | src/reducer/anastasis_api_discovery.c | 61 |
1 files changed, 54 insertions, 7 deletions
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); |