gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r20074 - gnunet/src/namestore


From: gnunet
Subject: [GNUnet-SVN] r20074 - gnunet/src/namestore
Date: Mon, 27 Feb 2012 17:03:12 +0100

Author: wachs
Date: 2012-02-27 17:03:12 +0100 (Mon, 27 Feb 2012)
New Revision: 20074

Modified:
   gnunet/src/namestore/gnunet-service-namestore.c
   gnunet/src/namestore/namestore.h
   gnunet/src/namestore/namestore_api.c
Log:
- more communication


Modified: gnunet/src/namestore/gnunet-service-namestore.c
===================================================================
--- gnunet/src/namestore/gnunet-service-namestore.c     2012-02-27 15:24:26 UTC 
(rev 20073)
+++ gnunet/src/namestore/gnunet-service-namestore.c     2012-02-27 16:03:12 UTC 
(rev 20074)
@@ -437,6 +437,145 @@
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
+
+static void handle_record_create (void *cls,
+                          struct GNUNET_SERVER_Client * client,
+                          const struct GNUNET_MessageHeader * message)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 
"NAMESTORE_RECORD_CREATE");
+  struct GNUNET_NAMESTORE_Client *nc;
+  struct RecordCreateResponseMessage rcr_msg;
+  size_t name_len;
+  size_t msg_size;
+  size_t msg_size_exp;
+  uint32_t id = 0;
+
+  int res = GNUNET_SYSERR;
+
+  if (ntohs (message->size) < sizeof (struct RecordCreateMessage))
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  nc = client_lookup(client);
+  if (nc == NULL)
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  struct RecordCreateMessage * rp_msg = (struct RecordCreateMessage *) message;
+  id = ntohl (rp_msg->op_id);
+  name_len = ntohs (rp_msg->name_len);
+  msg_size = ntohs (message->size);
+  msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + sizeof 
(struct GNUNET_NAMESTORE_RecordData);
+
+  if (msg_size != msg_size_exp)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message 
size is %u \n", msg_size_exp, msg_size);
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+
+  if ((name_len == 0) || (name_len > 256))
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  /* DO WORK HERE */
+
+  /* Send response */
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", 
"RECORD_CREATE_RESPONSE");
+  rcr_msg.header.type = htons 
(GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE);
+  rcr_msg.op_id = rp_msg->op_id;
+  rcr_msg.header.size = htons (sizeof (struct RecordCreateResponseMessage));
+  if (GNUNET_OK == res)
+    rcr_msg.op_result = htons (GNUNET_OK);
+  else
+    rcr_msg.op_result = htons (GNUNET_NO);
+  GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct 
GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO);
+
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+static void handle_record_remove (void *cls,
+                          struct GNUNET_SERVER_Client * client,
+                          const struct GNUNET_MessageHeader * message)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 
"NAMESTORE_RECORD_REMOVE");
+  struct GNUNET_NAMESTORE_Client *nc;
+  struct RecordRemoveResponseMessage rrr_msg;
+  size_t name_len;
+  size_t msg_size;
+  size_t msg_size_exp;
+  uint32_t id = 0;
+
+  int res = GNUNET_SYSERR;
+
+  if (ntohs (message->size) < sizeof (struct RecordRemoveMessage))
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  nc = client_lookup(client);
+  if (nc == NULL)
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  struct RecordRemoveMessage * rp_msg = (struct RecordRemoveMessage *) message;
+  id = ntohl (rp_msg->op_id);
+  name_len = ntohs (rp_msg->name_len);
+  msg_size = ntohs (message->size);
+  msg_size_exp = sizeof (struct RecordRemoveMessage) + name_len + sizeof 
(struct GNUNET_NAMESTORE_RecordData);
+
+  if (msg_size != msg_size_exp)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message 
size is %u \n", msg_size_exp, msg_size);
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+
+  if ((name_len == 0) || (name_len > 256))
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    return;
+  }
+
+  /* DO WORK HERE */
+
+  /* Send response */
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", 
"RECORD_REMOVE_RESPONSE");
+  rrr_msg.header.type = htons 
(GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE);
+  rrr_msg.op_id = rp_msg->op_id;
+  rrr_msg.header.size = htons (sizeof (struct RecordRemoveResponseMessage));
+  if (GNUNET_OK == res)
+    rrr_msg.op_result = htons (GNUNET_OK);
+  else
+    rrr_msg.op_result = htons (GNUNET_NO);
+  GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct 
GNUNET_MessageHeader *) &rrr_msg, GNUNET_NO);
+
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
+
 /**
  * Process template requests.
  *
@@ -457,8 +596,12 @@
      GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)},
     {&handle_lookup_name, NULL,
      GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0},
-     {&handle_record_put, NULL,
-      GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0},
+    {&handle_record_put, NULL,
+    GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0},
+    {&handle_record_create, NULL,
+     GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0},
+    {&handle_record_remove, NULL,
+     GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0},
     {NULL, NULL, 0, 0}
   };
 

Modified: gnunet/src/namestore/namestore.h
===================================================================
--- gnunet/src/namestore/namestore.h    2012-02-27 15:24:26 UTC (rev 20073)
+++ gnunet/src/namestore/namestore.h    2012-02-27 16:03:12 UTC (rev 20074)
@@ -33,7 +33,12 @@
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE 432
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT 433
 #define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE 434
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE 435
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE 436
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE 437
+#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE 438
 
+
 GNUNET_NETWORK_STRUCT_BEGIN
 /**
  * Connect to namestore service
@@ -160,15 +165,41 @@
 GNUNET_NETWORK_STRUCT_END
 
 /**
+ * Put a record to the namestore response
+ */
+GNUNET_NETWORK_STRUCT_BEGIN
+struct RecordPutResponseMessage
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Operation ID in NBO
+   */
+  uint32_t op_id;
+
+  /* Contenct starts here */
+
+  /**
+   *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
+   */
+  uint16_t op_result;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
+/**
  * Put a record to the namestore
  * Memory layout:
  * [struct RecordPutMessage][struct 
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct 
GNUNET_NAMESTORE_RecordData]
  */
 GNUNET_NETWORK_STRUCT_BEGIN
