2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file core/core_api.c
23 * @brief core service; this is the main API for encrypted P2P
25 * @author Christian Grothoff
28 * - implement atsi parsing and passing
31 #include "gnunet_constants.h"
32 #include "gnunet_core_service.h"
37 * Information we track for each peer.
43 * We generally do NOT keep peer records in a DLL; this
44 * DLL is only used IF this peer's 'pending_head' message
45 * is ready for transmission.
47 struct PeerRecord *prev;
50 * We generally do NOT keep peer records in a DLL; this
51 * DLL is only used IF this peer's 'pending_head' message
52 * is ready for transmission.
54 struct PeerRecord *next;
57 * Peer the record is about.
59 struct GNUNET_PeerIdentity peer;
62 * Corresponding core handle.
64 struct GNUNET_CORE_Handle *ch;
67 * Head of doubly-linked list of pending requests.
68 * Requests are sorted by deadline *except* for HEAD,
69 * which is only modified upon transmission to core.
71 struct GNUNET_CORE_TransmitHandle *pending_head;
74 * Tail of doubly-linked list of pending requests.
76 struct GNUNET_CORE_TransmitHandle *pending_tail;
79 * Pending callback waiting for peer information, or NULL for none.
81 GNUNET_CORE_PeerConfigurationInfoCallback pcic;
89 * Request information ID for the given pcic (needed in case a
90 * request is cancelled after being submitted to core and a new
91 * one is generated; in this case, we need to avoid matching the
92 * reply to the first (cancelled) request to the second request).
97 * ID of timeout task for the 'pending_head' handle
98 * which is the one with the smallest timeout.
100 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
103 * Current size of the queue of pending requests.
105 unsigned int queue_size;
108 * SendMessageRequest ID generator for this peer.
116 * Entry in a doubly-linked list of control messages to be transmitted
117 * to the core service. Control messages include traffic allocation,
118 * connection requests and of course our initial 'init' request.
120 * The actual message is allocated at the end of this struct.
122 struct ControlMessage
125 * This is a doubly-linked list.
127 struct ControlMessage *next;
130 * This is a doubly-linked list.
132 struct ControlMessage *prev;
135 * Function to run after successful transmission (or call with
136 * reason 'TIMEOUT' on error); called with scheduler context 'NULL'
139 GNUNET_SCHEDULER_Task cont;
142 * Closure for 'cont'.
147 * Transmit handle (if one is associated with this ControlMessage), or NULL.
149 struct GNUNET_CORE_TransmitHandle *th;
155 * Context for the core service connection.
157 struct GNUNET_CORE_Handle
161 * Configuration we're using.
163 const struct GNUNET_CONFIGURATION_Handle *cfg;
166 * Closure for the various callbacks.
171 * Function to call once we've handshaked with the core service.
173 GNUNET_CORE_StartupCallback init;
176 * Function to call whenever we're notified about a peer connecting.
178 GNUNET_CORE_ConnectEventHandler connects;
181 * Function to call whenever we're notified about a peer disconnecting.
183 GNUNET_CORE_DisconnectEventHandler disconnects;
186 * Function to call whenever we're notified about a peer changing status.
188 GNUNET_CORE_PeerStatusEventHandler status_events;
191 * Function to call whenever we receive an inbound message.
193 GNUNET_CORE_MessageCallback inbound_notify;
196 * Function to call whenever we receive an outbound message.
198 GNUNET_CORE_MessageCallback outbound_notify;
201 * Function handlers for messages of particular type.
203 const struct GNUNET_CORE_MessageHandler *handlers;
206 * Our connection to the service.
208 struct GNUNET_CLIENT_Connection *client;
211 * Handle for our current transmission request.
213 struct GNUNET_CLIENT_TransmitHandle *cth;
216 * Head of doubly-linked list of pending requests.
218 struct ControlMessage *pending_head;
221 * Tail of doubly-linked list of pending requests.
223 struct ControlMessage *pending_tail;
226 * Head of doubly-linked list of peers that are core-approved
227 * to send their next message.
229 struct PeerRecord *ready_peer_head;
232 * Tail of doubly-linked list of peers that are core-approved
233 * to send their next message.
235 struct PeerRecord *ready_peer_tail;
238 * Hash map listing all of the peers that we are currently
241 struct GNUNET_CONTAINER_MultiHashMap *peers;
244 * Identity of this peer.
246 struct GNUNET_PeerIdentity me;
249 * ID of reconnect task (if any).
251 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
254 * Current delay we use for re-trying to connect to core.
256 struct GNUNET_TIME_Relative retry_backoff;
259 * Request information ID generator.
264 * Number of messages we are allowed to queue per target.
266 unsigned int queue_size;
269 * Number of entries in the handlers array.
274 * For inbound notifications without a specific handler, do
275 * we expect to only receive headers?
277 int inbound_hdr_only;
280 * For outbound notifications without a specific handler, do
281 * we expect to only receive headers?
283 int outbound_hdr_only;
286 * Are we currently disconnected and hence unable to forward
295 * Handle for a transmission request.
297 struct GNUNET_CORE_TransmitHandle
301 * We keep active transmit handles in a doubly-linked list.
303 struct GNUNET_CORE_TransmitHandle *next;
306 * We keep active transmit handles in a doubly-linked list.
308 struct GNUNET_CORE_TransmitHandle *prev;
311 * Corresponding peer record.
313 struct PeerRecord *peer;
316 * Corresponding SEND_REQUEST message. Only non-NULL
317 * while SEND_REQUEST message is pending.
319 struct ControlMessage *cm;
322 * Function that will be called to get the actual request
323 * (once we are ready to transmit this request to the core).
324 * The function will be called with a NULL buffer to signal
327 GNUNET_CONNECTION_TransmitReadyNotify get_message;
330 * Closure for get_message.
332 void *get_message_cls;
335 * Timeout for this handle.
337 struct GNUNET_TIME_Absolute timeout;
340 * How important is this message?
345 * Size of this request.
350 * Send message request ID for this request.
358 * Our current client connection went down. Clean it up
359 * and try to reconnect!
361 * @param h our handle to the core service
364 reconnect (struct GNUNET_CORE_Handle *h);
368 * Task schedule to try to re-connect to core.
370 * @param cls the 'struct GNUNET_CORE_Handle'
371 * @param tc task context
374 reconnect_task (void *cls,
375 const struct GNUNET_SCHEDULER_TaskContext *tc)
377 struct GNUNET_CORE_Handle *h = cls;
379 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
382 "Connecting to CORE service after delay\n");
389 * Notify clients about disconnect and free
390 * the entry for connected peer.
392 * @param cls the 'struct GNUNET_CORE_Handle*'
393 * @param key the peer identity (not used)
394 * @param value the 'struct PeerRecord' to free.
395 * @return GNUNET_YES (continue)
398 disconnect_and_free_peer_entry (void *cls,
399 const GNUNET_HashCode *key,
402 static struct GNUNET_BANDWIDTH_Value32NBO zero;
403 struct GNUNET_CORE_Handle *h = cls;
404 struct GNUNET_CORE_TransmitHandle *th;
405 struct PeerRecord *pr = value;
406 GNUNET_CORE_PeerConfigurationInfoCallback pcic;
408 while (NULL != (th = pr->pending_head))
410 GNUNET_CONTAINER_DLL_remove (pr->pending_head,
415 th->get_message (th->get_message_cls,
419 if (NULL != (pcic = pr->pcic))
427 if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
429 GNUNET_SCHEDULER_cancel (pr->timeout_task);
430 pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
432 GNUNET_assert (pr->queue_size == 0);
433 if ( (pr->prev != NULL) ||
434 (pr->next != NULL) ||
435 (h->ready_peer_head == pr) )
436 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
439 if (h->disconnects != NULL)
440 h->disconnects (h->cls,
442 GNUNET_assert (GNUNET_YES ==
443 GNUNET_CONTAINER_multihashmap_remove (h->peers,
446 GNUNET_assert (pr->pending_head == NULL);
447 GNUNET_assert (pr->pending_tail == NULL);
448 GNUNET_assert (pr->ch = h);
449 GNUNET_assert (pr->queue_size == 0);
450 GNUNET_assert (pr->timeout_task == GNUNET_SCHEDULER_NO_TASK);
457 * Close down any existing connection to the CORE service and
458 * try re-establishing it later.
460 * @param h our handle
463 reconnect_later (struct GNUNET_CORE_Handle *h)
465 struct ControlMessage *cm;
467 while (NULL != (cm = h->pending_head))
469 GNUNET_CONTAINER_DLL_remove (h->pending_head,
474 if (cm->cont != NULL)
475 cm->cont (cm->cont_cls, NULL);
478 if (h->client != NULL)
480 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
483 GNUNET_CONTAINER_multihashmap_iterate (h->peers,
484 &disconnect_and_free_peer_entry,
487 GNUNET_assert (h->pending_head == NULL);
488 h->currently_down = GNUNET_YES;
489 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
490 h->retry_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
492 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
495 h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2);
500 * Check the list of pending requests, send the next
503 * @param h core handle
504 * @param ignore_currently_down transmit message even if not initialized?
507 trigger_next_request (struct GNUNET_CORE_Handle *h,
508 int ignore_currently_down);
512 * The given request hit its timeout. Remove from the
513 * doubly-linked list and call the respective continuation.
515 * @param cls the transmit handle of the request that timed out
516 * @param tc context, can be NULL (!)
519 transmission_timeout (void *cls,
520 const struct GNUNET_SCHEDULER_TaskContext *tc);
524 * Send a control message to the peer asking for transmission
525 * of the message in the given peer record.
527 * @param pr peer to request transmission to
530 request_next_transmission (struct PeerRecord *pr)
532 struct GNUNET_CORE_Handle *h = pr->ch;
533 struct ControlMessage *cm;
534 struct SendMessageRequest *smr;
535 struct GNUNET_CORE_TransmitHandle *th;
537 if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
539 GNUNET_SCHEDULER_cancel (pr->timeout_task);
540 pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
542 if (NULL == (th = pr->pending_head))
544 trigger_next_request (h, GNUNET_NO);
547 GNUNET_assert (pr->prev == NULL);
548 GNUNET_assert (pr->next == NULL);
549 pr->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (th->timeout),
550 &transmission_timeout,
552 cm = GNUNET_malloc (sizeof (struct ControlMessage) +
553 sizeof (struct SendMessageRequest));
556 smr = (struct SendMessageRequest*) &cm[1];
557 smr->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
558 smr->header.size = htons (sizeof (struct SendMessageRequest));
559 smr->priority = htonl (th->priority);
560 smr->deadline = GNUNET_TIME_absolute_hton (th->timeout);
561 smr->peer = pr->peer;
562 smr->queue_size = htonl (pr->queue_size);
563 smr->size = htons (th->msize);
564 smr->smr_id = htons (th->smr_id = pr->smr_id_gen++);
565 GNUNET_CONTAINER_DLL_insert_after (h->pending_head,
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
571 "Adding SEND REQUEST for peer `%s' to message queue\n",
572 GNUNET_i2s (&pr->peer));
574 trigger_next_request (h, GNUNET_NO);
579 * The given request hit its timeout. Remove from the
580 * doubly-linked list and call the respective continuation.
582 * @param cls the transmit handle of the request that timed out
583 * @param tc context, can be NULL (!)
586 transmission_timeout (void *cls,
587 const struct GNUNET_SCHEDULER_TaskContext *tc)
589 struct PeerRecord *pr = cls;
590 struct GNUNET_CORE_TransmitHandle *th;
592 pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
593 th = pr->pending_head;
594 GNUNET_CONTAINER_DLL_remove (pr->pending_head,
599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
600 "Signalling timeout of request for transmission to CORE service\n");
602 GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL));
603 request_next_transmission (pr);
608 * Transmit the next message to the core service.
611 transmit_message (void *cls,
615 struct GNUNET_CORE_Handle *h = cls;
616 struct ControlMessage *cm;
617 struct GNUNET_CORE_TransmitHandle *th;
618 struct PeerRecord *pr;
619 struct SendMessage *sm;
620 const struct GNUNET_MessageHeader *hdr;
628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
629 "Transmission failed, initiating reconnect\n");
634 /* first check for control messages */
635 if (NULL != (cm = h->pending_head))
637 hdr = (const struct GNUNET_MessageHeader*) &cm[1];
638 msize = ntohs (hdr->size);
641 trigger_next_request (h, GNUNET_NO);
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "Transmitting control message with %u bytes of type %u to core.\n",
647 (unsigned int) msize,
648 (unsigned int) ntohs (hdr->type));
650 memcpy (buf, hdr, msize);
651 GNUNET_CONTAINER_DLL_remove (h->pending_head,
656 if (NULL != cm->cont)
657 GNUNET_SCHEDULER_add_continuation (cm->cont,
659 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
661 trigger_next_request (h, GNUNET_NO);
664 /* now check for 'ready' P2P messages */
665 if (NULL != (pr = h->ready_peer_head))
667 /* FIXME: If a reconnect_later call happened, this can be NULL! */
668 if (pr->pending_head == NULL)
673 th = pr->pending_head;
674 if (size < th->msize + sizeof (struct SendMessage))
676 trigger_next_request (h, GNUNET_NO);
679 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
682 GNUNET_CONTAINER_DLL_remove (pr->pending_head,
686 if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
688 GNUNET_SCHEDULER_cancel (pr->timeout_task);
689 pr->timeout_task = GNUNET_SCHEDULER_NO_TASK;
692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
693 "Transmitting SEND request to `%s' with %u bytes.\n",
694 GNUNET_i2s (&pr->peer),
695 (unsigned int) th->msize);
697 sm = (struct SendMessage *) buf;
698 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
699 sm->priority = htonl (th->priority);
700 sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
702 ret = th->get_message (th->get_message_cls,
703 size - sizeof (struct SendMessage),
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
710 "Size of clients message to peer %s is 0!\n",
711 GNUNET_i2s(&pr->peer));
713 /* client decided to send nothing! */
714 request_next_transmission (pr);
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
719 "Produced SEND message to core with %u bytes payload\n",
722 GNUNET_assert (ret >= sizeof (struct GNUNET_MessageHeader));
723 if (ret + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
726 request_next_transmission (pr);
729 ret += sizeof (struct SendMessage);
730 sm->header.size = htons (ret);
731 GNUNET_assert (ret <= size);
733 request_next_transmission (pr);
741 * Check the list of pending requests, send the next
744 * @param h core handle
745 * @param ignore_currently_down transmit message even if not initialized?
748 trigger_next_request (struct GNUNET_CORE_Handle *h,
749 int ignore_currently_down)
753 if ( (GNUNET_YES == h->currently_down) &&
754 (ignore_currently_down == GNUNET_NO) )
757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
758 "Core connection down, not processing queue\n");
765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
766 "Request pending, not processing queue\n");
770 if (h->pending_head != NULL)
771 msize = ntohs (((struct GNUNET_MessageHeader*) &h->pending_head[1])->size);
772 else if ((h->ready_peer_head != NULL) && (h->ready_peer_head->pending_head != NULL)) /* FIXME: h->ready_peer_head->pending_head check necessary? */
773 msize = h->ready_peer_head->pending_head->msize + sizeof (struct SendMessage);
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Request queue empty, not processing queue\n");
780 return; /* no pending message */
782 h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client,
784 GNUNET_TIME_UNIT_FOREVER_REL,
786 &transmit_message, h);
791 * Handler for notification messages received from the core.
793 * @param cls our "struct GNUNET_CORE_Handle"
794 * @param msg the message received from the core service
797 main_notify_handler (void *cls,
798 const struct GNUNET_MessageHeader *msg)
800 struct GNUNET_CORE_Handle *h = cls;
801 const struct InitReplyMessage *m;
802 const struct ConnectNotifyMessage *cnm;
803 const struct DisconnectNotifyMessage *dnm;
804 const struct NotifyTrafficMessage *ntm;
805 const struct GNUNET_MessageHeader *em;
806 const struct ConfigurationInfoMessage *cim;
807 const struct PeerStatusNotifyMessage *psnm;
808 const struct SendMessageReady *smr;
809 const struct GNUNET_CORE_MessageHandler *mh;
810 GNUNET_CORE_StartupCallback init;
811 GNUNET_CORE_PeerConfigurationInfoCallback pcic;
812 struct PeerRecord *pr;
813 struct GNUNET_CORE_TransmitHandle *th;
821 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
823 ("Client was disconnected from core service, trying to reconnect.\n"));
827 msize = ntohs (msg->size);
829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
830 "Processing message of type %u and size %u from core service\n",
831 ntohs (msg->type), msize);
833 switch (ntohs (msg->type))
835 case GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY:
836 if (ntohs (msg->size) != sizeof (struct InitReplyMessage))
842 m = (const struct InitReplyMessage *) msg;
843 GNUNET_break (0 == ntohl (m->reserved));
844 /* start our message processing loop */
845 if (GNUNET_YES == h->currently_down)
847 h->currently_down = GNUNET_NO;
848 trigger_next_request (h, GNUNET_NO);
850 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
851 if (NULL != (init = h->init))
853 /* mark so we don't call init on reconnect */
855 GNUNET_CRYPTO_hash (&m->publicKey,
857 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
860 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
861 "Connected to core service of peer `%s'.\n",
862 GNUNET_i2s (&h->me));
864 init (h->cls, h, &h->me, &m->publicKey);
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
870 "Successfully reconnected to core service.\n");
874 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
875 if (msize != sizeof (struct ConnectNotifyMessage))
881 cnm = (const struct ConnectNotifyMessage *) msg;
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
884 "Received notification about connection from `%s'.\n",
885 GNUNET_i2s (&cnm->peer));
887 if (0 == memcmp (&h->me,
889 sizeof (struct GNUNET_PeerIdentity)))
891 /* disconnect from self!? */
895 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
896 &cnm->peer.hashPubKey);
903 pr = GNUNET_malloc (sizeof (struct PeerRecord));
904 pr->peer = cnm->peer;
906 GNUNET_assert (GNUNET_YES ==
907 GNUNET_CONTAINER_multihashmap_put (h->peers,
908 &cnm->peer.hashPubKey,
910 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
911 if (NULL != h->connects)
914 NULL /* FIXME: atsi! */);
916 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
917 if (msize != sizeof (struct DisconnectNotifyMessage))
923 dnm = (const struct DisconnectNotifyMessage *) msg;
924 if (0 == memcmp (&h->me,
926 sizeof (struct GNUNET_PeerIdentity)))
928 /* connection to self!? */
933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
934 "Received notification about disconnect from `%s'.\n",
935 GNUNET_i2s (&dnm->peer));
937 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
938 &dnm->peer.hashPubKey);
945 trigger = ( (pr->prev != NULL) ||
946 (pr->next != NULL) ||
947 (h->ready_peer_head == pr) );
948 disconnect_and_free_peer_entry (h, &dnm->peer.hashPubKey, pr);
950 trigger_next_request (h, GNUNET_NO);
952 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE:
953 if (NULL == h->status_events)
958 if (msize != sizeof (struct PeerStatusNotifyMessage))
964 psnm = (const struct PeerStatusNotifyMessage *) msg;
965 if (0 == memcmp (&h->me,
967 sizeof (struct GNUNET_PeerIdentity)))
974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
975 "Received notification about status change by `%s'.\n",
976 GNUNET_i2s (&psnm->peer));
978 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
979 &psnm->peer.hashPubKey);
986 h->status_events (h->cls,
990 GNUNET_TIME_absolute_ntoh (psnm->timeout),
991 NULL /* FIXME: atsi */);
993 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
995 sizeof (struct NotifyTrafficMessage) +
996 sizeof (struct GNUNET_MessageHeader))
1002 ntm = (const struct NotifyTrafficMessage *) msg;
1003 if (0 == memcmp (&h->me,
1005 sizeof (struct GNUNET_PeerIdentity)))
1011 em = (const struct GNUNET_MessageHeader *) &ntm[1];
1013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1014 "Received message of type %u and size %u from peer `%4s'\n",
1017 GNUNET_i2s (&ntm->peer));
1019 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
1020 &ntm->peer.hashPubKey);
1024 reconnect_later (h);
1027 if ((GNUNET_NO == h->inbound_hdr_only) &&
1028 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
1031 reconnect_later (h);
1034 et = ntohs (em->type);
1035 for (hpos = 0; hpos < h->hcnt; hpos++)
1037 mh = &h->handlers[hpos];
1040 if ((mh->expected_size != ntohs (em->size)) &&
1041 (mh->expected_size != 0))
1047 h->handlers[hpos].callback (h->cls, &ntm->peer, em,
1048 NULL /* FIXME: atsi */))
1050 /* error in processing, do not process other messages! */
1054 if (NULL != h->inbound_notify)
1055 h->inbound_notify (h->cls, &ntm->peer, em,
1056 NULL /* FIXME: atsi */);
1058 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
1060 sizeof (struct NotifyTrafficMessage) +
1061 sizeof (struct GNUNET_MessageHeader))
1064 reconnect_later (h);
1067 ntm = (const struct NotifyTrafficMessage *) msg;
1068 if (0 == memcmp (&h->me,
1070 sizeof (struct GNUNET_PeerIdentity)))
1076 em = (const struct GNUNET_MessageHeader *) &ntm[1];
1077 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
1078 &ntm->peer.hashPubKey);
1082 reconnect_later (h);
1086 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1087 "Received notification about transmission to `%s'.\n",
1088 GNUNET_i2s (&ntm->peer));
1090 if ((GNUNET_NO == h->outbound_hdr_only) &&
1091 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
1094 reconnect_later (h);
1097 if (NULL == h->outbound_notify)
1102 h->outbound_notify (h->cls, &ntm->peer, em,
1103 NULL /* FIXME: atsi? */);
1105 case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
1106 if (msize != sizeof (struct SendMessageReady))
1109 reconnect_later (h);
1112 smr = (const struct SendMessageReady *) msg;
1113 if (0 == memcmp (&h->me,
1115 sizeof (struct GNUNET_PeerIdentity)))
1121 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
1122 &smr->peer.hashPubKey);
1126 reconnect_later (h);
1130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1131 "Received notification about transmission readiness to `%s'.\n",
1132 GNUNET_i2s (&smr->peer));
1134 if (pr->pending_head == NULL)
1136 /* request must have been cancelled between the origional request
1137 and the response from core, ignore core's readiness */
1141 th = pr->pending_head;
1142 if (ntohs (smr->smr_id) != th->smr_id)
1144 /* READY message is for expired or cancelled message,
1145 ignore! (we should have already sent another request) */
1148 if ( (pr->prev != NULL) ||
1149 (pr->next != NULL) ||
1150 (h->ready_peer_head == pr) )
1152 /* we should not already be on the ready list... */
1154 reconnect_later (h);
1157 GNUNET_CONTAINER_DLL_insert (h->ready_peer_head,
1160 trigger_next_request (h, GNUNET_NO);
1162 case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
1163 if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage))
1166 reconnect_later (h);
1169 cim = (const struct ConfigurationInfoMessage*) msg;
1170 if (0 == memcmp (&h->me,
1172 sizeof (struct GNUNET_PeerIdentity)))
1179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1180 "Received notification about configuration update for `%s'.\n",
1181 GNUNET_i2s (&cim->peer));
1183 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
1184 &cim->peer.hashPubKey);
1188 reconnect_later (h);
1191 if (pr->rim_id != ntohl (cim->rim_id))
1199 ntohl (cim->reserved_amount),
1200 GNUNET_ntohll (cim->preference));
1203 reconnect_later (h);
1206 GNUNET_CLIENT_receive (h->client,
1207 &main_notify_handler, h,
1208 GNUNET_TIME_UNIT_FOREVER_REL);
1213 * Task executed once we are done transmitting the INIT message.
1214 * Starts our 'receive' loop.
1216 * @param cls the 'struct GNUNET_CORE_Handle'
1217 * @param tc task context
1220 init_done_task (void *cls,
1221 const struct GNUNET_SCHEDULER_TaskContext *tc)
1223 struct GNUNET_CORE_Handle *h = cls;
1227 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
1230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1231 "Failed to exchange INIT with core, retrying\n");
1233 reconnect_later (h);
1236 GNUNET_CLIENT_receive (h->client,
1237 &main_notify_handler,
1239 GNUNET_TIME_UNIT_FOREVER_REL);
1244 * Our current client connection went down. Clean it up
1245 * and try to reconnect!
1247 * @param h our handle to the core service
1250 reconnect (struct GNUNET_CORE_Handle *h)
1252 struct ControlMessage *cm;
1253 struct InitMessage *init;
1260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1261 "Reconnecting to CORE service\n");
1263 GNUNET_assert (h->client == NULL);
1264 GNUNET_assert (h->currently_down == GNUNET_YES);
1265 h->client = GNUNET_CLIENT_connect ("core", h->cfg);
1266 if (h->client == NULL)
1268 reconnect_later (h);
1271 msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage);
1272 cm = GNUNET_malloc (sizeof (struct ControlMessage) +
1274 cm->cont = &init_done_task;
1276 init = (struct InitMessage*) &cm[1];
1277 init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
1278 init->header.size = htons (msize);
1279 opt = GNUNET_CORE_OPTION_SEND_CONNECT | GNUNET_CORE_OPTION_SEND_DISCONNECT;
1280 if (h->status_events != NULL)
1281 opt |= GNUNET_CORE_OPTION_SEND_STATUS_CHANGE;
1282 if (h->inbound_notify != NULL)
1284 if (h->inbound_hdr_only)
1285 opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
1287 opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
1289 if (h->outbound_notify != NULL)
1291 if (h->outbound_hdr_only)
1292 opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
1294 opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
1296 init->options = htonl (opt);
1297 ts = (uint16_t *) &init[1];
1298 for (hpos = 0; hpos < h->hcnt; hpos++)
1299 ts[hpos] = htons (h->handlers[hpos].type);
1300 GNUNET_CONTAINER_DLL_insert (h->pending_head,
1303 trigger_next_request (h, GNUNET_YES);
1309 * Connect to the core service. Note that the connection may
1310 * complete (or fail) asynchronously.
1312 * @param cfg configuration to use
1313 * @param queue_size size of the per-peer message queue
1314 * @param cls closure for the various callbacks that follow (including handlers in the handlers array)
1315 * @param init callback to call on timeout or once we have successfully
1316 * connected to the core service; note that timeout is only meaningful if init is not NULL
1317 * @param connects function to call on peer connect, can be NULL
1318 * @param disconnects function to call on peer disconnect / timeout, can be NULL
1319 * @param status_events function to call on changes to peer connection status, can be NULL
1320 * @param inbound_notify function to call for all inbound messages, can be NULL
1321 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
1322 * GNUNET_MessageHeader and hence we do not need to give it the full message;
1323 * can be used to improve efficiency, ignored if inbound_notify is NULLL
1324 * @param outbound_notify function to call for all outbound messages, can be NULL
1325 * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the
1326 * GNUNET_MessageHeader and hence we do not need to give it the full message
1327 * can be used to improve efficiency, ignored if outbound_notify is NULLL
1328 * @param handlers callbacks for messages we care about, NULL-terminated
1329 * @return handle to the core service (only useful for disconnect until 'init' is called);
1330 * NULL on error (in this case, init is never called)
1332 struct GNUNET_CORE_Handle *
1333 GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1334 unsigned int queue_size,
1336 GNUNET_CORE_StartupCallback init,
1337 GNUNET_CORE_ConnectEventHandler connects,
1338 GNUNET_CORE_DisconnectEventHandler disconnects,
1339 GNUNET_CORE_PeerStatusEventHandler status_events,
1340 GNUNET_CORE_MessageCallback inbound_notify,
1341 int inbound_hdr_only,
1342 GNUNET_CORE_MessageCallback outbound_notify,
1343 int outbound_hdr_only,
1344 const struct GNUNET_CORE_MessageHandler *handlers)
1346 struct GNUNET_CORE_Handle *h;
1348 h = GNUNET_malloc (sizeof (struct GNUNET_CORE_Handle));
1350 h->queue_size = queue_size;
1353 h->connects = connects;
1354 h->disconnects = disconnects;
1355 h->status_events = status_events;
1356 h->inbound_notify = inbound_notify;
1357 h->outbound_notify = outbound_notify;
1358 h->inbound_hdr_only = inbound_hdr_only;
1359 h->outbound_hdr_only = outbound_hdr_only;
1360 h->handlers = handlers;
1362 h->currently_down = GNUNET_YES;
1363 h->peers = GNUNET_CONTAINER_multihashmap_create (128);
1364 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
1365 while (handlers[h->hcnt].callback != NULL)
1367 GNUNET_assert (h->hcnt <
1368 (GNUNET_SERVER_MAX_MESSAGE_SIZE -
1369 sizeof (struct InitMessage)) / sizeof (uint16_t));
1371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1372 "Connecting to CORE service\n");
1380 * Disconnect from the core service. This function can only
1381 * be called *after* all pending 'GNUNET_CORE_notify_transmit_ready'
1382 * requests have been explicitly canceled.
1384 * @param handle connection to core to disconnect
1387 GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
1389 struct ControlMessage *cm;
1392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1393 "Disconnecting from CORE service\n");
1395 if (handle->cth != NULL)
1397 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
1400 if (handle->client != NULL)
1402 GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
1403 handle->client = NULL;
1405 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
1407 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
1408 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1410 while (NULL != (cm = handle->pending_head))
1412 GNUNET_CONTAINER_DLL_remove (handle->pending_head,
1413 handle->pending_tail,
1417 if (cm->cont != NULL)
1418 cm->cont (cm->cont_cls, NULL);
1421 GNUNET_CONTAINER_multihashmap_iterate (handle->peers,
1422 &disconnect_and_free_peer_entry,
1424 GNUNET_CONTAINER_multihashmap_destroy (handle->peers);
1425 GNUNET_break (handle->ready_peer_head == NULL);
1426 GNUNET_free (handle);
1431 * Ask the core to call "notify" once it is ready to transmit the
1432 * given number of bytes to the specified "target". If we are not yet
1433 * connected to the specified peer, a call to this function will cause
1434 * us to try to establish a connection.
1436 * @param handle connection to core service
1437 * @param priority how important is the message?
1438 * @param maxdelay how long can the message wait?
1439 * @param target who should receive the message,
1440 * use NULL for this peer (loopback)
1441 * @param notify_size how many bytes of buffer space does notify want?
1442 * @param notify function to call when buffer space is available
1443 * @param notify_cls closure for notify
1444 * @return non-NULL if the notify callback was queued,
1445 * NULL if we can not even queue the request (insufficient
1446 * memory); if NULL is returned, "notify" will NOT be called.
1448 struct GNUNET_CORE_TransmitHandle *
1449 GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
1451 struct GNUNET_TIME_Relative maxdelay,
1452 const struct GNUNET_PeerIdentity *target,
1454 GNUNET_CONNECTION_TransmitReadyNotify notify,
1457 struct PeerRecord *pr;
1458 struct GNUNET_CORE_TransmitHandle *th;
1459 struct GNUNET_CORE_TransmitHandle *pos;
1460 struct GNUNET_CORE_TransmitHandle *prev;
1461 struct GNUNET_CORE_TransmitHandle *minp;
1463 pr = GNUNET_CONTAINER_multihashmap_get (handle->peers,
1464 &target->hashPubKey);
1467 /* attempt to send to peer that is not connected */
1468 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1469 "Attempting to send to peer `%s' from peer `%s', but not connected!\n",
1470 GNUNET_i2s(target), GNUNET_h2s(&handle->me.hashPubKey));
1474 GNUNET_assert (notify_size + sizeof (struct SendMessage) <
1475 GNUNET_SERVER_MAX_MESSAGE_SIZE);
1476 th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle));
1478 th->get_message = notify;
1479 th->get_message_cls = notify_cls;
1480 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
1481 th->priority = priority;
1482 th->msize = notify_size;
1483 /* bound queue size */
1484 if (pr->queue_size == handle->queue_size)
1486 /* find lowest-priority entry */
1487 minp = pr->pending_head;
1489 while (prev != NULL)
1491 if (prev->priority < minp->priority)
1497 GNUNET_break (handle->queue_size != 0);
1498 GNUNET_break (pr->queue_size == 0);
1501 if (priority <= minp->priority)
1504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1505 "Dropping transmission request: priority too low\n");
1507 return NULL; /* priority too low */
1509 GNUNET_CONTAINER_DLL_remove (pr->pending_head,
1514 minp->get_message (minp->get_message_cls,
1519 /* Order entries by deadline, but SKIP 'HEAD' if
1520 we're in the 'ready_peer_*' DLL */
1521 /* FIXME: again, pr->pending_head is NULL after a reconnect_later call */
1522 pos = pr->pending_head;
1523 if (pr->pending_head != NULL)
1525 if ( (pr->prev != NULL) ||
1526 (pr->next != NULL) ||
1527 (pr == handle->ready_peer_head) )
1529 GNUNET_assert (pos != NULL);
1530 pos = pos->next; /* skip head */
1538 /* insertion sort */
1540 while ( (pos != NULL) &&
1541 (pos->timeout.abs_value < th->timeout.abs_value) )
1546 GNUNET_CONTAINER_DLL_insert_after (pr->pending_head,
1551 /* was the request queue previously empty? */
1553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1554 "Transmission request added to queue\n");
1556 if (pr->pending_head == th)
1557 request_next_transmission (pr);
1563 * Cancel the specified transmission-ready notification.
1565 * @param th handle that was returned by "notify_transmit_ready".
1568 GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
1571 struct PeerRecord *pr = th->peer;
1572 struct GNUNET_CORE_Handle *h = pr->ch;
1575 was_head = (pr->pending_head == th);
1576 GNUNET_CONTAINER_DLL_remove (pr->pending_head,
1582 /* we're currently in the control queue, remove */
1583 GNUNET_CONTAINER_DLL_remove (h->pending_head,
1586 GNUNET_free (th->cm);
1591 if ( (pr->prev != NULL) ||
1592 (pr->next != NULL) ||
1593 (pr == h->ready_peer_head) )
1595 /* the request that was 'approved' by core was
1596 canceled before it could be transmitted; remove
1597 us from the 'ready' list */
1598 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head,
1602 request_next_transmission (pr);
1607 /* ****************** GNUNET_CORE_peer_request_connect ******************** */
1610 * Handle for a request to the core to connect to
1611 * a particular peer. Can be used to cancel the request
1612 * (before the 'cont'inuation is called).
1614 struct GNUNET_CORE_PeerRequestHandle
1618 * Link to control message.
1620 struct ControlMessage *cm;
1625 struct GNUNET_CORE_Handle *h;
1628 * Continuation to run when done.
1630 GNUNET_SCHEDULER_Task cont;
1633 * Closure for 'cont'.
1641 * Continuation called when the control message was transmitted.
1642 * Calls the original continuation and frees the remaining
1645 * @param cls the 'struct GNUNET_CORE_PeerRequestHandle'
1646 * @param tc scheduler context
1649 peer_request_connect_cont (void *cls,
1650 const struct GNUNET_SCHEDULER_TaskContext *tc)
1652 struct GNUNET_CORE_PeerRequestHandle *ret = cls;
1654 if (ret->cont != NULL)
1657 GNUNET_SCHEDULER_add_now (ret->cont,
1660 ret->cont (ret->cont_cls, tc);
1667 * Request that the core should try to connect to a particular peer.
1668 * Once the request has been transmitted to the core, the continuation
1669 * function will be called. Note that this does NOT mean that a
1670 * connection was successfully established -- it only means that the
1671 * core will now try. Successful establishment of the connection
1672 * will be signalled to the 'connects' callback argument of
1673 * 'GNUNET_CORE_connect' only. If the core service does not respond
1674 * to our connection attempt within the given time frame, 'cont' will
1675 * be called with the TIMEOUT reason code.
1677 * @param h core handle
1678 * @param timeout how long to try to talk to core
1679 * @param peer who should we connect to
1680 * @param cont function to call once the request has been completed (or timed out)
1681 * @param cont_cls closure for cont
1682 * @return NULL on error (cont will not be called), otherwise handle for cancellation
1684 struct GNUNET_CORE_PeerRequestHandle *
1685 GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
1686 struct GNUNET_TIME_Relative timeout,
1687 const struct GNUNET_PeerIdentity * peer,
1688 GNUNET_SCHEDULER_Task cont,
1691 struct GNUNET_CORE_PeerRequestHandle *ret;
1692 struct ControlMessage *cm;
1693 struct ConnectMessage *msg;
1695 cm = GNUNET_malloc (sizeof (struct ControlMessage) +
1696 sizeof (struct ConnectMessage));
1697 msg = (struct ConnectMessage*) &cm[1];
1698 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT);
1699 msg->header.size = htons (sizeof (struct ConnectMessage));
1700 msg->reserved = htonl (0);
1701 msg->timeout = GNUNET_TIME_relative_hton (timeout);
1703 GNUNET_CONTAINER_DLL_insert (h->pending_head,
1706 ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle));
1710 ret->cont_cls = cont_cls;
1711 cm->cont = &peer_request_connect_cont;
1714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1715 "Queueing REQUEST_CONNECT request\n");
1717 if (h->pending_head == cm)
1718 trigger_next_request (h, GNUNET_NO);
1724 * Cancel a pending request to connect to a particular peer. Must not
1725 * be called after the 'cont' function was invoked.
1727 * @param req request handle that was returned for the original request
1730 GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req)
1732 struct GNUNET_CORE_Handle *h = req->h;
1733 struct ControlMessage *cm = req->cm;
1735 GNUNET_CONTAINER_DLL_remove (h->pending_head,
1743 /* ****************** GNUNET_CORE_peer_change_preference ******************** */
1746 struct GNUNET_CORE_InformationRequestContext
1750 * Our connection to the service.
1752 struct GNUNET_CORE_Handle *h;
1755 * Function to call with the information.
1757 GNUNET_CORE_PeerConfigurationInfoCallback info;
1765 * Link to control message, NULL if CM was sent.
1767 struct ControlMessage *cm;
1770 * Link to peer record.
1772 struct PeerRecord *pr;
1777 * CM was sent, remove link so we don't double-free.
1779 * @param cls the 'struct GNUNET_CORE_InformationRequestContext'
1780 * @param tc scheduler context
1783 change_preference_send_continuation (void *cls,
1784 const struct GNUNET_SCHEDULER_TaskContext *tc)
1786 struct GNUNET_CORE_InformationRequestContext *irc = cls;
1793 * Obtain statistics and/or change preferences for the given peer.
1795 * @param h core handle
1796 * @param peer identifies the peer
1797 * @param timeout after how long should we give up (and call "info" with NULL
1798 * for "peer" to signal an error)?
1799 * @param bw_out set to the current bandwidth limit (sending) for this peer,
1800 * caller should set "bw_out" to "-1" to avoid changing
1801 * the current value; otherwise "bw_out" will be lowered to
1802 * the specified value; passing a pointer to "0" can be used to force
1803 * us to disconnect from the peer; "bw_out" might not increase
1804 * as specified since the upper bound is generally
1805 * determined by the other peer!
1806 * @param amount reserve N bytes for receiving, negative
1807 * amounts can be used to undo a (recent) reservation;
1808 * @param preference increase incoming traffic share preference by this amount;
1809 * in the absence of "amount" reservations, we use this
1810 * preference value to assign proportional bandwidth shares
1811 * to all connected peers
1812 * @param info function to call with the resulting configuration information
1813 * @param info_cls closure for info
1814 * @return NULL on error
1816 struct GNUNET_CORE_InformationRequestContext *
1817 GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
1818 const struct GNUNET_PeerIdentity *peer,
1819 struct GNUNET_TIME_Relative timeout,
1820 struct GNUNET_BANDWIDTH_Value32NBO bw_out,
1822 uint64_t preference,
1823 GNUNET_CORE_PeerConfigurationInfoCallback info,
1826 struct GNUNET_CORE_InformationRequestContext *irc;
1827 struct PeerRecord *pr;
1828 struct RequestInfoMessage *rim;
1829 struct ControlMessage *cm;
1831 pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
1835 /* attempt to change preference on peer that is not connected */
1839 if (pr->pcic != NULL)
1841 /* second change before first one is done */
1845 irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
1849 irc->info_cls = info_cls;
1850 cm = GNUNET_malloc (sizeof (struct ControlMessage) +
1851 sizeof (struct RequestInfoMessage));
1852 cm->cont = &change_preference_send_continuation;
1855 rim = (struct RequestInfoMessage*) &cm[1];
1856 rim->header.size = htons (sizeof (struct RequestInfoMessage));
1857 rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
1858 rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++);
1859 rim->limit_outbound = bw_out;
1860 rim->reserve_inbound = htonl (amount);
1861 rim->preference_change = GNUNET_htonll(preference);
1864 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1865 "Queueing CHANGE PREFERENCE request\n");
1867 GNUNET_CONTAINER_DLL_insert (h->pending_head,
1871 pr->pcic_cls = info_cls;
1872 if (h->pending_head == cm)
1873 trigger_next_request (h, GNUNET_NO);
1879 * Cancel request for getting information about a peer.
1880 * Note that an eventual change in preference, trust or bandwidth
1881 * assignment MAY have already been committed at the time,
1882 * so cancelling a request is NOT sure to undo the original
1883 * request. The original request may or may not still commit.
1884 * The only thing cancellation ensures is that the callback
1885 * from the original request will no longer be called.
1887 * @param irc context returned by the original GNUNET_CORE_peer_get_info call
1890 GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequestContext *irc)
1892 struct GNUNET_CORE_Handle *h = irc->h;
1893 struct PeerRecord *pr = irc->pr;
1895 if (irc->cm != NULL)
1897 GNUNET_CONTAINER_DLL_remove (h->pending_head,
1900 GNUNET_free (irc->cm);
1903 pr->pcic_cls = NULL;
1908 /* end of core_api.c */