aboutsummaryrefslogtreecommitdiff
path: root/src/dv/dv_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dv/dv_api.c')
-rw-r--r--src/dv/dv_api.c347
1 files changed, 188 insertions, 159 deletions
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index d954d718b..7a250b5a6 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -152,11 +152,10 @@ struct SendCallbackContext
152 * @param hash set to uid (extended with zeros) 152 * @param hash set to uid (extended with zeros)
153 */ 153 */
154static void 154static void
155hash_from_uid (uint32_t uid, 155hash_from_uid (uint32_t uid, GNUNET_HashCode * hash)
156 GNUNET_HashCode *hash)
157{ 156{
158 memset (hash, 0, sizeof(GNUNET_HashCode)); 157 memset (hash, 0, sizeof (GNUNET_HashCode));
159 *((uint32_t*)hash) = uid; 158 *((uint32_t *) hash) = uid;
160} 159}
161 160
162/** 161/**
@@ -181,7 +180,7 @@ try_connect (struct GNUNET_DV_Handle *ret)
181 return GNUNET_NO; 180 return GNUNET_NO;
182} 181}
183 182
184static void process_pending_message(struct GNUNET_DV_Handle *handle); 183static void process_pending_message (struct GNUNET_DV_Handle *handle);
185 184
186/** 185/**
187 * Send complete, schedule next 186 * Send complete, schedule next
@@ -193,10 +192,11 @@ static void
193finish (struct GNUNET_DV_Handle *handle, int code) 192finish (struct GNUNET_DV_Handle *handle, int code)
194{ 193{
195 struct PendingMessages *pos = handle->current; 194 struct PendingMessages *pos = handle->current;
195
196 handle->current = NULL; 196 handle->current = NULL;
197 process_pending_message (handle); 197 process_pending_message (handle);
198 198
199 GNUNET_free(pos->msg); 199 GNUNET_free (pos->msg);
200 GNUNET_free (pos); 200 GNUNET_free (pos);
201} 201}
202 202
@@ -218,31 +218,35 @@ transmit_pending (void *cls, size_t size, void *buf)
218 218
219#if DEBUG_DV 219#if DEBUG_DV
220 if (handle->current != NULL) 220 if (handle->current != NULL)
221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending called with message type %d\n", ntohs(handle->current->msg->header.type)); 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "DV API: Transmit pending called with message type %d\n",
223 ntohs (handle->current->msg->header.type));
222#endif 224#endif
223 225
224 if (buf == NULL) 226 if (buf == NULL)
225 { 227 {
226#if DEBUG_DV 228#if DEBUG_DV
227 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Transmit pending FAILED!\n\n\n"); 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
230 "DV API: Transmit pending FAILED!\n\n\n");
228#endif 231#endif
229 finish(handle, GNUNET_SYSERR); 232 finish (handle, GNUNET_SYSERR);
230 return 0; 233 return 0;
231 } 234 }
232 handle->th = NULL; 235 handle->th = NULL;
233 236
234 ret = 0; 237 ret = 0;
235 238
236 if (handle->current != NULL) 239 if (handle->current != NULL)
237 { 240 {
238 tsize = ntohs(handle->current->msg->header.size); 241 tsize = ntohs (handle->current->msg->header.size);
239 if (size >= tsize) 242 if (size >= tsize)
240 { 243 {
241 memcpy(buf, handle->current->msg, tsize); 244 memcpy (buf, handle->current->msg, tsize);
242#if DEBUG_DV 245#if DEBUG_DV
243 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Copied %d bytes into buffer!\n\n\n", tsize); 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "DV API: Copied %d bytes into buffer!\n\n\n", tsize);
244#endif 248#endif
245 finish(handle, GNUNET_OK); 249 finish (handle, GNUNET_OK);
246 return tsize; 250 return tsize;
247 } 251 }
248 252
@@ -256,39 +260,44 @@ transmit_pending (void *cls, size_t size, void *buf)
256 * 260 *
257 * @param handle handle to the distance vector service 261 * @param handle handle to the distance vector service
258 */ 262 */
259static void process_pending_message(struct GNUNET_DV_Handle *handle) 263static void
264process_pending_message (struct GNUNET_DV_Handle *handle)
260{ 265{
261 266
262 if (handle->current != NULL) 267 if (handle->current != NULL)
263 return; /* action already pending */ 268 return; /* action already pending */
264 if (GNUNET_YES != try_connect (handle)) 269 if (GNUNET_YES != try_connect (handle))
265 { 270 {
266 finish (handle, GNUNET_SYSERR); 271 finish (handle, GNUNET_SYSERR);
267 return; 272 return;
268 } 273 }
269 274
270 /* schedule next action */ 275 /* schedule next action */
271 handle->current = handle->pending_list; 276 handle->current = handle->pending_list;
272 if (NULL == handle->current) 277 if (NULL == handle->current)
273 { 278 {
274 return; 279 return;
275 } 280 }
276 handle->pending_list = handle->pending_list->next; 281 handle->pending_list = handle->pending_list->next;
277 handle->current->next = NULL; 282 handle->current->next = NULL;
278 283
279 if (NULL == 284 if (NULL ==
280 (handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client, 285 (handle->th = GNUNET_CLIENT_notify_transmit_ready (handle->client,
281 ntohs(handle->current->msg->header.size), 286 ntohs
282 handle->current->msg->timeout, 287 (handle->current->
288 msg->header.size),
289 handle->current->
290 msg->timeout,
283 GNUNET_YES, 291 GNUNET_YES,
284 &transmit_pending, handle))) 292 &transmit_pending,
285 { 293 handle)))
294 {
286#if DEBUG_DV 295#if DEBUG_DV
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "Failed to transmit request to dv service.\n"); 297 "Failed to transmit request to dv service.\n");
289#endif 298#endif
290 finish (handle, GNUNET_SYSERR); 299 finish (handle, GNUNET_SYSERR);
291 } 300 }
292} 301}
293 302
294/** 303/**
@@ -297,31 +306,32 @@ static void process_pending_message(struct GNUNET_DV_Handle *handle)
297 * @param handle handle to the specified DV api 306 * @param handle handle to the specified DV api
298 * @param msg the message to add to the list 307 * @param msg the message to add to the list
299 */ 308 */
300static void add_pending(struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMessage *msg) 309static void
310add_pending (struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMessage *msg)
301{ 311{
302 struct PendingMessages *new_message; 312 struct PendingMessages *new_message;
303 struct PendingMessages *pos; 313 struct PendingMessages *pos;
304 struct PendingMessages *last; 314 struct PendingMessages *last;
305 315
306 new_message = GNUNET_malloc(sizeof(struct PendingMessages)); 316 new_message = GNUNET_malloc (sizeof (struct PendingMessages));
307 new_message->msg = msg; 317 new_message->msg = msg;
308 318
309 if (handle->pending_list != NULL) 319 if (handle->pending_list != NULL)
320 {
321 pos = handle->pending_list;
322 while (pos != NULL)
310 { 323 {
311 pos = handle->pending_list; 324 last = pos;
312 while(pos != NULL) 325 pos = pos->next;
313 {
314 last = pos;
315 pos = pos->next;
316 }
317 last->next = new_message;
318 } 326 }
327 last->next = new_message;
328 }
319 else 329 else
320 { 330 {
321 handle->pending_list = new_message; 331 handle->pending_list = new_message;
322 } 332 }
323 333
324 process_pending_message(handle); 334 process_pending_message (handle);
325} 335}
326 336
327/** 337/**
@@ -331,8 +341,8 @@ static void add_pending(struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMe
331 * @param cls the handle to the DV API 341 * @param cls the handle to the DV API
332 * @param msg the message that was received 342 * @param msg the message that was received
333 */ 343 */
334void handle_message_receipt (void *cls, 344void
335 const struct GNUNET_MessageHeader * msg) 345handle_message_receipt (void *cls, const struct GNUNET_MessageHeader *msg)
336{ 346{
337 struct GNUNET_DV_Handle *handle = cls; 347 struct GNUNET_DV_Handle *handle = cls;
338 struct GNUNET_DV_MessageReceived *received_msg; 348 struct GNUNET_DV_MessageReceived *received_msg;
@@ -348,65 +358,75 @@ void handle_message_receipt (void *cls,
348 if (msg == NULL) 358 if (msg == NULL)
349 { 359 {
350#if DEBUG_DV_MESSAGES 360#if DEBUG_DV_MESSAGES
351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: connection closed\n"); 361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: connection closed\n");
352#endif 362#endif
353 return; /* Connection closed? */ 363 return; /* Connection closed? */
354 } 364 }
355 365
356 GNUNET_assert((ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE) || (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT)); 366 GNUNET_assert ((ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE)
367 || (ntohs (msg->type) ==
368 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT));
357 369
358 switch (ntohs(msg->type)) 370 switch (ntohs (msg->type))
359 { 371 {
360 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE: 372 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE:
361 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_MessageReceived)) 373 if (ntohs (msg->size) < sizeof (struct GNUNET_DV_MessageReceived))
362 return; 374 return;
363 375
364 received_msg = (struct GNUNET_DV_MessageReceived *)msg; 376 received_msg = (struct GNUNET_DV_MessageReceived *) msg;
365 packed_msg_len = ntohl(received_msg->msg_len); 377 packed_msg_len = ntohl (received_msg->msg_len);
366 sender_address_len = ntohs(msg->size) - packed_msg_len - sizeof(struct GNUNET_DV_MessageReceived); 378 sender_address_len =
367 GNUNET_assert(sender_address_len > 0); 379 ntohs (msg->size) - packed_msg_len -
368 sender_address = GNUNET_malloc(sender_address_len); 380 sizeof (struct GNUNET_DV_MessageReceived);
369 memcpy(sender_address, &received_msg[1], sender_address_len); 381 GNUNET_assert (sender_address_len > 0);
370 packed_msg_start = (char *)&received_msg[1]; 382 sender_address = GNUNET_malloc (sender_address_len);
371 packed_msg = GNUNET_malloc(packed_msg_len); 383 memcpy (sender_address, &received_msg[1], sender_address_len);
372 memcpy(packed_msg, &packed_msg_start[sender_address_len], packed_msg_len); 384 packed_msg_start = (char *) &received_msg[1];
385 packed_msg = GNUNET_malloc (packed_msg_len);
386 memcpy (packed_msg, &packed_msg_start[sender_address_len], packed_msg_len);
373 387
374#if DEBUG_DV_MESSAGES 388#if DEBUG_DV_MESSAGES
375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: packed message type: %d or %d\n", ntohs(((struct GNUNET_MessageHeader *)packed_msg)->type), ((struct GNUNET_MessageHeader *)packed_msg)->type); 389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
376 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: message sender reported as %s\n", GNUNET_i2s(&received_msg->sender)); 390 "DV_API receive: packed message type: %d or %d\n",
377 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: distance is %u\n", ntohl(received_msg->distance)); 391 ntohs (((struct GNUNET_MessageHeader *) packed_msg)->type),
392 ((struct GNUNET_MessageHeader *) packed_msg)->type);
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "DV_API receive: message sender reported as %s\n",
395 GNUNET_i2s (&received_msg->sender));
396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DV_API receive: distance is %u\n",
397 ntohl (received_msg->distance));
378#endif 398#endif
379 399
380 handle->receive_handler(handle->receive_cls, 400 handle->receive_handler (handle->receive_cls,
381 &received_msg->sender, 401 &received_msg->sender,
382 packed_msg, 402 packed_msg,
383 packed_msg_len, 403 packed_msg_len,
384 ntohl(received_msg->distance), 404 ntohl (received_msg->distance),
385 sender_address, 405 sender_address, sender_address_len);
386 sender_address_len);
387 406
388 GNUNET_free(sender_address); 407 GNUNET_free (sender_address);
389 break; 408 break;
390 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT: 409 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT:
391 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_SendResultMessage)) 410 if (ntohs (msg->size) < sizeof (struct GNUNET_DV_SendResultMessage))
392 return; 411 return;
393 412
394 send_result_msg = (struct GNUNET_DV_SendResultMessage *)msg; 413 send_result_msg = (struct GNUNET_DV_SendResultMessage *) msg;
395 hash_from_uid(ntohl(send_result_msg->uid), &uidhash); 414 hash_from_uid (ntohl (send_result_msg->uid), &uidhash);
396 send_ctx = GNUNET_CONTAINER_multihashmap_get(handle->send_callbacks, &uidhash); 415 send_ctx =
416 GNUNET_CONTAINER_multihashmap_get (handle->send_callbacks, &uidhash);
397 417
398 if ((send_ctx != NULL) && (send_ctx->cont != NULL)) 418 if ((send_ctx != NULL) && (send_ctx->cont != NULL))
419 {
420 if (ntohl (send_result_msg->result) == 0)
421 {
422 send_ctx->cont (send_ctx->cont_cls, &send_ctx->target, GNUNET_OK);
423 }
424 else
399 { 425 {
400 if (ntohl(send_result_msg->result) == 0) 426 send_ctx->cont (send_ctx->cont_cls, &send_ctx->target, GNUNET_SYSERR);
401 {
402 send_ctx->cont(send_ctx->cont_cls, &send_ctx->target, GNUNET_OK);
403 }
404 else
405 {
406 send_ctx->cont(send_ctx->cont_cls, &send_ctx->target, GNUNET_SYSERR);
407 }
408 } 427 }
409 GNUNET_free_non_null(send_ctx); 428 }
429 GNUNET_free_non_null (send_ctx);
410 break; 430 break;
411 default: 431 default:
412 break; 432 break;
@@ -432,48 +452,52 @@ void handle_message_receipt (void *cls,
432 * @param cont_cls closure for continuation 452 * @param cont_cls closure for continuation
433 * 453 *
434 */ 454 */
435int GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle, 455int
436 const struct GNUNET_PeerIdentity *target, 456GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
437 const char *msgbuf, 457 const struct GNUNET_PeerIdentity *target,
438 size_t msgbuf_size, 458 const char *msgbuf,
439 unsigned int priority, 459 size_t msgbuf_size,
440 struct GNUNET_TIME_Relative timeout, 460 unsigned int priority,
441 const void *addr, 461 struct GNUNET_TIME_Relative timeout,
442 size_t addrlen, 462 const void *addr,
443 GNUNET_TRANSPORT_TransmitContinuation 463 size_t addrlen,
444 cont, void *cont_cls) 464 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
445{ 465{
446 struct GNUNET_DV_SendMessage *msg; 466 struct GNUNET_DV_SendMessage *msg;
447 struct SendCallbackContext *send_ctx; 467 struct SendCallbackContext *send_ctx;
448 char *end_of_message; 468 char *end_of_message;
449 GNUNET_HashCode uidhash; 469 GNUNET_HashCode uidhash;
450 int msize; 470 int msize;
471
451#if DEBUG_DV_MESSAGES 472#if DEBUG_DV_MESSAGES
452 dv_handle->uid_gen = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX); 473 dv_handle->uid_gen =
474 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, UINT32_MAX);
453#else 475#else
454 dv_handle->uid_gen++; 476 dv_handle->uid_gen++;
455#endif 477#endif
456 478
457 msize = sizeof(struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size; 479 msize = sizeof (struct GNUNET_DV_SendMessage) + addrlen + msgbuf_size;
458 msg = GNUNET_malloc(msize); 480 msg = GNUNET_malloc (msize);
459 msg->header.size = htons(msize); 481 msg->header.size = htons (msize);
460 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND); 482 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND);
461 memcpy(&msg->target, target, sizeof(struct GNUNET_PeerIdentity)); 483 memcpy (&msg->target, target, sizeof (struct GNUNET_PeerIdentity));
462 msg->priority = htonl(priority); 484 msg->priority = htonl (priority);
463 msg->timeout = timeout; 485 msg->timeout = timeout;
464 msg->addrlen = htonl(addrlen); 486 msg->addrlen = htonl (addrlen);
465 msg->uid = htonl(dv_handle->uid_gen); 487 msg->uid = htonl (dv_handle->uid_gen);
466 memcpy(&msg[1], addr, addrlen); 488 memcpy (&msg[1], addr, addrlen);
467 end_of_message = (char *)&msg[1]; 489 end_of_message = (char *) &msg[1];
468 end_of_message = &end_of_message[addrlen]; 490 end_of_message = &end_of_message[addrlen];
469 memcpy(end_of_message, msgbuf, msgbuf_size); 491 memcpy (end_of_message, msgbuf, msgbuf_size);
470 add_pending(dv_handle, msg); 492 add_pending (dv_handle, msg);
471 send_ctx = GNUNET_malloc(sizeof(struct SendCallbackContext)); 493 send_ctx = GNUNET_malloc (sizeof (struct SendCallbackContext));
472 send_ctx->cont = cont; 494 send_ctx->cont = cont;
473 send_ctx->cont_cls = cont_cls; 495 send_ctx->cont_cls = cont_cls;
474 memcpy(&send_ctx->target, target, sizeof(struct GNUNET_PeerIdentity)); 496 memcpy (&send_ctx->target, target, sizeof (struct GNUNET_PeerIdentity));
475 hash_from_uid(dv_handle->uid_gen, &uidhash); 497 hash_from_uid (dv_handle->uid_gen, &uidhash);
476 GNUNET_CONTAINER_multihashmap_put(dv_handle->send_callbacks, &uidhash, send_ctx, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 498 GNUNET_CONTAINER_multihashmap_put (dv_handle->send_callbacks, &uidhash,
499 send_ctx,
500 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
477 501
478 return GNUNET_OK; 502 return GNUNET_OK;
479} 503}
@@ -494,23 +518,25 @@ transmit_start (void *cls, size_t size, void *buf)
494 struct StartContext *start_context = cls; 518 struct StartContext *start_context = cls;
495 struct GNUNET_DV_Handle *handle = start_context->handle; 519 struct GNUNET_DV_Handle *handle = start_context->handle;
496 size_t tsize; 520 size_t tsize;
521
497#if DEBUG_DV 522#if DEBUG_DV
498 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: sending start request to service\n"); 523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
524 "DV API: sending start request to service\n");
499#endif 525#endif
500 if (buf == NULL) 526 if (buf == NULL)
501 { 527 {
502 GNUNET_free(start_context->message); 528 GNUNET_free (start_context->message);
503 GNUNET_free(start_context); 529 GNUNET_free (start_context);
504 GNUNET_DV_disconnect(handle); 530 GNUNET_DV_disconnect (handle);
505 return 0; 531 return 0;
506 } 532 }
507 533
508 tsize = ntohs(start_context->message->size); 534 tsize = ntohs (start_context->message->size);
509 if (size >= tsize) 535 if (size >= tsize)
510 { 536 {
511 memcpy(buf, start_context->message, tsize); 537 memcpy (buf, start_context->message, tsize);
512 GNUNET_free(start_context->message); 538 GNUNET_free (start_context->message);
513 GNUNET_free(start_context); 539 GNUNET_free (start_context);
514 GNUNET_CLIENT_receive (handle->client, 540 GNUNET_CLIENT_receive (handle->client,
515 &handle_message_receipt, 541 &handle_message_receipt,
516 handle, GNUNET_TIME_UNIT_FOREVER_REL); 542 handle, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -533,42 +559,44 @@ transmit_start (void *cls, size_t size, void *buf)
533 */ 559 */
534struct GNUNET_DV_Handle * 560struct GNUNET_DV_Handle *
535GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 561GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
536 GNUNET_DV_MessageReceivedHandler receive_handler, 562 GNUNET_DV_MessageReceivedHandler receive_handler,
537 void *receive_handler_cls) 563 void *receive_handler_cls)
538{ 564{
539 struct GNUNET_DV_Handle *handle; 565 struct GNUNET_DV_Handle *handle;
540 struct GNUNET_MessageHeader *start_message; 566 struct GNUNET_MessageHeader *start_message;
541 struct StartContext *start_context; 567 struct StartContext *start_context;
542 handle = GNUNET_malloc(sizeof(struct GNUNET_DV_Handle)); 568
569 handle = GNUNET_malloc (sizeof (struct GNUNET_DV_Handle));
543 570
544 handle->cfg = cfg; 571 handle->cfg = cfg;
545 handle->pending_list = NULL; 572 handle->pending_list = NULL;
546 handle->current = NULL; 573 handle->current = NULL;
547 handle->th = NULL; 574 handle->th = NULL;
548 handle->client = GNUNET_CLIENT_connect("dv", cfg); 575 handle->client = GNUNET_CLIENT_connect ("dv", cfg);
549 handle->receive_handler = receive_handler; 576 handle->receive_handler = receive_handler;
550 handle->receive_cls = receive_handler_cls; 577 handle->receive_cls = receive_handler_cls;
551 578
552 if (handle->client == NULL) 579 if (handle->client == NULL)
553 { 580 {
554 GNUNET_free(handle); 581 GNUNET_free (handle);
555 return NULL; 582 return NULL;
556 } 583 }
557 584
558 start_message = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)); 585 start_message = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
559 start_message->size = htons(sizeof(struct GNUNET_MessageHeader)); 586 start_message->size = htons (sizeof (struct GNUNET_MessageHeader));
560 start_message->type = htons(GNUNET_MESSAGE_TYPE_DV_START); 587 start_message->type = htons (GNUNET_MESSAGE_TYPE_DV_START);
561 588
562 start_context = GNUNET_malloc(sizeof(struct StartContext)); 589 start_context = GNUNET_malloc (sizeof (struct StartContext));
563 start_context->handle = handle; 590 start_context->handle = handle;
564 start_context->message = start_message; 591 start_context->message = start_message;
565 GNUNET_CLIENT_notify_transmit_ready (handle->client, 592 GNUNET_CLIENT_notify_transmit_ready (handle->client,
566 sizeof(struct GNUNET_MessageHeader), 593 sizeof (struct GNUNET_MessageHeader),
567 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60), 594 GNUNET_TIME_relative_multiply
568 GNUNET_YES, 595 (GNUNET_TIME_UNIT_SECONDS, 60),
569 &transmit_start, start_context); 596 GNUNET_YES, &transmit_start,
597 start_context);
570 598
571 handle->send_callbacks = GNUNET_CONTAINER_multihashmap_create(100); 599 handle->send_callbacks = GNUNET_CONTAINER_multihashmap_create (100);
572 600
573 return handle; 601 return handle;
574} 602}
@@ -578,29 +606,30 @@ GNUNET_DV_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
578 * 606 *
579 * @param handle the current handle to the service to disconnect 607 * @param handle the current handle to the service to disconnect
580 */ 608 */
581void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle) 609void
610GNUNET_DV_disconnect (struct GNUNET_DV_Handle *handle)
582{ 611{
583 struct PendingMessages *pos; 612 struct PendingMessages *pos;
584 613
585 GNUNET_assert(handle != NULL); 614 GNUNET_assert (handle != NULL);
586 615
587 if (handle->th != NULL) /* We have a live transmit request in the Aether */ 616 if (handle->th != NULL) /* We have a live transmit request in the Aether */
588 { 617 {
589 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 618 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
590 handle->th = NULL; 619 handle->th = NULL;
591 } 620 }
592 if (handle->current != NULL) /* We are trying to send something now, clean it up */ 621 if (handle->current != NULL) /* We are trying to send something now, clean it up */
593 GNUNET_free(handle->current); 622 GNUNET_free (handle->current);
594 while (NULL != (pos = handle->pending_list)) /* Remove all pending sends from the list */ 623 while (NULL != (pos = handle->pending_list)) /* Remove all pending sends from the list */
595 { 624 {
596 handle->pending_list = pos->next; 625 handle->pending_list = pos->next;
597 GNUNET_free(pos); 626 GNUNET_free (pos);
598 } 627 }
599 if (handle->client != NULL) /* Finally, disconnect from the service */ 628 if (handle->client != NULL) /* Finally, disconnect from the service */
600 { 629 {
601 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); 630 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
602 handle->client = NULL; 631 handle->client = NULL;
603 } 632 }
604 633
605 GNUNET_free (handle); 634 GNUNET_free (handle);
606} 635}