-struct RecordPutResponseMessage
+struct RecordCreateMessage
 {
   /**
-   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE
    */
   struct GNUNET_MessageHeader header;
 
@@ -179,14 +210,93 @@
 
   /* Contenct starts here */
 
+  /* name length */
+  uint16_t name_len;
+
+  struct GNUNET_CRYPTO_RsaSignature signature;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
+/**
+ * Create a record to the namestore response
+ * Memory layout:
+ */
+GNUNET_NETWORK_STRUCT_BEGIN
+struct RecordCreateResponseMessage
+{
   /**
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Operation ID in NBO
+   */
+  uint32_t op_id;
+
+  /* Contenct starts here */
+
+  /**
    *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
    */
   uint16_t op_result;
 };
 GNUNET_NETWORK_STRUCT_END
 
+/**
+ * Remove a record from the namestore
+ * Memory layout:
+ * [struct RecordRemoveMessage][char *name][struct GNUNET_NAMESTORE_RecordData]
+ */
+GNUNET_NETWORK_STRUCT_BEGIN
+struct RecordRemoveMessage
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE
+   */
+  struct GNUNET_MessageHeader header;
 
+  /**
+   * Operation ID in NBO
+   */
+  uint32_t op_id;
 
+  /* Contenct starts here */
+
+  /* name length */
+  uint16_t name_len;
+
+  struct GNUNET_CRYPTO_RsaSignature signature;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
+/**
+ * Remove a record from the namestore response
+ */
+GNUNET_NETWORK_STRUCT_BEGIN
+struct RecordRemoveResponseMessage
+{
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * Operation ID in NBO
+   */
+  uint32_t op_id;
+
+  /* Contenct starts here */
+
+  /**
+   *  name length: GNUNET_NO (0) on error, GNUNET_OK (1) on success
+   */
+  uint16_t op_result;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
 /* end of namestore.h */
 #endif

Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c        2012-02-27 15:24:26 UTC (rev 
20073)
+++ gnunet/src/namestore/namestore_api.c        2012-02-27 16:03:12 UTC (rev 
20074)
@@ -285,7 +285,47 @@
     return;
   }
 
+  /* Operation done, remove */
+  GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
 
+  GNUNET_free (qe);
+}
+
+
+static void
+handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
+                             struct RecordCreateResponseMessage* msg,
+                             size_t size)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
+              "RECORD_CREATE_RESPONSE");
+
+  struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
+  int res = GNUNET_OK;
+
+  if (ntohs (msg->op_result) == GNUNET_OK)
+  {
+    res = GNUNET_OK;
+    if (qe->cont != NULL)
+    {
+      qe->cont (qe->cont_cls, res, _("Namestore added record successfully"));
+    }
+
+  }
+  else if (ntohs (msg->op_result) == GNUNET_NO)
+  {
+    res = GNUNET_SYSERR;
+    if (qe->cont != NULL)
+    {
+      qe->cont (qe->cont_cls, res, _("Namestore failed to add record"));
+    }
+  }
+  else
+  {
+    GNUNET_break_op (0);
+    return;
+  }
+
   /* Operation done, remove */
   GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
 
