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 transport/transport_api.c
23 * @brief library to access the low-level P2P IO service
24 * @author Christian Grothoff
27 #include "gnunet_bandwidth_lib.h"
28 #include "gnunet_client_lib.h"
29 #include "gnunet_constants.h"
30 #include "gnunet_container_lib.h"
31 #include "gnunet_arm_service.h"
32 #include "gnunet_hello_lib.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_server_lib.h"
35 #include "gnunet_time_lib.h"
36 #include "gnunet_transport_service.h"
37 #include "transport.h"
40 * After how long do we give up on transmitting a HELLO
43 #define OFFER_HELLO_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
46 * After how long do we automatically retry an unsuccessful
49 #define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 750)
52 * How long should ARM wait when starting up the
53 * transport service before reporting back?
55 #define START_SERVICE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
58 * How long should ARM wait when stopping the
59 * transport service before reporting back?
61 #define STOP_SERVICE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
65 * What stage are we in for transmission processing?
75 * Message in local queue, not given to service.
80 * Message given to service, not confirmed (no SEND_OK).
85 * One message was given to service and before it was confirmed,
86 * another one was already queued (waiting for SEND_OK to pass on
89 TS_TRANSMITTED_QUEUED = 3
94 * Handle for a transmission-ready request.
96 struct GNUNET_TRANSPORT_TransmitHandle
100 * Neighbour for this handle, NULL for control-traffic.
102 struct NeighbourList *neighbour;
105 * Function to call when notify_size bytes are available
108 GNUNET_CONNECTION_TransmitReadyNotify notify;
111 * Closure for notify.
116 * transmit_ready task Id. The task is used to introduce the
117 * artificial delay that may be required to maintain the bandwidth
118 * limits. Later, this will be the ID of the "transmit_timeout"
119 * task which is used to signal a timeout if the transmission could
120 * not be done in a timely fashion.
122 GNUNET_SCHEDULER_TaskIdentifier notify_delay_task;
125 * Timeout for this request.
127 struct GNUNET_TIME_Absolute timeout;
130 * How many bytes is our notify callback waiting for?
135 * How important is this message?
137 unsigned int priority;
143 * Handle for a control message queue entry.
145 struct ControlMessage
149 * This is a doubly-linked list.
151 struct ControlMessage *next;
154 * This is a doubly-linked list.
156 struct ControlMessage *prev;
159 * Overall transport handle.
161 struct GNUNET_TRANSPORT_Handle *h;
164 * Function to call when notify_size bytes are available
167 GNUNET_CONNECTION_TransmitReadyNotify notify;
170 * Closure for notify.
175 * transmit_ready task Id. The task is used to introduce the
176 * artificial delay that may be required to maintain the bandwidth
177 * limits. Later, this will be the ID of the "transmit_timeout"
178 * task which is used to signal a timeout if the transmission could
179 * not be done in a timely fashion.
181 GNUNET_SCHEDULER_TaskIdentifier notify_delay_task;
184 * How many bytes is our notify callback waiting for?
192 * Entry in linked list of all of our current neighbours.
198 * This is a linked list.
200 struct NeighbourList *next;
203 * Overall transport handle.
205 struct GNUNET_TRANSPORT_Handle *h;
208 * Active transmit handle; available if 'transmit_forbidden'
211 struct GNUNET_TRANSPORT_TransmitHandle transmit_handle;
214 * Identity of this neighbour.
216 struct GNUNET_PeerIdentity id;
219 * Outbound bandwidh tracker.
221 struct GNUNET_BANDWIDTH_Tracker out_tracker;
224 * Set to GNUNET_NO if we are currently allowed to accept a
225 * message to the transport service for this peer, GNUNET_YES
226 * if we have one and are waiting for transmission, GNUNET_SYSERR
227 * if we are waiting for confirmation AND have already accepted
228 * yet another message.
230 enum TransmitStage transmit_stage;
233 * Have we received a notification that this peer is connected
242 * Linked list of requests from clients for our HELLO that were
249 * This is a linked list.
251 struct HelloWaitList *next;
254 * Reference back to our transport handle.
256 struct GNUNET_TRANSPORT_Handle *handle;
259 * Callback to call once we got our HELLO.
261 GNUNET_TRANSPORT_HelloUpdateCallback rec;
272 * Handle for the transport service (includes all of the
273 * state for the transport service).
275 struct GNUNET_TRANSPORT_Handle
279 * Closure for the callbacks.
284 * Function to call for received data.
286 GNUNET_TRANSPORT_ReceiveCallback rec;
289 * function to call on connect events
291 GNUNET_TRANSPORT_NotifyConnect nc_cb;
294 * function to call on disconnect events
296 GNUNET_TRANSPORT_NotifyDisconnect nd_cb;
299 * Head of DLL of control messages.
301 struct ControlMessage *control_head;
304 * Tail of DLL of control messages.
306 struct ControlMessage *control_tail;
309 * The current HELLO message for this peer. Updated
310 * whenever transports change their addresses.
312 struct GNUNET_HELLO_Message *my_hello;
315 * My client connection to the transport service.
317 struct GNUNET_CLIENT_Connection *client;
320 * Handle to our registration with the client for notification.
322 struct GNUNET_CLIENT_TransmitHandle *network_handle;
325 * Linked list of pending requests for our HELLO.
327 struct HelloWaitList *hwl_head;
332 const struct GNUNET_CONFIGURATION_Handle *cfg;
335 * Linked list of the current neighbours of this peer.
337 struct NeighbourList *neighbours;
340 * Peer identity as assumed by this process, or all zeros.
342 struct GNUNET_PeerIdentity self;
345 * ID of the task trying to reconnect to the service.
347 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
350 * ID of the task trying to trigger transmission for a peer
351 * while maintaining bandwidth quotas.
353 GNUNET_SCHEDULER_TaskIdentifier quota_task;
356 * Delay until we try to reconnect.
358 struct GNUNET_TIME_Relative reconnect_delay;
361 * Set once we are in the process of disconnecting from the
367 * Should we check that 'self' matches what the service thinks?
368 * (if GNUNET_NO, then 'self' is all zeros!).
374 // FIXME: replace with hash map!
376 * Get the neighbour list entry for the given peer
378 * @param h our context
379 * @param peer peer to look up
380 * @return NULL if no such peer entry exists
382 static struct NeighbourList *
383 neighbour_find (struct GNUNET_TRANSPORT_Handle *h,
384 const struct GNUNET_PeerIdentity *peer)
386 struct NeighbourList *pos;
389 while ((pos != NULL) &&
390 (0 != memcmp (peer, &pos->id, sizeof (struct GNUNET_PeerIdentity))))
397 * Schedule the task to send one message, either from the control
398 * list or the peer message queues to the service.
400 static void schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
404 * Function called by the scheduler when the timeout for bandwidth
405 * availablility for the target neighbour is reached.
407 * @param cls the 'struct GNUNET_TRANSPORT_Handle*'
408 * @param tc scheduler context
411 quota_transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
413 struct GNUNET_TRANSPORT_Handle *h = cls;
415 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
416 schedule_transmission (h);
421 * Figure out which transmission to a peer can be done right now.
422 * If none can, schedule a task to call 'schedule_transmission'
423 * whenever a peer transmission can be done in the future and
424 * return NULL. Otherwise return the next transmission to be
427 * @param h handle to transport
428 * @return NULL to wait longer before doing any peer transmissions
430 static struct GNUNET_TRANSPORT_TransmitHandle *
431 schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h)
433 struct GNUNET_TRANSPORT_TransmitHandle *ret;
434 struct GNUNET_TRANSPORT_TransmitHandle *th;
435 struct NeighbourList *n;
436 struct NeighbourList *next;
437 struct GNUNET_TIME_Relative retry_time;
438 struct GNUNET_TIME_Relative duration;
440 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
442 GNUNET_SCHEDULER_cancel (h->quota_task);
443 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
445 retry_time = GNUNET_TIME_UNIT_FOREVER_REL;
447 next = h->neighbours;
448 while (NULL != (n = next))
451 if (n->transmit_stage != TS_QUEUED)
452 continue; /* not eligible */
453 if (n->is_connected != GNUNET_YES)
456 th = &n->transmit_handle;
457 GNUNET_break (n == th->neighbour);
458 /* check outgoing quota */
459 duration = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
460 th->notify_size - sizeof (struct OutboundMessage));
461 struct GNUNET_TIME_Absolute duration_abs = GNUNET_TIME_relative_to_absolute (duration);
462 if (th->timeout.abs_value < duration_abs.abs_value)
464 /* signal timeout! */
466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
467 "Would need %llu ms before bandwidth is available for delivery to `%4s', that is too long. Signaling timeout.\n",
469 GNUNET_i2s (&n->id));
471 if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
473 GNUNET_SCHEDULER_cancel (th->notify_delay_task);
474 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
476 n->transmit_stage = TS_NEW;
477 if (NULL != th->notify)
478 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
481 if (duration.rel_value > 0)
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "Need more bandwidth (%u b/s allowed, %u b needed), delaying delivery to `%4s' by %llu ms\n",
486 (unsigned int) n->out_tracker.available_bytes_per_s__,
487 (unsigned int) th->notify_size - sizeof (struct OutboundMessage),
491 retry_time = GNUNET_TIME_relative_min (retry_time,
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
497 "Have %u bytes of bandwidth available for transmission to `%4s' right now\n",
498 th->notify_size - sizeof (struct OutboundMessage),
499 GNUNET_i2s (&n->id));
502 if ( (ret == NULL) ||
503 (ret->priority < th->priority) )
507 h->quota_task = GNUNET_SCHEDULER_add_delayed (retry_time,
508 "a_transmit_ready,
515 * Transmit message(s) to service.
517 * @param cls handle to transport
518 * @param size number of bytes available in buf
519 * @param buf where to copy the message
520 * @return number of bytes copied to buf
523 transport_notify_ready (void *cls, size_t size, void *buf)
525 struct GNUNET_TRANSPORT_Handle *h = cls;
526 struct ControlMessage *cm;
527 struct GNUNET_TRANSPORT_TransmitHandle *th;
528 struct NeighbourList *n;
529 struct OutboundMessage obm;
535 h->network_handle = NULL;
538 schedule_transmission (h);
542 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
543 "Ready to transmit %u bytes to transport service\n", size);
547 while ( (NULL != (cm = h->control_head)) &&
548 (cm->notify_size <= size) )
550 if (cm->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
552 GNUNET_SCHEDULER_cancel (cm->notify_delay_task);
553 cm->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
555 GNUNET_CONTAINER_DLL_remove (h->control_head,
558 nret = cm->notify (cm->notify_cls, size, &cbuf[ret]);
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
561 "Added %u bytes of control message at %u\n",
569 while ( (NULL != (th = schedule_peer_transmission (h))) &&
570 (th->notify_size <= size) )
572 if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
574 GNUNET_SCHEDULER_cancel (th->notify_delay_task);
575 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
578 switch (n->transmit_stage)
584 n->transmit_stage = TS_TRANSMITTED;
589 case TS_TRANSMITTED_QUEUED:
595 GNUNET_assert (size >= sizeof (struct OutboundMessage));
596 mret = th->notify (th->notify_cls,
597 size - sizeof (struct OutboundMessage),
598 &cbuf[ret + sizeof (struct OutboundMessage)]);
599 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
602 "Message of %u bytes with timeout %llums constructed for `%4s'\n",
604 (unsigned long long) GNUNET_TIME_absolute_get_remaining (th->timeout).rel_value,
605 GNUNET_i2s (&n->id));
609 GNUNET_assert (mret + sizeof (struct OutboundMessage) < GNUNET_SERVER_MAX_MESSAGE_SIZE);
610 obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND);
611 obm.header.size = htons (mret + sizeof (struct OutboundMessage));
612 obm.priority = htonl (th->priority);
613 obm.timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (th->timeout));
615 memcpy (&cbuf[ret], &obm, sizeof (struct OutboundMessage));
616 ret += (mret + sizeof (struct OutboundMessage));
617 size -= (mret + sizeof (struct OutboundMessage));
618 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, mret);
622 switch (n->transmit_stage)
631 n->transmit_stage = TS_NEW;
633 case TS_TRANSMITTED_QUEUED:
634 n->transmit_stage = TS_QUEUED;
641 schedule_transmission (h);
643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
644 "Transmitting %u bytes to transport service\n", ret);
651 * Schedule the task to send one message, either from the control
652 * list or the peer message queues to the service.
655 schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
658 struct GNUNET_TIME_Relative timeout;
659 struct GNUNET_TRANSPORT_TransmitHandle *th;
661 if (NULL != h->network_handle)
663 if (h->client == NULL)
665 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
666 _("Could not yet schedule transmission: we are not yet connected to the transport service!\n"));
667 return; /* not yet connected */
669 if (NULL != h->control_head)
671 size = h->control_head->notify_size;
672 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
676 th = schedule_peer_transmission (h);
679 /* no transmission ready right now */
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
682 "Could not yet schedule transmission: none ready\n");
686 size = th->notify_size;
687 timeout = GNUNET_TIME_absolute_get_remaining (th->timeout);
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
691 "Calling notify_transmit_ready\n");
694 GNUNET_CLIENT_notify_transmit_ready (h->client,
698 &transport_notify_ready,
700 GNUNET_assert (NULL != h->network_handle);
705 * Called when our transmit request timed out before any transport
706 * reported success connecting to the desired peer or before the
707 * transport was ready to receive. Signal error and free
711 control_transmit_timeout (void *cls,
712 const struct GNUNET_SCHEDULER_TaskContext *tc)
714 struct ControlMessage *th = cls;
716 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
717 if (NULL != th->notify)
718 th->notify (th->notify_cls, 0, NULL);
719 GNUNET_CONTAINER_DLL_remove (th->h->control_head,
727 * Queue control request for transmission to the transport
730 * @param h handle to the transport service
731 * @param size number of bytes to be transmitted
732 * @param at_head request must be added to the head of the queue
733 * (otherwise request will be appended)
734 * @param timeout how long this transmission can wait (at most)
735 * @param notify function to call to get the content
736 * @param notify_cls closure for notify
739 schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h,
742 struct GNUNET_TIME_Relative timeout,
743 GNUNET_CONNECTION_TransmitReadyNotify notify,
746 struct ControlMessage *th;
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
750 "Control transmit of %u bytes within %llums requested\n",
751 size, (unsigned long long) timeout.rel_value);
753 th = GNUNET_malloc (sizeof (struct ControlMessage));
756 th->notify_cls = notify_cls;
757 th->notify_size = size;
758 th->notify_delay_task
759 = GNUNET_SCHEDULER_add_delayed (timeout, &control_transmit_timeout, th);
761 GNUNET_CONTAINER_DLL_insert (h->control_head,
765 GNUNET_CONTAINER_DLL_insert_after (h->control_head,
769 schedule_transmission (h);
773 struct SetQuotaContext
775 struct GNUNET_TRANSPORT_Handle *handle;
777 struct GNUNET_PeerIdentity target;
779 GNUNET_SCHEDULER_Task cont;
783 struct GNUNET_TIME_Absolute timeout;
785 struct GNUNET_BANDWIDTH_Value32NBO quota_in;
790 * Send SET_QUOTA message to the service.
792 * @param cls the 'struct SetQuotaContext'
793 * @param size number of bytes available in buf
794 * @param buf where to copy the message
795 * @return number of bytes copied to buf
798 send_set_quota (void *cls, size_t size, void *buf)
800 struct SetQuotaContext *sqc = cls;
801 struct QuotaSetMessage *msg;
805 GNUNET_SCHEDULER_add_continuation (sqc->cont,
807 GNUNET_SCHEDULER_REASON_TIMEOUT);
812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
813 "Transmitting `%s' request with respect to `%4s'.\n",
815 GNUNET_i2s (&sqc->target));
817 GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
819 msg->header.size = htons (sizeof (struct QuotaSetMessage));
820 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
821 msg->quota = sqc->quota_in;
822 memcpy (&msg->peer, &sqc->target, sizeof (struct GNUNET_PeerIdentity));
823 if (sqc->cont != NULL)
824 GNUNET_SCHEDULER_add_continuation (sqc->cont,
826 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
828 return sizeof (struct QuotaSetMessage);
833 * Set the share of incoming bandwidth for the given
834 * peer to the specified amount.
836 * @param handle connection to transport service
837 * @param target who's bandwidth quota is being changed
838 * @param quota_in incoming bandwidth quota in bytes per ms
839 * @param quota_out outgoing bandwidth quota in bytes per ms
840 * @param timeout how long to wait until signaling failure if
841 * we can not communicate the quota change
842 * @param cont continuation to call when done, will be called
843 * either with reason "TIMEOUT" or with reason "PREREQ_DONE"
844 * @param cont_cls closure for continuation
847 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
848 const struct GNUNET_PeerIdentity *target,
849 struct GNUNET_BANDWIDTH_Value32NBO quota_in,
850 struct GNUNET_BANDWIDTH_Value32NBO quota_out,
851 struct GNUNET_TIME_Relative timeout,
852 GNUNET_SCHEDULER_Task cont, void *cont_cls)
854 struct NeighbourList *n;
855 struct SetQuotaContext *sqc;
857 n = neighbour_find (handle, target);
861 if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__)
862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
863 "Quota changed from %u to %u for peer `%s'\n",
864 (unsigned int) n->out_tracker.available_bytes_per_s__,
865 (unsigned int) ntohl (quota_out.value__),
866 GNUNET_i2s (target));
868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
869 "Quota remains at %u for peer `%s'\n",
870 (unsigned int) n->out_tracker.available_bytes_per_s__,
871 GNUNET_i2s (target));
873 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker,
879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
880 "Quota changed to %u for peer `%s', but I have no such neighbour!\n",
881 (unsigned int) ntohl (quota_out.value__),
882 GNUNET_i2s (target));
885 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
886 sqc->handle = handle;
887 sqc->target = *target;
889 sqc->cont_cls = cont_cls;
890 sqc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
891 sqc->quota_in = quota_in;
892 schedule_control_transmit (handle,
893 sizeof (struct QuotaSetMessage),
894 GNUNET_NO, timeout, &send_set_quota, sqc);
899 * Obtain the HELLO message for this peer.
901 * @param handle connection to transport service
902 * @param rec function to call with the HELLO, sender will be our peer
903 * identity; message and sender will be NULL on timeout
904 * (handshake with transport service pending/failed).
905 * cost estimate will be 0.
906 * @param rec_cls closure for rec
909 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
910 GNUNET_TRANSPORT_HelloUpdateCallback rec,
913 struct HelloWaitList *hwl;
915 hwl = GNUNET_malloc (sizeof (struct HelloWaitList));
916 hwl->next = handle->hwl_head;
917 handle->hwl_head = hwl;
918 hwl->handle = handle;
920 hwl->rec_cls = rec_cls;
921 if (handle->my_hello == NULL)
923 rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello);
929 * Stop receiving updates about changes to our HELLO message.
931 * @param handle connection to transport service
932 * @param rec function previously registered to be called with the HELLOs
933 * @param rec_cls closure for rec
936 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
937 GNUNET_TRANSPORT_HelloUpdateCallback rec,
940 struct HelloWaitList *pos;
941 struct HelloWaitList *prev;
944 pos = handle->hwl_head;
947 if ( (pos->rec == rec) &&
948 (pos->rec_cls == rec_cls) )
953 GNUNET_break (pos != NULL);
957 handle->hwl_head = pos->next;
959 prev->next = pos->next;
965 * Send HELLO message to the service.
967 * @param cls the HELLO message to send
968 * @param size number of bytes available in buf
969 * @param buf where to copy the message
970 * @return number of bytes copied to buf
973 send_hello (void *cls, size_t size, void *buf)
975 struct GNUNET_MessageHeader *hello = cls;
980 #if DEBUG_TRANSPORT_TIMEOUT
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "Timeout while trying to transmit `%s' request.\n",
989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
990 "Transmitting `%s' request.\n", "HELLO");
992 msize = ntohs (hello->size);
993 GNUNET_assert (size >= msize);
994 memcpy (buf, hello, msize);
1001 * Offer the transport service the HELLO of another peer. Note that
1002 * the transport service may just ignore this message if the HELLO is
1003 * malformed or useless due to our local configuration.
1005 * @param handle connection to transport service
1006 * @param hello the hello message
1009 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1010 const struct GNUNET_MessageHeader *hello)
1012 struct GNUNET_MessageHeader *hc;
1014 struct GNUNET_PeerIdentity peer;
1016 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
1017 size = ntohs (hello->size);
1018 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
1019 if (GNUNET_OK != GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) hello,
1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1027 "Offering `%s' message of `%4s' to transport for validation.\n",
1029 GNUNET_i2s (&peer));
1031 hc = GNUNET_malloc (size);
1032 memcpy (hc, hello, size);
1033 schedule_control_transmit (handle,
1035 GNUNET_NO, OFFER_HELLO_TIMEOUT, &send_hello, hc);
1040 * Transmit START message to service.
1043 * @param size number of bytes available in buf
1044 * @param buf where to copy the message
1045 * @return number of bytes copied to buf
1048 send_start (void *cls, size_t size, void *buf)
1050 struct GNUNET_TRANSPORT_Handle *h = cls;
1051 struct StartMessage s;
1055 /* Can only be shutdown, just give up */
1057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1058 "Shutdown while trying to transmit `%s' request.\n",
1064 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1065 "Transmitting `%s' request.\n", "START");
1067 GNUNET_assert (size >= sizeof (struct StartMessage));
1068 s.header.size = htons (sizeof (struct StartMessage));
1069 s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START);
1070 s.do_check = htonl (h->check_self);
1072 memcpy (buf, &s, sizeof (struct StartMessage));
1073 return sizeof (struct StartMessage);
1080 * @param n the entry to free
1083 neighbour_free (struct NeighbourList *n)
1085 struct GNUNET_TRANSPORT_Handle *h;
1086 struct NeighbourList *prev;
1087 struct NeighbourList *pos;
1091 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1092 "Removing neighbour `%s' from list of connected peers.\n",
1093 GNUNET_i2s (&n->id));
1095 GNUNET_break (n->is_connected == GNUNET_NO);
1096 GNUNET_break (n->transmit_stage == TS_NEW);
1099 pos = h->neighbours;
1106 h->neighbours = n->next;
1108 prev->next = n->next;
1114 * Mark neighbour as disconnected.
1116 * @param n the entry to mark as disconnected
1119 neighbour_disconnect (struct NeighbourList *n)
1121 struct GNUNET_TRANSPORT_Handle *h = n->h;
1123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1124 "Removing neighbour `%s' from list of connected peers.\n",
1125 GNUNET_i2s (&n->id));
1127 GNUNET_break (n->is_connected == GNUNET_YES);
1128 n->is_connected = GNUNET_NO;
1129 if (h->nd_cb != NULL)
1130 h->nd_cb (h->cls, &n->id);
1131 if (n->transmit_stage == TS_NEW)
1137 * Function we use for handling incoming messages.
1139 * @param cls closure (struct GNUNET_TRANSPORT_Handle *)
1140 * @param msg message received, NULL on timeout or fatal error
1142 static void demultiplexer (void *cls,
1143 const struct GNUNET_MessageHeader *msg);
1147 * Try again to connect to transport service.
1149 * @param cls the handle to the transport service
1150 * @param tc scheduler context
1153 reconnect (void *cls,
1154 const struct GNUNET_SCHEDULER_TaskContext *tc)
1156 struct GNUNET_TRANSPORT_Handle *h = cls;
1157 struct ControlMessage *pos;
1158 struct NeighbourList *n;
1159 struct NeighbourList *next;
1161 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1162 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1164 /* shutdown, just give up */
1167 /* Forget about all neighbours that we used to be connected to */
1171 #if DEBUG_TRANSPORT_DISCONNECT
1172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1173 "Disconnecting due to reconnect being called\n");
1176 if (n->is_connected)
1177 neighbour_disconnect (n);
1181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1182 "Connecting to transport service.\n");
1184 GNUNET_assert (h->client == NULL);
1185 h->client = GNUNET_CLIENT_connect ("transport", h->cfg);
1186 GNUNET_assert (h->client != NULL);
1187 /* make sure we don't send "START" twice, remove existing entry from
1188 queue (if present) */
1189 pos = h->control_head;
1192 if (pos->notify == &send_start)
1194 GNUNET_CONTAINER_DLL_remove (h->control_head,
1197 if (GNUNET_SCHEDULER_NO_TASK != pos->notify_delay_task)
1199 GNUNET_SCHEDULER_cancel (pos->notify_delay_task);
1200 pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1207 schedule_control_transmit (h,
1208 sizeof (struct StartMessage),
1210 GNUNET_TIME_UNIT_FOREVER_REL, &send_start, h);
1211 GNUNET_CLIENT_receive (h->client,
1212 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
1217 * Function that will schedule the job that will try
1218 * to connect us again to the client.
1220 * @param h transport service to reconnect
1223 schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1227 "Scheduling task to reconnect to transport service in %llu ms.\n",
1228 h->reconnect_delay.rel_value);
1230 GNUNET_assert (h->client == NULL);
1231 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
1233 = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
1234 if (h->reconnect_delay.rel_value == 0)
1236 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
1240 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
1241 h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
1242 h->reconnect_delay);
1248 * Send request connect message to the service.
1250 * @param cls the TransportRequestConnectMessage
1251 * @param size number of bytes available in buf
1252 * @param buf where to copy the message
1253 * @return number of bytes copied to buf
1256 send_transport_request_connect (void *cls, size_t size, void *buf)
1258 struct TransportRequestConnectMessage *trcm = cls;
1263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1264 "Buffer null for %s\n",
1271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1272 "Transmitting `%s' request for `%4s'.\n",
1274 GNUNET_i2s (&trcm->peer));
1276 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1277 memcpy(buf, trcm, sizeof(struct TransportRequestConnectMessage));
1278 return sizeof(struct TransportRequestConnectMessage);
1282 * Create and send a request connect message to
1283 * the transport service for a particular peer.
1285 * @param h handle to the transport service
1286 * @param n the neighbor to send the request connect message about
1289 static void send_request_connect_message(struct GNUNET_TRANSPORT_Handle *h, struct NeighbourList *n)
1291 struct TransportRequestConnectMessage *trcm;
1293 trcm = GNUNET_malloc(sizeof(struct TransportRequestConnectMessage));
1294 trcm->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT);
1295 trcm->header.size = htons(sizeof(struct TransportRequestConnectMessage));
1296 memcpy(&trcm->peer, &n->id, sizeof(struct GNUNET_PeerIdentity));
1297 schedule_control_transmit (h,
1298 sizeof (struct TransportRequestConnectMessage),
1300 GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_request_connect, trcm);
1304 * Add neighbour to our list
1306 * @return NULL if this API is currently disconnecting from the service
1308 static struct NeighbourList *
1309 neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
1310 const struct GNUNET_PeerIdentity *pid)
1312 struct NeighbourList *n;
1314 if (GNUNET_YES == h->in_disconnect)
1316 /* check for duplicates */
1317 if (NULL != (n = neighbour_find (h, pid)))
1323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1324 "Creating entry for neighbour `%4s'.\n",
1327 n = GNUNET_malloc (sizeof (struct NeighbourList));
1329 GNUNET_BANDWIDTH_tracker_init (&n->out_tracker,
1330 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
1331 MAX_BANDWIDTH_CARRY_S);
1332 n->next = h->neighbours;
1342 * Connect to the transport service. Note that the connection may
1343 * complete (or fail) asynchronously.
1345 * @param cfg configuration to use
1346 * @param self our own identity (API should check that it matches
1347 * the identity found by transport), or NULL (no check)
1348 * @param cls closure for the callbacks
1349 * @param rec receive function to call
1350 * @param nc function to call on connect events
1351 * @param nd function to call on disconnect events
1353 struct GNUNET_TRANSPORT_Handle *
1354 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1355 const struct GNUNET_PeerIdentity *self,
1357 GNUNET_TRANSPORT_ReceiveCallback rec,
1358 GNUNET_TRANSPORT_NotifyConnect nc,
1359 GNUNET_TRANSPORT_NotifyDisconnect nd)
1361 struct GNUNET_TRANSPORT_Handle *ret;
1363 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle));
1367 ret->check_self = GNUNET_YES;
1374 ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
1375 schedule_reconnect (ret);
1381 * Disconnect from the transport service.
1384 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1386 struct GNUNET_TRANSPORT_TransmitHandle *th;
1387 struct NeighbourList *n;
1388 struct HelloWaitList *hwl;
1389 struct GNUNET_CLIENT_Connection *client;
1390 struct ControlMessage *cm;
1393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
1395 handle->in_disconnect = GNUNET_YES;
1396 while (NULL != (n = handle->neighbours))
1398 handle->neighbours = n->next;
1399 switch (n->transmit_stage)
1402 case TS_TRANSMITTED:
1406 case TS_TRANSMITTED_QUEUED:
1407 th = &n->transmit_handle;
1408 if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
1410 GNUNET_SCHEDULER_cancel (th->notify_delay_task);
1411 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1413 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
1420 while (NULL != (hwl = handle->hwl_head))
1422 handle->hwl_head = hwl->next;
1423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1425 ("Disconnect while notification for `%s' still registered.\n"),
1427 if (hwl->rec != NULL)
1428 hwl->rec (hwl->rec_cls, NULL);
1432 /* Check for still scheduled control messages, cancel delay tasks if so */
1433 /* Added because somehow a notify_delay_task is remaining scheduled and is ever so annoying */
1434 while ( (NULL != (cm = handle->control_head)))
1437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1438 "Disconnect before control message sent!\n");
1440 if (cm->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
1442 GNUNET_SCHEDULER_cancel (cm->notify_delay_task);
1443 cm->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1445 GNUNET_CONTAINER_DLL_remove (handle->control_head,
1446 handle->control_tail,
1452 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
1454 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
1455 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1457 if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK)
1459 GNUNET_SCHEDULER_cancel (handle->quota_task);
1460 handle->quota_task = GNUNET_SCHEDULER_NO_TASK;
1462 GNUNET_free_non_null (handle->my_hello);
1463 handle->my_hello = NULL;
1465 if (NULL != handle->network_handle)
1467 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->network_handle);
1468 handle->network_handle = NULL;
1470 if (NULL != (client = handle->client))
1473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1474 "Disconnecting from transport service for good.\n");
1476 handle->client = NULL;
1477 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
1479 GNUNET_free (handle);
1484 * Function we use for handling incoming messages.
1486 * @param cls closure (struct GNUNET_TRANSPORT_Handle *)
1487 * @param msg message received, NULL on timeout or fatal error
1490 demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
1492 struct GNUNET_TRANSPORT_Handle *h = cls;
1493 const struct DisconnectInfoMessage *dim;
1494 const struct ConnectInfoMessage *cim;
1495 const struct InboundMessage *im;
1496 const struct GNUNET_MessageHeader *imm;
1497 const struct SendOkMessage *okm;
1498 struct HelloWaitList *hwl;
1499 struct HelloWaitList *next_hwl;
1500 struct NeighbourList *n;
1501 struct GNUNET_PeerIdentity me;
1504 if (h->client == NULL)
1506 /* shutdown initiated from 'GNUNET_TRANSPORT_disconnect',
1507 finish clean up work! */
1514 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1515 "Error receiving from transport service, disconnecting temporarily.\n");
1517 if (h->network_handle != NULL)
1519 GNUNET_CLIENT_notify_transmit_ready_cancel (h->network_handle);
1520 h->network_handle = NULL;
1522 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
1524 schedule_reconnect (h);
1527 GNUNET_CLIENT_receive (h->client,
1528 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
1529 size = ntohs (msg->size);
1530 switch (ntohs (msg->type))
1532 case GNUNET_MESSAGE_TYPE_HELLO:
1534 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg,
1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1542 "Receiving (my own) `%s' message, I am `%4s'.\n",
1543 "HELLO", GNUNET_i2s (&me));
1545 GNUNET_free_non_null (h->my_hello);
1547 if (size < sizeof (struct GNUNET_MessageHeader))
1552 h->my_hello = GNUNET_malloc (size);
1553 memcpy (h->my_hello, msg, size);
1557 next_hwl = hwl->next;
1558 hwl->rec (hwl->rec_cls,
1559 (const struct GNUNET_MessageHeader *) h->my_hello);
1563 case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
1564 if (size != sizeof (struct ConnectInfoMessage))
1569 cim = (const struct ConnectInfoMessage *) msg;
1571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1572 "Receiving `%s' message for `%4s'.\n",
1573 "CONNECT", GNUNET_i2s (&cim->id));
1575 n = neighbour_find (h, &cim->id);
1577 n = neighbour_add (h,
1581 GNUNET_break (n->is_connected == GNUNET_NO);
1582 n->is_connected = GNUNET_YES;
1583 if (h->nc_cb != NULL)
1584 h->nc_cb (h->cls, &n->id,
1585 GNUNET_TIME_relative_ntoh (cim->latency),
1586 ntohl (cim->distance));
1588 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
1589 if (size != sizeof (struct DisconnectInfoMessage))
1594 dim = (const struct DisconnectInfoMessage *) msg;
1595 GNUNET_break (ntohl (dim->reserved) == 0);
1596 #if DEBUG_TRANSPORT_DISCONNECT
1597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1598 "Receiving `%s' message for `%4s'.\n",
1600 GNUNET_i2s (&dim->peer));
1602 n = neighbour_find (h, &dim->peer);
1603 GNUNET_break (n != NULL);
1605 neighbour_disconnect (n);
1607 case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK:
1608 if (size != sizeof (struct SendOkMessage))
1613 okm = (const struct SendOkMessage *) msg;
1615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1616 "Receiving `%s' message, transmission %s.\n", "SEND_OK",
1617 ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
1619 n = neighbour_find (h, &okm->peer);
1620 GNUNET_assert (n != NULL);
1621 switch (n->transmit_stage)
1629 case TS_TRANSMITTED:
1630 n->transmit_stage = TS_NEW;
1632 case TS_TRANSMITTED_QUEUED:
1633 n->transmit_stage = TS_QUEUED;
1634 schedule_transmission (h);
1640 case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV:
1642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1643 "Receiving `%s' message.\n", "RECV");
1646 sizeof (struct InboundMessage) +
1647 sizeof (struct GNUNET_MessageHeader))
1652 im = (const struct InboundMessage *) msg;
1653 GNUNET_break (0 == ntohl (im->reserved));
1654 imm = (const struct GNUNET_MessageHeader *) &im[1];
1655 if (ntohs (imm->size) + sizeof (struct InboundMessage) != size)
1661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1662 "Received message of type %u from `%4s'.\n",
1663 ntohs (imm->type), GNUNET_i2s (&im->peer));
1665 n = neighbour_find (h, &im->peer);
1671 if (n->is_connected != GNUNET_YES)
1677 h->rec (h->cls, &im->peer, imm,
1678 GNUNET_TIME_relative_ntoh (im->latency), ntohl(im->distance));
1681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1683 ("Received unexpected message of type %u in %s:%u\n"),
1684 ntohs (msg->type), __FILE__, __LINE__);
1692 * Called when our transmit request timed out before any transport
1693 * reported success connecting to the desired peer or before the
1694 * transport was ready to receive. Signal error and free
1697 * @param cls the 'struct GNUNET_TRANSPORT_TransmitHandle*' that is timing out
1698 * @param tc scheduler context
1701 peer_transmit_timeout (void *cls,
1702 const struct GNUNET_SCHEDULER_TaskContext *tc)
1704 struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
1705 struct NeighbourList *n;
1706 GNUNET_CONNECTION_TransmitReadyNotify notify;
1709 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1712 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1713 "Triggering timeout for request to transmit to `%4s' (%d)\n",
1714 GNUNET_i2s (&n->id),
1717 notify = th->notify;
1718 notify_cls = th->notify_cls;
1719 switch (n->transmit_stage)
1725 n->transmit_stage = TS_NEW;
1726 if (n->is_connected == GNUNET_NO)
1729 case TS_TRANSMITTED:
1732 case TS_TRANSMITTED_QUEUED:
1733 n->transmit_stage = TS_TRANSMITTED;
1739 notify (notify_cls, 0, NULL);
1744 * Check if we could queue a message of the given size for
1745 * transmission. The transport service will take both its
1746 * internal buffers and bandwidth limits imposed by the
1747 * other peer into consideration when answering this query.
1749 * @param handle connection to transport service
1750 * @param target who should receive the message
1751 * @param size how big is the message we want to transmit?
1752 * @param priority how important is the message?
1753 * @param timeout after how long should we give up (and call
1754 * notify with buf NULL and size 0)?
1755 * @param notify function to call when we are ready to
1756 * send such a message
1757 * @param notify_cls closure for notify
1758 * @return NULL if someone else is already waiting to be notified
1759 * non-NULL if the notify callback was queued (can be used to cancel
1760 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
1762 struct GNUNET_TRANSPORT_TransmitHandle *
1763 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
1765 const struct GNUNET_PeerIdentity
1766 *target, size_t size,
1767 unsigned int priority,
1768 struct GNUNET_TIME_Relative timeout,
1769 GNUNET_CONNECTION_TransmitReadyNotify
1770 notify, void *notify_cls)
1772 struct GNUNET_TRANSPORT_TransmitHandle *th;
1773 struct NeighbourList *n;
1775 if (size + sizeof (struct OutboundMessage) >=
1776 GNUNET_SERVER_MAX_MESSAGE_SIZE)
1779 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1780 "Message size is %d, max allowed is %d.\n",
1781 size + sizeof (struct OutboundMessage), GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
1787 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1788 "Asking transport service for transmission of %u bytes to peer `%4s' within %llu ms.\n",
1789 size, GNUNET_i2s (target),
1790 (unsigned long long) timeout.rel_value);
1792 n = neighbour_find (handle, target);
1795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1796 "Created neighbour entry for peer `%s'\n",
1797 GNUNET_i2s (target));
1798 n = neighbour_add (handle, target);
1803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1804 "Could not create neighbour entry for peer `%s'\n",
1805 GNUNET_i2s (target));
1810 * Send a request connect message if not connected,
1811 * otherwise we will never send anything to
1814 if (n->is_connected == GNUNET_NO)
1816 send_request_connect_message(handle, n);
1819 switch (n->transmit_stage)
1822 n->transmit_stage = TS_QUEUED;
1827 case TS_TRANSMITTED:
1828 n->transmit_stage = TS_TRANSMITTED_QUEUED;
1830 case TS_TRANSMITTED_QUEUED:
1837 th = &n->transmit_handle;
1839 th->notify = notify;
1840 th->notify_cls = notify_cls;
1841 th->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1842 th->notify_size = size + sizeof (struct OutboundMessage);
1843 th->priority = priority;
1844 th->notify_delay_task
1845 = GNUNET_SCHEDULER_add_delayed (timeout,
1846 &peer_transmit_timeout, th);
1847 schedule_transmission (handle);
1853 * Cancel the specified transmission-ready notification.
1856 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
1857 GNUNET_TRANSPORT_TransmitHandle
1860 struct NeighbourList *n;
1864 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1865 "Transmission request of %u bytes to `%4s' was cancelled.\n",
1866 th->notify_size - sizeof (struct OutboundMessage),
1867 GNUNET_i2s (&n->id));
1869 switch (n->transmit_stage)
1875 n->transmit_stage = TS_NEW;
1876 if (n->is_connected == GNUNET_NO)
1879 case TS_TRANSMITTED:
1882 case TS_TRANSMITTED_QUEUED:
1883 n->transmit_stage = TS_TRANSMITTED;
1888 if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
1890 GNUNET_SCHEDULER_cancel (th->notify_delay_task);
1891 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1896 /* end of transport_api.c */