diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2022-03-21 13:54:28 +0100 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2022-03-21 13:54:28 +0100 |
commit | 4e95b59a6f3cd35c9c1b5dcdc6320f0e0dfef79b (patch) | |
tree | 22f87fcea0ea417a7a3ca8b900c3e6c891c28088 /src/namestore/namestore_api.c | |
parent | ec8a825b0e56c692c4879db10c6b25cd26bb42e4 (diff) | |
download | gnunet-4e95b59a6f3cd35c9c1b5dcdc6320f0e0dfef79b.tar.gz gnunet-4e95b59a6f3cd35c9c1b5dcdc6320f0e0dfef79b.zip |
NAMESTORE: Towards new transaction-based API
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r-- | src/namestore/namestore_api.c | 115 |
1 files changed, 67 insertions, 48 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index a7380bbde..73f985803 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -411,7 +411,7 @@ handle_record_store_response (void *cls, | |||
411 | return; | 411 | return; |
412 | if (NULL != qe->cont) | 412 | if (NULL != qe->cont) |
413 | qe->cont (qe->cont_cls, res, | 413 | qe->cont (qe->cont_cls, res, |
414 | (GNUNET_OK == res) ? NULL : emsg); | 414 | (GNUNET_OK == res) ? NULL : emsg); |
415 | free_qe (qe); | 415 | free_qe (qe); |
416 | } | 416 | } |
417 | 417 | ||
@@ -482,7 +482,7 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) | |||
482 | int16_t found = (int16_t) ntohs (msg->found); | 482 | int16_t found = (int16_t) ntohs (msg->found); |
483 | 483 | ||
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT (found=%i)\n", | 484 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT (found=%i)\n", |
485 | found); | 485 | found); |
486 | qe = find_qe (h, ntohl (msg->gns_header.r_id)); | 486 | qe = find_qe (h, ntohl (msg->gns_header.r_id)); |
487 | if (NULL == qe) | 487 | if (NULL == qe) |
488 | return; | 488 | return; |
@@ -820,9 +820,9 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
820 | { | 820 | { |
821 | struct GNUNET_MQ_MessageHandler handlers[] = | 821 | struct GNUNET_MQ_MessageHandler handlers[] = |
822 | { GNUNET_MQ_hd_var_size (record_store_response, | 822 | { GNUNET_MQ_hd_var_size (record_store_response, |
823 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, | 823 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, |
824 | struct RecordStoreResponseMessage, | 824 | struct RecordStoreResponseMessage, |
825 | h), | 825 | h), |
826 | GNUNET_MQ_hd_var_size (zone_to_name_response, | 826 | GNUNET_MQ_hd_var_size (zone_to_name_response, |
827 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE, | 827 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE, |
828 | struct ZoneToNameResponseMessage, | 828 | struct ZoneToNameResponseMessage, |
@@ -1013,16 +1013,16 @@ warn_delay (void *cls) | |||
1013 | GNUNET_NAMESTORE_cancel (qe); | 1013 | GNUNET_NAMESTORE_cancel (qe); |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | |||
1016 | struct GNUNET_NAMESTORE_QueueEntry * | 1017 | struct GNUNET_NAMESTORE_QueueEntry * |
1017 | records_store_ ( | 1018 | GNUNET_NAMESTORE_records_store ( |
1018 | struct GNUNET_NAMESTORE_Handle *h, | 1019 | struct GNUNET_NAMESTORE_Handle *h, |
1019 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | 1020 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1020 | const char *label, | 1021 | const char *label, |
1021 | unsigned int rd_count, | 1022 | unsigned int rd_count, |
1022 | const struct GNUNET_GNSRECORD_Data *rd, | 1023 | const struct GNUNET_GNSRECORD_Data *rd, |
1023 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 1024 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
1024 | void *cont_cls, | 1025 | void *cont_cls) |
1025 | int locking) | ||
1026 | { | 1026 | { |
1027 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 1027 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
1028 | struct GNUNET_MQ_Envelope *env; | 1028 | struct GNUNET_MQ_Envelope *env; |
@@ -1067,9 +1067,8 @@ records_store_ ( | |||
1067 | msg->name_len = htons (name_len); | 1067 | msg->name_len = htons (name_len); |
1068 | msg->rd_count = htons (rd_count); | 1068 | msg->rd_count = htons (rd_count); |
1069 | msg->rd_len = htons (rd_ser_len); | 1069 | msg->rd_len = htons (rd_ser_len); |
1070 | msg->reserved = ntohs(0); | 1070 | msg->reserved = ntohs (0); |
1071 | msg->private_key = *pkey; | 1071 | msg->private_key = *pkey; |
1072 | msg->locking = htonl (locking); | ||
1073 | 1072 | ||
1074 | name_tmp = (char *) &msg[1]; | 1073 | name_tmp = (char *) &msg[1]; |
1075 | GNUNET_memcpy (name_tmp, label, name_len); | 1074 | GNUNET_memcpy (name_tmp, label, name_len); |
@@ -1101,22 +1100,11 @@ records_store_ ( | |||
1101 | return qe; | 1100 | return qe; |
1102 | } | 1101 | } |
1103 | 1102 | ||
1103 | /** | ||
1104 | * TODO: Experimental API will replace API above. | ||
1105 | */ | ||
1104 | struct GNUNET_NAMESTORE_QueueEntry * | 1106 | struct GNUNET_NAMESTORE_QueueEntry * |
1105 | GNUNET_NAMESTORE_records_store ( | 1107 | GNUNET_NAMESTORE_records_replace ( |
1106 | struct GNUNET_NAMESTORE_Handle *h, | ||
1107 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | ||
1108 | const char *label, | ||
1109 | unsigned int rd_count, | ||
1110 | const struct GNUNET_GNSRECORD_Data *rd, | ||
1111 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
1112 | void *cont_cls) | ||
1113 | { | ||
1114 | return records_store_ (h, pkey, label, | ||
1115 | rd_count, rd, cont, cont_cls, GNUNET_NO); | ||
1116 | } | ||
1117 | |||
1118 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1119 | GNUNET_NAMESTORE_records_commit ( | ||
1120 | struct GNUNET_NAMESTORE_Handle *h, | 1108 | struct GNUNET_NAMESTORE_Handle *h, |
1121 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | 1109 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1122 | const char *label, | 1110 | const char *label, |
@@ -1125,21 +1113,19 @@ GNUNET_NAMESTORE_records_commit ( | |||
1125 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 1113 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
1126 | void *cont_cls) | 1114 | void *cont_cls) |
1127 | { | 1115 | { |
1128 | return records_store_ (h, pkey, label, | 1116 | return GNUNET_NAMESTORE_records_store (h, pkey, label, rd_count, rd, |
1129 | rd_count, rd, cont, cont_cls, GNUNET_YES); | 1117 | cont, cont_cls); |
1130 | } | 1118 | } |
1131 | 1119 | ||
1132 | |||
1133 | struct GNUNET_NAMESTORE_QueueEntry * | 1120 | struct GNUNET_NAMESTORE_QueueEntry * |
1134 | records_lookup_ ( | 1121 | GNUNET_NAMESTORE_records_lookup ( |
1135 | struct GNUNET_NAMESTORE_Handle *h, | 1122 | struct GNUNET_NAMESTORE_Handle *h, |
1136 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | 1123 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1137 | const char *label, | 1124 | const char *label, |
1138 | GNUNET_SCHEDULER_TaskCallback error_cb, | 1125 | GNUNET_SCHEDULER_TaskCallback error_cb, |
1139 | void *error_cb_cls, | 1126 | void *error_cb_cls, |
1140 | GNUNET_NAMESTORE_RecordMonitor rm, | 1127 | GNUNET_NAMESTORE_RecordMonitor rm, |
1141 | void *rm_cls, | 1128 | void *rm_cls) |
1142 | int locking) | ||
1143 | { | 1129 | { |
1144 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 1130 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
1145 | struct GNUNET_MQ_Envelope *env; | 1131 | struct GNUNET_MQ_Envelope *env; |
@@ -1167,7 +1153,6 @@ records_lookup_ ( | |||
1167 | msg->gns_header.r_id = htonl (qe->op_id); | 1153 | msg->gns_header.r_id = htonl (qe->op_id); |
1168 | msg->zone = *pkey; | 1154 | msg->zone = *pkey; |
1169 | msg->label_len = htonl (label_len); | 1155 | msg->label_len = htonl (label_len); |
1170 | msg->locking = htonl (locking); | ||
1171 | GNUNET_memcpy (&msg[1], label, label_len); | 1156 | GNUNET_memcpy (&msg[1], label, label_len); |
1172 | if (NULL == h->mq) | 1157 | if (NULL == h->mq) |
1173 | qe->env = env; | 1158 | qe->env = env; |
@@ -1176,22 +1161,12 @@ records_lookup_ ( | |||
1176 | return qe; | 1161 | return qe; |
1177 | } | 1162 | } |
1178 | 1163 | ||
1179 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1180 | GNUNET_NAMESTORE_records_lookup ( | ||
1181 | struct GNUNET_NAMESTORE_Handle *h, | ||
1182 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | ||
1183 | const char *label, | ||
1184 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1185 | void *error_cb_cls, | ||
1186 | GNUNET_NAMESTORE_RecordMonitor rm, | ||
1187 | void *rm_cls) | ||
1188 | { | ||
1189 | return records_lookup_ (h, pkey, label, | ||
1190 | error_cb, error_cb_cls, rm, rm_cls, GNUNET_NO); | ||
1191 | } | ||
1192 | 1164 | ||
1165 | /** | ||
1166 | * TODO experimental API. Will replace old API above. | ||
1167 | */ | ||
1193 | struct GNUNET_NAMESTORE_QueueEntry * | 1168 | struct GNUNET_NAMESTORE_QueueEntry * |
1194 | GNUNET_NAMESTORE_records_open ( | 1169 | GNUNET_NAMESTORE_records_select ( |
1195 | struct GNUNET_NAMESTORE_Handle *h, | 1170 | struct GNUNET_NAMESTORE_Handle *h, |
1196 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | 1171 | const struct GNUNET_IDENTITY_PrivateKey *pkey, |
1197 | const char *label, | 1172 | const char *label, |
@@ -1200,8 +1175,9 @@ GNUNET_NAMESTORE_records_open ( | |||
1200 | GNUNET_NAMESTORE_RecordMonitor rm, | 1175 | GNUNET_NAMESTORE_RecordMonitor rm, |
1201 | void *rm_cls) | 1176 | void *rm_cls) |
1202 | { | 1177 | { |
1203 | return records_lookup_ (h, pkey, label, | 1178 | return GNUNET_NAMESTORE_records_lookup (h, pkey, label, |
1204 | error_cb, error_cb_cls, rm, rm_cls, GNUNET_YES); | 1179 | error_cb, error_cb_cls, |
1180 | rm, rm_cls); | ||
1205 | } | 1181 | } |
1206 | 1182 | ||
1207 | struct GNUNET_NAMESTORE_QueueEntry * | 1183 | struct GNUNET_NAMESTORE_QueueEntry * |
@@ -1364,5 +1340,48 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe) | |||
1364 | free_qe (qe); | 1340 | free_qe (qe); |
1365 | } | 1341 | } |
1366 | 1342 | ||
1343 | /** | ||
1344 | * New API draft. Experimental | ||
1345 | */ | ||
1346 | |||
1347 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1348 | GNUNET_NAMESTORE_transaction_begin (struct GNUNET_NAMESTORE_Handle *h, | ||
1349 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1350 | void *error_cb_cls) | ||
1351 | { | ||
1352 | GNUNET_break (0); | ||
1353 | return NULL; | ||
1354 | } | ||
1355 | |||
1356 | |||
1357 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1358 | GNUNET_NAMESTORE_transaction_abort (struct GNUNET_NAMESTORE_Handle *h, | ||
1359 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1360 | void *error_cb_cls) | ||
1361 | { | ||
1362 | GNUNET_break (0); | ||
1363 | return NULL; | ||
1364 | } | ||
1365 | |||
1366 | |||
1367 | /** | ||
1368 | * Commit a namestore transaction. | ||
1369 | * Saves all actions performed since #GNUNET_NAMESTORE_transaction_begin | ||
1370 | * | ||
1371 | * @param h handle to the namestore | ||
1372 | * @param error_cb function to call on error (i.e. disconnect or unable to get lock) | ||
1373 | * the handle is afterwards invalid | ||
1374 | * @param error_cb_cls closure for @a error_cb | ||
1375 | * @return handle to abort the request | ||
1376 | */ | ||
1377 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1378 | GNUNET_NAMESTORE_transaction_commit (struct GNUNET_NAMESTORE_Handle *h, | ||
1379 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1380 | void *error_cb_cls) | ||
1381 | { | ||
1382 | GNUNET_break (0); | ||
1383 | return NULL; | ||
1384 | } | ||
1385 | |||
1367 | 1386 | ||
1368 | /* end of namestore_api.c */ | 1387 | /* end of namestore_api.c */ |