aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_neighbours.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-24 01:10:47 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-24 01:10:47 +0000
commitf1f603c7d0b3f03dca46a4f313472288eb080eb1 (patch)
tree3a29966b02dfb83e0a8a8d5c42b3116380209fb0 /src/transport/gnunet-service-transport_neighbours.c
parent53cd5b8eda2fa8db86b0907a62a39598981d008a (diff)
downloadgnunet-f1f603c7d0b3f03dca46a4f313472288eb080eb1.tar.gz
gnunet-f1f603c7d0b3f03dca46a4f313472288eb080eb1.zip
making GNUNET_SCHEDULER_cancel() perform in O(1) instead of O(n) to help or even fully address #3247
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 695adedc9..b4db4c2cb 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -344,12 +344,12 @@ struct NeighbourMapEntry
344 * Main task that drives this peer (timeouts, keepalives, etc.). 344 * Main task that drives this peer (timeouts, keepalives, etc.).
345 * Always runs the 'master_task'. 345 * Always runs the 'master_task'.
346 */ 346 */
347 GNUNET_SCHEDULER_TaskIdentifier task; 347 struct GNUNET_SCHEDULER_Task * task;
348 348
349 /** 349 /**
350 * Task to disconnect neighbour after we received a DISCONNECT message 350 * Task to disconnect neighbour after we received a DISCONNECT message
351 */ 351 */
352 GNUNET_SCHEDULER_TaskIdentifier delayed_disconnect_task; 352 struct GNUNET_SCHEDULER_Task * delayed_disconnect_task;
353 353
354 /** 354 /**
355 * At what time should we sent the next keep-alive message? 355 * At what time should we sent the next keep-alive message?
@@ -539,7 +539,7 @@ static unsigned long long bytes_in_send_queue;
539/** 539/**
540 * Task transmitting utilization data 540 * Task transmitting utilization data
541 */ 541 */
542static GNUNET_SCHEDULER_TaskIdentifier util_transmission_tk; 542static struct GNUNET_SCHEDULER_Task * util_transmission_tk;
543 543
544 544
545static struct GNUNET_CONTAINER_MultiPeerMap *registered_quota_notifications; 545static struct GNUNET_CONTAINER_MultiPeerMap *registered_quota_notifications;
@@ -956,17 +956,17 @@ free_neighbour (struct NeighbourMapEntry *n,
956 } 956 }
957 957
958 /* Cancel the disconnect task */ 958 /* Cancel the disconnect task */
959 if (GNUNET_SCHEDULER_NO_TASK != n->delayed_disconnect_task) 959 if (NULL != n->delayed_disconnect_task)
960 { 960 {
961 GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task); 961 GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task);
962 n->delayed_disconnect_task = GNUNET_SCHEDULER_NO_TASK; 962 n->delayed_disconnect_task = NULL;
963 } 963 }
964 964
965 /* Cancel the master task */ 965 /* Cancel the master task */
966 if (GNUNET_SCHEDULER_NO_TASK != n->task) 966 if (NULL != n->task)
967 { 967 {
968 GNUNET_SCHEDULER_cancel (n->task); 968 GNUNET_SCHEDULER_cancel (n->task);
969 n->task = GNUNET_SCHEDULER_NO_TASK; 969 n->task = NULL;
970 } 970 }
971 /* free rest of memory */ 971 /* free rest of memory */
972 GNUNET_free (n); 972 GNUNET_free (n);
@@ -1054,7 +1054,7 @@ send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target,
1054 return; /* already gone */ 1054 return; /* already gone */
1055 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state) 1055 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state)
1056 return; /* have created a fresh entry since */ 1056 return; /* have created a fresh entry since */
1057 if (GNUNET_SCHEDULER_NO_TASK != n->task) 1057 if (NULL != n->task)
1058 GNUNET_SCHEDULER_cancel (n->task); 1058 GNUNET_SCHEDULER_cancel (n->task);
1059 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 1059 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1060} 1060}
@@ -1168,7 +1168,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1168 break; 1168 break;
1169 } 1169 }
1170 /* schedule timeout to clean up */ 1170 /* schedule timeout to clean up */
1171 if (GNUNET_SCHEDULER_NO_TASK != n->task) 1171 if (NULL != n->task)
1172 GNUNET_SCHEDULER_cancel (n->task); 1172 GNUNET_SCHEDULER_cancel (n->task);
1173 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT, 1173 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT,
1174 &master_task, n); 1174 &master_task, n);
@@ -1202,7 +1202,7 @@ transmit_send_continuation (void *cls,
1202 /* this is still "our" neighbour, remove us from its queue 1202 /* this is still "our" neighbour, remove us from its queue
1203 and allow it to send the next message now */ 1203 and allow it to send the next message now */
1204 n->is_active = NULL; 1204 n->is_active = NULL;
1205 if (GNUNET_SCHEDULER_NO_TASK != n->task) 1205 if (NULL != n->task)
1206 GNUNET_SCHEDULER_cancel (n->task); 1206 GNUNET_SCHEDULER_cancel (n->task);
1207 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 1207 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1208 } 1208 }
@@ -1650,7 +1650,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
1650 msg_size, GNUNET_i2s (target)); 1650 msg_size, GNUNET_i2s (target));
1651 1651
1652 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq); 1652 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
1653 if (GNUNET_SCHEDULER_NO_TASK != n->task) 1653 if (NULL != n->task)
1654 GNUNET_SCHEDULER_cancel (n->task); 1654 GNUNET_SCHEDULER_cancel (n->task);
1655 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 1655 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
1656} 1656}
@@ -2862,7 +2862,7 @@ static void
2862utilization_transmission (void *cls, 2862utilization_transmission (void *cls,
2863 const struct GNUNET_SCHEDULER_TaskContext *tc) 2863 const struct GNUNET_SCHEDULER_TaskContext *tc)
2864{ 2864{
2865 util_transmission_tk = GNUNET_SCHEDULER_NO_TASK; 2865 util_transmission_tk = NULL;
2866 2866
2867 if (0 < GNUNET_CONTAINER_multipeermap_size (neighbours)) 2867 if (0 < GNUNET_CONTAINER_multipeermap_size (neighbours))
2868 GNUNET_CONTAINER_multipeermap_iterate (neighbours, send_utilization_data, NULL); 2868 GNUNET_CONTAINER_multipeermap_iterate (neighbours, send_utilization_data, NULL);
@@ -2945,7 +2945,7 @@ master_task (void *cls,
2945 struct NeighbourMapEntry *n = cls; 2945 struct NeighbourMapEntry *n = cls;
2946 struct GNUNET_TIME_Relative delay; 2946 struct GNUNET_TIME_Relative delay;
2947 2947
2948 n->task = GNUNET_SCHEDULER_NO_TASK; 2948 n->task = NULL;
2949 delay = GNUNET_TIME_absolute_get_remaining (n->timeout); 2949 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
2950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2951 "Master task runs for neighbour `%s' in state %s with timeout in %s\n", 2951 "Master task runs for neighbour `%s' in state %s with timeout in %s\n",
@@ -3081,7 +3081,7 @@ master_task (void *cls,
3081 delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time), 3081 delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time),
3082 delay); 3082 delay);
3083 } 3083 }
3084 if (GNUNET_SCHEDULER_NO_TASK == n->task) 3084 if (NULL == n->task)
3085 n->task = GNUNET_SCHEDULER_add_delayed (delay, 3085 n->task = GNUNET_SCHEDULER_add_delayed (delay,
3086 &master_task, 3086 &master_task,
3087 n); 3087 n);
@@ -3405,7 +3405,7 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3405 GNUNET_break (0); 3405 GNUNET_break (0);
3406 break; 3406 break;
3407 } 3407 }
3408 if (GNUNET_SCHEDULER_NO_TASK != n->task) 3408 if (NULL != n->task)
3409 GNUNET_SCHEDULER_cancel (n->task); 3409 GNUNET_SCHEDULER_cancel (n->task);
3410 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 3410 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
3411 return GNUNET_YES; 3411 return GNUNET_YES;
@@ -3577,7 +3577,7 @@ void delayed_disconnect (void *cls,
3577{ 3577{
3578 struct NeighbourMapEntry *n = cls; 3578 struct NeighbourMapEntry *n = cls;
3579 3579
3580 n->delayed_disconnect_task = GNUNET_SCHEDULER_NO_TASK; 3580 n->delayed_disconnect_task = NULL;
3581 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3581 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3582 "Disconnecting by request from peer %s\n", 3582 "Disconnecting by request from peer %s\n",
3583 GNUNET_i2s (&n->id)); 3583 GNUNET_i2s (&n->id));
@@ -3884,10 +3884,10 @@ GST_neighbours_stop ()
3884 3884
3885 if (NULL == neighbours) 3885 if (NULL == neighbours)
3886 return; 3886 return;
3887 if (GNUNET_SCHEDULER_NO_TASK != util_transmission_tk) 3887 if (NULL != util_transmission_tk)
3888 { 3888 {
3889 GNUNET_SCHEDULER_cancel (util_transmission_tk); 3889 GNUNET_SCHEDULER_cancel (util_transmission_tk);
3890 util_transmission_tk = GNUNET_SCHEDULER_NO_TASK; 3890 util_transmission_tk = NULL;
3891 } 3891 }
3892 3892
3893 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &disconnect_all_neighbours, 3893 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &disconnect_all_neighbours,