aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dht/gnunet-service-dht.c3
-rw-r--r--src/dht/test_dht_api.c113
2 files changed, 106 insertions, 10 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 60a91eb3d..c1950673e 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -492,11 +492,10 @@ handle_dht_get (void *cls, struct GNUNET_DHT_GetMessage *get_msg,
492 GNUNET_DATACACHE_get (datacache, message_context->key, get_type, 492 GNUNET_DATACACHE_get (datacache, message_context->key, get_type,
493 &datacache_get_iterator, datacache_get_context); 493 &datacache_get_iterator, datacache_get_context);
494 494
495#if DEBUG_DHT
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 "`%s': Found %d results for local `%s' request\n", "DHT", 496 "`%s': Found %d results for local `%s' request\n", "DHT",
498 results, "GET"); 497 results, "GET");
499#endif 498
500 GNUNET_free (datacache_get_context); 499 GNUNET_free (datacache_get_context);
501 /* FIXME: Implement get functionality here */ 500 /* FIXME: Implement get functionality here */
502} 501}
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index 1e1a01e6e..f99e84269 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -40,12 +40,41 @@
40#define START_ARM GNUNET_YES 40#define START_ARM GNUNET_YES
41 41
42/** 42/**
43 * How long until we give up on transmitting the message? 43 * How long until we really give up on a particular testcase portion?
44 */ 44 */
45#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 50) 45#define TOTAL_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 50)
46
47/**
48 * How long until we give up on any particular operation (and retry)?
49 */
50#define BASE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
46 51
47#define MTYPE 12345 52#define MTYPE 12345
48 53
54struct RetryContext
55{
56 /**
57 * When to really abort the operation.
58 */
59 struct GNUNET_TIME_Absolute real_timeout;
60
61 /**
62 * What timeout to set for the current attempt (increases)
63 */
64 struct GNUNET_TIME_Relative next_timeout;
65
66 /**
67 * The context of the peer we are dealing with.
68 */
69 struct PeerContext *peer_ctx;
70
71 /**
72 * The task identifier of the retry task, so it can be cancelled.
73 */
74 GNUNET_SCHEDULER_TaskIdentifier retry_task;
75
76};
77
49struct PeerContext 78struct PeerContext
50{ 79{
51 struct GNUNET_CONFIGURATION_Handle *cfg; 80 struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -160,17 +189,77 @@ void test_find_peer_processor (void *cls,
160 const struct GNUNET_PeerIdentity *peer, 189 const struct GNUNET_PeerIdentity *peer,
161 const struct GNUNET_MessageHeader *reply) 190 const struct GNUNET_MessageHeader *reply)
162{ 191{
192 struct RetryContext *retry_ctx = cls;
163 193
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 "test_find_peer_processor called (peer `%s'), stopping find peer request!\n", GNUNET_i2s(peer)); 195 "test_find_peer_processor called (peer `%s'), stopping find peer request!\n", GNUNET_i2s(peer));
166 196
197 if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK)
198 GNUNET_SCHEDULER_cancel(sched, retry_ctx->retry_task);
199
167 GNUNET_SCHEDULER_add_continuation (sched, &test_find_peer_stop, &p1, 200 GNUNET_SCHEDULER_add_continuation (sched, &test_find_peer_stop, &p1,
168 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 201 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
169} 202}
170 203
171 204
172/** 205/**
173 * Signature of the main function of a task. 206 * Retry the find_peer task on timeout.
207 *
208 * @param cls closure
209 * @param tc context information (why was this task triggered now)
210 */
211void
212retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213{
214 struct RetryContext *retry_ctx = cls;
215 GNUNET_HashCode hash;
216 memset (&hash, 42, sizeof (GNUNET_HashCode));
217
218 if (GNUNET_TIME_absolute_get_remaining(retry_ctx->real_timeout).value > 0)
219 {
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "test_find_peer timed out, retrying!\n");
222
223 retry_ctx->peer_ctx->find_peer_handle =
224 GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle, retry_ctx->next_timeout, 0, NULL, &hash,
225 &test_find_peer_processor, retry_ctx, NULL, NULL);
226 }
227 else
228 {
229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "test_find_peer timed out for good, failing!\n");
231
232 retry_ctx->peer_ctx->find_peer_handle = NULL;
233 }
234
235 if (retry_ctx->peer_ctx->find_peer_handle == NULL)
236 GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1);
237 else
238 retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer, retry_ctx);
239}
240
241/**
242 * Retry the find_peer task on timeout.
243 *
244 * @param cls closure
245 * @param tc context information (why was this task triggered now)
246 */
247void
248retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
249{
250 struct RetryContext *retry_ctx = cls;
251 GNUNET_HashCode hash;
252 memset (&hash, 42, sizeof (GNUNET_HashCode));
253
254 if (retry_ctx->peer_ctx->find_peer_handle != NULL)
255 GNUNET_DHT_find_peer_stop(retry_ctx->peer_ctx->find_peer_handle, &retry_find_peer, retry_ctx);
256 else
257 GNUNET_SCHEDULER_add_now (sched, &retry_find_peer, retry_ctx);
258
259}
260
261/**
262 * Entry point for test of find_peer functionality.
174 * 263 *
175 * @param cls closure 264 * @param cls closure
176 * @param tc context information (why was this task triggered now) 265 * @param tc context information (why was this task triggered now)
@@ -181,16 +270,24 @@ test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
181 struct PeerContext *peer = cls; 270 struct PeerContext *peer = cls;
182 GNUNET_HashCode hash; 271 GNUNET_HashCode hash;
183 memset (&hash, 42, sizeof (GNUNET_HashCode)); 272 memset (&hash, 42, sizeof (GNUNET_HashCode));
273 struct RetryContext *retry_ctx;
184 274
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n"); 275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n");
186 GNUNET_assert (peer->dht_handle != NULL); 276 GNUNET_assert (peer->dht_handle != NULL);
187 277
278 retry_ctx = GNUNET_malloc(sizeof(struct RetryContext));
279 retry_ctx->real_timeout = GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT);
280 retry_ctx->next_timeout = BASE_TIMEOUT;
281 retry_ctx->peer_ctx = peer;
282
188 peer->find_peer_handle = 283 peer->find_peer_handle =
189 GNUNET_DHT_find_peer_start (peer->dht_handle, TIMEOUT, 0, NULL, &hash, 284 GNUNET_DHT_find_peer_start (peer->dht_handle, retry_ctx->next_timeout, 0, NULL, &hash,
190 &test_find_peer_processor, NULL, NULL, NULL); 285 &test_find_peer_processor, retry_ctx, NULL, NULL);
191 286
192 if (peer->find_peer_handle == NULL) 287 if (peer->find_peer_handle == NULL)
193 GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); 288 GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1);
289 else
290 retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx);
194} 291}
195 292
196/** 293/**
@@ -247,7 +344,7 @@ test_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
247 GNUNET_assert (peer->dht_handle != NULL); 344 GNUNET_assert (peer->dht_handle != NULL);
248 345
249 peer->get_handle = 346 peer->get_handle =
250 GNUNET_DHT_get_start (peer->dht_handle, TIMEOUT, 42, &hash, 347 GNUNET_DHT_get_start (peer->dht_handle, TOTAL_TIMEOUT, 42, &hash,
251 &test_get_iterator, NULL, NULL, NULL); 348 &test_get_iterator, NULL, NULL, NULL);
252 349
253 if (peer->get_handle == NULL) 350 if (peer->get_handle == NULL)
@@ -276,7 +373,7 @@ test_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
276 GNUNET_assert (peer->dht_handle != NULL); 373 GNUNET_assert (peer->dht_handle != NULL);
277 374
278 GNUNET_DHT_put (peer->dht_handle, &hash, 42, data_size, data, 375 GNUNET_DHT_put (peer->dht_handle, &hash, 42, data_size, data,
279 GNUNET_TIME_relative_to_absolute (TIMEOUT), TIMEOUT, 376 GNUNET_TIME_relative_to_absolute (TOTAL_TIMEOUT), TOTAL_TIMEOUT,
280 &test_get, &p1); 377 &test_get, &p1);
281 378
282} 379}
@@ -316,7 +413,7 @@ run (void *cls,
316 413
317 GNUNET_SCHEDULER_add_delayed (sched, 414 GNUNET_SCHEDULER_add_delayed (sched,
318 GNUNET_TIME_relative_multiply 415 GNUNET_TIME_relative_multiply
319 (GNUNET_TIME_UNIT_SECONDS, 3), &test_put, 416 (GNUNET_TIME_UNIT_SECONDS, 1), &test_put,
320 &p1); 417 &p1);
321} 418}
322 419