aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-10 13:37:42 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-10 13:37:42 +0000
commitaa332fdba373e28ac6b290238bd92ae0ad7f0535 (patch)
tree761ddfc0e762a2b1624b56e2487e0e1e20af502f /src/dht
parent4a7cbfbe33d22ff22e2885d0eec90fb238bc013a (diff)
downloadgnunet-aa332fdba373e28ac6b290238bd92ae0ad7f0535.tar.gz
gnunet-aa332fdba373e28ac6b290238bd92ae0ad7f0535.zip
use LOG macro in dht_api.c
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/dht_api.c136
1 files changed, 68 insertions, 68 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 5fff137a6..a50d2a228 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -36,6 +36,8 @@
36 36
37#define DEBUG_DHT_API GNUNET_EXTRA_LOGGING 37#define DEBUG_DHT_API GNUNET_EXTRA_LOGGING
38 38
39#define LOG(kind,...) GNUNET_log_from (kind, "dht-api",__VA_ARGS__)
40
39/** 41/**
40 * Entry in our list of messages to be (re-)transmitted. 42 * Entry in our list of messages to be (re-)transmitted.
41 */ 43 */
@@ -218,13 +220,12 @@ try_connect (struct GNUNET_DHT_Handle *handle)
218 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg); 220 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg);
219 if (handle->client == NULL) 221 if (handle->client == NULL)
220 { 222 {
221 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 223 LOG (GNUNET_ERROR_TYPE_WARNING,
222 _("Failed to connect to the DHT service!\n")); 224 _("Failed to connect to the DHT service!\n"));
223 return GNUNET_NO; 225 return GNUNET_NO;
224 } 226 }
225#if DEBUG_DHT 227#if DEBUG_DHT
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 228 LOG (GNUNET_ERROR_TYPE_DEBUG, "Starting to process replies from DHT\n");
227 "Starting to process replies from DHT\n");
228#endif 229#endif
229 GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle, 230 GNUNET_CLIENT_receive (handle->client, &service_message_handler, handle,
230 GNUNET_TIME_UNIT_FOREVER_REL); 231 GNUNET_TIME_UNIT_FOREVER_REL);
@@ -287,7 +288,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
287 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg); 288 handle->client = GNUNET_CLIENT_connect ("dht", handle->cfg);
288 if (handle->client == NULL) 289 if (handle->client == NULL)
289 { 290 {
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dht reconnect failed(!)\n"); 291 LOG (GNUNET_ERROR_TYPE_DEBUG, "dht reconnect failed(!)\n");
291 return; 292 return;
292 } 293 }
293 GNUNET_CONTAINER_multihashmap_iterate (handle->active_requests, 294 GNUNET_CONTAINER_multihashmap_iterate (handle->active_requests,
@@ -308,7 +309,7 @@ do_disconnect (struct GNUNET_DHT_Handle *handle)
308 return; 309 return;
309 GNUNET_assert (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK); 310 GNUNET_assert (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
310 if (NULL != handle->th) 311 if (NULL != handle->th)
311 GNUNET_CLIENT_notify_transmit_ready_cancel(handle->th); 312 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
312 handle->th = NULL; 313 handle->th = NULL;
313 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO); 314 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
314 handle->client = NULL; 315 handle->client = NULL;
@@ -366,8 +367,8 @@ transmit_pending (void *cls, size_t size, void *buf)
366 handle->th = NULL; 367 handle->th = NULL;
367 if (buf == NULL) 368 if (buf == NULL)
368 { 369 {
369 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 370 LOG (GNUNET_ERROR_TYPE_DEBUG,
370 "Transmission to DHT service failed! Reconnecting!\n"); 371 "Transmission to DHT service failed! Reconnecting!\n");
371 do_disconnect (handle); 372 do_disconnect (handle);
372 return 0; 373 return 0;
373 } 374 }
@@ -400,9 +401,8 @@ transmit_pending (void *cls, size_t size, void *buf)
400 GNUNET_free (head); 401 GNUNET_free (head);
401 process_pending_messages (handle); 402 process_pending_messages (handle);
402#if DEBUG_DHT 403#if DEBUG_DHT
403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 404 LOG (GNUNET_ERROR_TYPE_DEBUG,
404 "Forwarded request of %u bytes to DHT service\n", 405 "Forwarded request of %u bytes to DHT service\n", (unsigned int) tsize);
405 (unsigned int) tsize);
406#endif 406#endif
407 return tsize; 407 return tsize;
408} 408}
@@ -435,35 +435,33 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
435 if (dht_msg->unique_id != get_handle->unique_id) 435 if (dht_msg->unique_id != get_handle->unique_id)
436 { 436 {
437 /* UID mismatch */ 437 /* UID mismatch */
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 438 LOG (GNUNET_ERROR_TYPE_DEBUG, "Ignoring reply (UID mismatch: %llu/%llu)\n",
439 "Ignoring reply (UID mismatch: %llu/%llu)\n", 439 dht_msg->unique_id, get_handle->unique_id);
440 dht_msg->unique_id,
441 get_handle->unique_id);
442 return GNUNET_YES; 440 return GNUNET_YES;
443 } 441 }
444 msize = ntohs (dht_msg->header.size); 442 msize = ntohs (dht_msg->header.size);
445 put_path_length = ntohl (dht_msg->put_path_length); 443 put_path_length = ntohl (dht_msg->put_path_length);
446 get_path_length = ntohl (dht_msg->get_path_length); 444 get_path_length = ntohl (dht_msg->get_path_length);
447 meta_length = sizeof (struct GNUNET_DHT_ClientResultMessage) + 445 meta_length =
448 sizeof (struct GNUNET_PeerIdentity) * (get_path_length + put_path_length); 446 sizeof (struct GNUNET_DHT_ClientResultMessage) +
449 if ( (msize < meta_length) || 447 sizeof (struct GNUNET_PeerIdentity) * (get_path_length + put_path_length);
450 (get_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) || 448 if ((msize < meta_length) ||
451 (put_path_length > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ) 449 (get_path_length >
452 { 450 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
453 GNUNET_break (0); 451 (put_path_length >
454 return GNUNET_NO; 452 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)))
455 } 453 {
456 data_length = msize - meta_length; 454 GNUNET_break (0);
455 return GNUNET_NO;
456 }
457 data_length = msize - meta_length;
457 put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1]; 458 put_path = (const struct GNUNET_PeerIdentity *) &dht_msg[1];
458 get_path = &put_path[put_path_length]; 459 get_path = &put_path[put_path_length];
459 data = &get_path[get_path_length]; 460 data = &get_path[get_path_length];
460 get_handle->iter (get_handle->iter_cls, 461 get_handle->iter (get_handle->iter_cls,
461 GNUNET_TIME_absolute_ntoh (dht_msg->expiration), 462 GNUNET_TIME_absolute_ntoh (dht_msg->expiration), key,
462 key, 463 get_path, get_path_length, put_path, put_path_length,
463 get_path, get_path_length, 464 ntohl (dht_msg->type), data_length, data);
464 put_path, put_path_length,
465 ntohl (dht_msg->type),
466 data_length, data);
467 return GNUNET_YES; 465 return GNUNET_YES;
468} 466}
469 467
@@ -483,8 +481,8 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
483 481
484 if (msg == NULL) 482 if (msg == NULL)
485 { 483 {
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 484 LOG (GNUNET_ERROR_TYPE_DEBUG,
487 "Error receiving data from DHT service, reconnecting\n"); 485 "Error receiving data from DHT service, reconnecting\n");
488 do_disconnect (handle); 486 do_disconnect (handle);
489 return; 487 return;
490 } 488 }
@@ -500,8 +498,7 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
500 do_disconnect (handle); 498 do_disconnect (handle);
501 return; 499 return;
502 } 500 }
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 501 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received reply from DHT service\n");
504 "Received reply from DHT service\n");
505 dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg; 502 dht_msg = (const struct GNUNET_DHT_ClientResultMessage *) msg;
506 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests, 503 GNUNET_CONTAINER_multihashmap_get_multiple (handle->active_requests,
507 &dht_msg->key, &process_reply, 504 &dht_msg->key, &process_reply,
@@ -634,14 +631,14 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key,
634 struct PendingMessage *pending; 631 struct PendingMessage *pending;
635 632
636 msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size; 633 msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size;
637 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 634 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
638 (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) 635 (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
639 { 636 {
640 GNUNET_break (0); 637 GNUNET_break (0);
641 if (NULL != cont) 638 if (NULL != cont)
642 cont (cont_cls, NULL); 639 cont (cont_cls, NULL);
643 return; 640 return;
644 } 641 }
645 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 642 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
646 put_msg = (struct GNUNET_DHT_ClientPutMessage *) &pending[1]; 643 put_msg = (struct GNUNET_DHT_ClientPutMessage *) &pending[1];
647 pending->msg = &put_msg->header; 644 pending->msg = &put_msg->header;
@@ -650,7 +647,7 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const GNUNET_HashCode * key,
650 pending->cont_cls = cont_cls; 647 pending->cont_cls = cont_cls;
651 pending->free_on_send = GNUNET_YES; 648 pending->free_on_send = GNUNET_YES;
652 pending->timeout_task = 649 pending->timeout_task =
653 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_put_request, pending); 650 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_put_request, pending);
654 put_msg->header.size = htons (msize); 651 put_msg->header.size = htons (msize);
655 put_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT); 652 put_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT);
656 put_msg->type = htonl (type); 653 put_msg->type = htonl (type);
@@ -688,9 +685,9 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
688 struct GNUNET_TIME_Relative timeout, 685 struct GNUNET_TIME_Relative timeout,
689 enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key, 686 enum GNUNET_BLOCK_Type type, const GNUNET_HashCode * key,
690 uint32_t desired_replication_level, 687 uint32_t desired_replication_level,
691 enum GNUNET_DHT_RouteOption options, 688 enum GNUNET_DHT_RouteOption options, const void *xquery,
692 const void *xquery, size_t xquery_size, 689 size_t xquery_size, GNUNET_DHT_GetIterator iter,
693 GNUNET_DHT_GetIterator iter, void *iter_cls) 690 void *iter_cls)
694{ 691{
695 struct GNUNET_DHT_ClientGetMessage *get_msg; 692 struct GNUNET_DHT_ClientGetMessage *get_msg;
696 struct GNUNET_DHT_GetHandle *get_handle; 693 struct GNUNET_DHT_GetHandle *get_handle;
@@ -698,12 +695,12 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
698 struct PendingMessage *pending; 695 struct PendingMessage *pending;
699 696
700 msize = sizeof (struct GNUNET_DHT_ClientGetMessage) + xquery_size; 697 msize = sizeof (struct GNUNET_DHT_ClientGetMessage) + xquery_size;
701 if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 698 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
702 (xquery_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ) 699 (xquery_size >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
703 { 700 {
704 GNUNET_break (0); 701 GNUNET_break (0);
705 return NULL; 702 return NULL;
706 } 703 }
707 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 704 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
708 get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1]; 705 get_msg = (struct GNUNET_DHT_ClientGetMessage *) &pending[1];
709 pending->msg = &get_msg->header; 706 pending->msg = &get_msg->header;
@@ -724,11 +721,10 @@ GNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle,
724 get_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle)); 721 get_handle = GNUNET_malloc (sizeof (struct GNUNET_DHT_GetHandle));
725 get_handle->iter = iter; 722 get_handle->iter = iter;
726 get_handle->iter_cls = iter_cls; 723 get_handle->iter_cls = iter_cls;
727 get_handle->message = pending; 724 get_handle->message = pending;
728 get_handle->unique_id = get_msg->unique_id; 725 get_handle->unique_id = get_msg->unique_id;
729 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, 726 GNUNET_CONTAINER_multihashmap_put (handle->active_requests, key, get_handle,
730 key, get_handle, 727 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
731 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
732 process_pending_messages (handle); 728 process_pending_messages (handle);
733 return get_handle; 729 return get_handle;
734} 730}
@@ -748,15 +744,19 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle)
748 struct PendingMessage *pending; 744 struct PendingMessage *pending;
749 745
750 handle = get_handle->message->handle; 746 handle = get_handle->message->handle;
751 get_msg = (const struct GNUNET_DHT_ClientGetMessage*) get_handle->message->msg; 747 get_msg =
748 (const struct GNUNET_DHT_ClientGetMessage *) get_handle->message->msg;
752 749
753 /* generate STOP */ 750 /* generate STOP */
754 pending = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (struct GNUNET_DHT_ClientGetStopMessage)); 751 pending =
752 GNUNET_malloc (sizeof (struct PendingMessage) +
753 sizeof (struct GNUNET_DHT_ClientGetStopMessage));
755 stop_msg = (struct GNUNET_DHT_ClientGetStopMessage *) &pending[1]; 754 stop_msg = (struct GNUNET_DHT_ClientGetStopMessage *) &pending[1];
756 pending->msg = &stop_msg->header; 755 pending->msg = &stop_msg->header;
757 pending->handle = handle; 756 pending->handle = handle;
758 pending->free_on_send = GNUNET_YES; 757 pending->free_on_send = GNUNET_YES;
759 stop_msg->header.size = htons (sizeof (struct GNUNET_DHT_ClientGetStopMessage)); 758 stop_msg->header.size =
759 htons (sizeof (struct GNUNET_DHT_ClientGetStopMessage));
760 stop_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP); 760 stop_msg->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_STOP);
761 stop_msg->reserved = htonl (0); 761 stop_msg->reserved = htonl (0);
762 stop_msg->unique_id = get_msg->unique_id; 762 stop_msg->unique_id = get_msg->unique_id;
@@ -767,15 +767,15 @@ GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle)
767 767
768 /* remove 'GET' from active status */ 768 /* remove 'GET' from active status */
769 GNUNET_assert (GNUNET_YES == 769 GNUNET_assert (GNUNET_YES ==
770 GNUNET_CONTAINER_multihashmap_remove (handle->active_requests, 770 GNUNET_CONTAINER_multihashmap_remove (handle->active_requests,
771 &get_msg->key, get_handle)); 771 &get_msg->key,
772 get_handle));
772 if (GNUNET_YES == get_handle->message->in_pending_queue) 773 if (GNUNET_YES == get_handle->message->in_pending_queue)
773 { 774 {
774 GNUNET_CONTAINER_DLL_remove (handle->pending_head, 775 GNUNET_CONTAINER_DLL_remove (handle->pending_head, handle->pending_tail,
775 handle->pending_tail, 776 get_handle->message);
776 get_handle->message); 777 get_handle->message->in_pending_queue = GNUNET_NO;
777 get_handle->message->in_pending_queue = GNUNET_NO; 778 }
778 }
779 GNUNET_free (get_handle->message); 779 GNUNET_free (get_handle->message);
780 GNUNET_free (get_handle); 780 GNUNET_free (get_handle);
781 781