gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r19999 - gnunet/src/namestore
Date: Fri, 24 Feb 2012 10:40:02 +0100

Author: wachs
Date: 2012-02-24 10:40:02 +0100 (Fri, 24 Feb 2012)
New Revision: 19999

Modified:
   gnunet/src/namestore/namestore_api.c
   gnunet/src/namestore/test_namestore_api.c
Log:
- operation id for api


Modified: gnunet/src/namestore/namestore_api.c
===================================================================
--- gnunet/src/namestore/namestore_api.c        2012-02-24 06:54:24 UTC (rev 
19998)
+++ gnunet/src/namestore/namestore_api.c        2012-02-24 09:40:02 UTC (rev 
19999)
@@ -40,6 +40,11 @@
  */
 struct GNUNET_NAMESTORE_QueueEntry
 {
+  struct GNUNET_NAMESTORE_QueueEntry *next;
+  struct GNUNET_NAMESTORE_QueueEntry *prev;
+
+  uint64_t op_id;
+
   char *data; /*stub data pointer*/
 };
 
@@ -110,6 +115,16 @@
    * Should we reconnect to service due to some serious error?
    */
   int reconnect;
+
+
+  /**
+   * Pending namestore operations
+   */
+
+  struct GNUNET_NAMESTORE_QueueEntry * op_head;
+  struct GNUNET_NAMESTORE_QueueEntry * op_tail;
+
+  uint64_t op_id;
 };
 
 struct GNUNET_NAMESTORE_SimpleRecord
@@ -153,8 +168,10 @@
 process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_NAMESTORE_Handle *nsh = cls;
+  struct GNUNET_NAMESTORE_QueueEntry *qe;
   uint16_t size;
   uint16_t type;
+  uint64_t op_id = UINT64_MAX;
 
   if (NULL == msg)
   {
@@ -165,6 +182,27 @@
   size = ntohs (msg->size);
   type = ntohs (msg->type);
 
+  /* find matching operation */
+  if (op_id > nsh->op_id)
+  {
+    GNUNET_break_op (0);
+    GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
+                           GNUNET_TIME_UNIT_FOREVER_REL);
+    return;
+  }
+  for (qe = nsh->op_head; qe != NULL; qe = qe->next)
+  {
+    if (qe->op_id == op_id)
+      break;
+  }
+  if (qe == NULL)
+  {
+    GNUNET_break_op (0);
+    GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
+                           GNUNET_TIME_UNIT_FOREVER_REL);
+    return;
+  }
+
   switch (type) {
     case GNUNET_MESSAGE_TYPE_TEST:
       /* handle message here */
@@ -318,8 +356,14 @@
                                     nsh);
 }
 
+static void
+enqeue_namestore_operation (struct GNUNET_NAMESTORE_Handle *nsh, struct 
GNUNET_NAMESTORE_QueueEntry *qe)
+{
+  qe->op_id = nsh->op_id;
+  nsh->op_id ++;
+  GNUNET_CONTAINER_DLL_insert(nsh->op_head, nsh->op_tail, qe);
+}
 
-
 /**
  * Initialize the connection with the NAMESTORE service.
  *
@@ -334,10 +378,10 @@
   nsh = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle));
   nsh->cfg = cfg;
   nsh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect_task, nsh);
+  nsh->op_id = 0;
   return nsh;
 }
 
-
 /**
  * Shutdown connection with the NAMESTORE service.
  *
@@ -347,12 +391,20 @@
 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *nsh, int drop)
 {
   struct PendingMessage *p;
+  struct GNUNET_NAMESTORE_QueueEntry *q;
 
   while (NULL != (p = nsh->pending_head))
   {
     GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p);
     GNUNET_free (p);
   }
+
+  while (NULL != (q = nsh->op_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (nsh->op_head, nsh->op_tail, q);
+    GNUNET_free (q);
+  }
+
   if (NULL != nsh->client)
   {
     GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO);
@@ -398,7 +450,19 @@
                             void *cont_cls)
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
+  struct PendingMessage *pe;
+  size_t msg_size = 0;
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+  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 *sr;
   sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord));
@@ -526,6 +590,7 @@
 {
   struct GNUNET_NAMESTORE_QueueEntry *qe;
   qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
+
 #if 0
   struct GNUNET_NAMESTORE_SimpleRecord *iter;
   for (iter=h->records_head; iter != NULL; iter=iter->next)

Modified: gnunet/src/namestore/test_namestore_api.c
===================================================================
--- gnunet/src/namestore/test_namestore_api.c   2012-02-24 06:54:24 UTC (rev 
19998)
+++ gnunet/src/namestore/test_namestore_api.c   2012-02-24 09:40:02 UTC (rev 
19999)
@@ -82,7 +82,7 @@
   res = 1;
 }
 
-
+/*
 static void
 end (void)
 {
@@ -102,6 +102,7 @@
 
   res = 0;
 }
+*/
 
 
 static void
@@ -116,7 +117,7 @@
   nsh = GNUNET_NAMESTORE_connect (cfg);
   GNUNET_break (NULL != nsh);
 
-  GNUNET_NAMESTORE_lookup_name (nsh, NULL, NULL, 0, NULL, NULL);
+  //GNUNET_NAMESTORE_lookup_name (nsh, NULL, NULL, 0, NULL, NULL);
 
   //stop_arm ();
   //end ();




reply via email to

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