diff options
author | Christian Grothoff <christian@grothoff.org> | 2022-04-13 22:33:46 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2022-04-13 22:33:46 +0200 |
commit | 2c1d49cddefd079798e9ba1ddcb8d08bfbab9dd9 (patch) | |
tree | dba0a6f146f1f6c99339a665e482c48a3f4145b9 | |
parent | e3e3b0637264b6cbccf9c69b4546429187faa8e7 (diff) | |
download | anastasis-2c1d49cddefd079798e9ba1ddcb8d08bfbab9dd9.tar.gz anastasis-2c1d49cddefd079798e9ba1ddcb8d08bfbab9dd9.zip |
-return ref to respective providers
-rw-r--r-- | src/cli/anastasis-cli-discover.c | 3 | ||||
-rw-r--r-- | src/include/anastasis_redux.h | 4 | ||||
-rw-r--r-- | src/reducer/anastasis_api_discovery.c | 61 |
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, | |||
92 | uint32_t version, | 92 | uint32_t version, |
93 | json_int_t attribute_mask, | 93 | json_int_t attribute_mask, |
94 | struct GNUNET_TIME_Timestamp server_time, | 94 | struct GNUNET_TIME_Timestamp server_time, |
95 | const char *secret_name) | 95 | const char *secret_name, |
96 | const json_t *providers) | ||
96 | { | 97 | { |
97 | if (NULL == hcpd) | 98 | if (NULL == hcpd) |
98 | { | 99 | { |
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; | |||
135 | * present in the state that was used to locate this version | 135 | * present in the state that was used to locate this version |
136 | * @param server_time when did the provider receive the upload | 136 | * @param server_time when did the provider receive the upload |
137 | * @param secret_name name the user assigned to the backup | 137 | * @param secret_name name the user assigned to the backup |
138 | * @param providers json array of providers with this policy | ||
138 | */ | 139 | */ |
139 | typedef void | 140 | typedef void |
140 | (*ANASTASIS_PolicyDiscoveryCallback)(void *cls, | 141 | (*ANASTASIS_PolicyDiscoveryCallback)(void *cls, |
@@ -143,7 +144,8 @@ typedef void | |||
143 | uint32_t version, | 144 | uint32_t version, |
144 | json_int_t attribute_mask, | 145 | json_int_t attribute_mask, |
145 | struct GNUNET_TIME_Timestamp server_time, | 146 | struct GNUNET_TIME_Timestamp server_time, |
146 | const char *secret_name); | 147 | const char *secret_name, |
148 | const json_t *providers); | ||
147 | 149 | ||
148 | 150 | ||
149 | /** | 151 | /** |
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 | */ | ||
450 | static enum GNUNET_GenericReturnValue | ||
451 | free_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 | |||
420 | void | 464 | void |
421 | ANASTASIS_policy_discovery_stop (struct ANASTASIS_PolicyDiscovery *pd) | 465 | ANASTASIS_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); |