diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-03 15:00:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-03 15:00:26 +0000 |
commit | 7ae7229d2de6a6ef842634265847a46ac46f8c5c (patch) | |
tree | a06bd988dccc8fc26addac2a4b3d3133c5c71b25 | |
parent | 26ec3709bd1283f8cbb70e33043f69326285eb1e (diff) | |
download | gnunet-7ae7229d2de6a6ef842634265847a46ac46f8c5c.tar.gz gnunet-7ae7229d2de6a6ef842634265847a46ac46f8c5c.zip |
fix 1821: only send payload to transport clients that care
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 20 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.h | 2 | ||||
-rw-r--r-- | src/transport/transport.h | 6 | ||||
-rw-r--r-- | src/transport/transport_api.c | 8 |
4 files changed, 28 insertions, 8 deletions
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 50bb903c4..8b022ef7e 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -108,6 +108,11 @@ struct TransportClient | |||
108 | * Length of the list of messages pending for this client. | 108 | * Length of the list of messages pending for this client. |
109 | */ | 109 | */ |
110 | unsigned int message_count; | 110 | unsigned int message_count; |
111 | |||
112 | /** | ||
113 | * Is this client interested in payload messages? | ||
114 | */ | ||
115 | int send_payload; | ||
111 | }; | 116 | }; |
112 | 117 | ||
113 | 118 | ||
@@ -370,6 +375,7 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client, | |||
370 | { | 375 | { |
371 | const struct StartMessage *start; | 376 | const struct StartMessage *start; |
372 | struct TransportClient *tc; | 377 | struct TransportClient *tc; |
378 | uint32_t options; | ||
373 | 379 | ||
374 | tc = lookup_client (client); | 380 | tc = lookup_client (client); |
375 | 381 | ||
@@ -394,10 +400,11 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client, | |||
394 | return; | 400 | return; |
395 | } | 401 | } |
396 | start = (const struct StartMessage *) message; | 402 | start = (const struct StartMessage *) message; |
397 | if ((GNUNET_NO != ntohl (start->do_check)) && | 403 | options = ntohl (start->options); |
404 | if ((0 != (1 & options) ) && | ||
398 | (0 != | 405 | (0 != |
399 | memcmp (&start->self, &GST_my_identity, | 406 | memcmp (&start->self, &GST_my_identity, |
400 | sizeof (struct GNUNET_PeerIdentity)))) | 407 | sizeof (struct GNUNET_PeerIdentity)))) |
401 | { | 408 | { |
402 | /* client thinks this is a different peer, reject */ | 409 | /* client thinks this is a different peer, reject */ |
403 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -408,7 +415,7 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client, | |||
408 | return; | 415 | return; |
409 | } | 416 | } |
410 | tc = setup_client (client); | 417 | tc = setup_client (client); |
411 | 418 | tc->send_payload = (0 != (2 & options)); | |
412 | unicast (tc, GST_hello_get (), GNUNET_NO); | 419 | unicast (tc, GST_hello_get (), GNUNET_NO); |
413 | GST_neighbours_iterate (¬ify_client_about_neighbour, tc); | 420 | GST_neighbours_iterate (¬ify_client_about_neighbour, tc); |
414 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 421 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -892,7 +899,7 @@ GST_clients_stop () | |||
892 | * Broadcast the given message to all of our clients. | 899 | * Broadcast the given message to all of our clients. |
893 | * | 900 | * |
894 | * @param msg message to broadcast | 901 | * @param msg message to broadcast |
895 | * @param may_drop GNUNET_YES if the message can be dropped | 902 | * @param may_drop GNUNET_YES if the message can be dropped / is payload |
896 | */ | 903 | */ |
897 | void | 904 | void |
898 | GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) | 905 | GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) |
@@ -900,7 +907,12 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) | |||
900 | struct TransportClient *tc; | 907 | struct TransportClient *tc; |
901 | 908 | ||
902 | for (tc = clients_head; tc != NULL; tc = tc->next) | 909 | for (tc = clients_head; tc != NULL; tc = tc->next) |
910 | { | ||
911 | if ( (GNUNET_YES == may_drop) && | ||
912 | (GNUNET_YES != tc->send_payload) ) | ||
913 | continue; /* skip, this client does not care about payload */ | ||
903 | unicast (tc, msg, may_drop); | 914 | unicast (tc, msg, may_drop); |
915 | } | ||
904 | } | 916 | } |
905 | 917 | ||
906 | 918 | ||
diff --git a/src/transport/gnunet-service-transport_clients.h b/src/transport/gnunet-service-transport_clients.h index aae7ba89f..d428fb257 100644 --- a/src/transport/gnunet-service-transport_clients.h +++ b/src/transport/gnunet-service-transport_clients.h | |||
@@ -50,7 +50,7 @@ GST_clients_stop (void); | |||
50 | * Broadcast the given message to all of our clients. | 50 | * Broadcast the given message to all of our clients. |
51 | * | 51 | * |
52 | * @param msg message to broadcast | 52 | * @param msg message to broadcast |
53 | * @param may_drop GNUNET_YES if the message can be dropped | 53 | * @param may_drop GNUNET_YES if the message can be dropped / is payload |
54 | */ | 54 | */ |
55 | void | 55 | void |
56 | GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop); | 56 | GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop); |
diff --git a/src/transport/transport.h b/src/transport/transport.h index 5bc4bad2b..66f40cd06 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -75,9 +75,11 @@ struct StartMessage | |||
75 | struct GNUNET_MessageHeader header; | 75 | struct GNUNET_MessageHeader header; |
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Should the 'self' field be checked? | 78 | * 0: no options |
79 | * 1: The 'self' field should be checked | ||
80 | * 2: this client is interested in payload traffic | ||
79 | */ | 81 | */ |
80 | uint32_t do_check; | 82 | uint32_t options; |
81 | 83 | ||
82 | /** | 84 | /** |
83 | * Identity we think we have. If it does not match, the | 85 | * Identity we think we have. If it does not match, the |
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 2ececc10d..cff967b19 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -861,6 +861,7 @@ send_start (void *cls, size_t size, void *buf) | |||
861 | { | 861 | { |
862 | struct GNUNET_TRANSPORT_Handle *h = cls; | 862 | struct GNUNET_TRANSPORT_Handle *h = cls; |
863 | struct StartMessage s; | 863 | struct StartMessage s; |
864 | uint32_t options; | ||
864 | 865 | ||
865 | if (buf == NULL) | 866 | if (buf == NULL) |
866 | { | 867 | { |
@@ -877,7 +878,12 @@ send_start (void *cls, size_t size, void *buf) | |||
877 | GNUNET_assert (size >= sizeof (struct StartMessage)); | 878 | GNUNET_assert (size >= sizeof (struct StartMessage)); |
878 | s.header.size = htons (sizeof (struct StartMessage)); | 879 | s.header.size = htons (sizeof (struct StartMessage)); |
879 | s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 880 | s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
880 | s.do_check = htonl (h->check_self); | 881 | options = 0; |
882 | if (h->check_self) | ||
883 | options |= 1; | ||
884 | if (h->rec != NULL) | ||
885 | options |= 2; | ||
886 | s.options = htonl (options); | ||
881 | s.self = h->self; | 887 | s.self = h->self; |
882 | memcpy (buf, &s, sizeof (struct StartMessage)); | 888 | memcpy (buf, &s, sizeof (struct StartMessage)); |
883 | GNUNET_CLIENT_receive (h->client, &demultiplexer, h, | 889 | GNUNET_CLIENT_receive (h->client, &demultiplexer, h, |