diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-10-03 21:37:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-10-03 21:37:15 +0000 |
commit | bd271d337e6e406862e9784051b30045d8d649a6 (patch) | |
tree | 96e5d3e1417f17f635039abdb68cccdf5917a276 /src/dht/test_dht_api.c | |
parent | d27974ef39701bdd6c2dfc6a8b6f9e06239db330 (diff) | |
download | gnunet-bd271d337e6e406862e9784051b30045d8d649a6.tar.gz gnunet-bd271d337e6e406862e9784051b30045d8d649a6.zip |
making test_dht_api work
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r-- | src/dht/test_dht_api.c | 149 |
1 files changed, 50 insertions, 99 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index f0b330d3a..b4014a92c 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include "gnunet_dht_service.h" | 34 | #include "gnunet_dht_service.h" |
35 | #include "gnunet_hello_lib.h" | 35 | #include "gnunet_hello_lib.h" |
36 | 36 | ||
37 | #define VERBOSE GNUNET_YES | 37 | #define VERBOSE GNUNET_NO |
38 | 38 | ||
39 | #define VERBOSE_ARM GNUNET_NO | 39 | #define VERBOSE_ARM GNUNET_NO |
40 | 40 | ||
@@ -109,25 +109,12 @@ GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
109 | static void | 109 | static void |
110 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 110 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
111 | { | 111 | { |
112 | /* do work here */ | ||
113 | sleep(2); | ||
114 | GNUNET_SCHEDULER_cancel (sched, die_task); | 112 | GNUNET_SCHEDULER_cancel (sched, die_task); |
115 | |||
116 | GNUNET_DHT_disconnect (p1.dht_handle); | ||
117 | die_task = GNUNET_SCHEDULER_NO_TASK; | 113 | die_task = GNUNET_SCHEDULER_NO_TASK; |
118 | 114 | GNUNET_DHT_disconnect (p1.dht_handle); | |
119 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
120 | { | 116 | "DHT disconnected, returning success!\n"); |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 117 | ok = 0; |
122 | "DHT disconnected, returning FAIL!\n"); | ||
123 | ok = 365; | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
128 | "DHT disconnected, returning success!\n"); | ||
129 | ok = 0; | ||
130 | } | ||
131 | } | 118 | } |
132 | 119 | ||
133 | static void | 120 | static void |
@@ -150,76 +137,17 @@ end_badly () | |||
150 | fprintf (stderr, "Ending on an unhappy note.\n"); | 137 | fprintf (stderr, "Ending on an unhappy note.\n"); |
151 | #endif | 138 | #endif |
152 | 139 | ||
153 | if ((retry_context.peer_ctx != NULL) && (retry_context.peer_ctx->find_peer_handle != NULL)) | 140 | if ( (retry_context.peer_ctx != NULL) && |
141 | (retry_context.peer_ctx->find_peer_handle != NULL) ) | ||
154 | GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle); | 142 | GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle); |
143 | if ( (retry_context.peer_ctx != NULL) && | ||
144 | (retry_context.peer_ctx->get_handle != NULL) ) | ||
145 | GNUNET_DHT_get_stop (retry_context.peer_ctx->get_handle); | ||
155 | if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK) | 146 | if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK) |
156 | GNUNET_SCHEDULER_cancel(sched, retry_context.retry_task); | 147 | GNUNET_SCHEDULER_cancel(sched, retry_context.retry_task); |
157 | GNUNET_DHT_disconnect (p1.dht_handle); | 148 | GNUNET_DHT_disconnect (p1.dht_handle); |
158 | |||
159 | ok = 1; | 149 | ok = 1; |
160 | return; | ||
161 | } | ||
162 | |||
163 | #if HAVE_MALICIOUS | ||
164 | |||
165 | /** | ||
166 | * Signature of the main function of a task. | ||
167 | * | ||
168 | * @param cls closure | ||
169 | * @param tc context information (why was this task triggered now) | ||
170 | */ | ||
171 | void test_set_peer_malicious_drop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
172 | { | ||
173 | struct PeerContext *peer = cls; | ||
174 | |||
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_drop!\n"); | ||
176 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
177 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
178 | |||
179 | GNUNET_assert (peer->dht_handle != NULL); | ||
180 | |||
181 | GNUNET_DHT_set_malicious_dropper (peer->dht_handle, &end, &p1); | ||
182 | } | ||
183 | |||
184 | /** | ||
185 | * Signature of the main function of a task. | ||
186 | * | ||
187 | * @param cls closure | ||
188 | * @param tc context information (why was this task triggered now) | ||
189 | */ | ||
190 | void test_set_peer_malicious_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
191 | { | ||
192 | struct PeerContext *peer = cls; | ||
193 | |||
194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_put!\n"); | ||
195 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
196 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
197 | |||
198 | GNUNET_assert (peer->dht_handle != NULL); | ||
199 | |||
200 | GNUNET_DHT_set_malicious_putter (peer->dht_handle, 750, &test_set_peer_malicious_drop, &p1); | ||
201 | } | ||
202 | |||
203 | /** | ||
204 | * Signature of the main function of a task. | ||
205 | * | ||
206 | * @param cls closure | ||
207 | * @param tc context information (why was this task triggered now) | ||
208 | */ | ||
209 | static void | ||
210 | test_set_peer_malicious_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
211 | { | ||
212 | struct PeerContext *peer = cls; | ||
213 | |||
214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_get!\n"); | ||
215 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | ||
216 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
217 | |||
218 | GNUNET_assert (peer->dht_handle != NULL); | ||
219 | |||
220 | GNUNET_DHT_set_malicious_getter (peer->dht_handle, 1500, &test_set_peer_malicious_put, &p1); | ||
221 | } | 150 | } |
222 | #endif | ||
223 | 151 | ||
224 | 152 | ||
225 | /** | 153 | /** |
@@ -235,20 +163,25 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
235 | 163 | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); | 164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer_stop!\n"); |
237 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 165 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
238 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | 166 | { |
167 | GNUNET_break (0); | ||
168 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
169 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
170 | return; | ||
171 | } | ||
239 | 172 | ||
240 | GNUNET_assert (peer->dht_handle != NULL); | 173 | GNUNET_assert (peer->dht_handle != NULL); |
241 | 174 | ||
242 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle); | 175 | GNUNET_DHT_find_peer_stop (peer->find_peer_handle); |
243 | 176 | ||
244 | #if HAVE_MALICIOUS | 177 | #if HAVE_MALICIOUS |
245 | GNUNET_SCHEDULER_add_now (sched, | 178 | GNUNET_DHT_set_malicious_getter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS); |
246 | &test_set_peer_malicious_get, &p1); | 179 | GNUNET_DHT_set_malicious_putter (peer->dht_handle, GNUNET_TIME_UNIT_SECONDS); |
247 | #else | 180 | GNUNET_DHT_set_malicious_dropper (peer->dht_handle); |
248 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), | ||
249 | &end, &p1); | ||
250 | #endif | 181 | #endif |
251 | 182 | GNUNET_SCHEDULER_add_delayed(sched, | |
183 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), | ||
184 | &end, &p1); | ||
252 | } | 185 | } |
253 | 186 | ||
254 | 187 | ||
@@ -330,9 +263,13 @@ retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
330 | } | 263 | } |
331 | 264 | ||
332 | if (retry_ctx->peer_ctx->find_peer_handle == NULL) | 265 | if (retry_ctx->peer_ctx->find_peer_handle == NULL) |
333 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 266 | { |
334 | else | 267 | GNUNET_break (0); |
335 | retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx); | 268 | GNUNET_SCHEDULER_cancel (sched, die_task); |
269 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | ||
270 | return; | ||
271 | } | ||
272 | retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx); | ||
336 | } | 273 | } |
337 | 274 | ||
338 | /** | 275 | /** |
@@ -383,9 +320,13 @@ test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
383 | &test_find_peer_processor, &retry_context); | 320 | &test_find_peer_processor, &retry_context); |
384 | 321 | ||
385 | if (peer->find_peer_handle == NULL) | 322 | if (peer->find_peer_handle == NULL) |
386 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 323 | { |
387 | else | 324 | GNUNET_break (0); |
388 | retry_context.retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_context.next_timeout, &retry_find_peer_stop, &retry_context); | 325 | GNUNET_SCHEDULER_cancel (sched, die_task); |
326 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | ||
327 | return; | ||
328 | } | ||
329 | retry_context.retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_context.next_timeout, &retry_find_peer_stop, &retry_context); | ||
389 | } | 330 | } |
390 | 331 | ||
391 | /** | 332 | /** |
@@ -401,7 +342,12 @@ test_get_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
401 | 342 | ||
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); | 343 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_get_stop!\n"); |
403 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) | 344 | if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) |
404 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | 345 | { |
346 | GNUNET_break (0); | ||
347 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
348 | GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); | ||
349 | return; | ||
350 | } | ||
405 | GNUNET_assert (peer->dht_handle != NULL); | 351 | GNUNET_assert (peer->dht_handle != NULL); |
406 | GNUNET_DHT_get_stop (peer->get_handle); | 352 | GNUNET_DHT_get_stop (peer->get_handle); |
407 | GNUNET_SCHEDULER_add_now(sched, | 353 | GNUNET_SCHEDULER_add_now(sched, |
@@ -445,7 +391,7 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
445 | peer->get_handle = | 391 | peer->get_handle = |
446 | GNUNET_DHT_get_start (peer->dht_handle, | 392 | GNUNET_DHT_get_start (peer->dht_handle, |
447 | TOTAL_TIMEOUT, | 393 | TOTAL_TIMEOUT, |
448 | 49 /* fixme: use test type */, | 394 | GNUNET_BLOCK_TYPE_TEST, |
449 | &hash, | 395 | &hash, |
450 | GNUNET_DHT_RO_NONE, | 396 | GNUNET_DHT_RO_NONE, |
451 | NULL, 0, | 397 | NULL, 0, |
@@ -453,7 +399,12 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
453 | &test_get_iterator, NULL); | 399 | &test_get_iterator, NULL); |
454 | 400 | ||
455 | if (peer->get_handle == NULL) | 401 | if (peer->get_handle == NULL) |
456 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | 402 | { |
403 | GNUNET_break (0); | ||
404 | GNUNET_SCHEDULER_cancel (sched, die_task); | ||
405 | GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); | ||
406 | return; | ||
407 | } | ||
457 | } | 408 | } |
458 | 409 | ||
459 | /** | 410 | /** |
@@ -479,7 +430,7 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
479 | 430 | ||
480 | GNUNET_DHT_put (peer->dht_handle, &hash, | 431 | GNUNET_DHT_put (peer->dht_handle, &hash, |
481 | GNUNET_DHT_RO_NONE, | 432 | GNUNET_DHT_RO_NONE, |
482 | 49 /* fixme: use test type */, | 433 | GNUNET_BLOCK_TYPE_TEST, |
483 | data_size, data, | 434 | data_size, data, |
484 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), | 435 | GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), |
485 | TOTAL_TIMEOUT, | 436 | TOTAL_TIMEOUT, |