aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_clients.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-06 13:26:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-06 13:26:35 +0000
commitbef8aa69e425a0d6b30c892c8d1a2be9a49eecb5 (patch)
treecf689c29df8d1548f3ee3483f6b1aaa18c16d348 /src/core/gnunet-service-core_clients.c
parent4a5fc4b938bc98a2edc71d4875779619d0cebeec (diff)
downloadgnunet-bef8aa69e425a0d6b30c892c8d1a2be9a49eecb5.tar.gz
gnunet-bef8aa69e425a0d6b30c892c8d1a2be9a49eecb5.zip
stuff
Diffstat (limited to 'src/core/gnunet-service-core_clients.c')
-rw-r--r--src/core/gnunet-service-core_clients.c420
1 files changed, 219 insertions, 201 deletions
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c
index a0d5da65c..7d56a49a5 100644
--- a/src/core/gnunet-service-core_clients.c
+++ b/src/core/gnunet-service-core_clients.c
@@ -36,17 +36,17 @@
36/** 36/**
37 * Data structure for each client connected to the core service. 37 * Data structure for each client connected to the core service.
38 */ 38 */
39struct Client 39struct GSC_Client
40{ 40{
41 /** 41 /**
42 * Clients are kept in a linked list. 42 * Clients are kept in a linked list.
43 */ 43 */
44 struct Client *next; 44 struct GSC_Client *next;
45 45
46 /** 46 /**
47 * Clients are kept in a linked list. 47 * Clients are kept in a linked list.
48 */ 48 */
49 struct Client *prev; 49 struct GSC_Client *prev;
50 50
51 /** 51 /**
52 * Handle for the client with the server API. 52 * Handle for the client with the server API.
@@ -62,7 +62,7 @@ struct Client
62 62
63 /** 63 /**
64 * Map of peer identities to active transmission requests of this 64 * Map of peer identities to active transmission requests of this
65 * client to the peer (of type 'struct ClientActiveRequest'). 65 * client to the peer (of type 'struct GSC_ClientActiveRequest').
66 */ 66 */
67 struct GNUNET_CONTAINER_MultiHashMap *requests; 67 struct GNUNET_CONTAINER_MultiHashMap *requests;
68 68
@@ -84,12 +84,12 @@ struct Client
84/** 84/**
85 * Head of linked list of our clients. 85 * Head of linked list of our clients.
86 */ 86 */
87static struct Client *client_head; 87static struct GSC_Client *client_head;
88 88
89/** 89/**
90 * Tail of linked list of our clients. 90 * Tail of linked list of our clients.
91 */ 91 */
92static struct Client *client_tail; 92static struct GSC_Client *client_tail;
93 93
94/** 94/**
95 * Context for notifications we need to send to our clients. 95 * Context for notifications we need to send to our clients.
@@ -108,10 +108,10 @@ static struct GNUNET_SERVER_MessageStreamTokenizer *client_mst;
108 * @param client server client handle to look up 108 * @param client server client handle to look up
109 * @return our client handle for the client 109 * @return our client handle for the client
110 */ 110 */
111static struct Client * 111static struct GSC_Client *
112find_client (struct GNUNET_SERVER_Client *client) 112find_client (struct GNUNET_SERVER_Client *client)
113{ 113{
114 struct Client *c; 114 struct GSC_Client *c;
115 115
116 c = client_head; 116 c = client_head;
117 while ((c != NULL) && (c->client_handle != client)) 117 while ((c != NULL) && (c->client_handle != client))
@@ -129,7 +129,7 @@ find_client (struct GNUNET_SERVER_Client *client)
129 * client's queue is getting too large? 129 * client's queue is getting too large?
130 */ 130 */
131static void 131static void
132send_to_client (struct Client *client, 132send_to_client (struct GSC_Client *client,
133 const struct GNUNET_MessageHeader *msg, 133 const struct GNUNET_MessageHeader *msg,
134 int can_drop) 134 int can_drop)
135{ 135{
@@ -153,7 +153,7 @@ send_to_client (struct Client *client,
153 */ 153 */
154static int 154static int
155type_match (uint16_t type, 155type_match (uint16_t type,
156 struct Client *c) 156 struct GSC_Client *c)
157{ 157{
158 unsigned int i; 158 unsigned int i;
159 159
@@ -179,7 +179,7 @@ send_to_all_clients (const struct GNUNET_MessageHeader *msg,
179 int options, 179 int options,
180 uint16_t type) 180 uint16_t type)
181{ 181{
182 struct Client *c; 182 struct GSC_Client *c;
183 183
184 for (c = client_head; c != NULL; c = c->next) 184 for (c = client_head; c != NULL; c = c->next)
185 { 185 {
@@ -209,7 +209,7 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
209{ 209{
210 const struct InitMessage *im; 210 const struct InitMessage *im;
211 struct InitReplyMessage irm; 211 struct InitReplyMessage irm;
212 struct Client *c; 212 struct GSC_Client *c;
213 uint16_t msize; 213 uint16_t msize;
214 const uint16_t *types; 214 const uint16_t *types;
215 uint16_t *wtypes; 215 uint16_t *wtypes;
@@ -234,7 +234,7 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
234 im = (const struct InitMessage *) message; 234 im = (const struct InitMessage *) message;
235 types = (const uint16_t *) &im[1]; 235 types = (const uint16_t *) &im[1];
236 msize -= sizeof (struct InitMessage); 236 msize -= sizeof (struct InitMessage);
237 c = GNUNET_malloc (sizeof (struct Client) + msize); 237 c = GNUNET_malloc (sizeof (struct GSC_Client) + msize);
238 c->client_handle = client; 238 c->client_handle = client;
239 c->tcnt = msize / sizeof (uint16_t); 239 c->tcnt = msize / sizeof (uint16_t);
240 c->options = ntohl (im->options); 240 c->options = ntohl (im->options);
@@ -275,8 +275,8 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
275 const struct GNUNET_MessageHeader *message) 275 const struct GNUNET_MessageHeader *message)
276{ 276{
277 const struct SendMessageRequest *req; 277 const struct SendMessageRequest *req;
278 struct Client *c; 278 struct GSC_Client *c;
279 struct ClientActiveRequest *car; 279 struct GSC_ClientActiveRequest *car;
280 280
281 req = (const struct SendMessageRequest *) message; 281 req = (const struct SendMessageRequest *) message;
282 c = find_client (client); 282 c = find_client (client);
@@ -293,7 +293,7 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
293 if (car == NULL) 293 if (car == NULL)
294 { 294 {
295 /* create new entry */ 295 /* create new entry */
296 car = GNUNET_malloc (sizeof (struct ClientActiveRequest)); 296 car = GNUNET_malloc (sizeof (struct GSC_ClientActiveRequest));
297 GNUNET_assert (GNUNET_OK == 297 GNUNET_assert (GNUNET_OK ==
298 GNUNET_CONTAINER_multihashmap_put (c->requests, 298 GNUNET_CONTAINER_multihashmap_put (c->requests,
299 &req->peer.hashPubKey, 299 &req->peer.hashPubKey,
@@ -329,8 +329,8 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
329 const struct GNUNET_MessageHeader *message) 329 const struct GNUNET_MessageHeader *message)
330{ 330{
331 const struct SendMessage *sm; 331 const struct SendMessage *sm;
332 struct Client *c; 332 struct GSC_Client *c;
333 struct ClientActiveRequest *car; 333 struct GSC_ClientActiveRequest *car;
334 uint16_t msize; 334 uint16_t msize;
335 335
336 msize = ntohs (message->size); 336 msize = ntohs (message->size);
@@ -384,14 +384,14 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
384 * or other CLIENT (for loopback). 384 * or other CLIENT (for loopback).
385 * 385 *
386 * @param cls closure 386 * @param cls closure
387 * @param client reservation request ('struct ClientActiveRequest') 387 * @param client reservation request ('struct GSC_ClientActiveRequest')
388 * @param message the actual message 388 * @param message the actual message
389 */ 389 */
390static void 390static void
391client_tokenizer_callback (void *cls, void *client, 391client_tokenizer_callback (void *cls, void *client,
392 const struct GNUNET_MessageHeader *message) 392 const struct GNUNET_MessageHeader *message)
393{ 393{
394 struct ClientActiveRequest *car = client; 394 struct GSC_ClientActiveRequest *car = client;
395 395
396 if (0 == 396 if (0 ==
397 memcmp (&car->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 397 memcmp (&car->peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
@@ -406,15 +406,19 @@ client_tokenizer_callback (void *cls, void *client,
406 * 406 *
407 * @param cls NULL 407 * @param cls NULL
408 * @param key identity of peer for which this is an active request 408 * @param key identity of peer for which this is an active request
409 * @param value the 'struct ClientActiveRequest' to free 409 * @param value the 'struct GSC_ClientActiveRequest' to free
410 * @return GNUNET_YES (continue iteration) 410 * @return GNUNET_YES (continue iteration)
411 */ 411 */
412static int 412static int
413destroy_active_client_request (void *cls, const GNUNET_HashCode * key, 413destroy_active_client_request (void *cls, const GNUNET_HashCode * key,
414 void *value) 414 void *value)
415{ 415{
416 struct ClientActiveRequest *car = value; 416 struct GSC_ClientActiveRequest *car = value;
417 417
418 GNUNET_assert (GNUNET_YES ==
419 GNUNET_CONTAINER_multihashmap_remove (car->client->requests,
420 &car->peer,
421 car);
418 GSC_SESSIONS_dequeue_request (car); 422 GSC_SESSIONS_dequeue_request (car);
419 GNUNET_free (car); 423 GNUNET_free (car);
420 return GNUNET_YES; 424 return GNUNET_YES;
@@ -431,7 +435,7 @@ static void
431handle_client_disconnect (void *cls, 435handle_client_disconnect (void *cls,
432 struct GNUNET_SERVER_Client *client) 436 struct GNUNET_SERVER_Client *client)
433{ 437{
434 struct Client *c; 438 struct GSC_Client *c;
435 439
436 if (client == NULL) 440 if (client == NULL)
437 return; 441 return;
@@ -457,14 +461,6 @@ handle_client_disconnect (void *cls,
457} 461}
458 462
459 463
460
461
462
463
464// FIXME from here.......................................
465
466
467
468/** 464/**
469 * Tell a client that we are ready to receive the message. 465 * Tell a client that we are ready to receive the message.
470 * 466 *
@@ -475,6 +471,16 @@ handle_client_disconnect (void *cls,
475void 471void
476GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) 472GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
477{ 473{
474 struct GSC_Client *c;
475 struct SendMessageReady smr;
476
477 c = car->client;
478 smr.header.size = htons (sizeof (struct SendMessageReady));
479 smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
480 smr.size = htons (car->msize);
481 smr.smr_id = car->smr_id;
482 smr.peer = n->peer;
483 send_to_client (c, &smr.header, GNUNET_NO);
478} 484}
479 485
480 486
@@ -489,10 +495,18 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
489void 495void
490GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) 496GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
491{ 497{
498 GNUNET_assert (GNUNET_YES ==
499 destroy_active_client_request (NULL, &car->peer.hashPubKey, car));
492} 500}
493 501
494 502
495 503
504// FIXME from here.......................................
505
506
507
508
509
496 510
497/** 511/**
498 * Notify client about an existing connection to one of our neighbours. 512 * Notify client about an existing connection to one of our neighbours.
@@ -501,7 +515,7 @@ static int
501notify_client_about_neighbour (void *cls, const GNUNET_HashCode * key, 515notify_client_about_neighbour (void *cls, const GNUNET_HashCode * key,
502 void *value) 516 void *value)
503{ 517{
504 struct Client *c = cls; 518 struct GSC_Client *c = cls;
505 struct Neighbour *n = value; 519 struct Neighbour *n = value;
506 size_t size; 520 size_t size;
507 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 521 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
@@ -595,6 +609,177 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
595} 609}
596 610
597 611
612
613
614/**
615 * Send a P2P message to a client.
616 *
617 * @param sender who sent us the message?
618 * @param client who should we give the message to?
619 * @param m contains the message to transmit
620 * @param msize number of bytes in buf to transmit
621 */
622static void
623send_p2p_message_to_client (struct Neighbour *sender, struct GSC_Client *client,
624 const void *m, size_t msize)
625{
626 size_t size =
627 msize + sizeof (struct NotifyTrafficMessage) +
628 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
629 char buf[size];
630 struct NotifyTrafficMessage *ntm;
631 struct GNUNET_TRANSPORT_ATS_Information *ats;
632
633 GNUNET_assert (GNUNET_YES == sender->is_connected);
634 GNUNET_break (sender->status == PEER_STATE_KEY_CONFIRMED);
635 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
636 {
637 GNUNET_break (0);
638 /* recovery strategy: throw performance data away... */
639 GNUNET_array_grow (sender->ats, sender->ats_count, 0);
640 size =
641 msize + sizeof (struct NotifyTrafficMessage) +
642 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
643 }
644#if DEBUG_CORE
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "Core service passes message from `%4s' of type %u to client.\n",
647 GNUNET_i2s (&sender->peer),
648 (unsigned int)
649 ntohs (((const struct GNUNET_MessageHeader *) m)->type));
650#endif
651 ntm = (struct NotifyTrafficMessage *) buf;
652 ntm->header.size = htons (size);
653 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND);
654 ntm->ats_count = htonl (sender->ats_count);
655 ntm->peer = sender->peer;
656 ats = &ntm->ats;
657 memcpy (ats, sender->ats,
658 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count);
659 ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
660 ats[sender->ats_count].value = htonl (0);
661 memcpy (&ats[sender->ats_count + 1], m, msize);
662 send_to_client (client, &ntm->header, GNUNET_YES);
663}
664
665
666
667/**
668 * Notify a particular client about a change to existing connection to
669 * one of our neighbours (check if the client is interested). Called
670 * from 'GSC_SESSIONS_notify_client_about_sessions'.
671 *
672 * @param client client to notify
673 * @param neighbour identity of the neighbour that changed status
674 * @param tmap_old previous type map for the neighbour, NULL for disconnect
675 * @param tmap_new updated type map for the neighbour, NULL for disconnect
676 */
677void
678GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
679 const struct GNUNET_PeerIdentity *neighbour,
680 const struct GSC_TypeMap *tmap_old,
681 const struct GSC_TypeMap *tmap_new)
682{
683}
684
685
686/**
687 * Notify client about a change to existing connection to one of our neighbours.
688 *
689 * @param neighbour identity of the neighbour that changed status
690 * @param tmap_old previous type map for the neighbour, NULL for disconnect
691 * @param tmap_new updated type map for the neighbour, NULL for disconnect
692 */
693void
694GDS_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour,
695 const struct GSC_TypeMap *tmap_old,
696 const struct GSC_TypeMap *tmap_new)
697{
698}
699
700
701/**
702 * Deliver P2P message to interested clients.
703 *
704 * @param sender peer who sent us the message
705 * @param m the message
706 */
707void
708GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
709 const struct GNUNET_MessageHeader *m)
710{
711 struct Neighbour *sender = client;
712 size_t msize = ntohs (m->size);
713 char buf[256];
714 struct GSC_Client *cpos;
715 uint16_t type;
716 unsigned int tpos;
717 int deliver_full;
718 int dropped;
719
720 GNUNET_break (sender->status == PEER_STATE_KEY_CONFIRMED);
721 type = ntohs (m->type);
722#if DEBUG_CORE > 1
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
724 "Received encapsulated message of type %u and size %u from `%4s'\n",
725 (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer));
726#endif
727 GNUNET_snprintf (buf, sizeof (buf),
728 gettext_noop ("# bytes of messages of type %u received"),
729 (unsigned int) type);
730 GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO);
731 if ((GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) ||
732 (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type))
733 {
734 /* FIXME: update message type map for 'Neighbour' */
735 return;
736 }
737 dropped = GNUNET_YES;
738 cpos = clients;
739 while (cpos != NULL)
740 {
741 deliver_full = GNUNET_NO;
742 if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))
743 deliver_full = GNUNET_YES;
744 else
745 {
746 for (tpos = 0; tpos < cpos->tcnt; tpos++)
747 {
748 if (type != cpos->types[tpos])
749 continue;
750 deliver_full = GNUNET_YES;
751 break;
752 }
753 }
754 if (GNUNET_YES == deliver_full)
755 {
756 send_p2p_message_to_client (sender, cpos, m, msize);
757 dropped = GNUNET_NO;
758 }
759 else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)
760 {
761 send_p2p_message_to_client (sender, cpos, m,
762 sizeof (struct GNUNET_MessageHeader));
763 }
764 cpos = cpos->next;
765 }
766 if (dropped == GNUNET_YES)
767 {
768#if DEBUG_CORE
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Message of type %u from `%4s' not delivered to any client.\n",
771 (unsigned int) type, GNUNET_i2s (&sender->peer));
772#endif
773 GNUNET_STATISTICS_update (stats,
774 gettext_noop
775 ("# messages not delivered to any client"), 1,
776 GNUNET_NO);
777 }
778}
779
780
781
782
598/** 783/**
599 * Handle CORE_ITERATE_PEERS request. 784 * Handle CORE_ITERATE_PEERS request.
600 * 785 *
@@ -665,7 +850,7 @@ handle_client_request_info (void *cls, struct GNUNET_SERVER_Client *client,
665 const struct GNUNET_MessageHeader *message) 850 const struct GNUNET_MessageHeader *message)
666{ 851{
667 const struct RequestInfoMessage *rcm; 852 const struct RequestInfoMessage *rcm;
668 struct Client *pos; 853 struct GSC_Client *pos;
669 struct Neighbour *n; 854 struct Neighbour *n;
670 struct ConfigurationInfoMessage cim; 855 struct ConfigurationInfoMessage cim;
671 int32_t want_reserv; 856 int32_t want_reserv;
@@ -778,173 +963,6 @@ handle_client_request_info (void *cls, struct GNUNET_SERVER_Client *client,
778 963
779 964
780/** 965/**
781 * Send a P2P message to a client.
782 *
783 * @param sender who sent us the message?
784 * @param client who should we give the message to?
785 * @param m contains the message to transmit
786 * @param msize number of bytes in buf to transmit
787 */
788static void
789send_p2p_message_to_client (struct Neighbour *sender, struct Client *client,
790 const void *m, size_t msize)
791{
792 size_t size =
793 msize + sizeof (struct NotifyTrafficMessage) +
794 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
795 char buf[size];
796 struct NotifyTrafficMessage *ntm;
797 struct GNUNET_TRANSPORT_ATS_Information *ats;
798
799 GNUNET_assert (GNUNET_YES == sender->is_connected);
800 GNUNET_break (sender->status == PEER_STATE_KEY_CONFIRMED);
801 if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
802 {
803 GNUNET_break (0);
804 /* recovery strategy: throw performance data away... */
805 GNUNET_array_grow (sender->ats, sender->ats_count, 0);
806 size =
807 msize + sizeof (struct NotifyTrafficMessage) +
808 (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
809 }
810#if DEBUG_CORE
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
812 "Core service passes message from `%4s' of type %u to client.\n",
813 GNUNET_i2s (&sender->peer),
814 (unsigned int)
815 ntohs (((const struct GNUNET_MessageHeader *) m)->type));
816#endif
817 ntm = (struct NotifyTrafficMessage *) buf;
818 ntm->header.size = htons (size);
819 ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND);
820 ntm->ats_count = htonl (sender->ats_count);
821 ntm->peer = sender->peer;
822 ats = &ntm->ats;
823 memcpy (ats, sender->ats,
824 sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count);
825 ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
826 ats[sender->ats_count].value = htonl (0);
827 memcpy (&ats[sender->ats_count + 1], m, msize);
828 send_to_client (client, &ntm->header, GNUNET_YES);
829}
830
831
832
833/**
834 * Notify a particular client about a change to existing connection to
835 * one of our neighbours (check if the client is interested). Called
836 * from 'GSC_SESSIONS_notify_client_about_sessions'.
837 *
838 * @param client client to notify
839 * @param neighbour identity of the neighbour that changed status
840 * @param tmap_old previous type map for the neighbour, NULL for disconnect
841 * @param tmap_new updated type map for the neighbour, NULL for disconnect
842 */
843void
844GDS_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
845 const struct GNUNET_PeerIdentity *neighbour,
846 const struct GSC_TypeMap *tmap_old,
847 const struct GSC_TypeMap *tmap_new)
848{
849}
850
851
852/**
853 * Notify client about a change to existing connection to one of our neighbours.
854 *
855 * @param neighbour identity of the neighbour that changed status
856 * @param tmap_old previous type map for the neighbour, NULL for disconnect
857 * @param tmap_new updated type map for the neighbour, NULL for disconnect
858 */
859void
860GDS_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour,
861 const struct GSC_TypeMap *tmap_old,
862 const struct GSC_TypeMap *tmap_new)
863{
864}
865
866
867/**
868 * Deliver P2P message to interested clients.
869 *
870 * @param sender peer who sent us the message
871 * @param m the message
872 */
873void
874GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
875 const struct GNUNET_MessageHeader *m)
876{
877 struct Neighbour *sender = client;
878 size_t msize = ntohs (m->size);
879 char buf[256];
880 struct Client *cpos;
881 uint16_t type;
882 unsigned int tpos;
883 int deliver_full;
884 int dropped;
885
886 GNUNET_break (sender->status == PEER_STATE_KEY_CONFIRMED);
887 type = ntohs (m->type);
888#if DEBUG_CORE > 1
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 "Received encapsulated message of type %u and size %u from `%4s'\n",
891 (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer));
892#endif
893 GNUNET_snprintf (buf, sizeof (buf),
894 gettext_noop ("# bytes of messages of type %u received"),
895 (unsigned int) type);
896 GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO);
897 if ((GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) ||
898 (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type))
899 {
900 /* FIXME: update message type map for 'Neighbour' */
901 return;
902 }
903 dropped = GNUNET_YES;
904 cpos = clients;
905 while (cpos != NULL)
906 {
907 deliver_full = GNUNET_NO;
908 if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))
909 deliver_full = GNUNET_YES;
910 else
911 {
912 for (tpos = 0; tpos < cpos->tcnt; tpos++)
913 {
914 if (type != cpos->types[tpos])
915 continue;
916 deliver_full = GNUNET_YES;
917 break;
918 }
919 }
920 if (GNUNET_YES == deliver_full)
921 {
922 send_p2p_message_to_client (sender, cpos, m, msize);
923 dropped = GNUNET_NO;
924 }
925 else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)
926 {
927 send_p2p_message_to_client (sender, cpos, m,
928 sizeof (struct GNUNET_MessageHeader));
929 }
930 cpos = cpos->next;
931 }
932 if (dropped == GNUNET_YES)
933 {
934#if DEBUG_CORE
935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
936 "Message of type %u from `%4s' not delivered to any client.\n",
937 (unsigned int) type, GNUNET_i2s (&sender->peer));
938#endif
939 GNUNET_STATISTICS_update (stats,
940 gettext_noop
941 ("# messages not delivered to any client"), 1,
942 GNUNET_NO);
943 }
944}
945
946
947/**
948 * Initialize clients subsystem. 966 * Initialize clients subsystem.
949 * 967 *
950 * @param server handle to server clients connect to 968 * @param server handle to server clients connect to
@@ -988,7 +1006,7 @@ GSC_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
988void 1006void
989GSC_CLIENTS_done () 1007GSC_CLIENTS_done ()
990{ 1008{
991 struct Client *c; 1009 struct GSC_Client *c;
992 1010
993 while (NULL != (c = client_head)) 1011 while (NULL != (c = client_head))
994 handle_client_disconnect (NULL, c->client_handle); 1012 handle_client_disconnect (NULL, c->client_handle);