aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-08 23:11:15 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-08 23:11:15 +0000
commitf040dc7945a9f13204eb5820420c59e7d3178fb6 (patch)
treed39fac045ec54e3896c7cf4eb4bf82425a82bcf3 /src/transport/transport_api.c
parent20bdb602303bf3b36ab046111c97b78ae7641178 (diff)
downloadgnunet-f040dc7945a9f13204eb5820420c59e7d3178fb6.tar.gz
gnunet-f040dc7945a9f13204eb5820420c59e7d3178fb6.zip
-doxgyen, indentation, code clean up
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r--src/transport/transport_api.c303
1 files changed, 171 insertions, 132 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 86ce454e5..a1c325e7a 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -24,8 +24,6 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * TODO: 26 * TODO:
27 * - adjust testcases to use new 'try connect' style (should be easy, breaks API compatibility!)
28 * - adjust core service to use new 'try connect' style (should be MUCH nicer there as well!)
29 * - test test test 27 * - test test test
30 */ 28 */
31#include "platform.h" 29#include "platform.h"
@@ -181,7 +179,7 @@ struct GNUNET_TRANSPORT_GetHelloHandle
181 GNUNET_SCHEDULER_TaskIdentifier notify_task; 179 GNUNET_SCHEDULER_TaskIdentifier notify_task;
182 180
183 /** 181 /**
184 * Closure for rec. 182 * Closure for @e rec.
185 */ 183 */
186 void *rec_cls; 184 void *rec_cls;
187 185
@@ -192,14 +190,27 @@ struct GNUNET_TRANSPORT_GetHelloHandle
192 */ 190 */
193struct GNUNET_TRANSPORT_TryConnectHandle 191struct GNUNET_TRANSPORT_TryConnectHandle
194{ 192{
193 /**
194 * For the DLL.
195 */
195 struct GNUNET_TRANSPORT_TryConnectHandle *prev; 196 struct GNUNET_TRANSPORT_TryConnectHandle *prev;
197
198 /**
199 * For the DLL.
200 */
196 struct GNUNET_TRANSPORT_TryConnectHandle *next; 201 struct GNUNET_TRANSPORT_TryConnectHandle *next;
197 202
198 struct GNUNET_PeerIdentity pid; 203 struct GNUNET_PeerIdentity pid;
199 204
200 struct GNUNET_TRANSPORT_Handle *th; 205 struct GNUNET_TRANSPORT_Handle *th;
206
201 struct GNUNET_TRANSPORT_TransmitHandle *tth; 207 struct GNUNET_TRANSPORT_TransmitHandle *tth;
208
202 GNUNET_TRANSPORT_TryConnectCallback cb; 209 GNUNET_TRANSPORT_TryConnectCallback cb;
210
211 /**
212 * Closure for @e cb.
213 */
203 void *cb_cls; 214 void *cb_cls;
204}; 215};
205 216
@@ -209,14 +220,25 @@ struct GNUNET_TRANSPORT_TryConnectHandle
209 */ 220 */
210struct GNUNET_TRANSPORT_OfferHelloHandle 221struct GNUNET_TRANSPORT_OfferHelloHandle
211{ 222{
223 /**
224 * For the DLL.
225 */
212 struct GNUNET_TRANSPORT_OfferHelloHandle *prev; 226 struct GNUNET_TRANSPORT_OfferHelloHandle *prev;
227
228 /**
229 * For the DLL.
230 */
213 struct GNUNET_TRANSPORT_OfferHelloHandle *next; 231 struct GNUNET_TRANSPORT_OfferHelloHandle *next;
214 232
215 struct GNUNET_TRANSPORT_Handle *th; 233 struct GNUNET_TRANSPORT_Handle *th;
216 234
217 struct GNUNET_TRANSPORT_TransmitHandle *tth; 235 struct GNUNET_TRANSPORT_TransmitHandle *tth;
236
218 GNUNET_SCHEDULER_Task cont; 237 GNUNET_SCHEDULER_Task cont;
219 238
239 /**
240 * Closure for @e cont
241 */
220 void *cls; 242 void *cls;
221 243
222 struct GNUNET_MessageHeader *msg; 244 struct GNUNET_MessageHeader *msg;
@@ -349,8 +371,8 @@ struct GNUNET_TRANSPORT_Handle
349 struct GNUNET_TIME_Relative reconnect_delay; 371 struct GNUNET_TIME_Relative reconnect_delay;
350 372
351 /** 373 /**
352 * Should we check that 'self' matches what the service thinks? 374 * Should we check that @e self matches what the service thinks?
353 * (if GNUNET_NO, then 'self' is all zeros!). 375 * (if #GNUNET_NO, then @e self is all zeros!).
354 */ 376 */
355 int check_self; 377 int check_self;
356 378
@@ -408,9 +430,10 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
408{ 430{
409 struct Neighbour *n; 431 struct Neighbour *n;
410 432
411 LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating entry for neighbour `%4s'.\n", 433 LOG (GNUNET_ERROR_TYPE_DEBUG,
434 "Creating entry for neighbour `%4s'.\n",
412 GNUNET_i2s (pid)); 435 GNUNET_i2s (pid));
413 n = GNUNET_malloc (sizeof (struct Neighbour)); 436 n = GNUNET_new (struct Neighbour);
414 n->id = *pid; 437 n->id = *pid;
415 n->h = h; 438 n->h = h;
416 n->is_ready = GNUNET_YES; 439 n->is_ready = GNUNET_YES;
@@ -429,12 +452,12 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
429/** 452/**
430 * Iterator over hash map entries, for deleting state of a neighbour. 453 * Iterator over hash map entries, for deleting state of a neighbour.
431 * 454 *
432 * @param cls the 'struct GNUNET_TRANSPORT_Handle*' 455 * @param cls the `struct GNUNET_TRANSPORT_Handle *`
433 * @param key peer identity 456 * @param key peer identity
434 * @param value value in the hash map, the neighbour entry to delete 457 * @param value value in the hash map, the neighbour entry to delete
435 * @return GNUNET_YES if we should continue to 458 * @return #GNUNET_YES if we should continue to
436 * iterate, 459 * iterate,
437 * GNUNET_NO if not. 460 * #GNUNET_NO if not.
438 */ 461 */
439static int 462static int
440neighbour_delete (void *cls, 463neighbour_delete (void *cls,
@@ -479,8 +502,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
479 uint32_t bytes_msg; 502 uint32_t bytes_msg;
480 uint32_t bytes_physical; 503 uint32_t bytes_physical;
481 504
482 GNUNET_assert (h->client != NULL); 505 GNUNET_assert (NULL != h->client);
483 if (msg == NULL) 506 if (NULL == msg)
484 { 507 {
485 LOG (GNUNET_ERROR_TYPE_DEBUG, 508 LOG (GNUNET_ERROR_TYPE_DEBUG,
486 "Error receiving from transport service, disconnecting temporarily.\n"); 509 "Error receiving from transport service, disconnecting temporarily.\n");
@@ -533,17 +556,21 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
533 GNUNET_break (0); 556 GNUNET_break (0);
534 break; 557 break;
535 } 558 }
536 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n", 559 LOG (GNUNET_ERROR_TYPE_DEBUG,
560 "Receiving `%s' message for `%4s'.\n",
537 "CONNECT", GNUNET_i2s (&cim->id)); 561 "CONNECT", GNUNET_i2s (&cim->id));
538 n = neighbour_find (h, &cim->id); 562 n = neighbour_find (h, &cim->id);
539 if (n != NULL) 563 if (NULL != n)
540 { 564 {
541 GNUNET_break (0); 565 GNUNET_break (0);
542 break; 566 break;
543 } 567 }
544 n = neighbour_add (h, &cim->id); 568 n = neighbour_add (h, &cim->id);
545 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s' with quota %u\n", 569 LOG (GNUNET_ERROR_TYPE_DEBUG,
546 "CONNECT", GNUNET_i2s (&cim->id), ntohl (cim->quota_out.value__)); 570 "Receiving `%s' message for `%4s' with quota %u\n",
571 "CONNECT",
572 GNUNET_i2s (&cim->id),
573 ntohl (cim->quota_out.value__));
547 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); 574 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out);
548 if (h->nc_cb != NULL) 575 if (h->nc_cb != NULL)
549 h->nc_cb (h->cls, &n->id); 576 h->nc_cb (h->cls, &n->id);
@@ -556,10 +583,11 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
556 } 583 }
557 dim = (const struct DisconnectInfoMessage *) msg; 584 dim = (const struct DisconnectInfoMessage *) msg;
558 GNUNET_break (ntohl (dim->reserved) == 0); 585 GNUNET_break (ntohl (dim->reserved) == 0);
559 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n", 586 LOG (GNUNET_ERROR_TYPE_DEBUG,
587 "Receiving `%s' message for `%4s'.\n",
560 "DISCONNECT", GNUNET_i2s (&dim->peer)); 588 "DISCONNECT", GNUNET_i2s (&dim->peer));
561 n = neighbour_find (h, &dim->peer); 589 n = neighbour_find (h, &dim->peer);
562 if (n == NULL) 590 if (NULL == n)
563 { 591 {
564 GNUNET_break (0); 592 GNUNET_break (0);
565 break; 593 break;
@@ -579,7 +607,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
579 "SEND_OK", ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); 607 "SEND_OK", ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
580 608
581 n = neighbour_find (h, &okm->peer); 609 n = neighbour_find (h, &okm->peer);
582 if (n == NULL) 610 if (NULL == n)
583 break; 611 break;
584 612
585 if (bytes_physical >= bytes_msg) 613 if (bytes_physical >= bytes_msg)
@@ -590,7 +618,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
590 } 618 }
591 GNUNET_break (GNUNET_NO == n->is_ready); 619 GNUNET_break (GNUNET_NO == n->is_ready);
592 n->is_ready = GNUNET_YES; 620 n->is_ready = GNUNET_YES;
593 if ((n->th != NULL) && (n->hn == NULL)) 621 if ((NULL != n->th) && (NULL == n->hn))
594 { 622 {
595 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task); 623 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task);
596 GNUNET_SCHEDULER_cancel (n->th->timeout_task); 624 GNUNET_SCHEDULER_cancel (n->th->timeout_task);
@@ -602,7 +630,9 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
602 } 630 }
603 break; 631 break;
604 case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV: 632 case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV:
605 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message.\n", "RECV"); 633 LOG (GNUNET_ERROR_TYPE_DEBUG,
634 "Receiving `%s' message.\n",
635 "RECV");
606 if (size < 636 if (size <
607 sizeof (struct InboundMessage) + sizeof (struct GNUNET_MessageHeader)) 637 sizeof (struct InboundMessage) + sizeof (struct GNUNET_MessageHeader))
608 { 638 {
@@ -616,19 +646,21 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
616 GNUNET_break (0); 646 GNUNET_break (0);
617 break; 647 break;
618 } 648 }
619 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %u from `%4s'.\n", 649 LOG (GNUNET_ERROR_TYPE_DEBUG,
650 "Received message of type %u from `%4s'.\n",
620 ntohs (imm->type), GNUNET_i2s (&im->peer)); 651 ntohs (imm->type), GNUNET_i2s (&im->peer));
621 n = neighbour_find (h, &im->peer); 652 n = neighbour_find (h, &im->peer);
622 if (n == NULL) 653 if (NULL == n)
623 { 654 {
624 GNUNET_break (0); 655 GNUNET_break (0);
625 break; 656 break;
626 } 657 }
627 if (h->rec != NULL) 658 if (NULL != h->rec)
628 h->rec (h->cls, &im->peer, imm); 659 h->rec (h->cls, &im->peer, imm);
629 break; 660 break;
630 case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA: 661 case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA:
631 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message.\n", "SET_QUOTA"); 662 LOG (GNUNET_ERROR_TYPE_DEBUG,
663 "Receiving `%s' message.\n", "SET_QUOTA");
632 if (size != sizeof (struct QuotaSetMessage)) 664 if (size != sizeof (struct QuotaSetMessage))
633 { 665 {
634 GNUNET_break (0); 666 GNUNET_break (0);
@@ -636,10 +668,13 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
636 } 668 }
637 qm = (const struct QuotaSetMessage *) msg; 669 qm = (const struct QuotaSetMessage *) msg;
638 n = neighbour_find (h, &qm->peer); 670 n = neighbour_find (h, &qm->peer);
639 if (n == NULL) 671 if (NULL == n)
640 break; 672 break;
641 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s' with quota %u\n", 673 LOG (GNUNET_ERROR_TYPE_DEBUG,
642 "SET_QUOTA", GNUNET_i2s (&qm->peer), ntohl (qm->quota.value__)); 674 "Receiving `%s' message for `%4s' with quota %u\n",
675 "SET_QUOTA",
676 GNUNET_i2s (&qm->peer),
677 ntohl (qm->quota.value__));
643 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota); 678 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota);
644 break; 679 break;
645 default: 680 default:
@@ -656,13 +691,12 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
656 * A transmission request could not be satisfied because of 691 * A transmission request could not be satisfied because of
657 * network congestion. Notify the initiator and clean up. 692 * network congestion. Notify the initiator and clean up.
658 * 693 *
659 * @param cls the 'struct GNUNET_TRANSPORT_TransmitHandle' 694 * @param cls the `struct GNUNET_TRANSPORT_TransmitHandle`
660 * @param tc scheduler context 695 * @param tc scheduler context
661 */ 696 */
662static void 697static void
663timeout_request_due_to_congestion (void *cls, 698timeout_request_due_to_congestion (void *cls,
664 const struct GNUNET_SCHEDULER_TaskContext 699 const struct GNUNET_SCHEDULER_TaskContext *tc)
665 *tc)
666{ 700{
667 struct GNUNET_TRANSPORT_TransmitHandle *th = cls; 701 struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
668 struct Neighbour *n = th->neighbour; 702 struct Neighbour *n = th->neighbour;
@@ -771,7 +805,8 @@ transport_notify_ready (void *cls, size_t size, void *buf)
771 } 805 }
772 /* if there are more pending messages, try to schedule those */ 806 /* if there are more pending messages, try to schedule those */
773 schedule_transmission (h); 807 schedule_transmission (h);
774 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes to transport service\n", 808 LOG (GNUNET_ERROR_TYPE_DEBUG,
809 "Transmitting %u bytes to transport service\n",
775 ret); 810 ret);
776 return ret; 811 return ret;
777} 812}
@@ -879,7 +914,7 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
879 * @param size number of bytes to be transmitted 914 * @param size number of bytes to be transmitted
880 * @param notify function to call to get the content 915 * @param notify function to call to get the content
881 * @param notify_cls closure for notify 916 * @param notify_cls closure for notify
882 * @return a GNUNET_TRANSPORT_TransmitHandle 917 * @return a `struct GNUNET_TRANSPORT_TransmitHandle`
883 */ 918 */
884static struct GNUNET_TRANSPORT_TransmitHandle * 919static struct GNUNET_TRANSPORT_TransmitHandle *
885schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size, 920schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size,
@@ -888,9 +923,10 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h, size_t size,
888{ 923{
889 struct GNUNET_TRANSPORT_TransmitHandle *th; 924 struct GNUNET_TRANSPORT_TransmitHandle *th;
890 925
891 LOG (GNUNET_ERROR_TYPE_DEBUG, "Control transmit of %u bytes requested\n", 926 LOG (GNUNET_ERROR_TYPE_DEBUG,
927 "Control transmit of %u bytes requested\n",
892 size); 928 size);
893 th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); 929 th = GNUNET_new (struct GNUNET_TRANSPORT_TransmitHandle);
894 th->notify = notify; 930 th->notify = notify;
895 th->notify_cls = notify_cls; 931 th->notify_cls = notify_cls;
896 th->notify_size = size; 932 th->notify_size = size;
@@ -915,14 +951,17 @@ send_start (void *cls, size_t size, void *buf)
915 struct StartMessage s; 951 struct StartMessage s;
916 uint32_t options; 952 uint32_t options;
917 953
918 if (buf == NULL) 954 if (NULL == buf)
919 { 955 {
920 /* Can only be shutdown, just give up */ 956 /* Can only be shutdown, just give up */
921 LOG (GNUNET_ERROR_TYPE_DEBUG, 957 LOG (GNUNET_ERROR_TYPE_DEBUG,
922 "Shutdown while trying to transmit `%s' request.\n", "START"); 958 "Shutdown while trying to transmit `%s' request.\n",
959 "START");
923 return 0; 960 return 0;
924 } 961 }
925 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "START"); 962 LOG (GNUNET_ERROR_TYPE_DEBUG,
963 "Transmitting `%s' request.\n",
964 "START");
926 GNUNET_assert (size >= sizeof (struct StartMessage)); 965 GNUNET_assert (size >= sizeof (struct StartMessage));
927 s.header.size = htons (sizeof (struct StartMessage)); 966 s.header.size = htons (sizeof (struct StartMessage));
928 s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START); 967 s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START);
@@ -947,22 +986,24 @@ send_start (void *cls, size_t size, void *buf)
947 * @param tc scheduler context 986 * @param tc scheduler context
948 */ 987 */
949static void 988static void
950reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 989reconnect (void *cls,
990 const struct GNUNET_SCHEDULER_TaskContext *tc)
951{ 991{
952 struct GNUNET_TRANSPORT_Handle *h = cls; 992 struct GNUNET_TRANSPORT_Handle *h = cls;
953 993
954 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 994 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
955 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 995 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
956 { 996 {
957 /* shutdown, just give up */ 997 /* shutdown, just give up */
958 return; 998 return;
959 } 999 }
960 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); 1000 LOG (GNUNET_ERROR_TYPE_DEBUG,
961 GNUNET_assert (h->client == NULL); 1001 "Connecting to transport service.\n");
962 GNUNET_assert (h->control_head == NULL); 1002 GNUNET_assert (NULL == h->client);
963 GNUNET_assert (h->control_tail == NULL); 1003 GNUNET_assert (NULL == h->control_head);
1004 GNUNET_assert (NULL == h->control_tail);
964 h->client = GNUNET_CLIENT_connect ("transport", h->cfg); 1005 h->client = GNUNET_CLIENT_connect ("transport", h->cfg);
965 GNUNET_assert (h->client != NULL); 1006 GNUNET_assert (NULL != h->client);
966 schedule_control_transmit (h, sizeof (struct StartMessage), &send_start, h); 1007 schedule_control_transmit (h, sizeof (struct StartMessage), &send_start, h);
967} 1008}
968 1009
@@ -1018,13 +1059,11 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
1018 * @param tth transmit handle to cancel 1059 * @param tth transmit handle to cancel
1019 */ 1060 */
1020static void 1061static void
1021cancel_control_transmit (struct GNUNET_TRANSPORT_Handle *th, struct GNUNET_TRANSPORT_TransmitHandle *tth) 1062cancel_control_transmit (struct GNUNET_TRANSPORT_Handle *th,
1063 struct GNUNET_TRANSPORT_TransmitHandle *tth)
1022{ 1064{
1023 GNUNET_assert (NULL != th); 1065 LOG (GNUNET_ERROR_TYPE_DEBUG,
1024 GNUNET_assert (NULL != tth); 1066 "Canceling transmit of contral transmission requested\n");
1025
1026 LOG (GNUNET_ERROR_TYPE_DEBUG, "Canceling transmit of contral transmission requested\n");
1027
1028 GNUNET_CONTAINER_DLL_remove (th->control_head, th->control_tail, tth); 1067 GNUNET_CONTAINER_DLL_remove (th->control_head, th->control_tail, tth);
1029 GNUNET_free (tth); 1068 GNUNET_free (tth);
1030} 1069}
@@ -1034,10 +1073,10 @@ cancel_control_transmit (struct GNUNET_TRANSPORT_Handle *th, struct GNUNET_TRANS
1034/** 1073/**
1035 * Send REQUEST_CONNECT message to the service. 1074 * Send REQUEST_CONNECT message to the service.
1036 * 1075 *
1037 * @param cls the 'struct GNUNET_PeerIdentity' 1076 * @param cls the `struct GNUNET_PeerIdentity`
1038 * @param size number of bytes available in buf 1077 * @param size number of bytes available in @a buf
1039 * @param buf where to copy the message 1078 * @param buf where to copy the message
1040 * @return number of bytes copied to buf 1079 * @return number of bytes copied to @a buf
1041 */ 1080 */
1042static size_t 1081static size_t
1043send_try_connect (void *cls, size_t size, void *buf) 1082send_try_connect (void *cls, size_t size, void *buf)
@@ -1051,13 +1090,15 @@ send_try_connect (void *cls, size_t size, void *buf)
1051 tch->cb (tch->cb_cls, GNUNET_SYSERR); 1090 tch->cb (tch->cb_cls, GNUNET_SYSERR);
1052 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch); 1091 GNUNET_CONTAINER_DLL_remove (tch->th->tc_head, tch->th->tc_tail, tch);
1053 LOG (GNUNET_ERROR_TYPE_DEBUG, 1092 LOG (GNUNET_ERROR_TYPE_DEBUG,
1054 "Discarding `%s' request to `%4s' due to error in transport service connection.\n", "REQUEST_CONNECT", 1093 "Discarding `%s' request to `%4s' due to error in transport service connection.\n",
1094 "REQUEST_CONNECT",
1055 GNUNET_i2s (&tch->pid)); 1095 GNUNET_i2s (&tch->pid));
1056 GNUNET_free (tch); 1096 GNUNET_free (tch);
1057 return 0; 1097 return 0;
1058 } 1098 }
1059 LOG (GNUNET_ERROR_TYPE_DEBUG, 1099 LOG (GNUNET_ERROR_TYPE_DEBUG,
1060 "Transmitting `%s' request with respect to `%4s'.\n", "REQUEST_CONNECT", 1100 "Transmitting `%s' request with respect to `%4s'.\n",
1101 "REQUEST_CONNECT",
1061 GNUNET_i2s (&tch->pid)); 1102 GNUNET_i2s (&tch->pid));
1062 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); 1103 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1063 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); 1104 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
@@ -1081,7 +1122,7 @@ send_try_connect (void *cls, size_t size, void *buf)
1081 * @param cb callback to be called when request was transmitted to transport 1122 * @param cb callback to be called when request was transmitted to transport
1082 * service 1123 * service
1083 * @param cb_cls closure for the callback 1124 * @param cb_cls closure for the callback
1084 * @return a GNUNET_TRANSPORT_TryConnectHandle handle or 1125 * @return a `struct GNUNET_TRANSPORT_TryConnectHandle` handle or
1085 * NULL on failure (cb will not be called) 1126 * NULL on failure (cb will not be called)
1086 */ 1127 */
1087struct GNUNET_TRANSPORT_TryConnectHandle * 1128struct GNUNET_TRANSPORT_TryConnectHandle *
@@ -1094,15 +1135,14 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1094 1135
1095 if (NULL == handle->client) 1136 if (NULL == handle->client)
1096 return NULL; 1137 return NULL;
1097 1138 tch = GNUNET_new (struct GNUNET_TRANSPORT_TryConnectHandle);
1098 tch = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TryConnectHandle));
1099 tch->th = handle; 1139 tch->th = handle;
1100 tch->pid = *(target); 1140 tch->pid = *(target);
1101 tch->cb = cb; 1141 tch->cb = cb;
1102 tch->cb_cls = cb_cls; 1142 tch->cb_cls = cb_cls;
1103 tch->tth = schedule_control_transmit (handle, 1143 tch->tth = schedule_control_transmit (handle,
1104 sizeof (struct TransportRequestConnectMessage), 1144 sizeof (struct TransportRequestConnectMessage),
1105 &send_try_connect, tch); 1145 &send_try_connect, tch);
1106 GNUNET_CONTAINER_DLL_insert(handle->tc_head, handle->tc_tail, tch); 1146 GNUNET_CONTAINER_DLL_insert(handle->tc_head, handle->tc_tail, tch);
1107 return tch; 1147 return tch;
1108} 1148}
@@ -1112,13 +1152,12 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1112 * Cancel the request to transport to try a connect 1152 * Cancel the request to transport to try a connect
1113 * Callback will not be called 1153 * Callback will not be called
1114 * 1154 *
1115 * @param tch GNUNET_TRANSPORT_TryConnectHandle handle to cancel 1155 * @param tch the handle to cancel
1116 */ 1156 */
1117void 1157void
1118GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch) 1158GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *tch)
1119{ 1159{
1120 struct GNUNET_TRANSPORT_Handle *th; 1160 struct GNUNET_TRANSPORT_Handle *th;
1121 GNUNET_assert (NULL != tch);
1122 1161
1123 th = tch->th; 1162 th = tch->th;
1124 cancel_control_transmit (th, tch->tth); 1163 cancel_control_transmit (th, tch->tth);
@@ -1130,9 +1169,9 @@ GNUNET_TRANSPORT_try_connect_cancel (struct GNUNET_TRANSPORT_TryConnectHandle *t
1130 * Send HELLO message to the service. 1169 * Send HELLO message to the service.
1131 * 1170 *
1132 * @param cls the HELLO message to send 1171 * @param cls the HELLO message to send
1133 * @param size number of bytes available in buf 1172 * @param size number of bytes available in @a buf
1134 * @param buf where to copy the message 1173 * @param buf where to copy the message
1135 * @return number of bytes copied to buf 1174 * @return number of bytes copied to @a buf
1136 */ 1175 */
1137static size_t 1176static size_t
1138send_hello (void *cls, size_t size, void *buf) 1177send_hello (void *cls, size_t size, void *buf)
@@ -1141,14 +1180,15 @@ send_hello (void *cls, size_t size, void *buf)
1141 struct GNUNET_MessageHeader *msg = ohh->msg; 1180 struct GNUNET_MessageHeader *msg = ohh->msg;
1142 uint16_t ssize; 1181 uint16_t ssize;
1143 struct GNUNET_SCHEDULER_TaskContext tc; 1182 struct GNUNET_SCHEDULER_TaskContext tc;
1183
1144 tc.read_ready = NULL; 1184 tc.read_ready = NULL;
1145 tc.write_ready = NULL; 1185 tc.write_ready = NULL;
1146 tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT; 1186 tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
1147 1187 if (NULL == buf)
1148 if (buf == NULL)
1149 { 1188 {
1150 LOG (GNUNET_ERROR_TYPE_DEBUG, 1189 LOG (GNUNET_ERROR_TYPE_DEBUG,
1151 "Timeout while trying to transmit `%s' request.\n", "HELLO"); 1190 "Timeout while trying to transmit `%s' request.\n",
1191 "HELLO");
1152 if (NULL != ohh->cont) 1192 if (NULL != ohh->cont)
1153 ohh->cont (ohh->cls, &tc); 1193 ohh->cont (ohh->cls, &tc);
1154 GNUNET_free (msg); 1194 GNUNET_free (msg);
@@ -1156,7 +1196,9 @@ send_hello (void *cls, size_t size, void *buf)
1156 GNUNET_free (ohh); 1196 GNUNET_free (ohh);
1157 return 0; 1197 return 0;
1158 } 1198 }
1159 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "HELLO"); 1199 LOG (GNUNET_ERROR_TYPE_DEBUG,
1200 "Transmitting `%s' request.\n",
1201 "HELLO");
1160 ssize = ntohs (msg->size); 1202 ssize = ntohs (msg->size);
1161 GNUNET_assert (size >= ssize); 1203 GNUNET_assert (size >= ssize);
1162 memcpy (buf, msg, ssize); 1204 memcpy (buf, msg, ssize);
@@ -1174,23 +1216,27 @@ send_hello (void *cls, size_t size, void *buf)
1174 * Send traffic metric message to the service. 1216 * Send traffic metric message to the service.
1175 * 1217 *
1176 * @param cls the message to send 1218 * @param cls the message to send
1177 * @param size number of bytes available in buf 1219 * @param size number of bytes available in @a buf
1178 * @param buf where to copy the message 1220 * @param buf where to copy the message
1179 * @return number of bytes copied to buf 1221 * @return number of bytes copied to @a buf
1180 */ 1222 */
1181static size_t 1223static size_t
1182send_metric (void *cls, size_t size, void *buf) 1224send_metric (void *cls, size_t size, void *buf)
1183{ 1225{
1184 struct TrafficMetricMessage *msg = cls; 1226 struct TrafficMetricMessage *msg = cls;
1185 uint16_t ssize; 1227 uint16_t ssize;
1186 if (buf == NULL) 1228
1229 if (NULL == buf)
1187 { 1230 {
1188 LOG (GNUNET_ERROR_TYPE_DEBUG, 1231 LOG (GNUNET_ERROR_TYPE_DEBUG,
1189 "Timeout while trying to transmit `%s' request.\n", "TRAFFIC_METRIC"); 1232 "Timeout while trying to transmit `%s' request.\n",
1233 "TRAFFIC_METRIC");
1190 GNUNET_free (msg); 1234 GNUNET_free (msg);
1191 return 0; 1235 return 0;
1192 } 1236 }
1193 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "TRAFFIC_METRIC"); 1237 LOG (GNUNET_ERROR_TYPE_DEBUG,
1238 "Transmitting `%s' request.\n",
1239 "TRAFFIC_METRIC");
1194 ssize = ntohs (msg->header.size); 1240 ssize = ntohs (msg->header.size);
1195 GNUNET_assert (size >= ssize); 1241 GNUNET_assert (size >= ssize);
1196 memcpy (buf, msg, ssize); 1242 memcpy (buf, msg, ssize);
@@ -1204,49 +1250,46 @@ send_metric (void *cls, size_t size, void *buf)
1204 * 1250 *
1205 * @param handle transport handle 1251 * @param handle transport handle
1206 * @param peer the peer to set the metric for 1252 * @param peer the peer to set the metric for
1207 * @param inbound set inbound direction (GNUNET_YES or GNUNET_NO) 1253 * @param inbound set inbound direction (#GNUNET_YES or #GNUNET_NO)
1208 * @param outbound set outbound direction (GNUNET_YES or GNUNET_NO) 1254 * @param outbound set outbound direction (#GNUNET_YES or #GNUNET_NO)
1209 * @param ats the metric as ATS information 1255 * @param ats the metric as ATS information
1210 * @param ats_count the number of metrics 1256 * @param ats_count the number of metrics
1211 * 1257 *
1212 * Supported ATS values: 1258 * Supported ATS values:
1213 * GNUNET_ATS_QUALITY_NET_DELAY (value in ms) 1259 * #GNUNET_ATS_QUALITY_NET_DELAY (value in ms)
1214 * GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops)) 1260 * #GNUNET_ATS_QUALITY_NET_DISTANCE (value in count(hops))
1215 * 1261 *
1216 * Example 1262 * Example:
1217 * To enforce a delay of 10 ms for peer p1 in sending direction use: 1263 * To enforce a delay of 10 ms for peer p1 in sending direction use:
1218 * 1264 * <code>
1219 * struct GNUNET_ATS_Information ats; 1265 * struct GNUNET_ATS_Information ats;
1220 * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY); 1266 * ats.type = ntohl (GNUNET_ATS_QUALITY_NET_DELAY);
1221 * ats.value = ntohl (10); 1267 * ats.value = ntohl (10);
1222 * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1); 1268 * GNUNET_TRANSPORT_set_traffic_metric (th, p1, TM_SEND, &ats, 1);
1223 * 1269 * </code>
1224 * Note: 1270 * Note:
1225 * Delay restrictions in receiving direction will be enforced with 1271 * Delay restrictions in receiving direction will be enforced with
1226 * 1 message delay. 1272 * 1 message delay.
1227 */ 1273 */
1228void 1274void
1229GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, 1275GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
1230 const struct GNUNET_PeerIdentity *peer, 1276 const struct GNUNET_PeerIdentity *peer,
1231 int inbound, 1277 int inbound,
1232 int outbound, 1278 int outbound,
1233 const struct GNUNET_ATS_Information *ats, 1279 const struct GNUNET_ATS_Information *ats,
1234 size_t ats_count) 1280 size_t ats_count)
1235{ 1281{
1236 struct TrafficMetricMessage *msg; 1282 struct TrafficMetricMessage *msg;
1237 1283
1238 GNUNET_assert (NULL != handle);
1239 GNUNET_assert (NULL != peer);
1240 GNUNET_assert ((outbound == GNUNET_YES) || (outbound == GNUNET_NO)); 1284 GNUNET_assert ((outbound == GNUNET_YES) || (outbound == GNUNET_NO));
1241 GNUNET_assert ((inbound == GNUNET_YES) || (inbound == GNUNET_NO)); 1285 GNUNET_assert ((inbound == GNUNET_YES) || (inbound == GNUNET_NO));
1242
1243 if ((GNUNET_NO == inbound) && (GNUNET_NO == outbound)) 1286 if ((GNUNET_NO == inbound) && (GNUNET_NO == outbound))
1244 return; 1287 return;
1245 if (0 == ats_count) 1288 if (0 == ats_count)
1246 return; 1289 return;
1247 1290
1248 size_t len = sizeof (struct TrafficMetricMessage) + 1291 size_t len = sizeof (struct TrafficMetricMessage) +
1249 ats_count * sizeof (struct GNUNET_ATS_Information); 1292 ats_count * sizeof (struct GNUNET_ATS_Information);
1250 1293
1251 msg = GNUNET_malloc (len); 1294 msg = GNUNET_malloc (len);
1252 msg->header.size = htons (len); 1295 msg->header.size = htons (len);
@@ -1268,10 +1311,10 @@ GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
1268 * @param handle connection to transport service 1311 * @param handle connection to transport service
1269 * @param hello the hello message 1312 * @param hello the hello message
1270 * @param cont continuation to call when HELLO has been sent, 1313 * @param cont continuation to call when HELLO has been sent,
1271 * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail 1314 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
1272 * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success 1315 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
1273 * @param cls closure for continuation 1316 * @param cls closure for continuation
1274 * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure, 1317 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on failure,
1275 * in case of failure cont will not be called 1318 * in case of failure cont will not be called
1276 * 1319 *
1277 */ 1320 */
@@ -1285,12 +1328,8 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1285 struct GNUNET_PeerIdentity peer; 1328 struct GNUNET_PeerIdentity peer;
1286 uint16_t size; 1329 uint16_t size;
1287 1330
1288 GNUNET_assert (NULL != handle);
1289 GNUNET_assert (NULL != hello);
1290
1291 if (NULL == handle->client) 1331 if (NULL == handle->client)
1292 return NULL; 1332 return NULL;
1293
1294 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); 1333 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
1295 size = ntohs (hello->size); 1334 size = ntohs (hello->size);
1296 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader)); 1335 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
@@ -1307,7 +1346,7 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1307 "Offering `%s' message of `%4s' to transport for validation.\n", "HELLO", 1346 "Offering `%s' message of `%4s' to transport for validation.\n", "HELLO",
1308 GNUNET_i2s (&peer)); 1347 GNUNET_i2s (&peer));
1309 1348
1310 ohh = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_OfferHelloHandle)); 1349 ohh = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle);
1311 ohh->th = handle; 1350 ohh->th = handle;
1312 ohh->cont = cont; 1351 ohh->cont = cont;
1313 ohh->cls = cls; 1352 ohh->cls = cls;
@@ -1327,7 +1366,6 @@ void
1327GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh) 1366GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
1328{ 1367{
1329 struct GNUNET_TRANSPORT_Handle *th = ohh->th; 1368 struct GNUNET_TRANSPORT_Handle *th = ohh->th;
1330 GNUNET_assert (NULL != ohh);
1331 1369
1332 cancel_control_transmit (ohh->th, ohh->tth); 1370 cancel_control_transmit (ohh->th, ohh->tth);
1333 GNUNET_CONTAINER_DLL_remove (th->oh_head, th->oh_tail, ohh); 1371 GNUNET_CONTAINER_DLL_remove (th->oh_head, th->oh_tail, ohh);
@@ -1335,17 +1373,16 @@ GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *o
1335 GNUNET_free (ohh); 1373 GNUNET_free (ohh);
1336} 1374}
1337 1375
1376
1338int 1377int
1339GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *handle, 1378GNUNET_TRANSPORT_check_neighbour_connected (struct GNUNET_TRANSPORT_Handle *handle,
1340 const struct GNUNET_PeerIdentity *peer) 1379 const struct GNUNET_PeerIdentity *peer)
1341{ 1380{
1342 GNUNET_assert (NULL != handle); 1381 if (GNUNET_YES ==
1343 GNUNET_assert (NULL != peer); 1382 GNUNET_CONTAINER_multipeermap_contains (handle->neighbours,
1344 1383 peer))
1345 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (handle->neighbours, peer))
1346 return GNUNET_YES; 1384 return GNUNET_YES;
1347 else 1385 return GNUNET_NO;
1348 return GNUNET_NO;
1349} 1386}
1350 1387
1351 1388
@@ -1378,7 +1415,7 @@ call_hello_update_cb_async (void *cls,
1378 * identity; message and sender will be NULL on timeout 1415 * identity; message and sender will be NULL on timeout
1379 * (handshake with transport service pending/failed). 1416 * (handshake with transport service pending/failed).
1380 * cost estimate will be 0. 1417 * cost estimate will be 0.
1381 * @param rec_cls closure for rec 1418 * @param rec_cls closure for @a rec
1382 * @return handle to cancel the operation 1419 * @return handle to cancel the operation
1383 */ 1420 */
1384struct GNUNET_TRANSPORT_GetHelloHandle * 1421struct GNUNET_TRANSPORT_GetHelloHandle *
@@ -1388,7 +1425,7 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
1388{ 1425{
1389 struct GNUNET_TRANSPORT_GetHelloHandle *hwl; 1426 struct GNUNET_TRANSPORT_GetHelloHandle *hwl;
1390 1427
1391 hwl = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_GetHelloHandle)); 1428 hwl = GNUNET_new (struct GNUNET_TRANSPORT_GetHelloHandle);
1392 hwl->rec = rec; 1429 hwl->rec = rec;
1393 hwl->rec_cls = rec_cls; 1430 hwl->rec_cls = rec_cls;
1394 hwl->handle = handle; 1431 hwl->handle = handle;
@@ -1438,8 +1475,8 @@ GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1438{ 1475{
1439 struct GNUNET_TRANSPORT_Handle *ret; 1476 struct GNUNET_TRANSPORT_Handle *ret;
1440 1477
1441 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle)); 1478 ret = GNUNET_new (struct GNUNET_TRANSPORT_Handle);
1442 if (self != NULL) 1479 if (NULL != self)
1443 { 1480 {
1444 ret->self = *self; 1481 ret->self = *self;
1445 ret->check_self = GNUNET_YES; 1482 ret->check_self = GNUNET_YES;
@@ -1450,18 +1487,21 @@ GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1450 ret->nc_cb = nc; 1487 ret->nc_cb = nc;
1451 ret->nd_cb = nd; 1488 ret->nd_cb = nd;
1452 ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO; 1489 ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
1453 ret->neighbours = 1490 LOG (GNUNET_ERROR_TYPE_DEBUG,
1454 GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); 1491 "Connecting to transport service.\n");
1455 ret->ready_heap =
1456 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1457 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
1458 ret->client = GNUNET_CLIENT_connect ("transport", cfg); 1492 ret->client = GNUNET_CLIENT_connect ("transport", cfg);
1459 if (ret->client == NULL) 1493 if (NULL == ret->client)
1460 { 1494 {
1461 GNUNET_free (ret); 1495 GNUNET_free (ret);
1462 return NULL; 1496 return NULL;
1463 } 1497 }
1464 schedule_control_transmit (ret, sizeof (struct StartMessage), &send_start, ret); 1498 ret->neighbours =
1499 GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE,
1500 GNUNET_YES);
1501 ret->ready_heap =
1502 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1503 schedule_control_transmit (ret, sizeof (struct StartMessage),
1504 &send_start, ret);
1465 return ret; 1505 return ret;
1466} 1506}
1467 1507
@@ -1474,7 +1514,8 @@ GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1474void 1514void
1475GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) 1515GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1476{ 1516{
1477 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); 1517 LOG (GNUNET_ERROR_TYPE_DEBUG,
1518 "Transport disconnect called!\n");
1478 /* this disconnects all neighbours... */ 1519 /* this disconnects all neighbours... */
1479 if (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK) 1520 if (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
1480 disconnect_and_schedule_reconnect (handle); 1521 disconnect_and_schedule_reconnect (handle);
@@ -1517,18 +1558,18 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1517 * notify with buf NULL and size 0)? 1558 * notify with buf NULL and size 0)?
1518 * @param notify function to call when we are ready to 1559 * @param notify function to call when we are ready to
1519 * send such a message 1560 * send such a message
1520 * @param notify_cls closure for notify 1561 * @param notify_cls closure for @a notify
1521 * @return NULL if someone else is already waiting to be notified 1562 * @return NULL if someone else is already waiting to be notified
1522 * non-NULL if the notify callback was queued (can be used to cancel 1563 * non-NULL if the notify callback was queued (can be used to cancel
1523 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel) 1564 * using #GNUNET_TRANSPORT_notify_transmit_ready_cancel)
1524 */ 1565 */
1525struct GNUNET_TRANSPORT_TransmitHandle * 1566struct GNUNET_TRANSPORT_TransmitHandle *
1526GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle, 1567GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1527 const struct GNUNET_PeerIdentity 1568 const struct GNUNET_PeerIdentity *target,
1528 *target, size_t size, uint32_t priority, 1569 size_t size, uint32_t priority,
1529 struct GNUNET_TIME_Relative timeout, 1570 struct GNUNET_TIME_Relative timeout,
1530 GNUNET_CONNECTION_TransmitReadyNotify 1571 GNUNET_CONNECTION_TransmitReadyNotify notify,
1531 notify, void *notify_cls) 1572 void *notify_cls)
1532{ 1573{
1533 struct Neighbour *n; 1574 struct Neighbour *n;
1534 struct GNUNET_TRANSPORT_TransmitHandle *th; 1575 struct GNUNET_TRANSPORT_TransmitHandle *th;
@@ -1549,7 +1590,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1549 return NULL; 1590 return NULL;
1550 } 1591 }
1551 GNUNET_assert (NULL == n->hn); 1592 GNUNET_assert (NULL == n->hn);
1552 th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); 1593 th = GNUNET_new (struct GNUNET_TRANSPORT_TransmitHandle);
1553 th->neighbour = n; 1594 th->neighbour = n;
1554 th->notify = notify; 1595 th->notify = notify;
1555 th->notify_cls = notify_cls; 1596 th->notify_cls = notify_cls;
@@ -1575,12 +1616,10 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1575/** 1616/**
1576 * Cancel the specified transmission-ready notification. 1617 * Cancel the specified transmission-ready notification.
1577 * 1618 *
1578 * @param th handle returned from GNUNET_TRANSPORT_notify_transmit_ready 1619 * @param th handle returned from #GNUNET_TRANSPORT_notify_transmit_ready()
1579 */ 1620 */
1580void 1621void
1581GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct 1622GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th)
1582 GNUNET_TRANSPORT_TransmitHandle
1583 *th)
1584{ 1623{
1585 struct Neighbour *n; 1624 struct Neighbour *n;
1586 1625
@@ -1589,7 +1628,7 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
1589 n = th->neighbour; 1628 n = th->neighbour;
1590 GNUNET_assert (th == n->th); 1629 GNUNET_assert (th == n->th);
1591 n->th = NULL; 1630 n->th = NULL;
1592 if (n->hn != NULL) 1631 if (NULL != n->hn)
1593 { 1632 {
1594 GNUNET_CONTAINER_heap_remove_node (n->hn); 1633 GNUNET_CONTAINER_heap_remove_node (n->hn);
1595 n->hn = NULL; 1634 n->hn = NULL;