aboutsummaryrefslogtreecommitdiff
path: root/src/dht/test_dht_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-04-19 15:16:38 +0000
committerNathan S. Evans <evans@in.tum.de>2010-04-19 15:16:38 +0000
commitc5fee7d95eaa1695999c12d059b0aa4bc566d836 (patch)
tree062ba8d6e248ccb219d081bfcab6ed3790f95676 /src/dht/test_dht_api.c
parentc268decf67ed3178b8f9beee5b6fff11ee0c0037 (diff)
downloadgnunet-c5fee7d95eaa1695999c12d059b0aa4bc566d836.tar.gz
gnunet-c5fee7d95eaa1695999c12d059b0aa4bc566d836.zip
dht api fixes, it works again (for me)
Diffstat (limited to 'src/dht/test_dht_api.c')
-rw-r--r--src/dht/test_dht_api.c66
1 files changed, 45 insertions, 21 deletions
diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c
index f99e84269..10db5f45a 100644
--- a/src/dht/test_dht_api.c
+++ b/src/dht/test_dht_api.c
@@ -32,6 +32,7 @@
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.h"
35#include "gnunet_hello_lib.h"
35 36
36#define VERBOSE GNUNET_NO 37#define VERBOSE GNUNET_NO
37 38
@@ -90,6 +91,8 @@ struct PeerContext
90 91
91static struct PeerContext p1; 92static struct PeerContext p1;
92 93
94struct RetryContext retry_context;
95
93static struct GNUNET_SCHEDULER_Handle *sched; 96static struct GNUNET_SCHEDULER_Handle *sched;
94 97
95static int ok; 98static int ok;
@@ -146,7 +149,10 @@ end_badly ()
146#if VERBOSE 149#if VERBOSE
147 fprintf (stderr, "Ending on an unhappy note.\n"); 150 fprintf (stderr, "Ending on an unhappy note.\n");
148#endif 151#endif
149 152 if (retry_context.peer_ctx->find_peer_handle != NULL)
153 GNUNET_DHT_find_peer_stop(retry_context.peer_ctx->find_peer_handle, NULL, NULL);
154 if (retry_context.retry_task != GNUNET_SCHEDULER_NO_TASK)
155 GNUNET_SCHEDULER_cancel(sched, retry_context.retry_task);
150 GNUNET_DHT_disconnect (p1.dht_handle); 156 GNUNET_DHT_disconnect (p1.dht_handle);
151 157
152 ok = 1; 158 ok = 1;
@@ -186,21 +192,41 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
186 * @param reply response 192 * @param reply response
187 */ 193 */
188void test_find_peer_processor (void *cls, 194void test_find_peer_processor (void *cls,
189 const struct GNUNET_PeerIdentity *peer, 195 const struct GNUNET_HELLO_Message *hello)
190 const struct GNUNET_MessageHeader *reply)
191{ 196{
192 struct RetryContext *retry_ctx = cls; 197 struct RetryContext *retry_ctx = cls;
198 struct GNUNET_PeerIdentity peer;
193 199
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 200 if (GNUNET_OK == GNUNET_HELLO_get_id(hello, &peer))
195 "test_find_peer_processor called (peer `%s'), stopping find peer request!\n", GNUNET_i2s(peer)); 201 {
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "test_find_peer_processor called (peer `%s'), stopping find peer request!\n", GNUNET_i2s(&peer));
196 204
197 if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK) 205 if (retry_ctx->retry_task != GNUNET_SCHEDULER_NO_TASK)
198 GNUNET_SCHEDULER_cancel(sched, retry_ctx->retry_task); 206 {
207 GNUNET_SCHEDULER_cancel(sched, retry_ctx->retry_task);
208 retry_ctx->retry_task = GNUNET_SCHEDULER_NO_TASK;
209 }
210
211 GNUNET_SCHEDULER_add_continuation (sched, &test_find_peer_stop, &p1,
212 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
213 }
214 else
215 {
216 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
217 "received find peer request, but hello_get_id failed!\n");
218 }
199 219
200 GNUNET_SCHEDULER_add_continuation (sched, &test_find_peer_stop, &p1,
201 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
202} 220}
203 221
222/**
223 * Retry the find_peer task on timeout. (Forward declaration)
224 *
225 * @param cls closure
226 * @param tc context information (why was this task triggered now?)
227 */
228void
229retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
204 230
205/** 231/**
206 * Retry the find_peer task on timeout. 232 * Retry the find_peer task on timeout.
@@ -219,9 +245,9 @@ retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
219 { 245 {
220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "test_find_peer timed out, retrying!\n"); 247 "test_find_peer timed out, retrying!\n");
222 248 retry_ctx->next_timeout = GNUNET_TIME_relative_multiply(retry_ctx->next_timeout, 2);
223 retry_ctx->peer_ctx->find_peer_handle = 249 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, 250 GNUNET_DHT_find_peer_start (retry_ctx->peer_ctx->dht_handle, retry_ctx->next_timeout, 0, &hash,
225 &test_find_peer_processor, retry_ctx, NULL, NULL); 251 &test_find_peer_processor, retry_ctx, NULL, NULL);
226 } 252 }
227 else 253 else
@@ -235,14 +261,14 @@ retry_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
235 if (retry_ctx->peer_ctx->find_peer_handle == NULL) 261 if (retry_ctx->peer_ctx->find_peer_handle == NULL)
236 GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); 262 GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1);
237 else 263 else
238 retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer, retry_ctx); 264 retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx);
239} 265}
240 266
241/** 267/**
242 * Retry the find_peer task on timeout. 268 * Retry the find_peer task on timeout.
243 * 269 *
244 * @param cls closure 270 * @param cls closure
245 * @param tc context information (why was this task triggered now) 271 * @param tc context information (why was this task triggered now?)
246 */ 272 */
247void 273void
248retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 274retry_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
@@ -270,24 +296,22 @@ test_find_peer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
270 struct PeerContext *peer = cls; 296 struct PeerContext *peer = cls;
271 GNUNET_HashCode hash; 297 GNUNET_HashCode hash;
272 memset (&hash, 42, sizeof (GNUNET_HashCode)); 298 memset (&hash, 42, sizeof (GNUNET_HashCode));
273 struct RetryContext *retry_ctx;
274 299
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n"); 300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_find_peer!\n");
276 GNUNET_assert (peer->dht_handle != NULL); 301 GNUNET_assert (peer->dht_handle != NULL);
277 302
278 retry_ctx = GNUNET_malloc(sizeof(struct RetryContext)); 303 retry_context.real_timeout = GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT);
279 retry_ctx->real_timeout = GNUNET_TIME_relative_to_absolute(TOTAL_TIMEOUT); 304 retry_context.next_timeout = BASE_TIMEOUT;
280 retry_ctx->next_timeout = BASE_TIMEOUT; 305 retry_context.peer_ctx = peer;
281 retry_ctx->peer_ctx = peer;
282 306
283 peer->find_peer_handle = 307 peer->find_peer_handle =
284 GNUNET_DHT_find_peer_start (peer->dht_handle, retry_ctx->next_timeout, 0, NULL, &hash, 308 GNUNET_DHT_find_peer_start (peer->dht_handle, retry_context.next_timeout, 0, &hash,
285 &test_find_peer_processor, retry_ctx, NULL, NULL); 309 &test_find_peer_processor, &retry_context, NULL, NULL);
286 310
287 if (peer->find_peer_handle == NULL) 311 if (peer->find_peer_handle == NULL)
288 GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1); 312 GNUNET_SCHEDULER_add_now (sched, &end_badly, &p1);
289 else 313 else
290 retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_ctx->next_timeout, &retry_find_peer_stop, retry_ctx); 314 retry_context.retry_task = GNUNET_SCHEDULER_add_delayed(sched, retry_context.next_timeout, &retry_find_peer_stop, &retry_context);
291} 315}
292 316
293/** 317/**