-fix
[oweals/gnunet.git] / src / peerinfo / peerinfo_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2001, 2002, 2004, 2005, 2007, 2009, 2010, 2012 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file peerinfo/peerinfo_api.c
23  * @brief API to access peerinfo service
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_client_lib.h"
28 #include "gnunet_container_lib.h"
29 #include "gnunet_peerinfo_service.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_time_lib.h"
32 #include "peerinfo.h"
33
34 #define LOG(kind,...) GNUNET_log_from (kind, "peerinfo-api",__VA_ARGS__)
35
36
37 /**
38  * Entry in the transmission queue to PEERINFO service.  We use
39  * the same structure for queueing 'iteration' requests and
40  * actual 'add' messages.
41  */
42 struct GNUNET_PEERINFO_AddContext
43 {
44   /**
45    * This is a linked list.
46    */
47   struct GNUNET_PEERINFO_AddContext *next;
48
49   /**
50    * This is a linked list.
51    */
52   struct GNUNET_PEERINFO_AddContext *prev;
53
54   /**
55    * Handle to the PEERINFO service.
56    */
57   struct GNUNET_PEERINFO_Handle *h;
58
59   /**
60    * Function to call after request has been transmitted, or NULL.
61    */
62   GNUNET_PEERINFO_Continuation cont;
63
64   /**
65    * Closure for 'cont'.
66    */
67   void *cont_cls;
68
69   /**
70    * Number of bytes of the request message (follows after this struct).
71    */
72   size_t size;
73
74 };
75
76
77 /**
78  * Context for an iteration request.
79  */
80 struct GNUNET_PEERINFO_IteratorContext
81 {
82
83   /**
84    * Kept in a DLL.
85    */
86   struct GNUNET_PEERINFO_IteratorContext *next;
87
88   /**
89    * Kept in a DLL.
90    */
91   struct GNUNET_PEERINFO_IteratorContext *prev;
92
93   /**
94    * Handle to the PEERINFO service.
95    */
96   struct GNUNET_PEERINFO_Handle *h;
97
98   /**
99    * Function to call with the results.
100    */
101   GNUNET_PEERINFO_Processor callback;
102
103   /**
104    * Closure for 'callback'.
105    */
106   void *callback_cls;
107
108   /**
109    * Our entry in the transmission queue.
110    */
111   struct GNUNET_PEERINFO_AddContext *ac;
112
113   /**
114    * Task responsible for timeout.
115    */
116   GNUNET_SCHEDULER_TaskIdentifier timeout_task;
117
118   /**
119    * Timeout for the operation.
120    */
121   struct GNUNET_TIME_Absolute timeout;
122
123   /**
124    * Are we now receiving?
125    */
126   int in_receive;
127 };
128
129
130 /**
131  * Handle to the peerinfo service.
132  */
133 struct GNUNET_PEERINFO_Handle
134 {
135   /**
136    * Our configuration.
137    */
138   const struct GNUNET_CONFIGURATION_Handle *cfg;
139
140   /**
141    * Connection to the service.
142    */
143   struct GNUNET_CLIENT_Connection *client;
144
145   /**
146    * Head of transmission queue.
147    */
148   struct GNUNET_PEERINFO_AddContext *ac_head;
149
150   /**
151    * Tail of transmission queue.
152    */
153   struct GNUNET_PEERINFO_AddContext *ac_tail;
154
155   /**
156    * Handle for the current transmission request, or NULL if none is pending.
157    */
158   struct GNUNET_CLIENT_TransmitHandle *th;
159
160   /**
161    * Head of iterator DLL.
162    */
163   struct GNUNET_PEERINFO_IteratorContext *ic_head;
164
165   /**
166    * Tail of iterator DLL.
167    */
168   struct GNUNET_PEERINFO_IteratorContext *ic_tail;
169
170   /**
171    * ID for a reconnect task.
172    */
173   GNUNET_SCHEDULER_TaskIdentifier r_task;
174
175   /**
176    * Set to GNUNET_YES if we are currently receiving replies from the
177    * service.
178    */
179   int in_receive;
180
181 };
182
183
184 /**
185  * Connect to the peerinfo service.
186  *
187  * @param cfg configuration to use
188  * @return NULL on error (configuration related, actual connection
189  *         establishment may happen asynchronously).
190  */
191 struct GNUNET_PEERINFO_Handle *
192 GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
193 {
194   struct GNUNET_PEERINFO_Handle *h;
195
196   h = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_Handle));
197   h->client = GNUNET_CLIENT_connect ("peerinfo", cfg);
198   h->cfg = cfg;
199   return h;
200 }
201
202
203 /**
204  * Disconnect from the peerinfo service.  Note that all iterators must
205  * have completed or have been cancelled by the time this function is
206  * called (otherwise, calling this function is a serious error).
207  * Furthermore, if 'GNUNET_PEERINFO_add_peer' operations are still
208  * pending, they will be cancelled silently on disconnect.
209  *
210  * @param h handle to disconnect
211  */
212 void
213 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h)
214 {
215   struct GNUNET_PEERINFO_AddContext *ac;
216   struct GNUNET_PEERINFO_IteratorContext *ic;
217
218   while (NULL != (ic = h->ic_head))
219   {
220     GNUNET_break (GNUNET_YES == ic->in_receive);
221     ic->in_receive = GNUNET_NO;
222     GNUNET_PEERINFO_iterate_cancel (ic);
223   }
224   while (NULL != (ac = h->ac_head))
225   {
226     GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
227     if (NULL != ac->cont)
228       ac->cont (ac->cont_cls, _("aborted due to explicit disconnect request"));
229     GNUNET_free (ac);
230   }
231   if (NULL != h->th)
232   {
233     GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
234     h->th = NULL;
235   }
236   if (NULL != h->client)
237   {
238     GNUNET_CLIENT_disconnect (h->client);
239     h->client = NULL;
240   }
241   if (GNUNET_SCHEDULER_NO_TASK != h->r_task)
242   {
243     GNUNET_SCHEDULER_cancel (h->r_task);
244     h->r_task = GNUNET_SCHEDULER_NO_TASK;
245   }
246   GNUNET_free (h);
247 }
248
249
250 /**
251  * Check if we have a request pending in the transmission queue and are
252  * able to transmit it right now.  If so, schedule transmission.
253  *
254  * @param h handle to the service
255  */
256 static void
257 trigger_transmit (struct GNUNET_PEERINFO_Handle *h);
258
259
260 /**
261  * Close the existing connection to PEERINFO and reconnect.
262  *
263  * @param h handle to the service
264  */
265 static void
266 reconnect (struct GNUNET_PEERINFO_Handle *h);
267
268
269 /**
270  * Task scheduled to re-try connecting to the peerinfo service.
271  *
272  * @param cls the 'struct GNUNET_PEERINFO_Handle'
273  * @param tc scheduler context
274  */
275 static void
276 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
277 {
278   struct GNUNET_PEERINFO_Handle *h = cls;
279
280   h->r_task = GNUNET_SCHEDULER_NO_TASK;
281   reconnect (h);
282 }
283
284
285 /**
286  * Close the existing connection to PEERINFO and reconnect.
287  *
288  * @param h handle to the service
289  */
290 static void
291 reconnect (struct GNUNET_PEERINFO_Handle *h)
292 {
293   if (GNUNET_SCHEDULER_NO_TASK != h->r_task)
294   {
295     GNUNET_SCHEDULER_cancel (h->r_task);
296     h->r_task = GNUNET_SCHEDULER_NO_TASK;
297   }
298   if (NULL != h->th)
299   {
300     GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
301     h->th = NULL;
302   }
303   if (NULL != h->client)
304   {
305     GNUNET_CLIENT_disconnect (h->client);
306     h->client = NULL;
307   }
308   h->in_receive = GNUNET_NO;
309   h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg);
310   if (NULL == h->client)
311   {
312     h->r_task =
313         GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect_task,
314                                       h);
315     return;
316   }
317   trigger_transmit (h);
318 }
319
320
321 /**
322  * Transmit the request at the head of the transmission queue
323  * and trigger continuation (if any).
324  *
325  * @param cls the 'struct GNUNET_PEERINFO_Handle' (with the queue)
326  * @param size size of the buffer (0 on error)
327  * @param buf where to copy the message
328  * @return number of bytes copied to buf
329  */
330 static size_t
331 do_transmit (void *cls, size_t size, void *buf)
332 {
333   struct GNUNET_PEERINFO_Handle *h = cls;
334   struct GNUNET_PEERINFO_AddContext *ac = h->ac_head;
335   size_t ret;
336
337   h->th = NULL;
338   if (NULL == ac)
339     return 0; /* request was cancelled in the meantime */
340   if (NULL == buf)
341   {
342     /* peerinfo service died */
343     LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
344          "Failed to transmit message to `%s' service.\n", "PEERINFO");
345     GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
346     reconnect (h);
347     if (NULL != ac->cont)
348       ac->cont (ac->cont_cls, _("failed to transmit request (service down?)"));
349     GNUNET_free (ac);
350     return 0;
351   }
352   ret = ac->size;
353   if (size < ret)
354   {
355     /* change in head of queue (i.e. cancel + add), try again */
356     trigger_transmit (h);
357     return 0;
358   }
359   LOG (GNUNET_ERROR_TYPE_DEBUG,
360        "Transmitting request of size %u to `%s' service.\n", ret, "PEERINFO");
361   memcpy (buf, &ac[1], ret);
362   GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
363   trigger_transmit (h);
364   if (NULL != ac->cont)
365     ac->cont (ac->cont_cls, NULL);
366   GNUNET_free (ac);
367   return ret;
368 }
369
370
371 /**
372  * Check if we have a request pending in the transmission queue and are
373  * able to transmit it right now.  If so, schedule transmission.
374  *
375  * @param h handle to the service
376  */
377 static void
378 trigger_transmit (struct GNUNET_PEERINFO_Handle *h)
379 {
380   struct GNUNET_PEERINFO_AddContext *ac;
381
382   if (NULL == (ac = h->ac_head))
383     return; /* no requests queued */
384   if (NULL != h->th)
385     return; /* request already pending */
386   if (GNUNET_YES == h->in_receive)
387     return; /* still reading replies from last request */
388   if (NULL == h->client)
389   {
390     /* disconnected, try to reconnect */
391     reconnect (h);
392     return;
393   }
394   h->th =
395     GNUNET_CLIENT_notify_transmit_ready (h->client, ac->size,
396                                          GNUNET_TIME_UNIT_FOREVER_REL,
397                                          GNUNET_YES,
398                                          &do_transmit, h);
399 }
400
401
402 /**
403  * Add a host to the persistent list.  This method operates in
404  * semi-reliable mode: if the transmission is not completed by
405  * the time 'GNUNET_PEERINFO_disconnect' is called, it will be
406  * aborted.  Furthermore, if a second HELLO is added for the
407  * same peer before the first one was transmitted, PEERINFO may
408  * merge the two HELLOs prior to transmission to the service.
409  *
410  * @param h handle to the peerinfo service
411  * @param hello the verified (!) HELLO message
412  * @param cont continuation to call when done, NULL is allowed
413  * @param cont_cls closure for 'cont'
414  * @return handle to cancel add operation; all pending
415  *         'add' operations will be cancelled automatically
416  *        on disconnect, so it is not necessary to keep this
417  *        handle (unless 'cont' is NULL and at some point
418  *        calling 'cont' must be prevented)
419  */
420 struct GNUNET_PEERINFO_AddContext *
421 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
422                           const struct GNUNET_HELLO_Message *hello,
423                           GNUNET_PEERINFO_Continuation cont,
424                           void *cont_cls)
425 {
426   uint16_t hs = GNUNET_HELLO_size (hello);
427   struct GNUNET_PEERINFO_AddContext *ac;
428   struct GNUNET_PeerIdentity peer;
429
430   GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer));
431   LOG (GNUNET_ERROR_TYPE_DEBUG,
432        "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n",
433        GNUNET_i2s (&peer), hs, "HELLO");
434   ac = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) + hs);
435   ac->h = h;
436   ac->size = hs;
437   ac->cont = cont;
438   ac->cont_cls = cont_cls;
439   memcpy (&ac[1], hello, hs);
440   GNUNET_CONTAINER_DLL_insert_tail (h->ac_head, h->ac_tail, ac);
441   trigger_transmit (h);
442   return ac;
443 }
444
445
446 /**
447  * Cancel pending 'add' operation.  Must only be called before
448  * either 'cont' or 'GNUNET_PEERINFO_disconnect' are invoked.
449  *
450  * @param ac handle for the add operation to cancel
451  */
452 void 
453 GNUNET_PEERINFO_add_peer_cancel (struct GNUNET_PEERINFO_AddContext *ac)
454 {
455   struct GNUNET_PEERINFO_Handle *h = ac->h;
456
457   GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
458   GNUNET_free (ac);
459 }
460
461
462 /**
463  * Type of a function to call when we receive a message from the
464  * service.  Call the iterator with the result and (if applicable)
465  * continue to receive more messages or trigger processing the next
466  * event (if applicable).
467  *
468  * @param cls closure
469  * @param msg message received, NULL on timeout or fatal error
470  */
471 static void
472 peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
473 {
474   struct GNUNET_PEERINFO_IteratorContext *ic = cls;
475   struct GNUNET_PEERINFO_Handle *h = ic->h;
476   const struct InfoMessage *im;
477   const struct GNUNET_HELLO_Message *hello;
478   GNUNET_PEERINFO_Processor cb;
479   void *cb_cls;
480   uint16_t ms;
481
482   h->in_receive = GNUNET_NO;
483   ic->in_receive = GNUNET_NO;
484   cb = ic->callback;
485   cb_cls = ic->callback_cls;
486   if (NULL == msg)
487   {
488     /* peerinfo service died, signal error */
489     GNUNET_PEERINFO_iterate_cancel (ic);
490     reconnect (h);
491     if (NULL != cb)
492       cb (cb_cls, NULL, NULL,
493           _("Failed to receive response from `PEERINFO' service."));
494     return;
495   }
496   if (GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END == ntohs (msg->type))
497   {
498     /* normal end of list of peers, signal end, process next pending request */
499     LOG (GNUNET_ERROR_TYPE_DEBUG,
500          "Received end of list of peers from `%s' service\n", "PEERINFO");
501     GNUNET_PEERINFO_iterate_cancel (ic);
502     trigger_transmit (h);
503     if (NULL != cb)
504       cb (cb_cls, NULL, NULL, NULL);
505     return;
506   }
507   ms = ntohs (msg->size);
508   if ((ms < sizeof (struct InfoMessage)) ||
509       (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO))
510   {
511     /* malformed message */
512     GNUNET_break (0);
513     GNUNET_PEERINFO_iterate_cancel (ic);
514     reconnect (h);
515     if (NULL != cb)
516       cb (cb_cls, NULL, NULL,
517           _("Received invalid message from `PEERINFO' service."));
518     return;
519   }
520   im = (const struct InfoMessage *) msg;
521   GNUNET_break (0 == ntohl (im->reserved));
522   hello = NULL;
523   if (ms > sizeof (struct InfoMessage) + sizeof (struct GNUNET_MessageHeader))
524   {
525     hello = (const struct GNUNET_HELLO_Message *) &im[1];
526     if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
527     {
528       /* malformed message */
529       GNUNET_break (0);
530       GNUNET_PEERINFO_iterate_cancel (ic);
531       reconnect (h);
532       if (NULL != cb)      
533         cb (cb_cls, NULL, NULL,
534             _("Received invalid message from `PEERINFO' service."));
535       return;
536     }
537   }
538   /* normal data message */
539   LOG (GNUNET_ERROR_TYPE_DEBUG,
540        "Received %u bytes of `%s' information about peer `%s' from `%s' service\n",
541        (hello == NULL) ? 0 : (unsigned int) GNUNET_HELLO_size (hello), "HELLO",
542        GNUNET_i2s (&im->peer), "PEERINFO");
543   h->in_receive = GNUNET_YES;
544   ic->in_receive = GNUNET_YES;
545   GNUNET_CLIENT_receive (h->client, &peerinfo_handler, ic,
546                          GNUNET_TIME_absolute_get_remaining (ic->timeout));
547   if (NULL != cb)
548     cb (cb_cls, &im->peer, hello, NULL);
549 }
550
551
552 /**
553  * We've transmitted the iteration request.  Now get ready to process
554  * the results (or handle transmission error).
555  *
556  * @param cls the 'struct GNUNET_PEERINFO_IteratorContext'
557  * @param emsg error message, NULL if transmission worked
558  */
559 static void
560 iterator_start_receive (void *cls, const char *emsg)
561 {
562   struct GNUNET_PEERINFO_IteratorContext *ic = cls;
563   struct GNUNET_PEERINFO_Handle *h = ic->h;
564   GNUNET_PEERINFO_Processor cb;
565   void *cb_cls;
566
567   ic->ac = NULL;
568   if (NULL != emsg)
569   {
570     cb = ic->callback;
571     cb_cls = ic->callback_cls;
572     GNUNET_PEERINFO_iterate_cancel (ic);
573     reconnect (h);
574     if (NULL != cb)
575       cb (cb_cls, NULL, NULL, emsg);
576     return;
577   }
578   LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for response from `%s' service.\n",
579        "PEERINFO");
580   ic->in_receive = GNUNET_YES;
581   if (GNUNET_NO == h->in_receive)
582   {
583     h->in_receive = GNUNET_YES;
584     GNUNET_CLIENT_receive (h->client, &peerinfo_handler, ic,
585                            GNUNET_TIME_absolute_get_remaining (ic->timeout));
586   }
587 }
588
589
590 /**
591  * Peerinfo iteration request has timed out.
592  *
593  * @param cls the 'struct GNUNET_PEERINFO_IteratorContext*'
594  * @param tc scheduler context
595  */
596 static void
597 signal_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
598 {
599   struct GNUNET_PEERINFO_IteratorContext *ic = cls;
600   GNUNET_PEERINFO_Processor cb;
601   void *cb_cls;
602
603   ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
604   cb = ic->callback;
605   cb_cls = ic->callback_cls;
606   GNUNET_PEERINFO_iterate_cancel (ic);
607   if (NULL != cb)
608     cb (cb_cls, NULL, NULL,
609         _("Timeout transmitting iteration request to `PEERINFO' service."));
610 }
611
612
613 /**
614  * Call a method for each known matching host and change its trust
615  * value.  The callback method will be invoked once for each matching
616  * host and then finally once with a NULL pointer.  After that final
617  * invocation, the iterator context must no longer be used.
618  *
619  * Instead of calling this function with 'peer == NULL' it is often
620  * better to use 'GNUNET_PEERINFO_notify'.
621  *
622  * @param h handle to the peerinfo service
623  * @param peer restrict iteration to this peer only (can be NULL)
624  * @param timeout how long to wait until timing out
625  * @param callback the method to call for each peer
626  * @param callback_cls closure for callback
627  * @return iterator context
628  */
629 struct GNUNET_PEERINFO_IteratorContext *
630 GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
631                          const struct GNUNET_PeerIdentity *peer,
632                          struct GNUNET_TIME_Relative timeout,
633                          GNUNET_PEERINFO_Processor callback, void *callback_cls)
634 {
635   struct GNUNET_MessageHeader *lapm;
636   struct ListPeerMessage *lpm;
637   struct GNUNET_PEERINFO_IteratorContext *ic;
638   struct GNUNET_PEERINFO_AddContext *ac;
639
640   if (NULL == peer)
641   {
642     LOG (GNUNET_ERROR_TYPE_DEBUG,
643          "Requesting list of peers from PEERINFO service\n");
644     ac =
645         GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) +
646                        sizeof (struct GNUNET_MessageHeader));
647     ac->size = sizeof (struct GNUNET_MessageHeader);
648     lapm = (struct GNUNET_MessageHeader *) &ac[1];
649     lapm->size = htons (sizeof (struct GNUNET_MessageHeader));
650     lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
651   }
652   else
653   {
654     LOG (GNUNET_ERROR_TYPE_DEBUG,
655          "Requesting information on peer `%4s' from PEERINFO service\n",
656          GNUNET_i2s (peer));
657     ac =
658         GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) +
659                        sizeof (struct ListPeerMessage));
660     ac->size = sizeof (struct ListPeerMessage);
661     lpm = (struct ListPeerMessage *) &ac[1];
662     lpm->header.size = htons (sizeof (struct ListPeerMessage));
663     lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
664     memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
665   }
666   ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext));
667   ic->h = h;
668   ic->ac = ac;
669   ic->callback = callback;
670   ic->callback_cls = callback_cls;
671   ic->timeout = GNUNET_TIME_relative_to_absolute (timeout);
672   ic->timeout_task =
673       GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic);
674   ac->cont = &iterator_start_receive;
675   ac->cont_cls = ic;
676   GNUNET_CONTAINER_DLL_insert_after (h->ac_head, h->ac_tail, h->ac_tail, ac);
677   GNUNET_CONTAINER_DLL_insert (h->ic_head,
678                                h->ic_tail,
679                                ic);
680   trigger_transmit (h);
681   return ic;
682 }
683
684
685 /**
686  * Cancel an iteration over peer information.
687  *
688  * @param ic context of the iterator to cancel
689  */
690 void
691 GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
692 {
693   struct GNUNET_PEERINFO_Handle *h;
694
695   h = ic->h;
696   GNUNET_CONTAINER_DLL_remove (h->ic_head,
697                                h->ic_tail,
698                                ic);
699   if (GNUNET_SCHEDULER_NO_TASK != ic->timeout_task)
700   {
701     GNUNET_SCHEDULER_cancel (ic->timeout_task);
702     ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
703   }
704   ic->callback = NULL;
705   if (GNUNET_YES == ic->in_receive)
706     return;                     /* need to finish processing */
707   if (NULL != ic->ac)
708   {
709     GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ic->ac);
710     GNUNET_free (ic->ac);
711   }
712   GNUNET_free (ic);
713 }
714
715
716 /* end of peerinfo_api.c */