aboutsummaryrefslogtreecommitdiff
path: root/src/nat
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/nat
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/nat')
-rw-r--r--src/nat/nat.c44
-rw-r--r--src/nat/nat_auto.c8
-rw-r--r--src/nat/nat_mini.c16
-rw-r--r--src/nat/nat_test.c20
-rw-r--r--src/nat/test_nat_test.c6
5 files changed, 47 insertions, 47 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c
index 85d069e07..0225508a6 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -230,27 +230,27 @@ struct GNUNET_NAT_Handle
230 /** 230 /**
231 * ID of select gnunet-helper-nat-server stdout read task 231 * ID of select gnunet-helper-nat-server stdout read task
232 */ 232 */
233 GNUNET_SCHEDULER_TaskIdentifier server_read_task; 233 struct GNUNET_SCHEDULER_Task * server_read_task;
234 234
235 /** 235 /**
236 * ID of interface IP-scan task 236 * ID of interface IP-scan task
237 */ 237 */
238 GNUNET_SCHEDULER_TaskIdentifier ifc_task; 238 struct GNUNET_SCHEDULER_Task * ifc_task;
239 239
240 /** 240 /**
241 * ID of hostname DNS lookup task 241 * ID of hostname DNS lookup task
242 */ 242 */
243 GNUNET_SCHEDULER_TaskIdentifier hostname_task; 243 struct GNUNET_SCHEDULER_Task * hostname_task;
244 244
245 /** 245 /**
246 * ID of DynDNS lookup task 246 * ID of DynDNS lookup task
247 */ 247 */
248 GNUNET_SCHEDULER_TaskIdentifier dns_task; 248 struct GNUNET_SCHEDULER_Task * dns_task;
249 249
250 /** 250 /**
251 * ID of task to add addresses from bind. 251 * ID of task to add addresses from bind.
252 */ 252 */
253 GNUNET_SCHEDULER_TaskIdentifier bind_task; 253 struct GNUNET_SCHEDULER_Task * bind_task;
254 254
255 /** 255 /**
256 * How often do we scan for changes in our IP address from our local 256 * How often do we scan for changes in our IP address from our local
@@ -758,7 +758,7 @@ process_interfaces (void *cls, const char *name, int isDefault,
758 return GNUNET_OK; 758 return GNUNET_OK;
759 } 759 }
760 if ((h->internal_address == NULL) && (h->server_proc == NULL) && 760 if ((h->internal_address == NULL) && (h->server_proc == NULL) &&
761 (h->server_read_task == GNUNET_SCHEDULER_NO_TASK) && 761 (h->server_read_task == NULL) &&
762 (GNUNET_YES == isDefault) && ((addr->sa_family == AF_INET) || 762 (GNUNET_YES == isDefault) && ((addr->sa_family == AF_INET) ||
763 (addr->sa_family == AF_INET6))) 763 (addr->sa_family == AF_INET6)))
764 { 764 {
@@ -784,7 +784,7 @@ restart_nat_server (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
784{ 784{
785 struct GNUNET_NAT_Handle *h = cls; 785 struct GNUNET_NAT_Handle *h = cls;
786 786
787 h->server_read_task = GNUNET_SCHEDULER_NO_TASK; 787 h->server_read_task = NULL;
788 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 788 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
789 return; 789 return;
790 start_gnunet_nat_server (h); 790 start_gnunet_nat_server (h);
@@ -811,7 +811,7 @@ nat_server_read (void *cls,
811 const char *port_start; 811 const char *port_start;
812 struct sockaddr_in sin_addr; 812 struct sockaddr_in sin_addr;
813 813
814 h->server_read_task = GNUNET_SCHEDULER_NO_TASK; 814 h->server_read_task = NULL;
815 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 815 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
816 return; 816 return;
817 memset (mybuf, 0, sizeof (mybuf)); 817 memset (mybuf, 0, sizeof (mybuf));
@@ -946,7 +946,7 @@ list_interfaces (void *cls,
946{ 946{
947 struct GNUNET_NAT_Handle *h = cls; 947 struct GNUNET_NAT_Handle *h = cls;
948 948
949 h->ifc_task = GNUNET_SCHEDULER_NO_TASK; 949 h->ifc_task = NULL;
950 remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS); 950 remove_from_address_list_by_source (h, LAL_INTERFACE_ADDRESS);
951 GNUNET_OS_network_interfaces_list (&process_interfaces, h); 951 GNUNET_OS_network_interfaces_list (&process_interfaces, h);
952 h->ifc_task = 952 h->ifc_task =
@@ -967,7 +967,7 @@ resolve_hostname (void *cls,
967{ 967{
968 struct GNUNET_NAT_Handle *h = cls; 968 struct GNUNET_NAT_Handle *h = cls;
969 969
970 h->hostname_task = GNUNET_SCHEDULER_NO_TASK; 970 h->hostname_task = NULL;
971 remove_from_address_list_by_source (h, LAL_HOSTNAME_DNS); 971 remove_from_address_list_by_source (h, LAL_HOSTNAME_DNS);
972 h->hostname_dns = 972 h->hostname_dns =
973 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, HOSTNAME_RESOLVE_TIMEOUT, 973 GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, HOSTNAME_RESOLVE_TIMEOUT,
@@ -989,7 +989,7 @@ resolve_dns (void *cls,
989 struct GNUNET_NAT_Handle *h = cls; 989 struct GNUNET_NAT_Handle *h = cls;
990 struct LocalAddressList *pos; 990 struct LocalAddressList *pos;
991 991
992 h->dns_task = GNUNET_SCHEDULER_NO_TASK; 992 h->dns_task = NULL;
993 for (pos = h->lal_head; NULL != pos; pos = pos->next) 993 for (pos = h->lal_head; NULL != pos; pos = pos->next)
994 if (pos->source == LAL_EXTERNAL_IP) 994 if (pos->source == LAL_EXTERNAL_IP)
995 pos->source = LAL_EXTERNAL_IP_OLD; 995 pos->source = LAL_EXTERNAL_IP_OLD;
@@ -1124,7 +1124,7 @@ add_from_bind (void *cls,
1124 struct sockaddr *sa; 1124 struct sockaddr *sa;
1125 const struct sockaddr_in *v4; 1125 const struct sockaddr_in *v4;
1126 1126
1127 h->bind_task = GNUNET_SCHEDULER_NO_TASK; 1127 h->bind_task = NULL;
1128 for (i = 0; i < h->num_local_addrs; i++) 1128 for (i = 0; i < h->num_local_addrs; i++)
1129 { 1129 {
1130 sa = h->local_addrs[i]; 1130 sa = h->local_addrs[i];
@@ -1384,30 +1384,30 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h)
1384 GNUNET_RESOLVER_request_cancel (h->hostname_dns); 1384 GNUNET_RESOLVER_request_cancel (h->hostname_dns);
1385 h->hostname_dns = NULL; 1385 h->hostname_dns = NULL;
1386 } 1386 }
1387 if (GNUNET_SCHEDULER_NO_TASK != h->server_read_task) 1387 if (NULL != h->server_read_task)
1388 { 1388 {
1389 GNUNET_SCHEDULER_cancel (h->server_read_task); 1389 GNUNET_SCHEDULER_cancel (h->server_read_task);
1390 h->server_read_task = GNUNET_SCHEDULER_NO_TASK; 1390 h->server_read_task = NULL;
1391 } 1391 }
1392 if (GNUNET_SCHEDULER_NO_TASK != h->bind_task) 1392 if (NULL != h->bind_task)
1393 { 1393 {
1394 GNUNET_SCHEDULER_cancel (h->bind_task); 1394 GNUNET_SCHEDULER_cancel (h->bind_task);
1395 h->bind_task = GNUNET_SCHEDULER_NO_TASK; 1395 h->bind_task = NULL;
1396 } 1396 }
1397 if (GNUNET_SCHEDULER_NO_TASK != h->ifc_task) 1397 if (NULL != h->ifc_task)
1398 { 1398 {
1399 GNUNET_SCHEDULER_cancel (h->ifc_task); 1399 GNUNET_SCHEDULER_cancel (h->ifc_task);
1400 h->ifc_task = GNUNET_SCHEDULER_NO_TASK; 1400 h->ifc_task = NULL;
1401 } 1401 }
1402 if (GNUNET_SCHEDULER_NO_TASK != h->hostname_task) 1402 if (NULL != h->hostname_task)
1403 { 1403 {
1404 GNUNET_SCHEDULER_cancel (h->hostname_task); 1404 GNUNET_SCHEDULER_cancel (h->hostname_task);
1405 h->hostname_task = GNUNET_SCHEDULER_NO_TASK; 1405 h->hostname_task = NULL;
1406 } 1406 }
1407 if (GNUNET_SCHEDULER_NO_TASK != h->dns_task) 1407 if (NULL != h->dns_task)
1408 { 1408 {
1409 GNUNET_SCHEDULER_cancel (h->dns_task); 1409 GNUNET_SCHEDULER_cancel (h->dns_task);
1410 h->dns_task = GNUNET_SCHEDULER_NO_TASK; 1410 h->dns_task = NULL;
1411 } 1411 }
1412 if (NULL != h->server_proc) 1412 if (NULL != h->server_proc)
1413 { 1413 {
diff --git a/src/nat/nat_auto.c b/src/nat/nat_auto.c
index 8fc85d7a7..33ce8c1f1 100644
--- a/src/nat/nat_auto.c
+++ b/src/nat/nat_auto.c
@@ -129,7 +129,7 @@ struct GNUNET_NAT_AutoHandle
129 /** 129 /**
130 * Task identifier for the timeout. 130 * Task identifier for the timeout.
131 */ 131 */
132 GNUNET_SCHEDULER_TaskIdentifier task; 132 struct GNUNET_SCHEDULER_Task * task;
133 133
134 /** 134 /**
135 * Where are we in the test? 135 * Where are we in the test?
@@ -196,7 +196,7 @@ reversal_test (void *cls,
196{ 196{
197 struct GNUNET_NAT_AutoHandle *ah = cls; 197 struct GNUNET_NAT_AutoHandle *ah = cls;
198 198
199 ah->task = GNUNET_SCHEDULER_NO_TASK; 199 ah->task = NULL;
200 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 200 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
201 _("Testing connection reversal with ICMP server.\n")); 201 _("Testing connection reversal with ICMP server.\n"));
202 GNUNET_RESOLVER_connect (ah->cfg); 202 GNUNET_RESOLVER_connect (ah->cfg);
@@ -603,10 +603,10 @@ GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah)
603 GNUNET_NAT_mini_get_external_ipv4_cancel (ah->eh); 603 GNUNET_NAT_mini_get_external_ipv4_cancel (ah->eh);
604 ah->eh = NULL; 604 ah->eh = NULL;
605 } 605 }
606 if (GNUNET_SCHEDULER_NO_TASK != ah->task) 606 if (NULL != ah->task)
607 { 607 {
608 GNUNET_SCHEDULER_cancel (ah->task); 608 GNUNET_SCHEDULER_cancel (ah->task);
609 ah->task = GNUNET_SCHEDULER_NO_TASK; 609 ah->task = NULL;
610 } 610 }
611 GNUNET_CONFIGURATION_destroy (ah->cfg); 611 GNUNET_CONFIGURATION_destroy (ah->cfg);
612 GNUNET_CONFIGURATION_destroy (ah->initial_cfg); 612 GNUNET_CONFIGURATION_destroy (ah->initial_cfg);
diff --git a/src/nat/nat_mini.c b/src/nat/nat_mini.c
index 1e8ab7ecc..47ba27de8 100644
--- a/src/nat/nat_mini.c
+++ b/src/nat/nat_mini.c
@@ -66,7 +66,7 @@ struct GNUNET_NAT_ExternalHandle
66 /** 66 /**
67 * Read task. 67 * Read task.
68 */ 68 */
69 GNUNET_SCHEDULER_TaskIdentifier task; 69 struct GNUNET_SCHEDULER_Task * task;
70 70
71 /** 71 /**
72 * Handle to 'external-ip' process. 72 * Handle to 'external-ip' process.
@@ -120,7 +120,7 @@ read_external_ipv4 (void *cls,
120 ssize_t ret; 120 ssize_t ret;
121 struct in_addr addr; 121 struct in_addr addr;
122 122
123 eh->task = GNUNET_SCHEDULER_NO_TASK; 123 eh->task = NULL;
124 if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r)) 124 if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
125 ret = 125 ret =
126 GNUNET_DISK_file_read (eh->r, &eh->buf[eh->off], 126 GNUNET_DISK_file_read (eh->r, &eh->buf[eh->off],
@@ -170,7 +170,7 @@ signal_external_ip_error (void *cls,
170{ 170{
171 struct GNUNET_NAT_ExternalHandle *eh = cls; 171 struct GNUNET_NAT_ExternalHandle *eh = cls;
172 172
173 eh->task = GNUNET_SCHEDULER_NO_TASK; 173 eh->task = NULL;
174 eh->cb (eh->cb_cls, 174 eh->cb (eh->cb_cls,
175 NULL, 175 NULL,
176 eh->ret); 176 eh->ret);
@@ -254,7 +254,7 @@ GNUNET_NAT_mini_get_external_ipv4_cancel (struct GNUNET_NAT_ExternalHandle *eh)
254 } 254 }
255 if (NULL != eh->opipe) 255 if (NULL != eh->opipe)
256 GNUNET_DISK_pipe_close (eh->opipe); 256 GNUNET_DISK_pipe_close (eh->opipe);
257 if (GNUNET_SCHEDULER_NO_TASK != eh->task) 257 if (NULL != eh->task)
258 GNUNET_SCHEDULER_cancel (eh->task); 258 GNUNET_SCHEDULER_cancel (eh->task);
259 GNUNET_free (eh); 259 GNUNET_free (eh);
260} 260}
@@ -300,7 +300,7 @@ struct GNUNET_NAT_MiniHandle
300 * We check the mapping periodically to see if it 300 * We check the mapping periodically to see if it
301 * still works. This task triggers the check. 301 * still works. This task triggers the check.
302 */ 302 */
303 GNUNET_SCHEDULER_TaskIdentifier refresh_task; 303 struct GNUNET_SCHEDULER_Task * refresh_task;
304 304
305 /** 305 /**
306 * Are we mapping TCP or UDP? 306 * Are we mapping TCP or UDP?
@@ -543,7 +543,7 @@ process_map_output (void *cls,
543 GNUNET_SYSERR, 543 GNUNET_SYSERR,
544 NULL, 0, 544 NULL, 0,
545 GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED); 545 GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED);
546 if (GNUNET_SCHEDULER_NO_TASK == mini->refresh_task) 546 if (NULL == mini->refresh_task)
547 mini->refresh_task = 547 mini->refresh_task =
548 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini); 548 GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
549 return; 549 return;
@@ -664,10 +664,10 @@ GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini)
664{ 664{
665 char pstr[6]; 665 char pstr[6];
666 666
667 if (GNUNET_SCHEDULER_NO_TASK != mini->refresh_task) 667 if (NULL != mini->refresh_task)
668 { 668 {
669 GNUNET_SCHEDULER_cancel (mini->refresh_task); 669 GNUNET_SCHEDULER_cancel (mini->refresh_task);
670 mini->refresh_task = GNUNET_SCHEDULER_NO_TASK; 670 mini->refresh_task = NULL;
671 } 671 }
672 if (NULL != mini->refresh_cmd) 672 if (NULL != mini->refresh_cmd)
673 { 673 {
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c
index b96ee60ed..33fbb1070 100644
--- a/src/nat/nat_test.c
+++ b/src/nat/nat_test.c
@@ -60,7 +60,7 @@ struct NatActivity
60 /** 60 /**
61 * Task reading from the incoming connection. 61 * Task reading from the incoming connection.
62 */ 62 */
63 GNUNET_SCHEDULER_TaskIdentifier rtask; 63 struct GNUNET_SCHEDULER_Task * rtask;
64}; 64};
65 65
66 66
@@ -141,12 +141,12 @@ struct GNUNET_NAT_Test
141 /** 141 /**
142 * Identity of task for the listen socket (if any) 142 * Identity of task for the listen socket (if any)
143 */ 143 */
144 GNUNET_SCHEDULER_TaskIdentifier ltask; 144 struct GNUNET_SCHEDULER_Task * ltask;
145 145
146 /** 146 /**
147 * Task identifier for the timeout (if any) 147 * Task identifier for the timeout (if any)
148 */ 148 */
149 GNUNET_SCHEDULER_TaskIdentifier ttask; 149 struct GNUNET_SCHEDULER_Task * ttask;
150 150
151 /** 151 /**
152 * GNUNET_YES if we're testing TCP 152 * GNUNET_YES if we're testing TCP
@@ -250,7 +250,7 @@ do_read (void *cls,
250 struct GNUNET_NAT_Test *tst; 250 struct GNUNET_NAT_Test *tst;
251 uint16_t data; 251 uint16_t data;
252 252
253 na->rtask = GNUNET_SCHEDULER_NO_TASK; 253 na->rtask = NULL;
254 tst = na->h; 254 tst = na->h;
255 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na); 255 GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na);
256 if ((NULL != tc->write_ready) && 256 if ((NULL != tc->write_ready) &&
@@ -287,7 +287,7 @@ do_accept (void *cls,
287 struct GNUNET_NETWORK_Handle *s; 287 struct GNUNET_NETWORK_Handle *s;
288 struct NatActivity *wl; 288 struct NatActivity *wl;
289 289
290 tst->ltask = GNUNET_SCHEDULER_NO_TASK; 290 tst->ltask = NULL;
291 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 291 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
292 return; 292 return;
293 tst->ltask = 293 tst->ltask =
@@ -386,7 +386,7 @@ do_timeout (void *cls,
386{ 386{
387 struct GNUNET_NAT_Test *nh = cls; 387 struct GNUNET_NAT_Test *nh = cls;
388 388
389 nh->ttask = GNUNET_SCHEDULER_NO_TASK; 389 nh->ttask = NULL;
390 nh->report (nh->report_cls, 390 nh->report (nh->report_cls,
391 (GNUNET_NAT_ERROR_SUCCESS == nh->status) 391 (GNUNET_NAT_ERROR_SUCCESS == nh->status)
392 ? GNUNET_NAT_ERROR_TIMEOUT 392 ? GNUNET_NAT_ERROR_TIMEOUT
@@ -495,10 +495,10 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
495 { 495 {
496 LOG (GNUNET_ERROR_TYPE_ERROR, 496 LOG (GNUNET_ERROR_TYPE_ERROR,
497 _("NAT test failed to start NAT library\n")); 497 _("NAT test failed to start NAT library\n"));
498 if (GNUNET_SCHEDULER_NO_TASK != nh->ltask) 498 if (NULL != nh->ltask)
499 { 499 {
500 GNUNET_SCHEDULER_cancel (nh->ltask); 500 GNUNET_SCHEDULER_cancel (nh->ltask);
501 nh->ltask = GNUNET_SCHEDULER_NO_TASK; 501 nh->ltask = NULL;
502 } 502 }
503 if (NULL != nh->lsock) 503 if (NULL != nh->lsock)
504 { 504 {
@@ -541,9 +541,9 @@ GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst)
541 GNUNET_NETWORK_socket_close (pos->sock); 541 GNUNET_NETWORK_socket_close (pos->sock);
542 GNUNET_free (pos); 542 GNUNET_free (pos);
543 } 543 }
544 if (GNUNET_SCHEDULER_NO_TASK != tst->ttask) 544 if (NULL != tst->ttask)
545 GNUNET_SCHEDULER_cancel (tst->ttask); 545 GNUNET_SCHEDULER_cancel (tst->ttask);
546 if (GNUNET_SCHEDULER_NO_TASK != tst->ltask) 546 if (NULL != tst->ltask)
547 GNUNET_SCHEDULER_cancel (tst->ltask); 547 GNUNET_SCHEDULER_cancel (tst->ltask);
548 if (NULL != tst->lsock) 548 if (NULL != tst->lsock)
549 GNUNET_NETWORK_socket_close (tst->lsock); 549 GNUNET_NETWORK_socket_close (tst->lsock);
diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c
index d32015b56..a5e6ba209 100644
--- a/src/nat/test_nat_test.c
+++ b/src/nat/test_nat_test.c
@@ -36,7 +36,7 @@ static int ret = 1;
36 36
37static struct GNUNET_NAT_Test *tst; 37static struct GNUNET_NAT_Test *tst;
38 38
39static GNUNET_SCHEDULER_TaskIdentifier tsk; 39static struct GNUNET_SCHEDULER_Task * tsk;
40 40
41 41
42static void 42static void
@@ -54,7 +54,7 @@ report_result (void *cls,
54 GNUNET_NAT_test_stop (tst); 54 GNUNET_NAT_test_stop (tst);
55 tst = NULL; 55 tst = NULL;
56 GNUNET_SCHEDULER_cancel (tsk); 56 GNUNET_SCHEDULER_cancel (tsk);
57 tsk = GNUNET_SCHEDULER_NO_TASK; 57 tsk = NULL;
58} 58}
59 59
60 60
@@ -62,7 +62,7 @@ static void
62failed_timeout (void *cls, 62failed_timeout (void *cls,
63 const struct GNUNET_SCHEDULER_TaskContext *tc) 63 const struct GNUNET_SCHEDULER_TaskContext *tc)
64{ 64{
65 tsk = GNUNET_SCHEDULER_NO_TASK; 65 tsk = NULL;
66 fprintf (stderr, 66 fprintf (stderr,
67 "NAT test failed to terminate on timeout\n"); 67 "NAT test failed to terminate on timeout\n");
68 ret = 2; 68 ret = 2;