diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-23 13:07:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-23 13:07:53 +0000 |
commit | 519bae72ede0aae32978a3702313f0e97ccf14b4 (patch) | |
tree | 64e3418dca9d6841be5b37ed94fe3cb949fae6f9 /src/core/gnunet-service-core_clients.c | |
parent | 83980d6b91589995808ec5ff261f4e7ca48a8206 (diff) | |
download | gnunet-519bae72ede0aae32978a3702313f0e97ccf14b4.tar.gz gnunet-519bae72ede0aae32978a3702313f0e97ccf14b4.zip |
Diffstat (limited to 'src/core/gnunet-service-core_clients.c')
-rw-r--r-- | src/core/gnunet-service-core_clients.c | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c index 47bbd98db..11409392d 100644 --- a/src/core/gnunet-service-core_clients.c +++ b/src/core/gnunet-service-core_clients.c | |||
@@ -33,6 +33,8 @@ | |||
33 | #include "gnunet-service-core_typemap.h" | 33 | #include "gnunet-service-core_typemap.h" |
34 | #include "core.h" | 34 | #include "core.h" |
35 | 35 | ||
36 | #define DEBUG_CONNECTS GNUNET_YES | ||
37 | |||
36 | /** | 38 | /** |
37 | * How many messages do we queue up at most for optional | 39 | * How many messages do we queue up at most for optional |
38 | * notifications to a client? (this can cause notifications | 40 | * notifications to a client? (this can cause notifications |
@@ -74,6 +76,13 @@ struct GSC_Client | |||
74 | */ | 76 | */ |
75 | struct GNUNET_CONTAINER_MultiHashMap *requests; | 77 | struct GNUNET_CONTAINER_MultiHashMap *requests; |
76 | 78 | ||
79 | #if DEBUG_CONNECTS | ||
80 | /** | ||
81 | * Map containing all peers that this client knows we're connected to. | ||
82 | */ | ||
83 | struct GNUNET_CONTAINER_MultiHashMap *connectmap; | ||
84 | #endif | ||
85 | |||
77 | /** | 86 | /** |
78 | * Options for messages this client cares about, | 87 | * Options for messages this client cares about, |
79 | * see GNUNET_CORE_OPTION_ values. | 88 | * see GNUNET_CORE_OPTION_ values. |
@@ -209,7 +218,8 @@ type_match (uint16_t type, | |||
209 | * @param type type of the embedded message, 0 for none | 218 | * @param type type of the embedded message, 0 for none |
210 | */ | 219 | */ |
211 | static void | 220 | static void |
212 | send_to_all_clients (const struct GNUNET_MessageHeader *msg, | 221 | send_to_all_clients (const struct GNUNET_PeerIdentity *sender, |
222 | const struct GNUNET_MessageHeader *msg, | ||
213 | int can_drop, | 223 | int can_drop, |
214 | int options, | 224 | int options, |
215 | uint16_t type) | 225 | uint16_t type) |
@@ -229,6 +239,11 @@ send_to_all_clients (const struct GNUNET_MessageHeader *msg, | |||
229 | "Sending message to client interested in messages of type %u.\n", | 239 | "Sending message to client interested in messages of type %u.\n", |
230 | (unsigned int) type); | 240 | (unsigned int) type); |
231 | #endif | 241 | #endif |
242 | #if DEBUG_CONNECTS | ||
243 | GNUNET_assert (GNUNET_YES == | ||
244 | GNUNET_CONTAINER_multihashmap_contains (c->connectmap, | ||
245 | &sender->hashPubKey)); | ||
246 | #endif | ||
232 | send_to_client (c, msg, can_drop); | 247 | send_to_client (c, msg, can_drop); |
233 | } | 248 | } |
234 | } | 249 | } |
@@ -277,6 +292,15 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
277 | c->tcnt = msize / sizeof (uint16_t); | 292 | c->tcnt = msize / sizeof (uint16_t); |
278 | c->options = ntohl (im->options); | 293 | c->options = ntohl (im->options); |
279 | c->types = (const uint16_t *) &c[1]; | 294 | c->types = (const uint16_t *) &c[1]; |
295 | #if DEBUG_CONNECTS | ||
296 | c->connectmap = GNUNET_CONTAINER_multihashmap_create (16); | ||
297 | GNUNET_assert (GNUNET_YES == | ||
298 | GNUNET_CONTAINER_multihashmap_put (c->connectmap, | ||
299 | &GSC_my_identity.hashPubKey, | ||
300 | NULL, | ||
301 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
302 | #endif | ||
303 | |||
280 | wtypes = (uint16_t *) & c[1]; | 304 | wtypes = (uint16_t *) & c[1]; |
281 | for (i = 0; i < c->tcnt; i++) | 305 | for (i = 0; i < c->tcnt; i++) |
282 | wtypes[i] = ntohs (types[i]); | 306 | wtypes[i] = ntohs (types[i]); |
@@ -305,7 +329,7 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client, | |||
305 | * | 329 | * |
306 | * @param cls unused | 330 | * @param cls unused |
307 | * @param client new client that sent CORE_SEND_REQUEST | 331 | * @param client new client that sent CORE_SEND_REQUEST |
308 | * @param message the 'struct InitMessage' (presumably) | 332 | * @param message the 'struct SendMessageRequest' (presumably) |
309 | */ | 333 | */ |
310 | static void | 334 | static void |
311 | handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client, | 335 | handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client, |
@@ -324,6 +348,11 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client, | |||
324 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 348 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
325 | return; | 349 | return; |
326 | } | 350 | } |
351 | #if DEBUG_CONNECTS | ||
352 | GNUNET_assert (GNUNET_YES == | ||
353 | GNUNET_CONTAINER_multihashmap_contains (c->connectmap, | ||
354 | &req->peer.hashPubKey)); | ||
355 | #endif | ||
327 | if (c->requests == NULL) | 356 | if (c->requests == NULL) |
328 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); | 357 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); |
329 | #if DEBUG_CORE | 358 | #if DEBUG_CORE |
@@ -553,6 +582,9 @@ handle_client_disconnect (void *cls, | |||
553 | NULL); | 582 | NULL); |
554 | GNUNET_CONTAINER_multihashmap_destroy (c->requests); | 583 | GNUNET_CONTAINER_multihashmap_destroy (c->requests); |
555 | } | 584 | } |
585 | #if DEBUG_CONNECTS | ||
586 | GNUNET_CONTAINER_multihashmap_destroy (c->connectmap); | ||
587 | #endif | ||
556 | GSC_TYPEMAP_remove (c->types, c->tcnt); | 588 | GSC_TYPEMAP_remove (c->types, c->tcnt); |
557 | GNUNET_free (c); | 589 | GNUNET_free (c); |
558 | } | 590 | } |
@@ -577,6 +609,11 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) | |||
577 | smr.size = htons (car->msize); | 609 | smr.size = htons (car->msize); |
578 | smr.smr_id = car->smr_id; | 610 | smr.smr_id = car->smr_id; |
579 | smr.peer = car->target; | 611 | smr.peer = car->target; |
612 | #if DEBUG_CONNECTS | ||
613 | GNUNET_assert (GNUNET_YES == | ||
614 | GNUNET_CONTAINER_multihashmap_contains (c->connectmap, | ||
615 | &car->target.hashPubKey)); | ||
616 | #endif | ||
580 | send_to_client (c, &smr.header, GNUNET_NO); | 617 | send_to_client (c, &smr.header, GNUNET_NO); |
581 | } | 618 | } |
582 | 619 | ||
@@ -592,6 +629,11 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) | |||
592 | void | 629 | void |
593 | GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) | 630 | GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car) |
594 | { | 631 | { |
632 | #if DEBUG_CONNECTS | ||
633 | GNUNET_assert (GNUNET_YES == | ||
634 | GNUNET_CONTAINER_multihashmap_contains (car->client_handle->connectmap, | ||
635 | &car->target.hashPubKey)); | ||
636 | #endif | ||
595 | GNUNET_assert (GNUNET_YES == | 637 | GNUNET_assert (GNUNET_YES == |
596 | GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, | 638 | GNUNET_CONTAINER_multihashmap_remove (car->client_handle->requests, |
597 | &car->target.hashPubKey, | 639 | &car->target.hashPubKey, |
@@ -644,6 +686,16 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, | |||
644 | if (old_match == GNUNET_NO) | 686 | if (old_match == GNUNET_NO) |
645 | { | 687 | { |
646 | /* send connect */ | 688 | /* send connect */ |
689 | #if DEBUG_CONNECTS | ||
690 | GNUNET_assert (GNUNET_NO == | ||
691 | GNUNET_CONTAINER_multihashmap_contains (client->connectmap, | ||
692 | &neighbour->hashPubKey)); | ||
693 | GNUNET_assert (GNUNET_YES == | ||
694 | GNUNET_CONTAINER_multihashmap_put (client->connectmap, | ||
695 | &neighbour->hashPubKey, | ||
696 | NULL, | ||
697 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
698 | #endif | ||
647 | size = | 699 | size = |
648 | sizeof (struct ConnectNotifyMessage) + | 700 | sizeof (struct ConnectNotifyMessage) + |
649 | (atsi_count) * sizeof (struct GNUNET_ATS_Information); | 701 | (atsi_count) * sizeof (struct GNUNET_ATS_Information); |
@@ -672,6 +724,15 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client, | |||
672 | else | 724 | else |
673 | { | 725 | { |
674 | /* send disconnect */ | 726 | /* send disconnect */ |
727 | #if DEBUG_CONNECTS | ||
728 | GNUNET_assert (GNUNET_YES == | ||
729 | GNUNET_CONTAINER_multihashmap_contains (client->connectmap, | ||
730 | &neighbour->hashPubKey)); | ||
731 | GNUNET_assert (GNUNET_YES == | ||
732 | GNUNET_CONTAINER_multihashmap_remove (client->connectmap, | ||
733 | &neighbour->hashPubKey, | ||
734 | NULL)); | ||
735 | #endif | ||
675 | dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); | 736 | dcm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); |
676 | dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); | 737 | dcm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); |
677 | dcm.reserved = htonl (0); | 738 | dcm.reserved = htonl (0); |
@@ -767,7 +828,8 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
767 | a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); | 828 | a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR); |
768 | a[atsi_count].value = htonl (0); | 829 | a[atsi_count].value = htonl (0); |
769 | memcpy (&a[atsi_count + 1], msg, msize); | 830 | memcpy (&a[atsi_count + 1], msg, msize); |
770 | send_to_all_clients (&ntm->header, GNUNET_YES, | 831 | send_to_all_clients (sender, |
832 | &ntm->header, GNUNET_YES, | ||
771 | options, ntohs (msg->type)); | 833 | options, ntohs (msg->type)); |
772 | } | 834 | } |
773 | 835 | ||