aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/identity/gnunet-identity.c111
-rw-r--r--src/include/gnunet_crypto_lib.h10
-rw-r--r--src/namestore/Makefile.am21
-rw-r--r--src/namestore/gnunet-namestore-fcfsd.c143
-rw-r--r--src/peerinfo/gnunet-service-peerinfo.c2
5 files changed, 210 insertions, 77 deletions
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index e56a05807..c1803ea1d 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -23,8 +23,7 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 *
25 * Todo: 25 * Todo:
26 * - add options to get/set default egos 26 * - add options to get default egos
27 * - print short hashes of egos when printing
28 */ 27 */
29#include "platform.h" 28#include "platform.h"
30#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
@@ -56,6 +55,21 @@ static char *create_ego;
56static char *delete_ego; 55static char *delete_ego;
57 56
58/** 57/**
58 * -s option.
59 */
60static char *set_ego;
61
62/**
63 * -S option.
64 */
65static char *set_subsystem;
66
67/**
68 * Operation handle for set operation.
69 */
70static struct GNUNET_IDENTITY_Operation *set_op;
71
72/**
59 * Handle for create operation. 73 * Handle for create operation.
60 */ 74 */
61static struct GNUNET_IDENTITY_Operation *create_op; 75static struct GNUNET_IDENTITY_Operation *create_op;
@@ -76,12 +90,26 @@ static void
76shutdown_task (void *cls, 90shutdown_task (void *cls,
77 const struct GNUNET_SCHEDULER_TaskContext *tc) 91 const struct GNUNET_SCHEDULER_TaskContext *tc)
78{ 92{
93 if (NULL != set_op)
94 {
95 GNUNET_IDENTITY_cancel (set_op);
96 set_op = NULL;
97 }
98 if (NULL != create_op)
99 {
100 GNUNET_IDENTITY_cancel (create_op);
101 create_op = NULL;
102 }
103 if (NULL != delete_op)
104 {
105 GNUNET_IDENTITY_cancel (delete_op);
106 delete_op = NULL;
107 }
79 GNUNET_IDENTITY_disconnect (sh); 108 GNUNET_IDENTITY_disconnect (sh);
80 sh = NULL; 109 sh = NULL;
81} 110}
82 111
83 112
84
85/** 113/**
86 * Test if we are finished yet. 114 * Test if we are finished yet.
87 */ 115 */
@@ -90,6 +118,8 @@ test_finished ()
90{ 118{
91 if ( (NULL == create_op) && 119 if ( (NULL == create_op) &&
92 (NULL == delete_op) && 120 (NULL == delete_op) &&
121 (NULL == set_op) &&
122 (NULL == set_ego) &&
93 (! list) && 123 (! list) &&
94 (! monitor) ) 124 (! monitor) )
95 GNUNET_SCHEDULER_shutdown (); 125 GNUNET_SCHEDULER_shutdown ();
@@ -139,6 +169,25 @@ create_finished (void *cls,
139 169
140 170
141/** 171/**
172 * Function called by #GNUNET_IDENTITY_set up on completion.
173 *
174 * @param cls NULL
175 * @param emsg error message (NULL on success)
176 */
177static void
178set_done (void *cls,
179 const char *emsg)
180{
181 set_op = NULL;
182 if (NULL != emsg)
183 fprintf (stderr,
184 _("Failed to set default ego: %s\n"),
185 emsg);
186 test_finished ();
187}
188
189
190/**
142 * If listing is enabled, prints information about the egos. 191 * If listing is enabled, prints information about the egos.
143 * 192 *
144 * This function is initially called for all egos and then again 193 * This function is initially called for all egos and then again
@@ -177,17 +226,48 @@ print_ego (void *cls,
177 void **ctx, 226 void **ctx,
178 const char *identifier) 227 const char *identifier)
179{ 228{
180 if (! (list | monitor)) 229 struct GNUNET_CRYPTO_EccPublicKey pk;
181 return; 230 char *s;
231
232 if ( (NULL != set_ego) &&
233 (NULL != ego) &&
234 (NULL != identifier) &&
235 (0 == strcmp (identifier,
236 set_ego)) )
237 {
238 set_op = GNUNET_IDENTITY_set (sh,
239 set_subsystem,
240 ego,
241 &set_done,
242 NULL);
243 GNUNET_free (set_subsystem);
244 set_subsystem = NULL;
245 GNUNET_free (set_ego);
246 set_ego = NULL;
247 }
248 if ( (NULL == ego) &&
249 (NULL != set_ego) )
250 {
251 fprintf (stderr,
252 "Could not set ego to `%s' for subsystem `%s', ego not known\n",
253 set_ego,
254 set_subsystem);
255 GNUNET_free (set_subsystem);
256 set_subsystem = NULL;
257 GNUNET_free (set_ego);
258 set_ego = NULL;
259 }
182 if ( (NULL == ego) && (! monitor) ) 260 if ( (NULL == ego) && (! monitor) )
183 { 261 {
184 GNUNET_SCHEDULER_shutdown (); 262 GNUNET_SCHEDULER_shutdown ();
185 return; 263 return;
186 } 264 }
187 if (monitor) 265 if (! (list | monitor))
188 fprintf (stderr, "%s - %p\n", identifier, ego); 266 return;
189 else if (NULL != identifier) 267 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
190 fprintf (stderr, "%s\n", identifier); 268 s = GNUNET_CRYPTO_ecc_public_key_to_string (&pk);
269 if ( (monitor) || (NULL != identifier) )
270 fprintf (stderr, "%s - %s\n", identifier, s);
191} 271}
192 272
193 273
@@ -203,6 +283,13 @@ static void
203run (void *cls, char *const *args, const char *cfgfile, 283run (void *cls, char *const *args, const char *cfgfile,
204 const struct GNUNET_CONFIGURATION_Handle *cfg) 284 const struct GNUNET_CONFIGURATION_Handle *cfg)
205{ 285{
286 if ( (NULL == set_subsystem) ^
287 (NULL == set_ego) )
288 {
289 fprintf (stderr,
290 "Options -e and -s must always be specified together\n");
291 return;
292 }
206 sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL); 293 sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL);
207 if (NULL != delete_ego) 294 if (NULL != delete_ego)
208 delete_op = GNUNET_IDENTITY_delete (sh, 295 delete_op = GNUNET_IDENTITY_delete (sh,
@@ -242,9 +329,15 @@ main (int argc, char *const *argv)
242 {'d', "display", NULL, 329 {'d', "display", NULL,
243 gettext_noop ("display all egos"), 330 gettext_noop ("display all egos"),
244 0, &GNUNET_GETOPT_set_one, &list}, 331 0, &GNUNET_GETOPT_set_one, &list},
332 {'e', "ego", "NAME",
333 gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -s)"),
334 1, &GNUNET_GETOPT_set_string, &set_ego},
245 {'m', "monitor", NULL, 335 {'m', "monitor", NULL,
246 gettext_noop ("run in monitor mode egos"), 336 gettext_noop ("run in monitor mode egos"),
247 0, &GNUNET_GETOPT_set_one, &monitor}, 337 0, &GNUNET_GETOPT_set_one, &monitor},
338 {'s', "set", "SUBSYSYSTEM",
339 gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"),
340 1, &GNUNET_GETOPT_set_string, &set_subsystem},
248 GNUNET_GETOPT_OPTION_END 341 GNUNET_GETOPT_OPTION_END
249 }; 342 };
250 343
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 502209b0f..033803978 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -427,11 +427,11 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
427 427
428/** 428/**
429 * @ingroup hash 429 * @ingroup hash
430 * Compute the distance between 2 hashcodes. 430 *
431 * The computation must be fast, not involve 431 * Compute the distance between 2 hashcodes. The
432 * a.a or a.e (they're used elsewhere), and 432 * computation must be fast, not involve a[0] or a[4] (they're used
433 * be somewhat consistent. And of course, the 433 * elsewhere), and be somewhat consistent. And of course, the result
434 * result should be a positive number. 434 * should be a positive number.
435 * 435 *
436 * @param a some hash code 436 * @param a some hash code
437 * @param b some hash code 437 * @param b some hash code
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 7784f2b5b..3c719a451 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -43,16 +43,16 @@ if HAVE_TESTING
43TESTING_TESTS = \ 43TESTING_TESTS = \
44 test_namestore_api \ 44 test_namestore_api \
45 test_namestore_api_remove 45 test_namestore_api_remove
46 #test_namestore_api_lookup \ 46#test_namestore_api_lookup
47 #test_namestore_api_lookup_specific_type \ 47#test_namestore_api_lookup_specific_type
48 #test_namestore_api_create \ 48#test_namestore_api_create
49 #test_namestore_api_create_update \ 49#test_namestore_api_create_update
50 #test_namestore_api_remove_not_existing_record \ 50#test_namestore_api_remove_not_existing_record
51 #test_namestore_api_zone_to_name \ 51#test_namestore_api_zone_to_name
52 #test_namestore_api_monitoring \ 52#test_namestore_api_monitoring
53 #test_namestore_api_zone_iteration \ 53#test_namestore_api_zone_iteration
54 #test_namestore_api_zone_iteration_specific_zone \ 54#test_namestore_api_zone_iteration_specific_zone
55 #test_namestore_api_zone_iteration_stop 55#test_namestore_api_zone_iteration_stop
56endif 56endif
57 57
58if HAVE_SQLITE 58if HAVE_SQLITE
@@ -115,6 +115,7 @@ gnunet_namestore_fcfsd_SOURCES = \
115 gnunet-namestore-fcfsd.c 115 gnunet-namestore-fcfsd.c
116gnunet_namestore_fcfsd_LDADD = -lmicrohttpd \ 116gnunet_namestore_fcfsd_LDADD = -lmicrohttpd \
117 $(top_builddir)/src/util/libgnunetutil.la \ 117 $(top_builddir)/src/util/libgnunetutil.la \
118 $(top_builddir)/src/identity/libgnunetidentity.la \
118 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 119 $(top_builddir)/src/namestore/libgnunetnamestore.la \
119 $(GN_LIBINTL) 120 $(GN_LIBINTL)
120gnunet_namestore_fcfsd_DEPENDENCIES = \ 121gnunet_namestore_fcfsd_DEPENDENCIES = \
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 */
196static struct GNUNET_CRYPTO_EccPrivateKey *fcfs_zone_pkey; 197static struct GNUNET_CRYPTO_EccPrivateKey fcfs_zone_pkey;
198
199/**
200 * Connection to identity service.
201 */
202static struct GNUNET_IDENTITY_Handle *identity;
203
204/**
205 * Request for our ego.
206 */
207static struct GNUNET_IDENTITY_Operation *id_op;
208
209/**
210 * Port we use for the HTTP server.
211 */
212static 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 */
918static void
919identity_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
887run (void *cls, char *const *args, const char *cfgfile, 962run (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 */
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c
index 42e8dad1e..b1197dc7e 100644
--- a/src/peerinfo/gnunet-service-peerinfo.c
+++ b/src/peerinfo/gnunet-service-peerinfo.c
@@ -516,7 +516,7 @@ struct DirScanContext
516 * @param cls pointer to 'unsigned int' to increment for each file, or NULL 516 * @param cls pointer to 'unsigned int' to increment for each file, or NULL
517 * if the file is from a read-only, read-once resource directory 517 * if the file is from a read-only, read-once resource directory
518 * @param fullname name of the file to parse 518 * @param fullname name of the file to parse
519 * @return GNUNET_OK (continue iteration) 519 * @return #GNUNET_OK (continue iteration)
520 */ 520 */
521static int 521static int
522hosts_directory_scan_callback (void *cls, const char *fullname) 522hosts_directory_scan_callback (void *cls, const char *fullname)