From: Christian Grothoff Date: Thu, 3 Nov 2011 15:00:26 +0000 (+0000) Subject: fix 1821: only send payload to transport clients that care X-Git-Tag: initial-import-from-subversion-38251~16076 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=7ae7229d2de6a6ef842634265847a46ac46f8c5c;p=oweals%2Fgnunet.git fix 1821: only send payload to transport clients that care --- 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 * Length of the list of messages pending for this client. */ unsigned int message_count; + + /** + * Is this client interested in payload messages? + */ + int send_payload; }; @@ -370,6 +375,7 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client, { const struct StartMessage *start; struct TransportClient *tc; + uint32_t options; tc = lookup_client (client); @@ -394,10 +400,11 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client, return; } start = (const struct StartMessage *) message; - if ((GNUNET_NO != ntohl (start->do_check)) && + options = ntohl (start->options); + if ((0 != (1 & options) ) && (0 != memcmp (&start->self, &GST_my_identity, - sizeof (struct GNUNET_PeerIdentity)))) + sizeof (struct GNUNET_PeerIdentity)))) { /* client thinks this is a different peer, reject */ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, @@ -408,7 +415,7 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client, return; } tc = setup_client (client); - + tc->send_payload = (0 != (2 & options)); unicast (tc, GST_hello_get (), GNUNET_NO); GST_neighbours_iterate (¬ify_client_about_neighbour, tc); GNUNET_SERVER_receive_done (client, GNUNET_OK); @@ -892,7 +899,7 @@ GST_clients_stop () * Broadcast the given message to all of our clients. * * @param msg message to broadcast - * @param may_drop GNUNET_YES if the message can be dropped + * @param may_drop GNUNET_YES if the message can be dropped / is payload */ void 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) struct TransportClient *tc; for (tc = clients_head; tc != NULL; tc = tc->next) + { + if ( (GNUNET_YES == may_drop) && + (GNUNET_YES != tc->send_payload) ) + continue; /* skip, this client does not care about payload */ unicast (tc, msg, may_drop); + } } 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); * Broadcast the given message to all of our clients. * * @param msg message to broadcast - * @param may_drop GNUNET_YES if the message can be dropped + * @param may_drop GNUNET_YES if the message can be dropped / is payload */ void 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 struct GNUNET_MessageHeader header; /** - * Should the 'self' field be checked? + * 0: no options + * 1: The 'self' field should be checked + * 2: this client is interested in payload traffic */ - uint32_t do_check; + uint32_t options; /** * 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) { struct GNUNET_TRANSPORT_Handle *h = cls; struct StartMessage s; + uint32_t options; if (buf == NULL) { @@ -877,7 +878,12 @@ send_start (void *cls, size_t size, void *buf) GNUNET_assert (size >= sizeof (struct StartMessage)); s.header.size = htons (sizeof (struct StartMessage)); s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START); - s.do_check = htonl (h->check_self); + options = 0; + if (h->check_self) + options |= 1; + if (h->rec != NULL) + options |= 2; + s.options = htonl (options); s.self = h->self; memcpy (buf, &s, sizeof (struct StartMessage)); GNUNET_CLIENT_receive (h->client, &demultiplexer, h,