remove protocol violation
[oweals/gnunet.git] / src / psycstore / gnunet-service-psycstore.c
index 3d6cfdc40936e7726112ef7a7e06ed04b94ca581..8a70bb22f9a71f1d14b7e7eaa07d5563043924ea 100644 (file)
  * @brief PSYCstore service
  * @author Gabor X Toth
  * @author Christian Grothoff
- *
- * The purpose of this service is to manage private keys that
- * represent the various egos/pseudonyms/identities of a GNUnet user.
- *
  */
+
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_constants.h"
@@ -89,7 +86,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
-/** 
+/**
  * Send a result code back to the client.
  *
  * @param client Client that should receive the result code.
@@ -113,7 +110,8 @@ send_result_code (struct GNUNET_SERVER_Client *client, uint32_t result_code,
   res->header.size = htons (sizeof (struct OperationResult) + err_len);
   res->result_code = htonl (result_code);
   res->op_id = op_id;
-  memcpy (&res[1], err_msg, err_len);
+  if (0 < err_len)
+    memcpy (&res[1], err_msg, err_len);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending result %d (%s) to client\n",
              (int) result_code,
@@ -172,7 +170,7 @@ send_state_var (void *cls, const char *name,
   res->op_id = sc->op_id;
   res->name_size = htons (name_size);
   memcpy (&res[1], name, name_size);
-  memcpy ((void *) &res[1] + name_size, value, value_size);
+  memcpy ((char *) &res[1] + name_size, value, value_size);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Sending state variable %s to client\n", name);
   GNUNET_SERVER_notification_context_add (nc, sc->client);
@@ -336,19 +334,21 @@ handle_message_get_fragment (void *cls,
 
 
 static void
-handle_counters_get_master (void *cls,
-                            struct GNUNET_SERVER_Client *client,
-                            const struct GNUNET_MessageHeader *msg)
+handle_counters_get (void *cls,
+                     struct GNUNET_SERVER_Client *client,
+                     const struct GNUNET_MessageHeader *msg)
 {
   const struct OperationRequest *req = (const struct OperationRequest *) msg;
-  struct MasterCountersResult res = { {0} };
+  struct CountersResult res = { {0} };
 
-  int ret = db->counters_get_master (db->cls, &req->channel_key,
-                                     &res.fragment_id, &res.message_id,
-                                     &res.group_generation);
+  int ret = db->counters_message_get (db->cls, &req->channel_key,
+                                      &res.max_fragment_id, &res.max_message_id,
+                                      &res.max_group_generation);
   switch (ret)
   {
-  case GNUNET_YES:
+  case GNUNET_OK:
+    ret = db->counters_state_get (db->cls, &req->channel_key,
+                                  &res.max_state_message_id);
   case GNUNET_NO:
     break;
   default:
@@ -356,50 +356,14 @@ handle_counters_get_master (void *cls,
                 _("Failed to get master counters!\n"));
   }
 
-  res.header.type
-    = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_MASTER);
-  res.header.size = htons (sizeof (res));
-  res.result_code = htonl (ret);
-  res.op_id = req->op_id;
-  res.fragment_id = GNUNET_htonll (res.fragment_id);
-  res.message_id = GNUNET_htonll (res.message_id);
-  res.group_generation = GNUNET_htonll (res.group_generation);
-
-  GNUNET_SERVER_notification_context_add (nc, client);
-  GNUNET_SERVER_notification_context_unicast (nc, client, &res.header,
-                                              GNUNET_NO);
-
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-}
-
-
-static void
-handle_counters_get_slave (void *cls,
-                           struct GNUNET_SERVER_Client *client,
-                           const struct GNUNET_MessageHeader *msg)
-{
-  const struct OperationRequest *req = (const struct OperationRequest *) msg;
-  struct SlaveCountersResult res = { {0} };
-
-  int ret = db->counters_get_slave (db->cls, &req->channel_key,
-                                    &res.max_known_msg_id);
-
-  switch (ret)
-  {
-  case GNUNET_YES:
-  case GNUNET_NO:
-    break;
-  default:
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                _("Failed to get slave counters!\n"));
-  }
-
-  res.header.type
-    = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS_SLAVE);
+  res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
   res.header.size = htons (sizeof (res));
   res.result_code = htonl (ret);
   res.op_id = req->op_id;
-  res.max_known_msg_id = GNUNET_htonll (res.max_known_msg_id);
+  res.max_fragment_id = GNUNET_htonll (res.max_fragment_id);
+  res.max_message_id = GNUNET_htonll (res.max_message_id);
+  res.max_group_generation = GNUNET_htonll (res.max_group_generation);
+  res.max_state_message_id = GNUNET_htonll (res.max_state_message_id);
 
   GNUNET_SERVER_notification_context_add (nc, client);
   GNUNET_SERVER_notification_context_unicast (nc, client, &res.header,
@@ -607,6 +571,7 @@ handle_state_get (void *cls,
         ret = db->state_get (db->cls, &req->channel_key, n,
                              &send_state_var, &sc);
       }
+      GNUNET_free (n);
     }
   }
   switch (ret)
@@ -664,15 +629,14 @@ handle_state_get_prefix (void *cls,
 
 
 /**
- * Handle PSYCstore clients.
+ * Initialize the PSYCstore service.
  *
- * @param cls closure
- * @param server the initialized server
- * @param c configuration to use
+ * @param cls Closure.
+ * @param server The initialized server.
+ * @param c Configuration to use.
  */
 static void
-run (void *cls,
-     struct GNUNET_SERVER_Handle *server,
+run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
@@ -699,12 +663,8 @@ run (void *cls,
       GNUNET_MESSAGE_TYPE_PSYCSTORE_MESSAGE_GET_FRAGMENT,
       sizeof (struct MessageGetFragmentRequest) },
 
-    { &handle_counters_get_master, NULL,
-      GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_MASTER,
-      sizeof (struct OperationRequest) },
-
-    { &handle_counters_get_slave, NULL,
-      GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET_SLAVE,
+    { &handle_counters_get, NULL,
+      GNUNET_MESSAGE_TYPE_PSYCSTORE_COUNTERS_GET,
       sizeof (struct OperationRequest) },
 
     { &handle_state_modify, NULL,
@@ -764,7 +724,7 @@ run (void *cls,
 
 
 /**
- * The main function for the network size estimation service.
+ * The main function for the service.
  *
  * @param argc number of arguments from the command line
  * @param argv command line arguments