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 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 #include "gnunet_constants.h"
29 #include "gnunet_core_service.h"
34 * Context for the core service connection.
36 struct GNUNET_CORE_Handle
42 struct GNUNET_SCHEDULER_Handle *sched;
45 * Configuration we're using.
47 const struct GNUNET_CONFIGURATION_Handle *cfg;
50 * Closure for the various callbacks.
55 * Function to call once we've handshaked with the core service.
57 GNUNET_CORE_StartupCallback init;
60 * Function to call whenever we're notified about a peer connecting.
62 GNUNET_CORE_ConnectEventHandler connects;
65 * Function to call whenever we're notified about a peer disconnecting.
67 GNUNET_CORE_DisconnectEventHandler disconnects;
70 * Function to call whenever we receive an inbound message.
72 GNUNET_CORE_MessageCallback inbound_notify;
75 * Function to call whenever we receive an outbound message.
77 GNUNET_CORE_MessageCallback outbound_notify;
80 * Function handlers for messages of particular type.
82 const struct GNUNET_CORE_MessageHandler *handlers;
85 * Our connection to the service for notifications.
87 struct GNUNET_CLIENT_Connection *client_notifications;
90 * Handle for our current transmission request.
92 struct GNUNET_CLIENT_TransmitHandle *cth;
95 * Head of doubly-linked list of pending requests.
97 struct GNUNET_CORE_TransmitHandle *pending_head;
100 * Tail of doubly-linked list of pending requests.
102 struct GNUNET_CORE_TransmitHandle *pending_tail;
105 * Currently submitted request (or NULL)
107 struct GNUNET_CORE_TransmitHandle *submitted;
110 * Currently submitted request based on solicitation (or NULL)
112 struct GNUNET_CORE_TransmitHandle *solicit_transmit_req;
115 * Buffer where we store a message for transmission in response
116 * to a traffic solicitation (or NULL).
118 char *solicit_buffer;
121 * How long to wait until we time out the connection attempt?
123 struct GNUNET_TIME_Absolute startup_timeout;
126 * ID of reconnect task (if any).
128 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
131 * Number of entries in the handlers array.
136 * For inbound notifications without a specific handler, do
137 * we expect to only receive headers?
139 int inbound_hdr_only;
142 * For outbound notifications without a specific handler, do
143 * we expect to only receive headers?
145 int outbound_hdr_only;
148 * Are we currently disconnected and hence unable to forward
156 * Handle for a transmission request.
158 struct GNUNET_CORE_TransmitHandle
162 * We keep active transmit handles in a doubly-linked list.
164 struct GNUNET_CORE_TransmitHandle *next;
167 * We keep active transmit handles in a doubly-linked list.
169 struct GNUNET_CORE_TransmitHandle *prev;
172 * Corresponding core handle.
174 struct GNUNET_CORE_Handle *ch;
177 * Function that will be called to get the actual request
178 * (once we are ready to transmit this request to the core).
179 * The function will be called with a NULL buffer to signal
182 GNUNET_CONNECTION_TransmitReadyNotify get_message;
185 * Closure for get_message.
187 void *get_message_cls;
190 * If this entry is for a transmission request, pointer
191 * to the notify callback; otherwise NULL.
193 GNUNET_CONNECTION_TransmitReadyNotify notify;
196 * Closure for notify.
201 * Peer the request is about.
203 struct GNUNET_PeerIdentity peer;
206 * Timeout for this handle.
208 struct GNUNET_TIME_Absolute timeout;
211 * ID of timeout task.
213 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
216 * How important is this message?
221 * Size of this request.
230 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
234 * Function called when we are ready to transmit our
235 * "START" message (or when this operation timed out).
238 * @param size number of bytes available in buf
239 * @param buf where the callee should write the message
240 * @return number of bytes written to buf
242 static size_t transmit_start (void *cls, size_t size, void *buf);
246 * Our current client connection went down. Clean it up
247 * and try to reconnect!
249 * @param h our handle to the core service
252 reconnect (struct GNUNET_CORE_Handle *h)
255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
256 "Reconnecting to CORE service\n");
258 if (h->client_notifications != NULL)
259 GNUNET_CLIENT_disconnect (h->client_notifications, GNUNET_NO);
260 h->currently_down = GNUNET_YES;
261 h->client_notifications = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
262 if (h->client_notifications == NULL)
263 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->sched,
264 GNUNET_TIME_UNIT_SECONDS,
268 h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
269 sizeof (struct InitMessage) +
270 sizeof (uint16_t) * h->hcnt,
271 GNUNET_TIME_UNIT_SECONDS,
278 * The given request hit its timeout. Remove from the
279 * doubly-linked list and call the respective continuation.
281 * @param cls the transmit handle of the request that timed out
282 * @param tc context, can be NULL (!)
285 timeout_request (void *cls,
286 const struct GNUNET_SCHEDULER_TaskContext *tc)
288 struct GNUNET_CORE_TransmitHandle *th = cls;
290 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Signalling timeout of request for transmission to CORE service\n");
295 GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL));
300 * Function called when we are ready to transmit a request from our
301 * request list (or when this operation timed out).
304 * @param size number of bytes available in buf
305 * @param buf where the callee should write the message
306 * @return number of bytes written to buf
309 request_start (void *cls, size_t size, void *buf)
311 struct GNUNET_CORE_Handle *h = cls;
312 struct GNUNET_CORE_TransmitHandle *th;
316 th = h->pending_head;
319 timeout_request (th, NULL);
322 GNUNET_CONTAINER_DLL_remove (h->pending_head,
325 GNUNET_assert (h->submitted == NULL);
327 GNUNET_assert (size >= th->msize);
328 ret = th->get_message (th->get_message_cls, size, buf);
329 GNUNET_assert (ret <= size);
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Transmitting %u bytes to core\n",
340 * Check the list of pending requests, send the next
344 trigger_next_request (struct GNUNET_CORE_Handle *h)
346 struct GNUNET_CORE_TransmitHandle *th;
348 if (h->currently_down)
351 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
352 "In trigger_next_request, connection currently down...\n");
354 return; /* connection temporarily down */
356 if (NULL == (th = h->pending_head))
357 return; /* no requests pending */
358 GNUNET_assert (NULL == h->cth);
359 h->cth = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
361 GNUNET_TIME_absolute_get_remaining
370 * Handler for notification messages received from the core.
372 * @param cls our "struct GNUNET_CORE_Handle"
373 * @param msg the message received from the core service
376 main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
378 struct GNUNET_CORE_Handle *h = cls;
380 const struct ConnectNotifyMessage *cnm;
381 const struct DisconnectNotifyMessage *dnm;
382 const struct NotifyTrafficMessage *ntm;
383 const struct GNUNET_MessageHeader *em;
386 const struct GNUNET_CORE_MessageHandler *mh;
390 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
392 ("Client was disconnected from core service, trying to reconnect.\n"));
396 msize = ntohs (msg->size);
398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
399 "Processing message of type %u and size %u from core service\n",
400 ntohs (msg->type), msize);
402 switch (ntohs (msg->type))
404 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
405 if (NULL == h->connects)
410 if (msize != sizeof (struct ConnectNotifyMessage))
415 cnm = (const struct ConnectNotifyMessage *) msg;
418 GNUNET_TIME_relative_ntoh (cnm->latency),
419 ntohl (cnm->distance));
421 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
422 if (NULL == h->disconnects)
427 if (msize != sizeof (struct DisconnectNotifyMessage))
432 dnm = (const struct DisconnectNotifyMessage *) msg;
433 h->disconnects (h->cls,
436 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
438 sizeof (struct NotifyTrafficMessage) +
439 sizeof (struct GNUNET_MessageHeader))
444 ntm = (const struct NotifyTrafficMessage *) msg;
445 em = (const struct GNUNET_MessageHeader *) &ntm[1];
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "Received message of type %u and size %u from peer `%4s'\n",
451 GNUNET_i2s (&ntm->peer));
453 if ((GNUNET_NO == h->inbound_hdr_only) &&
454 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
459 et = ntohs (em->type);
460 for (hpos = 0; hpos < h->hcnt; hpos++)
462 mh = &h->handlers[hpos];
465 if ((mh->expected_size != ntohs (em->size)) &&
466 (mh->expected_size != 0))
472 h->handlers[hpos].callback (h->cls, &ntm->peer, em,
473 GNUNET_TIME_relative_ntoh (ntm->latency),
474 ntohl (ntm->distance)))
476 /* error in processing, disconnect ! */
481 if (NULL != h->inbound_notify)
482 h->inbound_notify (h->cls, &ntm->peer, em,
483 GNUNET_TIME_relative_ntoh (ntm->latency),
484 ntohl (ntm->distance));
486 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
488 sizeof (struct NotifyTrafficMessage) +
489 sizeof (struct GNUNET_MessageHeader))
494 ntm = (const struct NotifyTrafficMessage *) msg;
495 em = (const struct GNUNET_MessageHeader *) &ntm[1];
496 if ((GNUNET_NO == h->outbound_hdr_only) &&
497 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
502 if (NULL == h->outbound_notify)
507 h->outbound_notify (h->cls, &ntm->peer, em,
508 GNUNET_TIME_relative_ntoh (ntm->latency),
509 ntohl (ntm->distance));
515 GNUNET_CLIENT_receive (h->client_notifications,
516 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
521 * Function called when we are ready to transmit our
522 * "START" message (or when this operation timed out).
525 * @param size number of bytes available in buf
526 * @param buf where the callee should write the message
527 * @return number of bytes written to buf
529 static size_t transmit_start (void *cls, size_t size, void *buf);
533 * Function called on the first message received from
534 * the service (contains our public key, etc.).
535 * Should trigger calling the init callback
536 * and then start our regular message processing.
539 * @param msg message received, NULL on timeout or fatal error
542 init_reply_handler (void *cls, const struct GNUNET_MessageHeader *msg)
544 struct GNUNET_CORE_Handle *h = cls;
545 const struct InitReplyMessage *m;
546 GNUNET_CORE_StartupCallback init;
547 struct GNUNET_PeerIdentity my_identity;
550 (ntohs (msg->size) != sizeof (struct InitReplyMessage)) ||
551 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY))
555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
557 ("Error connecting to core service (failed to receive `%s' message, got message of type %u and size %u).\n"),
566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
567 _("Failed to connect to core service, will retry.\n"));
570 transmit_start (h, 0, NULL);
573 m = (const struct InitReplyMessage *) msg;
574 /* start our message processing loop */
576 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
577 "Successfully connected to core service, starting processing loop.\n");
579 h->currently_down = GNUNET_NO;
580 trigger_next_request (h);
581 GNUNET_CLIENT_receive (h->client_notifications,
582 &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
583 if (NULL != (init = h->init))
585 /* mark so we don't call init on reconnect */
587 GNUNET_CRYPTO_hash (&m->publicKey,
589 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
590 &my_identity.hashPubKey);
591 init (h->cls, h, &my_identity, &m->publicKey);
597 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
599 struct GNUNET_CORE_Handle *h = cls;
600 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
606 * Function called when we are ready to transmit our
607 * "START" message (or when this operation timed out).
610 * @param size number of bytes available in buf
611 * @param buf where the callee should write the message
612 * @return number of bytes written to buf
615 transmit_start (void *cls, size_t size, void *buf)
617 struct GNUNET_CORE_Handle *h = cls;
618 struct InitMessage *init;
623 struct GNUNET_TIME_Relative delay;
628 if ((h->init == NULL) ||
629 (GNUNET_TIME_absolute_get ().value < h->startup_timeout.value))
631 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
632 _("Failed to connect to core service, retrying.\n"));
633 delay = GNUNET_TIME_absolute_get_remaining (h->startup_timeout);
634 if ((h->init == NULL) || (delay.value > 1000))
635 delay = GNUNET_TIME_UNIT_SECONDS;
638 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
640 GNUNET_SCHEDULER_add_delayed (h->sched,
641 delay, &reconnect_task, h);
644 /* timeout on initial connect */
645 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
646 _("Failed to connect to core service, giving up.\n"));
647 h->init (h->cls, NULL, NULL, NULL);
648 GNUNET_CORE_disconnect (h);
651 msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage);
652 GNUNET_assert (size >= msize);
654 init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
655 init->header.size = htons (msize);
656 opt = GNUNET_CORE_OPTION_NOTHING;
657 if (h->connects != NULL)
658 opt |= GNUNET_CORE_OPTION_SEND_CONNECT;
659 if (h->disconnects != NULL)
660 opt |= GNUNET_CORE_OPTION_SEND_DISCONNECT;
661 if (h->inbound_notify != NULL)
663 if (h->inbound_hdr_only)
664 opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
666 opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
668 if (h->outbound_notify != NULL)
670 if (h->outbound_hdr_only)
671 opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
673 opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
675 init->options = htonl (opt);
676 ts = (uint16_t *) & init[1];
677 for (hpos = 0; hpos < h->hcnt; hpos++)
678 ts[hpos] = htons (h->handlers[hpos].type);
679 GNUNET_CLIENT_receive (h->client_notifications,
682 GNUNET_TIME_absolute_get_remaining
683 (h->startup_timeout));
684 return sizeof (struct InitMessage) + h->hcnt * sizeof (uint16_t);
689 * Connect to the core service. Note that the connection may
690 * complete (or fail) asynchronously.
692 * @param sched scheduler to use
693 * @param cfg configuration to use
694 * @param timeout after how long should we give up trying to connect to the core service?
695 * @param cls closure for the various callbacks that follow (including handlers in the handlers array)
696 * @param init callback to call on timeout or once we have successfully
697 * connected to the core service; note that timeout is only meaningful if init is not NULL
698 * @param connects function to call on peer connect, can be NULL
699 * @param disconnects function to call on peer disconnect / timeout, can be NULL
700 * @param inbound_notify function to call for all inbound messages, can be NULL
701 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
702 * GNUNET_MessageHeader and hence we do not need to give it the full message;
703 * can be used to improve efficiency, ignored if inbound_notify is NULLL
704 * @param outbound_notify function to call for all outbound messages, can be NULL
705 * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the
706 * GNUNET_MessageHeader and hence we do not need to give it the full message
707 * can be used to improve efficiency, ignored if outbound_notify is NULLL
708 * @param handlers callbacks for messages we care about, NULL-terminated
709 * @return handle to the core service (only useful for disconnect until 'init' is called);
710 * NULL on error (in this case, init is never called)
712 struct GNUNET_CORE_Handle *
713 GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
714 const struct GNUNET_CONFIGURATION_Handle *cfg,
715 struct GNUNET_TIME_Relative timeout,
717 GNUNET_CORE_StartupCallback init,
718 GNUNET_CORE_ConnectEventHandler connects,
719 GNUNET_CORE_DisconnectEventHandler disconnects,
720 GNUNET_CORE_MessageCallback inbound_notify,
721 int inbound_hdr_only,
722 GNUNET_CORE_MessageCallback outbound_notify,
723 int outbound_hdr_only,
724 const struct GNUNET_CORE_MessageHandler *handlers)
726 struct GNUNET_CORE_Handle *h;
728 h = GNUNET_malloc (sizeof (struct GNUNET_CORE_Handle));
733 h->connects = connects;
734 h->disconnects = disconnects;
735 h->inbound_notify = inbound_notify;
736 h->outbound_notify = outbound_notify;
737 h->inbound_hdr_only = inbound_hdr_only;
738 h->outbound_hdr_only = outbound_hdr_only;
739 h->handlers = handlers;
740 h->client_notifications = GNUNET_CLIENT_connect (sched, "core", cfg);
741 if (h->client_notifications == NULL)
746 h->startup_timeout = GNUNET_TIME_relative_to_absolute (timeout);
748 while (handlers[h->hcnt].callback != NULL)
750 GNUNET_assert (h->hcnt <
751 (GNUNET_SERVER_MAX_MESSAGE_SIZE -
752 sizeof (struct InitMessage)) / sizeof (uint16_t));
754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
755 "Trying to connect to core service in next %llu ms.\n",
759 GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
760 sizeof (struct InitMessage) +
761 sizeof (uint16_t) * h->hcnt, timeout,
769 * Disconnect from the core service.
771 * @param handle connection to core to disconnect
774 GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
776 if (handle->cth != NULL)
777 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->cth);
778 if (handle->solicit_transmit_req != NULL)
779 GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req);
780 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
781 GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
782 if (handle->client_notifications != NULL)
783 GNUNET_CLIENT_disconnect (handle->client_notifications, GNUNET_NO);
784 GNUNET_free_non_null (handle->solicit_buffer);
785 GNUNET_free (handle);
790 * Build the message requesting data transmission.
793 produce_send (void *cls, size_t size, void *buf)
795 struct GNUNET_CORE_TransmitHandle *th = cls;
796 struct GNUNET_CORE_Handle *h;
797 struct SendMessage *sm;
799 GNUNET_CONNECTION_TransmitReadyNotify notify;
805 /* timeout or error */
807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
808 "P2P transmission request for `%4s' timed out.\n",
809 GNUNET_i2s(&th->peer));
811 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
812 GNUNET_CORE_notify_transmit_ready_cancel (th);
813 trigger_next_request (h);
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 size = GNUNET_MIN (size,
826 GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
827 GNUNET_assert (size >= sizeof (struct SendMessage));
828 dt = notify (notify_cls, size - sizeof (struct SendMessage), &sm[1]);
832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
833 "Size of clients message to peer %s is 0!\n",
834 GNUNET_i2s(&th->peer));
836 /* client decided to send nothing! */
840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
841 "Produced SEND message to core with %u bytes payload\n",
844 GNUNET_assert (dt >= sizeof (struct GNUNET_MessageHeader));
845 if (dt + sizeof (struct SendMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
852 "Preparing for P2P transmission of %u bytes to `%4s'.\n",
854 GNUNET_i2s(&th->peer));
856 sm->header.size = htons (dt + sizeof (struct SendMessage));
857 GNUNET_assert (dt + sizeof (struct SendMessage) <= size);
858 return dt + sizeof (struct SendMessage);
863 * Ask the core to call "notify" once it is ready to transmit the
864 * given number of bytes to the specified "target". If we are not yet
865 * connected to the specified peer, a call to this function will cause
866 * us to try to establish a connection.
868 * @param handle connection to core service
869 * @param priority how important is the message?
870 * @param maxdelay how long can the message wait?
871 * @param target who should receive the message,
872 * use NULL for this peer (loopback)
873 * @param notify_size how many bytes of buffer space does notify want?
874 * @param notify function to call when buffer space is available
875 * @param notify_cls closure for notify
876 * @return non-NULL if the notify callback was queued,
877 * NULL if we can not even queue the request (insufficient
878 * memory); if NULL is returned, "notify" will NOT be called.
880 struct GNUNET_CORE_TransmitHandle *
881 GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
882 unsigned int priority,
883 struct GNUNET_TIME_Relative maxdelay,
884 const struct GNUNET_PeerIdentity *target,
886 GNUNET_CONNECTION_TransmitReadyNotify notify,
889 struct GNUNET_CORE_TransmitHandle *th;
891 GNUNET_assert (notify_size + sizeof (struct SendMessage) <
892 GNUNET_SERVER_MAX_MESSAGE_SIZE);
893 th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle));
895 GNUNET_CONTAINER_DLL_insert_after (handle->pending_head,
896 handle->pending_tail,
897 handle->pending_tail,
899 th->get_message = &produce_send;
900 th->get_message_cls = th;
902 th->notify_cls = notify_cls;
904 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
905 th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched,
907 &timeout_request, th);
908 th->priority = priority;
909 th->msize = sizeof (struct SendMessage) + notify_size;
910 /* was the request queue previously empty? */
911 if ( (handle->pending_head == th) &&
912 (handle->cth == NULL) )
913 trigger_next_request (handle);
919 * Cancel the specified transmission-ready notification.
921 * @param th handle that was returned by "notify_transmit_ready".
924 GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
927 struct GNUNET_CORE_Handle *h = th->ch;
929 if (h->submitted == th)
932 GNUNET_CONTAINER_DLL_remove (h->pending_head,
935 if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
936 GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task);
941 /* end of core_api.c */