@@ -373,6 +413,14 @@
         }
         handle_record_put_response (qe, (struct RecordPutResponseMessage *) 
msg, size);
       break;
+    case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE:
+        if (size != sizeof (struct RecordCreateResponseMessage))
+        {
+          GNUNET_break_op (0);
+          break;
+        }
+        handle_record_create_response (qe, (struct RecordCreateResponseMessage 
*) msg, size);
+      break;
     default:
       GNUNET_break_op (0);
       break;
@@ -549,6 +597,13 @@
 }
 
 
+/**
+ * Disconnect from the namestore service (and free associated
+ * resources).
+ *
+ * @param h handle to the namestore
+ * @param drop set to GNUNET_YES to delete all data in namestore (!)
+ */
 void
 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h, int drop)
 {
@@ -667,12 +722,6 @@
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s' 
with size %u\n", "NAMESTORE_RECORD_PUT", name, msg_size);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CALC: %u %u %u %u\n",
-      sizeof (struct RecordPutMessage),
-      sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
-      name_len,
-      rd_count * (sizeof (struct GNUNET_NAMESTORE_RecordData)));
-
   GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe);
   do_transmit(h);
 
@@ -724,21 +773,44 @@
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   struct PendingMessage *pe;
+  struct GNUNET_NAMESTORE_RecordData * rd_tmp;
+  char * name_tmp;
   size_t msg_size = 0;
+  size_t name_len = 0;
+  uint32_t id = 0;
 
   GNUNET_assert (NULL != h);
 
+  id = get_op_id(h);
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
   qe->nsh = h;
   qe->cont = cont;
   qe->cont_cls = cont_cls;
-  get_op_id(h);
+  qe->op_id = id;
 
   /* set msg_size*/
-  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+  struct RecordCreateMessage * msg;
+  msg_size = sizeof (struct RecordCreateMessage) + name_len + sizeof (struct 
GNUNET_NAMESTORE_RecordData);
 
   /* create msg here */
+  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+  pe->size = msg_size;
+  pe->is_init = GNUNET_NO;
+  msg = (struct RecordCreateMessage *) &pe[1];
 
+  name_tmp = (char *) &msg[1];
+  rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len];
+
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE);
+  msg->header.size = htons (msg_size);
+  msg->op_id = htonl (id);
+  //msg->signature = *signature;
+  msg->name_len = htons (name_len);
+  memcpy (name_tmp, name, name_len);
+  memcpy (rd_tmp, rd, sizeof (struct GNUNET_NAMESTORE_RecordData));
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s' 
with size %u\n", "NAMESTORE_RECORD_CREATE", name, msg_size);
+
   GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe);
   do_transmit(h);
   return qe;
@@ -770,38 +842,46 @@
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   struct PendingMessage *pe;
+  struct GNUNET_NAMESTORE_RecordData * rd_tmp;
+  char * name_tmp;
   size_t msg_size = 0;
+  size_t name_len = 0;
+  uint32_t id = 0;
 
   GNUNET_assert (NULL != h);
 
+  id = get_op_id(h);
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
   qe->nsh = h;
   qe->cont = cont;
   qe->cont_cls = cont_cls;
-  get_op_id(h);
+  qe->op_id = id;
 
   /* set msg_size*/
-  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+  struct RecordRemoveMessage * msg;
+  msg_size = sizeof (struct RecordRemoveMessage) + name_len + sizeof (struct 
GNUNET_NAMESTORE_RecordData);
 
   /* create msg here */
+  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+  pe->size = msg_size;
+  pe->is_init = GNUNET_NO;
+  msg = (struct RecordRemoveMessage *) &pe[1];
 
+  name_tmp = (char *) &msg[1];
+  rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len];
+
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE);
+  msg->header.size = htons (msg_size);
+  msg->op_id = htonl (id);
+  //msg->signature = *signature;
+  msg->name_len = htons (name_len);
+  memcpy (name_tmp, name, name_len);
+  memcpy (rd_tmp, rd, sizeof (struct GNUNET_NAMESTORE_RecordData));
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s' 
with size %u\n", "NAMESTORE_RECORD_REMOVE", name, msg_size);
+
   GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe);
   do_transmit(h);
-
-#if 0
-  struct GNUNET_NAMESTORE_SimpleRecord *iter;
-  for (iter=h->records_head; iter != NULL; iter=iter->next)
-  {
-    if (strcmp ( iter->name, name ) &&
-        iter->record_type == record_type &&
-        GNUNET_CRYPTO_hash_cmp (iter->zone, zone))
-      break;
-  }
-  if (iter)
-    GNUNET_CONTAINER_DLL_remove(h->records_head,
-                                h->records_tail,
-                                iter);
-#endif
   return qe;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]