aboutsummaryrefslogtreecommitdiff
path: root/src/identity-provider/gnunet-service-identity-provider.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
committerChristian Grothoff <christian@grothoff.org>2016-07-09 14:29:34 +0000
commit03374cc39814fa4bfb8d96e1165c688c44d8342f (patch)
treeed772250c49b39d82b9708ec8df0ee3e07e366d1 /src/identity-provider/gnunet-service-identity-provider.c
parent0c13a1e6fb0baffd83d413f313742a5f2b420297 (diff)
downloadgnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.tar.gz
gnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.zip
make namestore API less brittle/sublte to use
Diffstat (limited to 'src/identity-provider/gnunet-service-identity-provider.c')
-rw-r--r--src/identity-provider/gnunet-service-identity-provider.c186
1 files changed, 127 insertions, 59 deletions
diff --git a/src/identity-provider/gnunet-service-identity-provider.c b/src/identity-provider/gnunet-service-identity-provider.c
index 7a68fe902..228e6cdc5 100644
--- a/src/identity-provider/gnunet-service-identity-provider.c
+++ b/src/identity-provider/gnunet-service-identity-provider.c
@@ -531,6 +531,32 @@ clear_ego_attrs (void *cls,
531} 531}
532 532
533 533
534static void
535token_collect_error_cb (void *cls)
536{
537 // struct EgoEntry *ego_entry = cls;
538
539 GNUNET_assert (0); // FIXME: handle properly!
540}
541
542
543static void
544token_collect_finished_cb (void *cls)
545{
546 struct EgoEntry *ego_entry = cls;
547
548 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
549 ">>> Updating Ego finished\n");
550 //Clear attribute map for ego
551 GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
552 &clear_ego_attrs,
553 ego_entry);
554 GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
555 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
556 ego_entry->next);
557}
558
559
534/** 560/**
535 * 561 *
536 * Update all ID_TOKEN records for an identity and store them 562 * Update all ID_TOKEN records for an identity and store them
@@ -553,21 +579,6 @@ token_collect (void *cls,
553 const struct GNUNET_GNSRECORD_Data *token_metadata_record; 579 const struct GNUNET_GNSRECORD_Data *token_metadata_record;
554 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key; 580 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
555 581
556 if (NULL == lbl)
557 {
558 //Done
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 ">>> Updating Ego finished\n");
561 //Clear attribute map for ego
562 GNUNET_CONTAINER_multihashmap_iterate (ego_entry->attr_map,
563 &clear_ego_attrs,
564 ego_entry);
565 GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
566 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
567 ego_entry->next);
568 return;
569 }
570
571 //There should be only a single record for a token under a label 582 //There should be only a single record for a token under a label
572 if (2 != rd_count) 583 if (2 != rd_count)
573 { 584 {
@@ -614,6 +625,28 @@ token_collect (void *cls,
614} 625}
615 626
616 627
628static void
629attribute_collect_error_cb (void *cls)
630{
631 // struct EgoEntry *ego_entry = cls;
632
633 GNUNET_assert (0); // FIXME: handle properly!
634}
635
636
637static void
638attribute_collect_finished_cb (void *cls)
639{
640 struct EgoEntry *ego_entry = cls;
641
642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
643 ">>> Updating Attributes finished\n");
644 ego_entry->attributes_dirty = GNUNET_NO;
645 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
646 ego_entry);
647}
648
649
617/** 650/**
618 * 651 *
619 * Collect all ID_ATTR records for an identity and store them 652 * Collect all ID_ATTR records for an identity and store them
@@ -639,17 +672,6 @@ attribute_collect (void *cls,
639 char *val_str; 672 char *val_str;
640 int i; 673 int i;
641 674
642 if (NULL == lbl)
643 {
644 //Done
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 ">>> Updating Attributes finished\n");
647 ego_entry->attributes_dirty = GNUNET_NO;
648 update_task = GNUNET_SCHEDULER_add_now (&update_identities,
649 ego_entry);
650 return;
651 }
652
653 if (0 == rd_count) 675 if (0 == rd_count)
654 { 676 {
655 GNUNET_NAMESTORE_zone_iterator_next (ns_it); 677 GNUNET_NAMESTORE_zone_iterator_next (ns_it);
@@ -703,7 +725,6 @@ attribute_collect (void *cls,
703 attr, 725 attr,
704 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 726 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
705 GNUNET_NAMESTORE_zone_iterator_next (ns_it); 727 GNUNET_NAMESTORE_zone_iterator_next (ns_it);
706 return;
707} 728}
708 729
709/** 730/**
@@ -718,6 +739,7 @@ update_identities(void *cls)
718{ 739{
719 struct EgoEntry *next_ego = cls; 740 struct EgoEntry *next_ego = cls;
720 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 741 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
742
721 update_task = NULL; 743 update_task = NULL;
722 if (NULL == next_ego) 744 if (NULL == next_ego)
723 { 745 {
@@ -740,7 +762,11 @@ update_identities(void *cls)
740 //Starting over. We must update the Attributes for they might have changed. 762 //Starting over. We must update the Attributes for they might have changed.
741 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 763 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
742 priv_key, 764 priv_key,
765 &attribute_collect_error_cb,
766 next_ego,
743 &attribute_collect, 767 &attribute_collect,
768 next_ego,
769 &attribute_collect_finished_cb,
744 next_ego); 770 next_ego);
745 771
746 } 772 }
@@ -750,7 +776,11 @@ update_identities(void *cls)
750 next_ego->attributes_dirty = GNUNET_YES; 776 next_ego->attributes_dirty = GNUNET_YES;
751 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 777 ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
752 priv_key, 778 priv_key,
779 &token_collect_error_cb,
780 next_ego,
753 &token_collect, 781 &token_collect,
782 next_ego,
783 &token_collect_finished_cb,
754 next_ego); 784 next_ego);
755 } 785 }
756} 786}
@@ -939,7 +969,7 @@ store_token_issue_cont (void *cls,
939 struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm; 969 struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
940 char *ticket_str; 970 char *ticket_str;
941 char *token_str; 971 char *token_str;
942 972
943 handle->ns_qe = NULL; 973 handle->ns_qe = NULL;
944 if (GNUNET_SYSERR == success) 974 if (GNUNET_SYSERR == success)
945 { 975 {
@@ -1077,6 +1107,27 @@ sign_and_return_token (void *cls)
1077 GNUNET_free (token_metadata); 1107 GNUNET_free (token_metadata);
1078} 1108}
1079 1109
1110
1111static void
1112attr_collect_error (void *cls)
1113{
1114 // struct IssueHandle *handle = cls;
1115
1116 GNUNET_assert (0); // FIXME: handle error!
1117}
1118
1119
1120static void
1121attr_collect_finished (void *cls)
1122{
1123 struct IssueHandle *handle = cls;
1124
1125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
1126 handle->ns_it = NULL;
1127 GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
1128}
1129
1130
1080/** 1131/**
1081 * Collect attributes for token 1132 * Collect attributes for token
1082 */ 1133 */
@@ -1087,19 +1138,11 @@ attr_collect (void *cls,
1087 unsigned int rd_count, 1138 unsigned int rd_count,
1088 const struct GNUNET_GNSRECORD_Data *rd) 1139 const struct GNUNET_GNSRECORD_Data *rd)
1089{ 1140{
1141 struct IssueHandle *handle = cls;
1090 int i; 1142 int i;
1091 char* data; 1143 char* data;
1092 struct IssueHandle *handle = cls;
1093 struct GNUNET_HashCode key; 1144 struct GNUNET_HashCode key;
1094 1145
1095 if (NULL == label)
1096 {
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute END: \n");
1098 handle->ns_it = NULL;
1099 GNUNET_SCHEDULER_add_now (&sign_and_return_token, handle);
1100 return;
1101 }
1102
1103 GNUNET_CRYPTO_hash (label, 1146 GNUNET_CRYPTO_hash (label,
1104 strlen (label), 1147 strlen (label),
1105 &key); 1148 &key);
@@ -1278,6 +1321,41 @@ handle_exchange_message (void *cls,
1278} 1321}
1279 1322
1280 1323
1324static void
1325find_existing_token_error (void *cls)
1326{
1327 // struct IssueHandle *handle = cls;
1328
1329 GNUNET_assert (0); // FIXME: handle properly
1330}
1331
1332
1333static void
1334find_existing_token_finished (void *cls)
1335{
1336 struct IssueHandle *handle = cls;
1337 uint64_t rnd_key;
1338
1339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1340 ">>> No existing token found\n");
1341 rnd_key =
1342 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
1343 UINT64_MAX);
1344 GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
1345 sizeof (uint64_t),
1346 &handle->label);
1347 handle->ns_it = NULL;
1348 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1349 &handle->iss_key,
1350 &attr_collect_error,
1351 handle,
1352 &attr_collect,
1353 handle,
1354 &attr_collect_finished,
1355 handle);
1356}
1357
1358
1281/** 1359/**
1282 * 1360 *
1283 * Look for existing token 1361 * Look for existing token
@@ -1301,30 +1379,9 @@ find_existing_token (void *cls,
1301 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key; 1379 struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
1302 struct GNUNET_HashCode key; 1380 struct GNUNET_HashCode key;
1303 int scope_count_token; 1381 int scope_count_token;
1304 uint64_t rnd_key;
1305 char *scope; 1382 char *scope;
1306 char *tmp_scopes; 1383 char *tmp_scopes;
1307 1384
1308 if (NULL == lbl)
1309 {
1310 //Done
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1312 ">>> No existing token found\n");
1313 //Label
1314 rnd_key =
1315 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
1316 UINT64_MAX);
1317 GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
1318 sizeof (uint64_t),
1319 &handle->label);
1320 handle->ns_it = NULL;
1321 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1322 &handle->iss_key,
1323 &attr_collect,
1324 handle);
1325 return;
1326 }
1327
1328 //There should be only a single record for a token under a label 1385 //There should be only a single record for a token under a label
1329 if (2 != rd_count) 1386 if (2 != rd_count)
1330 { 1387 {
@@ -1335,7 +1392,9 @@ find_existing_token (void *cls,
1335 if (rd[0].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA) 1392 if (rd[0].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
1336 { 1393 {
1337 token_metadata_record = &rd[0]; 1394 token_metadata_record = &rd[0];
1338 } else { 1395 }
1396 else
1397 {
1339 token_metadata_record = &rd[1]; 1398 token_metadata_record = &rd[1];
1340 } 1399 }
1341 if (token_metadata_record->record_type != GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA) 1400 if (token_metadata_record->record_type != GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
@@ -1399,7 +1458,11 @@ find_existing_token (void *cls,
1399 handle->ns_it = NULL; 1458 handle->ns_it = NULL;
1400 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 1459 handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1401 &handle->iss_key, 1460 &handle->iss_key,
1461 &attr_collect_error,
1462 handle,
1402 &attr_collect, 1463 &attr_collect,
1464 handle,
1465 &attr_collect_finished,
1403 handle); 1466 handle);
1404 1467
1405 return; 1468 return;
@@ -1477,10 +1540,15 @@ handle_issue_message (void *cls,
1477 1540
1478 issue_handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle, 1541 issue_handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
1479 &im->iss_key, 1542 &im->iss_key,
1543 &find_existing_token_error,
1544 issue_handle,
1480 &find_existing_token, 1545 &find_existing_token,
1546 issue_handle,
1547 &find_existing_token_finished,
1481 issue_handle); 1548 issue_handle);
1482} 1549}
1483 1550
1551
1484/** 1552/**
1485 * Main function that will be run 1553 * Main function that will be run
1486 * 1554 *