aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
committerNathan S. Evans <evans@in.tum.de>2010-11-05 18:21:50 +0000
commit75a33a1499cf60ea4364c9aa673816629a6c1413 (patch)
tree0620da4312bb04de4d7b65074fdd3b0c3dd6cc0e /src/peerinfo
parent7217c601ad30760872823193d62307e7a335d226 (diff)
downloadgnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.tar.gz
gnunet-75a33a1499cf60ea4364c9aa673816629a6c1413.zip
big scheduler refactoring, expect some issues
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c19
-rw-r--r--src/peerinfo/peerinfo_api.c35
-rw-r--r--src/peerinfo/peerinfo_api_notify.c17
-rwxr-xr-xsrc/peerinfo/perf_peerinfo_api.c6
-rw-r--r--src/peerinfo/test_peerinfo_api.c6
5 files changed, 23 insertions, 60 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 698c7dc30..31b0199f4 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -311,8 +311,7 @@ cron_scan_directory_data_hosts (void *cls,
311 GNUNET_log (GNUNET_ERROR_TYPE_WARNING | 311 GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
312 GNUNET_ERROR_TYPE_BULK, 312 GNUNET_ERROR_TYPE_BULK,
313 _("Still no peers found in `%s'!\n"), networkIdDirectory); 313 _("Still no peers found in `%s'!\n"), networkIdDirectory);
314 GNUNET_SCHEDULER_add_delayed (tc->sched, 314 GNUNET_SCHEDULER_add_delayed (DATA_HOST_FREQ,
315 DATA_HOST_FREQ,
316 &cron_scan_directory_data_hosts, NULL); 315 &cron_scan_directory_data_hosts, NULL);
317} 316}
318 317
@@ -464,8 +463,7 @@ cron_clean_data_hosts (void *cls,
464 now = GNUNET_TIME_absolute_get (); 463 now = GNUNET_TIME_absolute_get ();
465 GNUNET_DISK_directory_scan (networkIdDirectory, 464 GNUNET_DISK_directory_scan (networkIdDirectory,
466 &discard_hosts_helper, &now); 465 &discard_hosts_helper, &now);
467 GNUNET_SCHEDULER_add_delayed (tc->sched, 466 GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ,
468 DATA_HOST_CLEAN_FREQ,
469 &cron_clean_data_hosts, NULL); 467 &cron_clean_data_hosts, NULL);
470} 468}
471 469
@@ -650,13 +648,11 @@ shutdown_task (void *cls,
650 * Process statistics requests. 648 * Process statistics requests.
651 * 649 *
652 * @param cls closure 650 * @param cls closure
653 * @param sched scheduler to use
654 * @param server the initialized server 651 * @param server the initialized server
655 * @param cfg configuration to use 652 * @param cfg configuration to use
656 */ 653 */
657static void 654static void
658run (void *cls, 655run (void *cls,
659 struct GNUNET_SCHEDULER_Handle *sched,
660 struct GNUNET_SERVER_Handle *server, 656 struct GNUNET_SERVER_Handle *server,
661 const struct GNUNET_CONFIGURATION_Handle *cfg) 657 const struct GNUNET_CONFIGURATION_Handle *cfg)
662{ 658{
@@ -672,7 +668,7 @@ run (void *cls,
672 }; 668 };
673 669
674 hostmap = GNUNET_CONTAINER_multihashmap_create (1024); 670 hostmap = GNUNET_CONTAINER_multihashmap_create (1024);
675 stats = GNUNET_STATISTICS_create (sched, "peerinfo", cfg); 671 stats = GNUNET_STATISTICS_create ("peerinfo", cfg);
676 notify_list = GNUNET_SERVER_notification_context_create (server, 0); 672 notify_list = GNUNET_SERVER_notification_context_create (server, 0);
677 GNUNET_assert (GNUNET_OK == 673 GNUNET_assert (GNUNET_OK ==
678 GNUNET_CONFIGURATION_get_value_filename (cfg, 674 GNUNET_CONFIGURATION_get_value_filename (cfg,
@@ -680,14 +676,11 @@ run (void *cls,
680 "HOSTS", 676 "HOSTS",
681 &networkIdDirectory)); 677 &networkIdDirectory));
682 GNUNET_DISK_directory_create (networkIdDirectory); 678 GNUNET_DISK_directory_create (networkIdDirectory);
683 GNUNET_SCHEDULER_add_with_priority (sched, 679 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
684 GNUNET_SCHEDULER_PRIORITY_IDLE,
685 &cron_scan_directory_data_hosts, NULL); 680 &cron_scan_directory_data_hosts, NULL);
686 GNUNET_SCHEDULER_add_with_priority (sched, 681 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
687 GNUNET_SCHEDULER_PRIORITY_IDLE,
688 &cron_clean_data_hosts, NULL); 682 &cron_clean_data_hosts, NULL);
689 GNUNET_SCHEDULER_add_delayed (sched, 683 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
690 GNUNET_TIME_UNIT_FOREVER_REL,
691 &shutdown_task, NULL); 684 &shutdown_task, NULL);
692 GNUNET_SERVER_add_handlers (server, handlers); 685 GNUNET_SERVER_add_handlers (server, handlers);
693} 686}
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c
index 5803b076a..e7f095eac 100644
--- a/src/peerinfo/peerinfo_api.c
+++ b/src/peerinfo/peerinfo_api.c
@@ -91,11 +91,6 @@ struct GNUNET_PEERINFO_Handle
91 const struct GNUNET_CONFIGURATION_Handle *cfg; 91 const struct GNUNET_CONFIGURATION_Handle *cfg;
92 92
93 /** 93 /**
94 * Our scheduler.
95 */
96 struct GNUNET_SCHEDULER_Handle *sched;
97
98 /**
99 * Connection to the service. 94 * Connection to the service.
100 */ 95 */
101 struct GNUNET_CLIENT_Connection *client; 96 struct GNUNET_CLIENT_Connection *client;
@@ -127,25 +122,22 @@ struct GNUNET_PEERINFO_Handle
127/** 122/**
128 * Connect to the peerinfo service. 123 * Connect to the peerinfo service.
129 * 124 *
130 * @param sched scheduler to use
131 * @param cfg configuration to use 125 * @param cfg configuration to use
132 * @return NULL on error (configuration related, actual connection 126 * @return NULL on error (configuration related, actual connection
133 * establishment may happen asynchronously). 127 * establishment may happen asynchronously).
134 */ 128 */
135struct GNUNET_PEERINFO_Handle * 129struct GNUNET_PEERINFO_Handle *
136GNUNET_PEERINFO_connect (struct GNUNET_SCHEDULER_Handle *sched, 130GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
137 const struct GNUNET_CONFIGURATION_Handle *cfg)
138{ 131{
139 struct GNUNET_CLIENT_Connection *client; 132 struct GNUNET_CLIENT_Connection *client;
140 struct GNUNET_PEERINFO_Handle *ret; 133 struct GNUNET_PEERINFO_Handle *ret;
141 134
142 client = GNUNET_CLIENT_connect (sched, "peerinfo", cfg); 135 client = GNUNET_CLIENT_connect ("peerinfo", cfg);
143 if (client == NULL) 136 if (client == NULL)
144 return NULL; 137 return NULL;
145 ret = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_Handle)); 138 ret = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_Handle));
146 ret->client = client; 139 ret->client = client;
147 ret->cfg = cfg; 140 ret->cfg = cfg;
148 ret->sched = sched;
149 return ret; 141 return ret;
150} 142}
151 143
@@ -203,7 +195,7 @@ reconnect (struct GNUNET_PEERINFO_Handle *h)
203{ 195{
204 GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR); 196 GNUNET_CLIENT_disconnect (h->client, GNUNET_SYSERR);
205 h->th = NULL; 197 h->th = NULL;
206 h->client = GNUNET_CLIENT_connect (h->sched, "peerinfo", h->cfg); 198 h->client = GNUNET_CLIENT_connect ("peerinfo", h->cfg);
207 GNUNET_assert (h->client != NULL); 199 GNUNET_assert (h->client != NULL);
208} 200}
209 201
@@ -395,8 +387,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
395 reconnect (ic->h); 387 reconnect (ic->h);
396 trigger_transmit (ic->h); 388 trigger_transmit (ic->h);
397 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) 389 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
398 GNUNET_SCHEDULER_cancel (ic->h->sched, 390 GNUNET_SCHEDULER_cancel (ic->timeout_task);
399 ic->timeout_task);
400 if (ic->callback != NULL) 391 if (ic->callback != NULL)
401 ic->callback (ic->callback_cls, NULL, NULL); 392 ic->callback (ic->callback_cls, NULL, NULL);
402 GNUNET_free (ic); 393 GNUNET_free (ic);
@@ -411,8 +402,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
411#endif 402#endif
412 trigger_transmit (ic->h); 403 trigger_transmit (ic->h);
413 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) 404 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
414 GNUNET_SCHEDULER_cancel (ic->h->sched, 405 GNUNET_SCHEDULER_cancel (ic->timeout_task);
415 ic->timeout_task);
416 if (ic->callback != NULL) 406 if (ic->callback != NULL)
417 ic->callback (ic->callback_cls, NULL, NULL); 407 ic->callback (ic->callback_cls, NULL, NULL);
418 GNUNET_free (ic); 408 GNUNET_free (ic);
@@ -426,8 +416,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
426 reconnect (ic->h); 416 reconnect (ic->h);
427 trigger_transmit (ic->h); 417 trigger_transmit (ic->h);
428 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) 418 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
429 GNUNET_SCHEDULER_cancel (ic->h->sched, 419 GNUNET_SCHEDULER_cancel (ic->timeout_task);
430 ic->timeout_task);
431 if (ic->callback != NULL) 420 if (ic->callback != NULL)
432 ic->callback (ic->callback_cls, NULL, NULL); 421 ic->callback (ic->callback_cls, NULL, NULL);
433 GNUNET_free (ic); 422 GNUNET_free (ic);
@@ -445,8 +434,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg)
445 reconnect (ic->h); 434 reconnect (ic->h);
446 trigger_transmit (ic->h); 435 trigger_transmit (ic->h);
447 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) 436 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
448 GNUNET_SCHEDULER_cancel (ic->h->sched, 437 GNUNET_SCHEDULER_cancel (ic->timeout_task);
449 ic->timeout_task);
450 if (ic->callback != NULL) 438 if (ic->callback != NULL)
451 ic->callback (ic->callback_cls, NULL, NULL); 439 ic->callback (ic->callback_cls, NULL, NULL);
452 GNUNET_free (ic); 440 GNUNET_free (ic);
@@ -492,8 +480,7 @@ iterator_start_receive (void *cls,
492 transmit_success); 480 transmit_success);
493 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) 481 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
494 { 482 {
495 GNUNET_SCHEDULER_cancel (ic->h->sched, 483 GNUNET_SCHEDULER_cancel (ic->timeout_task);
496 ic->timeout_task);
497 ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; 484 ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
498 } 485 }
499 reconnect (ic->h); 486 reconnect (ic->h);
@@ -609,8 +596,7 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h,
609 ic->callback = callback; 596 ic->callback = callback;
610 ic->callback_cls = callback_cls; 597 ic->callback_cls = callback_cls;
611 ic->timeout = GNUNET_TIME_relative_to_absolute (timeout); 598 ic->timeout = GNUNET_TIME_relative_to_absolute (timeout);
612 ic->timeout_task = GNUNET_SCHEDULER_add_delayed (h->sched, 599 ic->timeout_task = GNUNET_SCHEDULER_add_delayed (timeout,
613 timeout,
614 &signal_timeout, 600 &signal_timeout,
615 ic); 601 ic);
616 tqe->timeout = ic->timeout; 602 tqe->timeout = ic->timeout;
@@ -637,8 +623,7 @@ GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
637{ 623{
638 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK) 624 if (ic->timeout_task != GNUNET_SCHEDULER_NO_TASK)
639 { 625 {
640 GNUNET_SCHEDULER_cancel (ic->h->sched, 626 GNUNET_SCHEDULER_cancel (ic->timeout_task);
641 ic->timeout_task);
642 ic->timeout_task = GNUNET_SCHEDULER_NO_TASK; 627 ic->timeout_task = GNUNET_SCHEDULER_NO_TASK;
643 } 628 }
644 ic->callback = NULL; 629 ic->callback = NULL;
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c
index c7a9c6145..25f2b9d5e 100644
--- a/src/peerinfo/peerinfo_api_notify.c
+++ b/src/peerinfo/peerinfo_api_notify.c
@@ -62,10 +62,6 @@ struct GNUNET_PEERINFO_NotifyContext
62 */ 62 */
63 const struct GNUNET_CONFIGURATION_Handle *cfg; 63 const struct GNUNET_CONFIGURATION_Handle *cfg;
64 64
65 /**
66 * Scheduler.
67 */
68 struct GNUNET_SCHEDULER_Handle *sched;
69}; 65};
70 66
71 67
@@ -109,7 +105,7 @@ process_notification (void *cls,
109 if (msg == NULL) 105 if (msg == NULL)
110 { 106 {
111 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); 107 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
112 nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg); 108 nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
113 request_notifications (nc); 109 request_notifications (nc);
114 return; 110 return;
115 } 111 }
@@ -119,7 +115,7 @@ process_notification (void *cls,
119 { 115 {
120 GNUNET_break (0); 116 GNUNET_break (0);
121 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); 117 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
122 nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg); 118 nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
123 request_notifications (nc); 119 request_notifications (nc);
124 return; 120 return;
125 } 121 }
@@ -132,7 +128,7 @@ process_notification (void *cls,
132 { 128 {
133 GNUNET_break (0); 129 GNUNET_break (0);
134 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); 130 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
135 nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg); 131 nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
136 request_notifications (nc); 132 request_notifications (nc);
137 return; 133 return;
138 } 134 }
@@ -183,7 +179,7 @@ transmit_notify_request (void *cls,
183 if (buf == NULL) 179 if (buf == NULL)
184 { 180 {
185 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO); 181 GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
186 nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg); 182 nc->client = GNUNET_CLIENT_connect ("peerinfo", nc->cfg);
187 request_notifications (nc); 183 request_notifications (nc);
188 return 0; 184 return 0;
189 } 185 }
@@ -221,21 +217,19 @@ request_notifications (struct GNUNET_PEERINFO_NotifyContext *nc)
221 * peers and then only signals changes. 217 * peers and then only signals changes.
222 * 218 *
223 * @param cfg configuration to use 219 * @param cfg configuration to use
224 * @param sched scheduler to use
225 * @param callback the method to call for each peer 220 * @param callback the method to call for each peer
226 * @param callback_cls closure for callback 221 * @param callback_cls closure for callback
227 * @return NULL on error 222 * @return NULL on error
228 */ 223 */
229struct GNUNET_PEERINFO_NotifyContext * 224struct GNUNET_PEERINFO_NotifyContext *
230GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, 225GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
231 struct GNUNET_SCHEDULER_Handle *sched,
232 GNUNET_PEERINFO_Processor callback, 226 GNUNET_PEERINFO_Processor callback,
233 void *callback_cls) 227 void *callback_cls)
234{ 228{
235 struct GNUNET_PEERINFO_NotifyContext *nc; 229 struct GNUNET_PEERINFO_NotifyContext *nc;
236 struct GNUNET_CLIENT_Connection *client; 230 struct GNUNET_CLIENT_Connection *client;
237 231
238 client = GNUNET_CLIENT_connect (sched, "peerinfo", cfg); 232 client = GNUNET_CLIENT_connect ("peerinfo", cfg);
239 if (client == NULL) 233 if (client == NULL)
240 { 234 {
241 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 235 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -243,7 +237,6 @@ GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg,
243 return NULL; 237 return NULL;
244 } 238 }
245 nc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NotifyContext)); 239 nc = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_NotifyContext));
246 nc->sched = sched;
247 nc->cfg = cfg; 240 nc->cfg = cfg;
248 nc->client = client; 241 nc->client = client;
249 nc->callback = callback; 242 nc->callback = callback;
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
index 2c3d54109..1c2f81d76 100755
--- a/src/peerinfo/perf_peerinfo_api.c
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -37,8 +37,6 @@
37 37
38#define NUM_REQUESTS 5000 38#define NUM_REQUESTS 5000
39 39
40static struct GNUNET_SCHEDULER_Handle *sched;
41
42static const struct GNUNET_CONFIGURATION_Handle *cfg; 40static const struct GNUNET_CONFIGURATION_Handle *cfg;
43 41
44static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS]; 42static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS];
@@ -132,15 +130,13 @@ process (void *cls,
132 130
133static void 131static void
134run (void *cls, 132run (void *cls,
135 struct GNUNET_SCHEDULER_Handle *s,
136 char *const *args, 133 char *const *args,
137 const char *cfgfile, 134 const char *cfgfile,
138 const struct GNUNET_CONFIGURATION_Handle *c) 135 const struct GNUNET_CONFIGURATION_Handle *c)
139{ 136{
140 size_t i; 137 size_t i;
141 sched = s;
142 cfg = c; 138 cfg = c;
143 h = GNUNET_PEERINFO_connect (sched, cfg); 139 h = GNUNET_PEERINFO_connect (cfg);
144 GNUNET_assert (h != NULL); 140 GNUNET_assert (h != NULL);
145 for (i = 0; i < NUM_REQUESTS; i++) 141 for (i = 0; i < NUM_REQUESTS; i++)
146 { 142 {
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index eae448bbf..fdd0dc460 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -36,8 +36,6 @@
36#include "gnunet_time_lib.h" 36#include "gnunet_time_lib.h"
37#include "peerinfo.h" 37#include "peerinfo.h"
38 38
39static struct GNUNET_SCHEDULER_Handle *sched;
40
41static const struct GNUNET_CONFIGURATION_Handle *cfg; 39static const struct GNUNET_CONFIGURATION_Handle *cfg;
42 40
43static struct GNUNET_PEERINFO_IteratorContext *ic; 41static struct GNUNET_PEERINFO_IteratorContext *ic;
@@ -143,14 +141,12 @@ process (void *cls,
143 141
144static void 142static void
145run (void *cls, 143run (void *cls,
146 struct GNUNET_SCHEDULER_Handle *s,
147 char *const *args, 144 char *const *args,
148 const char *cfgfile, 145 const char *cfgfile,
149 const struct GNUNET_CONFIGURATION_Handle *c) 146 const struct GNUNET_CONFIGURATION_Handle *c)
150{ 147{
151 sched = s;
152 cfg = c; 148 cfg = c;
153 h = GNUNET_PEERINFO_connect (sched, cfg); 149 h = GNUNET_PEERINFO_connect (cfg);
154 GNUNET_assert (h != NULL); 150 GNUNET_assert (h != NULL);
155 add_peer (); 151 add_peer ();
156 ic = GNUNET_PEERINFO_iterate (h, 152 ic = GNUNET_PEERINFO_iterate (h,