2 This file is part of GNUnet.
3 (C) 2009-2013 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
30 #include "gnunet_util_lib.h"
31 #include "gnunet_constants.h"
32 #include "gnunet_arm_service.h"
33 #include "gnunet_hello_lib.h"
34 #include "gnunet_protocols.h"
35 #include "gnunet_transport_service.h"
36 #include "transport.h"
38 #define LOG(kind,...) GNUNET_log_from (kind, "transport-api",__VA_ARGS__)
41 * How large to start with for the hashmap of neighbours.
43 #define STARTING_NEIGHBOURS_SIZE 16
46 * Handle for a message that should be transmitted to the service.
47 * Used for both control messages and normal messages.
49 struct GNUNET_TRANSPORT_TransmitHandle
53 * We keep all requests in a DLL.
55 struct GNUNET_TRANSPORT_TransmitHandle *next;
58 * We keep all requests in a DLL.
60 struct GNUNET_TRANSPORT_TransmitHandle *prev;
63 * Neighbour for this handle, NULL for control messages.
65 struct Neighbour *neighbour;
68 * Function to call when notify_size bytes are available
71 GNUNET_CONNECTION_TransmitReadyNotify notify;
79 * Timeout for this request, 0 for control messages.
81 struct GNUNET_TIME_Absolute timeout;
84 * Task to trigger request timeout if the request is stalled due to
87 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
90 * How many bytes is our notify callback waiting for?
95 * How important is this message? Not used for control messages.
103 * Entry in hash table of all of our current neighbours.
108 * Overall transport handle.
110 struct GNUNET_TRANSPORT_Handle *h;
113 * Active transmit handle or NULL.
115 struct GNUNET_TRANSPORT_TransmitHandle *th;
118 * Identity of this neighbour.
120 struct GNUNET_PeerIdentity id;
123 * Outbound bandwidh tracker.
125 struct GNUNET_BANDWIDTH_Tracker out_tracker;
128 * Entry in our readyness heap (which is sorted by 'next_ready'
129 * value). NULL if there is no pending transmission request for
130 * this neighbour or if we're waiting for 'is_ready' to become
131 * true AFTER the 'out_tracker' suggested that this peer's quota
132 * has been satisfied (so once 'is_ready' goes to GNUNET_YES,
133 * we should immediately go back into the heap).
135 struct GNUNET_CONTAINER_HeapNode *hn;
138 * Is this peer currently ready to receive a message?
143 * Sending consumed more bytes on wire than payload was announced
144 * This overhead is added to the delay of next sending operation
146 size_t traffic_overhead;
151 * Linked list of functions to call whenever our HELLO is updated.
153 struct GNUNET_TRANSPORT_GetHelloHandle
157 * This is a doubly linked list.
159 struct GNUNET_TRANSPORT_GetHelloHandle *next;
162 * This is a doubly linked list.
164 struct GNUNET_TRANSPORT_GetHelloHandle *prev;
169 struct GNUNET_TRANSPORT_Handle *handle;
172 * Callback to call once we got our HELLO.
174 GNUNET_TRANSPORT_HelloUpdateCallback rec;
177 * Task for calling the HelloUpdateCallback when we already have a HELLO
179 GNUNET_SCHEDULER_TaskIdentifier notify_task;
182 * Closure for @e rec.
189 * Linked list for all try-connect requests
191 struct GNUNET_TRANSPORT_TryConnectHandle
196 struct GNUNET_TRANSPORT_TryConnectHandle *prev;
201 struct GNUNET_TRANSPORT_TryConnectHandle *next;
203 struct GNUNET_PeerIdentity pid;
205 struct GNUNET_TRANSPORT_Handle *th;
207 struct GNUNET_TRANSPORT_TransmitHandle *tth;
209 GNUNET_TRANSPORT_TryConnectCallback cb;
219 * Linked list for all try-connect requests
221 struct GNUNET_TRANSPORT_OfferHelloHandle
226 struct GNUNET_TRANSPORT_OfferHelloHandle *prev;
231 struct GNUNET_TRANSPORT_OfferHelloHandle *next;
233 struct GNUNET_TRANSPORT_Handle *th;
235 struct GNUNET_TRANSPORT_TransmitHandle *tth;
237 GNUNET_SCHEDULER_Task cont;
240 * Closure for @e cont
244 struct GNUNET_MessageHeader *msg;
249 * Handle for the transport service (includes all of the
250 * state for the transport service).
252 struct GNUNET_TRANSPORT_Handle
256 * Closure for the callbacks.
261 * Function to call for received data.
263 GNUNET_TRANSPORT_ReceiveCallback rec;
266 * function to call on connect events
268 GNUNET_TRANSPORT_NotifyConnect nc_cb;
271 * function to call on disconnect events
273 GNUNET_TRANSPORT_NotifyDisconnect nd_cb;
276 * Head of DLL of control messages.
278 struct GNUNET_TRANSPORT_TransmitHandle *control_head;
281 * Tail of DLL of control messages.
283 struct GNUNET_TRANSPORT_TransmitHandle *control_tail;
286 * The current HELLO message for this peer. Updated
287 * whenever transports change their addresses.
289 struct GNUNET_HELLO_Message *my_hello;
292 * My client connection to the transport service.
294 struct GNUNET_CLIENT_Connection *client;
297 * Handle to our registration with the client for notification.
299 struct GNUNET_CLIENT_TransmitHandle *cth;
302 * Linked list of pending requests for our HELLO.
304 struct GNUNET_TRANSPORT_GetHelloHandle *hwl_head;
307 * Linked list of pending requests for our HELLO.
309 struct GNUNET_TRANSPORT_GetHelloHandle *hwl_tail;
312 * Linked list of pending try connect requests head
314 struct GNUNET_TRANSPORT_TryConnectHandle *tc_head;
317 * Linked list of pending try connect requests tail
319 struct GNUNET_TRANSPORT_TryConnectHandle *tc_tail;
322 * Linked list of pending offer HELLO requests head
324 struct GNUNET_TRANSPORT_OfferHelloHandle *oh_head;
327 * Linked list of pending offer HELLO requests tail
329 struct GNUNET_TRANSPORT_OfferHelloHandle *oh_tail;
334 const struct GNUNET_CONFIGURATION_Handle *cfg;
337 * Hash map of the current connected neighbours of this peer.
338 * Maps peer identities to 'struct Neighbour' entries.
340 struct GNUNET_CONTAINER_MultiPeerMap *neighbours;
343 * Heap sorting peers with pending messages by the timestamps that
344 * specify when we could next send a message to the respective peer.
345 * Excludes control messages (which can always go out immediately).
346 * Maps time stamps to 'struct Neighbour' entries.
348 struct GNUNET_CONTAINER_Heap *ready_heap;
351 * Peer identity as assumed by this process, or all zeros.
353 struct GNUNET_PeerIdentity self;
356 * ID of the task trying to reconnect to the service.
358 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
361 * ID of the task trying to trigger transmission for a peer while
362 * maintaining bandwidth quotas. In use if there are no control
363 * messages and the smallest entry in the 'ready_heap' has a time
364 * stamp in the future.
366 GNUNET_SCHEDULER_TaskIdentifier quota_task;
369 * Delay until we try to reconnect.
371 struct GNUNET_TIME_Relative reconnect_delay;
374 * Should we check that @e self matches what the service thinks?
375 * (if #GNUNET_NO, then @e self is all zeros!).
380 * Reconnect in progress
388 * Schedule the task to send one message, either from the control
389 * list or the peer message queues to the service.
391 * @param h transport service to schedule a transmission for
394 schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
398 * Function that will schedule the job that will try
399 * to connect us again to the client.
401 * @param h transport service to reconnect
404 disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h);
408 * Get the neighbour list entry for the given peer
410 * @param h our context
411 * @param peer peer to look up
412 * @return NULL if no such peer entry exists
414 static struct Neighbour *
415 neighbour_find (struct GNUNET_TRANSPORT_Handle *h,
416 const struct GNUNET_PeerIdentity *peer)
418 return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer);
423 * Add neighbour to our list
425 * @return NULL if this API is currently disconnecting from the service
427 static struct Neighbour *
428 neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
429 const struct GNUNET_PeerIdentity *pid)
433 LOG (GNUNET_ERROR_TYPE_DEBUG,
434 "Creating entry for neighbour `%4s'.\n",
436 n = GNUNET_new (struct Neighbour);
439 n->is_ready = GNUNET_YES;
440 n->traffic_overhead = 0;
441 GNUNET_BANDWIDTH_tracker_init (&n->out_tracker,
442 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
443 MAX_BANDWIDTH_CARRY_S);
444 GNUNET_assert (GNUNET_OK ==
445 GNUNET_CONTAINER_multipeermap_put (h->neighbours,
447 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
453 * Iterator over hash map entries, for deleting state of a neighbour.
455 * @param cls the `struct GNUNET_TRANSPORT_Handle *`
456 * @param key peer identity
457 * @param value value in the hash map, the neighbour entry to delete
458 * @return #GNUNET_YES if we should continue to
463 neighbour_delete (void *cls,
464 const struct GNUNET_PeerIdentity *key, void *value)
466 struct GNUNET_TRANSPORT_Handle *handle = cls;
467 struct Neighbour *n = value;
469 if (NULL != handle->nd_cb)
470 handle->nd_cb (handle->cls, &n->id);
471 GNUNET_assert (NULL == n->th);
472 GNUNET_assert (NULL == n->hn);
473 GNUNET_assert (GNUNET_YES ==
474 GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key,
480 static int reconnecting;
483 * Function we use for handling incoming messages.
485 * @param cls closure, a `struct GNUNET_TRANSPORT_Handle *`
486 * @param msg message received, NULL on timeout or fatal error
489 demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
491 struct GNUNET_TRANSPORT_Handle *h = cls;
492 const struct DisconnectInfoMessage *dim;
493 const struct ConnectInfoMessage *cim;
494 const struct InboundMessage *im;
495 const struct GNUNET_MessageHeader *imm;
496 const struct SendOkMessage *okm;
497 const struct QuotaSetMessage *qm;
498 struct GNUNET_TRANSPORT_GetHelloHandle *hwl;
499 struct GNUNET_TRANSPORT_GetHelloHandle *next_hwl;
501 struct GNUNET_PeerIdentity me;
504 uint32_t bytes_physical;
506 GNUNET_assert (NULL != h->client);
507 if (GNUNET_YES == reconnecting)
513 LOG (GNUNET_ERROR_TYPE_DEBUG,
514 "Error receiving from transport service, disconnecting temporarily.\n");
515 reconnecting = GNUNET_YES;
516 disconnect_and_schedule_reconnect (h);
519 GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
520 GNUNET_TIME_UNIT_FOREVER_REL);
521 size = ntohs (msg->size);
522 switch (ntohs (msg->type))
524 case GNUNET_MESSAGE_TYPE_HELLO:
526 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me))
531 LOG (GNUNET_ERROR_TYPE_DEBUG,
532 "Receiving (my own) `%s' message, I am `%4s'.\n", "HELLO",
534 GNUNET_free_non_null (h->my_hello);
536 if (size < sizeof (struct GNUNET_MessageHeader))
541 h->my_hello = GNUNET_malloc (size);
542 memcpy (h->my_hello, msg, size);
546 next_hwl = hwl->next;
547 hwl->rec (hwl->rec_cls,
548 (const struct GNUNET_MessageHeader *) h->my_hello);
552 case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
553 if (size < sizeof (struct ConnectInfoMessage))
558 cim = (const struct ConnectInfoMessage *) msg;
560 sizeof (struct ConnectInfoMessage))
565 LOG (GNUNET_ERROR_TYPE_DEBUG,
566 "Receiving `%s' message for `%4s'.\n",
567 "CONNECT", GNUNET_i2s (&cim->id));
568 n = neighbour_find (h, &cim->id);
574 n = neighbour_add (h, &cim->id);
575 LOG (GNUNET_ERROR_TYPE_DEBUG,
576 "Receiving `%s' message for `%4s' with quota %u\n",
578 GNUNET_i2s (&cim->id),
579 ntohl (cim->quota_out.value__));
580 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out);
581 if (h->nc_cb != NULL)
582 h->nc_cb (h->cls, &n->id);
584 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
585 if (size != sizeof (struct DisconnectInfoMessage))
590 dim = (const struct DisconnectInfoMessage *) msg;
591 GNUNET_break (ntohl (dim->reserved) == 0);
592 LOG (GNUNET_ERROR_TYPE_DEBUG,
593 "Receiving `%s' message for `%4s'.\n",
594 "DISCONNECT", GNUNET_i2s (&dim->peer));
595 n = neighbour_find (h, &dim->peer);
601 neighbour_delete (h, &dim->peer, n);
603 case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK:
604 if (size != sizeof (struct SendOkMessage))
609 okm = (const struct SendOkMessage *) msg;
610 bytes_msg = ntohl (okm->bytes_msg);
611 bytes_physical = ntohl (okm->bytes_physical);
612 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message, transmission %s.\n",
613 "SEND_OK", ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
615 n = neighbour_find (h, &okm->peer);
619 if (bytes_physical >= bytes_msg)
621 LOG (GNUNET_ERROR_TYPE_DEBUG, "Overhead for %u byte message: %u \n",
622 bytes_msg, bytes_physical - bytes_msg);
623 n->traffic_overhead += bytes_physical - bytes_msg;
625 GNUNET_break (GNUNET_NO == n->is_ready);
626 n->is_ready = GNUNET_YES;
627 if ((NULL != n->th) && (NULL == n->hn))
629 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task);
630 GNUNET_SCHEDULER_cancel (n->th->timeout_task);
631 n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
632 /* we've been waiting for this (congestion, not quota,
633 * caused delayed transmission) */
634 n->hn = GNUNET_CONTAINER_heap_insert (h->ready_heap, n, 0);
635 schedule_transmission (h);
638 case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV:
639 LOG (GNUNET_ERROR_TYPE_DEBUG,
640 "Receiving `%s' message.\n",
643 sizeof (struct InboundMessage) + sizeof (struct GNUNET_MessageHeader))
648 im = (const struct InboundMessage *) msg;
649 imm = (const struct GNUNET_MessageHeader *) &im[1];
650 if (ntohs (imm->size) + sizeof (struct InboundMessage) != size)
655 LOG (GNUNET_ERROR_TYPE_DEBUG,
656 "Received message of type %u from `%4s'.\n",
657 ntohs (imm->type), GNUNET_i2s (&im->peer));
658 n = neighbour_find (h, &im->peer);
665 h->rec (h->cls, &im->peer, imm);
667 case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA:
668 LOG (GNUNET_ERROR_TYPE_DEBUG,
669 "Receiving `%s' message.\n", "SET_QUOTA");
670 if (size != sizeof (struct QuotaSetMessage))
675 qm = (const struct QuotaSetMessage *) msg;
676 n = neighbour_find (h, &qm->peer);
679 LOG (GNUNET_ERROR_TYPE_DEBUG,
680 "Receiving `%s' message for `%4s' with quota %u\n",
682 GNUNET_i2s (&qm->peer),
683 ntohl (qm->quota.value__));
684 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota);
687 LOG (GNUNET_ERROR_TYPE_ERROR,
688 _("Received unexpected message of type %u in %s:%u\n"),
689 ntohs (msg->type), __FILE__, __LINE__);
697 * A transmission request could not be satisfied because of
698 * network congestion. Notify the initiator and clean up.
700 * @param cls the `struct GNUNET_TRANSPORT_TransmitHandle`
701 * @param tc scheduler context
704 timeout_request_due_to_congestion (void *cls,
705 const struct GNUNET_SCHEDULER_TaskContext *tc)
707 struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
708 struct Neighbour *n = th->neighbour;
710 n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
711 GNUNET_assert (th == n->th);
712 GNUNET_assert (NULL == n->hn);
714 th->notify (th->notify_cls, 0, NULL);
720 * Transmit message(s) to service.
722 * @param cls handle to transport
723 * @param size number of bytes available in @a buf
724 * @param buf where to copy the message
725 * @return number of bytes copied to @a buf
728 transport_notify_ready (void *cls, size_t size, void *buf)
730 struct GNUNET_TRANSPORT_Handle *h = cls;
731 struct GNUNET_TRANSPORT_TransmitHandle *th;
734 struct OutboundMessage obm;
739 GNUNET_assert (NULL != h->client);
743 /* transmission failed */
744 disconnect_and_schedule_reconnect (h);
750 /* first send control messages */
751 while ((NULL != (th = h->control_head)) && (th->notify_size <= size))
753 GNUNET_CONTAINER_DLL_remove (h->control_head, h->control_tail, th);
754 nret = th->notify (th->notify_cls, size, &cbuf[ret]);
755 LOG (GNUNET_ERROR_TYPE_DEBUG,
756 "Added %u bytes of control message at %u\n",
763 /* then, if possible and no control messages pending, send data messages */
764 while ((NULL == h->control_head) &&
765 (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))))
767 if (GNUNET_YES != n->is_ready)
769 /* peer not ready, wait for notification! */
770 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
772 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task);
773 n->th->timeout_task =
774 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
776 &timeout_request_due_to_congestion,
781 if (th->notify_size + sizeof (struct OutboundMessage) > size)
782 break; /* does not fit */
783 if (GNUNET_BANDWIDTH_tracker_get_delay
784 (&n->out_tracker, th->notify_size).rel_value_us > 0)
785 break; /* too early */
786 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
789 n->is_ready = GNUNET_NO;
790 GNUNET_assert (size >= sizeof (struct OutboundMessage));
792 th->notify (th->notify_cls, size - sizeof (struct OutboundMessage),
793 &cbuf[ret + sizeof (struct OutboundMessage)]);
794 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
797 GNUNET_assert (mret + sizeof (struct OutboundMessage) <
798 GNUNET_SERVER_MAX_MESSAGE_SIZE);
799 obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND);
800 obm.header.size = htons (mret + sizeof (struct OutboundMessage));
801 obm.priority = htonl (th->priority);
803 GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
806 memcpy (&cbuf[ret], &obm, sizeof (struct OutboundMessage));
807 ret += (mret + sizeof (struct OutboundMessage));
808 size -= (mret + sizeof (struct OutboundMessage));
809 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, mret);
813 /* if there are more pending messages, try to schedule those */
814 schedule_transmission (h);
815 LOG (GNUNET_ERROR_TYPE_DEBUG,
816 "Transmitting %u bytes to transport service\n",
823 * Schedule the task to send one message, either from the control
824 * list or the peer message queues to the service.
826 * @param cls transport service to schedule a transmission for
827 * @param tc scheduler context
830 schedule_transmission_task (void *cls,
831 const struct GNUNET_SCHEDULER_TaskContext *tc)
833 struct GNUNET_TRANSPORT_Handle *h = cls;
835 struct GNUNET_TRANSPORT_TransmitHandle *th;
838 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
839 GNUNET_assert (NULL != h->client);
840 /* destroy all requests that have timed out */
841 while ((NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) &&
842 (0 == GNUNET_TIME_absolute_get_remaining (n->th->timeout).rel_value_us))
844 /* notify client that the request could not be satisfied within
845 * the given time constraints */
848 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
850 LOG (GNUNET_ERROR_TYPE_DEBUG,
851 "Signalling timeout for transmission to peer %s due to congestion\n",
852 GNUNET_i2s (&n->id));
853 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
858 if (NULL != h->control_head)
860 size = h->control_head->notify_size;
864 n = GNUNET_CONTAINER_heap_peek (h->ready_heap);
866 return; /* no pending messages */
867 size = n->th->notify_size + sizeof (struct OutboundMessage);
869 LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling notify_transmit_ready\n");
871 GNUNET_CLIENT_notify_transmit_ready (h->client, size,
872 GNUNET_TIME_UNIT_FOREVER_REL,
873 GNUNET_NO, &transport_notify_ready,
875 GNUNET_assert (NULL != h->cth);
880 * Schedule the task to send one message, either from the control
881 * list or the peer message queues to the service.
883 * @param h transport service to schedule a transmission for
886 schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
888 struct GNUNET_TIME_Relative delay;
891 GNUNET_assert (NULL != h->client);
892 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
894 GNUNET_SCHEDULER_cancel (h->quota_task);
895 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
897 if (NULL != h->control_head)
898 delay = GNUNET_TIME_UNIT_ZERO;
899 else if (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap)))
902 GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
903 n->th->notify_size + n->traffic_overhead);
904 n->traffic_overhead = 0;
907 return; /* no work to be done */
908 LOG (GNUNET_ERROR_TYPE_DEBUG,
909 "Scheduling next transmission to service in %s\n",
910 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
912 GNUNET_SCHEDULER_add_delayed (delay, &schedule_transmission_task, h);
917 * Queue control request for transmission to the transport
920 * @param h handle to the transport service
921 * @param size number of bytes to be transmitted
922 * @param notify function to call to get the content
923 * @param notify_cls closure for @a notify
924 * @return a `struct GNUNET_TRANSPORT_TransmitHandle`
926 static struct GNUNET_TRANSPORT_TransmitHandle *
927 schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size,
928 GNUNET_CONNECTION_TransmitReadyNotify notify,
931 struct GNUNET_TRANSPORT_TransmitHandle *th;
933 LOG (GNUNET_ERROR_TYPE_DEBUG,
934 "Control transmit of %u bytes requested\n",
936 th = GNUNET_new (struct GNUNET_TRANSPORT_TransmitHandle);
938 th->notify_cls = notify_cls;
939 th->notify_size = size;
940 GNUNET_CONTAINER_DLL_insert_tail (h->control_head, h->control_tail, th);
941 schedule_transmission (h);
947 * Transmit START message to service.
950 * @param size number of bytes available in @a buf
951 * @param buf where to copy the message
952 * @return number of bytes copied to @a buf
955 send_start (void *cls, size_t size, void *buf)
957 struct GNUNET_TRANSPORT_Handle *h = cls;
958 struct StartMessage s;
963 /* Can only be shutdown, just give up */
964 LOG (GNUNET_ERROR_TYPE_DEBUG,
965 "Shutdown while trying to transmit `%s' request.\n",
969 LOG (GNUNET_ERROR_TYPE_DEBUG,
970 "Transmitting `%s' request.\n",
972 GNUNET_assert (size >= sizeof (struct StartMessage));
973 s.header.size = htons (sizeof (struct StartMessage));
974 s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START);
980 s.options = htonl (options);
982 memcpy (buf, &s, sizeof (struct StartMessage));
983 GNUNET_CLIENT_receive (h->client, &demultiplexer, h,
984 GNUNET_TIME_UNIT_FOREVER_REL);
985 return sizeof (struct StartMessage);
990 * Try again to connect to transport service.
992 * @param cls the handle to the transport service
993 * @param tc scheduler context
996 reconnect (void *cls,
997 const struct GNUNET_SCHEDULER_TaskContext *tc)
999 struct GNUNET_TRANSPORT_Handle *h = cls;
1001 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1002 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1004 /* shutdown, just give up */
1007 LOG (GNUNET_ERROR_TYPE_DEBUG,
1008 "Connecting to transport service.\n");
1009 GNUNET_assert (NULL == h->client);
1010 GNUNET_assert (NULL == h->control_head);
1011 GNUNET_assert (NULL == h->control_tail);
1012 reconnecting = GNUNET_NO;
1013 h->client = GNUNET_CLIENT_connect ("transport", h->cfg);
1015 GNUNET_assert (NULL != h->client);
1016 schedule_control_transmit (h, sizeof (struct StartMessage), &send_start, h);
1021 * Function that will schedule the job that will try
1022 * to connect us again to the client.
1024 * @param h transport service to reconnect
1027 disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
1029 struct GNUNET_TRANSPORT_TransmitHandle *th;
1031 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
1034 GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
1037 if (NULL != h->client)
1039 GNUNET_CLIENT_disconnect (h->client);
1041 /* LOG (GNUNET_ERROR_TYPE_ERROR,
1042 "Client disconnect done \n");*/
1044 /* Forget about all neighbours that we used to be connected to */
1045 GNUNET_CONTAINER_multipeermap_iterate (h->neighbours,
1046 &neighbour_delete, h);
1047 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
1049 GNUNET_SCHEDULER_cancel (h->quota_task);
1050 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
1052 while ((NULL != (th = h->control_head)))
1054 GNUNET_CONTAINER_DLL_remove (h->control_head, h->control_tail, th);
1055 th->notify (th->notify_cls, 0, NULL);
1058 LOG (GNUNET_ERROR_TYPE_DEBUG,
1059 "Scheduling task to reconnect to transport service in %s.\n",
1060 GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES));
1062 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
1063 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
1068 * Cancel control request for transmission to the transport service.
1070 * @param th handle to the transport service
1071 * @param tth transmit handle to cancel
1074 cancel_control_transmit (struct GNUNET_TRANSPORT_Handle *th,
1075 struct GNUNET_TRANSPORT_TransmitHandle *tth)
1077 LOG (GNUNET_ERROR_TYPE_DEBUG,
1078 "Canceling transmit of contral transmission requested\n");
1079 GNUNET_CONTAINER_DLL_remove (th->control_head, th->control_tail, tth);
1086 * Send REQUEST_CONNECT message to the service.
1088 * @param cls the `struct GNUNET_PeerIdentity`
1089 * @param size number of bytes available in @a buf
1090 * @param buf where to copy the message
1091 * @return number of bytes copied to @a buf
1094 send_try_connect (void *cls, size_t size, void *buf)
1096 struct GNUNET_TRANSPORT_TryConnectHandle *tch = cls;
1097 struct TransportRequestConnectMessage msg;
1101 if (NULL != tch->cb)
1102 tch->cb (tch->cb_cls, GNUNET_SYSERR);
1103 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch);
1104 LOG (GNUNET_ERROR_TYPE_DEBUG,
1105 "Discarding `%s' request to `%4s' due to error in transport service connection.\n",
1107 GNUNET_i2s (&tch->pid));
1111 LOG (GNUNET_ERROR_TYPE_DEBUG,
1112 "Transmitting `%s' request with respect to `%4s'.\n",
1114 GNUNET_i2s (&tch->pid));
1115 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1116 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
1117 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT);
1118 msg.reserved = htonl (0);
1119 msg.peer = tch->pid;
1120 memcpy (buf, &msg, sizeof (msg));
1121 if (NULL != tch->cb)
1122 tch->cb (tch->cb_cls, GNUNET_OK);
1123 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch);
1125 return sizeof (struct TransportRequestConnectMessage);
1129 * Ask the transport service to establish a connection to
1132 * @param handle connection to transport service
1133 * @param target who we should try to connect to
1134 * @param cb callback to be called when request was transmitted to transport
1136 * @param cb_cls closure for the callback
1137 * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
1138 * NULL on failure (cb will not be called)
1140 struct GNUNET_TRANSPORT_TryConnectHandle *
1141 GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1142 const struct GNUNET_PeerIdentity *target,
1143 GNUNET_TRANSPORT_TryConnectCallback cb,
1146 struct GNUNET_TRANSPORT_TryConnectHandle *tch = NULL;
1148 if (NULL == handle->client)
1150 tch = GNUNET_new (struct GNUNET_TRANSPORT_TryConnectHandle);
1152 tch->pid = *(target);
1154 tch->cb_cls = cb_cls;
1155 tch->tth = schedule_control_transmit (handle,
1156 sizeof (struct TransportRequestConnectMessage),
1157 &send_try_connect, tch);
1158 GNUNET_CONTAINER_DLL_insert(handle->tc_head, handle->tc_tail, tch);
1164 * Cancel the request to transport to try a connect
1165 * Callback will not be called
1167 * @param tch the handle to cancel
1170 GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch)
1172 struct GNUNET_TRANSPORT_Handle *th;
1175 cancel_control_transmit (th, tch->tth);
1176 GNUNET_CONTAINER_DLL_remove (th->tc_head, th->tc_tail, tch);
1181 * Send HELLO message to the service.
1183 * @param cls the HELLO message to send
1184 * @param size number of bytes available in @a buf
1185 * @param buf where to copy the message
1186 * @return number of bytes copied to @a buf
1189 send_hello (void *cls, size_t size, void *buf)
1191 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls;
1192 struct GNUNET_MessageHeader *msg = ohh->msg;
1194 struct GNUNET_SCHEDULER_TaskContext tc;
1196 tc.read_ready = NULL;
1197 tc.write_ready = NULL;
1198 tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
1201 LOG (GNUNET_ERROR_TYPE_DEBUG,
1202 "Timeout while trying to transmit `%s' request.\n",
1204 if (NULL != ohh->cont)
1205 ohh->cont (ohh->cls, &tc);
1207 GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head, ohh->th->oh_tail, ohh);
1211 LOG (GNUNET_ERROR_TYPE_DEBUG,
1212 "Transmitting `%s' request.\n",
1214 ssize = ntohs (msg->size);
1215 GNUNET_assert (size >= ssize);
1216 memcpy (buf, msg, ssize);
1218 tc.reason = GNUNET_SCHEDULER_REASON_READ_READY;
1219 if (NULL != ohh->cont)
1220 ohh->cont (ohh->cls, &tc);
1221 GNUNET_CONTAINER_DLL_remove (ohh->th->oh_head, ohh->th->oh_tail, ohh);
1228 * Send traffic metric message to the service.
1230 * @param cls the message to send
1231 * @param size number of bytes available in @a buf
1232 * @param buf where to copy the message
1233 * @return number of bytes copied to @a buf
1236 send_metric (void *cls, size_t size, void *buf)
1238 struct TrafficMetricMessage *msg = cls;
1243 LOG (GNUNET_ERROR_TYPE_DEBUG,
1244 "Timeout while trying to transmit `%s' request.\n",
1249 LOG (GNUNET_ERROR_TYPE_DEBUG,
1250 "Transmitting `%s' request.\n",
1252 ssize = ntohs (msg->header.size);
1253 GNUNET_assert (size >= ssize);
1254 memcpy (buf, msg, ssize);
1261 * Set transport metrics for a peer and a direction
1263 * @param handle transport handle
1264 * @param peer the peer to set the metric for
1265 * @param inbound set inbound direction (#GNUNET_YES or #GNUNET_NO)
1266 * @param outbound set outbound direction (#GNUNET_YES or #GNUNET_NO)
1267 * @param ats the metric as ATS information
1268 * @param ats_count the number of metrics
1270 * Supported ATS values:
1271 * #GNUNET_ATS_QUALITY_NET_DELAY (value in ms)
1272 * #GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops))
1275 * To enforce a delay of 10 ms for peer p1 in sending direction use:
1277 * struct GNUNET_ATS_Information ats;
1278 * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY);
1279 * ats.value = ntohl (10);
1280 * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1);
1283 * Delay restrictions in receiving direction will be enforced with
1287 GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
1288 const struct GNUNET_PeerIdentity *peer,
1291 const struct GNUNET_ATS_Information *ats,
1294 struct TrafficMetricMessage *msg;
1296 GNUNET_assert ((outbound == GNUNET_YES) || (outbound == GNUNET_NO));
1297 GNUNET_assert ((inbound == GNUNET_YES) || (inbound == GNUNET_NO));
1298 if ((GNUNET_NO == inbound) && (GNUNET_NO == outbound))
1303 size_t len = sizeof (struct TrafficMetricMessage) +
1304 ats_count * sizeof (struct GNUNET_ATS_Information);
1306 msg = GNUNET_malloc (len);
1307 msg->header.size = htons (len);
1308 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC);
1309 msg->direction = htons (0 + outbound + 2 * inbound);
1310 msg->ats_count = htons (ats_count);
1311 msg->peer = (*peer);
1312 memcpy (&msg[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information));
1313 schedule_control_transmit (handle, len, &send_metric, msg);
1319 * Offer the transport service the HELLO of another peer. Note that
1320 * the transport service may just ignore this message if the HELLO is
1321 * malformed or useless due to our local configuration.
1323 * @param handle connection to transport service
1324 * @param hello the hello message
1325 * @param cont continuation to call when HELLO has been sent,
1326 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
1327 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
1328 * @param cls closure for continuation
1329 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on failure,
1330 * in case of failure cont will not be called
1333 struct GNUNET_TRANSPORT_OfferHelloHandle *
1334 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1335 const struct GNUNET_MessageHeader *hello,
1336 GNUNET_SCHEDULER_Task cont, void *cls)
1338 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh;
1339 struct GNUNET_MessageHeader *msg;
1340 struct GNUNET_PeerIdentity peer;
1343 if (NULL == handle->client)
1345 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
1346 size = ntohs (hello->size);
1347 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
1349 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer))
1355 msg = GNUNET_malloc (size);
1356 memcpy (msg, hello, size);
1357 LOG (GNUNET_ERROR_TYPE_DEBUG,
1358 "Offering `%s' message of `%4s' to transport for validation.\n", "HELLO",
1359 GNUNET_i2s (&peer));
1361 ohh = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle);
1366 ohh->tth = schedule_control_transmit (handle, size, &send_hello, ohh);
1367 GNUNET_CONTAINER_DLL_insert (handle->oh_head, handle->oh_tail, ohh);
1373 * Cancel the request to transport to offer the HELLO message
1375 * @param ohh the GNUNET_TRANSPORT_OfferHelloHandle to cancel
1378 GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
1380 struct GNUNET_TRANSPORT_Handle *th = ohh->th;
1382 cancel_control_transmit (ohh->th, ohh->tth);
1383 GNUNET_CONTAINER_DLL_remove (th->oh_head, th->oh_tail, ohh);
1384 GNUNET_free (ohh->msg);
1390 * Checks if a given peer is connected to us
1392 * @param handle connection to transport service
1393 * @param peer the peer to check
1394 * @return #GNUNET_YES (connected) or #GNUNET_NO (disconnected)
1397 GNUNET_TRANSPORT_check_peer_connected (struct GNUNET_TRANSPORT_Handle *handle,
1398 const struct GNUNET_PeerIdentity *peer)
1401 GNUNET_CONTAINER_multipeermap_contains (handle->neighbours,
1409 * Task to call the HelloUpdateCallback of the GetHelloHandle
1411 * @param cls the `struct GNUNET_TRANSPORT_GetHelloHandle`
1412 * @param tc the scheduler task context
1415 call_hello_update_cb_async (void *cls,
1416 const struct GNUNET_SCHEDULER_TaskContext *tc)
1418 struct GNUNET_TRANSPORT_GetHelloHandle *ghh = cls;
1420 GNUNET_assert (NULL != ghh->handle->my_hello);
1421 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != ghh->notify_task);
1422 ghh->notify_task = GNUNET_SCHEDULER_NO_TASK;
1423 ghh->rec (ghh->rec_cls,
1424 (const struct GNUNET_MessageHeader *) ghh->handle->my_hello);
1429 * Obtain the HELLO message for this peer. The callback given in this function
1430 * is never called synchronously.
1432 * @param handle connection to transport service
1433 * @param rec function to call with the HELLO, sender will be our peer
1434 * identity; message and sender will be NULL on timeout
1435 * (handshake with transport service pending/failed).
1436 * cost estimate will be 0.
1437 * @param rec_cls closure for @a rec
1438 * @return handle to cancel the operation
1440 struct GNUNET_TRANSPORT_GetHelloHandle *
1441 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
1442 GNUNET_TRANSPORT_HelloUpdateCallback rec,
1445 struct GNUNET_TRANSPORT_GetHelloHandle *hwl;
1447 hwl = GNUNET_new (struct GNUNET_TRANSPORT_GetHelloHandle);
1449 hwl->rec_cls = rec_cls;
1450 hwl->handle = handle;
1451 GNUNET_CONTAINER_DLL_insert (handle->hwl_head, handle->hwl_tail, hwl);
1452 if (handle->my_hello != NULL)
1453 hwl->notify_task = GNUNET_SCHEDULER_add_now (&call_hello_update_cb_async,
1460 * Stop receiving updates about changes to our HELLO message.
1462 * @param ghh handle to cancel
1465 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_GetHelloHandle *ghh)
1467 struct GNUNET_TRANSPORT_Handle *handle = ghh->handle;
1469 if (GNUNET_SCHEDULER_NO_TASK != ghh->notify_task)
1470 GNUNET_SCHEDULER_cancel (ghh->notify_task);
1471 GNUNET_CONTAINER_DLL_remove (handle->hwl_head, handle->hwl_tail, ghh);
1477 * Connect to the transport service. Note that the connection may
1478 * complete (or fail) asynchronously.
1480 * @param cfg configuration to use
1481 * @param self our own identity (API should check that it matches
1482 * the identity found by transport), or NULL (no check)
1483 * @param cls closure for the callbacks
1484 * @param rec receive function to call
1485 * @param nc function to call on connect events
1486 * @param nd function to call on disconnect events
1488 struct GNUNET_TRANSPORT_Handle *
1489 GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1490 const struct GNUNET_PeerIdentity *self, void *cls,
1491 GNUNET_TRANSPORT_ReceiveCallback rec,
1492 GNUNET_TRANSPORT_NotifyConnect nc,
1493 GNUNET_TRANSPORT_NotifyDisconnect nd)
1495 struct GNUNET_TRANSPORT_Handle *ret;
1497 ret = GNUNET_new (struct GNUNET_TRANSPORT_Handle);
1501 ret->check_self = GNUNET_YES;
1508 ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
1509 LOG (GNUNET_ERROR_TYPE_DEBUG,
1510 "Connecting to transport service.\n");
1511 ret->client = GNUNET_CLIENT_connect ("transport", cfg);
1512 if (NULL == ret->client)
1518 GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE,
1521 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1522 schedule_control_transmit (ret, sizeof (struct StartMessage),
1529 * Disconnect from the transport service.
1531 * @param handle handle to the service as returned from #GNUNET_TRANSPORT_connect()
1534 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1536 LOG (GNUNET_ERROR_TYPE_DEBUG,
1537 "Transport disconnect called!\n");
1538 /* this disconnects all neighbours... */
1539 if (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
1540 disconnect_and_schedule_reconnect (handle);
1541 /* and now we stop trying to connect again... */
1542 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
1544 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
1545 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1547 GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours);
1548 handle->neighbours = NULL;
1549 if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK)
1551 GNUNET_SCHEDULER_cancel (handle->quota_task);
1552 handle->quota_task = GNUNET_SCHEDULER_NO_TASK;
1554 GNUNET_free_non_null (handle->my_hello);
1555 handle->my_hello = NULL;
1556 GNUNET_assert (handle->tc_head == NULL);
1557 GNUNET_assert (handle->tc_tail == NULL);
1558 GNUNET_assert (handle->hwl_head == NULL);
1559 GNUNET_assert (handle->hwl_tail == NULL);
1560 GNUNET_CONTAINER_heap_destroy (handle->ready_heap);
1561 handle->ready_heap = NULL;
1562 GNUNET_free (handle);
1567 * Check if we could queue a message of the given size for
1568 * transmission. The transport service will take both its
1569 * internal buffers and bandwidth limits imposed by the
1570 * other peer into consideration when answering this query.
1572 * @param handle connection to transport service
1573 * @param target who should receive the message
1574 * @param size how big is the message we want to transmit?
1575 * @param priority how important is the message?
1576 * @param timeout after how long should we give up (and call
1577 * notify with buf NULL and size 0)?
1578 * @param notify function to call when we are ready to
1579 * send such a message
1580 * @param notify_cls closure for @a notify
1581 * @return NULL if someone else is already waiting to be notified
1582 * non-NULL if the notify callback was queued (can be used to cancel
1583 * using #GNUNET_TRANSPORT_notify_transmit_ready_cancel)
1585 struct GNUNET_TRANSPORT_TransmitHandle *
1586 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1587 const struct GNUNET_PeerIdentity *target,
1588 size_t size, uint32_t priority,
1589 struct GNUNET_TIME_Relative timeout,
1590 GNUNET_CONNECTION_TransmitReadyNotify notify,
1593 struct Neighbour *n;
1594 struct GNUNET_TRANSPORT_TransmitHandle *th;
1595 struct GNUNET_TIME_Relative delay;
1597 n = neighbour_find (handle, target);
1600 /* use GNUNET_TRANSPORT_try_connect first, only use this function
1601 * once a connection has been established */
1607 /* attempt to send two messages at the same time to the same peer */
1611 GNUNET_assert (NULL == n->hn);
1612 th = GNUNET_new (struct GNUNET_TRANSPORT_TransmitHandle);
1614 th->notify = notify;
1615 th->notify_cls = notify_cls;
1616 th->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1617 th->notify_size = size;
1618 th->priority = priority;
1620 /* calculate when our transmission should be ready */
1621 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, size + n->traffic_overhead);
1622 n->traffic_overhead = 0;
1623 if (delay.rel_value_us > timeout.rel_value_us)
1624 delay.rel_value_us = 0; /* notify immediately (with failure) */
1625 LOG (GNUNET_ERROR_TYPE_DEBUG,
1626 "Bandwidth tracker allows next transmission to peer %s in %s\n",
1627 GNUNET_i2s (target),
1628 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
1629 n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap, n, delay.rel_value_us);
1630 schedule_transmission (handle);
1636 * Cancel the specified transmission-ready notification.
1638 * @param th handle returned from #GNUNET_TRANSPORT_notify_transmit_ready()
1641 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th)
1643 struct Neighbour *n;
1645 GNUNET_assert (NULL == th->next);
1646 GNUNET_assert (NULL == th->prev);
1648 GNUNET_assert (th == n->th);
1652 GNUNET_CONTAINER_heap_remove_node (n->hn);
1657 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != th->timeout_task);
1658 GNUNET_SCHEDULER_cancel (th->timeout_task);
1659 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1665 /* end of transport_api.c */