diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-06-07 16:55:11 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-06-07 16:55:24 +0200 |
commit | 3eedf50775f5857416e1943901ffcef5f0504815 (patch) | |
tree | 2f9937ab386b6b5ecce2d32595cc6d1fa67557e1 /src/namestore | |
parent | 4e29ecde9b3ad3e34af359f18b6679c06b17ce78 (diff) | |
download | gnunet-3eedf50775f5857416e1943901ffcef5f0504815.tar.gz gnunet-3eedf50775f5857416e1943901ffcef5f0504815.zip |
avoid looping on listing of zone
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-namestore-fcfsd.c | 105 |
1 files changed, 65 insertions, 40 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 89e42ddac..b4f8a7b26 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -156,11 +156,6 @@ struct Request | |||
156 | struct ZoneinfoRequest | 156 | struct ZoneinfoRequest |
157 | { | 157 | { |
158 | /** | 158 | /** |
159 | * Connection | ||
160 | */ | ||
161 | struct MHD_Connection *connection; | ||
162 | |||
163 | /** | ||
164 | * List iterator | 159 | * List iterator |
165 | */ | 160 | */ |
166 | struct GNUNET_NAMESTORE_ZoneIterator *list_it; | 161 | struct GNUNET_NAMESTORE_ZoneIterator *list_it; |
@@ -207,6 +202,16 @@ static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey; | |||
207 | static struct GNUNET_IDENTITY_Handle *identity; | 202 | static struct GNUNET_IDENTITY_Handle *identity; |
208 | 203 | ||
209 | /** | 204 | /** |
205 | * Zoneinfo page we currently use. | ||
206 | */ | ||
207 | static struct MHD_Response *info_page; | ||
208 | |||
209 | /** | ||
210 | * Task that runs #update_zoneinfo_page peridicially. | ||
211 | */ | ||
212 | static struct GNUNET_SCHEDULER_Task *uzp_task; | ||
213 | |||
214 | /** | ||
210 | * Request for our ego. | 215 | * Request for our ego. |
211 | */ | 216 | */ |
212 | static struct GNUNET_IDENTITY_Operation *id_op; | 217 | static struct GNUNET_IDENTITY_Operation *id_op; |
@@ -247,25 +252,26 @@ run_httpd_now () | |||
247 | 252 | ||
248 | 253 | ||
249 | /** | 254 | /** |
255 | * Create fresh version of zone information. | ||
256 | */ | ||
257 | static void | ||
258 | update_zoneinfo_page (void *cls); | ||
259 | |||
260 | |||
261 | /** | ||
250 | * Function called on error in zone iteration. | 262 | * Function called on error in zone iteration. |
251 | */ | 263 | */ |
252 | static void | 264 | static void |
253 | zone_iteration_error (void *cls) | 265 | zone_iteration_error (void *cls) |
254 | { | 266 | { |
255 | struct ZoneinfoRequest *zr = cls; | 267 | struct ZoneinfoRequest *zr = cls; |
256 | struct MHD_Response *response; | ||
257 | 268 | ||
258 | zr->list_it = NULL; | 269 | zr->list_it = NULL; |
259 | response = MHD_create_response_from_buffer (strlen ("internal error"), | ||
260 | (void *) "internal error", | ||
261 | MHD_RESPMEM_PERSISTENT); | ||
262 | MHD_queue_response (zr->connection, | ||
263 | MHD_HTTP_INTERNAL_SERVER_ERROR, | ||
264 | response); | ||
265 | MHD_destroy_response (response); | ||
266 | GNUNET_free (zr->zoneinfo); | 270 | GNUNET_free (zr->zoneinfo); |
267 | GNUNET_free (zr); | 271 | GNUNET_free (zr); |
268 | run_httpd_now (); | 272 | GNUNET_SCHEDULER_cancel (uzp_task); |
273 | uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, | ||
274 | NULL); | ||
269 | } | 275 | } |
270 | 276 | ||
271 | 277 | ||
@@ -292,13 +298,10 @@ zone_iteration_end (void *cls) | |||
292 | MHD_add_response_header (response, | 298 | MHD_add_response_header (response, |
293 | MHD_HTTP_HEADER_CONTENT_TYPE, | 299 | MHD_HTTP_HEADER_CONTENT_TYPE, |
294 | MIME_HTML); | 300 | MIME_HTML); |
295 | MHD_queue_response (zr->connection, | 301 | MHD_destroy_response (info_page); |
296 | MHD_HTTP_OK, | 302 | info_page = response; |
297 | response); | ||
298 | MHD_destroy_response (response); | ||
299 | GNUNET_free (zr->zoneinfo); | 303 | GNUNET_free (zr->zoneinfo); |
300 | GNUNET_free (zr); | 304 | GNUNET_free (zr); |
301 | run_httpd_now (); | ||
302 | } | 305 | } |
303 | 306 | ||
304 | 307 | ||
@@ -373,27 +376,41 @@ iterate_cb (void *cls, | |||
373 | * Handler that returns FCFS zoneinfo page. | 376 | * Handler that returns FCFS zoneinfo page. |
374 | * | 377 | * |
375 | * @param connection connection to use | 378 | * @param connection connection to use |
376 | * @return MHD_YES on success | ||
377 | */ | 379 | */ |
378 | static int | 380 | static int |
379 | serve_zoneinfo_page (struct MHD_Connection *connection) | 381 | serve_zoneinfo_page (struct MHD_Connection *connection) |
380 | { | 382 | { |
381 | struct ZoneinfoRequest *zr; | 383 | return MHD_queue_response (connection, |
382 | 384 | MHD_HTTP_OK, | |
383 | zr = GNUNET_new (struct ZoneinfoRequest); | 385 | info_page); |
384 | zr->zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); | 386 | } |
385 | zr->buf_len = DEFAULT_ZONEINFO_BUFSIZE; | 387 | |
386 | zr->connection = connection; | 388 | |
387 | zr->write_offset = 0; | 389 | /** |
388 | zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 390 | * Create fresh version of zone information. |
389 | &fcfs_zone_pkey, | 391 | */ |
390 | &zone_iteration_error, | 392 | static void |
391 | zr, | 393 | update_zoneinfo_page (void *cls) |
392 | &iterate_cb, | 394 | { |
393 | zr, | 395 | static struct ZoneinfoRequest zr; |
394 | &zone_iteration_end, | 396 | |
395 | zr); | 397 | (void) cls; |
396 | return MHD_YES; | 398 | uzp_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
399 | &update_zoneinfo_page, | ||
400 | NULL); | ||
401 | if (NULL != zr.list_it) | ||
402 | return; | ||
403 | zr.zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); | ||
404 | zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE; | ||
405 | zr.write_offset = 0; | ||
406 | zr.list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | ||
407 | &fcfs_zone_pkey, | ||
408 | &zone_iteration_error, | ||
409 | &zr, | ||
410 | &iterate_cb, | ||
411 | &zr, | ||
412 | &zone_iteration_end, | ||
413 | &zr); | ||
397 | } | 414 | } |
398 | 415 | ||
399 | 416 | ||
@@ -401,7 +418,7 @@ serve_zoneinfo_page (struct MHD_Connection *connection) | |||
401 | * Handler that returns a simple static HTTP page. | 418 | * Handler that returns a simple static HTTP page. |
402 | * | 419 | * |
403 | * @param connection connection to use | 420 | * @param connection connection to use |
404 | * @return MHD_YES on success | 421 | * @return #MHD_YES on success |
405 | */ | 422 | */ |
406 | static int | 423 | static int |
407 | serve_main_page (struct MHD_Connection *connection) | 424 | serve_main_page (struct MHD_Connection *connection) |
@@ -703,8 +720,8 @@ lookup_block_processor (void *cls, | |||
703 | * @a upload_data provided; the method must update this | 720 | * @a upload_data provided; the method must update this |
704 | * value to the number of bytes NOT processed; | 721 | * value to the number of bytes NOT processed; |
705 | * @param ptr pointer to location where we store the 'struct Request' | 722 | * @param ptr pointer to location where we store the 'struct Request' |
706 | * @return MHD_YES if the connection was handled successfully, | 723 | * @return #MHD_YES if the connection was handled successfully, |
707 | * MHD_NO if the socket must be closed due to a serious | 724 | * #MHD_NO if the socket must be closed due to a serious |
708 | * error while handling the request | 725 | * error while handling the request |
709 | */ | 726 | */ |
710 | static int | 727 | static int |
@@ -959,6 +976,11 @@ do_shutdown (void *cls) | |||
959 | GNUNET_SCHEDULER_cancel (httpd_task); | 976 | GNUNET_SCHEDULER_cancel (httpd_task); |
960 | httpd_task = NULL; | 977 | httpd_task = NULL; |
961 | } | 978 | } |
979 | if (NULL != uzp_task) | ||
980 | { | ||
981 | GNUNET_SCHEDULER_cancel (uzp_task); | ||
982 | uzp_task = NULL; | ||
983 | } | ||
962 | if (NULL != ns) | 984 | if (NULL != ns) |
963 | { | 985 | { |
964 | GNUNET_NAMESTORE_disconnect (ns); | 986 | GNUNET_NAMESTORE_disconnect (ns); |
@@ -1045,6 +1067,7 @@ identity_cb (void *cls, | |||
1045 | while (NULL == httpd); | 1067 | while (NULL == httpd); |
1046 | if (NULL == httpd) | 1068 | if (NULL == httpd) |
1047 | { | 1069 | { |
1070 | |||
1048 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1071 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1049 | _("Failed to start HTTP server\n")); | 1072 | _("Failed to start HTTP server\n")); |
1050 | GNUNET_SCHEDULER_shutdown (); | 1073 | GNUNET_SCHEDULER_shutdown (); |
@@ -1097,6 +1120,8 @@ run (void *cls, | |||
1097 | _("Failed to connect to identity\n")); | 1120 | _("Failed to connect to identity\n")); |
1098 | return; | 1121 | return; |
1099 | } | 1122 | } |
1123 | uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, | ||
1124 | NULL); | ||
1100 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 1125 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
1101 | NULL); | 1126 | NULL); |
1102 | } | 1127 | } |