-fix logging, revert to break instead of assert
[oweals/gnunet.git] / src / core / gnunet-service-core_clients.c
index b57936baabd2fcacaf25efd82496a7ba6b438a42..1076f343f2ee5e879428c4b80c4e7597f86ad76a 100644 (file)
@@ -223,16 +223,18 @@ send_to_all_clients (const struct GNUNET_PeerIdentity *partner,
                      uint32_t options, uint16_t type)
 {
   struct GSC_Client *c;
+  int tm;
 
   for (c = client_head; c != NULL; c = c->next)
   {
+    tm = type_match (type, c);
     if (!  ( (0 != (c->options & options)) ||
             ( (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
-              (GNUNET_YES == type_match (type, c)) ) ) )
+              (GNUNET_YES == tm) ) ) )
       continue;  /* neither options nor type match permit the message */
     if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) &&
         ( (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
-          (GNUNET_YES == type_match (type, c)) ) )
+          (GNUNET_YES == tm) ) )
       continue;
     if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) &&
         (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) )
@@ -242,9 +244,11 @@ send_to_all_clients (const struct GNUNET_PeerIdentity *partner,
                options,
                ntohs (msg->size),
                 (unsigned int) type);
-    GNUNET_assert (GNUNET_YES ==
-                   GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
-                                                           &partner->hashPubKey));
+    GNUNET_assert ( (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
+                   (GNUNET_YES != tm) ||
+                   (GNUNET_YES ==
+                    GNUNET_CONTAINER_multihashmap_contains (c->connectmap,
+                                                            &partner->hashPubKey)) );
     send_to_client (c, msg, can_drop);
   }
 }
@@ -502,7 +506,7 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
  * @param client reservation request ('struct GSC_ClientActiveRequest')
  * @param message the actual message
  */
-static void
+static int
 client_tokenizer_callback (void *cls, void *client,
                            const struct GNUNET_MessageHeader *message)
 {
@@ -531,11 +535,9 @@ client_tokenizer_callback (void *cls, void *client,
   }
   else
   {
-#if DEBUG_CORE
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Delivering message of type %u to %s\n", ntohs (message->type),
                 GNUNET_i2s (&car->target));
-#endif
     GSC_CLIENTS_deliver_message (&car->target, NULL, 0, message,
                                 ntohs (message->size),
                                 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
@@ -544,6 +546,7 @@ client_tokenizer_callback (void *cls, void *client,
                                 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);  
     GSC_SESSIONS_transmit (car, message, tc->cork);
   }
+  return GNUNET_OK;
 }
 
 
@@ -585,10 +588,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
 
   if (client == NULL)
     return;
-#if DEBUG_CORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Client %p has disconnected from core service.\n", client);
-#endif
   c = find_client (client);
   if (c == NULL)
     return;                     /* client never sent INIT */
@@ -690,7 +691,7 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
 {
   struct ConnectNotifyMessage *cnm;
   size_t size;
-  char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
+  char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN;
   struct GNUNET_ATS_Information *a;
   struct DisconnectNotifyMessage dcm;
   int old_match;
@@ -732,10 +733,8 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
     cnm->ats_count = htonl (atsi_count);
     a = (struct GNUNET_ATS_Information *) &cnm[1];
     memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
-#if DEBUG_CORE
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
                 "NOTIFY_CONNECT");
-#endif
     cnm->peer = *neighbour;
     send_to_client (client, &cnm->header, GNUNET_NO);
   }
@@ -809,7 +808,7 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
   size_t size =
       msize + sizeof (struct NotifyTrafficMessage) +
       atsi_count * sizeof (struct GNUNET_ATS_Information);
-  char buf[size];
+  char buf[size] GNUNET_ALIGN;
   struct NotifyTrafficMessage *ntm;
   struct GNUNET_ATS_Information *a;
 
@@ -842,11 +841,9 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
     ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND);
   ntm->ats_count = htonl (atsi_count);
   ntm->peer = *sender;
-  a = &ntm->ats;
+  a = (struct GNUNET_ATS_Information*) &ntm[1];
   memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
-  a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
-  a[atsi_count].value = htonl (0);
-  memcpy (&a[atsi_count + 1], msg, msize);
+  memcpy (&a[atsi_count], msg, msize);
   send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
                        ntohs (msg->type));
 }