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 struct GNUNET_SCHEDULER_Handle *sched;
337 const struct GNUNET_CONFIGURATION_Handle *cfg;
340 * Linked list of the current neighbours of this peer.
342 struct NeighbourList *neighbours;
345 * Peer identity as assumed by this process, or all zeros.
347 struct GNUNET_PeerIdentity self;
350 * ID of the task trying to reconnect to the service.
352 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
355 * ID of the task trying to trigger transmission for a peer
356 * while maintaining bandwidth quotas.
358 GNUNET_SCHEDULER_TaskIdentifier quota_task;
361 * Delay until we try to reconnect.
363 struct GNUNET_TIME_Relative reconnect_delay;
366 * Set once we are in the process of disconnecting from the
372 * Should we check that 'self' matches what the service thinks?
373 * (if GNUNET_NO, then 'self' is all zeros!).
379 // FIXME: replace with hash map!
381 * Get the neighbour list entry for the given peer
383 * @param h our context
384 * @param peer peer to look up
385 * @return NULL if no such peer entry exists
387 static struct NeighbourList *
388 neighbour_find (struct GNUNET_TRANSPORT_Handle *h,
389 const struct GNUNET_PeerIdentity *peer)
391 struct NeighbourList *pos;
394 while ((pos != NULL) &&
395 (0 != memcmp (peer, &pos->id, sizeof (struct GNUNET_PeerIdentity))))
402 * Schedule the task to send one message, either from the control
403 * list or the peer message queues to the service.
405 static void schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
409 * Function called by the scheduler when the timeout for bandwidth
410 * availablility for the target neighbour is reached.
412 * @param cls the 'struct GNUNET_TRANSPORT_Handle*'
413 * @param tc scheduler context
416 quota_transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
418 struct GNUNET_TRANSPORT_Handle *h = cls;
420 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
421 schedule_transmission (h);
426 * Figure out which transmission to a peer can be done right now.
427 * If none can, schedule a task to call 'schedule_transmission'
428 * whenever a peer transmission can be done in the future and
429 * return NULL. Otherwise return the next transmission to be
432 * @param h handle to transport
433 * @return NULL to wait longer before doing any peer transmissions
435 static struct GNUNET_TRANSPORT_TransmitHandle *
436 schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h)
438 struct GNUNET_TRANSPORT_TransmitHandle *ret;
439 struct GNUNET_TRANSPORT_TransmitHandle *th;
440 struct NeighbourList *n;
441 struct NeighbourList *next;
442 struct GNUNET_TIME_Relative retry_time;
443 struct GNUNET_TIME_Relative duration;
445 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
447 GNUNET_SCHEDULER_cancel (h->sched,
449 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
451 retry_time = GNUNET_TIME_UNIT_FOREVER_REL;
453 next = h->neighbours;
454 while (NULL != (n = next))
457 if (n->transmit_stage != TS_QUEUED)
458 continue; /* not eligible */
459 if (n->is_connected != GNUNET_YES)
462 th = &n->transmit_handle;
463 GNUNET_break (n == th->neighbour);
464 /* check outgoing quota */
465 duration = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
466 th->notify_size - sizeof (struct OutboundMessage));
467 if (th->timeout.value < duration.value)
469 /* signal timeout! */
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "Would need %llu ms before bandwidth is available for delivery to `%4s', that is too long. Signaling timeout.\n",
474 GNUNET_i2s (&n->id));
476 if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
478 GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task);
479 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
481 n->transmit_stage = TS_NEW;
482 if (NULL != th->notify)
483 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
486 if (duration.value > 0)
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Need more bandwidth (%u b/s allowed, %u b needed), delaying delivery to `%4s' by %llu ms\n",
491 (unsigned int) n->out_tracker.available_bytes_per_s__,
492 (unsigned int) th->notify_size - sizeof (struct OutboundMessage),
496 retry_time = GNUNET_TIME_relative_min (retry_time,
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
502 "Have %u bytes of bandwidth available for transmission to `%4s' right now\n",
503 th->notify_size - sizeof (struct OutboundMessage),
504 GNUNET_i2s (&n->id));
507 if ( (ret == NULL) ||
508 (ret->priority < th->priority) )
512 h->quota_task = GNUNET_SCHEDULER_add_delayed (h->sched,
514 "a_transmit_ready,
521 * Transmit message(s) to service.
523 * @param cls handle to transport
524 * @param size number of bytes available in buf
525 * @param buf where to copy the message
526 * @return number of bytes copied to buf
529 transport_notify_ready (void *cls, size_t size, void *buf)
531 struct GNUNET_TRANSPORT_Handle *h = cls;
532 struct ControlMessage *cm;
533 struct GNUNET_TRANSPORT_TransmitHandle *th;
534 struct NeighbourList *n;
535 struct OutboundMessage obm;
541 h->network_handle = NULL;
544 schedule_transmission (h);
548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
549 "Ready to transmit %u bytes to transport service\n", size);
553 while ( (NULL != (cm = h->control_head)) &&
554 (cm->notify_size <= size) )
556 if (cm->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
558 GNUNET_SCHEDULER_cancel (h->sched, cm->notify_delay_task);
559 cm->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
561 GNUNET_CONTAINER_DLL_remove (h->control_head,
564 nret = cm->notify (cm->notify_cls, size, &cbuf[ret]);
566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
567 "Added %u bytes of control message at %u\n",
575 while ( (NULL != (th = schedule_peer_transmission (h))) &&
576 (th->notify_size <= size) )
578 if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
580 GNUNET_SCHEDULER_cancel (h->sched, th->notify_delay_task);
581 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
584 switch (n->transmit_stage)
590 n->transmit_stage = TS_TRANSMITTED;
595 case TS_TRANSMITTED_QUEUED:
601 GNUNET_assert (size >= sizeof (struct OutboundMessage));
602 mret = th->notify (th->notify_cls,
603 size - sizeof (struct OutboundMessage),
604 &cbuf[ret + sizeof (struct OutboundMessage)]);
605 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
608 "Message of %u bytes with timeout %llums constructed for `%4s'\n",
610 (unsigned long long) GNUNET_TIME_absolute_get_remaining (th->timeout).value,
611 GNUNET_i2s (&n->id));
615 GNUNET_assert (mret + sizeof (struct OutboundMessage) < GNUNET_SERVER_MAX_MESSAGE_SIZE);
616 obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND);
617 obm.header.size = htons (mret + sizeof (struct OutboundMessage));
618 obm.priority = htonl (th->priority);
619 obm.timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (th->timeout));
621 memcpy (&cbuf[ret], &obm, sizeof (struct OutboundMessage));
622 ret += (mret + sizeof (struct OutboundMessage));
623 size -= (mret + sizeof (struct OutboundMessage));
624 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, mret);
628 switch (n->transmit_stage)
637 n->transmit_stage = TS_NEW;
639 case TS_TRANSMITTED_QUEUED:
640 n->transmit_stage = TS_QUEUED;
647 schedule_transmission (h);
649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
650 "Transmitting %u bytes to transport service\n", ret);
657 * Schedule the task to send one message, either from the control
658 * list or the peer message queues to the service.
661 schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
664 struct GNUNET_TIME_Relative timeout;
665 struct GNUNET_TRANSPORT_TransmitHandle *th;
667 if (NULL != h->network_handle)
669 if (h->client == NULL)
671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 _("Could not yet schedule transmission: we are not yet connected to the transport service!\n"));
673 return; /* not yet connected */
675 if (NULL != h->control_head)
677 size = h->control_head->notify_size;
678 timeout = GNUNET_TIME_UNIT_FOREVER_REL;
682 th = schedule_peer_transmission (h);
685 /* no transmission ready right now */
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
688 "Could not yet schedule transmission: none ready\n");
692 size = th->notify_size;
693 timeout = GNUNET_TIME_absolute_get_remaining (th->timeout);
696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
697 "Calling notify_transmit_ready\n");
700 GNUNET_CLIENT_notify_transmit_ready (h->client,
704 &transport_notify_ready,
706 GNUNET_assert (NULL != h->network_handle);
711 * Called when our transmit request timed out before any transport
712 * reported success connecting to the desired peer or before the
713 * transport was ready to receive. Signal error and free
717 control_transmit_timeout (void *cls,
718 const struct GNUNET_SCHEDULER_TaskContext *tc)
720 struct ControlMessage *th = cls;
722 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
723 if (NULL != th->notify)
724 th->notify (th->notify_cls, 0, NULL);
725 GNUNET_CONTAINER_DLL_remove (th->h->control_head,
733 * Queue control request for transmission to the transport
736 * @param h handle to the transport service
737 * @param size number of bytes to be transmitted
738 * @param at_head request must be added to the head of the queue
739 * (otherwise request will be appended)
740 * @param timeout how long this transmission can wait (at most)
741 * @param notify function to call to get the content
742 * @param notify_cls closure for notify
745 schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h,
748 struct GNUNET_TIME_Relative timeout,
749 GNUNET_CONNECTION_TransmitReadyNotify notify,
752 struct ControlMessage *th;
755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 "Control transmit of %u bytes within %llums requested\n",
757 size, (unsigned long long) timeout.value);
759 th = GNUNET_malloc (sizeof (struct ControlMessage));
762 th->notify_cls = notify_cls;
763 th->notify_size = size;
764 th->notify_delay_task
765 = GNUNET_SCHEDULER_add_delayed (h->sched,
766 timeout, &control_transmit_timeout, th);
768 GNUNET_CONTAINER_DLL_insert (h->control_head,
772 GNUNET_CONTAINER_DLL_insert_after (h->control_head,
776 schedule_transmission (h);
780 struct SetQuotaContext
782 struct GNUNET_TRANSPORT_Handle *handle;
784 struct GNUNET_PeerIdentity target;
786 GNUNET_SCHEDULER_Task cont;
790 struct GNUNET_TIME_Absolute timeout;
792 struct GNUNET_BANDWIDTH_Value32NBO quota_in;
797 * Send SET_QUOTA message to the service.
799 * @param cls the 'struct SetQuotaContext'
800 * @param size number of bytes available in buf
801 * @param buf where to copy the message
802 * @return number of bytes copied to buf
805 send_set_quota (void *cls, size_t size, void *buf)
807 struct SetQuotaContext *sqc = cls;
808 struct QuotaSetMessage *msg;
812 GNUNET_SCHEDULER_add_continuation (sqc->handle->sched,
815 GNUNET_SCHEDULER_REASON_TIMEOUT);
820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
821 "Transmitting `%s' request with respect to `%4s'.\n",
823 GNUNET_i2s (&sqc->target));
825 GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
827 msg->header.size = htons (sizeof (struct QuotaSetMessage));
828 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
829 msg->quota = sqc->quota_in;
830 memcpy (&msg->peer, &sqc->target, sizeof (struct GNUNET_PeerIdentity));
831 if (sqc->cont != NULL)
832 GNUNET_SCHEDULER_add_continuation (sqc->handle->sched,
835 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
837 return sizeof (struct QuotaSetMessage);
842 * Set the share of incoming bandwidth for the given
843 * peer to the specified amount.
845 * @param handle connection to transport service
846 * @param target who's bandwidth quota is being changed
847 * @param quota_in incoming bandwidth quota in bytes per ms
848 * @param quota_out outgoing bandwidth quota in bytes per ms
849 * @param timeout how long to wait until signaling failure if
850 * we can not communicate the quota change
851 * @param cont continuation to call when done, will be called
852 * either with reason "TIMEOUT" or with reason "PREREQ_DONE"
853 * @param cont_cls closure for continuation
856 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
857 const struct GNUNET_PeerIdentity *target,
858 struct GNUNET_BANDWIDTH_Value32NBO quota_in,
859 struct GNUNET_BANDWIDTH_Value32NBO quota_out,
860 struct GNUNET_TIME_Relative timeout,
861 GNUNET_SCHEDULER_Task cont, void *cont_cls)
863 struct NeighbourList *n;
864 struct SetQuotaContext *sqc;
866 n = neighbour_find (handle, target);
870 if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__)
871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
872 "Quota changed from %u to %u for peer `%s'\n",
873 (unsigned int) n->out_tracker.available_bytes_per_s__,
874 (unsigned int) ntohl (quota_out.value__),
875 GNUNET_i2s (target));
877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
878 "Quota remains at %u for peer `%s'\n",
879 (unsigned int) n->out_tracker.available_bytes_per_s__,
880 GNUNET_i2s (target));
882 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker,
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
889 "Quota changed to %u for peer `%s', but I have no such neighbour!\n",
890 (unsigned int) ntohl (quota_out.value__),
891 GNUNET_i2s (target));
894 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
895 sqc->handle = handle;
896 sqc->target = *target;
898 sqc->cont_cls = cont_cls;
899 sqc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
900 sqc->quota_in = quota_in;
901 schedule_control_transmit (handle,
902 sizeof (struct QuotaSetMessage),
903 GNUNET_NO, timeout, &send_set_quota, sqc);
908 * Obtain the HELLO message for this peer.
910 * @param handle connection to transport service
911 * @param rec function to call with the HELLO, sender will be our peer
912 * identity; message and sender will be NULL on timeout
913 * (handshake with transport service pending/failed).
914 * cost estimate will be 0.
915 * @param rec_cls closure for rec
918 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
919 GNUNET_TRANSPORT_HelloUpdateCallback rec,
922 struct HelloWaitList *hwl;
924 hwl = GNUNET_malloc (sizeof (struct HelloWaitList));
925 hwl->next = handle->hwl_head;
926 handle->hwl_head = hwl;
927 hwl->handle = handle;
929 hwl->rec_cls = rec_cls;
930 if (handle->my_hello == NULL)
932 rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello);
938 * Stop receiving updates about changes to our HELLO message.
940 * @param handle connection to transport service
941 * @param rec function previously registered to be called with the HELLOs
942 * @param rec_cls closure for rec
945 GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
946 GNUNET_TRANSPORT_HelloUpdateCallback rec,
949 struct HelloWaitList *pos;
950 struct HelloWaitList *prev;
953 pos = handle->hwl_head;
956 if ( (pos->rec == rec) &&
957 (pos->rec_cls == rec_cls) )
962 GNUNET_break (pos != NULL);
966 handle->hwl_head = pos->next;
968 prev->next = pos->next;
974 * Send HELLO message to the service.
976 * @param cls the HELLO message to send
977 * @param size number of bytes available in buf
978 * @param buf where to copy the message
979 * @return number of bytes copied to buf
982 send_hello (void *cls, size_t size, void *buf)
984 struct GNUNET_MessageHeader *hello = cls;
989 #if DEBUG_TRANSPORT_TIMEOUT
990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
991 "Timeout while trying to transmit `%s' request.\n",
998 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
999 "Transmitting `%s' request.\n", "HELLO");
1001 msize = ntohs (hello->size);
1002 GNUNET_assert (size >= msize);
1003 memcpy (buf, hello, msize);
1004 GNUNET_free (hello);
1010 * Offer the transport service the HELLO of another peer. Note that
1011 * the transport service may just ignore this message if the HELLO is
1012 * malformed or useless due to our local configuration.
1014 * @param handle connection to transport service
1015 * @param hello the hello message
1018 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1019 const struct GNUNET_MessageHeader *hello)
1021 struct GNUNET_MessageHeader *hc;
1023 struct GNUNET_PeerIdentity peer;
1025 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
1026 size = ntohs (hello->size);
1027 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
1028 if (GNUNET_OK != GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) hello,
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1036 "Offering `%s' message of `%4s' to transport for validation.\n",
1038 GNUNET_i2s (&peer));
1040 hc = GNUNET_malloc (size);
1041 memcpy (hc, hello, size);
1042 schedule_control_transmit (handle,
1044 GNUNET_NO, OFFER_HELLO_TIMEOUT, &send_hello, hc);
1049 * Transmit START message to service.
1052 * @param size number of bytes available in buf
1053 * @param buf where to copy the message
1054 * @return number of bytes copied to buf
1057 send_start (void *cls, size_t size, void *buf)
1059 struct GNUNET_TRANSPORT_Handle *h = cls;
1060 struct StartMessage s;
1064 /* Can only be shutdown, just give up */
1066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1067 "Shutdown while trying to transmit `%s' request.\n",
1073 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1074 "Transmitting `%s' request.\n", "START");
1076 GNUNET_assert (size >= sizeof (struct StartMessage));
1077 s.header.size = htons (sizeof (struct StartMessage));
1078 s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START);
1079 s.do_check = htonl (h->check_self);
1081 memcpy (buf, &s, sizeof (struct StartMessage));
1082 return sizeof (struct StartMessage);
1089 * @param n the entry to free
1092 neighbour_free (struct NeighbourList *n)
1094 struct GNUNET_TRANSPORT_Handle *h;
1095 struct NeighbourList *prev;
1096 struct NeighbourList *pos;
1100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1101 "Removing neighbour `%s' from list of connected peers.\n",
1102 GNUNET_i2s (&n->id));
1104 GNUNET_break (n->is_connected == GNUNET_NO);
1105 GNUNET_break (n->transmit_stage == TS_NEW);
1108 pos = h->neighbours;
1115 h->neighbours = n->next;
1117 prev->next = n->next;
1123 * Mark neighbour as disconnected.
1125 * @param n the entry to mark as disconnected
1128 neighbour_disconnect (struct NeighbourList *n)
1130 struct GNUNET_TRANSPORT_Handle *h = n->h;
1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1133 "Removing neighbour `%s' from list of connected peers.\n",
1134 GNUNET_i2s (&n->id));
1136 GNUNET_break (n->is_connected == GNUNET_YES);
1137 n->is_connected = GNUNET_NO;
1138 if (h->nc_cb != NULL)
1139 h->nd_cb (h->cls, &n->id);
1140 if (n->transmit_stage == TS_NEW)
1146 * Function we use for handling incoming messages.
1148 * @param cls closure (struct GNUNET_TRANSPORT_Handle *)
1149 * @param msg message received, NULL on timeout or fatal error
1151 static void demultiplexer (void *cls,
1152 const struct GNUNET_MessageHeader *msg);
1156 * Try again to connect to transport service.
1158 * @param cls the handle to the transport service
1159 * @param tc scheduler context
1162 reconnect (void *cls,
1163 const struct GNUNET_SCHEDULER_TaskContext *tc)
1165 struct GNUNET_TRANSPORT_Handle *h = cls;
1166 struct ControlMessage *pos;
1167 struct NeighbourList *n;
1168 struct NeighbourList *next;
1170 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1171 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1173 /* shutdown, just give up */
1176 /* Forget about all neighbours that we used to be connected to */
1180 #if DEBUG_TRANSPORT_DISCONNECT
1181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1182 "Disconnecting due to reconnect being called\n");
1185 if (n->is_connected)
1186 neighbour_disconnect (n);
1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1191 "Connecting to transport service.\n");
1193 GNUNET_assert (h->client == NULL);
1194 h->client = GNUNET_CLIENT_connect (h->sched, "transport", h->cfg);
1195 GNUNET_assert (h->client != NULL);
1196 /* make sure we don't send "START" twice, remove existing entry from
1197 queue (if present) */
1198 pos = h->control_head;
1201 if (pos->notify == &send_start)
1203 GNUNET_CONTAINER_DLL_remove (h->control_head,
1206 if (GNUNET_SCHEDULER_NO_TASK != pos->notify_delay_task)
1208 GNUNET_SCHEDULER_cancel (h->sched, pos->notify_delay_task);
1209 pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1216 schedule_control_transmit (h,
1217 sizeof (struct StartMessage),
1219 GNUNET_TIME_UNIT_FOREVER_REL, &send_start, h);
1220 GNUNET_CLIENT_receive (h->client,
1221 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
1226 * Function that will schedule the job that will try
1227 * to connect us again to the client.
1229 * @param h transport service to reconnect
1232 schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1236 "Scheduling task to reconnect to transport service in %llu ms.\n",
1237 h->reconnect_delay.value);
1239 GNUNET_assert (h->client == NULL);
1240 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
1242 = GNUNET_SCHEDULER_add_delayed (h->sched,
1243 h->reconnect_delay, &reconnect, h);
1244 if (h->reconnect_delay.value == 0)
1246 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
1250 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
1251 h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
1252 h->reconnect_delay);
1258 * Send request connect message to the service.
1260 * @param cls the TransportRequestConnectMessage
1261 * @param size number of bytes available in buf
1262 * @param buf where to copy the message
1263 * @return number of bytes copied to buf
1266 send_transport_request_connect (void *cls, size_t size, void *buf)
1268 struct TransportRequestConnectMessage *trcm = cls;
1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1274 "Buffer null for %s\n",
1281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1282 "Transmitting `%s' request for `%4s'.\n",
1284 GNUNET_i2s (&trcm->peer));
1286 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1287 memcpy(buf, trcm, sizeof(struct TransportRequestConnectMessage));
1288 return sizeof(struct TransportRequestConnectMessage);
1292 * Create and send a request connect message to
1293 * the transport service for a particular peer.
1295 * @param h handle to the transport service
1296 * @param n the neighbor to send the request connect message about
1299 static void send_request_connect_message(struct GNUNET_TRANSPORT_Handle *h, struct NeighbourList *n)
1301 struct TransportRequestConnectMessage *trcm;
1303 trcm = GNUNET_malloc(sizeof(struct TransportRequestConnectMessage));
1304 trcm->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT);
1305 trcm->header.size = htons(sizeof(struct TransportRequestConnectMessage));
1306 memcpy(&trcm->peer, &n->id, sizeof(struct GNUNET_PeerIdentity));
1307 schedule_control_transmit (h,
1308 sizeof (struct TransportRequestConnectMessage),
1310 GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_request_connect, trcm);
1314 * Add neighbour to our list
1316 * @return NULL if this API is currently disconnecting from the service
1318 static struct NeighbourList *
1319 neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
1320 const struct GNUNET_PeerIdentity *pid)
1322 struct NeighbourList *n;
1324 if (GNUNET_YES == h->in_disconnect)
1326 /* check for duplicates */
1327 if (NULL != (n = neighbour_find (h, pid)))
1333 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1334 "Creating entry for neighbour `%4s'.\n",
1337 n = GNUNET_malloc (sizeof (struct NeighbourList));
1339 GNUNET_BANDWIDTH_tracker_init (&n->out_tracker,
1340 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
1341 MAX_BANDWIDTH_CARRY_S);
1342 n->next = h->neighbours;
1352 * Connect to the transport service. Note that the connection may
1353 * complete (or fail) asynchronously.
1355 * @param sched scheduler to use
1356 * @param cfg configuration to use
1357 * @param self our own identity (API should check that it matches
1358 * the identity found by transport), or NULL (no check)
1359 * @param cls closure for the callbacks
1360 * @param rec receive function to call
1361 * @param nc function to call on connect events
1362 * @param nd function to call on disconnect events
1364 struct GNUNET_TRANSPORT_Handle *
1365 GNUNET_TRANSPORT_connect (struct GNUNET_SCHEDULER_Handle *sched,
1366 const struct GNUNET_CONFIGURATION_Handle *cfg,
1367 const struct GNUNET_PeerIdentity *self,
1369 GNUNET_TRANSPORT_ReceiveCallback rec,
1370 GNUNET_TRANSPORT_NotifyConnect nc,
1371 GNUNET_TRANSPORT_NotifyDisconnect nd)
1373 struct GNUNET_TRANSPORT_Handle *ret;
1375 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle));
1379 ret->check_self = GNUNET_YES;
1387 ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
1388 schedule_reconnect (ret);
1394 * Disconnect from the transport service.
1397 GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1399 struct GNUNET_TRANSPORT_TransmitHandle *th;
1400 struct NeighbourList *n;
1401 struct HelloWaitList *hwl;
1402 struct GNUNET_CLIENT_Connection *client;
1403 struct ControlMessage *cm;
1406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
1408 handle->in_disconnect = GNUNET_YES;
1409 while (NULL != (n = handle->neighbours))
1411 handle->neighbours = n->next;
1412 switch (n->transmit_stage)
1415 case TS_TRANSMITTED:
1419 case TS_TRANSMITTED_QUEUED:
1420 th = &n->transmit_handle;
1421 if (th->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
1423 GNUNET_SCHEDULER_cancel (handle->sched,
1424 th->notify_delay_task);
1425 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1427 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
1434 while (NULL != (hwl = handle->hwl_head))
1436 handle->hwl_head = hwl->next;
1437 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1439 ("Disconnect while notification for `%s' still registered.\n"),
1441 if (hwl->rec != NULL)
1442 hwl->rec (hwl->rec_cls, NULL);
1446 /* Check for still scheduled control messages, cancel delay tasks if so */
1447 /* Added because somehow a notify_delay_task is remaining scheduled and is ever so annoying */
1448 while ( (NULL != (cm = handle->control_head)))
1451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1452 "Disconnect before control message sent!\n");
1454 if (cm->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
1456 GNUNET_SCHEDULER_cancel (handle->sched, cm->notify_delay_task);
1457 cm->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1459 GNUNET_CONTAINER_DLL_remove (handle->control_head,
1460 handle->control_tail,
1466 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
1468 GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
1469 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1471 if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK)
1473 GNUNET_SCHEDULER_cancel (handle->sched, handle->quota_task);
1474 handle->quota_task = GNUNET_SCHEDULER_NO_TASK;
1476 GNUNET_free_non_null (handle->my_hello);
1477 handle->my_hello = NULL;
1479 if (NULL != handle->network_handle)
1481 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->network_handle);
1482 handle->network_handle = NULL;
1484 if (NULL != (client = handle->client))
1487 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1488 "Disconnecting from transport service for good.\n");
1490 handle->client = NULL;
1491 GNUNET_CLIENT_disconnect (client, GNUNET_NO);
1493 GNUNET_free (handle);
1498 * Function we use for handling incoming messages.
1500 * @param cls closure (struct GNUNET_TRANSPORT_Handle *)
1501 * @param msg message received, NULL on timeout or fatal error
1504 demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
1506 struct GNUNET_TRANSPORT_Handle *h = cls;
1507 const struct DisconnectInfoMessage *dim;
1508 const struct ConnectInfoMessage *cim;
1509 const struct InboundMessage *im;
1510 const struct GNUNET_MessageHeader *imm;
1511 const struct SendOkMessage *okm;
1512 struct HelloWaitList *hwl;
1513 struct HelloWaitList *next_hwl;
1514 struct NeighbourList *n;
1515 struct GNUNET_PeerIdentity me;
1518 if (h->client == NULL)
1520 /* shutdown initiated from 'GNUNET_TRANSPORT_disconnect',
1521 finish clean up work! */
1528 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1529 "Error receiving from transport service, disconnecting temporarily.\n");
1531 if (h->network_handle != NULL)
1533 GNUNET_CLIENT_notify_transmit_ready_cancel (h->network_handle);
1534 h->network_handle = NULL;
1536 GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
1538 schedule_reconnect (h);
1541 GNUNET_CLIENT_receive (h->client,
1542 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
1543 size = ntohs (msg->size);
1544 switch (ntohs (msg->type))
1546 case GNUNET_MESSAGE_TYPE_HELLO:
1548 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg,
1555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1556 "Receiving (my own) `%s' message, I am `%4s'.\n",
1557 "HELLO", GNUNET_i2s (&me));
1559 GNUNET_free_non_null (h->my_hello);
1561 if (size < sizeof (struct GNUNET_MessageHeader))
1566 h->my_hello = GNUNET_malloc (size);
1567 memcpy (h->my_hello, msg, size);
1571 next_hwl = hwl->next;
1572 hwl->rec (hwl->rec_cls,
1573 (const struct GNUNET_MessageHeader *) h->my_hello);
1577 case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
1578 if (size != sizeof (struct ConnectInfoMessage))
1583 cim = (const struct ConnectInfoMessage *) msg;
1585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1586 "Receiving `%s' message for `%4s'.\n",
1587 "CONNECT", GNUNET_i2s (&cim->id));
1589 n = neighbour_find (h, &cim->id);
1591 n = neighbour_add (h,
1595 GNUNET_break (n->is_connected == GNUNET_NO);
1596 n->is_connected = GNUNET_YES;
1597 if (h->nc_cb != NULL)
1598 h->nc_cb (h->cls, &n->id,
1599 GNUNET_TIME_relative_ntoh (cim->latency),
1600 ntohl (cim->distance));
1602 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
1603 if (size != sizeof (struct DisconnectInfoMessage))
1608 dim = (const struct DisconnectInfoMessage *) msg;
1609 #if DEBUG_TRANSPORT_DISCONNECT
1610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1611 "Receiving `%s' message for `%4s'.\n",
1613 GNUNET_i2s (&dim->peer));
1615 n = neighbour_find (h, &dim->peer);
1616 GNUNET_break (n != NULL);
1618 neighbour_disconnect (n);
1620 case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK:
1621 if (size != sizeof (struct SendOkMessage))
1626 okm = (const struct SendOkMessage *) msg;
1628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1629 "Receiving `%s' message, transmission %s.\n", "SEND_OK",
1630 ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
1632 n = neighbour_find (h, &okm->peer);
1633 GNUNET_assert (n != NULL);
1634 switch (n->transmit_stage)
1642 case TS_TRANSMITTED:
1643 n->transmit_stage = TS_NEW;
1645 case TS_TRANSMITTED_QUEUED:
1646 n->transmit_stage = TS_QUEUED;
1647 schedule_transmission (h);
1653 case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV:
1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 "Receiving `%s' message.\n", "RECV");
1659 sizeof (struct InboundMessage) +
1660 sizeof (struct GNUNET_MessageHeader))
1665 im = (const struct InboundMessage *) msg;
1666 imm = (const struct GNUNET_MessageHeader *) &im[1];
1667 if (ntohs (imm->size) + sizeof (struct InboundMessage) != size)
1673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1674 "Received message of type %u from `%4s'.\n",
1675 ntohs (imm->type), GNUNET_i2s (&im->peer));
1677 n = neighbour_find (h, &im->peer);
1683 if (n->is_connected != GNUNET_YES)
1689 h->rec (h->cls, &im->peer, imm,
1690 GNUNET_TIME_relative_ntoh (im->latency), ntohl(im->distance));
1693 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1695 ("Received unexpected message of type %u in %s:%u\n"),
1696 ntohs (msg->type), __FILE__, __LINE__);
1704 * Called when our transmit request timed out before any transport
1705 * reported success connecting to the desired peer or before the
1706 * transport was ready to receive. Signal error and free
1709 * @param cls the 'struct GNUNET_TRANSPORT_TransmitHandle*' that is timing out
1710 * @param tc scheduler context
1713 peer_transmit_timeout (void *cls,
1714 const struct GNUNET_SCHEDULER_TaskContext *tc)
1716 struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
1717 struct NeighbourList *n;
1718 GNUNET_CONNECTION_TransmitReadyNotify notify;
1721 th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1724 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1725 "Triggering timeout for request to transmit to `%4s' (%d)\n",
1726 GNUNET_i2s (&n->id),
1729 notify = th->notify;
1730 notify_cls = th->notify_cls;
1731 switch (n->transmit_stage)
1737 n->transmit_stage = TS_NEW;
1738 if (n->is_connected == GNUNET_NO)
1741 case TS_TRANSMITTED:
1744 case TS_TRANSMITTED_QUEUED:
1745 n->transmit_stage = TS_TRANSMITTED;
1751 notify (notify_cls, 0, NULL);
1756 * Check if we could queue a message of the given size for
1757 * transmission. The transport service will take both its
1758 * internal buffers and bandwidth limits imposed by the
1759 * other peer into consideration when answering this query.
1761 * @param handle connection to transport service
1762 * @param target who should receive the message
1763 * @param size how big is the message we want to transmit?
1764 * @param priority how important is the message?
1765 * @param timeout after how long should we give up (and call
1766 * notify with buf NULL and size 0)?
1767 * @param notify function to call when we are ready to
1768 * send such a message
1769 * @param notify_cls closure for notify
1770 * @return NULL if someone else is already waiting to be notified
1771 * non-NULL if the notify callback was queued (can be used to cancel
1772 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
1774 struct GNUNET_TRANSPORT_TransmitHandle *
1775 GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
1777 const struct GNUNET_PeerIdentity
1778 *target, size_t size,
1779 unsigned int priority,
1780 struct GNUNET_TIME_Relative timeout,
1781 GNUNET_CONNECTION_TransmitReadyNotify
1782 notify, void *notify_cls)
1784 struct GNUNET_TRANSPORT_TransmitHandle *th;
1785 struct NeighbourList *n;
1787 if (size + sizeof (struct OutboundMessage) >=
1788 GNUNET_SERVER_MAX_MESSAGE_SIZE)
1791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1792 "Message size is %d, max allowed is %d.\n",
1793 size + sizeof (struct OutboundMessage), GNUNET_SERVER_MAX_MESSAGE_SIZE - 1);
1799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1800 "Asking transport service for transmission of %u bytes to peer `%4s' within %llu ms.\n",
1801 size, GNUNET_i2s (target),
1802 (unsigned long long) timeout.value);
1804 n = neighbour_find (handle, target);
1807 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1808 "Created neighbour entry for peer `%s'\n",
1809 GNUNET_i2s (target));
1810 n = neighbour_add (handle, target);
1815 * Send a request connect message if not connected,
1816 * otherwise we will never send anything to
1819 if (n->is_connected == GNUNET_NO)
1821 send_request_connect_message(handle, n);
1826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1827 "Could not create neighbour entry for peer `%s'\n",
1828 GNUNET_i2s (target));
1831 switch (n->transmit_stage)
1834 n->transmit_stage = TS_QUEUED;
1839 case TS_TRANSMITTED:
1840 n->transmit_stage = TS_TRANSMITTED_QUEUED;
1842 case TS_TRANSMITTED_QUEUED:
1849 th = &n->transmit_handle;
1851 th->notify = notify;
1852 th->notify_cls = notify_cls;
1853 th->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1854 th->notify_size = size + sizeof (struct OutboundMessage);
1855 th->priority = priority;
1856 th->notify_delay_task
1857 = GNUNET_SCHEDULER_add_delayed (handle->sched, timeout,
1858 &peer_transmit_timeout, th);
1859 schedule_transmission (handle);
1865 * Cancel the specified transmission-ready notification.
1868 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
1869 GNUNET_TRANSPORT_TransmitHandle
1872 struct NeighbourList *n;
1876 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1877 "Transmission request of %u bytes to `%4s' was cancelled.\n",
1878 th->notify_size - sizeof (struct OutboundMessage),
1879 GNUNET_i2s (&n->id));
1881 switch (n->transmit_stage)
1887 n->transmit_stage = TS_NEW;
1888 if (n->is_connected == GNUNET_NO)
1891 case TS_TRANSMITTED:
1894 case TS_TRANSMITTED_QUEUED:
1895 n->transmit_stage = TS_TRANSMITTED;
1903 /* end of transport_api.c */