- changes
authorMatthias Wachs <wachs@net.in.tum.de>
Fri, 24 Feb 2012 10:57:17 +0000 (10:57 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Fri, 24 Feb 2012 10:57:17 +0000 (10:57 +0000)
src/namestore/gnunet-service-namestore.c
src/namestore/namestore_api.c

index 59126ba6a78b7172dd26276e4973a5260d5ee679..000243e3467ad19bb5b9da578701136ab4853316 100644 (file)
 #include "gnunet_namestore_plugin.h"
 #include "namestore.h"
 
+
+
+/**
+ * A namestore operation.
+ */
+struct GNUNET_NAMESTORE_Operation
+{
+  struct GNUNET_NAMESTORE_Operation *next;
+  struct GNUNET_NAMESTORE_Operation *prev;
+
+  uint64_t op_id;
+
+  char *data; /*stub data pointer*/
+};
+
+
+/**
+ * A namestore client
+ */
+struct GNUNET_NAMESTORE_Client
+{
+  struct GNUNET_NAMESTORE_Client *next;
+  struct GNUNET_NAMESTORE_Client *prev;
+
+  struct GNUNET_SERVER_Client * client;
+
+  struct GNUNET_NAMESTORE_Operation *op_head;
+  struct GNUNET_NAMESTORE_Operation *op_tail;
+};
+
+
+
 /**
  * Configuration handle.
  */
@@ -39,6 +71,10 @@ static struct GNUNET_NAMESTORE_PluginFunctions *GSN_database;
 
 static char *db_lib_name;
 
+static struct GNUNET_NAMESTORE_Client *client_head;
+static struct GNUNET_NAMESTORE_Client *client_tail;
+
+
 /**
  * Task run during shutdown.
  *
@@ -50,6 +86,21 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping namestore service\n");
 
+  struct GNUNET_NAMESTORE_Operation * no;
+  struct GNUNET_NAMESTORE_Client * nc;
+
+  for (nc = client_head; nc != NULL; nc = nc->next)
+  {
+    for (no = nc->op_head; no != NULL; no = no->next)
+    {
+      GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
+      GNUNET_free (no);
+    }
+  }
+
+  GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
+  GNUNET_free (nc);
+
   GNUNET_break (NULL == GNUNET_PLUGIN_unload (db_lib_name, GSN_database));
   GNUNET_free (db_lib_name);
 }
@@ -64,8 +115,29 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
 {
-  if (NULL != client)
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client);
+  struct GNUNET_NAMESTORE_Operation * no;
+  struct GNUNET_NAMESTORE_Client * nc;
+  if (NULL == client)
+    return;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected \n", client);
+
+  for (nc = client_head; nc != NULL; nc = nc->next)
+  {
+    if (client == nc->client)
+      break;
+  }
+  if (NULL == client)
+    return;
+
+  for (no = nc->op_head; no != NULL; no = no->next)
+  {
+    GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no);
+    GNUNET_free (no);
+  }
+
+  GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc);
+  GNUNET_free (nc);
 }
 
 static void handle_start (void *cls,
@@ -73,6 +145,12 @@ static void handle_start (void *cls,
                           const struct GNUNET_MessageHeader * message)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n");
+
+  struct GNUNET_NAMESTORE_Client * nc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Client));
+  nc->client = client;
+
+  GNUNET_CONTAINER_DLL_insert(client_head, client_tail, nc);
+
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
index ff3ae0dd1eeea0b1e000be757148f0c8a3b1d480..af39a834c6e8867098a98170c8f4d0173ccb9eea 100644 (file)
@@ -45,6 +45,12 @@ struct GNUNET_NAMESTORE_QueueEntry
 
   uint64_t op_id;
 
+  GNUNET_NAMESTORE_ContinuationWithStatus cont;
+  void *cont_cls;
+
+  GNUNET_NAMESTORE_RecordProcessor proc;
+  void *proc_cls;
+
   char *data; /*stub data pointer*/
 };
 
@@ -452,7 +458,12 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   struct PendingMessage *pe;
   size_t msg_size = 0;
+
+  GNUNET_assert (NULL != h);
+
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+  qe->cont = cont;
+  qe->cont_cls = cont_cls;
   enqeue_namestore_operation(h, qe);
 
   /* set msg_size*/
@@ -520,7 +531,25 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
                                GNUNET_NAMESTORE_ContinuationWithStatus cont,
                                void *cont_cls)
 {
-  return NULL;
+  struct GNUNET_NAMESTORE_QueueEntry *qe;
+  struct PendingMessage *pe;
+  size_t msg_size = 0;
+
+  GNUNET_assert (NULL != h);
+
+  qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+  qe->cont = cont;
+  qe->cont_cls = cont_cls;
+  enqeue_namestore_operation(h, qe);
+
+  /* set msg_size*/
+  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+
+  /* create msg here */
+
+  GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe);
+  do_transmit(h);
+  return qe;
 }
 
 
@@ -548,7 +577,24 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
                                void *cont_cls)
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
+  struct PendingMessage *pe;
+  size_t msg_size = 0;
+
+  GNUNET_assert (NULL != h);
+
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+  qe->cont = cont;
+  qe->cont_cls = cont_cls;
+  enqeue_namestore_operation(h, qe);
+
+  /* set msg_size*/
+  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+
+  /* create msg here */
+
+  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)
@@ -589,7 +635,33 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
                              GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls)
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
+  struct PendingMessage *pe;
+  size_t msg_size = 0;
+
+  GNUNET_assert (NULL != h);
+
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+  qe->proc = proc;
+  qe->proc_cls = proc_cls;
+  enqeue_namestore_operation(h, qe);
+
+  /* set msg_size*/
+  msg_size = sizeof (struct LookupNameMessage);
+  pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
+
+  /* create msg here */
+
+  struct LookupNameMessage * msg;
+  pe->size = msg_size;
+  pe->is_init = GNUNET_NO;
+  msg = (struct LookupNameMessage *) &pe[1];
+  msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME);
+  msg->header.size = htons (msg_size);
+
+  /* create msg done */
+
+  GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe);
+  do_transmit(h);
 
 #if 0
   struct GNUNET_NAMESTORE_SimpleRecord *iter;
@@ -606,20 +678,7 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
        GNUNET_TIME_absolute_get_forever(), 0, NULL, 0, NULL); /*TERMINATE*/
 #endif
 
-  GNUNET_assert (NULL != h);
 
-  struct PendingMessage * p;
-  struct LookupNameMessage * msg;
-  size_t msg_len = sizeof (struct LookupNameMessage);
-
-  p = GNUNET_malloc (sizeof (struct PendingMessage) + msg_len);
-  p->size = msg_len;
-  p->is_init = GNUNET_NO;
-  msg = (struct LookupNameMessage *) &p[1];
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME);
-  msg->header.size = htons (msg_len);
-  GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, p);
-  do_transmit (h);
 
   return qe;
 }