aboutsummaryrefslogtreecommitdiff
path: root/src/identity
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-17 20:26:02 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-17 20:26:02 +0000
commitaabe756fa2d764481c337060d27ff03c74b9e320 (patch)
tree4f0f5222a0e8cab9d7e99ca6a0f16c6752562472 /src/identity
parent4fbefa9b5336452df611c4f02232a45caa1d0e6f (diff)
downloadgnunet-aabe756fa2d764481c337060d27ff03c74b9e320.tar.gz
gnunet-aabe756fa2d764481c337060d27ff03c74b9e320.zip
-misc bugfixes and test-fixes
Diffstat (limited to 'src/identity')
-rw-r--r--src/identity/Makefile.am10
-rw-r--r--src/identity/gnunet-service-identity.c23
-rw-r--r--src/identity/identity_api.c12
-rw-r--r--src/identity/test_identity.c13
-rw-r--r--src/identity/test_identity.conf4
-rw-r--r--src/identity/test_identity_defaults.c93
6 files changed, 69 insertions, 86 deletions
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am
index e68debbc1..060345607 100644
--- a/src/identity/Makefile.am
+++ b/src/identity/Makefile.am
@@ -56,7 +56,8 @@ gnunet_service_identity_DEPENDENCIES = \
56 56
57if HAVE_TESTING 57if HAVE_TESTING
58check_PROGRAMS = \ 58check_PROGRAMS = \
59 test_identity 59 test_identity \
60 test_identity_defaults
60endif 61endif
61 62
62if ENABLE_TEST_RUN 63if ENABLE_TEST_RUN
@@ -70,6 +71,13 @@ test_identity_LDADD = \
70 $(top_builddir)/src/testing/libgnunettesting.la \ 71 $(top_builddir)/src/testing/libgnunettesting.la \
71 $(top_builddir)/src/util/libgnunetutil.la 72 $(top_builddir)/src/util/libgnunetutil.la
72 73
74test_identity_defaults_SOURCES = \
75 test_identity_defaults.c
76test_identity_defaults_LDADD = \
77 $(top_builddir)/src/identity/libgnunetidentity.la \
78 $(top_builddir)/src/testing/libgnunettesting.la \
79 $(top_builddir)/src/util/libgnunetutil.la
80
73 81
74EXTRA_DIST = \ 82EXTRA_DIST = \
75 test_identity.conf 83 test_identity.conf
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index fe6c3efa7..eeaa4e253 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -27,7 +27,6 @@
27 * represent the various egos/pseudonyms/identities of a GNUnet user. 27 * represent the various egos/pseudonyms/identities of a GNUnet user.
28 * 28 *
29 * Todo: 29 * Todo:
30 * - testcases
31 * - auto-initialze default egos; maybe trigger default 30 * - auto-initialze default egos; maybe trigger default
32 * initializations (such as gnunet-gns-import.sh?) 31 * initializations (such as gnunet-gns-import.sh?)
33 */ 32 */
@@ -320,8 +319,6 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
320 const char *name; 319 const char *name;
321 char *identifier; 320 char *identifier;
322 321
323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
324 "Received GET_DEFAULT message from client\n");
325 size = ntohs (message->size); 322 size = ntohs (message->size);
326 if (size <= sizeof (struct GNUNET_IDENTITY_GetDefaultMessage)) 323 if (size <= sizeof (struct GNUNET_IDENTITY_GetDefaultMessage))
327 { 324 {
@@ -340,6 +337,9 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
340 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 337 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
341 return; 338 return;
342 } 339 }
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Received GET_DEFAULT for service `%s' from client\n",
342 name);
343 if (GNUNET_OK != 343 if (GNUNET_OK !=
344 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg, 344 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
345 name, 345 name,
@@ -363,6 +363,9 @@ handle_get_default_message (void *cls, struct GNUNET_SERVER_Client *client,
363 return; 363 return;
364 } 364 }
365 } 365 }
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "Failed to find ego `%s'\n",
368 name);
366 send_result_code (client, 1, 369 send_result_code (client, 1,
367 gettext_noop ("default configured, but ego unknown (internal error)")); 370 gettext_noop ("default configured, but ego unknown (internal error)"));
368 GNUNET_SERVER_receive_done (client, GNUNET_OK); 371 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -409,8 +412,6 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
409 const char *str; 412 const char *str;
410 struct GNUNET_CRYPTO_EccPrivateKey *pk; 413 struct GNUNET_CRYPTO_EccPrivateKey *pk;
411 414
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Received SET_DEFAULT message from client\n");
414 size = ntohs (message->size); 415 size = ntohs (message->size);
415 if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) 416 if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage))
416 { 417 {
@@ -436,6 +437,9 @@ handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client,
436 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 437 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
437 return; 438 return;
438 } 439 }
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Received SET_DEFAULT for service `%s' from client\n",
442 str);
439 for (ego = ego_head; NULL != ego; ego = ego->next) 443 for (ego = ego_head; NULL != ego; ego = ego->next)
440 { 444 {
441 if (0 == key_cmp (ego->pk, 445 if (0 == key_cmp (ego->pk,
@@ -848,8 +852,10 @@ process_ego_file (void *cls,
848 filename); 852 filename);
849 return GNUNET_OK; 853 return GNUNET_OK;
850 } 854 }
851 855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
852 ego->identifier = GNUNET_strdup (fn); 856 "Loaded ego `%s'\n",
857 fn + 1);
858 ego->identifier = GNUNET_strdup (fn + 1);
853 GNUNET_CONTAINER_DLL_insert (ego_head, 859 GNUNET_CONTAINER_DLL_insert (ego_head,
854 ego_tail, 860 ego_tail,
855 ego); 861 ego);
@@ -904,6 +910,9 @@ run (void *cls,
904 GNUNET_SCHEDULER_shutdown (); 910 GNUNET_SCHEDULER_shutdown ();
905 return; 911 return;
906 } 912 }
913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
914 "Loading subsystem configuration `%s'\n",
915 subsystem_cfg_file);
907 subsystem_cfg = GNUNET_CONFIGURATION_create (); 916 subsystem_cfg = GNUNET_CONFIGURATION_create ();
908 if ( (GNUNET_YES == 917 if ( (GNUNET_YES ==
909 GNUNET_DISK_file_test (subsystem_cfg_file)) && 918 GNUNET_DISK_file_test (subsystem_cfg_file)) &&
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index e5c871bbe..54144c5bc 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -707,15 +707,15 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *id,
707 * 707 *
708 * @param id identity service to use 708 * @param id identity service to use
709 * @param identifier desired identifier 709 * @param identifier desired identifier
710 * @param cb function to call with the result (will only be called once) 710 * @param cont function to call with the result (will only be called once)
711 * @param cb_cls closure for cb 711 * @param cont_cls closure for cont
712 * @return handle to abort the operation 712 * @return handle to abort the operation
713 */ 713 */
714struct GNUNET_IDENTITY_Operation * 714struct GNUNET_IDENTITY_Operation *
715GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, 715GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
716 const char *identifier, 716 const char *identifier,
717 GNUNET_IDENTITY_Callback cb, 717 GNUNET_IDENTITY_Continuation cont,
718 void *cb_cls) 718 void *cont_cls)
719{ 719{
720 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc; 720 struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded *enc;
721 struct GNUNET_IDENTITY_Operation *op; 721 struct GNUNET_IDENTITY_Operation *op;
@@ -741,8 +741,8 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
741 sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) + 741 sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
742 enc_len + slen); 742 enc_len + slen);
743 op->h = id; 743 op->h = id;
744 op->cb = cb; 744 op->cont = cont;
745 op->cls = cb_cls; 745 op->cls = cont_cls;
746 crm = (struct GNUNET_IDENTITY_CreateRequestMessage *) &op[1]; 746 crm = (struct GNUNET_IDENTITY_CreateRequestMessage *) &op[1];
747 crm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_CREATE); 747 crm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
748 crm->header.size = htons (sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) + 748 crm->header.size = htons (sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) +
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index f97b469f4..60c6c2dad 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -226,19 +226,13 @@ success_rename_cont (void *cls,
226 * Called with events about created ego. 226 * Called with events about created ego.
227 * 227 *
228 * @param cls NULL 228 * @param cls NULL
229 * @param ego ego handle 229 * @param emsg error message
230 * @param ego_ctx context for application to store data for this ego
231 * (during the lifetime of this process, initially NULL)
232 * @param identifier identifier assigned by the user for this ego,
233 * NULL if the user just deleted the ego and it
234 * must thus no longer be used
235 */ 230 */
236static void 231static void
237create_cb (void *cls, 232create_cb (void *cls,
238 struct GNUNET_IDENTITY_Ego *ego, 233 const char *emsg)
239 void **ctx,
240 const char *identifier)
241{ 234{
235 GNUNET_assert (NULL == emsg);
242 op = GNUNET_IDENTITY_rename (h, 236 op = GNUNET_IDENTITY_rename (h,
243 "test-id", 237 "test-id",
244 "test", 238 "test",
@@ -274,6 +268,7 @@ run (void *cls,
274int 268int
275main (int argc, char *argv[]) 269main (int argc, char *argv[])
276{ 270{
271 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
277 res = 1; 272 res = 1;
278 if (0 != 273 if (0 !=
279 GNUNET_TESTING_service_run ("test-identity", 274 GNUNET_TESTING_service_run ("test-identity",
diff --git a/src/identity/test_identity.conf b/src/identity/test_identity.conf
index 3f57af93e..3349f6aa3 100644
--- a/src/identity/test_identity.conf
+++ b/src/identity/test_identity.conf
@@ -3,3 +3,7 @@ PORT = 12000
3DEFAULTSERVICES = identity 3DEFAULTSERVICES = identity
4UNIXPATH = /tmp/gnunet-p1-service-arm.sock 4UNIXPATH = /tmp/gnunet-p1-service-arm.sock
5 5
6[identity]
7# need to overwrite paths to ensure they stay the same between runs...
8EGODIR = /tmp/test-identity-service/egos/
9SUBSYSTEM_CFG = /tmp/test-identity-service/s.conf
diff --git a/src/identity/test_identity_defaults.c b/src/identity/test_identity_defaults.c
index c0b6efc50..2caf03a1e 100644
--- a/src/identity/test_identity_defaults.c
+++ b/src/identity/test_identity_defaults.c
@@ -119,58 +119,6 @@ end ()
119 119
120 120
121/** 121/**
122 * Called with events about egos.
123 *
124 * @param cls NULL
125 * @param ego ego handle
126 * @param ego_ctx context for application to store data for this ego
127 * (during the lifetime of this process, initially NULL)
128 * @param identifier identifier assigned by the user for this ego,
129 * NULL if the user just deleted the ego and it
130 * must thus no longer be used
131 */
132static void
133notification_cb (void *cls,
134 struct GNUNET_IDENTITY_Ego *ego,
135 void **ctx,
136 const char *identifier)
137{
138#if 0
139 static struct GNUNET_IDENTITY_Ego *my_ego;
140 static int round;
141
142 switch (round)
143 {
144 case 0: /* end of initial iteration */
145 GNUNET_assert (NULL == ego);
146 GNUNET_assert (NULL == identifier);
147 break;
148 case 1: /* create */
149 GNUNET_assert (NULL != ego);
150 GNUNET_assert (0 == strcmp (identifier, "test-id"));
151 my_ego = ego;
152 *ctx = &round;
153 break;
154 case 2: /* rename */
155 GNUNET_assert (my_ego == ego);
156 GNUNET_assert (0 == strcmp (identifier, "test"));
157 GNUNET_assert (*ctx == &round);
158 break;
159 case 3: /* delete */
160 GNUNET_assert (my_ego == ego);
161 GNUNET_assert (NULL == identifier);
162 GNUNET_assert (*ctx == &round);
163 *ctx = NULL;
164 break;
165 default:
166 GNUNET_break (0);
167 }
168 round++;
169#endif
170}
171
172
173/**
174 * Continuation called from successful delete operation. 122 * Continuation called from successful delete operation.
175 * 123 *
176 * @param cls NULL 124 * @param cls NULL
@@ -198,8 +146,8 @@ get_cb (void *cls,
198 void **ctx, 146 void **ctx,
199 const char *identifier) 147 const char *identifier)
200{ 148{
201 GNUNET_assert (NULL != emsg); 149 GNUNET_assert (NULL != ego);
202 GNUNET_assert (my_ego == ego); 150 GNUNET_assert (NULL != identifier);
203 GNUNET_assert (0 == strcmp (identifier, "test-id")); 151 GNUNET_assert (0 == strcmp (identifier, "test-id"));
204 op = GNUNET_IDENTITY_delete (h, 152 op = GNUNET_IDENTITY_delete (h,
205 "test-id", 153 "test-id",
@@ -222,7 +170,7 @@ run_get (void *cls,
222{ 170{
223 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 171 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
224 &endbadly, NULL); 172 &endbadly, NULL);
225 h = GNUNET_IDENTITY_connect (cfg, &notification_cb, NULL); 173 h = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
226 GNUNET_assert (NULL != h); 174 GNUNET_assert (NULL != h);
227 op = GNUNET_IDENTITY_get (h, 175 op = GNUNET_IDENTITY_get (h,
228 "test-service", 176 "test-service",
@@ -248,7 +196,7 @@ success_set_cont (void *cls,
248 196
249 197
250/** 198/**
251 * Called with events about created ego. 199 * Called with events about egos.
252 * 200 *
253 * @param cls NULL 201 * @param cls NULL
254 * @param ego ego handle 202 * @param ego ego handle
@@ -259,11 +207,13 @@ success_set_cont (void *cls,
259 * must thus no longer be used 207 * must thus no longer be used
260 */ 208 */
261static void 209static void
262create_cb (void *cls, 210notification_cb (void *cls,
263 struct GNUNET_IDENTITY_Ego *ego, 211 struct GNUNET_IDENTITY_Ego *ego,
264 void **ctx, 212 void **ctx,
265 const char *identifier) 213 const char *identifier)
266{ 214{
215 if (NULL == ego)
216 return; /* skip first call */
267 op = GNUNET_IDENTITY_set (h, 217 op = GNUNET_IDENTITY_set (h,
268 "test-service", 218 "test-service",
269 ego, 219 ego,
@@ -273,6 +223,21 @@ create_cb (void *cls,
273 223
274 224
275/** 225/**
226 * Called with events about created ego.
227 *
228 * @param cls NULL
229 * @param emsg error message
230 */
231static void
232create_cb (void *cls,
233 const char *emsg)
234{
235 GNUNET_assert (NULL == emsg);
236 op = NULL;
237}
238
239
240/**
276 * Main function of the test, run from scheduler. 241 * Main function of the test, run from scheduler.
277 * 242 *
278 * @param cls NULL 243 * @param cls NULL
@@ -299,21 +264,23 @@ run_set (void *cls,
299int 264int
300main (int argc, char *argv[]) 265main (int argc, char *argv[])
301{ 266{
267 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
302 res = 1; 268 res = 1;
303 if (0 != 269 if (0 !=
304 GNUNET_TESTING_service_run ("test-identity", 270 GNUNET_TESTING_service_run ("test-identity-defaults",
305 "identity", 271 "identity",
306 "test_identity.conf", 272 "test_identity.conf",
307 &run_set, 273 &run_set,
308 NULL)) 274 NULL))
309 return 1; 275 return 1;
310 if (0 != 276 if (0 !=
311 GNUNET_TESTING_service_run ("test-identity", 277 GNUNET_TESTING_service_run ("test-identity-defaults",
312 "identity", 278 "identity",
313 "test_identity.conf", 279 "test_identity.conf",
314 &run_get, 280 &run_get,
315 NULL)) 281 NULL))
316 return 1; 282 return 1;
283 GNUNET_DISK_directory_remove ("/tmp/test-identity-service");
317 return res; 284 return res;
318} 285}
319 286