diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-20 15:26:30 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-20 15:26:30 +0000 |
commit | 51cc0a0fe9fe26f3fd91d508a0268295924ae35a (patch) | |
tree | bf5aca1f5c11e9f50778440b935b11a34f781d05 /src/namestore | |
parent | 18656ea25708198199589ac8c32c360f2ee1a544 (diff) | |
download | gnunet-51cc0a0fe9fe26f3fd91d508a0268295924ae35a.tar.gz gnunet-51cc0a0fe9fe26f3fd91d508a0268295924ae35a.zip |
- docu
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 227 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 6 |
2 files changed, 222 insertions, 11 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index a5e1ab9ae..d9e07f8d2 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -408,6 +408,7 @@ client_lookup (struct GNUNET_SERVER_Client *client) | |||
408 | return nc; | 408 | return nc; |
409 | } | 409 | } |
410 | 410 | ||
411 | |||
411 | /** | 412 | /** |
412 | * Called whenever a client is disconnected. | 413 | * Called whenever a client is disconnected. |
413 | * Frees our resources associated with that client. | 414 | * Frees our resources associated with that client. |
@@ -444,6 +445,7 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) | |||
444 | nc = NULL; | 445 | nc = NULL; |
445 | } | 446 | } |
446 | 447 | ||
448 | |||
447 | /** | 449 | /** |
448 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_START' message | 450 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_START' message |
449 | * | 451 | * |
@@ -467,17 +469,52 @@ handle_start (void *cls, | |||
467 | } | 469 | } |
468 | 470 | ||
469 | 471 | ||
472 | /** | ||
473 | * LookupNameContext | ||
474 | * | ||
475 | * Context for name lookups passed from 'handle_lookup_name' to | ||
476 | * 'handle_lookup_name_it' as closure | ||
477 | */ | ||
470 | struct LookupNameContext | 478 | struct LookupNameContext |
471 | { | 479 | { |
472 | 480 | /** | |
481 | * The client to send the response to | ||
482 | */ | ||
473 | struct GNUNET_NAMESTORE_Client *nc; | 483 | struct GNUNET_NAMESTORE_Client *nc; |
484 | |||
485 | /** | ||
486 | * Operation id for the name lookup | ||
487 | */ | ||
474 | uint32_t request_id; | 488 | uint32_t request_id; |
489 | |||
490 | /** | ||
491 | * Requested specific record type | ||
492 | */ | ||
475 | uint32_t record_type; | 493 | uint32_t record_type; |
494 | |||
495 | /** | ||
496 | * Requested zone | ||
497 | */ | ||
476 | struct GNUNET_CRYPTO_ShortHashCode *zone; | 498 | struct GNUNET_CRYPTO_ShortHashCode *zone; |
499 | |||
500 | /** | ||
501 | * Requested name | ||
502 | */ | ||
477 | char *name; | 503 | char *name; |
478 | }; | 504 | }; |
479 | 505 | ||
480 | 506 | ||
507 | /** | ||
508 | * A 'GNUNET_NAMESTORE_RecordIterator' for name lookups in handle_lookup_name | ||
509 | * | ||
510 | * @param cls a 'struct LookupNameContext *' with information about the request | ||
511 | * @param zone_key zone key of the zone | ||
512 | * @param expire expiration time | ||
513 | * @param name name | ||
514 | * @param rd_count number of records | ||
515 | * @param rd array of records | ||
516 | * @param signature signature | ||
517 | */ | ||
481 | static void | 518 | static void |
482 | handle_lookup_name_it (void *cls, | 519 | handle_lookup_name_it (void *cls, |
483 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 520 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
@@ -829,17 +866,62 @@ send: | |||
829 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 866 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
830 | } | 867 | } |
831 | 868 | ||
869 | |||
870 | /** | ||
871 | * CreateRecordContext | ||
872 | * | ||
873 | * Context for record create operations passed from 'handle_record_create' to | ||
874 | * 'handle_create_record_it' as closure | ||
875 | */ | ||
832 | struct CreateRecordContext | 876 | struct CreateRecordContext |
833 | { | 877 | { |
878 | /** | ||
879 | * Record data | ||
880 | */ | ||
834 | struct GNUNET_NAMESTORE_RecordData *rd; | 881 | struct GNUNET_NAMESTORE_RecordData *rd; |
882 | |||
883 | /** | ||
884 | * Zone's private key | ||
885 | */ | ||
835 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 886 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
887 | |||
888 | /** | ||
889 | * Zone's public key | ||
890 | */ | ||
836 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; | 891 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey; |
892 | |||
893 | /** | ||
894 | * Record expiration time | ||
895 | */ | ||
837 | struct GNUNET_TIME_Absolute expire; | 896 | struct GNUNET_TIME_Absolute expire; |
897 | |||
898 | /** | ||
899 | * Name for the record to create | ||
900 | */ | ||
838 | char *name; | 901 | char *name; |
902 | |||
903 | /** | ||
904 | * result returned from 'handle_create_record_it' | ||
905 | * GNUNET_SYSERR: failed to create the record | ||
906 | * GNUNET_NO: we updated an existing record or identical entry existed | ||
907 | * GNUNET_YES : we created a new record | ||
908 | */ | ||
839 | int res; | 909 | int res; |
840 | }; | 910 | }; |
841 | 911 | ||
842 | 912 | ||
913 | /** | ||
914 | * A 'GNUNET_NAMESTORE_RecordIterator' for record create operations | ||
915 | * in handle_record_create | ||
916 | * | ||
917 | * @param cls a 'struct CreateRecordContext *' with information about the request | ||
918 | * @param pubkey zone key of the zone | ||
919 | * @param expire expiration time | ||
920 | * @param name name | ||
921 | * @param rd_count number of records | ||
922 | * @param rd array of records | ||
923 | * @param signature signature | ||
924 | */ | ||
843 | static void | 925 | static void |
844 | handle_create_record_it (void *cls, | 926 | handle_create_record_it (void *cls, |
845 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey, | 927 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pubkey, |
@@ -1131,12 +1213,36 @@ send: | |||
1131 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1213 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1132 | } | 1214 | } |
1133 | 1215 | ||
1134 | 1216 | /** | |
1217 | * RemoveRecordContext | ||
1218 | * | ||
1219 | * Context for record remove operations passed from 'handle_record_remove' to | ||
1220 | * 'handle_record_remove_it' as closure | ||
1221 | */ | ||
1135 | struct RemoveRecordContext | 1222 | struct RemoveRecordContext |
1136 | { | 1223 | { |
1224 | /** | ||
1225 | * Record to remove | ||
1226 | */ | ||
1137 | struct GNUNET_NAMESTORE_RecordData *rd; | 1227 | struct GNUNET_NAMESTORE_RecordData *rd; |
1228 | |||
1229 | /** | ||
1230 | * Zone's private keys | ||
1231 | */ | ||
1138 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; | 1232 | struct GNUNET_CRYPTO_RsaPrivateKey *pkey; |
1233 | |||
1234 | /** | ||
1235 | * Name to remove | ||
1236 | */ | ||
1139 | int remove_name; | 1237 | int remove_name; |
1238 | |||
1239 | /** | ||
1240 | * 0 : Success | ||
1241 | * 1 : Could not find record to remove, empty result set | ||
1242 | * 2 : Could not find record to remove, record did not exist in result set | ||
1243 | * 3 : Could not remove records from database | ||
1244 | * 4 : Could not put records into database | ||
1245 | */ | ||
1140 | uint16_t op_res; | 1246 | uint16_t op_res; |
1141 | }; | 1247 | }; |
1142 | 1248 | ||
@@ -1203,8 +1309,8 @@ handle_record_remove_it (void *cls, | |||
1203 | name, res); | 1309 | name, res); |
1204 | if (GNUNET_OK != res) | 1310 | if (GNUNET_OK != res) |
1205 | { | 1311 | { |
1206 | /* Could put records into database */ | 1312 | /* Could not remove records from database */ |
1207 | rrc->op_res = 4; | 1313 | rrc->op_res = 3; |
1208 | return; | 1314 | return; |
1209 | } | 1315 | } |
1210 | rrc->op_res = 0; | 1316 | rrc->op_res = 0; |
@@ -1241,7 +1347,7 @@ handle_record_remove_it (void *cls, | |||
1241 | &dummy_signature); | 1347 | &dummy_signature); |
1242 | if (GNUNET_OK != res) | 1348 | if (GNUNET_OK != res) |
1243 | { | 1349 | { |
1244 | /* Could put records into database */ | 1350 | /* Could not put records into database */ |
1245 | rrc->op_res = 4; | 1351 | rrc->op_res = 4; |
1246 | return; | 1352 | return; |
1247 | } | 1353 | } |
@@ -1428,13 +1534,37 @@ send: | |||
1428 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1534 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1429 | } | 1535 | } |
1430 | 1536 | ||
1431 | 1537 | /** | |
1538 | * ZoneToNameCtx | ||
1539 | * | ||
1540 | * Context for record remove operations passed from 'handle_zone_to_name' to | ||
1541 | * 'handle_zone_to_name_it' as closure | ||
1542 | */ | ||
1432 | struct ZoneToNameCtx | 1543 | struct ZoneToNameCtx |
1433 | { | 1544 | { |
1545 | /** | ||
1546 | * Namestore client | ||
1547 | */ | ||
1434 | struct GNUNET_NAMESTORE_Client *nc; | 1548 | struct GNUNET_NAMESTORE_Client *nc; |
1549 | |||
1550 | /** | ||
1551 | * Request id | ||
1552 | */ | ||
1435 | uint32_t rid; | 1553 | uint32_t rid; |
1436 | }; | 1554 | }; |
1437 | 1555 | ||
1556 | |||
1557 | /** | ||
1558 | * Zone to name iterator | ||
1559 | * | ||
1560 | * @param cls struct ZoneToNameCtx * | ||
1561 | * @param zone_key the zone key | ||
1562 | * @param expire expiration date | ||
1563 | * @param name name | ||
1564 | * @param rd_count number of records | ||
1565 | * @param rd record data | ||
1566 | * @param signature signature | ||
1567 | */ | ||
1438 | static void | 1568 | static void |
1439 | handle_zone_to_name_it (void *cls, | 1569 | handle_zone_to_name_it (void *cls, |
1440 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 1570 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
@@ -1584,7 +1714,10 @@ handle_zone_to_name (void *cls, | |||
1584 | 1714 | ||
1585 | 1715 | ||
1586 | /** | 1716 | /** |
1587 | * Copy record, data has to be free separetely | 1717 | * Copy record, data has to be free'd separetely |
1718 | * | ||
1719 | * @param src source record | ||
1720 | * @param dest destination record | ||
1588 | */ | 1721 | */ |
1589 | static void | 1722 | static void |
1590 | copy_record (const struct GNUNET_NAMESTORE_RecordData *src, struct GNUNET_NAMESTORE_RecordData *dest) | 1723 | copy_record (const struct GNUNET_NAMESTORE_RecordData *src, struct GNUNET_NAMESTORE_RecordData *dest) |
@@ -1595,23 +1728,79 @@ copy_record (const struct GNUNET_NAMESTORE_RecordData *src, struct GNUNET_NAMEST | |||
1595 | memcpy ((void *) dest->data, src->data, src->data_size); | 1728 | memcpy ((void *) dest->data, src->data, src->data_size); |
1596 | } | 1729 | } |
1597 | 1730 | ||
1731 | |||
1732 | /** | ||
1733 | * ZoneIterationProcResult | ||
1734 | * | ||
1735 | * Context for record remove operations passed from | ||
1736 | * 'find_next_zone_iteration_result' to 'zone_iteraterate_proc' as closure | ||
1737 | */ | ||
1598 | struct ZoneIterationProcResult | 1738 | struct ZoneIterationProcResult |
1599 | { | 1739 | { |
1740 | /** | ||
1741 | * The zone iteration handle | ||
1742 | */ | ||
1600 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 1743 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
1601 | 1744 | ||
1745 | /** | ||
1746 | * Iteration result: iteration done? | ||
1747 | */ | ||
1602 | int res_iteration_finished; | 1748 | int res_iteration_finished; |
1749 | |||
1750 | /** | ||
1751 | * Iteration result: number of records included | ||
1752 | */ | ||
1603 | int records_included; | 1753 | int records_included; |
1754 | |||
1755 | /** | ||
1756 | * Iteration result: is a valid signature included? | ||
1757 | */ | ||
1604 | int has_signature; | 1758 | int has_signature; |
1605 | 1759 | ||
1760 | /** | ||
1761 | * Name | ||
1762 | */ | ||
1606 | char *name; | 1763 | char *name; |
1764 | |||
1765 | /** | ||
1766 | * Zone hash | ||
1767 | */ | ||
1607 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; | 1768 | struct GNUNET_CRYPTO_ShortHashCode zone_hash; |
1769 | |||
1770 | /** | ||
1771 | * Record data | ||
1772 | */ | ||
1608 | struct GNUNET_NAMESTORE_RecordData *rd; | 1773 | struct GNUNET_NAMESTORE_RecordData *rd; |
1774 | |||
1775 | /** | ||
1776 | * Zone's public key | ||
1777 | */ | ||
1609 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; | 1778 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; |
1779 | |||
1780 | /** | ||
1781 | * Signature | ||
1782 | */ | ||
1610 | struct GNUNET_CRYPTO_RsaSignature signature; | 1783 | struct GNUNET_CRYPTO_RsaSignature signature; |
1784 | |||
1785 | /** | ||
1786 | * Expiration date | ||
1787 | */ | ||
1611 | struct GNUNET_TIME_Absolute expire; | 1788 | struct GNUNET_TIME_Absolute expire; |
1612 | }; | 1789 | }; |
1613 | 1790 | ||
1614 | 1791 | ||
1792 | /** | ||
1793 | * Process results for zone iteration from database | ||
1794 | * | ||
1795 | * @param cls struct ZoneIterationProcResult *proc | ||
1796 | * @param zone_key the zone key | ||
1797 | * @param expire expiration time | ||
1798 | * @param name name | ||
1799 | * @param rd_count number of records for this name | ||
1800 | * @param rd record data | ||
1801 | * @param signature block signature | ||
1802 | */ | ||
1803 | |||
1615 | static void | 1804 | static void |
1616 | zone_iteraterate_proc (void *cls, | 1805 | zone_iteraterate_proc (void *cls, |
1617 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 1806 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
@@ -1738,6 +1927,11 @@ zone_iteraterate_proc (void *cls, | |||
1738 | 1927 | ||
1739 | } | 1928 | } |
1740 | 1929 | ||
1930 | |||
1931 | /** | ||
1932 | * Find next zone iteration result in database | ||
1933 | * @param proc the zone iteration processing to use | ||
1934 | */ | ||
1741 | static void | 1935 | static void |
1742 | find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) | 1936 | find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) |
1743 | { | 1937 | { |
@@ -1758,6 +1952,10 @@ find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
1758 | } | 1952 | } |
1759 | 1953 | ||
1760 | 1954 | ||
1955 | /** | ||
1956 | * Send zone iteration result to client | ||
1957 | * @param proc the zone iteration processing result to send | ||
1958 | */ | ||
1761 | static void | 1959 | static void |
1762 | send_zone_iteration_result (struct ZoneIterationProcResult *proc) | 1960 | send_zone_iteration_result (struct ZoneIterationProcResult *proc) |
1763 | { | 1961 | { |
@@ -1836,6 +2034,11 @@ send_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
1836 | } | 2034 | } |
1837 | } | 2035 | } |
1838 | 2036 | ||
2037 | |||
2038 | /** | ||
2039 | * Clean up after zone iteration | ||
2040 | * @param proc the zone iteration processor | ||
2041 | */ | ||
1839 | static void | 2042 | static void |
1840 | clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc) | 2043 | clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc) |
1841 | { | 2044 | { |
@@ -2030,6 +2233,14 @@ handle_iteration_next (void *cls, | |||
2030 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2233 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2031 | } | 2234 | } |
2032 | 2235 | ||
2236 | |||
2237 | /** | ||
2238 | * Load zone keys from directory by reading all .zkey files in this directory | ||
2239 | * | ||
2240 | * @param cls int * 'counter' to store the number of files found | ||
2241 | * @param filename directory to scan | ||
2242 | * @return GNUNET_OK to continue | ||
2243 | */ | ||
2033 | static int | 2244 | static int |
2034 | zonekey_file_it (void *cls, const char *filename) | 2245 | zonekey_file_it (void *cls, const char *filename) |
2035 | { | 2246 | { |
@@ -2059,7 +2270,7 @@ zonekey_file_it (void *cls, const char *filename) | |||
2059 | 2270 | ||
2060 | 2271 | ||
2061 | /** | 2272 | /** |
2062 | * Process template requests. | 2273 | * Process namestore requests. |
2063 | * | 2274 | * |
2064 | * @param cls closure | 2275 | * @param cls closure |
2065 | * @param server the initialized server | 2276 | * @param server the initialized server |
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 168ae1f1c..866d1bf1c 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -576,7 +576,7 @@ handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
576 | /** | 576 | /** |
577 | * Handle incoming messages for record operations | 577 | * Handle incoming messages for record operations |
578 | * | 578 | * |
579 | * @param ze the respective zone iteration handle | 579 | * @param qe the respective zone iteration handle |
580 | * @param msg the message we received | 580 | * @param msg the message we received |
581 | * @param type the message type in HBO | 581 | * @param type the message type in HBO |
582 | * @param size the message size | 582 | * @param size the message size |
@@ -1159,7 +1159,7 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
1159 | * to validate signatures received from the network. | 1159 | * to validate signatures received from the network. |
1160 | * | 1160 | * |
1161 | * @param public_key public key of the zone | 1161 | * @param public_key public key of the zone |
1162 | * @param expire block expiration | 1162 | * @param freshness block expiration |
1163 | * @param name name that is being mapped (at most 255 characters long) | 1163 | * @param name name that is being mapped (at most 255 characters long) |
1164 | * @param rd_count number of entries in 'rd' array | 1164 | * @param rd_count number of entries in 'rd' array |
1165 | * @param rd array of records with data to store | 1165 | * @param rd array of records with data to store |
@@ -1168,7 +1168,7 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
1168 | */ | 1168 | */ |
1169 | int | 1169 | int |
1170 | GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, | 1170 | GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, |
1171 | const struct GNUNET_TIME_Absolute expire, | 1171 | const struct GNUNET_TIME_Absolute freshness, |
1172 | const char *name, | 1172 | const char *name, |
1173 | unsigned int rd_count, | 1173 | unsigned int rd_count, |
1174 | const struct GNUNET_NAMESTORE_RecordData *rd, | 1174 | const struct GNUNET_NAMESTORE_RecordData *rd, |