aboutsummaryrefslogtreecommitdiff
path: root/src/dv/dv_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-04-01 15:51:38 +0000
committerNathan S. Evans <evans@in.tum.de>2010-04-01 15:51:38 +0000
commitd816ced9a78620f055abc3c556736ee2887f1603 (patch)
treea398d5764fb40495f4724cf13c30dcad530180a2 /src/dv/dv_api.c
parent36bfd342bf5703f0f482e0ea0c6adf0682f3d014 (diff)
downloadgnunet-d816ced9a78620f055abc3c556736ee2887f1603.tar.gz
gnunet-d816ced9a78620f055abc3c556736ee2887f1603.zip
dv changes, closer to a working state
Diffstat (limited to 'src/dv/dv_api.c')
-rw-r--r--src/dv/dv_api.c68
1 files changed, 64 insertions, 4 deletions
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index 7b1a4f0cf..abfb249e4 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -57,6 +57,8 @@ struct PendingMessages
57 57
58}; 58};
59 59
60
61
60/** 62/**
61 * Handle for the service. 63 * Handle for the service.
62 */ 64 */
@@ -110,6 +112,21 @@ struct GNUNET_DV_Handle
110}; 112};
111 113
112 114
115struct StartContext
116{
117
118 /**
119 * Start message
120 */
121 struct GNUNET_MessageHeader *message;
122
123 /**
124 * Handle to service, in case of timeout
125 */
126 struct GNUNET_DV_Handle *handle;
127};
128
129
113/** 130/**
114 * Try to (re)connect to the dv service. 131 * Try to (re)connect to the dv service.
115 * 132 *
@@ -215,7 +232,7 @@ static void process_pending_message(struct GNUNET_DV_Handle *handle)
215 GNUNET_YES, 232 GNUNET_YES,
216 &transmit_pending, handle))) 233 &transmit_pending, handle)))
217 { 234 {
218#if DEBUG_STATISTICS 235#if DEBUG_DV
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220 "Failed to transmit request to dv service.\n"); 237 "Failed to transmit request to dv service.\n");
221#endif 238#endif
@@ -259,8 +276,6 @@ static void add_pending(struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMe
259} 276}
260 277
261 278
262
263
264void handle_message_receipt (void *cls, 279void handle_message_receipt (void *cls,
265 const struct GNUNET_MessageHeader * msg) 280 const struct GNUNET_MessageHeader * msg)
266{ 281{
@@ -276,6 +291,9 @@ void handle_message_receipt (void *cls,
276 return; /* Connection closed? */ 291 return; /* Connection closed? */
277 } 292 }
278 293
294#if DEBUG_DV
295 fprintf(stdout, "dv api receives message of type %d or raw %d\n", ntohs(msg->type), msg->type);
296#endif
279 GNUNET_assert(ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE); 297 GNUNET_assert(ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE);
280 298
281 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_MessageReceived)) 299 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_MessageReceived))
@@ -348,6 +366,34 @@ int GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
348 return GNUNET_OK; 366 return GNUNET_OK;
349} 367}
350 368
369/* Forward declaration */
370void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle);
371
372static size_t
373transmit_start (void *cls, size_t size, void *buf)
374{
375 struct StartContext *start_context = cls;
376 struct GNUNET_DV_Handle *handle = start_context->handle;
377 size_t tsize;
378
379 if (buf == NULL)
380 {
381 GNUNET_free(start_context->message);
382 GNUNET_free(start_context);
383 GNUNET_DV_disconnect(handle);
384 return 0;
385 }
386
387 tsize = ntohs(start_context->message->size);
388 if (size >= tsize)
389 {
390 memcpy(buf, start_context->message, tsize);
391 return tsize;
392 }
393
394 return 0;
395}
396
351/** 397/**
352 * Connect to the DV service 398 * Connect to the DV service
353 * 399 *
@@ -365,7 +411,8 @@ GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
365 void *receive_handler_cls) 411 void *receive_handler_cls)
366{ 412{
367 struct GNUNET_DV_Handle *handle; 413 struct GNUNET_DV_Handle *handle;
368 414 struct GNUNET_MessageHeader *start_message;
415 struct StartContext *start_context;
369 handle = GNUNET_malloc(sizeof(struct GNUNET_DV_Handle)); 416 handle = GNUNET_malloc(sizeof(struct GNUNET_DV_Handle));
370 417
371 handle->cfg = cfg; 418 handle->cfg = cfg;
@@ -384,6 +431,19 @@ GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
384 return NULL; 431 return NULL;
385 } 432 }
386 433
434 start_message = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
435 start_message->size = htons(sizeof(struct GNUNET_MessageHeader));
436 start_message->type = htons(GNUNET_MESSAGE_TYPE_DV_START);
437
438 start_context = GNUNET_malloc(sizeof(struct StartContext));
439 start_context->handle = handle;
440 start_context->message = start_message;
441 GNUNET_CLIENT_notify_transmit_ready (handle->client,
442 sizeof(struct GNUNET_MessageHeader),
443 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
444 GNUNET_YES,
445 &transmit_start, start_context);
446
387 GNUNET_CLIENT_receive (handle->client, 447 GNUNET_CLIENT_receive (handle->client,
388 &handle_message_receipt, 448 &handle_message_receipt,
389 handle, GNUNET_TIME_UNIT_FOREVER_REL); 449 handle, GNUNET_TIME_UNIT_FOREVER_REL);