diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
commit | 95f9076a2139f5fb042b944a0658b6cda2fa35db (patch) | |
tree | b0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/peerinfo | |
parent | 7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff) | |
download | gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip |
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 68 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 4 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 5 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_notify_friend_only.c | 43 |
4 files changed, 74 insertions, 46 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index a0defb8cc..66082e8f7 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -161,6 +161,16 @@ static struct NotificationContext *nc_head; | |||
161 | */ | 161 | */ |
162 | static struct NotificationContext *nc_tail; | 162 | static struct NotificationContext *nc_tail; |
163 | 163 | ||
164 | /** | ||
165 | * Handle for task to run #cron_clean_data_hosts() | ||
166 | */ | ||
167 | static struct GNUNET_SCHEDULER_Task *cron_clean; | ||
168 | |||
169 | /** | ||
170 | * Handle for task to run #cron_scan_directory_hosts() | ||
171 | */ | ||
172 | static struct GNUNET_SCHEDULER_Task *cron_scan; | ||
173 | |||
164 | 174 | ||
165 | /** | 175 | /** |
166 | * Notify all clients in the notify list about the | 176 | * Notify all clients in the notify list about the |
@@ -657,16 +667,14 @@ cron_scan_directory_data_hosts (void *cls) | |||
657 | { | 667 | { |
658 | static unsigned int retries; | 668 | static unsigned int retries; |
659 | struct DirScanContext dsc; | 669 | struct DirScanContext dsc; |
660 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
661 | 670 | ||
662 | tc = GNUNET_SCHEDULER_get_task_context (); | 671 | cron_scan = NULL; |
663 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 672 | if (GNUNET_SYSERR == |
664 | return; | 673 | GNUNET_DISK_directory_create (networkIdDirectory)) |
665 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) | ||
666 | { | 674 | { |
667 | GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, | 675 | cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, |
668 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 676 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
669 | &cron_scan_directory_data_hosts, NULL); | 677 | &cron_scan_directory_data_hosts, NULL); |
670 | return; | 678 | return; |
671 | } | 679 | } |
672 | dsc.matched = 0; | 680 | dsc.matched = 0; |
@@ -680,10 +688,10 @@ cron_scan_directory_data_hosts (void *cls) | |||
680 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 688 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
681 | _("Still no peers found in `%s'!\n"), | 689 | _("Still no peers found in `%s'!\n"), |
682 | networkIdDirectory); | 690 | networkIdDirectory); |
683 | GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, | 691 | cron_scan = GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, |
684 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 692 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
685 | &cron_scan_directory_data_hosts, | 693 | &cron_scan_directory_data_hosts, |
686 | NULL); | 694 | NULL); |
687 | } | 695 | } |
688 | 696 | ||
689 | 697 | ||
@@ -1046,11 +1054,8 @@ static void | |||
1046 | cron_clean_data_hosts (void *cls) | 1054 | cron_clean_data_hosts (void *cls) |
1047 | { | 1055 | { |
1048 | struct GNUNET_TIME_Absolute now; | 1056 | struct GNUNET_TIME_Absolute now; |
1049 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
1050 | 1057 | ||
1051 | tc = GNUNET_SCHEDULER_get_task_context (); | 1058 | cron_clean = NULL; |
1052 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
1053 | return; | ||
1054 | now = GNUNET_TIME_absolute_get (); | 1059 | now = GNUNET_TIME_absolute_get (); |
1055 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 1060 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
1056 | _("Cleaning up directory `%s'\n"), | 1061 | _("Cleaning up directory `%s'\n"), |
@@ -1058,9 +1063,9 @@ cron_clean_data_hosts (void *cls) | |||
1058 | GNUNET_DISK_directory_scan (networkIdDirectory, | 1063 | GNUNET_DISK_directory_scan (networkIdDirectory, |
1059 | &discard_hosts_helper, | 1064 | &discard_hosts_helper, |
1060 | &now); | 1065 | &now); |
1061 | GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, | 1066 | cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, |
1062 | &cron_clean_data_hosts, | 1067 | &cron_clean_data_hosts, |
1063 | NULL); | 1068 | NULL); |
1064 | } | 1069 | } |
1065 | 1070 | ||
1066 | 1071 | ||
@@ -1302,6 +1307,16 @@ shutdown_task (void *cls) | |||
1302 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1307 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1303 | stats = NULL; | 1308 | stats = NULL; |
1304 | } | 1309 | } |
1310 | if (NULL != cron_clean) | ||
1311 | { | ||
1312 | GNUNET_SCHEDULER_cancel (cron_clean); | ||
1313 | cron_clean = NULL; | ||
1314 | } | ||
1315 | if (NULL != cron_scan) | ||
1316 | { | ||
1317 | GNUNET_SCHEDULER_cancel (cron_scan); | ||
1318 | cron_scan = NULL; | ||
1319 | } | ||
1305 | } | 1320 | } |
1306 | 1321 | ||
1307 | 1322 | ||
@@ -1342,9 +1357,8 @@ run (void *cls, | |||
1342 | "USE_INCLUDED_HELLOS"); | 1357 | "USE_INCLUDED_HELLOS"); |
1343 | if (GNUNET_SYSERR == use_included) | 1358 | if (GNUNET_SYSERR == use_included) |
1344 | use_included = GNUNET_NO; | 1359 | use_included = GNUNET_NO; |
1345 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1360 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1346 | &shutdown_task, | 1361 | NULL); |
1347 | NULL); | ||
1348 | if (GNUNET_YES != noio) | 1362 | if (GNUNET_YES != noio) |
1349 | { | 1363 | { |
1350 | GNUNET_assert (GNUNET_OK == | 1364 | GNUNET_assert (GNUNET_OK == |
@@ -1358,11 +1372,13 @@ run (void *cls, | |||
1358 | return; | 1372 | return; |
1359 | } | 1373 | } |
1360 | 1374 | ||
1361 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1375 | cron_scan = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1362 | &cron_scan_directory_data_hosts, NULL); | 1376 | &cron_scan_directory_data_hosts, |
1377 | NULL); | ||
1363 | 1378 | ||
1364 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 1379 | cron_clean = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1365 | &cron_clean_data_hosts, NULL); | 1380 | &cron_clean_data_hosts, |
1381 | NULL); | ||
1366 | if (GNUNET_YES == use_included) | 1382 | if (GNUNET_YES == use_included) |
1367 | { | 1383 | { |
1368 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | 1384 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); |
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index ad4576fc2..0637eda72 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -786,7 +786,9 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
786 | GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic); | 786 | GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic); |
787 | ac->cont = &iterator_start_receive; | 787 | ac->cont = &iterator_start_receive; |
788 | ac->cont_cls = ic; | 788 | ac->cont_cls = ic; |
789 | GNUNET_CONTAINER_DLL_insert_tail (h->ac_head, h->ac_tail, ac); | 789 | GNUNET_CONTAINER_DLL_insert_tail (h->ac_head, |
790 | h->ac_tail, | ||
791 | ac); | ||
790 | GNUNET_CONTAINER_DLL_insert_tail (h->ic_head, | 792 | GNUNET_CONTAINER_DLL_insert_tail (h->ic_head, |
791 | h->ic_tail, | 793 | h->ic_tail, |
792 | ic); | 794 | ic); |
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index 16331548d..2a80c6c1a 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.c | |||
@@ -66,7 +66,7 @@ struct GNUNET_PEERINFO_NotifyContext | |||
66 | /** | 66 | /** |
67 | * Tasked used for delayed re-connection attempt. | 67 | * Tasked used for delayed re-connection attempt. |
68 | */ | 68 | */ |
69 | struct GNUNET_SCHEDULER_Task * task; | 69 | struct GNUNET_SCHEDULER_Task *task; |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * Include friend only HELLOs in callbacks | 72 | * Include friend only HELLOs in callbacks |
@@ -112,7 +112,8 @@ reconnect (void *cls) | |||
112 | { | 112 | { |
113 | /* ugh */ | 113 | /* ugh */ |
114 | nc->task = | 114 | nc->task = |
115 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, nc); | 115 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
116 | &reconnect, nc); | ||
116 | return; | 117 | return; |
117 | } | 118 | } |
118 | request_notifications (nc); | 119 | request_notifications (nc); |
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c index d0322713c..403ed4b71 100644 --- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c +++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c | |||
@@ -127,15 +127,18 @@ address_generator (void *cls, size_t max, void *buf) | |||
127 | return ret; | 127 | return ret; |
128 | } | 128 | } |
129 | 129 | ||
130 | |||
130 | static void | 131 | static void |
131 | process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer, | 132 | process_w_fo (void *cls, |
132 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 133 | const struct GNUNET_PeerIdentity *peer, |
134 | const struct GNUNET_HELLO_Message *hello, | ||
135 | const char *err_msg) | ||
133 | { | 136 | { |
134 | if (err_msg != NULL ) | 137 | if (err_msg != NULL) |
135 | { | 138 | { |
136 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 139 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
137 | _("Error in communication with PEERINFO service\n")); | 140 | _("Error in communication with PEERINFO service\n")); |
138 | GNUNET_SCHEDULER_add_now (&done, NULL ); | 141 | GNUNET_SCHEDULER_add_now (&done, NULL); |
139 | return; | 142 | return; |
140 | } | 143 | } |
141 | 144 | ||
@@ -160,7 +163,7 @@ process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
160 | if (0 == memcmp (&pid, peer, sizeof(pid))) | 163 | if (0 == memcmp (&pid, peer, sizeof(pid))) |
161 | { | 164 | { |
162 | res_cb_w_fo = GNUNET_YES; | 165 | res_cb_w_fo = GNUNET_YES; |
163 | GNUNET_SCHEDULER_add_now (&done, NULL ); | 166 | GNUNET_SCHEDULER_add_now (&done, NULL); |
164 | } | 167 | } |
165 | return; | 168 | return; |
166 | } | 169 | } |
@@ -170,11 +173,11 @@ static void | |||
170 | process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer, | 173 | process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer, |
171 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 174 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
172 | { | 175 | { |
173 | if (err_msg != NULL ) | 176 | if (err_msg != NULL) |
174 | { | 177 | { |
175 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 178 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
176 | _("Error in communication with PEERINFO service\n")); | 179 | _("Error in communication with PEERINFO service\n")); |
177 | GNUNET_SCHEDULER_add_now (&done, NULL ); | 180 | GNUNET_SCHEDULER_add_now (&done, NULL); |
178 | return; | 181 | return; |
179 | } | 182 | } |
180 | 183 | ||
@@ -204,6 +207,7 @@ process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
204 | } | 207 | } |
205 | } | 208 | } |
206 | 209 | ||
210 | |||
207 | static void | 211 | static void |
208 | add_peer_done (void *cls, const char *emsg) | 212 | add_peer_done (void *cls, const char *emsg) |
209 | { | 213 | { |
@@ -215,10 +219,11 @@ add_peer_done (void *cls, const char *emsg) | |||
215 | { | 219 | { |
216 | GNUNET_break(0); | 220 | GNUNET_break(0); |
217 | GNUNET_SCHEDULER_cancel (timeout_task); | 221 | GNUNET_SCHEDULER_cancel (timeout_task); |
218 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); | 222 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
219 | } | 223 | } |
220 | } | 224 | } |
221 | 225 | ||
226 | |||
222 | static void | 227 | static void |
223 | add_peer () | 228 | add_peer () |
224 | { | 229 | { |
@@ -229,33 +234,37 @@ add_peer () | |||
229 | memset (&pid, 32, sizeof(pid)); | 234 | memset (&pid, 32, sizeof(pid)); |
230 | h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, | 235 | h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, |
231 | GNUNET_YES); | 236 | GNUNET_YES); |
232 | GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL ); | 237 | GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL); |
233 | GNUNET_free(h2); | 238 | GNUNET_free(h2); |
234 | 239 | ||
235 | } | 240 | } |
236 | 241 | ||
242 | |||
237 | static void | 243 | static void |
238 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, | 244 | run (void *cls, |
239 | struct GNUNET_TESTING_Peer *peer) | 245 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
246 | struct GNUNET_TESTING_Peer *peer) | ||
240 | { | 247 | { |
241 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); | 248 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
242 | mycfg = cfg; | 249 | mycfg = cfg; |
243 | pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL ); | 250 | pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL); |
244 | pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL ); | 251 | pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL); |
245 | h = GNUNET_PEERINFO_connect (cfg); | 252 | h = GNUNET_PEERINFO_connect (cfg); |
246 | GNUNET_assert(NULL != h); | 253 | GNUNET_assert(NULL != h); |
247 | add_peer (); | 254 | add_peer (); |
248 | } | 255 | } |
249 | 256 | ||
257 | |||
250 | int | 258 | int |
251 | main (int argc, char *argv[]) | 259 | main (int argc, char *argv[]) |
252 | { | 260 | { |
253 | res_cb_w_fo = GNUNET_NO; | 261 | res_cb_w_fo = GNUNET_NO; |
254 | res_cb_wo_fo = GNUNET_NO; | 262 | res_cb_wo_fo = GNUNET_NO; |
255 | global_ret = 3; | 263 | global_ret = 3; |
256 | if (0 | 264 | if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", |
257 | != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", | 265 | "peerinfo", |
258 | "peerinfo", "test_peerinfo_api_data.conf", &run, NULL )) | 266 | "test_peerinfo_api_data.conf", |
267 | &run, NULL)) | ||
259 | return 1; | 268 | return 1; |
260 | return global_ret; | 269 | return global_ret; |
261 | } | 270 | } |