diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-20 22:50:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-20 22:50:58 +0000 |
commit | db141c2daac6c97ff63c2a4f99ad475da149f45c (patch) | |
tree | 6043605940327581bdc07aa9645e3180e2560e30 /src/namestore | |
parent | d0ddec50cd8ebed5269ce277195cc858b8ea709c (diff) | |
download | gnunet-db141c2daac6c97ff63c2a4f99ad475da149f45c.tar.gz gnunet-db141c2daac6c97ff63c2a4f99ad475da149f45c.zip |
-some namestore code cleanup
Diffstat (limited to 'src/namestore')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 352 |
1 files changed, 182 insertions, 170 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index d9e07f8d2..257892bf9 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2012 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -154,18 +154,18 @@ struct GNUNET_NAMESTORE_CryptoContainer | |||
154 | 154 | ||
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Configuration handle. | 157 | * Configuration handle. |
158 | */ | 158 | */ |
159 | const struct GNUNET_CONFIGURATION_Handle *GSN_cfg; | 159 | const struct GNUNET_CONFIGURATION_Handle *GSN_cfg; |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * Database handle | 162 | * Database handle |
163 | */ | 163 | */ |
164 | struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; | 164 | struct GNUNET_NAMESTORE_PluginFunctions *GSN_database; |
165 | 165 | ||
166 | /** | 166 | /** |
167 | * Zonefile directory | 167 | * Zonefile directory |
168 | */ | 168 | */ |
169 | static char *zonefile_directory; | 169 | static char *zonefile_directory; |
170 | 170 | ||
171 | /** | 171 | /** |
@@ -173,7 +173,6 @@ static char *zonefile_directory; | |||
173 | */ | 173 | */ |
174 | static char *db_lib_name; | 174 | static char *db_lib_name; |
175 | 175 | ||
176 | |||
177 | /** | 176 | /** |
178 | * Our notification context. | 177 | * Our notification context. |
179 | */ | 178 | */ |
@@ -222,7 +221,8 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer | |||
222 | if (privkey == NULL) | 221 | if (privkey == NULL) |
223 | { | 222 | { |
224 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 223 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
225 | _("File zone `%s' but corrupt content already exists, failed to write! \n"), GNUNET_short_h2s (&zone)); | 224 | _("File zone `%s' but corrupt content already exists, failed to write! \n"), |
225 | GNUNET_short_h2s (&zone)); | ||
226 | return GNUNET_SYSERR; | 226 | return GNUNET_SYSERR; |
227 | } | 227 | } |
228 | 228 | ||
@@ -239,7 +239,8 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer | |||
239 | else | 239 | else |
240 | { | 240 | { |
241 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 241 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
242 | _("File zone `%s' but different zone key already exists, failed to write! \n"), GNUNET_short_h2s (&zone)); | 242 | _("File zone `%s' but different zone key already exists, failed to write! \n"), |
243 | GNUNET_short_h2s (&zone)); | ||
243 | return GNUNET_OK; | 244 | return GNUNET_OK; |
244 | } | 245 | } |
245 | } | 246 | } |
@@ -277,7 +278,8 @@ write_key_to_file (const char *filename, struct GNUNET_NAMESTORE_CryptoContainer | |||
277 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); | 278 | GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); |
278 | 279 | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 280 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
280 | _("Stored zonekey for zone `%s' in file `%s'\n"), GNUNET_short_h2s(&c->zone), c->filename); | 281 | "Stored zonekey for zone `%s' in file `%s'\n", |
282 | GNUNET_short_h2s(&c->zone), c->filename); | ||
281 | return GNUNET_OK; | 283 | return GNUNET_OK; |
282 | } | 284 | } |
283 | 285 | ||
@@ -1213,6 +1215,7 @@ send: | |||
1213 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1215 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1214 | } | 1216 | } |
1215 | 1217 | ||
1218 | |||
1216 | /** | 1219 | /** |
1217 | * RemoveRecordContext | 1220 | * RemoveRecordContext |
1218 | * | 1221 | * |
@@ -1246,6 +1249,10 @@ struct RemoveRecordContext | |||
1246 | uint16_t op_res; | 1249 | uint16_t op_res; |
1247 | }; | 1250 | }; |
1248 | 1251 | ||
1252 | |||
1253 | /** | ||
1254 | * FIXME... | ||
1255 | */ | ||
1249 | static void | 1256 | static void |
1250 | handle_record_remove_it (void *cls, | 1257 | handle_record_remove_it (void *cls, |
1251 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 1258 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
@@ -1355,6 +1362,7 @@ handle_record_remove_it (void *cls, | |||
1355 | rrc->op_res = 0; | 1362 | rrc->op_res = 0; |
1356 | } | 1363 | } |
1357 | 1364 | ||
1365 | |||
1358 | /** | 1366 | /** |
1359 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE' message | 1367 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE' message |
1360 | * | 1368 | * |
@@ -1616,8 +1624,6 @@ handle_zone_to_name_it (void *cls, | |||
1616 | else | 1624 | else |
1617 | contains_sig = GNUNET_NO; | 1625 | contains_sig = GNUNET_NO; |
1618 | 1626 | ||
1619 | |||
1620 | |||
1621 | msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len + contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature); | 1627 | msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len + contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature); |
1622 | ztnr_msg = GNUNET_malloc (msg_size); | 1628 | ztnr_msg = GNUNET_malloc (msg_size); |
1623 | 1629 | ||
@@ -1653,6 +1659,7 @@ handle_zone_to_name_it (void *cls, | |||
1653 | GNUNET_free_non_null (rd_ser); | 1659 | GNUNET_free_non_null (rd_ser); |
1654 | } | 1660 | } |
1655 | 1661 | ||
1662 | |||
1656 | /** | 1663 | /** |
1657 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME' message | 1664 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME' message |
1658 | * | 1665 | * |
@@ -1722,7 +1729,6 @@ handle_zone_to_name (void *cls, | |||
1722 | static void | 1729 | static void |
1723 | copy_record (const struct GNUNET_NAMESTORE_RecordData *src, struct GNUNET_NAMESTORE_RecordData *dest) | 1730 | copy_record (const struct GNUNET_NAMESTORE_RecordData *src, struct GNUNET_NAMESTORE_RecordData *dest) |
1724 | { | 1731 | { |
1725 | |||
1726 | memcpy (dest, src, sizeof (struct GNUNET_NAMESTORE_RecordData)); | 1732 | memcpy (dest, src, sizeof (struct GNUNET_NAMESTORE_RecordData)); |
1727 | dest->data = GNUNET_malloc (src->data_size); | 1733 | dest->data = GNUNET_malloc (src->data_size); |
1728 | memcpy ((void *) dest->data, src->data, src->data_size); | 1734 | memcpy ((void *) dest->data, src->data, src->data_size); |
@@ -1800,7 +1806,6 @@ struct ZoneIterationProcResult | |||
1800 | * @param rd record data | 1806 | * @param rd record data |
1801 | * @param signature block signature | 1807 | * @param signature block signature |
1802 | */ | 1808 | */ |
1803 | |||
1804 | static void | 1809 | static void |
1805 | zone_iteraterate_proc (void *cls, | 1810 | zone_iteraterate_proc (void *cls, |
1806 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | 1811 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, |
@@ -1924,7 +1929,6 @@ zone_iteraterate_proc (void *cls, | |||
1924 | GNUNET_break (0); | 1929 | GNUNET_break (0); |
1925 | return; | 1930 | return; |
1926 | } | 1931 | } |
1927 | |||
1928 | } | 1932 | } |
1929 | 1933 | ||
1930 | 1934 | ||
@@ -1948,7 +1952,7 @@ find_next_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
1948 | GSN_database->iterate_records (GSN_database->cls, zone , NULL, proc->zi->offset, &zone_iteraterate_proc, proc); | 1952 | GSN_database->iterate_records (GSN_database->cls, zone , NULL, proc->zi->offset, &zone_iteraterate_proc, proc); |
1949 | proc->zi->offset++; | 1953 | proc->zi->offset++; |
1950 | } | 1954 | } |
1951 | while ((proc->records_included == 0) && (GNUNET_NO == proc->res_iteration_finished)); | 1955 | while ((0 == proc->records_included) && (GNUNET_NO == proc->res_iteration_finished)); |
1952 | } | 1956 | } |
1953 | 1957 | ||
1954 | 1958 | ||
@@ -1987,51 +1991,49 @@ send_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
1987 | GNUNET_free (zi); | 1991 | GNUNET_free (zi); |
1988 | return; | 1992 | return; |
1989 | } | 1993 | } |
1990 | else | ||
1991 | { | ||
1992 | GNUNET_assert (proc->records_included > 0); | ||
1993 | 1994 | ||
1994 | struct ZoneIterationResponseMessage *zir_msg; | 1995 | GNUNET_assert (proc->records_included > 0); |
1995 | if (zi->has_zone == GNUNET_YES) | ||
1996 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n", | ||
1997 | proc->name, GNUNET_short_h2s(&zi->zone)); | ||
1998 | if (zi->has_zone == GNUNET_NO) | ||
1999 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n", | ||
2000 | proc->name); | ||
2001 | |||
2002 | size_t name_len; | ||
2003 | size_t rd_ser_len; | ||
2004 | size_t msg_size; | ||
2005 | char *name_tmp; | ||
2006 | char *rd_tmp; | ||
2007 | name_len = strlen (proc->name) +1; | ||
2008 | |||
2009 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(proc->records_included, proc->rd); | ||
2010 | char rd_ser[rd_ser_len]; | ||
2011 | GNUNET_NAMESTORE_records_serialize(proc->records_included, proc->rd, rd_ser_len, rd_ser); | ||
2012 | msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len; | ||
2013 | zir_msg = GNUNET_malloc(msg_size); | ||
2014 | |||
2015 | name_tmp = (char *) &zir_msg[1]; | ||
2016 | rd_tmp = &name_tmp[name_len]; | ||
2017 | |||
2018 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | ||
2019 | zir_msg->gns_header.header.size = htons (msg_size); | ||
2020 | zir_msg->gns_header.r_id = htonl(zi->request_id); | ||
2021 | zir_msg->expire = GNUNET_TIME_absolute_hton(proc->expire); | ||
2022 | zir_msg->reserved = htons (0); | ||
2023 | zir_msg->name_len = htons (name_len); | ||
2024 | zir_msg->rd_count = htons (proc->records_included); | ||
2025 | zir_msg->rd_len = htons (rd_ser_len); | ||
2026 | zir_msg->signature = proc->signature; | ||
2027 | zir_msg->public_key = proc->zone_key; | ||
2028 | memcpy (name_tmp, proc->name, name_len); | ||
2029 | memcpy (rd_tmp, rd_ser, rd_ser_len); | ||
2030 | 1996 | ||
2031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with size %u\n", "ZONE_ITERATION_RESPONSE", msg_size); | 1997 | struct ZoneIterationResponseMessage *zir_msg; |
2032 | GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) zir_msg, GNUNET_NO); | 1998 | size_t name_len; |
2033 | GNUNET_free (zir_msg); | 1999 | size_t rd_ser_len; |
2034 | } | 2000 | size_t msg_size; |
2001 | char *name_tmp; | ||
2002 | char *rd_tmp; | ||
2003 | |||
2004 | if (zi->has_zone == GNUNET_YES) | ||
2005 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over zone `%s'\n", | ||
2006 | proc->name, GNUNET_short_h2s(&zi->zone)); | ||
2007 | if (zi->has_zone == GNUNET_NO) | ||
2008 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iteration over all zones\n", | ||
2009 | proc->name); | ||
2010 | name_len = strlen (proc->name) +1; | ||
2011 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(proc->records_included, proc->rd); | ||
2012 | char rd_ser[rd_ser_len]; | ||
2013 | GNUNET_NAMESTORE_records_serialize(proc->records_included, proc->rd, rd_ser_len, rd_ser); | ||
2014 | msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len; | ||
2015 | zir_msg = GNUNET_malloc(msg_size); | ||
2016 | name_tmp = (char *) &zir_msg[1]; | ||
2017 | rd_tmp = &name_tmp[name_len]; | ||
2018 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | ||
2019 | zir_msg->gns_header.header.size = htons (msg_size); | ||
2020 | zir_msg->gns_header.r_id = htonl(zi->request_id); | ||
2021 | zir_msg->expire = GNUNET_TIME_absolute_hton(proc->expire); | ||
2022 | zir_msg->reserved = htons (0); | ||
2023 | zir_msg->name_len = htons (name_len); | ||
2024 | zir_msg->rd_count = htons (proc->records_included); | ||
2025 | zir_msg->rd_len = htons (rd_ser_len); | ||
2026 | zir_msg->signature = proc->signature; | ||
2027 | zir_msg->public_key = proc->zone_key; | ||
2028 | memcpy (name_tmp, proc->name, name_len); | ||
2029 | memcpy (rd_tmp, rd_ser, rd_ser_len); | ||
2030 | |||
2031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2032 | "Sending `%s' message with size %u\n", "ZONE_ITERATION_RESPONSE", msg_size); | ||
2033 | GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, | ||
2034 | (const struct GNUNET_MessageHeader *) zir_msg, | ||
2035 | GNUNET_NO); | ||
2036 | GNUNET_free (zir_msg); | ||
2035 | } | 2037 | } |
2036 | 2038 | ||
2037 | 2039 | ||
@@ -2042,7 +2044,8 @@ send_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
2042 | static void | 2044 | static void |
2043 | clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc) | 2045 | clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc) |
2044 | { | 2046 | { |
2045 | int c; | 2047 | unsigned int c; |
2048 | |||
2046 | GNUNET_free_non_null (proc->name); | 2049 | GNUNET_free_non_null (proc->name); |
2047 | for (c = 0; c < proc->records_included; c++) | 2050 | for (c = 0; c < proc->records_included; c++) |
2048 | { | 2051 | { |
@@ -2055,6 +2058,35 @@ clean_up_zone_iteration_result (struct ZoneIterationProcResult *proc) | |||
2055 | 2058 | ||
2056 | 2059 | ||
2057 | /** | 2060 | /** |
2061 | * Perform the next round of the zone iteration. | ||
2062 | * | ||
2063 | * @param zi zone iterator to process | ||
2064 | */ | ||
2065 | static void | ||
2066 | run_zone_iteration_round (struct GNUNET_NAMESTORE_ZoneIteration *zi) | ||
2067 | { | ||
2068 | struct ZoneIterationProcResult proc; | ||
2069 | |||
2070 | memset (&proc, 0, sizeof (proc)); | ||
2071 | proc.zi = zi; | ||
2072 | find_next_zone_iteration_result (&proc); | ||
2073 | if (GNUNET_YES == proc.res_iteration_finished) | ||
2074 | { | ||
2075 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2076 | "Zone iteration done\n"); | ||
2077 | } | ||
2078 | else if (0 != proc.records_included) | ||
2079 | { | ||
2080 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2081 | "Zone iteration return %u records\n", | ||
2082 | proc.records_included); | ||
2083 | } | ||
2084 | send_zone_iteration_result (&proc); | ||
2085 | clean_up_zone_iteration_result (&proc); | ||
2086 | } | ||
2087 | |||
2088 | |||
2089 | /** | ||
2058 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START' message | 2090 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START' message |
2059 | * | 2091 | * |
2060 | * @param cls unused | 2092 | * @param cls unused |
@@ -2066,31 +2098,27 @@ handle_iteration_start (void *cls, | |||
2066 | struct GNUNET_SERVER_Client *client, | 2098 | struct GNUNET_SERVER_Client *client, |
2067 | const struct GNUNET_MessageHeader *message) | 2099 | const struct GNUNET_MessageHeader *message) |
2068 | { | 2100 | { |
2069 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START"); | 2101 | static struct GNUNET_CRYPTO_ShortHashCode zeros; |
2070 | 2102 | const struct ZoneIterationStartMessage *zis_msg; | |
2071 | struct ZoneIterationStartMessage *zis_msg = (struct ZoneIterationStartMessage *) message; | ||
2072 | struct GNUNET_NAMESTORE_Client *nc; | 2103 | struct GNUNET_NAMESTORE_Client *nc; |
2073 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 2104 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
2074 | struct GNUNET_CRYPTO_ShortHashCode dummy; | ||
2075 | struct ZoneIterationProcResult proc; | ||
2076 | 2105 | ||
2077 | nc = client_lookup(client); | 2106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_START"); |
2078 | if (nc == NULL) | 2107 | nc = client_lookup (client); |
2108 | if (NULL == nc) | ||
2079 | { | 2109 | { |
2080 | GNUNET_break_op (0); | 2110 | GNUNET_break_op (0); |
2081 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2111 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2082 | return; | 2112 | return; |
2083 | } | 2113 | } |
2084 | 2114 | zis_msg = (const struct ZoneIterationStartMessage *) message; | |
2085 | zi = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIteration)); | 2115 | zi = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIteration)); |
2086 | zi->request_id = ntohl (zis_msg->gns_header.r_id); | 2116 | zi->request_id = ntohl (zis_msg->gns_header.r_id); |
2087 | zi->offset = 0; | 2117 | zi->offset = 0; |
2088 | zi->client = nc; | 2118 | zi->client = nc; |
2089 | zi->must_have_flags = ntohs (zis_msg->must_have_flags); | 2119 | zi->must_have_flags = ntohs (zis_msg->must_have_flags); |
2090 | zi->must_not_have_flags = ntohs (zis_msg->must_not_have_flags); | 2120 | zi->must_not_have_flags = ntohs (zis_msg->must_not_have_flags); |
2091 | 2121 | if (0 == memcmp (&zeros, &zis_msg->zone, sizeof (zeros))) | |
2092 | memset (&dummy, '\0', sizeof (dummy)); | ||
2093 | if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy))) | ||
2094 | { | 2122 | { |
2095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n"); | 2123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n"); |
2096 | zi->zone = zis_msg->zone; | 2124 | zi->zone = zis_msg->zone; |
@@ -2098,26 +2126,13 @@ handle_iteration_start (void *cls, | |||
2098 | } | 2126 | } |
2099 | else | 2127 | else |
2100 | { | 2128 | { |
2101 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_short_h2s (&zis_msg->zone)); | 2129 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2130 | "Starting to iterate over zone `%s'\n", GNUNET_short_h2s (&zis_msg->zone)); | ||
2102 | zi->zone = zis_msg->zone; | 2131 | zi->zone = zis_msg->zone; |
2103 | zi->has_zone = GNUNET_YES; | 2132 | zi->has_zone = GNUNET_YES; |
2104 | } | 2133 | } |
2105 | |||
2106 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); | 2134 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); |
2107 | 2135 | run_zone_iteration_round (zi); | |
2108 | proc.zi = zi; | ||
2109 | find_next_zone_iteration_result (&proc); | ||
2110 | if (GNUNET_YES == proc.res_iteration_finished) | ||
2111 | { | ||
2112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration done\n"); | ||
2113 | } | ||
2114 | else if (proc.records_included != 0) | ||
2115 | { | ||
2116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration return %u records\n", proc.records_included); | ||
2117 | } | ||
2118 | send_zone_iteration_result (&proc); | ||
2119 | clean_up_zone_iteration_result (&proc); | ||
2120 | |||
2121 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2136 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2122 | } | 2137 | } |
2123 | 2138 | ||
@@ -2134,48 +2149,47 @@ handle_iteration_stop (void *cls, | |||
2134 | struct GNUNET_SERVER_Client *client, | 2149 | struct GNUNET_SERVER_Client *client, |
2135 | const struct GNUNET_MessageHeader *message) | 2150 | const struct GNUNET_MessageHeader *message) |
2136 | { | 2151 | { |
2137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_STOP"); | ||
2138 | |||
2139 | struct GNUNET_NAMESTORE_Client *nc; | 2152 | struct GNUNET_NAMESTORE_Client *nc; |
2140 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 2153 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
2141 | struct ZoneIterationStopMessage *zis_msg; | 2154 | struct ZoneIterationStopMessage *zis_msg; |
2142 | uint32_t rid; | 2155 | uint32_t rid; |
2143 | 2156 | ||
2157 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2158 | "Received `%s' message\n", | ||
2159 | "ZONE_ITERATION_STOP"); | ||
2144 | nc = client_lookup(client); | 2160 | nc = client_lookup(client); |
2145 | if (nc == NULL) | 2161 | if (NULL == nc) |
2146 | { | 2162 | { |
2147 | GNUNET_break_op (0); | 2163 | GNUNET_break (0); |
2148 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2164 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2149 | return; | 2165 | return; |
2150 | } | 2166 | } |
2151 | |||
2152 | zis_msg = (struct ZoneIterationStopMessage *) message; | 2167 | zis_msg = (struct ZoneIterationStopMessage *) message; |
2153 | rid = ntohl (zis_msg->gns_header.r_id); | 2168 | rid = ntohl (zis_msg->gns_header.r_id); |
2154 | for (zi = nc->op_head; zi != NULL; zi = zi->next) | 2169 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
2155 | { | ||
2156 | if (zi->request_id == rid) | 2170 | if (zi->request_id == rid) |
2157 | break; | 2171 | break; |
2158 | } | 2172 | if (NULL == zi) |
2159 | if (zi == NULL) | ||
2160 | { | 2173 | { |
2161 | GNUNET_break_op (0); | 2174 | GNUNET_break (0); |
2162 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2175 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2163 | return; | 2176 | return; |
2164 | } | 2177 | } |
2165 | 2178 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); | |
2166 | GNUNET_CONTAINER_DLL_remove(nc->op_head, nc->op_tail, zi); | ||
2167 | if (GNUNET_YES == zi->has_zone) | 2179 | if (GNUNET_YES == zi->has_zone) |
2168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration for zone `%s'\n", GNUNET_short_h2s (&zi->zone)); | 2180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2181 | "Stopped zone iteration for zone `%s'\n", | ||
2182 | GNUNET_short_h2s (&zi->zone)); | ||
2169 | else | 2183 | else |
2170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopped zone iteration all zones\n"); | 2184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2185 | "Stopped zone iteration over all zones\n"); | ||
2171 | GNUNET_free (zi); | 2186 | GNUNET_free (zi); |
2172 | |||
2173 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2187 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2174 | } | 2188 | } |
2175 | 2189 | ||
2176 | 2190 | ||
2177 | /** | 2191 | /** |
2178 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP' message | 2192 | * Handles a 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT' message |
2179 | * | 2193 | * |
2180 | * @param cls unused | 2194 | * @param cls unused |
2181 | * @param client GNUNET_SERVER_Client sending the message | 2195 | * @param client GNUNET_SERVER_Client sending the message |
@@ -2186,50 +2200,31 @@ handle_iteration_next (void *cls, | |||
2186 | struct GNUNET_SERVER_Client *client, | 2200 | struct GNUNET_SERVER_Client *client, |
2187 | const struct GNUNET_MessageHeader *message) | 2201 | const struct GNUNET_MessageHeader *message) |
2188 | { | 2202 | { |
2189 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT"); | ||
2190 | |||
2191 | struct GNUNET_NAMESTORE_Client *nc; | 2203 | struct GNUNET_NAMESTORE_Client *nc; |
2192 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 2204 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
2193 | struct ZoneIterationNextMessage *zis_msg; | 2205 | const struct ZoneIterationNextMessage *zis_msg; |
2194 | uint32_t rid; | 2206 | uint32_t rid; |
2195 | 2207 | ||
2208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "ZONE_ITERATION_NEXT"); | ||
2196 | nc = client_lookup(client); | 2209 | nc = client_lookup(client); |
2197 | if (nc == NULL) | 2210 | if (NULL == nc) |
2198 | { | 2211 | { |
2199 | GNUNET_break_op (0); | 2212 | GNUNET_break (0); |
2200 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2213 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2201 | return; | 2214 | return; |
2202 | } | 2215 | } |
2203 | 2216 | zis_msg = (const struct ZoneIterationNextMessage *) message; | |
2204 | zis_msg = (struct ZoneIterationNextMessage *) message; | ||
2205 | rid = ntohl (zis_msg->gns_header.r_id); | 2217 | rid = ntohl (zis_msg->gns_header.r_id); |
2206 | for (zi = nc->op_head; zi != NULL; zi = zi->next) | 2218 | for (zi = nc->op_head; NULL != zi; zi = zi->next) |
2207 | { | ||
2208 | if (zi->request_id == rid) | 2219 | if (zi->request_id == rid) |
2209 | break; | 2220 | break; |
2210 | } | 2221 | if (NULL == zi) |
2211 | if (zi == NULL) | ||
2212 | { | 2222 | { |
2213 | GNUNET_break_op (0); | 2223 | GNUNET_break (0); |
2214 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2224 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2215 | return; | 2225 | return; |
2216 | } | 2226 | } |
2217 | 2227 | run_zone_iteration_round (zi); | |
2218 | struct ZoneIterationProcResult proc; | ||
2219 | proc.zi = zi; | ||
2220 | |||
2221 | find_next_zone_iteration_result (&proc); | ||
2222 | if (GNUNET_YES == proc.res_iteration_finished) | ||
2223 | { | ||
2224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration done\n"); | ||
2225 | } | ||
2226 | else if (proc.records_included != 0) | ||
2227 | { | ||
2228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration return %u records\n", proc.records_included); | ||
2229 | } | ||
2230 | send_zone_iteration_result (&proc); | ||
2231 | clean_up_zone_iteration_result (&proc); | ||
2232 | |||
2233 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2228 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2234 | } | 2229 | } |
2235 | 2230 | ||
@@ -2244,28 +2239,37 @@ handle_iteration_next (void *cls, | |||
2244 | static int | 2239 | static int |
2245 | zonekey_file_it (void *cls, const char *filename) | 2240 | zonekey_file_it (void *cls, const char *filename) |
2246 | { | 2241 | { |
2242 | unsigned int *counter = cls; | ||
2247 | struct GNUNET_HashCode long_hash; | 2243 | struct GNUNET_HashCode long_hash; |
2248 | int *counter = cls; | 2244 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; |
2249 | if ((filename != NULL) && (NULL != strstr(filename, ".zkey"))) | 2245 | struct GNUNET_NAMESTORE_CryptoContainer *c; |
2250 | { | 2246 | |
2251 | struct GNUNET_CRYPTO_RsaPrivateKey *privkey; | 2247 | if ((NULL == filename) || |
2252 | struct GNUNET_NAMESTORE_CryptoContainer *c; | 2248 | (NULL == strstr(filename, ".zkey"))) |
2253 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file(filename); | 2249 | return GNUNET_OK; |
2254 | if (privkey == NULL) | 2250 | privkey = GNUNET_CRYPTO_rsa_key_create_from_file (filename); |
2255 | return GNUNET_OK; | 2251 | if (NULL == privkey) |
2256 | 2252 | { | |
2257 | c = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | 2253 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2258 | c->pubkey = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 2254 | _("Could not parse zone key file `%s'\n"), |
2259 | c->privkey = privkey; | 2255 | filename); |
2260 | GNUNET_CRYPTO_rsa_key_get_public(privkey, c->pubkey); | 2256 | return GNUNET_OK; |
2261 | GNUNET_CRYPTO_short_hash(c->pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &c->zone); | 2257 | } |
2262 | 2258 | c = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_CryptoContainer)); | |
2263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone)); | 2259 | c->pubkey = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
2264 | GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash); | 2260 | c->privkey = privkey; |
2265 | GNUNET_CONTAINER_multihashmap_put(zonekeys, &long_hash, c, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 2261 | GNUNET_CRYPTO_rsa_key_get_public(privkey, c->pubkey); |
2266 | (*counter) ++; | 2262 | GNUNET_CRYPTO_short_hash(c->pubkey, |
2267 | } | 2263 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
2268 | return GNUNET_OK; | 2264 | &c->zone); |
2265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2266 | "Found zonefile for zone `%s'\n", GNUNET_short_h2s (&c->zone)); | ||
2267 | GNUNET_CRYPTO_short_hash_double (&c->zone, &long_hash); | ||
2268 | GNUNET_assert (GNUNET_OK == | ||
2269 | GNUNET_CONTAINER_multihashmap_put (zonekeys, &long_hash, c, | ||
2270 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2271 | (*counter)++; | ||
2272 | return GNUNET_OK; | ||
2269 | } | 2273 | } |
2270 | 2274 | ||
2271 | 2275 | ||
@@ -2280,10 +2284,6 @@ static void | |||
2280 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 2284 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
2281 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 2285 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
2282 | { | 2286 | { |
2283 | char *database; | ||
2284 | int counter = 0; | ||
2285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); | ||
2286 | |||
2287 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 2287 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
2288 | {&handle_start, NULL, | 2288 | {&handle_start, NULL, |
2289 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, | 2289 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, |
@@ -2305,15 +2305,20 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2305 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 0}, | 2305 | GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP, 0}, |
2306 | {NULL, NULL, 0, 0} | 2306 | {NULL, NULL, 0, 0} |
2307 | }; | 2307 | }; |
2308 | char *database; | ||
2309 | unsigned int counter; | ||
2308 | 2310 | ||
2311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting namestore service\n"); | ||
2309 | GSN_cfg = cfg; | 2312 | GSN_cfg = cfg; |
2310 | 2313 | ||
2311 | /* Load private keys from disk */ | 2314 | /* Load private keys from disk */ |
2312 | if (GNUNET_OK != | 2315 | if (GNUNET_OK != |
2313 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore", "zonefile_directory", | 2316 | GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore", |
2314 | &zonefile_directory)) | 2317 | "zonefile_directory", |
2318 | &zonefile_directory)) | ||
2315 | { | 2319 | { |
2316 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("No directory to load zonefiles specified in configuration\n")); | 2320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2321 | _("No directory to load zonefiles specified in configuration\n")); | ||
2317 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | 2322 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); |
2318 | return; | 2323 | return; |
2319 | } | 2324 | } |
@@ -2322,17 +2327,25 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2322 | { | 2327 | { |
2323 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (zonefile_directory)) | 2328 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (zonefile_directory)) |
2324 | { | 2329 | { |
2325 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Creating directory `%s' for zone files failed!\n"), zonefile_directory); | 2330 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2331 | _("Creating directory `%s' for zone files failed!\n"), | ||
2332 | zonefile_directory); | ||
2326 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | 2333 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); |
2327 | return; | 2334 | return; |
2328 | } | 2335 | } |
2329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created directory `%s' for zone files\n", zonefile_directory); | 2336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2337 | "Created directory `%s' for zone files\n", | ||
2338 | zonefile_directory); | ||
2330 | } | 2339 | } |
2331 | 2340 | ||
2332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scanning directory `%s' for zone files\n", zonefile_directory); | 2341 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2333 | zonekeys = GNUNET_CONTAINER_multihashmap_create (10); | 2342 | "Scanning directory `%s' for zone files\n", zonefile_directory); |
2343 | zonekeys = GNUNET_CONTAINER_multihashmap_create (16); | ||
2344 | counter = 0; | ||
2334 | GNUNET_DISK_directory_scan (zonefile_directory, zonekey_file_it, &counter); | 2345 | GNUNET_DISK_directory_scan (zonefile_directory, zonekey_file_it, &counter); |
2335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found %u zone files\n", counter); | 2346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2347 | "Found %u zone files\n", | ||
2348 | counter); | ||
2336 | 2349 | ||
2337 | /* Loading database plugin */ | 2350 | /* Loading database plugin */ |
2338 | if (GNUNET_OK != | 2351 | if (GNUNET_OK != |
@@ -2343,10 +2356,11 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2343 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); | 2356 | GNUNET_asprintf (&db_lib_name, "libgnunet_plugin_namestore_%s", database); |
2344 | GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg); | 2357 | GSN_database = GNUNET_PLUGIN_load (db_lib_name, (void *) GSN_cfg); |
2345 | GNUNET_free (database); | 2358 | GNUNET_free (database); |
2346 | if (GSN_database == NULL) | 2359 | if (NULL == GSN_database) |
2347 | { | 2360 | { |
2348 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load database backend `%s'\n", | 2361 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2349 | db_lib_name); | 2362 | "Could not load database backend `%s'\n", |
2363 | db_lib_name); | ||
2350 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); | 2364 | GNUNET_SCHEDULER_add_now (&cleanup_task, NULL); |
2351 | return; | 2365 | return; |
2352 | } | 2366 | } |
@@ -2357,10 +2371,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
2357 | GNUNET_SERVER_disconnect_notify (server, | 2371 | GNUNET_SERVER_disconnect_notify (server, |
2358 | &client_disconnect_notification, | 2372 | &client_disconnect_notification, |
2359 | NULL); | 2373 | NULL); |
2360 | |||
2361 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, | 2374 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, |
2362 | NULL); | 2375 | NULL); |
2363 | |||
2364 | } | 2376 | } |
2365 | 2377 | ||
2366 | 2378 | ||