aboutsummaryrefslogtreecommitdiff
path: root/src/credential/gnunet-service-credential.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r--src/credential/gnunet-service-credential.c193
1 files changed, 179 insertions, 14 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 41f4f64d6..9de16bf72 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -243,6 +243,11 @@ struct DelegationSetQueueEntry
243 * The delegation chain entry 243 * The delegation chain entry
244 */ 244 */
245 struct DelegationChainEntry *delegation_chain_entry; 245 struct DelegationChainEntry *delegation_chain_entry;
246
247 /**
248 * True if added by backward resolution
249 */
250 bool from_bw;
246}; 251};
247 252
248 253
@@ -369,6 +374,10 @@ static struct GNUNET_STATISTICS_Handle *statistics;
369 */ 374 */
370static struct GNUNET_GNS_Handle *gns; 375static struct GNUNET_GNS_Handle *gns;
371 376
377//TODO vrh dependent
378static struct DelegationSetQueueEntry *dsq_head;
379static struct DelegationSetQueueEntry *dsq_tail;
380
372 381
373/** 382/**
374 * Handle to namestore service 383 * Handle to namestore service
@@ -564,7 +573,8 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
564 573
565 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env); 574 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env);
566 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh); 575 GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
567 cleanup_handle (vrh); 576 //TODO fix cleanup with bidirectional
577 //cleanup_handle (vrh);
568 578
569 GNUNET_STATISTICS_update (statistics, 579 GNUNET_STATISTICS_update (statistics,
570 "Completed verifications", 580 "Completed verifications",
@@ -806,6 +816,42 @@ forward_resolution (void *cls,
806 } 816 }
807 } 817 }
808 818
819 // TODO testing area
820
821 // Check list
822 for (struct DelegationSetQueueEntry *del_entry = dsq_head;
823 del_entry != NULL;
824 del_entry = del_entry->next)
825 {
826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"--fw-------- %s.%s <- %s.%s\n",
827 GNUNET_CRYPTO_ecdsa_public_key_to_string(&del_entry->delegation_chain_entry->issuer_key),
828 del_entry->delegation_chain_entry->issuer_attribute,
829 GNUNET_CRYPTO_ecdsa_public_key_to_string(&del_entry->delegation_chain_entry->subject_key),
830 del_entry->delegation_chain_entry->subject_attribute);
831
832 // only check entries not added by forward algorithm
833 if(del_entry->from_bw)
834 {
835 // key of list entry matches actual key
836 if (0 == memcmp (&del_entry->delegation_chain_entry->subject_key,
837 &ds_entry->delegation_chain_entry->issuer_key,
838 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
839 {
840 // compare entry subject attributes to this trailer (iss attr + old trailer)
841 if (0 == strcmp (del_entry->delegation_chain_entry->subject_attribute,
842 ds_entry->attr_trailer))
843 {
844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"--fw-------- Found match with above!\n");
845 send_lookup_response (vrh);
846 return;
847 }
848 }
849 }
850 }
851 // No crossmatch/bidirectional result, add this ds_entry for the bw algo to match
852 ds_entry->from_bw = false;
853 GNUNET_CONTAINER_DLL_insert (dsq_head, dsq_tail, ds_entry);
854
809 // Starting a new GNS lookup 855 // Starting a new GNS lookup
810 vrh->pending_lookups++; 856 vrh->pending_lookups++;
811 ds_entry->handle = vrh; 857 ds_entry->handle = vrh;
@@ -833,6 +879,17 @@ forward_resolution (void *cls,
833} 879}
834 880
835static void 881static void
882print_deleset(struct DelegationSetQueueEntry *dsentry, char* text)
883{
884 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"%s %s.%s <- %s.%s\n",
885 text,
886 GNUNET_CRYPTO_ecdsa_public_key_to_string(&dsentry->delegation_chain_entry->issuer_key),
887 dsentry->delegation_chain_entry->issuer_attribute,
888 GNUNET_CRYPTO_ecdsa_public_key_to_string(&dsentry->delegation_chain_entry->subject_key),
889 dsentry->delegation_chain_entry->subject_attribute);
890}
891
892static void
836backward_resolution (void *cls, 893backward_resolution (void *cls,
837 uint32_t rd_count, 894 uint32_t rd_count,
838 const struct GNUNET_GNSRECORD_Data *rd) 895 const struct GNUNET_GNSRECORD_Data *rd)
@@ -934,14 +991,15 @@ backward_resolution (void *cls,
934 dq_entry->set_entries_tail, 991 dq_entry->set_entries_tail,
935 ds_entry); 992 ds_entry);
936 993
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
938 /** 994 /**
939 * Check if this delegation already matches one of our credentials 995 * Check if this delegation already matches one of our credentials
940 */ 996 */
997 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
998
941 for (del_pointer = vrh->del_chain_head; del_pointer != NULL; 999 for (del_pointer = vrh->del_chain_head; del_pointer != NULL;
942 del_pointer = del_pointer->next) 1000 del_pointer = del_pointer->next)
943 { 1001 {
944 // If key and attribute match credential continue and backtrack 1002 // If key and attribute match credential: continue and backtrack
945 if (0 != memcmp (&set->subject_key, 1003 if (0 != memcmp (&set->subject_key,
946 &del_pointer->delegate->issuer_key, 1004 &del_pointer->delegate->issuer_key,
947 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) 1005 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
@@ -956,7 +1014,9 @@ backward_resolution (void *cls,
956 continue; 1014 continue;
957 1015
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n"); 1016 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
1017 // increase refcount of the start delegation
959 del_pointer->refcount++; 1018 del_pointer->refcount++;
1019
960 // Backtrack 1020 // Backtrack
961 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry; 1021 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
962 tmp_set = tmp_set->parent_queue_entry->parent_set) 1022 tmp_set = tmp_set->parent_queue_entry->parent_set)
@@ -973,6 +1033,7 @@ backward_resolution (void *cls,
973 break; 1033 break;
974 } 1034 }
975 1035
1036 // if the break above is not called the condition of the for is met
976 if (NULL == tmp_set->parent_queue_entry) 1037 if (NULL == tmp_set->parent_queue_entry)
977 { 1038 {
978 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All solutions found\n"); 1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All solutions found\n");
@@ -983,10 +1044,11 @@ backward_resolution (void *cls,
983 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not all solutions found yet.\n"); 1044 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not all solutions found yet.\n");
984 continue; 1045 continue;
985 } 1046 }
1047
986 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
987 "Building new lookup request from %s\n", 1049 "Building new lookup request from %s\n",
988 ds_entry->unresolved_attribute_delegation); 1050 ds_entry->unresolved_attribute_delegation);
989 // Continue with backward resolution 1051 // Continue with next/new backward resolution
990 char issuer_attribute_name[strlen ( 1052 char issuer_attribute_name[strlen (
991 ds_entry->unresolved_attribute_delegation) + 1053 ds_entry->unresolved_attribute_delegation) +
992 1]; 1054 1];
@@ -1011,6 +1073,106 @@ backward_resolution (void *cls,
1011 ds_entry->attr_trailer = GNUNET_strdup (next_attr); 1073 ds_entry->attr_trailer = GNUNET_strdup (next_attr);
1012 } 1074 }
1013 1075
1076
1077 // TODO testing area
1078 // Check list
1079 for (struct DelegationSetQueueEntry *del_entry = dsq_head;
1080 del_entry != NULL;
1081 del_entry = del_entry->next)
1082 {
1083 print_deleset(del_entry, "-----bw----- ");
1084
1085 // only check entries not added by forward algorithm
1086 if(!del_entry->from_bw)
1087 {
1088 // key of list entry matches actual key
1089 if (0 == memcmp (&del_entry->delegation_chain_entry->issuer_key,
1090 &ds_entry->delegation_chain_entry->subject_key,
1091 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
1092 {
1093 // compare entry subject attributes to this trailer (iss attr + old trailer)
1094 if (0 == strcmp (del_entry->attr_trailer,
1095 ds_entry->delegation_chain_entry->subject_attribute))
1096 {
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"--bw-------- Found match with above!\n");
1098
1099 //TODO parents are not set correctly, for FW parents are going down in the chain
1100 // and for BW parents are going up
1101 // therefore: parent fixing needs to be done and then the stuff from above
1102 // backtrack(required solutions) and refcount++
1103 // might need some functions cuz its getting real big in here
1104
1105 struct DelegationSetQueueEntry *old_fw_parent;
1106 struct DelegationSetQueueEntry *fw_entry = del_entry;
1107 struct DelegationSetQueueEntry *bw_entry = ds_entry;
1108 // parentset and add
1109 while(NULL != fw_entry->parent_queue_entry)
1110 {
1111 print_deleset(fw_entry, "-----in while----- ");
1112 old_fw_parent = fw_entry->parent_queue_entry->parent_set;
1113 // set parent
1114 fw_entry->parent_queue_entry->parent_set = bw_entry;
1115
1116 bw_entry = fw_entry;
1117 fw_entry = old_fw_parent;
1118 }
1119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "NACH WHILE\n");
1120 // set last entry of chain as actual ds_entry
1121 ds_entry = bw_entry;
1122 // set refcount, loop all delegations
1123 for (del_pointer = vrh->del_chain_head; del_pointer != NULL;
1124 del_pointer = del_pointer->next)
1125 {
1126 if (0 != memcmp (&ds_entry->delegation_chain_entry->subject_key,
1127 &del_pointer->delegate->issuer_key,
1128 sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
1129 continue;
1130 if (0 != strcmp (ds_entry->delegation_chain_entry->subject_attribute,
1131 del_pointer->delegate->issuer_attribute))
1132 continue;
1133
1134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found delegate.\n");
1135 // increase refcount of the start delegation
1136 del_pointer->refcount++;
1137 }
1138 // backtrack
1139 for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
1140 tmp_set = tmp_set->parent_queue_entry->parent_set)
1141 {
1142 //TODO set refcount
1143 print_deleset(tmp_set, "-----ENDSET----- ");
1144 tmp_set->parent_queue_entry->required_solutions--;
1145
1146 // add new found entry to vrh
1147 vrh->delegation_chain_size++;
1148 GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
1149 vrh->delegation_chain_tail,
1150 tmp_set->delegation_chain_entry);
1151
1152 // if one node on the path still needs solutions, this current
1153 // patch cannot fullfil the conditions and therefore stops here
1154 // however, it is in the vrh and can be used by the other paths
1155 // related to this path/collection/verification
1156 if (0 < tmp_set->parent_queue_entry->required_solutions)
1157 {
1158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Chain requires more solutions, waiting...\n");
1159 return;
1160 }
1161 }
1162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "NACH FOR\n");
1163
1164 send_lookup_response (vrh);
1165 return;
1166 }
1167 }
1168 }
1169 }
1170 // No crossmatch/bidirectional result, add this ds_entry for the bw algo to match
1171 ds_entry->from_bw = true;
1172 GNUNET_CONTAINER_DLL_insert (dsq_head, dsq_tail, ds_entry);
1173
1174
1175
1014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1015 "Looking up %s\n", 1177 "Looking up %s\n",
1016 ds_entry->lookup_attribute); 1178 ds_entry->lookup_attribute);
@@ -1305,7 +1467,12 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
1305 } 1467 }
1306 1468
1307 // Switch resolution algo 1469 // Switch resolution algo
1308 if (GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo) 1470 if(GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo && GNUNET_CREDENTIAL_FLAG_FORWARD & vrh->resolution_algo)
1471 {
1472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "--------BOTH\n");
1473 delegation_chain_fw_resolution_start (vrh);
1474 delegation_chain_bw_resolution_start (vrh);
1475 } else if (GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo)
1309 { 1476 {
1310 delegation_chain_bw_resolution_start (vrh); 1477 delegation_chain_bw_resolution_start (vrh);
1311 } 1478 }
@@ -1313,10 +1480,6 @@ handle_verify (void *cls, const struct VerifyMessage *v_msg)
1313 { 1480 {
1314 delegation_chain_fw_resolution_start (vrh); 1481 delegation_chain_fw_resolution_start (vrh);
1315 } 1482 }
1316 else
1317 {
1318 //TODO
1319 }
1320} 1483}
1321 1484
1322static void 1485static void
@@ -1335,7 +1498,13 @@ delegate_collection_finished (void *cls)
1335 struct VerifyRequestHandle *vrh = cls; 1498 struct VerifyRequestHandle *vrh = cls;
1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting delegates.\n"); 1499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting delegates.\n");
1337 1500
1338 if (GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo) 1501 //TODO correct calls
1502 if(GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo && GNUNET_CREDENTIAL_FLAG_FORWARD & vrh->resolution_algo)
1503 {
1504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "--------BOTH\n");
1505 delegation_chain_fw_resolution_start (vrh);
1506 delegation_chain_bw_resolution_start (vrh);
1507 }else if (GNUNET_CREDENTIAL_FLAG_BACKWARD & vrh->resolution_algo)
1339 { 1508 {
1340 delegation_chain_bw_resolution_start (vrh); 1509 delegation_chain_bw_resolution_start (vrh);
1341 } 1510 }
@@ -1343,10 +1512,6 @@ delegate_collection_finished (void *cls)
1343 { 1512 {
1344 delegation_chain_fw_resolution_start (vrh); 1513 delegation_chain_fw_resolution_start (vrh);
1345 } 1514 }
1346 else
1347 {
1348 //TODO
1349 }
1350} 1515}
1351 1516
1352static void 1517static void