diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-07-10 01:31:13 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-07-10 01:31:13 +0000 |
commit | 6b8400966a5e6c2194785b3a33f91b748cfa7b7b (patch) | |
tree | 0dafa7ba24c7a6dbb852fdedfd1822cd1e4835c0 /src/set/gnunet-set-profiler.c | |
parent | 084cb3e09007ef50a3d9bd29514c8ec455249633 (diff) | |
download | gnunet-6b8400966a5e6c2194785b3a33f91b748cfa7b7b.tar.gz gnunet-6b8400966a5e6c2194785b3a33f91b748cfa7b7b.zip |
- set service working
- set profiler
Diffstat (limited to 'src/set/gnunet-set-profiler.c')
-rw-r--r-- | src/set/gnunet-set-profiler.c | 229 |
1 files changed, 116 insertions, 113 deletions
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c index 814c9e436..b0c81feb1 100644 --- a/src/set/gnunet-set-profiler.c +++ b/src/set/gnunet-set-profiler.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file set/gnunet-set-profiler.c | 22 | * @file set/gnunet-set-profiler.c |
@@ -42,25 +42,17 @@ static char *op_str = "union"; | |||
42 | 42 | ||
43 | const static struct GNUNET_CONFIGURATION_Handle *config; | 43 | const static struct GNUNET_CONFIGURATION_Handle *config; |
44 | 44 | ||
45 | struct GNUNET_CONTAINER_MultiHashMap *map_a; | 45 | struct SetInfo |
46 | struct GNUNET_CONTAINER_MultiHashMap *map_b; | 46 | { |
47 | struct GNUNET_CONTAINER_MultiHashMap *map_c; | 47 | char *id; |
48 | 48 | struct GNUNET_SET_Handle *set; | |
49 | 49 | struct GNUNET_SET_OperationHandle *oh; | |
50 | /** | 50 | struct GNUNET_CONTAINER_MultiHashMap *sent; |
51 | * Elements that set a received, should match map_c | 51 | struct GNUNET_CONTAINER_MultiHashMap *received; |
52 | * in the end. | 52 | int done; |
53 | */ | 53 | } info1, info2; |
54 | struct GNUNET_CONTAINER_MultiHashMap *map_a_received; | ||
55 | |||
56 | /** | ||
57 | * Elements that set b received, should match map_c | ||
58 | * in the end. | ||
59 | */ | ||
60 | struct GNUNET_CONTAINER_MultiHashMap *map_b_received; | ||
61 | 54 | ||
62 | struct GNUNET_SET_Handle *set_a; | 55 | struct GNUNET_CONTAINER_MultiHashMap *common_sent; |
63 | struct GNUNET_SET_Handle *set_b; | ||
64 | 56 | ||
65 | struct GNUNET_HashCode app_id; | 57 | struct GNUNET_HashCode app_id; |
66 | 58 | ||
@@ -68,14 +60,6 @@ struct GNUNET_PeerIdentity local_peer; | |||
68 | 60 | ||
69 | struct GNUNET_SET_ListenHandle *set_listener; | 61 | struct GNUNET_SET_ListenHandle *set_listener; |
70 | 62 | ||
71 | struct GNUNET_SET_OperationHandle *set_oh1; | ||
72 | struct GNUNET_SET_OperationHandle *set_oh2; | ||
73 | |||
74 | |||
75 | int a_done; | ||
76 | int b_done; | ||
77 | |||
78 | |||
79 | 63 | ||
80 | static int | 64 | static int |
81 | map_remove_iterator (void *cls, | 65 | map_remove_iterator (void *cls, |
@@ -85,66 +69,69 @@ map_remove_iterator (void *cls, | |||
85 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; | 69 | struct GNUNET_CONTAINER_MultiHashMap *m = cls; |
86 | int ret; | 70 | int ret; |
87 | 71 | ||
72 | GNUNET_assert (NULL != key); | ||
73 | |||
88 | ret = GNUNET_CONTAINER_multihashmap_remove (m, key, NULL); | 74 | ret = GNUNET_CONTAINER_multihashmap_remove (m, key, NULL); |
89 | GNUNET_assert (GNUNET_OK == ret); | 75 | if (GNUNET_OK != ret) |
76 | printf ("spurious element\n"); | ||
90 | return GNUNET_YES; | 77 | return GNUNET_YES; |
91 | 78 | ||
92 | } | 79 | } |
93 | 80 | ||
94 | |||
95 | static void | 81 | static void |
96 | set_result_cb_1 (void *cls, | 82 | check_all_done (void) |
97 | const struct GNUNET_SET_Element *element, | ||
98 | enum GNUNET_SET_Status status) | ||
99 | { | 83 | { |
100 | GNUNET_assert (GNUNET_NO == a_done); | 84 | if (info1.done == GNUNET_NO || info2.done == GNUNET_NO) |
101 | GNUNET_assert (element->size == sizeof (struct GNUNET_HashCode)); | 85 | return; |
102 | switch (status) | 86 | |
103 | { | 87 | GNUNET_CONTAINER_multihashmap_iterate (info1.received, map_remove_iterator, info2.sent); |
104 | case GNUNET_SET_STATUS_DONE: | 88 | GNUNET_CONTAINER_multihashmap_iterate (info2.received, map_remove_iterator, info1.sent); |
105 | case GNUNET_SET_STATUS_HALF_DONE: | 89 | |
106 | a_done = GNUNET_YES; | 90 | printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info1.sent)); |
107 | GNUNET_CONTAINER_multihashmap_iterate (map_c, map_remove_iterator, map_a_received); | 91 | printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info2.sent)); |
108 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (map_a_received)); | 92 | |
109 | return; | 93 | GNUNET_SCHEDULER_shutdown (); |
110 | case GNUNET_SET_STATUS_FAILURE: | ||
111 | GNUNET_assert (0); | ||
112 | return; | ||
113 | case GNUNET_SET_STATUS_OK: | ||
114 | break; | ||
115 | default: | ||
116 | GNUNET_assert (0); | ||
117 | } | ||
118 | GNUNET_CONTAINER_multihashmap_put (map_a_received, | ||
119 | element->data, NULL, | ||
120 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
121 | } | 94 | } |
122 | 95 | ||
123 | 96 | ||
124 | static void | 97 | static void |
125 | set_result_cb_2 (void *cls, | 98 | set_result_cb (void *cls, |
126 | const struct GNUNET_SET_Element *element, | 99 | const struct GNUNET_SET_Element *element, |
127 | enum GNUNET_SET_Status status) | 100 | enum GNUNET_SET_Status status) |
128 | { | 101 | { |
129 | GNUNET_assert (GNUNET_NO == b_done); | 102 | struct SetInfo *info = cls; |
130 | GNUNET_assert (element->size == sizeof (struct GNUNET_HashCode)); | 103 | |
104 | GNUNET_assert (GNUNET_NO == info->done); | ||
131 | switch (status) | 105 | switch (status) |
132 | { | 106 | { |
133 | case GNUNET_SET_STATUS_DONE: | 107 | case GNUNET_SET_STATUS_DONE: |
134 | case GNUNET_SET_STATUS_HALF_DONE: | 108 | case GNUNET_SET_STATUS_HALF_DONE: |
135 | b_done = GNUNET_YES; | 109 | info->done = GNUNET_YES; |
136 | GNUNET_CONTAINER_multihashmap_iterate (map_c, map_remove_iterator, map_b_received); | 110 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s done\n", info->id); |
137 | GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (map_b_received)); | 111 | check_all_done (); |
112 | info->oh = NULL; | ||
138 | return; | 113 | return; |
139 | case GNUNET_SET_STATUS_FAILURE: | 114 | case GNUNET_SET_STATUS_FAILURE: |
140 | GNUNET_assert (0); | 115 | info->oh = NULL; |
116 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "failure\n"); | ||
117 | GNUNET_SCHEDULER_shutdown (); | ||
141 | return; | 118 | return; |
142 | case GNUNET_SET_STATUS_OK: | 119 | case GNUNET_SET_STATUS_OK: |
143 | break; | 120 | break; |
144 | default: | 121 | default: |
145 | GNUNET_assert (0); | 122 | GNUNET_assert (0); |
146 | } | 123 | } |
147 | GNUNET_CONTAINER_multihashmap_put (map_b_received, | 124 | |
125 | if (element->size != sizeof (struct GNUNET_HashCode)) | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "wrong element size: %u\n", element->size); | ||
128 | GNUNET_assert (0); | ||
129 | } | ||
130 | |||
131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set %s: got element (%s)\n", | ||
132 | info->id, GNUNET_h2s (element->data)); | ||
133 | GNUNET_assert (NULL != element->data); | ||
134 | GNUNET_CONTAINER_multihashmap_put (info->received, | ||
148 | element->data, NULL, | 135 | element->data, NULL, |
149 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 136 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
150 | } | 137 | } |
@@ -156,11 +143,16 @@ set_listen_cb (void *cls, | |||
156 | const struct GNUNET_MessageHeader *context_msg, | 143 | const struct GNUNET_MessageHeader *context_msg, |
157 | struct GNUNET_SET_Request *request) | 144 | struct GNUNET_SET_Request *request) |
158 | { | 145 | { |
159 | GNUNET_assert (NULL == set_oh2); | 146 | if (NULL == request) |
147 | { | ||
148 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "listener failed\n"); | ||
149 | return; | ||
150 | } | ||
151 | GNUNET_assert (NULL == info2.oh); | ||
160 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set listen cb called\n"); | 152 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "set listen cb called\n"); |
161 | set_oh2 = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, | 153 | info2.oh = GNUNET_SET_accept (request, GNUNET_SET_RESULT_ADDED, |
162 | set_result_cb_2, NULL); | 154 | set_result_cb, &info2); |
163 | GNUNET_SET_commit (set_oh2, set_b); | 155 | GNUNET_SET_commit (info2.oh, info2.set); |
164 | } | 156 | } |
165 | 157 | ||
166 | 158 | ||
@@ -185,6 +177,37 @@ set_insert_iterator (void *cls, | |||
185 | 177 | ||
186 | 178 | ||
187 | static void | 179 | static void |
180 | handle_shutdown (void *cls, | ||
181 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
182 | { | ||
183 | if (NULL != set_listener) | ||
184 | { | ||
185 | GNUNET_SET_listen_cancel (set_listener); | ||
186 | set_listener = NULL; | ||
187 | } | ||
188 | if (NULL != info1.oh) | ||
189 | { | ||
190 | GNUNET_SET_operation_cancel (info1.oh); | ||
191 | info1.oh = NULL; | ||
192 | } | ||
193 | if (NULL != info2.oh) | ||
194 | { | ||
195 | GNUNET_SET_operation_cancel (info2.oh); | ||
196 | info2.oh = NULL; | ||
197 | } | ||
198 | if (NULL != info1.set) | ||
199 | { | ||
200 | GNUNET_SET_destroy (info1.set); | ||
201 | info1.set = NULL; | ||
202 | } | ||
203 | if (NULL != info2.set) | ||
204 | { | ||
205 | GNUNET_SET_destroy (info2.set); | ||
206 | info2.set = NULL; | ||
207 | } | ||
208 | } | ||
209 | |||
210 | static void | ||
188 | run (void *cls, char *const *args, const char *cfgfile, | 211 | run (void *cls, char *const *args, const char *cfgfile, |
189 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 212 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
190 | { | 213 | { |
@@ -195,63 +218,41 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
195 | 218 | ||
196 | if (GNUNET_OK != GNUNET_CRYPTO_get_host_identity (cfg, &local_peer)) | 219 | if (GNUNET_OK != GNUNET_CRYPTO_get_host_identity (cfg, &local_peer)) |
197 | { | 220 | { |
198 | GNUNET_assert (0); | 221 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); |
222 | ret = 0; | ||
199 | return; | 223 | return; |
200 | } | 224 | } |
225 | |||
226 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, handle_shutdown, NULL); | ||
227 | |||
228 | info1.id = "a"; | ||
229 | info2.id = "b"; | ||
201 | 230 | ||
202 | map_a = GNUNET_CONTAINER_multihashmap_create (num_a, GNUNET_NO); | 231 | info1.sent = GNUNET_CONTAINER_multihashmap_create (num_a, GNUNET_NO); |
203 | map_b = GNUNET_CONTAINER_multihashmap_create (num_b, GNUNET_NO); | 232 | info2.sent = GNUNET_CONTAINER_multihashmap_create (num_b, GNUNET_NO); |
204 | map_c = GNUNET_CONTAINER_multihashmap_create (num_c, GNUNET_NO); | 233 | common_sent = GNUNET_CONTAINER_multihashmap_create (num_c, GNUNET_NO); |
234 | |||
235 | info1.received = GNUNET_CONTAINER_multihashmap_create (num_a, GNUNET_NO); | ||
236 | info2.received = GNUNET_CONTAINER_multihashmap_create (num_b, GNUNET_NO); | ||
205 | 237 | ||
206 | for (i = 0; i < num_a; i++) | 238 | for (i = 0; i < num_a; i++) |
207 | { | 239 | { |
208 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | 240 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); |
209 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_a, &hash)) | 241 | GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, NULL, |
210 | { | 242 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
211 | i--; | ||
212 | continue; | ||
213 | } | ||
214 | GNUNET_CONTAINER_multihashmap_put (map_a, &hash, &hash, | ||
215 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
216 | } | 243 | } |
217 | 244 | ||
218 | for (i = 0; i < num_b; i++) | 245 | for (i = 0; i < num_b; i++) |
219 | { | 246 | { |
220 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | 247 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); |
221 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_a, &hash)) | 248 | GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, NULL, |
222 | { | ||
223 | i--; | ||
224 | continue; | ||
225 | } | ||
226 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_b, &hash)) | ||
227 | { | ||
228 | i--; | ||
229 | continue; | ||
230 | } | ||
231 | GNUNET_CONTAINER_multihashmap_put (map_b, &hash, NULL, | ||
232 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 249 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
233 | } | 250 | } |
234 | 251 | ||
235 | for (i = 0; i < num_c; i++) | 252 | for (i = 0; i < num_c; i++) |
236 | { | 253 | { |
237 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | 254 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); |
238 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_a, &hash)) | 255 | GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, NULL, |
239 | { | ||
240 | i--; | ||
241 | continue; | ||
242 | } | ||
243 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_b, &hash)) | ||
244 | { | ||
245 | i--; | ||
246 | continue; | ||
247 | } | ||
248 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains (map_c, &hash)) | ||
249 | { | ||
250 | i--; | ||
251 | continue; | ||
252 | } | ||
253 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); | ||
254 | GNUNET_CONTAINER_multihashmap_put (map_c, &hash, NULL, | ||
255 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 256 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
256 | } | 257 | } |
257 | 258 | ||
@@ -259,20 +260,22 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
259 | app_id = hash; | 260 | app_id = hash; |
260 | 261 | ||
261 | /* FIXME: also implement intersection etc. */ | 262 | /* FIXME: also implement intersection etc. */ |
262 | set_a = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | 263 | info1.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); |
263 | set_b = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); | 264 | info2.set = GNUNET_SET_create (config, GNUNET_SET_OPERATION_UNION); |
264 | 265 | ||
265 | GNUNET_CONTAINER_multihashmap_iterate (map_a, set_insert_iterator, set_a); | 266 | GNUNET_CONTAINER_multihashmap_iterate (info1.sent, set_insert_iterator, info1.set); |
266 | GNUNET_CONTAINER_multihashmap_iterate (map_b, set_insert_iterator, set_b); | 267 | GNUNET_CONTAINER_multihashmap_iterate (info2.sent, set_insert_iterator, info2.set); |
267 | GNUNET_CONTAINER_multihashmap_iterate (map_c, set_insert_iterator, set_a); | 268 | GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator, info1.set); |
268 | GNUNET_CONTAINER_multihashmap_iterate (map_c, set_insert_iterator, set_b); | 269 | GNUNET_CONTAINER_multihashmap_iterate (common_sent, set_insert_iterator, info2.set); |
269 | 270 | ||
270 | set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, | 271 | set_listener = GNUNET_SET_listen (config, GNUNET_SET_OPERATION_UNION, |
271 | &app_id, set_listen_cb, NULL); | 272 | &app_id, set_listen_cb, NULL); |
272 | 273 | ||
273 | set_oh1 = GNUNET_SET_prepare (&local_peer, &app_id, NULL, salt, GNUNET_SET_RESULT_ADDED, | 274 | info1.oh = GNUNET_SET_prepare (&local_peer, &app_id, NULL, salt, GNUNET_SET_RESULT_ADDED, |
274 | set_result_cb_1, NULL); | 275 | set_result_cb, &info1); |
275 | GNUNET_SET_commit (set_oh1, set_a); | 276 | GNUNET_SET_commit (info1.oh, info1.set); |
277 | GNUNET_SET_destroy (info1.set); | ||
278 | info1.set = NULL; | ||
276 | } | 279 | } |
277 | 280 | ||
278 | 281 | ||