add some extra GNS-record well-formedness checks if logging is enabled
[oweals/gnunet.git] / src / ats / gnunet-service-ats_preferences.c
index 9cee64b1dcd1806a2e29c90a17176689e9434531..9f11dc6a8dd180aa1c8f6522b6057724fb19d77e 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2011-2015 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 /**
  * @file ats/gnunet-service-ats_preferences.c
@@ -132,7 +132,7 @@ struct PreferenceClient
   /**
    * Client handle
    */
-  struct GNUNET_SERVER_Client *client;
+  struct GNUNET_SERVICE_Client *client;
 
   /**
    * Mapping peer identities to `struct PreferencePeer` entry
@@ -218,7 +218,6 @@ sum_relative_preferences (void *cls,
  *
  * @param id peer id of the peer for which we should do the update
  * @param kind the kind of preference value to update
- * @param rp the relative peer struct where we store the global result
  * @return the new relative preference
  */
 static void
@@ -388,11 +387,9 @@ age_values (void *cls,
  * Reduce absolute preferences since they got old.
  *
  * @param cls unused
- * @param tc context
  */
 static void
-preference_aging (void *cls,
-                  const struct GNUNET_SCHEDULER_TaskContext *tc)
+preference_aging (void *cls)
 {
   struct AgeContext ac;
 
@@ -528,7 +525,7 @@ recalculate_relative_preferences (struct PreferenceClient *c,
  * changed, update the global preferences for the given
  * peer and notify the plugin.
  *
- * @param value the kind of preference to calculate the
+ * @param cls the kind of preference to calculate the
  *        new global relative preference values for
  * @param key the peer to update relative preference values for
  * @param value a `struct PeerRelative`, unused
@@ -556,7 +553,7 @@ update_iterator (void *cls,
  * @param score_abs the normalized score
  */
 static void
-update_preference (struct GNUNET_SERVER_Client *client,
+update_preference (struct GNUNET_SERVICE_Client *client,
                    const struct GNUNET_PeerIdentity *peer,
                    enum GNUNET_ATS_PreferenceKind kind,
                    float score_abs)
@@ -649,41 +646,17 @@ update_preference (struct GNUNET_SERVER_Client *client,
 /**
  * Handle 'preference change' messages from clients.
  *
- * @param cls unused, NULL
- * @param client client that sent the request
- * @param message the request message
+ * @param client the client that sent the request
+ * @param msg the request message
  */
 void
-GAS_handle_preference_change (void *cls,
-                              struct GNUNET_SERVER_Client *client,
-                              const struct GNUNET_MessageHeader *message)
+GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client,
+                             const struct ChangePreferenceMessage *msg)
 {
-  const struct ChangePreferenceMessage *msg;
   const struct PreferenceInformation *pi;
-  uint16_t msize;
   uint32_t nump;
-  uint32_t i;
 
-  msize = ntohs (message->size);
-  if (msize < sizeof (struct ChangePreferenceMessage))
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client,
-                                GNUNET_SYSERR);
-    return;
-  }
-  msg = (const struct ChangePreferenceMessage *) message;
   nump = ntohl (msg->num_preferences);
-  if ( (msize !=
-        sizeof (struct ChangePreferenceMessage) +
-        nump * sizeof (struct PreferenceInformation)) ||
-       (UINT16_MAX / sizeof (struct PreferenceInformation) < nump) )
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client,
-                                GNUNET_SYSERR);
-    return;
-  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received PREFERENCE_CHANGE message for peer `%s'\n",
               GNUNET_i2s (&msg->peer));
@@ -693,14 +666,12 @@ GAS_handle_preference_change (void *cls,
                             GNUNET_NO);
   pi = (const struct PreferenceInformation *) &msg[1];
   GAS_plugin_solver_lock ();
-  for (i = 0; i < nump; i++)
+  for (uint32_t i = 0; i < nump; i++)
     update_preference (client,
                        &msg->peer,
                        (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind),
                        pi[i].preference_value);
   GAS_plugin_solver_unlock ();
-  GNUNET_SERVER_receive_done (client,
-                              GNUNET_OK);
 }
 
 
@@ -785,7 +756,7 @@ GAS_preference_get_by_peer (void *cls,
  * @param client the client
  */
 void
-GAS_preference_client_disconnect (struct GNUNET_SERVER_Client *client)
+GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client)
 {
   struct PreferenceClient *c_cur;