aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/gnunet-service-reclaim.c
diff options
context:
space:
mode:
authorMarkus Voggenreiter <Markus.Voggenreiter@tum.de>2019-11-29 13:00:18 +0100
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-01-13 13:31:05 +0100
commit76df96b59f803f9ba68849f452efbeed50d80086 (patch)
tree774df3681862e922231960ef238aa33b6a219048 /src/reclaim/gnunet-service-reclaim.c
parent1267dec774294ec2dcc6d2b89bced85eb4fadaa7 (diff)
downloadgnunet-76df96b59f803f9ba68849f452efbeed50d80086.tar.gz
gnunet-76df96b59f803f9ba68849f452efbeed50d80086.zip
Fixed Adding Attestations
Diffstat (limited to 'src/reclaim/gnunet-service-reclaim.c')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c166
1 files changed, 121 insertions, 45 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 8b7557090..5727f1ccd 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -1087,44 +1087,144 @@ attest_store_cont (void *cls, int32_t success, const char *emsg)
1087} 1087}
1088 1088
1089/** 1089/**
1090 * Add a new attestation 1090 * Send a reference error response
1091 *
1092 * @param ash our attribute store handle
1093 * @param success the success status
1094 */
1095static void
1096send_ref_error (struct AttributeStoreHandle *ash)
1097{
1098 struct GNUNET_MQ_Envelope *env;
1099 struct SuccessResultMessage *acr_msg;
1100
1101 ash->ns_qe = NULL;
1102 GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head,
1103 ash->client->store_op_tail,
1104 ash);
1105
1106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
1107 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
1108 acr_msg->id = htonl (ash->r_id);
1109 acr_msg->op_result = htonl (GNUNET_SYSERR);
1110 GNUNET_MQ_send (ash->client->mq, env);
1111 cleanup_as_handle (ash);
1112}
1113
1114/**
1115 * Error looking up potential attestation. Abort.
1091 * 1116 *
1092 * @param cls the AttributeStoreHandle 1117 * @param cls our attribute store handle
1093 */ 1118 */
1094static void 1119static void
1095attest_store_task (void *cls) 1120attest_error (void *cls)
1121{
1122 struct AttributeStoreHandle *ash = cls;
1123 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1124 "Failed to check for existing Attestation\n");
1125 cleanup_as_handle (ash);
1126 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1127 return;
1128}
1129
1130/**
1131* Check for existing record before storing reference
1132*
1133* @param cls our attribute store handle
1134* @param zone zone we are iterating
1135* @param label label of the records
1136* @param rd_count record count
1137* @param rd records
1138*/
1139static void
1140attest_add_cb (void *cls,
1141 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1142 const char *label,
1143 unsigned int rd_count,
1144 const struct GNUNET_GNSRECORD_Data *rd)
1096{ 1145{
1097 struct AttributeStoreHandle *ash = cls; 1146 struct AttributeStoreHandle *ash = cls;
1098 struct GNUNET_GNSRECORD_Data rd[1];
1099 char *buf; 1147 char *buf;
1100 char *label;
1101 size_t buf_size; 1148 size_t buf_size;
1102
1103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Storing attestation\n");
1104 buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest); 1149 buf_size = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (ash->attest);
1105 buf = GNUNET_malloc (buf_size); 1150 buf = GNUNET_malloc (buf_size);
1106 // Give the ash a new id if unset
1107 if (0 == ash->attest->id)
1108 ash->attest->id
1109 = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
1110 GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf); 1151 GNUNET_RECLAIM_ATTESTATION_serialize (ash->attest, buf);
1111 label = GNUNET_STRINGS_data_to_string_alloc (&ash->attest->id, 1152 if (0 == rd_count )
1112 sizeof(uint64_t)); 1153 {
1154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1155 "Storing new Attestation\n");
1156 struct GNUNET_GNSRECORD_Data rd_new[1];
1157 rd_new[0].data_size = buf_size;
1158 rd_new[0].data = buf;
1159 rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR;
1160 rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1161 rd_new[0].expiration_time = ash->exp.rel_value_us;
1162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
1163 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1164 &ash->identity,
1165 label,
1166 1,
1167 rd_new,
1168 &attest_store_cont,
1169 ash);
1170 GNUNET_free (buf);
1171 return;
1172 }
1173 if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR != rd[0].record_type)
1174 {
1175 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1176 "Existing Attestation location is not an Attestation\n");
1177 send_ref_error (ash);
1178 return;
1179 }
1180 struct GNUNET_GNSRECORD_Data rd_new[rd_count];
1181 for (int i = 0; i<rd_count; i++)
1182 {
1183 rd_new[i] = rd[i];
1184 }
1185 rd_new[0].data_size = buf_size;
1186 rd_new[0].data = buf;
1187 rd_new[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR;
1188 rd_new[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1189 rd_new[0].expiration_time = ash->exp.rel_value_us;
1113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label); 1190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypting with label %s\n", label);
1114
1115 rd[0].data_size = buf_size;
1116 rd[0].data = buf;
1117 rd[0].record_type = GNUNET_GNSRECORD_TYPE_RECLAIM_ATTEST_ATTR;
1118 rd[0].flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1119 rd[0].expiration_time = ash->exp.rel_value_us;
1120 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh, 1191 ash->ns_qe = GNUNET_NAMESTORE_records_store (nsh,
1121 &ash->identity, 1192 &ash->identity,
1122 label, 1193 label,
1123 1, 1194 rd_count,
1124 rd, 1195 rd_new,
1125 &attest_store_cont, 1196 &attest_store_cont,
1126 ash); 1197 ash);
1127 GNUNET_free (buf); 1198 GNUNET_free (buf);
1199}
1200
1201/**
1202 * Add a new attestation
1203 *
1204 * @param cls the AttributeStoreHandle
1205 */
1206static void
1207attest_store_task (void *cls)
1208{
1209 struct AttributeStoreHandle *ash = cls;
1210 char *label;
1211
1212 // Give the ash a new id if unset
1213 if (0 == ash->attest->id)
1214 ash->attest->id
1215 = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
1216 label = GNUNET_STRINGS_data_to_string_alloc (&ash->attest->id,
1217 sizeof(uint64_t));
1218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1219 "Looking up existing data under label %s\n", label);
1220// Test for the content of the existing ID
1221 ash->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh,
1222 &ash->identity,
1223 label,
1224 &attest_error,
1225 ash,
1226 &attest_add_cb,
1227 ash);
1128 GNUNET_free (label); 1228 GNUNET_free (label);
1129} 1229}
1130 1230
@@ -1250,30 +1350,6 @@ reference_store_cont (void *cls, int32_t success, const char *emsg)
1250 cleanup_as_handle (ash); 1350 cleanup_as_handle (ash);
1251} 1351}
1252 1352
1253/**
1254 * Send a reference error response
1255 *
1256 * @param ash our attribute store handle
1257 * @param success the success status
1258 */
1259static void
1260send_ref_error (struct AttributeStoreHandle *ash)
1261{
1262 struct GNUNET_MQ_Envelope *env;
1263 struct SuccessResultMessage *acr_msg;
1264
1265 ash->ns_qe = NULL;
1266 GNUNET_CONTAINER_DLL_remove (ash->client->store_op_head,
1267 ash->client->store_op_tail,
1268 ash);
1269
1270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending SUCCESS_RESPONSE message\n");
1271 env = GNUNET_MQ_msg (acr_msg, GNUNET_MESSAGE_TYPE_RECLAIM_SUCCESS_RESPONSE);
1272 acr_msg->id = htonl (ash->r_id);
1273 acr_msg->op_result = htonl (GNUNET_SYSERR);
1274 GNUNET_MQ_send (ash->client->mq, env);
1275 cleanup_as_handle (ash);
1276}
1277 1353
1278/** 1354/**
1279* Check for existing record before storing reference 1355* Check for existing record before storing reference