fix 1821: only send payload to transport clients that care
authorChristian Grothoff <christian@grothoff.org>
Thu, 3 Nov 2011 15:00:26 +0000 (15:00 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 3 Nov 2011 15:00:26 +0000 (15:00 +0000)
src/transport/gnunet-service-transport_clients.c
src/transport/gnunet-service-transport_clients.h
src/transport/transport.h
src/transport/transport_api.c

index 50bb903c4858eb79d89dc9cdded033db4119f729..8b022ef7e50a8ba25a41edd2e6dd50fb4d47ad3d 100644 (file)
@@ -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 (&notify_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);
+  }
 }
 
 
index aae7ba89f6bae1576dfe7517bd2f659067b28dd9..d428fb257461720e7529f19b523e16d992928070 100644 (file)
@@ -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);
index 5bc4bad2b378ad437c474aba1e5bc297f65e482c..66f40cd06a6199453f1754b35690fadbcbe447f5 100644 (file)
@@ -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
index 2ececc10da107a7822d48f45c9bbd80a2268d37c..cff967b19b2333822d820c1a4967bb426951c493 100644 (file)
@@ -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,