-fix
authorChristian Grothoff <christian@grothoff.org>
Thu, 3 May 2012 11:35:36 +0000 (11:35 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 3 May 2012 11:35:36 +0000 (11:35 +0000)
src/peerinfo-tool/gnunet-peerinfo.c
src/peerinfo/peerinfo_api.c

index d450bf748eb3bdd8f730d44388c1f1368389fe3c..de27cd276e5ec3720d878c25dbd327cd252578c8 100644 (file)
@@ -679,7 +679,7 @@ static void
 add_continuation (void *cls,
                  const char *emsg)
 {
-  ai = NULL;
+  ac = NULL;
   if (NULL != emsg)
     fprintf (stderr,
             _("Failure adding HELLO: %s\n"),
@@ -723,7 +723,7 @@ parse_hello_uri (const char *put_uri)
   {
     /* WARNING: this adds the address from URI WITHOUT verification! */
     if (GNUNET_OK == ctx.ret)    
-      ac = GNUNET_PEERINFO_add_peer (peerinfo, hello, NULL, NULL);
+      ac = GNUNET_PEERINFO_add_peer (peerinfo, hello, &add_continuation, NULL);
     else
       tt = GNUNET_SCHEDULER_add_now (&state_machine, NULL);
     GNUNET_free (hello);
index f70b8fde108c5c505da316282ed2634bc2ad08ff..5b79a17e5cf5ed43f108f705a971df26ecc82704 100644 (file)
@@ -51,6 +51,11 @@ struct GNUNET_PEERINFO_AddContext
    */
   struct GNUNET_PEERINFO_AddContext *prev;
 
+  /**
+   * Handle to the PEERINFO service.
+   */
+  struct GNUNET_PEERINFO_Handle *h;
+
   /**
    * Function to call after request has been transmitted, or NULL.
    */
@@ -420,16 +425,33 @@ GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
        "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n",
        GNUNET_i2s (&peer), hs, "HELLO");
   ac = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) + hs);
+  ac->h = h;
   ac->size = hs;
   ac->cont = cont;
   ac->cont_cls = cont_cls;
   memcpy (&ac[1], hello, hs);
-  GNUNET_CONTAINER_DLL_insert_after (h->ac_head, h->ac_tail, h->ac_tail, ac);
+  GNUNET_CONTAINER_DLL_insert_tail (h->ac_head, h->ac_tail, ac);
   trigger_transmit (h);
   return ac;
 }
 
 
+/**
+ * Cancel pending 'add' operation.  Must only be called before
+ * either 'cont' or 'GNUNET_PEERINFO_disconnect' are invoked.
+ *
+ * @param ac handle for the add operation to cancel
+ */
+void 
+GNUNET_PEERINFO_add_peer_cancel (struct GNUNET_PEERINFO_AddContext *ac)
+{
+  struct GNUNET_PEERINFO_Handle *h = ac->h;
+
+  GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
+  GNUNET_free (ac);
+}
+
+
 /**
  * Type of a function to call when we receive a message from the
  * service.  Call the iterator with the result and (if applicable)