diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-09-27 19:11:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-09-27 19:11:47 +0000 |
commit | 1b1df3463080c4f269394dac31854a024e8c2ec4 (patch) | |
tree | 38dc6bd90c5ba17c3b84d23fc9b3cc510876f5e2 /src/dht/test_dht_api.c | |
parent | 31ee5f418d7ae0d1ede1f24397769868e4341e28 (diff) | |
download | gnunet-1b1df3463080c4f269394dac31854a024e8c2ec4.tar.gz gnunet-1b1df3463080c4f269394dac31854a024e8c2ec4.zip |
adding some stats
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r-- | src/dht/test_dht_api.c | 219 |
1 files changed, 12 insertions, 207 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 7605d8499..a38da8c73 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_os_lib.h" | 31 | #include "gnunet_os_lib.h" |
32 | #include "gnunet_program_lib.h" | 32 | #include "gnunet_program_lib.h" |
33 | #include "gnunet_scheduler_lib.h" | 33 | #include "gnunet_scheduler_lib.h" |
34 | #include "gnunet_dht_service.h" | 34 | #include "gnunet_dht_service_new.h" |
35 | #include "gnunet_hello_lib.h" | 35 | #include "gnunet_hello_lib.h" |
36 | 36 | ||
37 | #define VERBOSE GNUNET_NO | 37 | #define VERBOSE GNUNET_NO |
@@ -82,8 +82,6 @@ struct PeerContext | |||
82 | struct GNUNET_DHT_Handle *dht_handle; | 82 | struct GNUNET_DHT_Handle *dht_handle; |
83 | struct GNUNET_PeerIdentity id; | 83 | struct GNUNET_PeerIdentity id; |
84 | struct GNUNET_DHT_GetHandle *get_handle; | 84 | struct GNUNET_DHT_GetHandle *get_handle; |
85 | struct GNUNET_DHT_FindPeerHandle *find_peer_handle; | ||
86 | |||
87 | #if START_ARM | 85 | #if START_ARM |
88 | struct GNUNET_OS_Process *arm_proc; | 86 | struct GNUNET_OS_Process *arm_proc; |
89 | #endif | 87 | #endif |
@@ -139,12 +137,6 @@ end_badly () | |||
139 | #endif | 137 | #endif |
140 | 138 | ||
141 | if ((retry_context.peer_ctx != NULL) && | 139 | if ((retry_context.peer_ctx != NULL) && |
142 | (retry_context.peer_ctx->find_peer_handle != NULL)) | ||
143 | { | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping find peer request!\n"); | ||
145 | GNUNET_DHT_find_peer_stop (retry_context.peer_ctx->find_peer_handle); | ||
146 | } | ||
147 | if ((retry_context.peer_ctx != NULL) && | ||
148 | (retry_context.peer_ctx->get_handle != NULL)) | 140 | (retry_context.peer_ctx->get_handle != NULL)) |
149 | { | 141 | { |
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping get request!\n"); | 142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping get request!\n"); |
@@ -163,197 +155,7 @@ end_badly () | |||
163 | * @param cls closure | 155 | * @param cls closure |
164 | * @param tc context information (why was this task triggered now) | 156 | * @param tc context information (why was this task triggered now) |
165 | */ | 157 | */ |
166 | void | 158 | static void |
167 | test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
168 | { | ||
169 | struct PeerContext *peer = cls; | ||
170 | |||
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); | ||
172 | if ((tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT) != 0) | ||
173 | { | ||
174 | GNUNET_break (0); | ||
175 | GNUNET_SCHEDULER_cancel (die_task); | ||
176 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | GNUNET_assert (peer->dht_handle != NULL); | ||
181 | |||
182 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle); | ||
183 | peer->find_peer_handle = NULL; | ||
184 | |||
185 | #if HAVE_MALICIOUS | ||
186 | GNUNET_DHT_set_malicious_getter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS, | ||
187 | NULL, NULL); | ||
188 | GNUNET_DHT_set_malicious_putter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS, | ||
189 | NULL, NULL); | ||
190 | GNUNET_DHT_set_malicious_dropper (peer->dht_handle, NULL, NULL); | ||
191 | #endif | ||
192 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
193 | (GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1); | ||
194 | } | ||
195 | |||
196 | |||
197 | /** | ||
198 | * Iterator called on each result obtained from a find peer | ||
199 | * operation | ||
200 | * | ||
201 | * @param cls closure (NULL) | ||
202 | * @param peer the peer we learned about | ||
203 | * @param reply response | ||
204 | */ | ||
205 | void | ||
206 | test_find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello) | ||
207 | { | ||
208 | struct RetryContext *retry_ctx = cls; | ||
209 | struct GNUNET_PeerIdentity peer; | ||
210 | |||
211 | if (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer)) | ||
212 | { | ||
213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
214 | "test_find_peer_processor called (peer `%s'), stopping find peer request!\n", | ||
215 | GNUNET_i2s (&peer)); | ||
216 | |||
217 | if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK) | ||
218 | { | ||
219 | GNUNET_SCHEDULER_cancel (retry_ctx->retry_task); | ||
220 | retry_ctx->retry_task = GNUNET_SCHEDULER_NO_TASK; | ||
221 | } | ||
222 | |||
223 | GNUNET_SCHEDULER_add_continuation (&test_find_peer_stop, &p1, | ||
224 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
225 | } | ||
226 | else | ||
227 | { | ||
228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
229 | "received find peer request, but hello_get_id failed!\n"); | ||
230 | } | ||
231 | |||
232 | } | ||
233 | |||
234 | /** | ||
235 | * Retry the find_peer task on timeout. (Forward declaration) | ||
236 | * | ||
237 | * @param cls closure | ||
238 | * @param tc context information (why was this task triggered now?) | ||
239 | */ | ||
240 | void | ||
241 | retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
242 | |||
243 | /** | ||
244 | * Retry the find_peer task on timeout. | ||
245 | * | ||
246 | * @param cls closure | ||
247 | * @param tc context information (why was this task triggered now) | ||
248 | */ | ||
249 | void | ||
250 | retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
251 | { | ||
252 | struct RetryContext *retry_ctx = cls; | ||
253 | GNUNET_HashCode hash; | ||
254 | |||
255 | memset (&hash, 42, sizeof (GNUNET_HashCode)); | ||
256 | |||
257 | if (GNUNET_TIME_absolute_get_remaining (retry_ctx->real_timeout).rel_value > | ||
258 | 0) | ||
259 | { | ||
260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
261 | "test_find_peer timed out, retrying!\n"); | ||
262 | retry_ctx->next_timeout = | ||
263 | GNUNET_TIME_relative_multiply (retry_ctx->next_timeout, 2); | ||
264 | retry_ctx->peer_ctx->find_peer_handle = | ||
265 | GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle, | ||
266 | retry_ctx->next_timeout, &hash, | ||
267 | GNUNET_DHT_RO_NONE, | ||
268 | &test_find_peer_processor, retry_ctx); | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
273 | "test_find_peer timed out for good, failing!\n"); | ||
274 | |||
275 | retry_ctx->peer_ctx->find_peer_handle = NULL; | ||
276 | } | ||
277 | |||
278 | if (retry_ctx->peer_ctx->find_peer_handle == NULL) | ||
279 | { | ||
280 | GNUNET_break (0); | ||
281 | GNUNET_SCHEDULER_cancel (die_task); | ||
282 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, &p1); | ||
283 | return; | ||
284 | } | ||
285 | retry_ctx->retry_task = | ||
286 | GNUNET_SCHEDULER_add_delayed (retry_ctx->next_timeout, | ||
287 | &retry_find_peer_stop, retry_ctx); | ||
288 | } | ||
289 | |||
290 | /** | ||
291 | * Retry the find_peer task on timeout. | ||
292 | * | ||
293 | * @param cls closure | ||
294 | * @param tc context information (why was this task triggered now?) | ||
295 | */ | ||
296 | void | ||
297 | retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
298 | { | ||
299 | struct RetryContext *retry_ctx = cls; | ||
300 | GNUNET_HashCode hash; | ||
301 | |||
302 | memset (&hash, 42, sizeof (GNUNET_HashCode)); | ||
303 | |||
304 | if (retry_ctx->peer_ctx->find_peer_handle != NULL) | ||
305 | { | ||
306 | GNUNET_DHT_find_peer_stop (retry_ctx->peer_ctx->find_peer_handle); | ||
307 | retry_ctx->peer_ctx->find_peer_handle = NULL; | ||
308 | } | ||
309 | GNUNET_SCHEDULER_add_now (&retry_find_peer, retry_ctx); | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * Entry point for test of find_peer functionality. | ||
314 | * | ||
315 | * @param cls closure | ||
316 | * @param tc context information (why was this task triggered now) | ||
317 | */ | ||
318 | void | ||
319 | test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
320 | { | ||
321 | struct PeerContext *peer = cls; | ||
322 | GNUNET_HashCode hash; | ||
323 | |||
324 | memset (&hash, 42, sizeof (GNUNET_HashCode)); | ||
325 | |||
326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n"); | ||
327 | GNUNET_assert (peer->dht_handle != NULL); | ||
328 | |||
329 | retry_context.real_timeout = GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT); | ||
330 | retry_context.next_timeout = BASE_TIMEOUT; | ||
331 | retry_context.peer_ctx = peer; | ||
332 | |||
333 | peer->find_peer_handle = | ||
334 | GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout, | ||
335 | &hash, GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
336 | &test_find_peer_processor, &retry_context); | ||
337 | |||
338 | if (peer->find_peer_handle == NULL) | ||
339 | { | ||
340 | GNUNET_break (0); | ||
341 | GNUNET_SCHEDULER_cancel (die_task); | ||
342 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, &p1); | ||
343 | return; | ||
344 | } | ||
345 | retry_context.retry_task = | ||
346 | GNUNET_SCHEDULER_add_delayed (retry_context.next_timeout, | ||
347 | &retry_find_peer_stop, &retry_context); | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * Signature of the main function of a task. | ||
352 | * | ||
353 | * @param cls closure | ||
354 | * @param tc context information (why was this task triggered now) | ||
355 | */ | ||
356 | void | ||
357 | test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 159 | test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
358 | { | 160 | { |
359 | struct PeerContext *peer = cls; | 161 | struct PeerContext *peer = cls; |
@@ -369,14 +171,17 @@ test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
369 | GNUNET_assert (peer->dht_handle != NULL); | 171 | GNUNET_assert (peer->dht_handle != NULL); |
370 | GNUNET_DHT_get_stop (peer->get_handle); | 172 | GNUNET_DHT_get_stop (peer->get_handle); |
371 | peer->get_handle = NULL; | 173 | peer->get_handle = NULL; |
372 | GNUNET_SCHEDULER_add_now (&test_find_peer, &p1); | 174 | GNUNET_SCHEDULER_add_now (&end, &p1); |
373 | } | 175 | } |
374 | 176 | ||
375 | void | 177 | |
178 | static void | ||
376 | test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, | 179 | test_get_iterator (void *cls, struct GNUNET_TIME_Absolute exp, |
377 | const GNUNET_HashCode * key, | 180 | const GNUNET_HashCode * key, |
378 | const struct GNUNET_PeerIdentity *const *get_path, | 181 | const struct GNUNET_PeerIdentity *get_path, |
379 | const struct GNUNET_PeerIdentity *const *put_path, | 182 | unsigned int get_path_length, |
183 | const struct GNUNET_PeerIdentity *put_path, | ||
184 | unsigned int put_path_length, | ||
380 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) | 185 | enum GNUNET_BLOCK_Type type, size_t size, const void *data) |
381 | { | 186 | { |
382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 187 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -409,8 +214,8 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
409 | peer->get_handle = | 214 | peer->get_handle = |
410 | GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, | 215 | GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, |
411 | GNUNET_BLOCK_TYPE_TEST, &hash, | 216 | GNUNET_BLOCK_TYPE_TEST, &hash, |
412 | DEFAULT_GET_REPLICATION, GNUNET_DHT_RO_NONE, NULL, | 217 | 1, GNUNET_DHT_RO_NONE, NULL, |
413 | 0, NULL, 0, &test_get_iterator, NULL); | 218 | 0, &test_get_iterator, NULL); |
414 | 219 | ||
415 | if (peer->get_handle == NULL) | 220 | if (peer->get_handle == NULL) |
416 | { | 221 | { |
@@ -445,7 +250,7 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
445 | 250 | ||
446 | GNUNET_assert (peer->dht_handle != NULL); | 251 | GNUNET_assert (peer->dht_handle != NULL); |
447 | 252 | ||
448 | GNUNET_DHT_put (peer->dht_handle, &hash, DEFAULT_PUT_REPLICATION, | 253 | GNUNET_DHT_put (peer->dht_handle, &hash, 1, |
449 | GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data, | 254 | GNUNET_DHT_RO_NONE, GNUNET_BLOCK_TYPE_TEST, data_size, data, |
450 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), | 255 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), |
451 | TOTAL_TIMEOUT, &test_get, &p1); | 256 | TOTAL_TIMEOUT, &test_get, &p1); |