diff options
Diffstat (limited to 'src/service/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/service/namestore/gnunet-service-namestore.c | 410 |
1 files changed, 183 insertions, 227 deletions
diff --git a/src/service/namestore/gnunet-service-namestore.c b/src/service/namestore/gnunet-service-namestore.c index 26de295bf..230583936 100644 --- a/src/service/namestore/gnunet-service-namestore.c +++ b/src/service/namestore/gnunet-service-namestore.c | |||
@@ -24,17 +24,16 @@ | |||
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | 25 | * @author Christian Grothoff |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "gnunet_error_codes.h" |
28 | #include "gnunet_gnsrecord_lib.h" | ||
29 | #include "gnunet_protocols.h" | ||
28 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_gns_service.h" | ||
30 | #include "gnunet_namestore_service.h" | ||
31 | #include "gnunet_namestore_plugin.h" | 31 | #include "gnunet_namestore_plugin.h" |
32 | #include "gnunet_statistics_service.h" | 32 | #include "gnunet_statistics_service.h" |
33 | #include "gnunet_signatures.h" | ||
34 | #include "namestore.h" | 33 | #include "namestore.h" |
35 | 34 | ||
36 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ | 35 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ |
37 | GNUNET_log_from_strerror_file (kind, "util", syscall, filename) | 36 | GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
38 | 37 | ||
39 | /** | 38 | /** |
40 | * If a monitor takes more than 1 minute to process an event, print a warning. | 39 | * If a monitor takes more than 1 minute to process an event, print a warning. |
@@ -145,11 +144,6 @@ struct NamestoreClient | |||
145 | char *db_lib_name; | 144 | char *db_lib_name; |
146 | 145 | ||
147 | /** | 146 | /** |
148 | * GNUNET_YES if this nc has begun a transaction which is uncommited. | ||
149 | */ | ||
150 | int in_transaction; | ||
151 | |||
152 | /** | ||
153 | * Message queue for transmission to @e client | 147 | * Message queue for transmission to @e client |
154 | */ | 148 | */ |
155 | struct GNUNET_MQ_Handle *mq; | 149 | struct GNUNET_MQ_Handle *mq; |
@@ -256,7 +250,6 @@ struct ZoneMonitor | |||
256 | }; | 250 | }; |
257 | 251 | ||
258 | 252 | ||
259 | |||
260 | /** | 253 | /** |
261 | * Information for an ongoing #handle_record_store() operation. | 254 | * Information for an ongoing #handle_record_store() operation. |
262 | * Needed as we may wait for monitors to be ready for the notification. | 255 | * Needed as we may wait for monitors to be ready for the notification. |
@@ -294,12 +287,6 @@ struct StoreActivity | |||
294 | uint16_t rd_set_count; | 287 | uint16_t rd_set_count; |
295 | 288 | ||
296 | /** | 289 | /** |
297 | * Wheather or not this store action is already commited. | ||
298 | * The store activity will not be processed unless this field is GNUNET_YES | ||
299 | */ | ||
300 | int uncommited; | ||
301 | |||
302 | /** | ||
303 | * The zone private key | 290 | * The zone private key |
304 | */ | 291 | */ |
305 | struct GNUNET_CRYPTO_PrivateKey private_key; | 292 | struct GNUNET_CRYPTO_PrivateKey private_key; |
@@ -438,6 +425,7 @@ free_store_activity (struct StoreActivity *sa) | |||
438 | GNUNET_free (sa); | 425 | GNUNET_free (sa); |
439 | } | 426 | } |
440 | 427 | ||
428 | |||
441 | /** | 429 | /** |
442 | * Function called with the records for the #GNUNET_GNS_EMPTY_LABEL_AT | 430 | * Function called with the records for the #GNUNET_GNS_EMPTY_LABEL_AT |
443 | * label in the zone. Used to locate the #GNUNET_GNSRECORD_TYPE_NICK | 431 | * label in the zone. Used to locate the #GNUNET_GNSRECORD_TYPE_NICK |
@@ -453,6 +441,7 @@ free_store_activity (struct StoreActivity *sa) | |||
453 | static void | 441 | static void |
454 | lookup_nick_it (void *cls, | 442 | lookup_nick_it (void *cls, |
455 | uint64_t seq, | 443 | uint64_t seq, |
444 | const char *editor_hint, | ||
456 | const struct GNUNET_CRYPTO_PrivateKey *private_key, | 445 | const struct GNUNET_CRYPTO_PrivateKey *private_key, |
457 | const char *label, | 446 | const char *label, |
458 | unsigned int rd_count, | 447 | unsigned int rd_count, |
@@ -788,8 +777,8 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, | |||
788 | zir_msg->rd_len = htons ((uint16_t) rd_ser_len); | 777 | zir_msg->rd_len = htons ((uint16_t) rd_ser_len); |
789 | zir_msg->key_len = htons (key_len); | 778 | zir_msg->key_len = htons (key_len); |
790 | GNUNET_CRYPTO_write_private_key_to_buffer (zone_key, | 779 | GNUNET_CRYPTO_write_private_key_to_buffer (zone_key, |
791 | &zir_msg[1], | 780 | &zir_msg[1], |
792 | key_len); | 781 | key_len); |
793 | zir_msg->expire = GNUNET_TIME_absolute_hton (block_exp); | 782 | zir_msg->expire = GNUNET_TIME_absolute_hton (block_exp); |
794 | name_tmp = (char *) &zir_msg[1] + key_len; | 783 | name_tmp = (char *) &zir_msg[1] + key_len; |
795 | GNUNET_memcpy (name_tmp, name, name_len); | 784 | GNUNET_memcpy (name_tmp, name, name_len); |
@@ -810,6 +799,7 @@ send_lookup_response_with_filter (struct NamestoreClient *nc, | |||
810 | return res_count; | 799 | return res_count; |
811 | } | 800 | } |
812 | 801 | ||
802 | |||
813 | /** | 803 | /** |
814 | * Send response to the store request to the client. | 804 | * Send response to the store request to the client. |
815 | * | 805 | * |
@@ -823,17 +813,17 @@ send_store_response (struct NamestoreClient *nc, | |||
823 | uint32_t rid) | 813 | uint32_t rid) |
824 | { | 814 | { |
825 | struct GNUNET_MQ_Envelope *env; | 815 | struct GNUNET_MQ_Envelope *env; |
826 | struct RecordStoreResponseMessage *rcr_msg; | 816 | struct NamestoreResponseMessage *rcr_msg; |
827 | 817 | ||
828 | GNUNET_assert (NULL != nc); | 818 | GNUNET_assert (NULL != nc); |
829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
830 | "Sending RECORD_STORE_RESPONSE message\n"); | 820 | "Sending GENERIC_RESPONSE message\n"); |
831 | GNUNET_STATISTICS_update (statistics, | 821 | GNUNET_STATISTICS_update (statistics, |
832 | "Store requests completed", | 822 | "Store requests completed", |
833 | 1, | 823 | 1, |
834 | GNUNET_NO); | 824 | GNUNET_NO); |
835 | env = GNUNET_MQ_msg (rcr_msg, | 825 | env = GNUNET_MQ_msg (rcr_msg, |
836 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE); | 826 | GNUNET_MESSAGE_TYPE_NAMESTORE_GENERIC_RESPONSE); |
837 | rcr_msg->gns_header.r_id = htonl (rid); | 827 | rcr_msg->gns_header.r_id = htonl (rid); |
838 | rcr_msg->ec = htonl (ec); | 828 | rcr_msg->ec = htonl (ec); |
839 | GNUNET_MQ_send (nc->mq, env); | 829 | GNUNET_MQ_send (nc->mq, env); |
@@ -865,8 +855,6 @@ zone_iteration_done_client_continue (struct ZoneIteration *zi) | |||
865 | } | 855 | } |
866 | 856 | ||
867 | 857 | ||
868 | |||
869 | |||
870 | /** | 858 | /** |
871 | * Print a warning that one of our monitors is no longer reacting. | 859 | * Print a warning that one of our monitors is no longer reacting. |
872 | * | 860 | * |
@@ -904,17 +892,6 @@ continue_store_activity (struct StoreActivity *sa, | |||
904 | const char *buf; | 892 | const char *buf; |
905 | char *conv_name; | 893 | char *conv_name; |
906 | 894 | ||
907 | // If we are in a transaction, do not notify monitors or update | ||
908 | // cached. This will be done when we are commiting. | ||
909 | if (GNUNET_YES == sa->uncommited) | ||
910 | { | ||
911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
912 | "Transaction not yet committed, delaying monitor and cache updates\n"); | ||
913 | send_store_response (sa->nc, GNUNET_EC_NONE, sa->rid); | ||
914 | if (GNUNET_YES == call_continue) | ||
915 | GNUNET_SERVICE_client_continue (sa->nc->client); | ||
916 | return GNUNET_OK; | ||
917 | } | ||
918 | buf = (const char *) &sa[1]; | 895 | buf = (const char *) &sa[1]; |
919 | for (int i = sa->rd_set_pos; i < sa->rd_set_count; i++) | 896 | for (int i = sa->rd_set_pos; i < sa->rd_set_count; i++) |
920 | { | 897 | { |
@@ -1004,39 +981,9 @@ client_disconnect_cb (void *cls, | |||
1004 | struct ZoneIteration *no; | 981 | struct ZoneIteration *no; |
1005 | struct StoreActivity *sa = sa_head; | 982 | struct StoreActivity *sa = sa_head; |
1006 | struct StoreActivity *sn; | 983 | struct StoreActivity *sn; |
1007 | char *emsg; | ||
1008 | 984 | ||
1009 | (void) cls; | 985 | (void) cls; |
1010 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); | 986 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client); |
1011 | if (GNUNET_YES == nc->in_transaction) | ||
1012 | { | ||
1013 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1014 | "Client in transaction, rolling back...\n"); | ||
1015 | if (GNUNET_SYSERR == nc->GSN_database->transaction_rollback ( | ||
1016 | nc->GSN_database->cls, | ||
1017 | &emsg)) | ||
1018 | { | ||
1019 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1020 | "Unable to roll back: %s\n", emsg); | ||
1021 | GNUNET_free (emsg); | ||
1022 | } | ||
1023 | else | ||
1024 | { | ||
1025 | nc->in_transaction = GNUNET_NO; | ||
1026 | while (NULL != sa) | ||
1027 | { | ||
1028 | if ((nc != sa->nc) || | ||
1029 | (GNUNET_NO == sa->uncommited)) | ||
1030 | { | ||
1031 | sa = sa->next; | ||
1032 | continue; | ||
1033 | } | ||
1034 | sn = sa->next; | ||
1035 | free_store_activity (sa); | ||
1036 | sa = sn; | ||
1037 | } | ||
1038 | } | ||
1039 | } | ||
1040 | for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next) | 987 | for (struct ZoneMonitor *zm = monitor_head; NULL != zm; zm = zm->next) |
1041 | { | 988 | { |
1042 | if (nc != zm->nc) | 989 | if (nc != zm->nc) |
@@ -1148,6 +1095,11 @@ struct RecordLookupContext | |||
1148 | const char *label; | 1095 | const char *label; |
1149 | 1096 | ||
1150 | /** | 1097 | /** |
1098 | * The editor hint for set | ||
1099 | */ | ||
1100 | const char *editor_hint; | ||
1101 | |||
1102 | /** | ||
1151 | * The record result. | 1103 | * The record result. |
1152 | */ | 1104 | */ |
1153 | char *res_rd; | 1105 | char *res_rd; |
@@ -1194,6 +1146,7 @@ struct RecordLookupContext | |||
1194 | static void | 1146 | static void |
1195 | lookup_it (void *cls, | 1147 | lookup_it (void *cls, |
1196 | uint64_t seq, | 1148 | uint64_t seq, |
1149 | const char *editor_hint, | ||
1197 | const struct GNUNET_CRYPTO_PrivateKey *private_key, | 1150 | const struct GNUNET_CRYPTO_PrivateKey *private_key, |
1198 | const char *label, | 1151 | const char *label, |
1199 | unsigned int rd_count_nf, | 1152 | unsigned int rd_count_nf, |
@@ -1210,7 +1163,7 @@ lookup_it (void *cls, | |||
1210 | if (0 != strcmp (label, rlc->label)) | 1163 | if (0 != strcmp (label, rlc->label)) |
1211 | return; | 1164 | return; |
1212 | rlc->found = GNUNET_YES; | 1165 | rlc->found = GNUNET_YES; |
1213 | 1166 | rlc->editor_hint = editor_hint; | |
1214 | if (GNUNET_OK != GNUNET_GNSRECORD_normalize_record_set (rlc->label, | 1167 | if (GNUNET_OK != GNUNET_GNSRECORD_normalize_record_set (rlc->label, |
1215 | rd_nf, | 1168 | rd_nf, |
1216 | rd_count_nf, | 1169 | rd_count_nf, |
@@ -1302,6 +1255,132 @@ lookup_it (void *cls, | |||
1302 | 1255 | ||
1303 | 1256 | ||
1304 | /** | 1257 | /** |
1258 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT message | ||
1259 | * | ||
1260 | * @param cls client sending the message | ||
1261 | * @param er_msg message of type `struct EditRecordSetMessage` | ||
1262 | * @return #GNUNET_OK if @a er_msg is well-formed | ||
1263 | */ | ||
1264 | static int | ||
1265 | check_edit_record_set (void *cls, const struct EditRecordSetMessage *er_msg) | ||
1266 | { | ||
1267 | uint16_t name_len; | ||
1268 | uint16_t editor_hint_len; | ||
1269 | size_t src_size; | ||
1270 | size_t key_len; | ||
1271 | |||
1272 | (void) cls; | ||
1273 | name_len = ntohs (er_msg->label_len); | ||
1274 | editor_hint_len = ntohs (er_msg->editor_hint_len); | ||
1275 | key_len = ntohs (er_msg->key_len); | ||
1276 | src_size = ntohs (er_msg->gns_header.header.size); | ||
1277 | if (name_len + editor_hint_len + key_len != src_size - sizeof(struct | ||
1278 | LabelLookupMessage)) | ||
1279 | { | ||
1280 | GNUNET_break (0); | ||
1281 | return GNUNET_SYSERR; | ||
1282 | } | ||
1283 | return GNUNET_OK; | ||
1284 | } | ||
1285 | |||
1286 | |||
1287 | /** | ||
1288 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message | ||
1289 | * | ||
1290 | * @param cls client sending the message | ||
1291 | * @param ll_msg message of type `struct LabelLookupMessage` | ||
1292 | */ | ||
1293 | static void | ||
1294 | handle_edit_record_set (void *cls, const struct EditRecordSetMessage *er_msg) | ||
1295 | { | ||
1296 | struct GNUNET_CRYPTO_PrivateKey zone; | ||
1297 | struct NamestoreClient *nc = cls; | ||
1298 | struct GNUNET_MQ_Envelope *env; | ||
1299 | struct EditRecordSetResponseMessage *rer_msg; | ||
1300 | struct RecordLookupContext rlc; | ||
1301 | const char *name_tmp; | ||
1302 | const char *editor_hint; | ||
1303 | char *conv_name; | ||
1304 | uint16_t name_len; | ||
1305 | uint16_t old_editor_hint_len; | ||
1306 | int res; | ||
1307 | size_t key_len; | ||
1308 | size_t kb_read; | ||
1309 | |||
1310 | key_len = ntohs (er_msg->key_len); | ||
1311 | name_len = ntohs (er_msg->label_len); | ||
1312 | if ((GNUNET_SYSERR == | ||
1313 | GNUNET_CRYPTO_read_private_key_from_buffer (&er_msg[1], | ||
1314 | key_len, | ||
1315 | &zone, | ||
1316 | &kb_read)) || | ||
1317 | (kb_read != key_len)) | ||
1318 | { | ||
1319 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1320 | "Error reading private key\n"); | ||
1321 | GNUNET_SERVICE_client_drop (nc->client); | ||
1322 | return; | ||
1323 | } | ||
1324 | name_tmp = (const char *) &er_msg[1] + key_len; | ||
1325 | editor_hint = (const char *) name_tmp + name_len; | ||
1326 | GNUNET_SERVICE_client_continue (nc->client); | ||
1327 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1328 | "Received NAMESTORE_RECORD_SET_EDIT message for name `%s'\n", | ||
1329 | name_tmp); | ||
1330 | |||
1331 | conv_name = GNUNET_GNSRECORD_string_normalize (name_tmp); | ||
1332 | if (NULL == conv_name) | ||
1333 | { | ||
1334 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1335 | "Error converting name `%s'\n", | ||
1336 | name_tmp); | ||
1337 | GNUNET_SERVICE_client_drop (nc->client); | ||
1338 | return; | ||
1339 | } | ||
1340 | name_len = strlen (conv_name) + 1; | ||
1341 | rlc.label = conv_name; | ||
1342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1343 | "Looking up without filter\n"); | ||
1344 | rlc.filter = GNUNET_GNSRECORD_FILTER_NONE; | ||
1345 | rlc.found = GNUNET_NO; | ||
1346 | rlc.res_rd_count = 0; | ||
1347 | rlc.res_rd = NULL; | ||
1348 | rlc.rd_ser_len = 0; | ||
1349 | rlc.nick = get_nick_record (&zone); | ||
1350 | res = nc->GSN_database->edit_records (nc->GSN_database->cls, | ||
1351 | editor_hint, | ||
1352 | &zone, | ||
1353 | conv_name, | ||
1354 | &lookup_it, | ||
1355 | &rlc); | ||
1356 | |||
1357 | old_editor_hint_len = 0; | ||
1358 | if (NULL != rlc.editor_hint) | ||
1359 | old_editor_hint_len = strlen (rlc.editor_hint) + 1; | ||
1360 | env = | ||
1361 | GNUNET_MQ_msg_extra (rer_msg, | ||
1362 | rlc.rd_ser_len + old_editor_hint_len, | ||
1363 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT_RESPONSE); | ||
1364 | rer_msg->editor_hint_len = htons (old_editor_hint_len); | ||
1365 | rer_msg->gns_header.r_id = er_msg->gns_header.r_id; | ||
1366 | rer_msg->rd_count = htons (rlc.res_rd_count); | ||
1367 | rer_msg->rd_len = htons (rlc.rd_ser_len); | ||
1368 | if (GNUNET_YES == rlc.found) | ||
1369 | rer_msg->ec = htons (GNUNET_EC_NONE); | ||
1370 | else if (GNUNET_SYSERR == res) | ||
1371 | rer_msg->ec = htons (GNUNET_EC_NAMESTORE_UNKNOWN); | ||
1372 | else | ||
1373 | rer_msg->ec = htons (GNUNET_EC_NAMESTORE_NO_RESULTS); | ||
1374 | GNUNET_memcpy (&rer_msg[1], rlc.editor_hint, old_editor_hint_len); | ||
1375 | GNUNET_memcpy ((char*) &rer_msg[1] + old_editor_hint_len, rlc.res_rd, | ||
1376 | rlc.rd_ser_len); | ||
1377 | GNUNET_MQ_send (nc->mq, env); | ||
1378 | GNUNET_free (rlc.res_rd); | ||
1379 | GNUNET_free (conv_name); | ||
1380 | } | ||
1381 | |||
1382 | |||
1383 | /** | ||
1305 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message | 1384 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP message |
1306 | * | 1385 | * |
1307 | * @param cls client sending the message | 1386 | * @param cls client sending the message |
@@ -1353,9 +1432,9 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) | |||
1353 | key_len = ntohs (ll_msg->key_len); | 1432 | key_len = ntohs (ll_msg->key_len); |
1354 | if ((GNUNET_SYSERR == | 1433 | if ((GNUNET_SYSERR == |
1355 | GNUNET_CRYPTO_read_private_key_from_buffer (&ll_msg[1], | 1434 | GNUNET_CRYPTO_read_private_key_from_buffer (&ll_msg[1], |
1356 | key_len, | 1435 | key_len, |
1357 | &zone, | 1436 | &zone, |
1358 | &kb_read)) || | 1437 | &kb_read)) || |
1359 | (kb_read != key_len)) | 1438 | (kb_read != key_len)) |
1360 | { | 1439 | { |
1361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1440 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1388,19 +1467,11 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) | |||
1388 | rlc.res_rd = NULL; | 1467 | rlc.res_rd = NULL; |
1389 | rlc.rd_ser_len = 0; | 1468 | rlc.rd_ser_len = 0; |
1390 | rlc.nick = get_nick_record (&zone); | 1469 | rlc.nick = get_nick_record (&zone); |
1391 | if (GNUNET_YES != ntohs (ll_msg->is_edit_request)) | 1470 | res = nc->GSN_database->lookup_records (nc->GSN_database->cls, |
1392 | res = nc->GSN_database->lookup_records (nc->GSN_database->cls, | ||
1393 | &zone, | ||
1394 | conv_name, | ||
1395 | &lookup_it, | ||
1396 | &rlc); | ||
1397 | else | ||
1398 | res = nc->GSN_database->edit_records (nc->GSN_database->cls, | ||
1399 | &zone, | 1471 | &zone, |
1400 | conv_name, | 1472 | conv_name, |
1401 | &lookup_it, | 1473 | &lookup_it, |
1402 | &rlc); | 1474 | &rlc); |
1403 | |||
1404 | env = | 1475 | env = |
1405 | GNUNET_MQ_msg_extra (llr_msg, | 1476 | GNUNET_MQ_msg_extra (llr_msg, |
1406 | key_len + name_len + rlc.rd_ser_len, | 1477 | key_len + name_len + rlc.rd_ser_len, |
@@ -1427,7 +1498,6 @@ handle_record_lookup (void *cls, const struct LabelLookupMessage *ll_msg) | |||
1427 | } | 1498 | } |
1428 | 1499 | ||
1429 | 1500 | ||
1430 | |||
1431 | /** | 1501 | /** |
1432 | * Checks a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message | 1502 | * Checks a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message |
1433 | * | 1503 | * |
@@ -1458,6 +1528,7 @@ check_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1458 | return GNUNET_OK; | 1528 | return GNUNET_OK; |
1459 | } | 1529 | } |
1460 | 1530 | ||
1531 | |||
1461 | struct LookupExistingRecordsContext | 1532 | struct LookupExistingRecordsContext |
1462 | { | 1533 | { |
1463 | 1534 | ||
@@ -1488,6 +1559,7 @@ struct LookupExistingRecordsContext | |||
1488 | static void | 1559 | static void |
1489 | get_existing_rd_exp (void *cls, | 1560 | get_existing_rd_exp (void *cls, |
1490 | uint64_t seq, | 1561 | uint64_t seq, |
1562 | const char *editor_hint, | ||
1491 | const struct | 1563 | const struct |
1492 | GNUNET_CRYPTO_PrivateKey *private_key, | 1564 | GNUNET_CRYPTO_PrivateKey *private_key, |
1493 | const char *label, | 1565 | const char *label, |
@@ -1521,6 +1593,7 @@ get_existing_rd_exp (void *cls, | |||
1521 | } | 1593 | } |
1522 | } | 1594 | } |
1523 | 1595 | ||
1596 | |||
1524 | static enum GNUNET_ErrorCode | 1597 | static enum GNUNET_ErrorCode |
1525 | store_record_set (struct NamestoreClient *nc, | 1598 | store_record_set (struct NamestoreClient *nc, |
1526 | const struct GNUNET_CRYPTO_PrivateKey *private_key, | 1599 | const struct GNUNET_CRYPTO_PrivateKey *private_key, |
@@ -1635,8 +1708,6 @@ store_record_set (struct NamestoreClient *nc, | |||
1635 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && | 1708 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && |
1636 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type)) | 1709 | (GNUNET_GNSRECORD_TYPE_NICK == rd[i].record_type)) |
1637 | { | 1710 | { |
1638 | // FIXME: In case this is an uncommited transaction, | ||
1639 | // we should not do this here. Can we do this in the store activity? | ||
1640 | cache_nick (private_key, &rd[i]); | 1711 | cache_nick (private_key, &rd[i]); |
1641 | have_nick = GNUNET_YES; | 1712 | have_nick = GNUNET_YES; |
1642 | } | 1713 | } |
@@ -1681,9 +1752,6 @@ store_record_set (struct NamestoreClient *nc, | |||
1681 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && | 1752 | if ((0 == strcmp (GNUNET_GNS_EMPTY_LABEL_AT, conv_name)) && |
1682 | (GNUNET_NO == have_nick)) | 1753 | (GNUNET_NO == have_nick)) |
1683 | { | 1754 | { |
1684 | /* remove nick record from cache, in case we have one there */ | ||
1685 | // FIXME: In case this is an uncommited transaction, | ||
1686 | // we should not do this here. Can we do this in the store activity? | ||
1687 | cache_nick (private_key, NULL); | 1755 | cache_nick (private_key, NULL); |
1688 | } | 1756 | } |
1689 | res = nc->GSN_database->store_records (nc->GSN_database->cls, | 1757 | res = nc->GSN_database->store_records (nc->GSN_database->cls, |
@@ -1718,6 +1786,7 @@ store_record_set (struct NamestoreClient *nc, | |||
1718 | return ec; | 1786 | return ec; |
1719 | } | 1787 | } |
1720 | 1788 | ||
1789 | |||
1721 | /** | 1790 | /** |
1722 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message | 1791 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE message |
1723 | * | 1792 | * |
@@ -1748,9 +1817,9 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1748 | rs_len = rp_msg_len - rs_off; | 1817 | rs_len = rp_msg_len - rs_off; |
1749 | if ((GNUNET_SYSERR == | 1818 | if ((GNUNET_SYSERR == |
1750 | GNUNET_CRYPTO_read_private_key_from_buffer (&rp_msg[1], | 1819 | GNUNET_CRYPTO_read_private_key_from_buffer (&rp_msg[1], |
1751 | key_len, | 1820 | key_len, |
1752 | &zone, | 1821 | &zone, |
1753 | &kb_read)) || | 1822 | &kb_read)) || |
1754 | (kb_read != key_len)) | 1823 | (kb_read != key_len)) |
1755 | { | 1824 | { |
1756 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1825 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1786,130 +1855,9 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1786 | sa->rd_set_pos = 0; | 1855 | sa->rd_set_pos = 0; |
1787 | sa->private_key = zone; | 1856 | sa->private_key = zone; |
1788 | sa->zm_pos = monitor_head; | 1857 | sa->zm_pos = monitor_head; |
1789 | sa->uncommited = nc->in_transaction; | ||
1790 | continue_store_activity (sa, GNUNET_YES); | 1858 | continue_store_activity (sa, GNUNET_YES); |
1791 | } | 1859 | } |
1792 | 1860 | ||
1793 | static void | ||
1794 | send_tx_response (int rid, enum GNUNET_ErrorCode ec, struct NamestoreClient *nc) | ||
1795 | { | ||
1796 | struct TxControlResultMessage *txr_msg; | ||
1797 | struct GNUNET_MQ_Envelope *env; | ||
1798 | |||
1799 | env = | ||
1800 | GNUNET_MQ_msg (txr_msg, GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT); | ||
1801 | txr_msg->gns_header.r_id = rid; | ||
1802 | txr_msg->ec = htonl (ec); | ||
1803 | GNUNET_MQ_send (nc->mq, env); | ||
1804 | } | ||
1805 | |||
1806 | /** | ||
1807 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL message | ||
1808 | * | ||
1809 | * @param cls client sending the message | ||
1810 | * @param tx_msg message of type `struct TxControlMessage` | ||
1811 | */ | ||
1812 | static void | ||
1813 | handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) | ||
1814 | { | ||
1815 | struct NamestoreClient *nc = cls; | ||
1816 | struct StoreActivity *sa = sa_head; | ||
1817 | struct StoreActivity *sn; | ||
1818 | enum GNUNET_GenericReturnValue ret; | ||
1819 | char *emsg = NULL; | ||
1820 | int blocked = GNUNET_NO; | ||
1821 | |||
1822 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TX_CONTROL message\n"); | ||
1823 | |||
1824 | switch (ntohs (tx_msg->control)) | ||
1825 | { | ||
1826 | case GNUNET_NAMESTORE_TX_BEGIN: | ||
1827 | ret = nc->GSN_database->transaction_begin (nc->GSN_database->cls, | ||
1828 | &emsg); | ||
1829 | send_tx_response (tx_msg->gns_header.r_id, | ||
1830 | (GNUNET_SYSERR == ret) ? | ||
1831 | GNUNET_EC_NAMESTORE_BACKEND_FAILED : GNUNET_EC_NONE, nc); | ||
1832 | if (GNUNET_SYSERR == ret) | ||
1833 | { | ||
1834 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1835 | "Databse backend error: `%s'", emsg); | ||
1836 | GNUNET_free (emsg); | ||
1837 | } | ||
1838 | GNUNET_SERVICE_client_continue (nc->client); | ||
1839 | nc->in_transaction = GNUNET_YES; | ||
1840 | break; | ||
1841 | case GNUNET_NAMESTORE_TX_COMMIT: | ||
1842 | ret = nc->GSN_database->transaction_commit (nc->GSN_database->cls, | ||
1843 | &emsg); | ||
1844 | send_tx_response (tx_msg->gns_header.r_id, | ||
1845 | (GNUNET_SYSERR == ret) ? | ||
1846 | GNUNET_EC_NAMESTORE_BACKEND_FAILED : GNUNET_EC_NONE, | ||
1847 | nc); | ||
1848 | if (GNUNET_SYSERR == ret) | ||
1849 | { | ||
1850 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1851 | "Databse backend error: `%s'", emsg); | ||
1852 | GNUNET_free (emsg); | ||
1853 | } | ||
1854 | if (GNUNET_SYSERR != ret) | ||
1855 | { | ||
1856 | nc->in_transaction = GNUNET_NO; | ||
1857 | while (NULL != sa) | ||
1858 | { | ||
1859 | if ((nc != sa->nc) || | ||
1860 | (GNUNET_NO == sa->uncommited)) | ||
1861 | { | ||
1862 | sa = sa->next; | ||
1863 | continue; | ||
1864 | } | ||
1865 | sa->uncommited = GNUNET_NO; | ||
1866 | sn = sa->next; | ||
1867 | if (GNUNET_OK != continue_store_activity (sa, GNUNET_NO)) | ||
1868 | blocked = GNUNET_YES; | ||
1869 | sa = sn; | ||
1870 | } | ||
1871 | if (GNUNET_YES != blocked) | ||
1872 | GNUNET_SERVICE_client_continue (nc->client); | ||
1873 | } | ||
1874 | break; | ||
1875 | case GNUNET_NAMESTORE_TX_ROLLBACK: | ||
1876 | ret = nc->GSN_database->transaction_rollback (nc->GSN_database->cls, | ||
1877 | &emsg); | ||
1878 | send_tx_response (tx_msg->gns_header.r_id, | ||
1879 | (GNUNET_SYSERR == ret) ? | ||
1880 | GNUNET_EC_NAMESTORE_BACKEND_FAILED : GNUNET_EC_NONE, nc); | ||
1881 | GNUNET_SERVICE_client_continue (nc->client); | ||
1882 | if (GNUNET_SYSERR == ret) | ||
1883 | { | ||
1884 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1885 | "Databse backend error: `%s'", emsg); | ||
1886 | GNUNET_free (emsg); | ||
1887 | } | ||
1888 | if (GNUNET_SYSERR != ret) | ||
1889 | { | ||
1890 | nc->in_transaction = GNUNET_NO; | ||
1891 | while (NULL != sa) | ||
1892 | { | ||
1893 | if ((nc != sa->nc) || | ||
1894 | (GNUNET_NO == sa->uncommited)) | ||
1895 | { | ||
1896 | sa = sa->next; | ||
1897 | continue; | ||
1898 | } | ||
1899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1900 | "Discarding uncommited StoreActivity\n"); | ||
1901 | sn = sa->next; | ||
1902 | free_store_activity (sa); | ||
1903 | sa = sn; | ||
1904 | } | ||
1905 | } | ||
1906 | break; | ||
1907 | default: | ||
1908 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1909 | "Unknown control type %u\n", ntohs (tx_msg->control)); | ||
1910 | GNUNET_break (0); | ||
1911 | } | ||
1912 | } | ||
1913 | 1861 | ||
1914 | /** | 1862 | /** |
1915 | * Context for record remove operations passed from #handle_zone_to_name to | 1863 | * Context for record remove operations passed from #handle_zone_to_name to |
@@ -1949,6 +1897,7 @@ struct ZoneToNameCtx | |||
1949 | static void | 1897 | static void |
1950 | handle_zone_to_name_it (void *cls, | 1898 | handle_zone_to_name_it (void *cls, |
1951 | uint64_t seq, | 1899 | uint64_t seq, |
1900 | const char *editor_hint, | ||
1952 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, | 1901 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, |
1953 | const char *name, | 1902 | const char *name, |
1954 | unsigned int rd_count, | 1903 | unsigned int rd_count, |
@@ -1998,8 +1947,8 @@ handle_zone_to_name_it (void *cls, | |||
1998 | ztnr_msg->name_len = htons (name_len); | 1947 | ztnr_msg->name_len = htons (name_len); |
1999 | ztnr_msg->key_len = htons (key_len); | 1948 | ztnr_msg->key_len = htons (key_len); |
2000 | GNUNET_CRYPTO_write_private_key_to_buffer (zone_key, | 1949 | GNUNET_CRYPTO_write_private_key_to_buffer (zone_key, |
2001 | &ztnr_msg[1], | 1950 | &ztnr_msg[1], |
2002 | key_len); | 1951 | key_len); |
2003 | name_tmp = (char *) &ztnr_msg[1] + key_len; | 1952 | name_tmp = (char *) &ztnr_msg[1] + key_len; |
2004 | GNUNET_memcpy (name_tmp, name, name_len); | 1953 | GNUNET_memcpy (name_tmp, name, name_len); |
2005 | rd_tmp = &name_tmp[name_len]; | 1954 | rd_tmp = &name_tmp[name_len]; |
@@ -2010,6 +1959,7 @@ handle_zone_to_name_it (void *cls, | |||
2010 | GNUNET_MQ_send (ztn_ctx->nc->mq, env); | 1959 | GNUNET_MQ_send (ztn_ctx->nc->mq, env); |
2011 | } | 1960 | } |
2012 | 1961 | ||
1962 | |||
2013 | static enum GNUNET_GenericReturnValue | 1963 | static enum GNUNET_GenericReturnValue |
2014 | check_zone_to_name (void *cls, | 1964 | check_zone_to_name (void *cls, |
2015 | const struct ZoneToNameMessage *zis_msg) | 1965 | const struct ZoneToNameMessage *zis_msg) |
@@ -2044,9 +1994,9 @@ handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) | |||
2044 | key_len = ntohs (ztn_msg->key_len); | 1994 | key_len = ntohs (ztn_msg->key_len); |
2045 | if ((GNUNET_SYSERR == | 1995 | if ((GNUNET_SYSERR == |
2046 | GNUNET_CRYPTO_read_private_key_from_buffer (&ztn_msg[1], | 1996 | GNUNET_CRYPTO_read_private_key_from_buffer (&ztn_msg[1], |
2047 | key_len, | 1997 | key_len, |
2048 | &zone, | 1998 | &zone, |
2049 | &kb_read)) || | 1999 | &kb_read)) || |
2050 | (kb_read != key_len)) | 2000 | (kb_read != key_len)) |
2051 | { | 2001 | { |
2052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2058,10 +2008,10 @@ handle_zone_to_name (void *cls, const struct ZoneToNameMessage *ztn_msg) | |||
2058 | pkey_len = ntohs (ztn_msg->pkey_len); | 2008 | pkey_len = ntohs (ztn_msg->pkey_len); |
2059 | if ((GNUNET_SYSERR == | 2009 | if ((GNUNET_SYSERR == |
2060 | GNUNET_CRYPTO_read_public_key_from_buffer ((char*) &ztn_msg[1] | 2010 | GNUNET_CRYPTO_read_public_key_from_buffer ((char*) &ztn_msg[1] |
2061 | + key_len, | 2011 | + key_len, |
2062 | pkey_len, | 2012 | pkey_len, |
2063 | &value_zone, | 2013 | &value_zone, |
2064 | &kb_read)) || | 2014 | &kb_read)) || |
2065 | (kb_read != pkey_len)) | 2015 | (kb_read != pkey_len)) |
2066 | { | 2016 | { |
2067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2017 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2133,6 +2083,7 @@ struct ZoneIterationProcResult | |||
2133 | static void | 2083 | static void |
2134 | zone_iterate_proc (void *cls, | 2084 | zone_iterate_proc (void *cls, |
2135 | uint64_t seq, | 2085 | uint64_t seq, |
2086 | const char *editor_hint, | ||
2136 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, | 2087 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, |
2137 | const char *name, | 2088 | const char *name, |
2138 | unsigned int rd_count, | 2089 | unsigned int rd_count, |
@@ -2225,6 +2176,7 @@ run_zone_iteration_round (struct ZoneIteration *zi, uint64_t limit) | |||
2225 | zone_iteration_done_client_continue (zi); | 2176 | zone_iteration_done_client_continue (zi); |
2226 | } | 2177 | } |
2227 | 2178 | ||
2179 | |||
2228 | static enum GNUNET_GenericReturnValue | 2180 | static enum GNUNET_GenericReturnValue |
2229 | check_iteration_start (void *cls, | 2181 | check_iteration_start (void *cls, |
2230 | const struct ZoneIterationStartMessage *zis_msg) | 2182 | const struct ZoneIterationStartMessage *zis_msg) |
@@ -2268,9 +2220,9 @@ handle_iteration_start (void *cls, | |||
2268 | { | 2220 | { |
2269 | if ((GNUNET_SYSERR == | 2221 | if ((GNUNET_SYSERR == |
2270 | GNUNET_CRYPTO_read_private_key_from_buffer (&zis_msg[1], | 2222 | GNUNET_CRYPTO_read_private_key_from_buffer (&zis_msg[1], |
2271 | key_len, | 2223 | key_len, |
2272 | &zone, | 2224 | &zone, |
2273 | &kb_read)) || | 2225 | &kb_read)) || |
2274 | (kb_read != key_len)) | 2226 | (kb_read != key_len)) |
2275 | { | 2227 | { |
2276 | GNUNET_SERVICE_client_drop (nc->client); | 2228 | GNUNET_SERVICE_client_drop (nc->client); |
@@ -2443,6 +2395,7 @@ monitor_iteration_next (void *cls); | |||
2443 | static void | 2395 | static void |
2444 | monitor_iterate_cb (void *cls, | 2396 | monitor_iterate_cb (void *cls, |
2445 | uint64_t seq, | 2397 | uint64_t seq, |
2398 | const char *editor_hint, | ||
2446 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, | 2399 | const struct GNUNET_CRYPTO_PrivateKey *zone_key, |
2447 | const char *name, | 2400 | const char *name, |
2448 | unsigned int rd_count, | 2401 | unsigned int rd_count, |
@@ -2476,6 +2429,7 @@ monitor_iterate_cb (void *cls, | |||
2476 | } | 2429 | } |
2477 | } | 2430 | } |
2478 | 2431 | ||
2432 | |||
2479 | static enum GNUNET_GenericReturnValue | 2433 | static enum GNUNET_GenericReturnValue |
2480 | check_monitor_start (void *cls, | 2434 | check_monitor_start (void *cls, |
2481 | const struct ZoneMonitorStartMessage *zis_msg) | 2435 | const struct ZoneMonitorStartMessage *zis_msg) |
@@ -2520,9 +2474,9 @@ handle_monitor_start (void *cls, const struct | |||
2520 | { | 2474 | { |
2521 | if ((GNUNET_SYSERR == | 2475 | if ((GNUNET_SYSERR == |
2522 | GNUNET_CRYPTO_read_private_key_from_buffer (&zis_msg[1], | 2476 | GNUNET_CRYPTO_read_private_key_from_buffer (&zis_msg[1], |
2523 | key_len, | 2477 | key_len, |
2524 | &zone, | 2478 | &zone, |
2525 | &kb_read)) || | 2479 | &kb_read)) || |
2526 | (kb_read != key_len)) | 2480 | (kb_read != key_len)) |
2527 | { | 2481 | { |
2528 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2482 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -2594,6 +2548,7 @@ monitor_iteration_next (void *cls) | |||
2594 | } | 2548 | } |
2595 | } | 2549 | } |
2596 | 2550 | ||
2551 | |||
2597 | /** | 2552 | /** |
2598 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT message | 2553 | * Handles a #GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT message |
2599 | * | 2554 | * |
@@ -2652,6 +2607,7 @@ handle_monitor_next (void *cls, const struct ZoneMonitorNextMessage *nm) | |||
2652 | } | 2607 | } |
2653 | } | 2608 | } |
2654 | 2609 | ||
2610 | |||
2655 | /** | 2611 | /** |
2656 | * Process namestore requests. | 2612 | * Process namestore requests. |
2657 | * | 2613 | * |
@@ -2710,14 +2666,14 @@ GNUNET_SERVICE_MAIN ( | |||
2710 | &client_connect_cb, | 2666 | &client_connect_cb, |
2711 | &client_disconnect_cb, | 2667 | &client_disconnect_cb, |
2712 | NULL, | 2668 | NULL, |
2713 | GNUNET_MQ_hd_fixed_size (tx_control, | ||
2714 | GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL, | ||
2715 | struct TxControlMessage, | ||
2716 | NULL), | ||
2717 | GNUNET_MQ_hd_var_size (record_store, | 2669 | GNUNET_MQ_hd_var_size (record_store, |
2718 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, | 2670 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE, |
2719 | struct RecordStoreMessage, | 2671 | struct RecordStoreMessage, |
2720 | NULL), | 2672 | NULL), |
2673 | GNUNET_MQ_hd_var_size (edit_record_set, | ||
2674 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_SET_EDIT, | ||
2675 | struct EditRecordSetMessage, | ||
2676 | NULL), | ||
2721 | GNUNET_MQ_hd_var_size (record_lookup, | 2677 | GNUNET_MQ_hd_var_size (record_lookup, |
2722 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, | 2678 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP, |
2723 | struct LabelLookupMessage, | 2679 | struct LabelLookupMessage, |