diff options
Diffstat (limited to 'src/namestore/gnunet-namestore-fcfsd.c')
-rw-r--r-- | src/namestore/gnunet-namestore-fcfsd.c | 160 |
1 files changed, 98 insertions, 62 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 903253b1a..f4cdf26b4 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012-2014 GNUnet e.V. | 3 | Copyright (C) 2012-2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file gnunet-namestore-fcfsd.c | 19 | * @file gnunet-namestore-fcfsd.c |
@@ -161,11 +159,6 @@ struct Request | |||
161 | struct ZoneinfoRequest | 159 | struct ZoneinfoRequest |
162 | { | 160 | { |
163 | /** | 161 | /** |
164 | * Connection | ||
165 | */ | ||
166 | struct MHD_Connection *connection; | ||
167 | |||
168 | /** | ||
169 | * List iterator | 162 | * List iterator |
170 | */ | 163 | */ |
171 | struct GNUNET_NAMESTORE_ZoneIterator *list_it; | 164 | struct GNUNET_NAMESTORE_ZoneIterator *list_it; |
@@ -212,6 +205,16 @@ static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey; | |||
212 | static struct GNUNET_IDENTITY_Handle *identity; | 205 | static struct GNUNET_IDENTITY_Handle *identity; |
213 | 206 | ||
214 | /** | 207 | /** |
208 | * Zoneinfo page we currently use. | ||
209 | */ | ||
210 | static struct MHD_Response *info_page; | ||
211 | |||
212 | /** | ||
213 | * Task that runs #update_zoneinfo_page peridicially. | ||
214 | */ | ||
215 | static struct GNUNET_SCHEDULER_Task *uzp_task; | ||
216 | |||
217 | /** | ||
215 | * Request for our ego. | 218 | * Request for our ego. |
216 | */ | 219 | */ |
217 | static struct GNUNET_IDENTITY_Operation *id_op; | 220 | static struct GNUNET_IDENTITY_Operation *id_op; |
@@ -221,6 +224,11 @@ static struct GNUNET_IDENTITY_Operation *id_op; | |||
221 | */ | 224 | */ |
222 | static unsigned long long port; | 225 | static unsigned long long port; |
223 | 226 | ||
227 | /** | ||
228 | * Name of the zone we manage. | ||
229 | */ | ||
230 | static char *zone; | ||
231 | |||
224 | 232 | ||
225 | /** | 233 | /** |
226 | * Task run whenever HTTP server operations are pending. | 234 | * Task run whenever HTTP server operations are pending. |
@@ -247,25 +255,25 @@ run_httpd_now () | |||
247 | 255 | ||
248 | 256 | ||
249 | /** | 257 | /** |
258 | * Create fresh version of zone information. | ||
259 | */ | ||
260 | static void | ||
261 | update_zoneinfo_page (void *cls); | ||
262 | |||
263 | |||
264 | /** | ||
250 | * Function called on error in zone iteration. | 265 | * Function called on error in zone iteration. |
251 | */ | 266 | */ |
252 | static void | 267 | static void |
253 | zone_iteration_error (void *cls) | 268 | zone_iteration_error (void *cls) |
254 | { | 269 | { |
255 | struct ZoneinfoRequest *zr = cls; | 270 | struct ZoneinfoRequest *zr = cls; |
256 | struct MHD_Response *response; | ||
257 | 271 | ||
258 | zr->list_it = NULL; | 272 | 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); | 273 | GNUNET_free (zr->zoneinfo); |
267 | GNUNET_free (zr); | 274 | GNUNET_SCHEDULER_cancel (uzp_task); |
268 | run_httpd_now (); | 275 | uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, |
276 | NULL); | ||
269 | } | 277 | } |
270 | 278 | ||
271 | 279 | ||
@@ -292,13 +300,9 @@ zone_iteration_end (void *cls) | |||
292 | MHD_add_response_header (response, | 300 | MHD_add_response_header (response, |
293 | MHD_HTTP_HEADER_CONTENT_TYPE, | 301 | MHD_HTTP_HEADER_CONTENT_TYPE, |
294 | MIME_HTML); | 302 | MIME_HTML); |
295 | MHD_queue_response (zr->connection, | 303 | MHD_destroy_response (info_page); |
296 | MHD_HTTP_OK, | 304 | info_page = response; |
297 | response); | ||
298 | MHD_destroy_response (response); | ||
299 | GNUNET_free (zr->zoneinfo); | 305 | GNUNET_free (zr->zoneinfo); |
300 | GNUNET_free (zr); | ||
301 | run_httpd_now (); | ||
302 | } | 306 | } |
303 | 307 | ||
304 | 308 | ||
@@ -373,27 +377,41 @@ iterate_cb (void *cls, | |||
373 | * Handler that returns FCFS zoneinfo page. | 377 | * Handler that returns FCFS zoneinfo page. |
374 | * | 378 | * |
375 | * @param connection connection to use | 379 | * @param connection connection to use |
376 | * @return MHD_YES on success | ||
377 | */ | 380 | */ |
378 | static int | 381 | static int |
379 | serve_zoneinfo_page (struct MHD_Connection *connection) | 382 | serve_zoneinfo_page (struct MHD_Connection *connection) |
380 | { | 383 | { |
381 | struct ZoneinfoRequest *zr; | 384 | return MHD_queue_response (connection, |
382 | 385 | MHD_HTTP_OK, | |
383 | zr = GNUNET_new (struct ZoneinfoRequest); | 386 | info_page); |
384 | zr->zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); | 387 | } |
385 | zr->buf_len = DEFAULT_ZONEINFO_BUFSIZE; | 388 | |
386 | zr->connection = connection; | 389 | |
387 | zr->write_offset = 0; | 390 | /** |
388 | zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 391 | * Create fresh version of zone information. |
389 | &fcfs_zone_pkey, | 392 | */ |
390 | &zone_iteration_error, | 393 | static void |
391 | zr, | 394 | update_zoneinfo_page (void *cls) |
392 | &iterate_cb, | 395 | { |
393 | zr, | 396 | static struct ZoneinfoRequest zr; |
394 | &zone_iteration_end, | 397 | |
395 | zr); | 398 | (void) cls; |
396 | return MHD_YES; | 399 | uzp_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
400 | &update_zoneinfo_page, | ||
401 | NULL); | ||
402 | if (NULL != zr.list_it) | ||
403 | return; | ||
404 | zr.zoneinfo = GNUNET_malloc (DEFAULT_ZONEINFO_BUFSIZE); | ||
405 | zr.buf_len = DEFAULT_ZONEINFO_BUFSIZE; | ||
406 | zr.write_offset = 0; | ||
407 | zr.list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | ||
408 | &fcfs_zone_pkey, | ||
409 | &zone_iteration_error, | ||
410 | &zr, | ||
411 | &iterate_cb, | ||
412 | &zr, | ||
413 | &zone_iteration_end, | ||
414 | &zr); | ||
397 | } | 415 | } |
398 | 416 | ||
399 | 417 | ||
@@ -401,7 +419,7 @@ serve_zoneinfo_page (struct MHD_Connection *connection) | |||
401 | * Handler that returns a simple static HTTP page. | 419 | * Handler that returns a simple static HTTP page. |
402 | * | 420 | * |
403 | * @param connection connection to use | 421 | * @param connection connection to use |
404 | * @return MHD_YES on success | 422 | * @return #MHD_YES on success |
405 | */ | 423 | */ |
406 | static int | 424 | static int |
407 | serve_main_page (struct MHD_Connection *connection) | 425 | serve_main_page (struct MHD_Connection *connection) |
@@ -634,14 +652,14 @@ lookup_block_error (void *cls) | |||
634 | * and continue to process the result. | 652 | * and continue to process the result. |
635 | * | 653 | * |
636 | * @param cls the 'struct Request' we are processing | 654 | * @param cls the 'struct Request' we are processing |
637 | * @param zone private key of the zone; NULL on disconnect | 655 | * @param zonekey private key of the zone; NULL on disconnect |
638 | * @param label label of the records; NULL on disconnect | 656 | * @param label label of the records; NULL on disconnect |
639 | * @param rd_count number of entries in @a rd array, 0 if label was deleted | 657 | * @param rd_count number of entries in @a rd array, 0 if label was deleted |
640 | * @param rd array of records with data to store | 658 | * @param rd array of records with data to store |
641 | */ | 659 | */ |
642 | static void | 660 | static void |
643 | lookup_block_processor (void *cls, | 661 | lookup_block_processor (void *cls, |
644 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 662 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, |
645 | const char *label, | 663 | const char *label, |
646 | unsigned int rd_count, | 664 | unsigned int rd_count, |
647 | const struct GNUNET_GNSRECORD_Data *rd) | 665 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -650,7 +668,7 @@ lookup_block_processor (void *cls, | |||
650 | 668 | ||
651 | (void) label; | 669 | (void) label; |
652 | (void) rd; | 670 | (void) rd; |
653 | (void) zone; | 671 | (void) zonekey; |
654 | request->qe = NULL; | 672 | request->qe = NULL; |
655 | if (0 == rd_count) | 673 | if (0 == rd_count) |
656 | { | 674 | { |
@@ -703,8 +721,8 @@ lookup_block_processor (void *cls, | |||
703 | * @a upload_data provided; the method must update this | 721 | * @a upload_data provided; the method must update this |
704 | * value to the number of bytes NOT processed; | 722 | * value to the number of bytes NOT processed; |
705 | * @param ptr pointer to location where we store the 'struct Request' | 723 | * @param ptr pointer to location where we store the 'struct Request' |
706 | * @return MHD_YES if the connection was handled successfully, | 724 | * @return #MHD_YES if the connection was handled successfully, |
707 | * MHD_NO if the socket must be closed due to a serious | 725 | * #MHD_NO if the socket must be closed due to a serious |
708 | * error while handling the request | 726 | * error while handling the request |
709 | */ | 727 | */ |
710 | static int | 728 | static int |
@@ -959,6 +977,11 @@ do_shutdown (void *cls) | |||
959 | GNUNET_SCHEDULER_cancel (httpd_task); | 977 | GNUNET_SCHEDULER_cancel (httpd_task); |
960 | httpd_task = NULL; | 978 | httpd_task = NULL; |
961 | } | 979 | } |
980 | if (NULL != uzp_task) | ||
981 | { | ||
982 | GNUNET_SCHEDULER_cancel (uzp_task); | ||
983 | uzp_task = NULL; | ||
984 | } | ||
962 | if (NULL != ns) | 985 | if (NULL != ns) |
963 | { | 986 | { |
964 | GNUNET_NAMESTORE_disconnect (ns); | 987 | GNUNET_NAMESTORE_disconnect (ns); |
@@ -1011,12 +1034,16 @@ identity_cb (void *cls, | |||
1011 | 1034 | ||
1012 | (void) cls; | 1035 | (void) cls; |
1013 | (void) ctx; | 1036 | (void) ctx; |
1014 | (void) name; | 1037 | if (NULL == name) |
1015 | id_op = NULL; | 1038 | return; |
1039 | if (0 != strcmp (name, | ||
1040 | zone)) | ||
1041 | return; | ||
1016 | if (NULL == ego) | 1042 | if (NULL == ego) |
1017 | { | 1043 | { |
1018 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1044 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1019 | _("No ego configured for `fcfsd` subsystem\n")); | 1045 | _("No ego configured for `fcfsd` subsystem\n")); |
1046 | GNUNET_SCHEDULER_shutdown (); | ||
1020 | return; | 1047 | return; |
1021 | } | 1048 | } |
1022 | fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | 1049 | fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); |
@@ -1041,6 +1068,7 @@ identity_cb (void *cls, | |||
1041 | while (NULL == httpd); | 1068 | while (NULL == httpd); |
1042 | if (NULL == httpd) | 1069 | if (NULL == httpd) |
1043 | { | 1070 | { |
1071 | |||
1044 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1072 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1045 | _("Failed to start HTTP server\n")); | 1073 | _("Failed to start HTTP server\n")); |
1046 | GNUNET_SCHEDULER_shutdown (); | 1074 | GNUNET_SCHEDULER_shutdown (); |
@@ -1085,16 +1113,18 @@ run (void *cls, | |||
1085 | return; | 1113 | return; |
1086 | } | 1114 | } |
1087 | identity = GNUNET_IDENTITY_connect (cfg, | 1115 | identity = GNUNET_IDENTITY_connect (cfg, |
1088 | NULL, NULL); | 1116 | &identity_cb, |
1117 | NULL); | ||
1089 | if (NULL == identity) | 1118 | if (NULL == identity) |
1090 | { | 1119 | { |
1091 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1092 | _("Failed to connect to identity\n")); | 1121 | _("Failed to connect to identity\n")); |
1093 | return; | 1122 | return; |
1094 | } | 1123 | } |
1095 | id_op = GNUNET_IDENTITY_get (identity, "fcfsd", | 1124 | uzp_task = GNUNET_SCHEDULER_add_now (&update_zoneinfo_page, |
1096 | &identity_cb, NULL); | 1125 | NULL); |
1097 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 1126 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
1127 | NULL); | ||
1098 | } | 1128 | } |
1099 | 1129 | ||
1100 | 1130 | ||
@@ -1109,7 +1139,13 @@ int | |||
1109 | main (int argc, | 1139 | main (int argc, |
1110 | char *const *argv) | 1140 | char *const *argv) |
1111 | { | 1141 | { |
1112 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 1142 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
1143 | GNUNET_GETOPT_option_mandatory | ||
1144 | (GNUNET_GETOPT_option_string ('z', | ||
1145 | "zone", | ||
1146 | "EGO", | ||
1147 | gettext_noop ("name of the zone that is to be managed by FCFSD"), | ||
1148 | &zone)), | ||
1113 | GNUNET_GETOPT_OPTION_END | 1149 | GNUNET_GETOPT_OPTION_END |
1114 | }; | 1150 | }; |
1115 | int ret; | 1151 | int ret; |