aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2022-03-17 15:12:06 +0100
committert3sserakt <t3ss@posteo.de>2022-03-17 15:12:06 +0100
commit8d41efc36bec5bc5ec29278a365d5a63d7349084 (patch)
tree99177b1b5400df5ae7180c2af1f47408cace1034 /src/namestore/namestore_api.c
parent95a1edacccd9b3bf769a144a12d41946d0ac25dc (diff)
parentea4a5dd6ca3d62f852b5c2de94071b7fc8f0544c (diff)
downloadgnunet-8d41efc36bec5bc5ec29278a365d5a63d7349084.tar.gz
gnunet-8d41efc36bec5bc5ec29278a365d5a63d7349084.zip
Merge branch 'master' of ssh://git.gnunet.org/gnunet
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r--src/namestore/namestore_api.c173
1 files changed, 117 insertions, 56 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index b24db9b26..a7380bbde 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -346,6 +346,44 @@ check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
346 return GNUNET_OK; 346 return GNUNET_OK;
347} 347}
348 348
349/**
350 * Handle an incoming message of type
351 * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
352 *
353 * @param cls
354 * @param msg the message we received
355 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
356 */
357static int
358check_record_store_response (void *cls,
359 const struct RecordStoreResponseMessage *msg)
360{
361 const char *emsg;
362 size_t msg_len;
363 size_t emsg_len;
364
365 (void) cls;
366 msg_len = ntohs (msg->gns_header.header.size);
367 emsg_len = ntohs (msg->emsg_len);
368 if (0 != ntohs (msg->reserved))
369 {
370 GNUNET_break (0);
371 return GNUNET_SYSERR;
372 }
373 if (msg_len != sizeof(struct RecordStoreResponseMessage) + emsg_len)
374 {
375 GNUNET_break (0);
376 return GNUNET_SYSERR;
377 }
378 emsg = (const char *) &msg[1];
379 if ((0 != emsg_len) && ('\0' != emsg[emsg_len - 1]))
380 {
381 GNUNET_break (0);
382 return GNUNET_SYSERR;
383 }
384 return GNUNET_OK;
385}
386
349 387
350/** 388/**
351 * Handle an incoming message of type 389 * Handle an incoming message of type
@@ -364,19 +402,16 @@ handle_record_store_response (void *cls,
364 const char *emsg; 402 const char *emsg;
365 403
366 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 404 qe = find_qe (h, ntohl (msg->gns_header.r_id));
405 emsg = (const char *) &msg[1];
367 res = ntohl (msg->op_result); 406 res = ntohl (msg->op_result);
368 LOG (GNUNET_ERROR_TYPE_DEBUG, 407 LOG (GNUNET_ERROR_TYPE_DEBUG,
369 "Received RECORD_STORE_RESPONSE with result %d\n", 408 "Received RECORD_STORE_RESPONSE with result %d\n",
370 res); 409 res);
371 /* TODO: add actual error message from namestore to response... */
372 if (GNUNET_SYSERR == res)
373 emsg = _ ("Namestore failed to store record\n");
374 else
375 emsg = NULL;
376 if (NULL == qe) 410 if (NULL == qe)
377 return; 411 return;
378 if (NULL != qe->cont) 412 if (NULL != qe->cont)
379 qe->cont (qe->cont_cls, res, emsg); 413 qe->cont (qe->cont_cls, res,
414 (GNUNET_OK == res) ? NULL : emsg);
380 free_qe (qe); 415 free_qe (qe);
381} 416}
382 417
@@ -444,8 +479,10 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
444 size_t name_len; 479 size_t name_len;
445 size_t rd_len; 480 size_t rd_len;
446 unsigned int rd_count; 481 unsigned int rd_count;
482 int16_t found = (int16_t) ntohs (msg->found);
447 483
448 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n"); 484 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT (found=%i)\n",
485 found);
449 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 486 qe = find_qe (h, ntohl (msg->gns_header.r_id));
450 if (NULL == qe) 487 if (NULL == qe)
451 return; 488 return;
@@ -453,7 +490,7 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
453 rd_count = ntohs (msg->rd_count); 490 rd_count = ntohs (msg->rd_count);
454 name_len = ntohs (msg->name_len); 491 name_len = ntohs (msg->name_len);
455 name = (const char *) &msg[1]; 492 name = (const char *) &msg[1];
456 if (GNUNET_NO == ntohs (msg->found)) 493 if (GNUNET_NO == found)
457 { 494 {
458 /* label was not in namestore */ 495 /* label was not in namestore */
459 if (NULL != qe->proc) 496 if (NULL != qe->proc)
@@ -461,6 +498,13 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
461 free_qe (qe); 498 free_qe (qe);
462 return; 499 return;
463 } 500 }
501 if (GNUNET_SYSERR == found)
502 {
503 if (NULL != qe->error_cb)
504 qe->error_cb (qe->error_cb_cls);
505 free_qe (qe);
506 return;
507 }
464 508
465 rd_tmp = &name[name_len]; 509 rd_tmp = &name[name_len];
466 { 510 {
@@ -775,7 +819,7 @@ static void
775reconnect (struct GNUNET_NAMESTORE_Handle *h) 819reconnect (struct GNUNET_NAMESTORE_Handle *h)
776{ 820{
777 struct GNUNET_MQ_MessageHandler handlers[] = 821 struct GNUNET_MQ_MessageHandler handlers[] =
778 { GNUNET_MQ_hd_fixed_size (record_store_response, 822 { GNUNET_MQ_hd_var_size (record_store_response,
779 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, 823 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE,
780 struct RecordStoreResponseMessage, 824 struct RecordStoreResponseMessage,
781 h), 825 h),
@@ -969,30 +1013,16 @@ warn_delay (void *cls)
969 GNUNET_NAMESTORE_cancel (qe); 1013 GNUNET_NAMESTORE_cancel (qe);
970} 1014}
971 1015
972
973/**
974 * Store an item in the namestore. If the item is already present,
975 * it is replaced with the new record. Use an empty array to
976 * remove all records under the given name.
977 *
978 * @param h handle to the namestore
979 * @param pkey private key of the zone
980 * @param label name that is being mapped (at most 255 characters long)
981 * @param rd_count number of records in the @a rd array
982 * @param rd array of records with data to store
983 * @param cont continuation to call when done
984 * @param cont_cls closure for @a cont
985 * @return handle to abort the request
986 */
987struct GNUNET_NAMESTORE_QueueEntry * 1016struct GNUNET_NAMESTORE_QueueEntry *
988GNUNET_NAMESTORE_records_store ( 1017records_store_ (
989 struct GNUNET_NAMESTORE_Handle *h, 1018 struct GNUNET_NAMESTORE_Handle *h,
990 const struct GNUNET_IDENTITY_PrivateKey *pkey, 1019 const struct GNUNET_IDENTITY_PrivateKey *pkey,
991 const char *label, 1020 const char *label,
992 unsigned int rd_count, 1021 unsigned int rd_count,
993 const struct GNUNET_GNSRECORD_Data *rd, 1022 const struct GNUNET_GNSRECORD_Data *rd,
994 GNUNET_NAMESTORE_ContinuationWithStatus cont, 1023 GNUNET_NAMESTORE_ContinuationWithStatus cont,
995 void *cont_cls) 1024 void *cont_cls,
1025 int locking)
996{ 1026{
997 struct GNUNET_NAMESTORE_QueueEntry *qe; 1027 struct GNUNET_NAMESTORE_QueueEntry *qe;
998 struct GNUNET_MQ_Envelope *env; 1028 struct GNUNET_MQ_Envelope *env;
@@ -1037,8 +1067,9 @@ GNUNET_NAMESTORE_records_store (
1037 msg->name_len = htons (name_len); 1067 msg->name_len = htons (name_len);
1038 msg->rd_count = htons (rd_count); 1068 msg->rd_count = htons (rd_count);
1039 msg->rd_len = htons (rd_ser_len); 1069 msg->rd_len = htons (rd_ser_len);
1040 msg->reserved = htons (0); 1070 msg->reserved = ntohs(0);
1041 msg->private_key = *pkey; 1071 msg->private_key = *pkey;
1072 msg->locking = htonl (locking);
1042 1073
1043 name_tmp = (char *) &msg[1]; 1074 name_tmp = (char *) &msg[1];
1044 GNUNET_memcpy (name_tmp, label, name_len); 1075 GNUNET_memcpy (name_tmp, label, name_len);
@@ -1070,28 +1101,45 @@ GNUNET_NAMESTORE_records_store (
1070 return qe; 1101 return qe;
1071} 1102}
1072 1103
1104struct GNUNET_NAMESTORE_QueueEntry *
1105GNUNET_NAMESTORE_records_store (
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
1118struct GNUNET_NAMESTORE_QueueEntry *
1119GNUNET_NAMESTORE_records_commit (
1120 struct GNUNET_NAMESTORE_Handle *h,
1121 const struct GNUNET_IDENTITY_PrivateKey *pkey,
1122 const char *label,
1123 unsigned int rd_count,
1124 const struct GNUNET_GNSRECORD_Data *rd,
1125 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1126 void *cont_cls)
1127{
1128 return records_store_ (h, pkey, label,
1129 rd_count, rd, cont, cont_cls, GNUNET_YES);
1130}
1131
1073 1132
1074/**
1075 * Lookup an item in the namestore.
1076 *
1077 * @param h handle to the namestore
1078 * @param pkey private key of the zone
1079 * @param label name that is being mapped (at most 255 characters long)
1080 * @param error_cb function to call on error (i.e. disconnect)
1081 * @param error_cb_cls closure for @a error_cb
1082 * @param rm function to call with the result (with 0 records if we don't have that label)
1083 * @param rm_cls closure for @a rm
1084 * @return handle to abort the request
1085 */
1086struct GNUNET_NAMESTORE_QueueEntry * 1133struct GNUNET_NAMESTORE_QueueEntry *
1087GNUNET_NAMESTORE_records_lookup ( 1134records_lookup_ (
1088 struct GNUNET_NAMESTORE_Handle *h, 1135 struct GNUNET_NAMESTORE_Handle *h,
1089 const struct GNUNET_IDENTITY_PrivateKey *pkey, 1136 const struct GNUNET_IDENTITY_PrivateKey *pkey,
1090 const char *label, 1137 const char *label,
1091 GNUNET_SCHEDULER_TaskCallback error_cb, 1138 GNUNET_SCHEDULER_TaskCallback error_cb,
1092 void *error_cb_cls, 1139 void *error_cb_cls,
1093 GNUNET_NAMESTORE_RecordMonitor rm, 1140 GNUNET_NAMESTORE_RecordMonitor rm,
1094 void *rm_cls) 1141 void *rm_cls,
1142 int locking)
1095{ 1143{
1096 struct GNUNET_NAMESTORE_QueueEntry *qe; 1144 struct GNUNET_NAMESTORE_QueueEntry *qe;
1097 struct GNUNET_MQ_Envelope *env; 1145 struct GNUNET_MQ_Envelope *env;
@@ -1119,6 +1167,7 @@ GNUNET_NAMESTORE_records_lookup (
1119 msg->gns_header.r_id = htonl (qe->op_id); 1167 msg->gns_header.r_id = htonl (qe->op_id);
1120 msg->zone = *pkey; 1168 msg->zone = *pkey;
1121 msg->label_len = htonl (label_len); 1169 msg->label_len = htonl (label_len);
1170 msg->locking = htonl (locking);
1122 GNUNET_memcpy (&msg[1], label, label_len); 1171 GNUNET_memcpy (&msg[1], label, label_len);
1123 if (NULL == h->mq) 1172 if (NULL == h->mq)
1124 qe->env = env; 1173 qe->env = env;
@@ -1127,22 +1176,34 @@ GNUNET_NAMESTORE_records_lookup (
1127 return qe; 1176 return qe;
1128} 1177}
1129 1178
1179struct GNUNET_NAMESTORE_QueueEntry *
1180GNUNET_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
1193struct GNUNET_NAMESTORE_QueueEntry *
1194GNUNET_NAMESTORE_records_open (
1195 struct GNUNET_NAMESTORE_Handle *h,
1196 const struct GNUNET_IDENTITY_PrivateKey *pkey,
1197 const char *label,
1198 GNUNET_SCHEDULER_TaskCallback error_cb,
1199 void *error_cb_cls,
1200 GNUNET_NAMESTORE_RecordMonitor rm,
1201 void *rm_cls)
1202{
1203 return records_lookup_ (h, pkey, label,
1204 error_cb, error_cb_cls, rm, rm_cls, GNUNET_YES);
1205}
1130 1206
1131/**
1132 * Look for an existing PKEY delegation record for a given public key.
1133 * Returns at most one result to the processor.
1134 *
1135 * @param h handle to the namestore
1136 * @param zone public key of the zone to look up in, never NULL
1137 * @param value_zone public key of the target zone (value), never NULL
1138 * @param error_cb function to call on error (i.e. disconnect)
1139 * @param error_cb_cls closure for @a error_cb
1140 * @param proc function to call on the matching records, or with
1141 * NULL (rd_count == 0) if there are no matching records
1142 * @param proc_cls closure for @a proc
1143 * @return a handle that can be used to
1144 * cancel
1145 */
1146struct GNUNET_NAMESTORE_QueueEntry * 1207struct GNUNET_NAMESTORE_QueueEntry *
1147GNUNET_NAMESTORE_zone_to_name ( 1208GNUNET_NAMESTORE_zone_to_name (
1148 struct GNUNET_NAMESTORE_Handle *h, 1209 struct GNUNET_NAMESTORE_Handle *h,