aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/identity/gnunet-identity.c7
-rw-r--r--src/identity/identity_api.c337
2 files changed, 126 insertions, 218 deletions
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index 635c59efd..e22ac9106 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -327,7 +327,12 @@ run (void *cls,
327 fprintf (stderr, "Option -s requires option -e to be specified as well.\n"); 327 fprintf (stderr, "Option -s requires option -e to be specified as well.\n");
328 return; 328 return;
329 } 329 }
330 sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL); 330 sh = GNUNET_IDENTITY_connect (cfg,
331 (monitor | list) || (NULL != set_ego) ||
332 (NULL != set_subsystem)
333 ? &print_ego
334 : NULL,
335 NULL);
331 if (NULL != delete_ego) 336 if (NULL != delete_ego)
332 delete_op = 337 delete_op =
333 GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op); 338 GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op);
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index f16500ab5..6cf1b65ca 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -11,7 +11,7 @@
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 Affero 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 Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -30,7 +30,7 @@
30#include "gnunet_identity_service.h" 30#include "gnunet_identity_service.h"
31#include "identity.h" 31#include "identity.h"
32 32
33#define LOG(kind,...) GNUNET_log_from (kind, "identity-api",__VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__)
34 34
35/** 35/**
36 * Handle for an ego. 36 * Handle for an ego.
@@ -102,7 +102,7 @@ struct GNUNET_IDENTITY_Operation
102 * Private key to return to @e create_cont, or NULL. 102 * Private key to return to @e create_cont, or NULL.
103 */ 103 */
104 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; 104 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
105 105
106 /** 106 /**
107 * Continuation to invoke with the result of the transmission for 107 * Continuation to invoke with the result of the transmission for
108 * 'get' operations (@e cont and @a create_cont will be NULL in this case). 108 * 'get' operations (@e cont and @a create_cont will be NULL in this case).
@@ -113,7 +113,6 @@ struct GNUNET_IDENTITY_Operation
113 * Closure for @e cont or @e cb. 113 * Closure for @e cont or @e cb.
114 */ 114 */
115 void *cls; 115 void *cls;
116
117}; 116};
118 117
119 118
@@ -172,7 +171,6 @@ struct GNUNET_IDENTITY_Handle
172 * Are we polling for incoming messages right now? 171 * Are we polling for incoming messages right now?
173 */ 172 */
174 int in_receive; 173 int in_receive;
175
176}; 174};
177 175
178 176
@@ -189,12 +187,10 @@ GNUNET_IDENTITY_ego_get_anonymous ()
189 187
190 if (NULL != anon.pk) 188 if (NULL != anon.pk)
191 return &anon; 189 return &anon;
192 anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *) GNUNET_CRYPTO_ecdsa_key_get_anonymous (); 190 anon.pk = (struct GNUNET_CRYPTO_EcdsaPrivateKey *)
193 GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, 191 GNUNET_CRYPTO_ecdsa_key_get_anonymous ();
194 &pub); 192 GNUNET_CRYPTO_ecdsa_key_get_public (anon.pk, &pub);
195 GNUNET_CRYPTO_hash (&pub, 193 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &anon.id);
196 sizeof (pub),
197 &anon.id);
198 return &anon; 194 return &anon;
199} 195}
200 196
@@ -217,24 +213,17 @@ reconnect (void *cls);
217 * @return #GNUNET_OK (continue to iterate) 213 * @return #GNUNET_OK (continue to iterate)
218 */ 214 */
219static int 215static int
220free_ego (void *cls, 216free_ego (void *cls, const struct GNUNET_HashCode *key, void *value)
221 const struct GNUNET_HashCode *key,
222 void *value)
223{ 217{
224 struct GNUNET_IDENTITY_Handle *h = cls; 218 struct GNUNET_IDENTITY_Handle *h = cls;
225 struct GNUNET_IDENTITY_Ego *ego = value; 219 struct GNUNET_IDENTITY_Ego *ego = value;
226 220
227 if (NULL != h->cb) 221 if (NULL != h->cb)
228 h->cb (h->cb_cls, 222 h->cb (h->cb_cls, ego, &ego->ctx, NULL);
229 ego,
230 &ego->ctx,
231 NULL);
232 GNUNET_free (ego->pk); 223 GNUNET_free (ego->pk);
233 GNUNET_free (ego->name); 224 GNUNET_free (ego->name);
234 GNUNET_assert (GNUNET_YES == 225 GNUNET_assert (GNUNET_YES ==
235 GNUNET_CONTAINER_multihashmap_remove (h->egos, 226 GNUNET_CONTAINER_multihashmap_remove (h->egos, key, value));
236 key,
237 value));
238 GNUNET_free (ego); 227 GNUNET_free (ego);
239 return GNUNET_OK; 228 return GNUNET_OK;
240} 229}
@@ -259,35 +248,24 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
259 } 248 }
260 while (NULL != (op = h->op_head)) 249 while (NULL != (op = h->op_head))
261 { 250 {
262 GNUNET_CONTAINER_DLL_remove (h->op_head, 251 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
263 h->op_tail,
264 op);
265 if (NULL != op->cont) 252 if (NULL != op->cont)
266 op->cont (op->cls, 253 op->cont (op->cls, "Error in communication with the identity service");
267 "Error in communication with the identity service");
268 else if (NULL != op->cb) 254 else if (NULL != op->cb)
269 op->cb (op->cls, 255 op->cb (op->cls, NULL, NULL, NULL);
270 NULL,
271 NULL,
272 NULL);
273 else if (NULL != op->create_cont) 256 else if (NULL != op->create_cont)
274 op->create_cont (op->cls, 257 op->create_cont (op->cls,
275 NULL, 258 NULL,
276 "Failed to communicate with the identity service"); 259 "Failed to communicate with the identity service");
277 GNUNET_free_non_null (op->pk); 260 GNUNET_free_non_null (op->pk);
278 GNUNET_free (op); 261 GNUNET_free (op);
279 } 262 }
280 GNUNET_CONTAINER_multihashmap_iterate (h->egos, 263 GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h);
281 &free_ego,
282 h);
283 LOG (GNUNET_ERROR_TYPE_DEBUG, 264 LOG (GNUNET_ERROR_TYPE_DEBUG,
284 "Scheduling task to reconnect to identity service in %s.\n", 265 "Scheduling task to reconnect to identity service in %s.\n",
285 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, 266 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES));
286 GNUNET_YES));
287 h->reconnect_task = 267 h->reconnect_task =
288 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, 268 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
289 &reconnect,
290 h);
291 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); 269 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
292} 270}
293 271
@@ -301,8 +279,7 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
301 * @param error error code 279 * @param error error code
302 */ 280 */
303static void 281static void
304mq_error_handler (void *cls, 282mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
305 enum GNUNET_MQ_Error error)
306{ 283{
307 struct GNUNET_IDENTITY_Handle *h = cls; 284 struct GNUNET_IDENTITY_Handle *h = cls;
308 285
@@ -319,8 +296,7 @@ mq_error_handler (void *cls,
319 * @return #GNUNET_OK if the message is well-formed 296 * @return #GNUNET_OK if the message is well-formed
320 */ 297 */
321static int 298static int
322check_identity_result_code (void *cls, 299check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
323 const struct ResultCodeMessage *rcm)
324{ 300{
325 uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm); 301 uint16_t size = ntohs (rcm->header.size) - sizeof (*rcm);
326 const char *str = (const char *) &rcm[1]; 302 const char *str = (const char *) &rcm[1];
@@ -343,8 +319,7 @@ check_identity_result_code (void *cls,
343 * @param rcm result message received 319 * @param rcm result message received
344 */ 320 */
345static void 321static void
346handle_identity_result_code (void *cls, 322handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
347 const struct ResultCodeMessage *rcm)
348{ 323{
349 struct GNUNET_IDENTITY_Handle *h = cls; 324 struct GNUNET_IDENTITY_Handle *h = cls;
350 struct GNUNET_IDENTITY_Operation *op; 325 struct GNUNET_IDENTITY_Operation *op;
@@ -358,18 +333,13 @@ handle_identity_result_code (void *cls,
358 reschedule_connect (h); 333 reschedule_connect (h);
359 return; 334 return;
360 } 335 }
361 GNUNET_CONTAINER_DLL_remove (h->op_head, 336 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
362 h->op_tail,
363 op);
364 if (NULL != op->cont) 337 if (NULL != op->cont)
365 op->cont (op->cls, 338 op->cont (op->cls, str);
366 str);
367 else if (NULL != op->cb) 339 else if (NULL != op->cb)
368 op->cb (op->cls, NULL, NULL, NULL); 340 op->cb (op->cls, NULL, NULL, NULL);
369 else if (NULL != op->create_cont) 341 else if (NULL != op->create_cont)
370 op->create_cont (op->cls, 342 op->create_cont (op->cls, (NULL == str) ? op->pk : NULL, str);
371 (NULL == str) ? op->pk : NULL,
372 str);
373 GNUNET_free_non_null (op->pk); 343 GNUNET_free_non_null (op->pk);
374 GNUNET_free (op); 344 GNUNET_free (op);
375} 345}
@@ -383,16 +353,14 @@ handle_identity_result_code (void *cls,
383 * @return #GNUNET_OK if the message is well-formed 353 * @return #GNUNET_OK if the message is well-formed
384 */ 354 */
385static int 355static int
386check_identity_update (void *cls, 356check_identity_update (void *cls, const struct UpdateMessage *um)
387 const struct UpdateMessage *um)
388{ 357{
389 uint16_t size = ntohs (um->header.size); 358 uint16_t size = ntohs (um->header.size);
390 uint16_t name_len = ntohs (um->name_len); 359 uint16_t name_len = ntohs (um->name_len);
391 const char *str = (const char *) &um[1]; 360 const char *str = (const char *) &um[1];
392 361
393 if ( (size != name_len + sizeof (struct UpdateMessage)) || 362 if ((size != name_len + sizeof (struct UpdateMessage)) ||
394 ( (0 != name_len) && 363 ((0 != name_len) && ('\0' != str[name_len - 1])))
395 ('\0' != str[name_len - 1])) )
396 { 364 {
397 GNUNET_break (0); 365 GNUNET_break (0);
398 return GNUNET_SYSERR; 366 return GNUNET_SYSERR;
@@ -408,8 +376,7 @@ check_identity_update (void *cls,
408 * @param um message received 376 * @param um message received
409 */ 377 */
410static void 378static void
411handle_identity_update (void *cls, 379handle_identity_update (void *cls, const struct UpdateMessage *um)
412 const struct UpdateMessage *um)
413{ 380{
414 struct GNUNET_IDENTITY_Handle *h = cls; 381 struct GNUNET_IDENTITY_Handle *h = cls;
415 uint16_t name_len = ntohs (um->name_len); 382 uint16_t name_len = ntohs (um->name_len);
@@ -422,19 +389,12 @@ handle_identity_update (void *cls,
422 { 389 {
423 /* end of initial list of data */ 390 /* end of initial list of data */
424 if (NULL != h->cb) 391 if (NULL != h->cb)
425 h->cb (h->cb_cls, 392 h->cb (h->cb_cls, NULL, NULL, NULL);
426 NULL,
427 NULL,
428 NULL);
429 return; 393 return;
430 } 394 }
431 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, 395 GNUNET_CRYPTO_ecdsa_key_get_public (&um->private_key, &pub);
432 &pub); 396 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
433 GNUNET_CRYPTO_hash (&pub, 397 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
434 sizeof (pub),
435 &id);
436 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
437 &id);
438 if (NULL == ego) 398 if (NULL == ego)
439 { 399 {
440 /* ego was created */ 400 /* ego was created */
@@ -451,18 +411,18 @@ handle_identity_update (void *cls,
451 ego->name = GNUNET_strdup (str); 411 ego->name = GNUNET_strdup (str);
452 ego->id = id; 412 ego->id = id;
453 GNUNET_assert (GNUNET_YES == 413 GNUNET_assert (GNUNET_YES ==
454 GNUNET_CONTAINER_multihashmap_put (h->egos, 414 GNUNET_CONTAINER_multihashmap_put (
455 &ego->id, 415 h->egos,
456 ego, 416 &ego->id,
457 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 417 ego,
418 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
458 } 419 }
459 if (NULL == str) 420 if (NULL == str)
460 { 421 {
461 /* ego was deleted */ 422 /* ego was deleted */
462 GNUNET_assert (GNUNET_YES == 423 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (h->egos,
463 GNUNET_CONTAINER_multihashmap_remove (h->egos, 424 &ego->id,
464 &ego->id, 425 ego));
465 ego));
466 } 426 }
467 else 427 else
468 { 428 {
@@ -472,10 +432,7 @@ handle_identity_update (void *cls,
472 } 432 }
473 /* inform application about change */ 433 /* inform application about change */
474 if (NULL != h->cb) 434 if (NULL != h->cb)
475 h->cb (h->cb_cls, 435 h->cb (h->cb_cls, ego, &ego->ctx, str);
476 ego,
477 &ego->ctx,
478 str);
479 /* complete deletion */ 436 /* complete deletion */
480 if (NULL == str) 437 if (NULL == str)
481 { 438 {
@@ -495,16 +452,13 @@ handle_identity_update (void *cls,
495 * @return #GNUNET_OK if the message is well-formed 452 * @return #GNUNET_OK if the message is well-formed
496 */ 453 */
497static int 454static int
498check_identity_set_default (void *cls, 455check_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
499 const struct SetDefaultMessage *sdm)
500{ 456{
501 uint16_t size = ntohs (sdm->header.size) - sizeof (*sdm); 457 uint16_t size = ntohs (sdm->header.size) - sizeof (*sdm);
502 uint16_t name_len = ntohs (sdm->name_len); 458 uint16_t name_len = ntohs (sdm->name_len);
503 const char *str = (const char *) &sdm[1]; 459 const char *str = (const char *) &sdm[1];
504 460
505 if ( (size != name_len) || 461 if ((size != name_len) || ((0 != name_len) && ('\0' != str[name_len - 1])))
506 ( (0 != name_len) &&
507 ('\0' != str[name_len - 1]) ) )
508 { 462 {
509 GNUNET_break (0); 463 GNUNET_break (0);
510 return GNUNET_SYSERR; 464 return GNUNET_SYSERR;
@@ -522,8 +476,7 @@ check_identity_set_default (void *cls,
522 * @param sdm message received 476 * @param sdm message received
523 */ 477 */
524static void 478static void
525handle_identity_set_default (void *cls, 479handle_identity_set_default (void *cls, const struct SetDefaultMessage *sdm)
526 const struct SetDefaultMessage *sdm)
527{ 480{
528 struct GNUNET_IDENTITY_Handle *h = cls; 481 struct GNUNET_IDENTITY_Handle *h = cls;
529 struct GNUNET_IDENTITY_Operation *op; 482 struct GNUNET_IDENTITY_Operation *op;
@@ -531,13 +484,9 @@ handle_identity_set_default (void *cls,
531 struct GNUNET_HashCode id; 484 struct GNUNET_HashCode id;
532 struct GNUNET_IDENTITY_Ego *ego; 485 struct GNUNET_IDENTITY_Ego *ego;
533 486
534 GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, 487 GNUNET_CRYPTO_ecdsa_key_get_public (&sdm->private_key, &pub);
535 &pub); 488 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &id);
536 GNUNET_CRYPTO_hash (&pub, 489 ego = GNUNET_CONTAINER_multihashmap_get (h->egos, &id);
537 sizeof (pub),
538 &id);
539 ego = GNUNET_CONTAINER_multihashmap_get (h->egos,
540 &id);
541 if (NULL == ego) 490 if (NULL == ego)
542 { 491 {
543 GNUNET_break (0); 492 GNUNET_break (0);
@@ -553,14 +502,9 @@ handle_identity_set_default (void *cls,
553 } 502 }
554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
555 "Received SET_DEFAULT message from identity service\n"); 504 "Received SET_DEFAULT message from identity service\n");
556 GNUNET_CONTAINER_DLL_remove (h->op_head, 505 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
557 h->op_tail,
558 op);
559 if (NULL != op->cb) 506 if (NULL != op->cb)
560 op->cb (op->cls, 507 op->cb (op->cls, ego, &ego->ctx, ego->name);
561 ego,
562 &ego->ctx,
563 ego->name);
564 GNUNET_free (op); 508 GNUNET_free (op);
565} 509}
566 510
@@ -574,39 +518,35 @@ static void
574reconnect (void *cls) 518reconnect (void *cls)
575{ 519{
576 struct GNUNET_IDENTITY_Handle *h = cls; 520 struct GNUNET_IDENTITY_Handle *h = cls;
577 struct GNUNET_MQ_MessageHandler handlers[] = { 521 struct GNUNET_MQ_MessageHandler handlers[] =
578 GNUNET_MQ_hd_var_size (identity_result_code, 522 {GNUNET_MQ_hd_var_size (identity_result_code,
579 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, 523 GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE,
580 struct ResultCodeMessage, 524 struct ResultCodeMessage,
581 h), 525 h),
582 GNUNET_MQ_hd_var_size (identity_update, 526 GNUNET_MQ_hd_var_size (identity_update,
583 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, 527 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE,
584 struct UpdateMessage, 528 struct UpdateMessage,
585 h), 529 h),
586 GNUNET_MQ_hd_var_size (identity_set_default, 530 GNUNET_MQ_hd_var_size (identity_set_default,
587 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 531 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
588 struct SetDefaultMessage, 532 struct SetDefaultMessage,
589 h), 533 h),
590 GNUNET_MQ_handler_end () 534 GNUNET_MQ_handler_end ()};
591 };
592 struct GNUNET_MQ_Envelope *env; 535 struct GNUNET_MQ_Envelope *env;
593 struct GNUNET_MessageHeader *msg; 536 struct GNUNET_MessageHeader *msg;
594 537
595 h->reconnect_task = NULL; 538 h->reconnect_task = NULL;
596 LOG (GNUNET_ERROR_TYPE_DEBUG, 539 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to identity service.\n");
597 "Connecting to identity service.\n");
598 GNUNET_assert (NULL == h->mq); 540 GNUNET_assert (NULL == h->mq);
599 h->mq = GNUNET_CLIENT_connect (h->cfg, 541 h->mq =
600 "identity", 542 GNUNET_CLIENT_connect (h->cfg, "identity", handlers, &mq_error_handler, h);
601 handlers,
602 &mq_error_handler,
603 h);
604 if (NULL == h->mq) 543 if (NULL == h->mq)
605 return; 544 return;
606 env = GNUNET_MQ_msg (msg, 545 if (NULL != h->cb)
607 GNUNET_MESSAGE_TYPE_IDENTITY_START); 546 {
608 GNUNET_MQ_send (h->mq, 547 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_IDENTITY_START);
609 env); 548 GNUNET_MQ_send (h->mq, env);
549 }
610} 550}
611 551
612 552
@@ -620,8 +560,8 @@ reconnect (void *cls)
620 */ 560 */
621struct GNUNET_IDENTITY_Handle * 561struct GNUNET_IDENTITY_Handle *
622GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 562GNUNET_IDENTITY_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
623 GNUNET_IDENTITY_Callback cb, 563 GNUNET_IDENTITY_Callback cb,
624 void *cb_cls) 564 void *cb_cls)
625{ 565{
626 struct GNUNET_IDENTITY_Handle *h; 566 struct GNUNET_IDENTITY_Handle *h;
627 567
@@ -661,10 +601,9 @@ GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego)
661 */ 601 */
662void 602void
663GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego, 603GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
664 struct GNUNET_CRYPTO_EcdsaPublicKey *pk) 604 struct GNUNET_CRYPTO_EcdsaPublicKey *pk)
665{ 605{
666 GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, 606 GNUNET_CRYPTO_ecdsa_key_get_public (ego->pk, pk);
667 pk);
668} 607}
669 608
670 609
@@ -680,9 +619,9 @@ GNUNET_IDENTITY_ego_get_public_key (const struct GNUNET_IDENTITY_Ego *ego,
680 */ 619 */
681struct GNUNET_IDENTITY_Operation * 620struct GNUNET_IDENTITY_Operation *
682GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h, 621GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
683 const char *service_name, 622 const char *service_name,
684 GNUNET_IDENTITY_Callback cb, 623 GNUNET_IDENTITY_Callback cb,
685 void *cb_cls) 624 void *cb_cls)
686{ 625{
687 struct GNUNET_IDENTITY_Operation *op; 626 struct GNUNET_IDENTITY_Operation *op;
688 struct GNUNET_MQ_Envelope *env; 627 struct GNUNET_MQ_Envelope *env;
@@ -701,19 +640,13 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
701 op->h = h; 640 op->h = h;
702 op->cb = cb; 641 op->cb = cb;
703 op->cls = cb_cls; 642 op->cls = cb_cls;
704 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 643 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
705 h->op_tail, 644 env =
706 op); 645 GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT);
707 env = GNUNET_MQ_msg_extra (gdm,
708 slen,
709 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT);
710 gdm->name_len = htons (slen); 646 gdm->name_len = htons (slen);
711 gdm->reserved = htons (0); 647 gdm->reserved = htons (0);
712 GNUNET_memcpy (&gdm[1], 648 GNUNET_memcpy (&gdm[1], service_name, slen);
713 service_name, 649 GNUNET_MQ_send (h->mq, env);
714 slen);
715 GNUNET_MQ_send (h->mq,
716 env);
717 return op; 650 return op;
718} 651}
719 652
@@ -730,10 +663,10 @@ GNUNET_IDENTITY_get (struct GNUNET_IDENTITY_Handle *h,
730 */ 663 */
731struct GNUNET_IDENTITY_Operation * 664struct GNUNET_IDENTITY_Operation *
732GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h, 665GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
733 const char *service_name, 666 const char *service_name,
734 struct GNUNET_IDENTITY_Ego *ego, 667 struct GNUNET_IDENTITY_Ego *ego,
735 GNUNET_IDENTITY_Continuation cont, 668 GNUNET_IDENTITY_Continuation cont,
736 void *cont_cls) 669 void *cont_cls)
737{ 670{
738 struct GNUNET_IDENTITY_Operation *op; 671 struct GNUNET_IDENTITY_Operation *op;
739 struct GNUNET_MQ_Envelope *env; 672 struct GNUNET_MQ_Envelope *env;
@@ -752,20 +685,14 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
752 op->h = h; 685 op->h = h;
753 op->cont = cont; 686 op->cont = cont;
754 op->cls = cont_cls; 687 op->cls = cont_cls;
755 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 688 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
756 h->op_tail, 689 env =
757 op); 690 GNUNET_MQ_msg_extra (sdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
758 env = GNUNET_MQ_msg_extra (sdm,
759 slen,
760 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
761 sdm->name_len = htons (slen); 691 sdm->name_len = htons (slen);
762 sdm->reserved = htons (0); 692 sdm->reserved = htons (0);
763 sdm->private_key = *ego->pk; 693 sdm->private_key = *ego->pk;
764 GNUNET_memcpy (&sdm[1], 694 GNUNET_memcpy (&sdm[1], service_name, slen);
765 service_name, 695 GNUNET_MQ_send (h->mq, env);
766 slen);
767 GNUNET_MQ_send (h->mq,
768 env);
769 return op; 696 return op;
770} 697}
771 698
@@ -781,9 +708,9 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
781 */ 708 */
782struct GNUNET_IDENTITY_Operation * 709struct GNUNET_IDENTITY_Operation *
783GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h, 710GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
784 const char *name, 711 const char *name,
785 GNUNET_IDENTITY_CreateContinuation cont, 712 GNUNET_IDENTITY_CreateContinuation cont,
786 void *cont_cls) 713 void *cont_cls)
787{ 714{
788 struct GNUNET_IDENTITY_Operation *op; 715 struct GNUNET_IDENTITY_Operation *op;
789 struct GNUNET_MQ_Envelope *env; 716 struct GNUNET_MQ_Envelope *env;
@@ -803,22 +730,15 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
803 op->h = h; 730 op->h = h;
804 op->create_cont = cont; 731 op->create_cont = cont;
805 op->cls = cont_cls; 732 op->cls = cont_cls;
806 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 733 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
807 h->op_tail, 734 env = GNUNET_MQ_msg_extra (crm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
808 op);
809 env = GNUNET_MQ_msg_extra (crm,
810 slen,
811 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE);
812 crm->name_len = htons (slen); 735 crm->name_len = htons (slen);
813 crm->reserved = htons (0); 736 crm->reserved = htons (0);
814 pk = GNUNET_CRYPTO_ecdsa_key_create (); 737 pk = GNUNET_CRYPTO_ecdsa_key_create ();
815 crm->private_key = *pk; 738 crm->private_key = *pk;
816 op->pk = pk; 739 op->pk = pk;
817 GNUNET_memcpy (&crm[1], 740 GNUNET_memcpy (&crm[1], name, slen);
818 name, 741 GNUNET_MQ_send (h->mq, env);
819 slen);
820 GNUNET_MQ_send (h->mq,
821 env);
822 return op; 742 return op;
823} 743}
824 744
@@ -835,10 +755,10 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
835 */ 755 */
836struct GNUNET_IDENTITY_Operation * 756struct GNUNET_IDENTITY_Operation *
837GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h, 757GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
838 const char *old_name, 758 const char *old_name,
839 const char *new_name, 759 const char *new_name,
840 GNUNET_IDENTITY_Continuation cb, 760 GNUNET_IDENTITY_Continuation cb,
841 void *cb_cls) 761 void *cb_cls)
842{ 762{
843 struct GNUNET_IDENTITY_Operation *op; 763 struct GNUNET_IDENTITY_Operation *op;
844 struct GNUNET_MQ_Envelope *env; 764 struct GNUNET_MQ_Envelope *env;
@@ -851,9 +771,10 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
851 return NULL; 771 return NULL;
852 slen_old = strlen (old_name) + 1; 772 slen_old = strlen (old_name) + 1;
853 slen_new = strlen (new_name) + 1; 773 slen_new = strlen (new_name) + 1;
854 if ( (slen_old >= GNUNET_MAX_MESSAGE_SIZE) || 774 if ((slen_old >= GNUNET_MAX_MESSAGE_SIZE) ||
855 (slen_new >= GNUNET_MAX_MESSAGE_SIZE) || 775 (slen_new >= GNUNET_MAX_MESSAGE_SIZE) ||
856 (slen_old + slen_new >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct RenameMessage)) ) 776 (slen_old + slen_new >=
777 GNUNET_MAX_MESSAGE_SIZE - sizeof (struct RenameMessage)))
857 { 778 {
858 GNUNET_break (0); 779 GNUNET_break (0);
859 return NULL; 780 return NULL;
@@ -862,23 +783,16 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
862 op->h = h; 783 op->h = h;
863 op->cont = cb; 784 op->cont = cb;
864 op->cls = cb_cls; 785 op->cls = cb_cls;
865 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 786 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
866 h->op_tail,
867 op);
868 env = GNUNET_MQ_msg_extra (grm, 787 env = GNUNET_MQ_msg_extra (grm,
869 slen_old + slen_new, 788 slen_old + slen_new,
870 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME); 789 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME);
871 grm->old_name_len = htons (slen_old); 790 grm->old_name_len = htons (slen_old);
872 grm->new_name_len = htons (slen_new); 791 grm->new_name_len = htons (slen_new);
873 dst = (char *) &grm[1]; 792 dst = (char *) &grm[1];
874 GNUNET_memcpy (dst, 793 GNUNET_memcpy (dst, old_name, slen_old);
875 old_name, 794 GNUNET_memcpy (&dst[slen_old], new_name, slen_new);
876 slen_old); 795 GNUNET_MQ_send (h->mq, env);
877 GNUNET_memcpy (&dst[slen_old],
878 new_name,
879 slen_new);
880 GNUNET_MQ_send (h->mq,
881 env);
882 return op; 796 return op;
883} 797}
884 798
@@ -894,9 +808,9 @@ GNUNET_IDENTITY_rename (struct GNUNET_IDENTITY_Handle *h,
894 */ 808 */
895struct GNUNET_IDENTITY_Operation * 809struct GNUNET_IDENTITY_Operation *
896GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h, 810GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h,
897 const char *name, 811 const char *name,
898 GNUNET_IDENTITY_Continuation cb, 812 GNUNET_IDENTITY_Continuation cb,
899 void *cb_cls) 813 void *cb_cls)
900{ 814{
901 struct GNUNET_IDENTITY_Operation *op; 815 struct GNUNET_IDENTITY_Operation *op;
902 struct GNUNET_MQ_Envelope *env; 816 struct GNUNET_MQ_Envelope *env;
@@ -915,19 +829,12 @@ GNUNET_IDENTITY_delete (struct GNUNET_IDENTITY_Handle *h,
915 op->h = h; 829 op->h = h;
916 op->cont = cb; 830 op->cont = cb;
917 op->cls = cb_cls; 831 op->cls = cb_cls;
918 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, 832 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, op);
919 h->op_tail, 833 env = GNUNET_MQ_msg_extra (gdm, slen, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE);
920 op);
921 env = GNUNET_MQ_msg_extra (gdm,
922 slen,
923 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE);
924 gdm->name_len = htons (slen); 834 gdm->name_len = htons (slen);
925 gdm->reserved = htons (0); 835 gdm->reserved = htons (0);
926 GNUNET_memcpy (&gdm[1], 836 GNUNET_memcpy (&gdm[1], name, slen);
927 name, 837 GNUNET_MQ_send (h->mq, env);
928 slen);
929 GNUNET_MQ_send (h->mq,
930 env);
931 return op; 838 return op;
932} 839}
933 840
@@ -972,18 +879,14 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h)
972 } 879 }
973 if (NULL != h->egos) 880 if (NULL != h->egos)
974 { 881 {
975 GNUNET_CONTAINER_multihashmap_iterate (h->egos, 882 GNUNET_CONTAINER_multihashmap_iterate (h->egos, &free_ego, h);
976 &free_ego,
977 h);
978 GNUNET_CONTAINER_multihashmap_destroy (h->egos); 883 GNUNET_CONTAINER_multihashmap_destroy (h->egos);
979 h->egos = NULL; 884 h->egos = NULL;
980 } 885 }
981 while (NULL != (op = h->op_head)) 886 while (NULL != (op = h->op_head))
982 { 887 {
983 GNUNET_break (NULL == op->cont); 888 GNUNET_break (NULL == op->cont);
984 GNUNET_CONTAINER_DLL_remove (h->op_head, 889 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
985 h->op_tail,
986 op);
987 GNUNET_free_non_null (op->pk); 890 GNUNET_free_non_null (op->pk);
988 GNUNET_free (op); 891 GNUNET_free (op);
989 } 892 }