- changes
[oweals/gnunet.git] / src / namestore / namestore_api.c
index 53235de6afa50e47ee6441eefa73b67d322a43e9..28f304d082e16ef473fba2f959a9eee9ff2e501f 100644 (file)
@@ -146,6 +146,45 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *nsh);
 static void
 do_transmit (struct GNUNET_NAMESTORE_Handle *nsh);
 
+
+/**
+ * Type of a function to call when we receive a message
+ * from the service.
+ *
+ * @param cls the 'struct GNUNET_NAMESTORE_SchedulingHandle'
+ * @param msg message received, NULL on timeout or fatal error
+ */
+static void
+process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
+{
+  struct GNUNET_NAMESTORE_Handle *nsh = cls;
+  uint16_t size;
+  uint16_t type;
+
+  if (NULL == msg)
+  {
+    force_reconnect (nsh);
+    return;
+  }
+
+  size = ntohs (msg->size);
+  type = ntohs (msg->type);
+
+  switch (type) {
+    case GNUNET_MESSAGE_TYPE_TEST:
+      /* handle message here */
+      break;
+    default:
+      break;
+  }
+
+  GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
+                         GNUNET_TIME_UNIT_FOREVER_REL);
+
+  if (GNUNET_YES == nsh->reconnect)
+    force_reconnect (nsh);
+}
+
 /**
  * We can now transmit a message to NAMESTORE. Do it.
  *
@@ -177,7 +216,7 @@ transmit_message_to_namestore (void *cls, size_t size, void *buf)
     size -= p->size;
     GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p);
     if (GNUNET_YES == p->is_init)
-      GNUNET_CLIENT_receive (nsh->client,/* &process_namestore_message*/ NULL, nsh,
+      GNUNET_CLIENT_receive (nsh->client, &process_namestore_message, nsh,
                              GNUNET_TIME_UNIT_FOREVER_REL);
     GNUNET_free (p);
   }
@@ -267,8 +306,8 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *nsh)
   nsh->reconnect = GNUNET_NO;
   GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO);
   nsh->client = NULL;
-  nsh->reconnect_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
+  nsh->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                    &reconnect_task,
                                     nsh);
 }
 
@@ -287,7 +326,7 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 
   nsh = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle));
   nsh->cfg = cfg;
-  nsh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, nsh);
+  nsh->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect_task, nsh);
   return nsh;
 }
 
@@ -298,9 +337,27 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
  * @param handle handle of the NAMESTORE connection to stop
  */
 void
-GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *handle, int drop)
+GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *nsh, int drop)
 {
-  GNUNET_free(handle);
+  struct PendingMessage *p;
+
+  while (NULL != (p = nsh->pending_head))
+  {
+    GNUNET_CONTAINER_DLL_remove (nsh->pending_head, nsh->pending_tail, p);
+    GNUNET_free (p);
+  }
+  if (NULL != nsh->client)
+  {
+    GNUNET_CLIENT_disconnect (nsh->client, GNUNET_NO);
+    nsh->client = NULL;
+  }
+  if (GNUNET_SCHEDULER_NO_TASK != nsh->reconnect_task)
+  {
+    GNUNET_SCHEDULER_cancel (nsh->reconnect_task);
+    nsh->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  }
+  GNUNET_free(nsh);
+  nsh = NULL;
 }
 
 /**
@@ -384,8 +441,7 @@ GNUNET_NAMESTORE_stree_start (struct GNUNET_NAMESTORE_Handle *h,
  * @param h handle to the namestore
  * @param zone_key public key of the zone
  * @param loc location in the B-tree
- * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1), NULL for root
- * @param top_sig signature at the top, NULL if 'loc.depth > 0'
+ * @param ploc parent's location in the B-tree (must have depth = loc.depth - 1)
  * @param num_entries number of entries at this node in the B-tree
  * @param entries the 'num_entries' entries to store (hashes over the
  *                records)
@@ -398,7 +454,6 @@ GNUNET_NAMESTORE_stree_put (struct GNUNET_NAMESTORE_Handle *h,
                             const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key,
                             const struct GNUNET_NAMESTORE_SignatureLocation *loc,
                             const struct GNUNET_NAMESTORE_SignatureLocation *ploc,
-                            const struct GNUNET_CRYPTO_RsaSignature *sig,
                             unsigned int num_entries,
                             const GNUNET_HashCode *entries,
                             GNUNET_NAMESTORE_ContinuationWithStatus cont,