diff options
Diffstat (limited to 'src/namestore/gnunet-namestore-fcfsd.c')
-rw-r--r-- | src/namestore/gnunet-namestore-fcfsd.c | 143 |
1 files changed, 91 insertions, 52 deletions
diff --git a/src/namestore/gnunet-namestore-fcfsd.c b/src/namestore/gnunet-namestore-fcfsd.c index 90ec84bde..f655ef45c 100644 --- a/src/namestore/gnunet-namestore-fcfsd.c +++ b/src/namestore/gnunet-namestore-fcfsd.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | #include <microhttpd.h> | 32 | #include <microhttpd.h> |
33 | #include "gnunet_util_lib.h" | 33 | #include "gnunet_util_lib.h" |
34 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_namestore_service.h" | 35 | #include "gnunet_namestore_service.h" |
35 | 36 | ||
36 | /** | 37 | /** |
@@ -63,7 +64,7 @@ | |||
63 | /** | 64 | /** |
64 | * Name of our cookie. | 65 | * Name of our cookie. |
65 | */ | 66 | */ |
66 | #define COOKIE_NAME "gns-fcfs" | 67 | #define COOKIE_NAME "namestore-fcfsd" |
67 | 68 | ||
68 | #define DEFAULT_ZONEINFO_BUFSIZE 2048 | 69 | #define DEFAULT_ZONEINFO_BUFSIZE 2048 |
69 | 70 | ||
@@ -193,7 +194,22 @@ static struct GNUNET_NAMESTORE_Handle *ns; | |||
193 | /** | 194 | /** |
194 | * Private key for the fcfsd zone. | 195 | * Private key for the fcfsd zone. |
195 | */ | 196 | */ |
196 | static struct GNUNET_CRYPTO_EccPrivateKey *fcfs_zone_pkey; | 197 | static struct GNUNET_CRYPTO_EccPrivateKey fcfs_zone_pkey; |
198 | |||
199 | /** | ||
200 | * Connection to identity service. | ||
201 | */ | ||
202 | static struct GNUNET_IDENTITY_Handle *identity; | ||
203 | |||
204 | /** | ||
205 | * Request for our ego. | ||
206 | */ | ||
207 | static struct GNUNET_IDENTITY_Operation *id_op; | ||
208 | |||
209 | /** | ||
210 | * Port we use for the HTTP server. | ||
211 | */ | ||
212 | static unsigned long long port; | ||
197 | 213 | ||
198 | 214 | ||
199 | /** | 215 | /** |
@@ -315,7 +331,7 @@ serve_zoneinfo_page (struct MHD_Connection *connection) | |||
315 | zr->connection = connection; | 331 | zr->connection = connection; |
316 | zr->write_offset = 0; | 332 | zr->write_offset = 0; |
317 | zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, | 333 | zr->list_it = GNUNET_NAMESTORE_zone_iteration_start (ns, |
318 | fcfs_zone_pkey, | 334 | &fcfs_zone_pkey, |
319 | &iterate_cb, | 335 | &iterate_cb, |
320 | zr); | 336 | zr); |
321 | return MHD_YES; | 337 | return MHD_YES; |
@@ -511,7 +527,7 @@ zone_to_name_cb (void *cls, | |||
511 | r.record_type = GNUNET_NAMESTORE_TYPE_PKEY; | 527 | r.record_type = GNUNET_NAMESTORE_TYPE_PKEY; |
512 | r.flags = GNUNET_NAMESTORE_RF_AUTHORITY; | 528 | r.flags = GNUNET_NAMESTORE_RF_AUTHORITY; |
513 | request->qe = GNUNET_NAMESTORE_records_store (ns, | 529 | request->qe = GNUNET_NAMESTORE_records_store (ns, |
514 | fcfs_zone_pkey, | 530 | &fcfs_zone_pkey, |
515 | request->domain_name, | 531 | request->domain_name, |
516 | 1, &r, | 532 | 1, &r, |
517 | &put_continuation, | 533 | &put_continuation, |
@@ -557,7 +573,7 @@ lookup_result_processor (void *cls, | |||
557 | return; | 573 | return; |
558 | } | 574 | } |
559 | request->qe = GNUNET_NAMESTORE_zone_to_name (ns, | 575 | request->qe = GNUNET_NAMESTORE_zone_to_name (ns, |
560 | fcfs_zone_pkey, | 576 | &fcfs_zone_pkey, |
561 | &pub, | 577 | &pub, |
562 | &zone_to_name_cb, | 578 | &zone_to_name_cb, |
563 | request); | 579 | request); |
@@ -584,7 +600,7 @@ lookup_block_processor (void *cls, | |||
584 | lookup_result_processor (request, 0, NULL); | 600 | lookup_result_processor (request, 0, NULL); |
585 | return; | 601 | return; |
586 | } | 602 | } |
587 | GNUNET_CRYPTO_ecc_key_get_public (fcfs_zone_pkey, | 603 | GNUNET_CRYPTO_ecc_key_get_public (&fcfs_zone_pkey, |
588 | &pub); | 604 | &pub); |
589 | if (GNUNET_OK != | 605 | if (GNUNET_OK != |
590 | GNUNET_NAMESTORE_block_decrypt (block, | 606 | GNUNET_NAMESTORE_block_decrypt (block, |
@@ -715,7 +731,7 @@ create_response (void *cls, | |||
715 | request, connection); | 731 | request, connection); |
716 | } | 732 | } |
717 | request->phase = RP_LOOKUP; | 733 | request->phase = RP_LOOKUP; |
718 | GNUNET_CRYPTO_ecc_key_get_public (fcfs_zone_pkey, | 734 | GNUNET_CRYPTO_ecc_key_get_public (&fcfs_zone_pkey, |
719 | &pub); | 735 | &pub); |
720 | GNUNET_NAMESTORE_query_from_public_key (&pub, | 736 | GNUNET_NAMESTORE_query_from_public_key (&pub, |
721 | request->domain_name, | 737 | request->domain_name, |
@@ -867,14 +883,73 @@ do_shutdown (void *cls, | |||
867 | MHD_stop_daemon (httpd); | 883 | MHD_stop_daemon (httpd); |
868 | httpd = NULL; | 884 | httpd = NULL; |
869 | } | 885 | } |
870 | if (NULL != fcfs_zone_pkey) | 886 | if (NULL != id_op) |
871 | { | 887 | { |
872 | GNUNET_free (fcfs_zone_pkey); | 888 | GNUNET_IDENTITY_cancel (id_op); |
873 | fcfs_zone_pkey = NULL; | 889 | id_op = NULL; |
890 | } | ||
891 | if (NULL != identity) | ||
892 | { | ||
893 | GNUNET_IDENTITY_disconnect (identity); | ||
894 | identity = NULL; | ||
874 | } | 895 | } |
875 | } | 896 | } |
876 | 897 | ||
877 | 898 | ||
899 | /** | ||
900 | * Method called to inform about the egos of this peer. | ||
901 | * | ||
902 | * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, | ||
903 | * this function is only called ONCE, and 'NULL' being passed in | ||
904 | * @a ego does indicate an error (i.e. name is taken or no default | ||
905 | * value is known). If @a ego is non-NULL and if '*ctx' | ||
906 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
907 | * call to the identity callback of #GNUNET_IDENTITY_connect (if | ||
908 | * that one was not NULL). | ||
909 | * | ||
910 | * @param cls closure, NULL | ||
911 | * @param ego ego handle | ||
912 | * @param ctx context for application to store data for this ego | ||
913 | * (during the lifetime of this process, initially NULL) | ||
914 | * @param name name assigned by the user for this ego, | ||
915 | * NULL if the user just deleted the ego and it | ||
916 | * must thus no longer be used | ||
917 | */ | ||
918 | static void | ||
919 | identity_cb (void *cls, | ||
920 | struct GNUNET_IDENTITY_Ego *ego, | ||
921 | void **ctx, | ||
922 | const char *name) | ||
923 | { | ||
924 | id_op = NULL; | ||
925 | if (NULL == ego) | ||
926 | { | ||
927 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
928 | _("No ego configured for `fcfsd` subsystem\n")); | ||
929 | return; | ||
930 | } | ||
931 | fcfs_zone_pkey = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
932 | httpd = MHD_start_daemon (MHD_USE_DUAL_STACK | MHD_USE_DEBUG, | ||
933 | (uint16_t) port, | ||
934 | NULL, NULL, | ||
935 | &create_response, NULL, | ||
936 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, | ||
937 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | ||
938 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | ||
939 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4 * 1024), | ||
940 | MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, | ||
941 | MHD_OPTION_END); | ||
942 | if (NULL == httpd) | ||
943 | { | ||
944 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
945 | _("Failed to start HTTP server\n")); | ||
946 | GNUNET_SCHEDULER_shutdown (); | ||
947 | return; | ||
948 | } | ||
949 | run_httpd (); | ||
950 | } | ||
951 | |||
952 | |||
878 | /** | 953 | /** |
879 | * Main function that will be run. | 954 | * Main function that will be run. |
880 | * | 955 | * |
@@ -887,9 +962,6 @@ static void | |||
887 | run (void *cls, char *const *args, const char *cfgfile, | 962 | run (void *cls, char *const *args, const char *cfgfile, |
888 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 963 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
889 | { | 964 | { |
890 | char *keyfile; | ||
891 | unsigned long long port; | ||
892 | |||
893 | if (GNUNET_OK != | 965 | if (GNUNET_OK != |
894 | GNUNET_CONFIGURATION_get_value_number (cfg, | 966 | GNUNET_CONFIGURATION_get_value_number (cfg, |
895 | "fcfsd", | 967 | "fcfsd", |
@@ -900,24 +972,6 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
900 | "fcfsd", "HTTPPORT"); | 972 | "fcfsd", "HTTPPORT"); |
901 | return; | 973 | return; |
902 | } | 974 | } |
903 | if (GNUNET_OK != | ||
904 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
905 | "fcfsd", | ||
906 | "ZONEKEY", | ||
907 | &keyfile)) | ||
908 | { | ||
909 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
910 | "fcfsd", "ZONEKEY"); | ||
911 | return; | ||
912 | } | ||
913 | fcfs_zone_pkey = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); | ||
914 | GNUNET_free (keyfile); | ||
915 | if (NULL == fcfs_zone_pkey) | ||
916 | { | ||
917 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
918 | _("Failed to read or create private zone key\n")); | ||
919 | return; | ||
920 | } | ||
921 | ns = GNUNET_NAMESTORE_connect (cfg); | 975 | ns = GNUNET_NAMESTORE_connect (cfg); |
922 | if (NULL == ns) | 976 | if (NULL == ns) |
923 | { | 977 | { |
@@ -925,25 +979,10 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
925 | _("Failed to connect to namestore\n")); | 979 | _("Failed to connect to namestore\n")); |
926 | return; | 980 | return; |
927 | } | 981 | } |
928 | httpd = MHD_start_daemon (MHD_USE_DEBUG, | 982 | identity = GNUNET_IDENTITY_connect (cfg, |
929 | (uint16_t) port, | 983 | NULL, NULL); |
930 | NULL, NULL, | 984 | id_op = GNUNET_IDENTITY_get (identity, "fcfsd", |
931 | &create_response, NULL, | 985 | &identity_cb, NULL); |
932 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128, | ||
933 | MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int) 1, | ||
934 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16, | ||
935 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4 * 1024), | ||
936 | MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, | ||
937 | MHD_OPTION_END); | ||
938 | if (NULL == httpd) | ||
939 | { | ||
940 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
941 | _("Failed to start HTTP server\n")); | ||
942 | GNUNET_NAMESTORE_disconnect (ns); | ||
943 | ns = NULL; | ||
944 | return; | ||
945 | } | ||
946 | run_httpd (); | ||
947 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 986 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
948 | &do_shutdown, NULL); | 987 | &do_shutdown, NULL); |
949 | } | 988 | } |
@@ -972,11 +1011,11 @@ main (int argc, char *const *argv) | |||
972 | ret = | 1011 | ret = |
973 | (GNUNET_OK == | 1012 | (GNUNET_OK == |
974 | GNUNET_PROGRAM_run (argc, argv, "fcfsd", | 1013 | GNUNET_PROGRAM_run (argc, argv, "fcfsd", |
975 | _("GNUnet GNS first come first serve registration service"), | 1014 | _("GNU Name System First Come First Serve name registration service"), |
976 | options, | 1015 | options, |
977 | &run, NULL)) ? 0 : 1; | 1016 | &run, NULL)) ? 0 : 1; |
978 | GNUNET_free ((void*) argv); | 1017 | GNUNET_free ((void*) argv); |
979 | return ret; | 1018 | return ret; |
980 | } | 1019 | } |
981 | 1020 | ||
982 | /* end of gnunet-gns-fcfsd.c */ | 1021 | /* end of gnunet-namestore-fcfsd.c */ |