2 This file is part of GNUnet.
3 (C) 2009 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 2, 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 #include "gnunet_core_service.h"
33 * Context for the core service connection.
35 struct GNUNET_CORE_Handle
41 struct GNUNET_SCHEDULER_Handle *sched;
44 * Configuration we're using.
46 const struct GNUNET_CONFIGURATION_Handle *cfg;
49 * Closure for the various callbacks.
54 * Function to call once we've handshaked with the core service.
56 GNUNET_CORE_StartupCallback init;
59 * Function to call whenever we're notified about a peer connecting.
61 GNUNET_CORE_ConnectEventHandler connects;
64 * Function to call whenever we're notified about a peer disconnecting.
66 GNUNET_CORE_DisconnectEventHandler disconnects;
69 * Function to call whenever we receive an inbound message.
71 GNUNET_CORE_MessageCallback inbound_notify;
74 * Function to call whenever we receive an outbound message.
76 GNUNET_CORE_MessageCallback outbound_notify;
79 * Function handlers for messages of particular type.
81 const struct GNUNET_CORE_MessageHandler *handlers;
84 * Our connection to the service for notifications.
86 struct GNUNET_CLIENT_Connection *client_notifications;
89 * Handle for our current transmission request.
91 struct GNUNET_CLIENT_TransmitHandle *th;
94 * Head of doubly-linked list of pending requests.
96 struct GNUNET_CORE_TransmitHandle *pending_head;
99 * Tail of doubly-linked list of pending requests.
101 struct GNUNET_CORE_TransmitHandle *pending_tail;
104 * Currently submitted request (or NULL)
106 struct GNUNET_CORE_TransmitHandle *submitted;
109 * Currently submitted request based on solicitation (or NULL)
111 struct GNUNET_CORE_TransmitHandle *solicit_transmit_req;
114 * Buffer where we store a message for transmission in response
115 * to a traffic solicitation (or NULL).
117 char *solicit_buffer;
120 * How long to wait until we time out the connection attempt?
122 struct GNUNET_TIME_Absolute startup_timeout;
125 * ID of reconnect task (if any).
127 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
130 * Number of entries in the handlers array.
135 * For inbound notifications without a specific handler, do
136 * we expect to only receive headers?
138 int inbound_hdr_only;
141 * For outbound notifications without a specific handler, do
142 * we expect to only receive headers?
144 int outbound_hdr_only;
147 * Are we currently disconnected and hence unable to forward
155 * Handle for a transmission request.
157 struct GNUNET_CORE_TransmitHandle
161 * We keep active transmit handles in a doubly-linked list.
163 struct GNUNET_CORE_TransmitHandle *next;
166 * We keep active transmit handles in a doubly-linked list.
168 struct GNUNET_CORE_TransmitHandle *prev;
171 * Corresponding core handle.
173 struct GNUNET_CORE_Handle *ch;
176 * Function that will be called to get the actual request
177 * (once we are ready to transmit this request to the core).
178 * The function will be called with a NULL buffer to signal
181 GNUNET_CONNECTION_TransmitReadyNotify get_message;
184 * Closure for get_message.
186 void *get_message_cls;
189 * If this entry is for a transmission request, pointer
190 * to the notify callback; otherwise NULL.
192 GNUNET_CONNECTION_TransmitReadyNotify notify;
195 * Closure for notify.
200 * Peer the request is about.
202 struct GNUNET_PeerIdentity peer;
205 * Timeout for this handle.
207 struct GNUNET_TIME_Absolute timeout;
210 * ID of timeout task.
212 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
215 * How important is this message?
220 * Size of this request.
229 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
233 * Function called when we are ready to transmit our
234 * "START" message (or when this operation timed out).
237 * @param size number of bytes available in buf
238 * @param buf where the callee should write the message
239 * @return number of bytes written to buf
241 static size_t transmit_start (void *cls, size_t size, void *buf);
245 * Our current client connection went down. Clean it up
246 * and try to reconnect!
248 * @param h our handle to the core service
251 reconnect (struct GNUNET_CORE_Handle *h)
253 if (h->client_notifications != NULL)
254 GNUNET_CLIENT_disconnect (h->client_notifications, GNUNET_NO);
255 h->currently_down = GNUNET_YES;
256 h->client_notifications = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
257 if (h->client_notifications == NULL)
258 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->sched,
259 GNUNET_TIME_UNIT_SECONDS,
263 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
264 sizeof (struct InitMessage) +
265 sizeof (uint16_t) * h->hcnt,
266 GNUNET_TIME_UNIT_SECONDS,
273 * The given request hit its timeout. Remove from the
274 * doubly-linked list and call the respective continuation.
276 * @param cls the transmit handle of the request that timed out
277 * @param tc context, can be NULL (!)
280 timeout_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
282 struct GNUNET_CORE_TransmitHandle *th = cls;
284 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
285 GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL));
290 * Function called when we are ready to transmit a request from our
291 * request list (or when this operation timed out).
294 * @param size number of bytes available in buf
295 * @param buf where the callee should write the message
296 * @return number of bytes written to buf
299 request_start (void *cls, size_t size, void *buf)
301 struct GNUNET_CORE_Handle *h = cls;
302 struct GNUNET_CORE_TransmitHandle *th;
306 th = h->pending_head;
309 timeout_request (th, NULL);
312 /* create new timeout task (in case core takes too long to respond!) */
313 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->timeout_task);
314 th->timeout_task = GNUNET_SCHEDULER_add_delayed (h->sched,
315 GNUNET_TIME_absolute_get_remaining
317 &timeout_request, th);
318 GNUNET_CONTAINER_DLL_remove (h->pending_head,
321 GNUNET_assert (h->submitted == NULL);
323 GNUNET_assert (size >= th->msize);
324 ret = th->get_message (th->get_message_cls, size, buf);
325 GNUNET_assert (ret <= size);
331 * Check the list of pending requests, send the next
335 trigger_next_request (struct GNUNET_CORE_Handle *h)
337 struct GNUNET_CORE_TransmitHandle *th;
339 if (h->currently_down)
342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
343 "In trigger_next_request, connection currently down...\n");
345 return; /* connection temporarily down */
347 if (NULL == (th = h->pending_head))
348 return; /* no requests pending */
349 GNUNET_assert (NULL == h->th);
350 if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task)
352 GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task);
353 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
355 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
357 GNUNET_TIME_absolute_get_remaining
366 * Handler for notification messages received from the core.
368 * @param cls our "struct GNUNET_CORE_Handle"
369 * @param msg the message received from the core service
372 main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
374 struct GNUNET_CORE_Handle *h = cls;
376 const struct ConnectNotifyMessage *cnm;
377 const struct DisconnectNotifyMessage *dnm;
378 const struct NotifyTrafficMessage *ntm;
379 const struct GNUNET_MessageHeader *em;
382 const struct GNUNET_CORE_MessageHandler *mh;
386 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
388 ("Client was disconnected from core service, trying to reconnect.\n"));
392 msize = ntohs (msg->size);
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
395 "Processing message of type %u and size %u from core service\n",
396 ntohs (msg->type), msize);
398 switch (ntohs (msg->type))
400 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
401 if (NULL == h->connects)
406 if (msize != sizeof (struct ConnectNotifyMessage))
411 cnm = (const struct ConnectNotifyMessage *) msg;
414 GNUNET_TIME_relative_ntoh (cnm->latency),
415 ntohl (cnm->distance));
417 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
418 if (NULL == h->disconnects)
423 if (msize != sizeof (struct DisconnectNotifyMessage))
428 dnm = (const struct DisconnectNotifyMessage *) msg;
429 h->disconnects (h->cls,
432 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
434 sizeof (struct NotifyTrafficMessage) +
435 sizeof (struct GNUNET_MessageHeader))
440 ntm = (const struct NotifyTrafficMessage *) msg;
441 em = (const struct GNUNET_MessageHeader *) &ntm[1];
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
444 "Received message of type %u from peer `%4s'\n",
445 ntohs (em->type), GNUNET_i2s (&ntm->peer));
447 if ((GNUNET_NO == h->inbound_hdr_only) &&
448 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
453 et = ntohs (em->type);
454 for (hpos = 0; hpos < h->hcnt; hpos++)
456 mh = &h->handlers[hpos];
459 if ((mh->expected_size != ntohs (em->size)) &&
460 (mh->expected_size != 0))
466 h->handlers[hpos].callback (h->cls, &ntm->peer, em,
467 GNUNET_TIME_relative_ntoh (ntm->latency),
468 ntohl (ntm->distance)))
470 /* error in processing, disconnect ! */
475 if (NULL != h->inbound_notify)
476 h->inbound_notify (h->cls, &ntm->peer, em,
477 GNUNET_TIME_relative_ntoh (ntm->latency),
478 ntohl (ntm->distance));
480 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
482 sizeof (struct NotifyTrafficMessage) +
483 sizeof (struct GNUNET_MessageHeader))
488 ntm = (const struct NotifyTrafficMessage *) msg;
489 em = (const struct GNUNET_MessageHeader *) &ntm[1];
490 if ((GNUNET_NO == h->outbound_hdr_only) &&
491 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
496 if (NULL == h->outbound_notify)
501 h->outbound_notify (h->cls, &ntm->peer, em,
502 GNUNET_TIME_relative_ntoh (ntm->latency),
503 ntohl (ntm->distance));
509 GNUNET_CLIENT_receive (h->client_notifications,
510 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
515 * Function called when we are ready to transmit our
516 * "START" message (or when this operation timed out).
519 * @param size number of bytes available in buf
520 * @param buf where the callee should write the message
521 * @return number of bytes written to buf
523 static size_t transmit_start (void *cls, size_t size, void *buf);
527 * Function called on the first message received from
528 * the service (contains our public key, etc.).
529 * Should trigger calling the init callback
530 * and then start our regular message processing.
533 * @param msg message received, NULL on timeout or fatal error
536 init_reply_handler (void *cls, const struct GNUNET_MessageHeader *msg)
538 struct GNUNET_CORE_Handle *h = cls;
539 const struct InitReplyMessage *m;
540 GNUNET_CORE_StartupCallback init;
541 struct GNUNET_PeerIdentity my_identity;
544 (ntohs (msg->size) != sizeof (struct InitReplyMessage)) ||
545 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY))
549 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
551 ("Error connecting to core service (failed to receive `%s' message, got message of type %u and size %u).\n"),
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
561 _("Failed to connect to core service, will retry.\n"));
564 transmit_start (h, 0, NULL);
567 m = (const struct InitReplyMessage *) msg;
568 /* start our message processing loop */
570 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
571 "Successfully connected to core service, starting processing loop.\n");
573 h->currently_down = GNUNET_NO;
574 trigger_next_request (h);
575 GNUNET_CLIENT_receive (h->client_notifications,
576 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
577 if (NULL != (init = h->init))
579 /* mark so we don't call init on reconnect */
581 GNUNET_CRYPTO_hash (&m->publicKey,
583 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
584 &my_identity.hashPubKey);
585 init (h->cls, h, &my_identity, &m->publicKey);
591 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
593 struct GNUNET_CORE_Handle *h = cls;
594 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
600 * Function called when we are ready to transmit our
601 * "START" message (or when this operation timed out).
604 * @param size number of bytes available in buf
605 * @param buf where the callee should write the message
606 * @return number of bytes written to buf
609 transmit_start (void *cls, size_t size, void *buf)
611 struct GNUNET_CORE_Handle *h = cls;
612 struct InitMessage *init;
617 struct GNUNET_TIME_Relative delay;
622 if ((h->init == NULL) ||
623 (GNUNET_TIME_absolute_get ().value < h->startup_timeout.value))
625 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
626 _("Failed to connect to core service, retrying.\n"));
627 delay = GNUNET_TIME_absolute_get_remaining (h->startup_timeout);
628 if ((h->init == NULL) || (delay.value > 1000))
629 delay = GNUNET_TIME_UNIT_SECONDS;
632 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
634 GNUNET_SCHEDULER_add_delayed (h->sched,
635 delay, &reconnect_task, h);
638 /* timeout on initial connect */
639 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
640 _("Failed to connect to core service, giving up.\n"));
641 h->init (h->cls, NULL, NULL, NULL);
642 GNUNET_CORE_disconnect (h);
645 msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage);
646 GNUNET_assert (size >= msize);
648 init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
649 init->header.size = htons (msize);
650 opt = GNUNET_CORE_OPTION_NOTHING;
651 if (h->connects != NULL)
652 opt |= GNUNET_CORE_OPTION_SEND_CONNECT;
653 if (h->disconnects != NULL)
654 opt |= GNUNET_CORE_OPTION_SEND_DISCONNECT;
655 if (h->inbound_notify != NULL)
657 if (h->inbound_hdr_only)
658 opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
660 opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
662 if (h->outbound_notify != NULL)
664 if (h->outbound_hdr_only)
665 opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
667 opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
669 init->options = htonl (opt);
670 ts = (uint16_t *) & init[1];
671 for (hpos = 0; hpos < h->hcnt; hpos++)
672 ts[hpos] = htons (h->handlers[hpos].type);
673 GNUNET_CLIENT_receive (h->client_notifications,
676 GNUNET_TIME_absolute_get_remaining
677 (h->startup_timeout));
678 return sizeof (struct InitMessage) + h->hcnt * sizeof (uint16_t);
683 * Connect to the core service. Note that the connection may
684 * complete (or fail) asynchronously.
686 * @param sched scheduler to use
687 * @param cfg configuration to use
688 * @param timeout after how long should we give up trying to connect to the core service?
689 * @param cls closure for the various callbacks that follow (including handlers in the handlers array)
690 * @param init callback to call on timeout or once we have successfully
691 * connected to the core service; note that timeout is only meaningful if init is not NULL
692 * @param connects function to call on peer connect, can be NULL
693 * @param disconnects function to call on peer disconnect / timeout, can be NULL
694 * @param inbound_notify function to call for all inbound messages, can be NULL
695 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
696 * GNUNET_MessageHeader and hence we do not need to give it the full message;
697 * can be used to improve efficiency, ignored if inbound_notify is NULLL
698 * @param outbound_notify function to call for all outbound messages, can be NULL
699 * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the
700 * GNUNET_MessageHeader and hence we do not need to give it the full message
701 * can be used to improve efficiency, ignored if outbound_notify is NULLL
702 * @param handlers callbacks for messages we care about, NULL-terminated
703 * @return handle to the core service (only useful for disconnect until 'init' is called);
704 * NULL on error (in this case, init is never called)
706 struct GNUNET_CORE_Handle *
707 GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
708 const struct GNUNET_CONFIGURATION_Handle *cfg,
709 struct GNUNET_TIME_Relative timeout,
711 GNUNET_CORE_StartupCallback init,
712 GNUNET_CORE_ConnectEventHandler connects,
713 GNUNET_CORE_DisconnectEventHandler disconnects,
714 GNUNET_CORE_MessageCallback inbound_notify,
715 int inbound_hdr_only,
716 GNUNET_CORE_MessageCallback outbound_notify,
717 int outbound_hdr_only,
718 const struct GNUNET_CORE_MessageHandler *handlers)
720 struct GNUNET_CORE_Handle *h;
722 h = GNUNET_malloc (sizeof (struct GNUNET_CORE_Handle));
727 h->connects = connects;
728 h->disconnects = disconnects;
729 h->inbound_notify = inbound_notify;
730 h->outbound_notify = outbound_notify;
731 h->inbound_hdr_only = inbound_hdr_only;
732 h->outbound_hdr_only = outbound_hdr_only;
733 h->handlers = handlers;
734 h->client_notifications = GNUNET_CLIENT_connect (sched, "core", cfg);
735 if (h->client_notifications == NULL)
740 h->startup_timeout = GNUNET_TIME_relative_to_absolute (timeout);
742 while (handlers[h->hcnt].callback != NULL)
744 GNUNET_assert (h->hcnt <
745 (GNUNET_SERVER_MAX_MESSAGE_SIZE -
746 sizeof (struct InitMessage)) / sizeof (uint16_t));
748 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
749 "Trying to connect to core service in next %llu ms.\n",
753 GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
754 sizeof (struct InitMessage) +
755 sizeof (uint16_t) * h->hcnt, timeout,
763 * Disconnect from the core service.
765 * @param handle connection to core to disconnect
768 GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
770 if (handle->th != NULL)
771 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
772 if (handle->solicit_transmit_req != NULL)
773 GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req);
774 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
775 GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
776 if (handle->client_notifications != NULL)
777 GNUNET_CLIENT_disconnect (handle->client_notifications, GNUNET_NO);
778 GNUNET_free_non_null (handle->solicit_buffer);
779 GNUNET_free (handle);
784 * Build the message requesting data transmission.
787 produce_send (void *cls, size_t size, void *buf)
789 struct GNUNET_CORE_TransmitHandle *th = cls;
790 struct GNUNET_CORE_Handle *h;
791 struct SendMessage *sm;
793 GNUNET_CONNECTION_TransmitReadyNotify notify;
799 /* timeout or error */
801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
802 "P2P transmission request for `%4s' timed out.\n",
803 GNUNET_i2s(&th->peer));
805 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
806 GNUNET_CORE_notify_transmit_ready_cancel (th);
807 trigger_next_request (h);
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
812 "Preparing for P2P transmission to `%4s'.\n",
813 GNUNET_i2s(&th->peer));
815 GNUNET_assert (th->timeout_task != GNUNET_SCHEDULER_NO_TASK);
816 sm = (struct SendMessage *) buf;
817 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
818 sm->priority = htonl (th->priority);
819 sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
822 notify_cls = th->notify_cls;
823 GNUNET_CORE_notify_transmit_ready_cancel (th);
824 trigger_next_request (h);
825 GNUNET_assert (size >= sizeof (struct SendMessage));
826 dt = notify (notify_cls, size - sizeof (struct SendMessage), &sm[1]);
830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
831 "Size of clients message to peer %s is 0!\n",
832 GNUNET_i2s(&th->peer));
834 /* client decided to send nothing! */
837 GNUNET_assert (dt >= sizeof (struct GNUNET_MessageHeader));
838 if (dt + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
843 sm->header.size = htons (dt + sizeof (struct SendMessage));
844 GNUNET_assert (dt + sizeof (struct SendMessage) <= size);
845 return dt + sizeof (struct SendMessage);
850 * Ask the core to call "notify" once it is ready to transmit the
851 * given number of bytes to the specified "target". If we are not yet
852 * connected to the specified peer, a call to this function will cause
853 * us to try to establish a connection.
855 * @param handle connection to core service
856 * @param priority how important is the message?
857 * @param maxdelay how long can the message wait?
858 * @param target who should receive the message,
859 * use NULL for this peer (loopback)
860 * @param notify_size how many bytes of buffer space does notify want?
861 * @param notify function to call when buffer space is available
862 * @param notify_cls closure for notify
863 * @return non-NULL if the notify callback was queued,
864 * NULL if we can not even queue the request (insufficient
865 * memory); if NULL is returned, "notify" will NOT be called.
867 struct GNUNET_CORE_TransmitHandle *
868 GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
869 unsigned int priority,
870 struct GNUNET_TIME_Relative maxdelay,
871 const struct GNUNET_PeerIdentity *target,
873 GNUNET_CONNECTION_TransmitReadyNotify notify,
876 struct GNUNET_CORE_TransmitHandle *th;
878 GNUNET_assert (notify_size + sizeof (struct SendMessage) <
879 GNUNET_SERVER_MAX_MESSAGE_SIZE);
880 th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle));
882 GNUNET_CONTAINER_DLL_insert_after (handle->pending_head,
883 handle->pending_tail,
884 handle->pending_tail,
886 th->get_message = &produce_send;
887 th->get_message_cls = th;
889 th->notify_cls = notify_cls;
891 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
892 th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched,
894 &timeout_request, th);
895 th->priority = priority;
896 th->msize = sizeof (struct SendMessage) + notify_size;
897 /* was the request queue previously empty? */
898 if ( (handle->pending_head == th) &&
899 (handle->th == NULL) )
900 trigger_next_request (handle);
906 * Cancel the specified transmission-ready notification.
908 * @param h handle that was returned by "notify_transmit_ready".
911 GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
914 struct GNUNET_CORE_Handle *handle = h->ch;
916 if (handle->submitted == h)
918 handle->submitted = NULL;
922 GNUNET_CONTAINER_DLL_remove (handle->pending_head,
923 handle->pending_tail,
926 if (h->timeout_task != GNUNET_SCHEDULER_NO_TASK)
927 GNUNET_SCHEDULER_cancel (handle->sched, h->timeout_task);
932 /* end of core_api.c */