aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-07 09:42:36 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-07 09:42:36 +0000
commit145db4f07472ffd03b8872928c165a4a7ef46352 (patch)
tree8bf1eee2d2dfb2537b34b39f2d3cc81fb6be1ddd /src/core/gnunet-service-core_clients.c
parentdb1ababc2af1771a10c79c65a729852700ac7699 (diff)
downloadgnunet-145db4f07472ffd03b8872928c165a4a7ef46352.tar.gz
gnunet-145db4f07472ffd03b8872928c165a4a7ef46352.zip
fixes
Diffstat (limited to 'src/core/gnunet-service-core_clients.c')
-rw-r--r--src/core/gnunet-service-core_clients.c107
1 files changed, 58 insertions, 49 deletions
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c
index 333bd5ad8..7b884f44f 100644
--- a/src/core/gnunet-service-core_clients.c
+++ b/src/core/gnunet-service-core_clients.c
@@ -25,11 +25,20 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_statistics_service.h"
28#include "gnunet_transport_service.h" 29#include "gnunet_transport_service.h"
29#include "gnunet_service_core.h" 30#include "gnunet-service-core.h"
30#include "gnunet_service_core_clients.h" 31#include "gnunet-service-core_clients.h"
31#include "gnunet_service_core_sessions.h" 32#include "gnunet-service-core_sessions.h"
32#include "gnunet_service_core_typemap.h" 33#include "gnunet-service-core_typemap.h"
34#include "core.h"
35
36/**
37 * How many messages do we queue up at most for optional
38 * notifications to a client? (this can cause notifications
39 * about outgoing messages to be dropped).
40 */
41#define MAX_NOTIFY_QUEUE 1024
33 42
34 43
35/** 44/**
@@ -207,12 +216,10 @@ send_to_all_clients (const struct GNUNET_MessageHeader *msg,
207 216
208 for (c = client_head; c != NULL; c = c->next) 217 for (c = client_head; c != NULL; c = c->next)
209 { 218 {
210 if ( (0 != (c->options & options)) && 219 if (! ( (0 != (c->options & options)) ||
211 (GNUNET_YES == type_match (type, c)) ) 220 ( (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
212 continue; /* both match, wait for only type match */ 221 (GNUNET_YES == type_match (type, c)) ) ) )
213 if ( (0 == (c->options & options)) && 222 continue; /* skip */
214 (GNUNET_YES != type_match (type, c)) )
215 continue; /* neither match, skip entirely */
216#if DEBUG_CORE_CLIENT > 1 223#if DEBUG_CORE_CLIENT > 1
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
218 "Sending message of type %u to client.\n", 225 "Sending message of type %u to client.\n",
@@ -326,11 +333,9 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
326 &req->peer.hashPubKey, 333 &req->peer.hashPubKey,
327 car, 334 car,
328 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 335 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
329 car->client = c; 336 car->client_handle = c;
330 } 337 }
331 car->target = req->peer; 338 car->target = req->peer;
332 GNUNET_SERVER_client_keep (client);
333 car->client_handle = client;
334 car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); 339 car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
335 car->priority = ntohl (req->priority); 340 car->priority = ntohl (req->priority);
336 car->msize = ntohs (req->size); 341 car->msize = ntohs (req->size);
@@ -393,11 +398,11 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
393 car)); 398 car));
394 GNUNET_SERVER_mst_receive (client_mst, 399 GNUNET_SERVER_mst_receive (client_mst,
395 car, 400 car,
396 &sm[1], msize, 401 (const char*) &sm[1], msize,
397 GNUNET_YES, 402 GNUNET_YES,
398 GNUNET_NO); 403 GNUNET_NO);
399 if (0 != 404 if (0 !=
400 memcmp (&car->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 405 memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
401 GSC_SESSIONS_dequeue_request (car); 406 GSC_SESSIONS_dequeue_request (car);
402 GNUNET_free (car); 407 GNUNET_free (car);
403 GNUNET_SERVER_receive_done (client, GNUNET_OK); 408 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -421,10 +426,21 @@ client_tokenizer_callback (void *cls, void *client,
421 struct GSC_ClientActiveRequest *car = client; 426 struct GSC_ClientActiveRequest *car = client;
422 427
423 if (0 == 428 if (0 ==
424 memcmp (&car->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 429 memcmp (&car->target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
425 GDS_CLIENTS_deliver_message (&GSC_my_identity, &payload->header); 430 {
431 GSC_CLIENTS_deliver_message (&GSC_my_identity,
432 NULL, 0,
433 message,
434 ntohs (message->size),
435 GNUNET_CORE_OPTION_SEND_FULL_INBOUND | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
436 GSC_CLIENTS_deliver_message (&GSC_my_identity,
437 NULL, 0,
438 message,
439 sizeof (struct GNUNET_MessageHeader),
440 GNUNET_CORE_OPTION_SEND_HDR_INBOUND | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
441 }
426 else 442 else
427 GSC_SESSIONS_transmit (car, &payload->header); 443 GSC_SESSIONS_transmit (car, message);
428} 444}
429 445
430 446
@@ -443,9 +459,9 @@ destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
443 struct GSC_ClientActiveRequest *car = value; 459 struct GSC_ClientActiveRequest *car = value;
444 460
445 GNUNET_assert (GNUNET_YES == 461 GNUNET_assert (GNUNET_YES ==
446 GNUNET_CONTAINER_multihashmap_remove (car->client->requests, 462 GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests,
447 &car->peer, 463 &car->target.hashPubKey,
448 car); 464 car));
449 GSC_SESSIONS_dequeue_request (car); 465 GSC_SESSIONS_dequeue_request (car);
450 GNUNET_free (car); 466 GNUNET_free (car);
451 return GNUNET_YES; 467 return GNUNET_YES;
@@ -501,12 +517,12 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
501 struct GSC_Client *c; 517 struct GSC_Client *c;
502 struct SendMessageReady smr; 518 struct SendMessageReady smr;
503 519
504 c = car->client; 520 c = car->client_handle;
505 smr.header.size = htons (sizeof (struct SendMessageReady)); 521 smr.header.size = htons (sizeof (struct SendMessageReady));
506 smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY); 522 smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
507 smr.size = htons (car->msize); 523 smr.size = htons (car->msize);
508 smr.smr_id = car->smr_id; 524 smr.smr_id = car->smr_id;
509 smr.peer = n->peer; 525 smr.peer = car->target;
510 send_to_client (c, &smr.header, GNUNET_NO); 526 send_to_client (c, &smr.header, GNUNET_NO);
511} 527}
512 528
@@ -523,7 +539,7 @@ void
523GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) 539GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
524{ 540{
525 GNUNET_assert (GNUNET_YES == 541 GNUNET_assert (GNUNET_YES ==
526 destroy_active_client_request (NULL, &car->peer.hashPubKey, car)); 542 destroy_active_client_request (NULL, &car->target.hashPubKey, car));
527} 543}
528 544
529 545
@@ -564,31 +580,29 @@ GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
564 /* send connect */ 580 /* send connect */
565 size = 581 size =
566 sizeof (struct ConnectNotifyMessage) + 582 sizeof (struct ConnectNotifyMessage) +
567 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 583 (atsi_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
568 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 584 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
569 { 585 {
570 GNUNET_break (0); 586 GNUNET_break (0);
571 /* recovery strategy: throw away performance data */ 587 /* recovery strategy: throw away performance data */
572 GNUNET_array_grow (n->ats, n->ats_count, 0); 588 atsi_count = 0;
573 size = 589 size = sizeof (struct ConnectNotifyMessage);
574 sizeof (struct ConnectNotifyMessage) +
575 (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
576 } 590 }
577 cnm = (struct ConnectNotifyMessage *) buf; 591 cnm = (struct ConnectNotifyMessage *) buf;
578 cnm->header.size = htons (size); 592 cnm->header.size = htons (size);
579 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 593 cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
580 cnm->ats_count = htonl (atsi); 594 cnm->ats_count = htonl (atsi_count);
581 a = &cnm->atsi; 595 a = &cnm->ats;
582 memcpy (a, atsi, 596 memcpy (a, atsi,
583 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * atsi_count); 597 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * atsi_count);
584 a[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 598 a[atsi_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
585 a[ats_count].value = htonl (0); 599 a[atsi_count].value = htonl (0);
586#if DEBUG_CORE_CLIENT 600#if DEBUG_CORE_CLIENT
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Sending `%s' message to client.\n", 602 "Sending `%s' message to client.\n",
589 "NOTIFY_CONNECT"); 603 "NOTIFY_CONNECT");
590#endif 604#endif
591 cnm->peer = n->peer; 605 cnm->peer = *neighbour;
592 send_to_client (client, &cnm->header, GNUNET_NO); 606 send_to_client (client, &cnm->header, GNUNET_NO);
593 } 607 }
594 else 608 else
@@ -597,8 +611,8 @@ GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
597 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); 611 dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage));
598 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); 612 dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
599 dcm.reserved = htonl (0); 613 dcm.reserved = htonl (0);
600 dcm.peer = *peer; 614 dcm.peer = *neighbour;
601 send_to_client (client, &cnm.header, GNUNET_NO); 615 send_to_client (client, &dcm.header, GNUNET_NO);
602 } 616 }
603} 617}
604 618
@@ -652,29 +666,24 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
652 int options) 666 int options)
653{ 667{
654 size_t size = msize + sizeof (struct NotifyTrafficMessage) + 668 size_t size = msize + sizeof (struct NotifyTrafficMessage) +
655 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 669 atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
656 char buf[size]; 670 char buf[size];
657 struct NotifyTrafficMessage *ntm; 671 struct NotifyTrafficMessage *ntm;
658 struct GNUNET_TRANSPORT_ATS_Information *a; 672 struct GNUNET_TRANSPORT_ATS_Information *a;
659 int dropped;
660 673
661 if (0 == options) 674 if (0 == options)
662 { 675 {
663 GNUNET_snprintf (buf, sizeof (buf), 676 GNUNET_snprintf (buf, sizeof (buf),
664 gettext_noop ("# bytes of messages of type %u received"), 677 gettext_noop ("# bytes of messages of type %u received"),
665 (unsigned int) ntohs (msg->type)); 678 (unsigned int) ntohs (msg->type));
666 GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO); 679 GNUNET_STATISTICS_update (GSC_stats, buf, msize, GNUNET_NO);
667 } 680 }
668 GNUNET_assert (GNUNET_YES == sender->is_connected);
669 GNUNET_break (sender->status == PEER_STATE_KEY_CONFIRMED);
670 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 681 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
671 { 682 {
672 GNUNET_break (0); 683 GNUNET_break (0);
673 /* recovery strategy: throw performance data away... */ 684 /* recovery strategy: throw performance data away... */
674 GNUNET_array_grow (sender->ats, sender->ats_count, 0); 685 atsi_count = 0;
675 size = 686 size = msize + sizeof (struct NotifyTrafficMessage);
676 msize + sizeof (struct NotifyTrafficMessage) +
677 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
678 } 687 }
679#if DEBUG_CORE 688#if DEBUG_CORE
680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -686,13 +695,13 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
686 ntm->header.size = htons (size); 695 ntm->header.size = htons (size);
687 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND); 696 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND);
688 ntm->ats_count = htonl (atsi_count); 697 ntm->ats_count = htonl (atsi_count);
689 ntm->peer = sender->peer; 698 ntm->peer = *sender;
690 a = &ntm->ats; 699 a = &ntm->ats;
691 memcpy (a, atsi, 700 memcpy (a, atsi,
692 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->atsi_count); 701 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * atsi_count);
693 a[atsi_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 702 a[atsi_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
694 a[atsi_count].value = htonl (0); 703 a[atsi_count].value = htonl (0);
695 memcpy (&ats[atsi_count + 1], msg, msize); 704 memcpy (&a[atsi_count + 1], msg, msize);
696 send_to_all_clients (&ntm->header, GNUNET_YES, 705 send_to_all_clients (&ntm->header, GNUNET_YES,
697 options, ntohs (msg->type)); 706 options, ntohs (msg->type));
698} 707}
@@ -748,7 +757,7 @@ GSC_CLIENTS_done ()
748 handle_client_disconnect (NULL, c->client_handle); 757 handle_client_disconnect (NULL, c->client_handle);
749 GNUNET_SERVER_notification_context_destroy (notifier); 758 GNUNET_SERVER_notification_context_destroy (notifier);
750 notifier = NULL; 759 notifier = NULL;
751 GNUNET_SERVER_MST_destroy (client_mst); 760 GNUNET_SERVER_mst_destroy (client_mst);
752 client_mst = NULL; 761 client_mst = NULL;
753} 762}
754 763