aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api_new.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-04 22:29:07 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-04 22:29:07 +0000
commitb22e23b08ffd14a0396cfe17c4f5a0571b7fc258 (patch)
treeb0de439c63c59ec878d4513006277fa6875c8386 /src/transport/transport_api_new.c
parentde4de0f76f88209a6cd2d78f512c793e099552f5 (diff)
downloadgnunet-b22e23b08ffd14a0396cfe17c4f5a0571b7fc258.tar.gz
gnunet-b22e23b08ffd14a0396cfe17c4f5a0571b7fc258.zip
fixes
Diffstat (limited to 'src/transport/transport_api_new.c')
-rw-r--r--src/transport/transport_api_new.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/transport/transport_api_new.c b/src/transport/transport_api_new.c
index 0080937ca..5ec5cb6d1 100644
--- a/src/transport/transport_api_new.c
+++ b/src/transport/transport_api_new.c
@@ -662,13 +662,12 @@ transport_notify_ready (void *cls, size_t size, void *buf)
662 662
663 /* then, if possible and no control messages pending, send data messages */ 663 /* then, if possible and no control messages pending, send data messages */
664 while ( (NULL == h->control_head) && 664 while ( (NULL == h->control_head) &&
665 (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) ) 665 (NULL != (n = GNUNET_CONTAINER_heap_remove_root (h->ready_heap))) )
666 { 666 {
667 n->hn = NULL;
667 if (GNUNET_YES != n->is_ready) 668 if (GNUNET_YES != n->is_ready)
668 { 669 {
669 /* peer not ready, wait for notification! */ 670 /* peer not ready, wait for notification! */
670 GNUNET_CONTAINER_heap_remove_node (n->hn);
671 n->hn = NULL;
672 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task); 671 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task);
673 n->th->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (n->th->timeout), 672 n->th->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (n->th->timeout),
674 &timeout_request_due_to_congestion, 673 &timeout_request_due_to_congestion,
@@ -738,6 +737,11 @@ schedule_transmission_task (void *cls,
738 n->th = NULL; 737 n->th = NULL;
739 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap)); 738 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
740 n->hn = NULL; 739 n->hn = NULL;
740#if DEBUG_TRANSPORT
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Signalling timeout for transmission to peer %s due to congestion\n",
743 GNUNET_i2s (&n->id));
744#endif
741 GNUNET_assert (0 == 745 GNUNET_assert (0 ==
742 th->notify (th->notify_cls, 0, NULL)); 746 th->notify (th->notify_cls, 0, NULL));
743 GNUNET_free (th); 747 GNUNET_free (th);
@@ -790,10 +794,13 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
790 } 794 }
791 if (NULL != h->control_head) 795 if (NULL != h->control_head)
792 delay = GNUNET_TIME_UNIT_ZERO; 796 delay = GNUNET_TIME_UNIT_ZERO;
793 else if (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) 797 else if (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap)))
794 delay = GNUNET_TIME_absolute_get_remaining (n->th->timeout); 798 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, n->th->notify_size);
795 else 799 else
796 return; /* no work to be done */ 800 return; /* no work to be done */
801 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
802 "Scheduling next transmission to service in %llu ms\n",
803 (unsigned long long) delay.rel_value);
797 h->quota_task = GNUNET_SCHEDULER_add_delayed (delay, 804 h->quota_task = GNUNET_SCHEDULER_add_delayed (delay,
798 &schedule_transmission_task, 805 &schedule_transmission_task,
799 h); 806 h);
@@ -826,9 +833,9 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h,
826 th->notify = notify; 833 th->notify = notify;
827 th->notify_cls = notify_cls; 834 th->notify_cls = notify_cls;
828 th->notify_size = size; 835 th->notify_size = size;
829 GNUNET_CONTAINER_DLL_insert (h->control_head, 836 GNUNET_CONTAINER_DLL_insert_tail (h->control_head,
830 h->control_tail, 837 h->control_tail,
831 th); 838 th);
832 schedule_transmission (h); 839 schedule_transmission (h);
833} 840}
834 841
@@ -867,6 +874,8 @@ send_start (void *cls, size_t size, void *buf)
867 s.do_check = htonl (h->check_self); 874 s.do_check = htonl (h->check_self);
868 s.self = h->self; 875 s.self = h->self;
869 memcpy (buf, &s, sizeof (struct StartMessage)); 876 memcpy (buf, &s, sizeof (struct StartMessage));
877 GNUNET_CLIENT_receive (h->client,
878 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
870 return sizeof (struct StartMessage); 879 return sizeof (struct StartMessage);
871} 880}
872 881
@@ -901,8 +910,6 @@ reconnect (void *cls,
901 schedule_control_transmit (h, 910 schedule_control_transmit (h,
902 sizeof (struct StartMessage), 911 sizeof (struct StartMessage),
903 &send_start, h); 912 &send_start, h);
904 GNUNET_CLIENT_receive (h->client,
905 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
906} 913}
907 914
908 915
@@ -921,7 +928,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
921 /* Forget about all neighbours that we used to be connected to */ 928 /* Forget about all neighbours that we used to be connected to */
922 GNUNET_CONTAINER_multihashmap_iterate(h->neighbours, 929 GNUNET_CONTAINER_multihashmap_iterate(h->neighbours,
923 &neighbour_delete, 930 &neighbour_delete,
924 NULL); 931 h);
925 if (NULL != h->cth) 932 if (NULL != h->cth)
926 { 933 {
927 GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth); 934 GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
@@ -1037,7 +1044,7 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
1037{ 1044{
1038 struct Neighbour *n; 1045 struct Neighbour *n;
1039 struct SetQuotaContext *sqc; 1046 struct SetQuotaContext *sqc;
1040 1047
1041 n = neighbour_find (handle, target); 1048 n = neighbour_find (handle, target);
1042 if (NULL == n) 1049 if (NULL == n)
1043 { 1050 {
@@ -1047,6 +1054,7 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
1047 GNUNET_i2s (target)); 1054 GNUNET_i2s (target));
1048 return; 1055 return;
1049 } 1056 }
1057 GNUNET_assert (NULL != handle->client);
1050#if DEBUG_TRANSPORT 1058#if DEBUG_TRANSPORT
1051 if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__) 1059 if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__)
1052 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1094,7 +1102,7 @@ send_try_connect (void *cls, size_t size, void *buf)
1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1095 "Transmitting `%s' request with respect to `%4s'.\n", 1103 "Transmitting `%s' request with respect to `%4s'.\n",
1096 "REQUEST_CONNECT", 1104 "REQUEST_CONNECT",
1097 GNUNET_i2s (&sqc->target)); 1105 GNUNET_i2s (pid));
1098#endif 1106#endif
1099 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); 1107 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1100 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); 1108 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
@@ -1120,6 +1128,8 @@ GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1120{ 1128{
1121 struct GNUNET_PeerIdentity *pid; 1129 struct GNUNET_PeerIdentity *pid;
1122 1130
1131 if (NULL == handle->client)
1132 return;
1123 pid = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); 1133 pid = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1124 *pid = *target; 1134 *pid = *target;
1125 schedule_control_transmit (handle, 1135 schedule_control_transmit (handle,
@@ -1406,6 +1416,12 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1406 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, size); 1416 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, size);
1407 if (delay.rel_value > timeout.rel_value) 1417 if (delay.rel_value > timeout.rel_value)
1408 delay.rel_value = 0; /* notify immediately (with failure) */ 1418 delay.rel_value = 0; /* notify immediately (with failure) */
1419#if DEBUG_TRANSPORT
1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1421 "Bandwidth tracker allows next transmission to peer %s in %llu ms\n",
1422 GNUNET_i2s (target),
1423 (unsigned long long) delay.rel_value);
1424#endif
1409 n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap, 1425 n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap,
1410 n, 1426 n,
1411 delay.rel_value); 1427 delay.rel_value);