diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-28 23:13:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-28 23:13:32 +0000 |
commit | 49a8faaa2968fdc4291baee50b6a2636d0340e8a (patch) | |
tree | e4a15e2ba6fa3b2c913dee12a34027a64899fb18 /src/namestore | |
parent | bf760b3f47cae6c7d5a0e9cf4f617f0595515273 (diff) | |
download | gnunet-49a8faaa2968fdc4291baee50b6a2636d0340e8a.tar.gz gnunet-49a8faaa2968fdc4291baee50b6a2636d0340e8a.zip |
-more namestore code cleanup
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 547 | ||||
-rw-r--r-- | src/namestore/test_namestore_api_zone_iteration.c | 2 |
2 files changed, 203 insertions, 346 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 83cad685b..dd1e3f69d 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -297,6 +297,44 @@ zone_to_disk_it (void *cls, | |||
297 | 297 | ||
298 | 298 | ||
299 | /** | 299 | /** |
300 | * Add the given private key to the set of private keys | ||
301 | * this namestore can use to sign records when needed. | ||
302 | * | ||
303 | * @param pkey private key to add to our list (reference will | ||
304 | * be taken over or freed and should not be used afterwards) | ||
305 | */ | ||
306 | static void | ||
307 | learn_private_key (struct GNUNET_CRYPTO_RsaPrivateKey *pkey) | ||
308 | { | ||
309 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | ||
310 | struct GNUNET_HashCode long_hash; | ||
311 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; | ||
312 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | ||
313 | |||
314 | GNUNET_CRYPTO_rsa_key_get_public (pkey, &pub); | ||
315 | GNUNET_CRYPTO_short_hash (&pub, | ||
316 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
317 | &pubkey_hash); | ||
318 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); | ||
319 | |||
320 | if (GNUNET_NO != GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | ||
321 | { | ||
322 | GNUNET_CRYPTO_rsa_key_free (pkey); | ||
323 | return; | ||
324 | } | ||
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
326 | "Received new private key for zone `%s'\n", | ||
327 | GNUNET_short_h2s(&pubkey_hash)); | ||
328 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | ||
329 | cc->privkey = pkey; | ||
330 | cc->zone = pubkey_hash; | ||
331 | GNUNET_assert (GNUNET_YES == | ||
332 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, | ||
333 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
334 | } | ||
335 | |||
336 | |||
337 | /** | ||
300 | * Returns the expiration time of the given block of records. The block | 338 | * Returns the expiration time of the given block of records. The block |
301 | * expiration time is the expiration time of the block with smallest | 339 | * expiration time is the expiration time of the block with smallest |
302 | * expiration time. | 340 | * expiration time. |
@@ -412,8 +450,7 @@ client_disconnect_notification (void *cls, | |||
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 450 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
413 | "Client %p disconnected\n", | 451 | "Client %p disconnected\n", |
414 | client); | 452 | client); |
415 | nc = client_lookup (client); | 453 | if (NULL == (nc = client_lookup (client))) |
416 | if (NULL == nc) | ||
417 | return; | 454 | return; |
418 | while (NULL != (no = nc->op_head)) | 455 | while (NULL != (no = nc->op_head)) |
419 | { | 456 | { |
@@ -693,7 +730,7 @@ handle_lookup_name (void *cls, | |||
693 | return; | 730 | return; |
694 | } | 731 | } |
695 | name = (const char *) &ln_msg[1]; | 732 | name = (const char *) &ln_msg[1]; |
696 | if (name[name_len -1] != '\0') | 733 | if ('\0' != name[name_len -1]) |
697 | { | 734 | { |
698 | GNUNET_break (0); | 735 | GNUNET_break (0); |
699 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 736 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -830,7 +867,7 @@ handle_record_put (void *cls, | |||
830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
831 | "Putting record for name `%s': %s\n", | 868 | "Putting record for name `%s': %s\n", |
832 | name, | 869 | name, |
833 | (res == GNUNET_OK) ? "OK" : "FAILED"); | 870 | (GNUNET_OK == res) ? "OK" : "FAILED"); |
834 | } | 871 | } |
835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
836 | "Sending `%s' message\n", | 873 | "Sending `%s' message\n", |
@@ -861,7 +898,7 @@ struct CreateRecordContext | |||
861 | /** | 898 | /** |
862 | * Zone's public key | 899 | * Zone's public key |
863 | */ | 900 | */ |
864 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; | 901 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; |
865 | 902 | ||
866 | /** | 903 | /** |
867 | * Name for the record to create | 904 | * Name for the record to create |
@@ -987,7 +1024,7 @@ handle_create_record_it (void *cls, | |||
987 | block_expiration = GNUNET_TIME_absolute_max (crc->expire, expire); | 1024 | block_expiration = GNUNET_TIME_absolute_max (crc->expire, expire); |
988 | if (GNUNET_OK != | 1025 | if (GNUNET_OK != |
989 | GSN_database->put_records (GSN_database->cls, | 1026 | GSN_database->put_records (GSN_database->cls, |
990 | crc->pubkey, | 1027 | &crc->pubkey, |
991 | block_expiration, | 1028 | block_expiration, |
992 | crc->name, | 1029 | crc->name, |
993 | rd_count_new, rd_new, | 1030 | rd_count_new, rd_new, |
@@ -1015,13 +1052,9 @@ handle_record_create (void *cls, | |||
1015 | { | 1052 | { |
1016 | struct GNUNET_NAMESTORE_Client *nc; | 1053 | struct GNUNET_NAMESTORE_Client *nc; |
1017 | const struct RecordCreateMessage *rp_msg; | 1054 | const struct RecordCreateMessage *rp_msg; |
1018 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | ||
1019 | struct CreateRecordContext crc; | 1055 | struct CreateRecordContext crc; |
1020 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 1056 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
1021 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | ||
1022 | struct RecordCreateResponseMessage rcr_msg; | 1057 | struct RecordCreateResponseMessage rcr_msg; |
1023 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; | ||
1024 | struct GNUNET_HashCode long_hash; | ||
1025 | size_t name_len; | 1058 | size_t name_len; |
1026 | size_t msg_size; | 1059 | size_t msg_size; |
1027 | size_t msg_size_exp; | 1060 | size_t msg_size_exp; |
@@ -1034,6 +1067,7 @@ handle_record_create (void *cls, | |||
1034 | unsigned int rd_count; | 1067 | unsigned int rd_count; |
1035 | int res; | 1068 | int res; |
1036 | struct GNUNET_NAMESTORE_RecordData rd; | 1069 | struct GNUNET_NAMESTORE_RecordData rd; |
1070 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; | ||
1037 | 1071 | ||
1038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1072 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1039 | "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); | 1073 | "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); |
@@ -1072,7 +1106,7 @@ handle_record_create (void *cls, | |||
1072 | pkey_tmp = (const char *) &rp_msg[1]; | 1106 | pkey_tmp = (const char *) &rp_msg[1]; |
1073 | name_tmp = &pkey_tmp[key_len]; | 1107 | name_tmp = &pkey_tmp[key_len]; |
1074 | rd_ser = &name_tmp[name_len]; | 1108 | rd_ser = &name_tmp[name_len]; |
1075 | if (name_tmp[name_len -1] != '\0') | 1109 | if ('\0' != name_tmp[name_len -1]) |
1076 | { | 1110 | { |
1077 | GNUNET_break (0); | 1111 | GNUNET_break (0); |
1078 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1112 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -1094,32 +1128,16 @@ handle_record_create (void *cls, | |||
1094 | } | 1128 | } |
1095 | 1129 | ||
1096 | /* Extracting and converting private key */ | 1130 | /* Extracting and converting private key */ |
1097 | GNUNET_CRYPTO_rsa_key_get_public (pkey, &pub); | 1131 | GNUNET_CRYPTO_rsa_key_get_public (pkey, &crc.pubkey); |
1098 | GNUNET_CRYPTO_short_hash (&pub, | 1132 | GNUNET_CRYPTO_short_hash (&crc.pubkey, |
1099 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 1133 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1100 | &pubkey_hash); | 1134 | &pubkey_hash); |
1101 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); | 1135 | learn_private_key (pkey); |
1102 | |||
1103 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | ||
1104 | { | ||
1105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1106 | "Received new private key for zone `%s'\n", | ||
1107 | GNUNET_short_h2s(&pubkey_hash)); | ||
1108 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | ||
1109 | cc->privkey = pkey; | ||
1110 | pkey = NULL; | ||
1111 | cc->zone = pubkey_hash; | ||
1112 | GNUNET_assert (GNUNET_YES == | ||
1113 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, cc, | ||
1114 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1115 | } | ||
1116 | |||
1117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1118 | "Creating record for name `%s' in zone `%s'\n", | 1137 | "Creating record for name `%s' in zone `%s'\n", |
1119 | name_tmp, GNUNET_short_h2s(&pubkey_hash)); | 1138 | name_tmp, GNUNET_short_h2s(&pubkey_hash)); |
1120 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); | 1139 | crc.expire = GNUNET_TIME_absolute_ntoh(rp_msg->expire); |
1121 | crc.res = GNUNET_SYSERR; | 1140 | crc.res = GNUNET_SYSERR; |
1122 | crc.pubkey = &pub; | ||
1123 | crc.rd = &rd; | 1141 | crc.rd = &rd; |
1124 | crc.name = name_tmp; | 1142 | crc.name = name_tmp; |
1125 | 1143 | ||
@@ -1128,8 +1146,6 @@ handle_record_create (void *cls, | |||
1128 | &handle_create_record_it, &crc); | 1146 | &handle_create_record_it, &crc); |
1129 | if (res != GNUNET_SYSERR) | 1147 | if (res != GNUNET_SYSERR) |
1130 | res = GNUNET_OK; | 1148 | res = GNUNET_OK; |
1131 | if (NULL != pkey) | ||
1132 | GNUNET_CRYPTO_rsa_key_free (pkey); | ||
1133 | 1149 | ||
1134 | /* Send response */ | 1150 | /* Send response */ |
1135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1301,10 +1317,8 @@ handle_record_remove (void *cls, | |||
1301 | const struct RecordRemoveMessage *rr_msg; | 1317 | const struct RecordRemoveMessage *rr_msg; |
1302 | struct RecordRemoveResponseMessage rrr_msg; | 1318 | struct RecordRemoveResponseMessage rrr_msg; |
1303 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 1319 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
1304 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | ||
1305 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 1320 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
1306 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; | 1321 | struct GNUNET_CRYPTO_ShortHashCode pubkey_hash; |
1307 | struct GNUNET_HashCode long_hash; | ||
1308 | struct GNUNET_NAMESTORE_RecordData rd; | 1322 | struct GNUNET_NAMESTORE_RecordData rd; |
1309 | const char *pkey_tmp; | 1323 | const char *pkey_tmp; |
1310 | const char *name_tmp; | 1324 | const char *name_tmp; |
@@ -1373,24 +1387,7 @@ handle_record_remove (void *cls, | |||
1373 | GNUNET_CRYPTO_short_hash (&pub, | 1387 | GNUNET_CRYPTO_short_hash (&pub, |
1374 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 1388 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
1375 | &pubkey_hash); | 1389 | &pubkey_hash); |
1376 | GNUNET_CRYPTO_short_hash_double (&pubkey_hash, &long_hash); | 1390 | learn_private_key (pkey); |
1377 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (zonekeys, &long_hash)) | ||
1378 | { | ||
1379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1380 | "Received new private key for zone `%s'\n", | ||
1381 | GNUNET_short_h2s (&pubkey_hash)); | ||
1382 | cc = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | ||
1383 | cc->privkey = pkey; | ||
1384 | pkey = NULL; | ||
1385 | cc->zone = pubkey_hash; | ||
1386 | GNUNET_assert (GNUNET_YES == | ||
1387 | GNUNET_CONTAINER_multihashmap_put (zonekeys, | ||
1388 | &long_hash, cc, | ||
1389 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1390 | } | ||
1391 | if (NULL != pkey) | ||
1392 | GNUNET_CRYPTO_rsa_key_free (pkey); | ||
1393 | |||
1394 | if (GNUNET_OK != | 1391 | if (GNUNET_OK != |
1395 | GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, &rd)) | 1392 | GNUNET_NAMESTORE_records_deserialize (rd_ser_len, rd_ser, rd_count, &rd)) |
1396 | { | 1393 | { |
@@ -1407,7 +1404,7 @@ handle_record_remove (void *cls, | |||
1407 | name_tmp); | 1404 | name_tmp); |
1408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1409 | "Removing name `%s': %s\n", | 1406 | "Removing name `%s': %s\n", |
1410 | name_tmp, (GNUNET_OK == res) ? "OK" : "FAIL"); | 1407 | name_tmp, (GNUNET_OK == res) ? "OK" : "FAILED"); |
1411 | if (GNUNET_OK != res) | 1408 | if (GNUNET_OK != res) |
1412 | /* Could not remove entry from database */ | 1409 | /* Could not remove entry from database */ |
1413 | res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE; | 1410 | res = RECORD_REMOVE_RESULT_FAILED_TO_PUT_UPDATE; |
@@ -1614,28 +1611,9 @@ handle_zone_to_name (void *cls, | |||
1614 | } | 1611 | } |
1615 | 1612 | ||
1616 | 1613 | ||
1617 | ///////////////////////////////////////////////////////////// | ||
1618 | |||
1619 | |||
1620 | /** | ||
1621 | * Copy record, data has to be free'd separetely | ||
1622 | * | ||
1623 | * @param src source record | ||
1624 | * @param dest destination record | ||
1625 | */ | ||
1626 | static void | ||
1627 | copy_record (const struct GNUNET_NAMESTORE_RecordData *src, | ||
1628 | struct GNUNET_NAMESTORE_RecordData *dest) | ||
1629 | { | ||
1630 | memcpy (dest, src, sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
1631 | dest->data = GNUNET_malloc (src->data_size); | ||
1632 | memcpy ((void *) dest->data, src->data, src->data_size); | ||
1633 | } | ||
1634 | |||
1635 | |||
1636 | /** | 1614 | /** |
1637 | * Context for record remove operations passed from | 1615 | * Context for record remove operations passed from |
1638 | * 'find_next_zone_iteration_result' to 'zone_iteraterate_proc' as closure | 1616 | * 'run_zone_iteration_round' to 'zone_iteraterate_proc' as closure |
1639 | */ | 1617 | */ |
1640 | struct ZoneIterationProcResult | 1618 | struct ZoneIterationProcResult |
1641 | { | 1619 | { |
@@ -1645,49 +1623,13 @@ struct ZoneIterationProcResult | |||
1645 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 1623 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
1646 | 1624 | ||
1647 | /** | 1625 | /** |
1648 | * Iteration result: iteration done? | 1626 | * Iteration result: iteration done? Set to GNUNET_YES |
1627 | * if there are no further results, GNUNET_NO if there | ||
1628 | * may be more results overall but we got one for now, | ||
1629 | * GNUNET_SYSERR if all results were filtered so far. | ||
1649 | */ | 1630 | */ |
1650 | int res_iteration_finished; | 1631 | int res_iteration_finished; |
1651 | 1632 | ||
1652 | /** | ||
1653 | * Iteration result: number of records included | ||
1654 | */ | ||
1655 | int records_included; | ||
1656 | |||
1657 | /** | ||
1658 | * Iteration result: is a valid signature included? | ||
1659 | */ | ||
1660 | int has_signature; | ||
1661 | |||
1662 | /** | ||
1663 | * Name???? | ||
1664 | */ | ||
1665 | char *name; | ||
1666 | |||
1667 | /** | ||
1668 | * Zone hash | ||
1669 | */ | ||
1670 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; | ||
1671 | |||
1672 | /** | ||
1673 | * Record data | ||
1674 | */ | ||
1675 | struct GNUNET_NAMESTORE_RecordData *rd; | ||
1676 | |||
1677 | /** | ||
1678 | * Zone's public key | ||
1679 | */ | ||
1680 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; | ||
1681 | |||
1682 | /** | ||
1683 | * Signature | ||
1684 | */ | ||
1685 | struct GNUNET_CRYPTO_RsaSignature signature; | ||
1686 | |||
1687 | /** | ||
1688 | * Expiration date | ||
1689 | */ | ||
1690 | struct GNUNET_TIME_Absolute expire; | ||
1691 | }; | 1633 | }; |
1692 | 1634 | ||
1693 | 1635 | ||
@@ -1712,248 +1654,155 @@ zone_iteraterate_proc (void *cls, | |||
1712 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 1654 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
1713 | { | 1655 | { |
1714 | struct ZoneIterationProcResult *proc = cls; | 1656 | struct ZoneIterationProcResult *proc = cls; |
1715 | struct GNUNET_NAMESTORE_RecordData *rd_filtered; | 1657 | struct GNUNET_NAMESTORE_RecordData rd_filtered[rd_count]; |
1716 | struct GNUNET_CRYPTO_RsaSignature *new_signature; | 1658 | struct GNUNET_CRYPTO_RsaSignature *new_signature; |
1717 | struct GNUNET_NAMESTORE_CryptoContainer *cc; | 1659 | struct GNUNET_NAMESTORE_CryptoContainer *cc; |
1718 | struct GNUNET_CRYPTO_ShortHashCode hash; | ||
1719 | struct GNUNET_HashCode long_hash; | 1660 | struct GNUNET_HashCode long_hash; |
1720 | struct GNUNET_TIME_Absolute e; | 1661 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; |
1721 | unsigned int rd_count_filtered = 0; | 1662 | struct ZoneIterationResponseMessage *zir_msg; |
1663 | unsigned int rd_count_filtered; | ||
1664 | unsigned int c; | ||
1665 | size_t name_len; | ||
1666 | size_t rd_ser_len; | ||
1667 | size_t msg_size; | ||
1668 | char *name_tmp; | ||
1669 | char *rd_ser; | ||
1722 | int include; | 1670 | int include; |
1723 | int c; | ||
1724 | 1671 | ||
1725 | proc->res_iteration_finished = GNUNET_NO; | 1672 | proc->res_iteration_finished = GNUNET_NO; |
1726 | proc->records_included = 0; | 1673 | if ((NULL == zone_key) && (NULL == name)) |
1727 | |||
1728 | if ((zone_key == NULL) && (name == NULL)) | ||
1729 | { | 1674 | { |
1730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration done\n"); | 1675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1676 | "Iteration done\n"); | ||
1731 | proc->res_iteration_finished = GNUNET_YES; | 1677 | proc->res_iteration_finished = GNUNET_YES; |
1732 | proc->rd = NULL; | 1678 | return; |
1733 | proc->name = NULL; | ||
1734 | } | 1679 | } |
1735 | else if ((zone_key != NULL) && (name != NULL)) /* just a safety check */ | 1680 | if ((NULL == zone_key) || (NULL == name)) |
1736 | { | 1681 | { |
1737 | rd_filtered = GNUNET_malloc (rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | 1682 | /* what is this!? should never happen */ |
1738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received result for zone iteration: `%s'\n", name); | 1683 | GNUNET_break (0); |
1739 | for (c = 0; c < rd_count; c++) | 1684 | return; |
1685 | } | ||
1686 | rd_count_filtered = 0; | ||
1687 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1688 | "Received result for zone iteration: `%s'\n", | ||
1689 | name); | ||
1690 | for (c = 0; c < rd_count; c++) | ||
1691 | { | ||
1692 | // FIXME: new expiration flags need additional special treatment here! | ||
1693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1694 | "Record %i has flags: 0x%x must have 0x%x \n", | ||
1695 | c, rd[c].flags, | ||
1696 | proc->zi->must_have_flags); | ||
1697 | include = GNUNET_YES; | ||
1698 | /* Checking must have flags */ | ||
1699 | if ((rd[c].flags & proc->zi->must_have_flags) == proc->zi->must_have_flags) | ||
1740 | { | 1700 | { |
1741 | include = GNUNET_YES; | 1701 | /* Include */ |
1742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: 0x%x must have 0x%x \n", | 1702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Include \n", c); |
1743 | c, rd[c].flags, proc->zi->must_have_flags); | ||
1744 | /* Checking must have flags */ | ||
1745 | if ((rd[c].flags & proc->zi->must_have_flags) == proc->zi->must_have_flags) | ||
1746 | { | ||
1747 | /* Include */ | ||
1748 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Include \n", c); | ||
1749 | } | ||
1750 | else | ||
1751 | { | ||
1752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Not include \n", c); | ||
1753 | include = GNUNET_NO; | ||
1754 | } | ||
1755 | |||
1756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: 0x%x must not have 0x%x\n", | ||
1757 | c, rd[c].flags, proc->zi->must_not_have_flags); | ||
1758 | if ((rd[c].flags & proc->zi->must_not_have_flags) != 0) | ||
1759 | { | ||
1760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Not include \n", c); | ||
1761 | include = GNUNET_NO; | ||
1762 | } | ||
1763 | else | ||
1764 | { | ||
1765 | /* Include */ | ||
1766 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Include \n", c); | ||
1767 | } | ||
1768 | if (GNUNET_YES == include) | ||
1769 | { | ||
1770 | copy_record (&rd[c], &rd_filtered[rd_count_filtered]); | ||
1771 | rd_count_filtered++; | ||
1772 | } | ||
1773 | |||
1774 | } | 1703 | } |
1775 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Included %i of %i records \n", rd_count_filtered, rd_count); | 1704 | else |
1776 | |||
1777 | proc->records_included = rd_count_filtered; | ||
1778 | if (0 == rd_count_filtered) | ||
1779 | { | 1705 | { |
1780 | GNUNET_free (rd_filtered); | 1706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Not include \n", c); |
1781 | rd_filtered = NULL; | 1707 | include = GNUNET_NO; |
1782 | } | 1708 | } |
1783 | proc->rd = rd_filtered; | 1709 | |
1784 | proc->name = GNUNET_strdup(name); | 1710 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1785 | memcpy (&proc->zone_key, zone_key, sizeof (proc->zone_key)); | 1711 | "Record %i has flags: 0x%x must not have 0x%x\n", |
1786 | 1712 | c, rd[c].flags, proc->zi->must_not_have_flags); | |
1787 | /* Signature */ | 1713 | if (0 != (rd[c].flags & proc->zi->must_not_have_flags)) |
1788 | proc->has_signature = GNUNET_NO; | ||
1789 | GNUNET_CRYPTO_short_hash (zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &hash); | ||
1790 | GNUNET_CRYPTO_short_hash_double(&hash, &long_hash); | ||
1791 | proc->zone_hash = hash; | ||
1792 | |||
1793 | if (GNUNET_CONTAINER_multihashmap_contains(zonekeys, &long_hash)) | ||
1794 | { | 1714 | { |
1795 | cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash); | 1715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1796 | e = get_block_expiration_time(rd_count_filtered, rd_filtered); | 1716 | "Record %i has flags: Not include \n", c); |
1797 | proc->expire = e; | 1717 | include = GNUNET_NO; |
1798 | new_signature = GNUNET_NAMESTORE_create_signature(cc->privkey, e, name, rd_filtered, rd_count_filtered); | ||
1799 | GNUNET_assert (signature != NULL); | ||
1800 | proc->signature = (*new_signature); | ||
1801 | GNUNET_free (new_signature); | ||
1802 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating signature for `%s' in zone `%s' with %u records and expiration %llu\n", | ||
1803 | name, GNUNET_short_h2s(&hash), rd_count_filtered, e.abs_value); | ||
1804 | proc->has_signature = GNUNET_YES; | ||
1805 | } | 1718 | } |
1806 | else if (rd_count_filtered == rd_count) | 1719 | else |
1807 | { | 1720 | { |
1808 | proc->expire = expire; | 1721 | /* Include */ |
1809 | if (NULL != signature) | 1722 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Record %i has flags: Include \n", c); |
1810 | { | ||
1811 | proc->signature = (*signature); | ||
1812 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using provided signature for `%s' in zone `%s' with %u records and expiration %llu\n", | ||
1813 | name, GNUNET_short_h2s(&hash), rd_count_filtered, expire.abs_value); | ||
1814 | proc->has_signature = GNUNET_YES; | ||
1815 | } | ||
1816 | else | ||
1817 | { | ||
1818 | memset (&proc->signature, '\0', sizeof (proc->signature)); | ||
1819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No signature provided for `%s'\n", name); | ||
1820 | } | ||
1821 | } | 1723 | } |
1724 | if (GNUNET_YES == include) | ||
1725 | rd_filtered[rd_count_filtered++] = rd[c]; | ||
1822 | } | 1726 | } |
1823 | else | 1727 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1728 | "Included %u of %u records\n", | ||
1729 | rd_count_filtered, rd_count); | ||
1730 | |||
1731 | /* compute / obtain signature */ | ||
1732 | GNUNET_CRYPTO_short_hash (zone_key, | ||
1733 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
1734 | &zone_hash); | ||
1735 | GNUNET_CRYPTO_short_hash_double (&zone_hash, &long_hash); | ||
1736 | if (NULL != (cc = GNUNET_CONTAINER_multihashmap_get(zonekeys, &long_hash))) | ||
1824 | { | 1737 | { |
1825 | GNUNET_break (0); | 1738 | expire = get_block_expiration_time (rd_count_filtered, rd_filtered); |
1826 | return; | 1739 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1740 | "Creating signature for `%s' in zone `%s' with %u records and expiration %llu\n", | ||
1741 | name, GNUNET_short_h2s(&zone_hash), | ||
1742 | rd_count_filtered, | ||
1743 | (unsigned long long) expire.abs_value); | ||
1744 | new_signature = GNUNET_NAMESTORE_create_signature (cc->privkey, expire, name, | ||
1745 | rd_filtered, rd_count_filtered); | ||
1746 | GNUNET_assert (NULL != signature); | ||
1747 | signature = new_signature; | ||
1827 | } | 1748 | } |
1828 | } | 1749 | else if (rd_count_filtered == rd_count) |
1829 | |||
1830 | |||
1831 | ///////////////////////////////////////////////////////////// | ||
1832 | |||
1833 | |||
1834 | /** | ||
1835 | * Find next zone iteration result in database | ||
1836 | * | ||
1837 | * @param proc the zone iteration processing to use | ||
1838 | */ | ||
1839 | static void | ||
1840 | find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) | ||
1841 | { | ||
1842 | struct GNUNET_CRYPTO_ShortHashCode *zone; | ||
1843 | |||
1844 | if (GNUNET_YES == proc->zi->has_zone) | ||
1845 | zone = &proc->zi->zone; | ||
1846 | else | ||
1847 | zone = NULL; | ||
1848 | do | ||
1849 | { | 1750 | { |
1850 | if (GNUNET_SYSERR == | 1751 | if (NULL != signature) |
1851 | GSN_database->iterate_records (GSN_database->cls, zone, NULL, | ||
1852 | proc->zi->offset, | ||
1853 | &zone_iteraterate_proc, proc)) | ||
1854 | { | 1752 | { |
1855 | GNUNET_break (0); | 1753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1856 | break; | 1754 | "Using provided signature for `%s' in zone `%s' with %u records and expiration %llu\n", |
1755 | name, GNUNET_short_h2s (&zone_hash), rd_count_filtered, | ||
1756 | (unsigned long long) expire.abs_value); | ||
1757 | return; | ||
1857 | } | 1758 | } |
1858 | proc->zi->offset++; | ||
1859 | } | 1759 | } |
1860 | while ((0 == proc->records_included) && (GNUNET_NO == proc->res_iteration_finished)); | 1760 | else |
1861 | } | ||
1862 | |||
1863 | |||
1864 | /** | ||
1865 | * Send zone iteration result to client | ||
1866 | * | ||
1867 | * @param proc the zone iteration processing result to send | ||
1868 | */ | ||
1869 | static void | ||
1870 | send_zone_iteration_result (struct ZoneIterationProcResult *proc) | ||
1871 | { | ||
1872 | struct GNUNET_NAMESTORE_ZoneIteration *zi = proc->zi; | ||
1873 | struct ZoneIterationResponseMessage zir_end; | ||
1874 | struct ZoneIterationResponseMessage *zir_msg; | ||
1875 | size_t name_len; | ||
1876 | size_t rd_ser_len; | ||
1877 | size_t msg_size; | ||
1878 | char *name_tmp; | ||
1879 | char *rd_ser; | ||
1880 | |||
1881 | if (GNUNET_YES == proc->res_iteration_finished) | ||
1882 | { | 1761 | { |
1883 | if (zi->has_zone == GNUNET_YES) | 1762 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1884 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1763 | "No signature provided for `%s'\n", |
1885 | "No more results for zone `%s'\n", | 1764 | name); |
1886 | GNUNET_short_h2s(&zi->zone)); | 1765 | signature = NULL; |
1887 | else | ||
1888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1889 | "No more results for all zones\n"); | ||
1890 | memset (&zir_end, 0, sizeof (zir_end)); | ||
1891 | zir_end.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | ||
1892 | zir_end.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); | ||
1893 | zir_end.gns_header.r_id = htonl(zi->request_id); | ||
1894 | GNUNET_SERVER_notification_context_unicast (snc, | ||
1895 | zi->client->client, | ||
1896 | &zir_end.gns_header.header, GNUNET_NO); | ||
1897 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing zone iterator\n"); | ||
1898 | GNUNET_CONTAINER_DLL_remove (zi->client->op_head, zi->client->op_tail, zi); | ||
1899 | GNUNET_free (zi); | ||
1900 | return; | ||
1901 | } | 1766 | } |
1902 | GNUNET_assert (proc->records_included > 0); | 1767 | |
1903 | if (GNUNET_YES == zi->has_zone) | 1768 | if (GNUNET_YES == proc->zi->has_zone) |
1904 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1905 | "Sending name `%s' for iteration over zone `%s'\n", | 1770 | "Sending name `%s' for iteration over zone `%s'\n", |
1906 | proc->name, GNUNET_short_h2s(&zi->zone)); | 1771 | name, GNUNET_short_h2s(&proc->zi->zone)); |
1907 | else | 1772 | else |
1908 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1773 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1909 | "Sending name `%s' for iteration over all zones\n", | 1774 | "Sending name `%s' for iteration over all zones\n", |
1910 | proc->name); | 1775 | name); |
1911 | name_len = strlen (proc->name) + 1; | 1776 | name_len = strlen (name) + 1; |
1912 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(proc->records_included, proc->rd); | 1777 | rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count_filtered, rd_filtered); |
1913 | msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len; | 1778 | msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len; |
1914 | 1779 | ||
1915 | zir_msg = GNUNET_malloc(msg_size); | 1780 | zir_msg = GNUNET_malloc (msg_size); |
1916 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | 1781 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); |
1917 | zir_msg->gns_header.header.size = htons (msg_size); | 1782 | zir_msg->gns_header.header.size = htons (msg_size); |
1918 | zir_msg->gns_header.r_id = htonl(zi->request_id); | 1783 | zir_msg->gns_header.r_id = htonl (proc->zi->request_id); |
1919 | zir_msg->expire = GNUNET_TIME_absolute_hton(proc->expire); | 1784 | zir_msg->expire = GNUNET_TIME_absolute_hton (expire); |
1920 | zir_msg->reserved = htons (0); | 1785 | zir_msg->reserved = htons (0); |
1921 | zir_msg->name_len = htons (name_len); | 1786 | zir_msg->name_len = htons (name_len); |
1922 | zir_msg->rd_count = htons (proc->records_included); | 1787 | zir_msg->rd_count = htons (rd_count_filtered); |
1923 | zir_msg->rd_len = htons (rd_ser_len); | 1788 | zir_msg->rd_len = htons (rd_ser_len); |
1924 | zir_msg->signature = proc->signature; | 1789 | if (NULL != signature) |
1925 | zir_msg->public_key = proc->zone_key; | 1790 | zir_msg->signature = *signature; |
1791 | zir_msg->public_key = *zone_key; | ||
1926 | name_tmp = (char *) &zir_msg[1]; | 1792 | name_tmp = (char *) &zir_msg[1]; |
1927 | memcpy (name_tmp, proc->name, name_len); | 1793 | memcpy (name_tmp, name, name_len); |
1928 | rd_ser = &name_tmp[name_len]; | 1794 | rd_ser = &name_tmp[name_len]; |
1929 | GNUNET_NAMESTORE_records_serialize (proc->records_included, proc->rd, rd_ser_len, rd_ser); | 1795 | GNUNET_NAMESTORE_records_serialize (rd_count_filtered, rd_filtered, rd_ser_len, rd_ser); |
1930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1931 | "Sending `%s' message with size %u\n", | 1797 | "Sending `%s' message with size %u\n", |
1932 | "ZONE_ITERATION_RESPONSE", | 1798 | "ZONE_ITERATION_RESPONSE", |
1933 | msg_size); | 1799 | msg_size); |
1934 | GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, | 1800 | GNUNET_SERVER_notification_context_unicast (snc, proc->zi->client->client, |
1935 | (const struct GNUNET_MessageHeader *) zir_msg, | 1801 | (const struct GNUNET_MessageHeader *) zir_msg, |
1936 | GNUNET_NO); | 1802 | GNUNET_NO); |
1803 | proc->res_iteration_finished = GNUNET_NO; | ||
1937 | GNUNET_free (zir_msg); | 1804 | GNUNET_free (zir_msg); |
1938 | } | 1805 | GNUNET_free_non_null (new_signature); |
1939 | |||
1940 | |||
1941 | /** | ||
1942 | * Clean up after zone iteration | ||
1943 | * @param proc the zone iteration processor | ||
1944 | */ | ||
1945 | static void | ||
1946 | clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc) | ||
1947 | { | ||
1948 | unsigned int c; | ||
1949 | |||
1950 | GNUNET_free_non_null (proc->name); | ||
1951 | proc->name = NULL; | ||
1952 | for (c = 0; c < proc->records_included; c++) | ||
1953 | GNUNET_free ((void *) proc->rd[c].data); | ||
1954 | GNUNET_free_non_null (proc->rd); | ||
1955 | proc->rd = NULL; | ||
1956 | proc->records_included = 0; | ||
1957 | } | 1806 | } |
1958 | 1807 | ||
1959 | 1808 | ||
@@ -1966,23 +1815,48 @@ static void | |||
1966 | run_zone_iteration_round (struct GNUNET_NAMESTORE_ZoneIteration *zi) | 1815 | run_zone_iteration_round (struct GNUNET_NAMESTORE_ZoneIteration *zi) |
1967 | { | 1816 | { |
1968 | struct ZoneIterationProcResult proc; | 1817 | struct ZoneIterationProcResult proc; |
1818 | struct ZoneIterationResponseMessage zir_end; | ||
1819 | struct GNUNET_CRYPTO_ShortHashCode *zone; | ||
1969 | 1820 | ||
1970 | memset (&proc, 0, sizeof (proc)); | 1821 | memset (&proc, 0, sizeof (proc)); |
1971 | proc.zi = zi; | 1822 | proc.zi = zi; |
1972 | find_next_zone_iteration_result (&proc); | 1823 | if (GNUNET_YES == zi->has_zone) |
1973 | if (GNUNET_YES == proc.res_iteration_finished) | 1824 | zone = &zi->zone; |
1825 | else | ||
1826 | zone = NULL; | ||
1827 | proc.res_iteration_finished = GNUNET_SYSERR; | ||
1828 | while (GNUNET_SYSERR == proc.res_iteration_finished) | ||
1974 | { | 1829 | { |
1975 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1830 | if (GNUNET_SYSERR == |
1976 | "Zone iteration done\n"); | 1831 | GSN_database->iterate_records (GSN_database->cls, zone, NULL, |
1832 | zi->offset, | ||
1833 | &zone_iteraterate_proc, &proc)) | ||
1834 | { | ||
1835 | GNUNET_break (0); | ||
1836 | break; | ||
1837 | } | ||
1838 | zi->offset++; | ||
1977 | } | 1839 | } |
1978 | else if (0 != proc.records_included) | 1840 | if (GNUNET_YES != proc.res_iteration_finished) |
1979 | { | 1841 | return; /* more results later */ |
1842 | if (GNUNET_YES == zi->has_zone) | ||
1980 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1981 | "Zone iteration returns %u records\n", | 1844 | "No more results for zone `%s'\n", |
1982 | proc.records_included); | 1845 | GNUNET_short_h2s(&zi->zone)); |
1983 | } | 1846 | else |
1984 | send_zone_iteration_result (&proc); | 1847 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1985 | clean_up_zone_iteration_result (&proc); | 1848 | "No more results for all zones\n"); |
1849 | memset (&zir_end, 0, sizeof (zir_end)); | ||
1850 | zir_end.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | ||
1851 | zir_end.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); | ||
1852 | zir_end.gns_header.r_id = htonl(zi->request_id); | ||
1853 | GNUNET_SERVER_notification_context_unicast (snc, | ||
1854 | zi->client->client, | ||
1855 | &zir_end.gns_header.header, GNUNET_NO); | ||
1856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1857 | "Removing zone iterator\n"); | ||
1858 | GNUNET_CONTAINER_DLL_remove (zi->client->op_head, zi->client->op_tail, zi); | ||
1859 | GNUNET_free (zi); | ||
1986 | } | 1860 | } |
1987 | 1861 | ||
1988 | 1862 | ||
@@ -2004,11 +1878,10 @@ handle_iteration_start (void *cls, | |||
2004 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 1878 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
2005 | 1879 | ||
2006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START"); | 1880 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START"); |
2007 | nc = client_lookup (client); | 1881 | if (NULL == (nc = client_lookup (client))) |
2008 | if (NULL == nc) | ||
2009 | { | 1882 | { |
2010 | GNUNET_break_op (0); | 1883 | GNUNET_break (0); |
2011 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1884 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2012 | return; | 1885 | return; |
2013 | } | 1886 | } |
2014 | zis_msg = (const struct ZoneIterationStartMessage *) message; | 1887 | zis_msg = (const struct ZoneIterationStartMessage *) message; |
@@ -2057,11 +1930,10 @@ handle_iteration_stop (void *cls, | |||
2057 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2058 | "Received `%s' message\n", | 1931 | "Received `%s' message\n", |
2059 | "ZONE_ITERATION_STOP"); | 1932 | "ZONE_ITERATION_STOP"); |
2060 | nc = client_lookup(client); | 1933 | if (NULL == (nc = client_lookup(client))) |
2061 | if (NULL == nc) | ||
2062 | { | 1934 | { |
2063 | GNUNET_break (0); | 1935 | GNUNET_break (0); |
2064 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1936 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2065 | return; | 1937 | return; |
2066 | } | 1938 | } |
2067 | zis_msg = (const struct ZoneIterationStopMessage *) message; | 1939 | zis_msg = (const struct ZoneIterationStopMessage *) message; |
@@ -2072,7 +1944,7 @@ handle_iteration_stop (void *cls, | |||
2072 | if (NULL == zi) | 1944 | if (NULL == zi) |
2073 | { | 1945 | { |
2074 | GNUNET_break (0); | 1946 | GNUNET_break (0); |
2075 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1947 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2076 | return; | 1948 | return; |
2077 | } | 1949 | } |
2078 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); | 1950 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); |
@@ -2106,11 +1978,10 @@ handle_iteration_next (void *cls, | |||
2106 | uint32_t rid; | 1978 | uint32_t rid; |
2107 | 1979 | ||
2108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT"); | 1980 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT"); |
2109 | nc = client_lookup(client); | 1981 | if (NULL == (nc = client_lookup(client))) |
2110 | if (NULL == nc) | ||
2111 | { | 1982 | { |
2112 | GNUNET_break (0); | 1983 | GNUNET_break (0); |
2113 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1984 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2114 | return; | 1985 | return; |
2115 | } | 1986 | } |
2116 | zis_msg = (const struct ZoneIterationNextMessage *) message; | 1987 | zis_msg = (const struct ZoneIterationNextMessage *) message; |
@@ -2121,7 +1992,7 @@ handle_iteration_next (void *cls, | |||
2121 | if (NULL == zi) | 1992 | if (NULL == zi) |
2122 | { | 1993 | { |
2123 | GNUNET_break (0); | 1994 | GNUNET_break (0); |
2124 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1995 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2125 | return; | 1996 | return; |
2126 | } | 1997 | } |
2127 | run_zone_iteration_round (zi); | 1998 | run_zone_iteration_round (zi); |
@@ -2140,10 +2011,7 @@ static int | |||
2140 | zonekey_file_it (void *cls, const char *filename) | 2011 | zonekey_file_it (void *cls, const char *filename) |
2141 | { | 2012 | { |
2142 | unsigned int *counter = cls; | 2013 | unsigned int *counter = cls; |
2143 | struct GNUNET_HashCode long_hash; | ||
2144 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; | 2014 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; |
2145 | struct GNUNET_NAMESTORE_CryptoContainer *c; | ||
2146 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; | ||
2147 | 2015 | ||
2148 | if ((NULL == filename) || | 2016 | if ((NULL == filename) || |
2149 | (NULL == strstr(filename, ".zkey"))) | 2017 | (NULL == strstr(filename, ".zkey"))) |
@@ -2156,18 +2024,7 @@ zonekey_file_it (void *cls, const char *filename) | |||
2156 | filename); | 2024 | filename); |
2157 | return GNUNET_OK; | 2025 | return GNUNET_OK; |
2158 | } | 2026 | } |
2159 | c = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | 2027 | learn_private_key (privkey); |
2160 | c->privkey = privkey; | ||
2161 | GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey); | ||
2162 | GNUNET_CRYPTO_short_hash (&pubkey, | ||
2163 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | ||
2164 | &c->zone); | ||
2165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2166 | "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone)); | ||
2167 | GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash); | ||
2168 | GNUNET_assert (GNUNET_OK == | ||
2169 | GNUNET_CONTAINER_multihashmap_put (zonekeys, &long_hash, c, | ||
2170 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2171 | (*counter)++; | 2028 | (*counter)++; |
2172 | return GNUNET_OK; | 2029 | return GNUNET_OK; |
2173 | } | 2030 | } |
diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index 5a8b12778..1d5f013cb 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c | |||
@@ -187,7 +187,7 @@ zone_proc (void *cls, | |||
187 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 187 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
188 | { | 188 | { |
189 | int failed = GNUNET_NO; | 189 | int failed = GNUNET_NO; |
190 | if ((zone_key == NULL) && (name == NULL)) | 190 | if ((zone_key == NULL) && (name == NULL)) |
191 | { | 191 | { |
192 | GNUNET_break (3 == returned_records); | 192 | GNUNET_break (3 == returned_records); |
193 | if (3 == returned_records) | 193 | if (3 == returned_records) |