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
60 * (pre-connects, no session key exchange yet).
62 GNUNET_CORE_ClientEventHandler pre_connects;
65 * Function to call whenever we're notified about a peer connecting.
67 GNUNET_CORE_ClientEventHandler connects;
70 * Function to call whenever we're notified about a peer disconnecting.
72 GNUNET_CORE_ClientEventHandler disconnects;
75 * Function to call whenever we receive an inbound message.
77 GNUNET_CORE_MessageCallback inbound_notify;
80 * Function to call whenever we receive an outbound message.
82 GNUNET_CORE_MessageCallback outbound_notify;
85 * Function handlers for messages of particular type.
87 const struct GNUNET_CORE_MessageHandler *handlers;
90 * Our connection to the service.
92 struct GNUNET_CLIENT_Connection *client;
95 * Handle for our current transmission request.
97 struct GNUNET_CLIENT_TransmitHandle *th;
100 * Head of doubly-linked list of pending requests.
102 struct GNUNET_CORE_TransmitHandle *pending_head;
105 * Tail of doubly-linked list of pending requests.
107 struct GNUNET_CORE_TransmitHandle *pending_tail;
110 * Currently submitted request (or NULL)
112 struct GNUNET_CORE_TransmitHandle *submitted;
115 * Currently submitted request based on solicitation (or NULL)
117 struct GNUNET_CORE_TransmitHandle *solicit_transmit_req;
120 * Buffer where we store a message for transmission in response
121 * to a traffic solicitation (or NULL).
123 char *solicit_buffer;
126 * How long to wait until we time out the connection attempt?
128 struct GNUNET_TIME_Absolute startup_timeout;
131 * ID of reconnect task (if any).
133 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
136 * Number of entries in the handlers array.
141 * For inbound notifications without a specific handler, do
142 * we expect to only receive headers?
144 int inbound_hdr_only;
147 * For outbound notifications without a specific handler, do
148 * we expect to only receive headers?
150 int outbound_hdr_only;
153 * Are we currently disconnected and hence unable to forward
161 * Handle for a transmission request.
163 struct GNUNET_CORE_TransmitHandle
167 * We keep active transmit handles in a doubly-linked list.
169 struct GNUNET_CORE_TransmitHandle *next;
172 * We keep active transmit handles in a doubly-linked list.
174 struct GNUNET_CORE_TransmitHandle *prev;
177 * Corresponding core handle.
179 struct GNUNET_CORE_Handle *ch;
182 * Function that will be called to get the actual request
183 * (once we are ready to transmit this request to the core).
184 * The function will be called with a NULL buffer to signal
187 GNUNET_CONNECTION_TransmitReadyNotify get_message;
190 * Closure for get_message.
192 void *get_message_cls;
195 * If this entry is for a configuration request, pointer
196 * to the information callback; otherwise NULL.
198 GNUNET_CORE_PeerConfigurationInfoCallback info;
206 * If this entry is for a transmission request, pointer
207 * to the notify callback; otherwise NULL.
209 GNUNET_CONNECTION_TransmitReadyNotify notify;
212 * Closure for notify.
217 * Peer the request is about.
219 struct GNUNET_PeerIdentity peer;
222 * Timeout for this handle.
224 struct GNUNET_TIME_Absolute timeout;
227 * ID of timeout task.
229 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
232 * How important is this message?
237 * Size of this request.
246 * Function called when we are ready to transmit our
247 * "START" message (or when this operation timed out).
250 * @param size number of bytes available in buf
251 * @param buf where the callee should write the message
252 * @return number of bytes written to buf
254 static size_t transmit_start (void *cls, size_t size, void *buf);
258 * Our current client connection went down. Clean it up
259 * and try to reconnect!
261 * @param h our handle to the core service
264 reconnect (struct GNUNET_CORE_Handle *h)
266 GNUNET_CLIENT_disconnect (h->client);
267 h->currently_down = GNUNET_YES;
268 h->client = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
269 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
270 sizeof (struct InitMessage) +
271 sizeof (uint16_t) * h->hcnt,
272 GNUNET_TIME_UNIT_SECONDS,
279 * The given request hit its timeout. Remove from the
280 * doubly-linked list and call the respective continuation.
282 * @param cls the transmit handle of the request that timed out
283 * @param tc context, can be NULL (!)
286 timeout_request (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
288 struct GNUNET_CORE_TransmitHandle *th = cls;
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 "Transmission request timed out.\n");
292 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
293 GNUNET_assert (0 == th->get_message (th->get_message_cls, 0, NULL));
298 * Function called when we are ready to transmit a request from our
299 * request list (or when this operation timed out).
302 * @param size number of bytes available in buf
303 * @param buf where the callee should write the message
304 * @return number of bytes written to buf
307 request_start (void *cls, size_t size, void *buf)
309 struct GNUNET_CORE_Handle *h = cls;
310 struct GNUNET_CORE_TransmitHandle *th;
314 th = h->pending_head;
317 timeout_request (th, NULL);
320 /* create new timeout task (in case core takes too long to respond!) */
321 th->timeout_task = GNUNET_SCHEDULER_add_delayed (h->sched,
322 GNUNET_TIME_absolute_get_remaining
324 &timeout_request, th);
325 /* remove th from doubly-linked pending list, move to submitted */
326 GNUNET_assert (th->prev == NULL);
327 h->pending_head = th->next;
328 if (th->next == NULL)
329 h->pending_tail = NULL;
331 th->next->prev = NULL;
332 GNUNET_assert (h->submitted == NULL);
334 GNUNET_assert (size >= th->msize);
335 ret = th->get_message (th->get_message_cls, size, buf);
336 GNUNET_assert (ret <= size);
342 * Check the list of pending requests, send the next
346 trigger_next_request (struct GNUNET_CORE_Handle *h)
348 struct GNUNET_CORE_TransmitHandle *th;
349 if (h->currently_down)
350 return; /* connection temporarily down */
351 if (NULL == (th = h->pending_head))
352 return; /* no requests pending */
353 GNUNET_assert (NULL == h->th);
354 if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task)
356 GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task);
357 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
359 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
361 GNUNET_TIME_absolute_get_remaining
370 * Handler for most 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_handler (void *cls, const struct GNUNET_MessageHeader *msg)
378 struct GNUNET_CORE_Handle *h = cls;
380 const struct ConnectNotifyMessage *cnm;
381 const struct NotifyTrafficMessage *ntm;
382 const struct ConfigurationInfoMessage *cim;
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_PRE_CONNECT:
405 if (NULL == h->pre_connects)
410 if (msize != sizeof (struct ConnectNotifyMessage))
415 cnm = (const struct ConnectNotifyMessage *) msg;
416 h->pre_connects (h->cls,
419 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
420 if (NULL == h->connects)
425 if (msize != sizeof (struct ConnectNotifyMessage))
430 cnm = (const struct ConnectNotifyMessage *) msg;
434 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
435 if (NULL == h->disconnects)
440 if (msize != sizeof (struct ConnectNotifyMessage))
445 cnm = (const struct ConnectNotifyMessage *) msg;
446 h->disconnects (h->cls,
449 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND:
451 sizeof (struct NotifyTrafficMessage) +
452 sizeof (struct GNUNET_MessageHeader))
457 ntm = (const struct NotifyTrafficMessage *) msg;
458 em = (const struct GNUNET_MessageHeader *) &ntm[1];
460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
461 "Received message of type %u from peer `%4s'\n",
462 ntohs (em->type), GNUNET_i2s (&ntm->peer));
464 if ((GNUNET_NO == h->inbound_hdr_only) &&
465 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
470 et = ntohs (em->type);
471 for (hpos = 0; hpos < h->hcnt; hpos++)
473 mh = &h->handlers[hpos];
476 if ((mh->expected_size != ntohs (em->size)) &&
477 (mh->expected_size != 0))
483 h->handlers[hpos].callback (h->cls, &ntm->peer, em))
485 /* error in processing, disconnect ! */
490 if (NULL != h->inbound_notify)
491 h->inbound_notify (h->cls, &ntm->peer, em);
493 case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
495 sizeof (struct NotifyTrafficMessage) +
496 sizeof (struct GNUNET_MessageHeader))
501 ntm = (const struct NotifyTrafficMessage *) msg;
502 em = (const struct GNUNET_MessageHeader *) &ntm[1];
503 if ((GNUNET_NO == h->outbound_hdr_only) &&
504 (msize != ntohs (em->size) + sizeof (struct NotifyTrafficMessage)))
509 if (NULL == h->outbound_notify)
514 h->outbound_notify (h->cls, &ntm->peer, em);
516 case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
517 if (msize != sizeof (struct ConfigurationInfoMessage))
522 if (NULL == h->submitted)
524 cim = (const struct ConfigurationInfoMessage *) msg;
526 /* process configuration data */
527 if (h->submitted->info != NULL)
528 h->submitted->info (h->submitted->info_cls,
531 ntohl (cim->bpm_out),
532 GNUNET_TIME_relative_ntoh (cim->latency),
533 (int) ntohl (cim->reserved_amount),
535 /* done, clean up! */
536 GNUNET_CORE_notify_transmit_ready_cancel (h->submitted); // HUH?
537 trigger_next_request (h);
543 GNUNET_CLIENT_receive (h->client,
544 &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
550 * Function called when we are ready to transmit our
551 * "START" message (or when this operation timed out).
554 * @param size number of bytes available in buf
555 * @param buf where the callee should write the message
556 * @return number of bytes written to buf
558 static size_t transmit_start (void *cls, size_t size, void *buf);
562 * Function called on the first message received from
563 * the service (contains our public key, etc.).
564 * Should trigger calling the init callback
565 * and then start our regular message processing.
568 * @param msg message received, NULL on timeout or fatal error
571 init_reply_handler (void *cls, const struct GNUNET_MessageHeader *msg)
573 struct GNUNET_CORE_Handle *h = cls;
574 const struct InitReplyMessage *m;
575 GNUNET_CORE_StartupCallback init;
576 struct GNUNET_PeerIdentity my_identity;
579 (ntohs (msg->size) != sizeof (struct InitReplyMessage)) ||
580 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY))
582 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
584 ("Error connecting to core service (failed to receive `%s' message).\n"),
586 GNUNET_break (msg == NULL);
587 transmit_start (h, 0, NULL);
590 m = (const struct InitReplyMessage *) msg;
591 /* start our message processing loop */
593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
595 ("Successfully connected to core service, starting processing loop.\n"));
597 h->currently_down = GNUNET_NO;
598 trigger_next_request (h);
599 GNUNET_CLIENT_receive (h->client,
600 &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
601 if (NULL != (init = h->init))
603 /* mark so we don't call init on reconnect */
606 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
607 _("Successfully connected to core service.\n"));
609 GNUNET_CRYPTO_hash (&m->publicKey,
611 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
612 &my_identity.hashPubKey);
613 init (h->cls, h, &my_identity, &m->publicKey);
619 reconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
621 struct GNUNET_CORE_Handle *h = cls;
622 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
628 * Function called when we are ready to transmit our
629 * "START" message (or when this operation timed out).
632 * @param size number of bytes available in buf
633 * @param buf where the callee should write the message
634 * @return number of bytes written to buf
637 transmit_start (void *cls, size_t size, void *buf)
639 struct GNUNET_CORE_Handle *h = cls;
640 struct InitMessage *init;
645 struct GNUNET_TIME_Relative delay;
650 if ((h->init == NULL) ||
651 (GNUNET_TIME_absolute_get ().value < h->startup_timeout.value))
653 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
654 _("Failed to connect to core service, retrying.\n"));
655 delay = GNUNET_TIME_absolute_get_remaining (h->startup_timeout);
656 if ((h->init == NULL) || (delay.value > 1000))
657 delay = GNUNET_TIME_UNIT_SECONDS;
660 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES);
662 GNUNET_SCHEDULER_add_delayed (h->sched,
663 delay, &reconnect_task, h);
666 /* timeout on initial connect */
667 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
668 _("Failed to connect to core service, giving up.\n"));
669 h->init (h->cls, NULL, NULL, NULL);
670 GNUNET_CORE_disconnect (h);
673 msize = h->hcnt * sizeof (uint16_t) + sizeof (struct InitMessage);
674 GNUNET_assert (size >= msize);
676 init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
677 init->header.size = htons (msize);
678 opt = GNUNET_CORE_OPTION_NOTHING;
679 if (h->pre_connects != NULL)
680 opt |= GNUNET_CORE_OPTION_SEND_PRE_CONNECT;
681 if (h->connects != NULL)
682 opt |= GNUNET_CORE_OPTION_SEND_CONNECT;
683 if (h->disconnects != NULL)
684 opt |= GNUNET_CORE_OPTION_SEND_DISCONNECT;
685 if (h->inbound_notify != NULL)
687 if (h->inbound_hdr_only)
688 opt |= GNUNET_CORE_OPTION_SEND_HDR_INBOUND;
690 opt |= GNUNET_CORE_OPTION_SEND_FULL_INBOUND;
692 if (h->outbound_notify != NULL)
694 if (h->outbound_hdr_only)
695 opt |= GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND;
697 opt |= GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND;
699 init->options = htonl (opt);
700 ts = (uint16_t *) & init[1];
701 for (hpos = 0; hpos < h->hcnt; hpos++)
702 ts[hpos] = htons (h->handlers[hpos].type);
703 GNUNET_CLIENT_receive (h->client,
706 GNUNET_TIME_absolute_get_remaining
707 (h->startup_timeout));
708 return sizeof (struct InitMessage) + h->hcnt * sizeof (uint16_t);
713 * Connect to the core service. Note that the connection may
714 * complete (or fail) asynchronously.
716 * @param sched scheduler to use
717 * @param cfg configuration to use
718 * @param timeout after how long should we give up trying to connect to the core service?
719 * @param cls closure for the various callbacks that follow (including handlers in the handlers array)
720 * @param init callback to call on timeout or once we have successfully
721 * connected to the core service; note that timeout is only meaningful if init is not NULL
722 * @param pre_connects function to call on peer pre-connect (no session key yet), can be NULL
723 * @param connects function to call on peer connect, can be NULL
724 * @param disconnects function to call on peer disconnect / timeout, can be NULL
725 * @param inbound_notify function to call for all inbound messages, can be NULL
726 * @param inbound_hdr_only set to GNUNET_YES if inbound_notify will only read the
727 * GNUNET_MessageHeader and hence we do not need to give it the full message;
728 * can be used to improve efficiency, ignored if inbound_notify is NULLL
729 * @param outbound_notify function to call for all outbound messages, can be NULL
730 * @param outbound_hdr_only set to GNUNET_YES if outbound_notify will only read the
731 * GNUNET_MessageHeader and hence we do not need to give it the full message
732 * can be used to improve efficiency, ignored if outbound_notify is NULLL
733 * @param handlers callbacks for messages we care about, NULL-terminated
734 * @return handle to the core service (only useful for disconnect until 'init' is called);
735 * NULL on error (in this case, init is never called)
737 struct GNUNET_CORE_Handle *
738 GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched,
739 const struct GNUNET_CONFIGURATION_Handle *cfg,
740 struct GNUNET_TIME_Relative timeout,
742 GNUNET_CORE_StartupCallback init,
743 GNUNET_CORE_ClientEventHandler pre_connects,
744 GNUNET_CORE_ClientEventHandler connects,
745 GNUNET_CORE_ClientEventHandler disconnects,
746 GNUNET_CORE_MessageCallback inbound_notify,
747 int inbound_hdr_only,
748 GNUNET_CORE_MessageCallback outbound_notify,
749 int outbound_hdr_only,
750 const struct GNUNET_CORE_MessageHandler *handlers)
752 struct GNUNET_CORE_Handle *h;
754 h = GNUNET_malloc (sizeof (struct GNUNET_CORE_Handle));
759 h->pre_connects = pre_connects;
760 h->connects = connects;
761 h->disconnects = disconnects;
762 h->inbound_notify = inbound_notify;
763 h->outbound_notify = outbound_notify;
764 h->inbound_hdr_only = inbound_hdr_only;
765 h->outbound_hdr_only = outbound_hdr_only;
766 h->handlers = handlers;
767 h->client = GNUNET_CLIENT_connect (sched, "core", cfg);
768 if (h->client == NULL)
773 h->startup_timeout = GNUNET_TIME_relative_to_absolute (timeout);
775 while (handlers[h->hcnt].callback != NULL)
777 GNUNET_assert (h->hcnt <
778 (GNUNET_SERVER_MAX_MESSAGE_SIZE -
779 sizeof (struct InitMessage)) / sizeof (uint16_t));
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Trying to connect to core service in next %llu ms.\n",
786 GNUNET_CLIENT_notify_transmit_ready (h->client,
787 sizeof (struct InitMessage) +
788 sizeof (uint16_t) * h->hcnt, timeout,
796 * Disconnect from the core service.
798 * @param handle connection to core to disconnect
801 GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
803 if (handle->th != NULL)
804 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
805 if (handle->solicit_transmit_req != NULL)
806 GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req);
807 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
808 GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
809 GNUNET_CLIENT_disconnect (handle->client);
810 GNUNET_free_non_null (handle->solicit_buffer);
811 GNUNET_free (handle);
816 * Build the message requesting data transmission.
819 produce_send (void *cls, size_t size, void *buf)
821 struct GNUNET_CORE_TransmitHandle *th = cls;
822 struct GNUNET_CORE_Handle *h;
823 struct SendMessage *sm;
825 GNUNET_CONNECTION_TransmitReadyNotify notify;
831 /* timeout or error */
833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
834 "P2P transmission request for `%4s' timed out.\n",
835 GNUNET_i2s(&th->peer));
837 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
838 GNUNET_CORE_notify_transmit_ready_cancel (th);
839 trigger_next_request (h);
843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
844 "Preparing for P2P transmission to `%4s'.\n",
845 GNUNET_i2s(&th->peer));
847 GNUNET_assert (th->timeout_task != GNUNET_SCHEDULER_NO_TASK);
848 sm = (struct SendMessage *) buf;
849 sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND);
850 sm->priority = htonl (th->priority);
851 sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
854 notify_cls = th->notify_cls;
855 GNUNET_CORE_notify_transmit_ready_cancel (th);
856 trigger_next_request (h);
857 GNUNET_assert (size >= sizeof (struct SendMessage));
858 dt = notify (notify_cls, size - sizeof (struct SendMessage), &sm[1]);
861 /* client decided to send nothing! */
864 GNUNET_assert (dt >= sizeof (struct GNUNET_MessageHeader));
865 sm->header.size = htons (dt + sizeof (struct SendMessage));
866 GNUNET_assert (dt + sizeof (struct SendMessage) < size);
867 return dt + sizeof (struct SendMessage);
872 * Ask the core to call "notify" once it is ready to transmit the
873 * given number of bytes to the specified "target". If we are not yet
874 * connected to the specified peer, a call to this function will cause
875 * us to try to establish a connection.
877 * @param handle connection to core service
878 * @param priority how important is the message?
879 * @param maxdelay how long can the message wait?
880 * @param target who should receive the message,
881 * use NULL for this peer (loopback)
882 * @param notify_size how many bytes of buffer space does notify want?
883 * @param notify function to call when buffer space is available
884 * @param notify_cls closure for notify
885 * @return non-NULL if the notify callback was queued,
886 * NULL if we can not even queue the request (insufficient
887 * memory); if NULL is returned, "notify" will NOT be called.
889 struct GNUNET_CORE_TransmitHandle *
890 GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
891 unsigned int priority,
892 struct GNUNET_TIME_Relative maxdelay,
893 const struct GNUNET_PeerIdentity *target,
895 GNUNET_CONNECTION_TransmitReadyNotify notify,
898 struct GNUNET_CORE_TransmitHandle *th;
900 GNUNET_assert (notify_size + sizeof (struct SendMessage) <
901 GNUNET_SERVER_MAX_MESSAGE_SIZE);
902 th = GNUNET_malloc (sizeof (struct GNUNET_CORE_TransmitHandle));
905 th->prev = handle->pending_tail;
906 if (handle->pending_tail == NULL)
907 handle->pending_head = th;
909 handle->pending_tail->next = th;
910 th->get_message = &produce_send;
911 th->get_message_cls = th;
913 th->notify_cls = notify_cls;
915 th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
916 th->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->sched,
918 &timeout_request, th);
919 th->priority = priority;
920 th->msize = sizeof (struct SendMessage) + notify_size;
921 /* was the request queue previously empty? */
922 if ( (handle->pending_head == th) &&
923 (handle->th == NULL) )
924 trigger_next_request (handle);
930 * Cancel the specified transmission-ready notification.
932 * @param h handle that was returned by "notify_transmit_ready".
935 GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle
938 struct GNUNET_CORE_Handle *handle = h->ch;
940 if (handle->submitted == h)
942 handle->submitted = NULL;
947 handle->pending_head = h->next;
949 h->prev->next = h->next;
951 handle->pending_tail = h->prev;
953 h->next->prev = h->prev;
955 if (h->timeout_task != GNUNET_SCHEDULER_NO_TASK)
956 GNUNET_SCHEDULER_cancel (handle->sched, h->timeout_task);
961 /* end of core_api.c */