From 5fed535a3e841e0c317506db8a698b65a4b4cf28 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 3 May 2012 11:35:36 +0000 Subject: [PATCH] -fix --- src/peerinfo-tool/gnunet-peerinfo.c | 4 ++-- src/peerinfo/peerinfo_api.c | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index d450bf748..de27cd276 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c @@ -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); diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index f70b8fde1..5b79a17e5 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c @@ -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) -- 2.25.1