aboutsummaryrefslogtreecommitdiff
path: root/src/reducer/anastasis_api_discovery.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reducer/anastasis_api_discovery.c')
-rw-r--r--src/reducer/anastasis_api_discovery.c61
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
92 92
93 /** 93 /**
94 * Map for duplicate detection, maps hashes of policies we 94 * Map for duplicate detection, maps hashes of policies we
95 * have already seen to the value "dummy". 95 * have already seen to a json_array with all providers
96 * and versions corresponding to this policy hash.
96 */ 97 */
97 struct GNUNET_CONTAINER_MultiHashMap *dd_map; 98 struct GNUNET_CONTAINER_MultiHashMap *dd_map;
98 99
@@ -130,6 +131,8 @@ meta_cb (void *cls,
130{ 131{
131 struct ProviderOperation *po = cls; 132 struct ProviderOperation *po = cls;
132 struct ANASTASIS_PolicyDiscovery *pd = po->pd; 133 struct ANASTASIS_PolicyDiscovery *pd = po->pd;
134 json_t *pa;
135 json_t *pe;
133 136
134 if (NULL == recdoc_id) 137 if (NULL == recdoc_id)
135 { 138 {
@@ -141,16 +144,32 @@ meta_cb (void *cls,
141 GNUNET_free (po); 144 GNUNET_free (po);
142 return; 145 return;
143 } 146 }
144 if (GNUNET_YES == 147 pe = GNUNET_JSON_PACK (
145 GNUNET_CONTAINER_multihashmap_contains (pd->dd_map, 148 GNUNET_JSON_pack_uint64 ("version",
146 recdoc_id)) 149 version),
150 GNUNET_JSON_pack_string ("url",
151 po->provider_url));
152
153 pa = GNUNET_CONTAINER_multihashmap_get (pd->dd_map,
154 recdoc_id);
155 if (NULL != pa)
156 {
157 GNUNET_break (0 ==
158 json_array_append_new (pa,
159 pe));
147 return; 160 return;
161 }
162 pa = json_array ();
163 GNUNET_assert (NULL != pa);
164 GNUNET_break (0 ==
165 json_array_append_new (pa,
166 pe));
148 GNUNET_assert ( 167 GNUNET_assert (
149 GNUNET_OK == 168 GNUNET_OK ==
150 GNUNET_CONTAINER_multihashmap_put ( 169 GNUNET_CONTAINER_multihashmap_put (
151 pd->dd_map, 170 pd->dd_map,
152 recdoc_id, 171 recdoc_id,
153 "dummy", 172 pa,
154 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 173 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
155 pd->cb (pd->cb_cls, 174 pd->cb (pd->cb_cls,
156 recdoc_id, 175 recdoc_id,
@@ -158,7 +177,8 @@ meta_cb (void *cls,
158 version, 177 version,
159 po->attribute_mask, 178 po->attribute_mask,
160 server_time, 179 server_time,
161 secret_name); 180 secret_name,
181 pe);
162} 182}
163 183
164 184
@@ -309,7 +329,9 @@ ANASTASIS_policy_discovery_start (const json_t *state,
309 size_t index; 329 size_t index;
310 json_t *required_attribute; 330 json_t *required_attribute;
311 331
312 json_array_foreach (required_attributes, index, required_attribute) 332 json_array_foreach (required_attributes,
333 index,
334 required_attribute)
313 { 335 {
314 const char *name; 336 const char *name;
315 int optional = false; 337 int optional = false;
@@ -417,6 +439,28 @@ ANASTASIS_policy_discovery_more (struct ANASTASIS_PolicyDiscovery *pd,
417} 439}
418 440
419 441
442/**
443 * Free JSON Arrays from our hash map.
444 *
445 * @param cls NULL
446 * @param key ignored
447 * @param value `json_t *` to free
448 * @return #GNUNET_OK
449 */
450static enum GNUNET_GenericReturnValue
451free_dd_json (void *cls,
452 const struct GNUNET_HashCode *key,
453 void *value)
454{
455 json_t *j = value;
456
457 (void) cls;
458 (void) key;
459 json_decref (j);
460 return GNUNET_OK;
461}
462
463
420void 464void
421ANASTASIS_policy_discovery_stop (struct ANASTASIS_PolicyDiscovery *pd) 465ANASTASIS_policy_discovery_stop (struct ANASTASIS_PolicyDiscovery *pd)
422{ 466{
@@ -431,6 +475,9 @@ ANASTASIS_policy_discovery_stop (struct ANASTASIS_PolicyDiscovery *pd)
431 GNUNET_free (po->provider_url); 475 GNUNET_free (po->provider_url);
432 GNUNET_free (po); 476 GNUNET_free (po);
433 } 477 }
478 GNUNET_CONTAINER_multihashmap_iterate (pd->dd_map,
479 &free_dd_json,
480 NULL);
434 GNUNET_CONTAINER_multihashmap_destroy (pd->dd_map); 481 GNUNET_CONTAINER_multihashmap_destroy (pd->dd_map);
435 json_decref (pd->state); 482 json_decref (pd->state);
436 GNUNET_free (pd); 483 GNUNET_free (pd);