diff options
Diffstat (limited to 'src/namecache')
-rw-r--r-- | src/namecache/Makefile.am | 9 | ||||
-rw-r--r-- | src/namecache/gnunet-namecache.c | 4 | ||||
-rw-r--r-- | src/namecache/gnunet-service-namecache.c | 47 | ||||
-rw-r--r-- | src/namecache/namecache.h | 4 | ||||
-rw-r--r-- | src/namecache/namecache_api.c | 23 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_flat.c | 16 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_postgres.c | 30 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_sqlite.c | 16 | ||||
-rw-r--r-- | src/namecache/test_namecache_api_cache_block.c | 20 |
9 files changed, 55 insertions, 114 deletions
diff --git a/src/namecache/Makefile.am b/src/namecache/Makefile.am index 5e80ea4c5..836a6b5d9 100644 --- a/src/namecache/Makefile.am +++ b/src/namecache/Makefile.am | |||
@@ -65,6 +65,7 @@ libgnunetnamecache_la_SOURCES = \ | |||
65 | namecache.h | 65 | namecache.h |
66 | libgnunetnamecache_la_LIBADD = \ | 66 | libgnunetnamecache_la_LIBADD = \ |
67 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 67 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
68 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
68 | $(top_builddir)/src/util/libgnunetutil.la \ | 69 | $(top_builddir)/src/util/libgnunetutil.la \ |
69 | $(GN_LIBINTL) | 70 | $(GN_LIBINTL) |
70 | libgnunetnamecache_la_LDFLAGS = \ | 71 | libgnunetnamecache_la_LDFLAGS = \ |
@@ -82,6 +83,7 @@ gnunet_namecache_SOURCES = \ | |||
82 | gnunet-namecache.c | 83 | gnunet-namecache.c |
83 | gnunet_namecache_LDADD = \ | 84 | gnunet_namecache_LDADD = \ |
84 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 85 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
86 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
85 | $(top_builddir)/src/util/libgnunetutil.la \ | 87 | $(top_builddir)/src/util/libgnunetutil.la \ |
86 | libgnunetnamecache.la \ | 88 | libgnunetnamecache.la \ |
87 | $(GN_LIBINTL) | 89 | $(GN_LIBINTL) |
@@ -91,6 +93,7 @@ gnunet_service_namecache_SOURCES = \ | |||
91 | 93 | ||
92 | gnunet_service_namecache_LDADD = \ | 94 | gnunet_service_namecache_LDADD = \ |
93 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 95 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
96 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
94 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 97 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
95 | $(top_builddir)/src/util/libgnunetutil.la \ | 98 | $(top_builddir)/src/util/libgnunetutil.la \ |
96 | libgnunetnamecache.la \ | 99 | libgnunetnamecache.la \ |
@@ -107,6 +110,8 @@ libgnunet_plugin_namecache_flat_la_SOURCES = \ | |||
107 | libgnunet_plugin_namecache_flat_la_LIBADD = \ | 110 | libgnunet_plugin_namecache_flat_la_LIBADD = \ |
108 | libgnunetnamecache.la \ | 111 | libgnunetnamecache.la \ |
109 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 112 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
113 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
114 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
110 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | 115 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ |
111 | $(LTLIBINTL) | 116 | $(LTLIBINTL) |
112 | libgnunet_plugin_namecache_flat_la_LDFLAGS = \ | 117 | libgnunet_plugin_namecache_flat_la_LDFLAGS = \ |
@@ -118,6 +123,8 @@ libgnunet_plugin_namecache_sqlite_la_LIBADD = \ | |||
118 | libgnunetnamecache.la \ | 123 | libgnunetnamecache.la \ |
119 | $(top_builddir)/src/sq/libgnunetsq.la \ | 124 | $(top_builddir)/src/sq/libgnunetsq.la \ |
120 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 125 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
126 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
127 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
121 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ | 128 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 \ |
122 | $(LTLIBINTL) | 129 | $(LTLIBINTL) |
123 | libgnunet_plugin_namecache_sqlite_la_LDFLAGS = \ | 130 | libgnunet_plugin_namecache_sqlite_la_LDFLAGS = \ |
@@ -130,6 +137,8 @@ libgnunet_plugin_namecache_postgres_la_LIBADD = \ | |||
130 | libgnunetnamecache.la \ | 137 | libgnunetnamecache.la \ |
131 | $(top_builddir)/src/pq/libgnunetpq.la \ | 138 | $(top_builddir)/src/pq/libgnunetpq.la \ |
132 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 139 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
140 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
141 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
133 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \ | 142 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lpq \ |
134 | $(LTLIBINTL) | 143 | $(LTLIBINTL) |
135 | libgnunet_plugin_namecache_postgres_la_LDFLAGS = \ | 144 | libgnunet_plugin_namecache_postgres_la_LDFLAGS = \ |
diff --git a/src/namecache/gnunet-namecache.c b/src/namecache/gnunet-namecache.c index 2e3c733e6..19f2a5766 100644 --- a/src/namecache/gnunet-namecache.c +++ b/src/namecache/gnunet-namecache.c | |||
@@ -51,7 +51,7 @@ static char *name; | |||
51 | /** | 51 | /** |
52 | * Public key of the zone to look in. | 52 | * Public key of the zone to look in. |
53 | */ | 53 | */ |
54 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 54 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
55 | 55 | ||
56 | /** | 56 | /** |
57 | * Public key of the zone to look in, in ASCII. | 57 | * Public key of the zone to look in, in ASCII. |
@@ -177,7 +177,7 @@ run (void *cls, | |||
177 | } | 177 | } |
178 | 178 | ||
179 | if (GNUNET_OK != | 179 | if (GNUNET_OK != |
180 | GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey, strlen (pkey), &pubkey)) | 180 | GNUNET_IDENTITY_public_key_from_string (pkey, &pubkey)) |
181 | { | 181 | { |
182 | fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey); | 182 | fprintf (stderr, _ ("Invalid public key for zone `%s'\n"), pkey); |
183 | GNUNET_SCHEDULER_shutdown (); | 183 | GNUNET_SCHEDULER_shutdown (); |
diff --git a/src/namecache/gnunet-service-namecache.c b/src/namecache/gnunet-service-namecache.c index 7cf216ce3..07bf30de9 100644 --- a/src/namecache/gnunet-service-namecache.c +++ b/src/namecache/gnunet-service-namecache.c | |||
@@ -184,40 +184,24 @@ handle_lookup_block_it (void *cls, | |||
184 | struct LookupBlockContext *lnc = cls; | 184 | struct LookupBlockContext *lnc = cls; |
185 | struct GNUNET_MQ_Envelope *env; | 185 | struct GNUNET_MQ_Envelope *env; |
186 | struct LookupBlockResponseMessage *r; | 186 | struct LookupBlockResponseMessage *r; |
187 | size_t esize; | ||
188 | size_t bsize; | 187 | size_t bsize; |
189 | 188 | ||
190 | bsize = ntohl (block->purpose.size); | 189 | bsize = GNUNET_GNSRECORD_block_get_size (block); |
191 | if (bsize < | ||
192 | (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof(struct | ||
193 | GNUNET_TIME_AbsoluteNBO))) | ||
194 | { | ||
195 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
196 | "Malformed block."); | ||
197 | lnc->status = GNUNET_SYSERR; | ||
198 | return; | ||
199 | } | ||
200 | esize = ntohl (block->purpose.size) | ||
201 | - sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
202 | - sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
203 | env = GNUNET_MQ_msg_extra (r, | 190 | env = GNUNET_MQ_msg_extra (r, |
204 | esize, | 191 | bsize, |
205 | GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE); | 192 | GNUNET_MESSAGE_TYPE_NAMECACHE_LOOKUP_BLOCK_RESPONSE); |
206 | r->gns_header.r_id = htonl (lnc->request_id); | 193 | r->gns_header.r_id = htonl (lnc->request_id); |
207 | r->expire = block->expiration_time; | ||
208 | r->signature = block->signature; | ||
209 | r->derived_key = block->derived_key; | ||
210 | GNUNET_memcpy (&r[1], | 194 | GNUNET_memcpy (&r[1], |
211 | &block[1], | 195 | block, |
212 | esize); | 196 | bsize); |
213 | GNUNET_STATISTICS_update (statistics, | 197 | GNUNET_STATISTICS_update (statistics, |
214 | "blocks found in cache", | 198 | "blocks found in cache", |
215 | 1, | 199 | 1, |
216 | GNUNET_NO); | 200 | GNUNET_NO); |
201 | r->expire = GNUNET_TIME_absolute_hton ( | ||
202 | GNUNET_GNSRECORD_block_get_expiration (block)); | ||
217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
218 | "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message with expiration time %s\n", | 204 | "Sending NAMECACHE_LOOKUP_BLOCK_RESPONSE message\n"); |
219 | GNUNET_STRINGS_absolute_time_to_string ( | ||
220 | GNUNET_TIME_absolute_ntoh (r->expire))); | ||
221 | GNUNET_MQ_send (lnc->nc->mq, | 205 | GNUNET_MQ_send (lnc->nc->mq, |
222 | env); | 206 | env); |
223 | } | 207 | } |
@@ -314,20 +298,11 @@ handle_block_cache (void *cls, | |||
314 | GNUNET_NO); | 298 | GNUNET_NO); |
315 | esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct | 299 | esize = ntohs (rp_msg->gns_header.header.size) - sizeof(struct |
316 | BlockCacheMessage); | 300 | BlockCacheMessage); |
317 | block = GNUNET_malloc (sizeof(struct GNUNET_GNSRECORD_Block) + esize); | 301 | block = GNUNET_malloc (esize); |
318 | block->signature = rp_msg->signature; | 302 | memcpy (block, &rp_msg[1], esize); |
319 | block->derived_key = rp_msg->derived_key; | ||
320 | block->purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | ||
321 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
322 | + esize); | ||
323 | block->expiration_time = rp_msg->expire; | ||
324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
325 | "Received NAMECACHE_BLOCK_CACHE message with expiration time %s\n", | 304 | "Received NAMECACHE_BLOCK_CACHE message with type %u\n", |
326 | GNUNET_STRINGS_absolute_time_to_string ( | 305 | htonl (block->type)); |
327 | GNUNET_TIME_absolute_ntoh (block->expiration_time))); | ||
328 | GNUNET_memcpy (&block[1], | ||
329 | &rp_msg[1], | ||
330 | esize); | ||
331 | res = GSN_database->cache_block (GSN_database->cls, | 306 | res = GSN_database->cache_block (GSN_database->cls, |
332 | block); | 307 | block); |
333 | GNUNET_free (block); | 308 | GNUNET_free (block); |
diff --git a/src/namecache/namecache.h b/src/namecache/namecache.h index 1657662c2..43c8cf85f 100644 --- a/src/namecache/namecache.h +++ b/src/namecache/namecache.h | |||
@@ -92,7 +92,7 @@ struct LookupBlockResponseMessage | |||
92 | /** | 92 | /** |
93 | * Derived public key. | 93 | * Derived public key. |
94 | */ | 94 | */ |
95 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; | 95 | struct GNUNET_IDENTITY_PublicKey derived_key; |
96 | 96 | ||
97 | /* follwed by encrypted block data */ | 97 | /* follwed by encrypted block data */ |
98 | }; | 98 | }; |
@@ -121,7 +121,7 @@ struct BlockCacheMessage | |||
121 | /** | 121 | /** |
122 | * Derived public key. | 122 | * Derived public key. |
123 | */ | 123 | */ |
124 | struct GNUNET_CRYPTO_EcdsaPublicKey derived_key; | 124 | struct GNUNET_IDENTITY_PublicKey derived_key; |
125 | 125 | ||
126 | /* follwed by encrypted block data */ | 126 | /* follwed by encrypted block data */ |
127 | }; | 127 | }; |
diff --git a/src/namecache/namecache_api.c b/src/namecache/namecache_api.c index 0c904c9ed..fdbf142a7 100644 --- a/src/namecache/namecache_api.c +++ b/src/namecache/namecache_api.c | |||
@@ -225,19 +225,11 @@ handle_lookup_block_response (void *cls, | |||
225 | size = ntohs (msg->gns_header.header.size) | 225 | size = ntohs (msg->gns_header.header.size) |
226 | - sizeof(struct LookupBlockResponseMessage); | 226 | - sizeof(struct LookupBlockResponseMessage); |
227 | { | 227 | { |
228 | char buf[size + sizeof(struct GNUNET_GNSRECORD_Block)] GNUNET_ALIGN; | 228 | char buf[size] GNUNET_ALIGN; |
229 | struct GNUNET_GNSRECORD_Block *block; | 229 | struct GNUNET_GNSRECORD_Block *block; |
230 | 230 | ||
231 | block = (struct GNUNET_GNSRECORD_Block *) buf; | 231 | block = (struct GNUNET_GNSRECORD_Block *) buf; |
232 | block->signature = msg->signature; | 232 | GNUNET_memcpy (block, |
233 | block->derived_key = msg->derived_key; | ||
234 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
235 | block->purpose.size = htonl (size | ||
236 | + sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
237 | + sizeof(struct | ||
238 | GNUNET_CRYPTO_EccSignaturePurpose)); | ||
239 | block->expiration_time = msg->expire; | ||
240 | GNUNET_memcpy (&block[1], | ||
241 | &msg[1], | 233 | &msg[1], |
242 | size); | 234 | size); |
243 | if (GNUNET_OK != | 235 | if (GNUNET_OK != |
@@ -483,11 +475,7 @@ GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, | |||
483 | 475 | ||
484 | if (NULL == h->mq) | 476 | if (NULL == h->mq) |
485 | return NULL; | 477 | return NULL; |
486 | blen = ntohl (block->purpose.size); | 478 | blen = GNUNET_GNSRECORD_block_get_size (block); |
487 | GNUNET_assert (blen > (sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
488 | + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose))); | ||
489 | blen -= (sizeof(struct GNUNET_TIME_AbsoluteNBO) | ||
490 | + sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | ||
491 | rid = get_op_id (h); | 479 | rid = get_op_id (h); |
492 | qe = GNUNET_new (struct GNUNET_NAMECACHE_QueueEntry); | 480 | qe = GNUNET_new (struct GNUNET_NAMECACHE_QueueEntry); |
493 | qe->nsh = h; | 481 | qe->nsh = h; |
@@ -502,11 +490,8 @@ GNUNET_NAMECACHE_block_cache (struct GNUNET_NAMECACHE_Handle *h, | |||
502 | blen, | 490 | blen, |
503 | GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE); | 491 | GNUNET_MESSAGE_TYPE_NAMECACHE_BLOCK_CACHE); |
504 | msg->gns_header.r_id = htonl (rid); | 492 | msg->gns_header.r_id = htonl (rid); |
505 | msg->expire = block->expiration_time; | ||
506 | msg->signature = block->signature; | ||
507 | msg->derived_key = block->derived_key; | ||
508 | GNUNET_memcpy (&msg[1], | 493 | GNUNET_memcpy (&msg[1], |
509 | &block[1], | 494 | block, |
510 | blen); | 495 | blen); |
511 | GNUNET_MQ_send (h->mq, | 496 | GNUNET_MQ_send (h->mq, |
512 | env); | 497 | env); |
diff --git a/src/namecache/plugin_namecache_flat.c b/src/namecache/plugin_namecache_flat.c index 24f4f2570..eb7800051 100644 --- a/src/namecache/plugin_namecache_flat.c +++ b/src/namecache/plugin_namecache_flat.c | |||
@@ -207,10 +207,7 @@ store_and_free_entries (void *cls, | |||
207 | struct GNUNET_CRYPTO_HashAsciiEncoded query; | 207 | struct GNUNET_CRYPTO_HashAsciiEncoded query; |
208 | size_t block_size; | 208 | size_t block_size; |
209 | 209 | ||
210 | block_size = ntohl (entry->block->purpose.size) | 210 | block_size = GNUNET_GNSRECORD_block_get_size (entry->block); |
211 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
212 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
213 | |||
214 | GNUNET_STRINGS_base64_encode ((char *) entry->block, | 211 | GNUNET_STRINGS_base64_encode ((char *) entry->block, |
215 | block_size, | 212 | block_size, |
216 | &block_b64); | 213 | &block_b64); |
@@ -277,7 +274,7 @@ expire_blocks (void *cls, | |||
277 | struct GNUNET_TIME_Absolute expiration; | 274 | struct GNUNET_TIME_Absolute expiration; |
278 | 275 | ||
279 | now = GNUNET_TIME_absolute_get (); | 276 | now = GNUNET_TIME_absolute_get (); |
280 | expiration = GNUNET_TIME_absolute_ntoh (entry->block->expiration_time); | 277 | expiration = GNUNET_GNSRECORD_block_get_expiration (entry->block); |
281 | 278 | ||
282 | if (0 == GNUNET_TIME_absolute_get_difference (now, | 279 | if (0 == GNUNET_TIME_absolute_get_difference (now, |
283 | expiration).rel_value_us) | 280 | expiration).rel_value_us) |
@@ -319,12 +316,9 @@ namecache_cache_block (void *cls, | |||
319 | size_t block_size; | 316 | size_t block_size; |
320 | 317 | ||
321 | namecache_expire_blocks (plugin); | 318 | namecache_expire_blocks (plugin); |
322 | GNUNET_CRYPTO_hash (&block->derived_key, | 319 | GNUNET_GNSRECORD_query_from_block (block, |
323 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 320 | &query); |
324 | &query); | 321 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
325 | block_size = ntohl (block->purpose.size) | ||
326 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
327 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
328 | if (block_size > 64 * 65536) | 322 | if (block_size > 64 * 65536) |
329 | { | 323 | { |
330 | GNUNET_break (0); | 324 | GNUNET_break (0); |
diff --git a/src/namecache/plugin_namecache_postgres.c b/src/namecache/plugin_namecache_postgres.c index 0e947e9c5..ae0f71a1f 100644 --- a/src/namecache/plugin_namecache_postgres.c +++ b/src/namecache/plugin_namecache_postgres.c | |||
@@ -64,15 +64,13 @@ database_setup (struct Plugin *plugin) | |||
64 | " query BYTEA NOT NULL DEFAULT ''," | 64 | " query BYTEA NOT NULL DEFAULT ''," |
65 | " block BYTEA NOT NULL DEFAULT ''," | 65 | " block BYTEA NOT NULL DEFAULT ''," |
66 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 66 | " expiration_time BIGINT NOT NULL DEFAULT 0" |
67 | ")" | 67 | ")"); |
68 | "WITH OIDS"); | ||
69 | struct GNUNET_PQ_ExecuteStatement es_default = | 68 | struct GNUNET_PQ_ExecuteStatement es_default = |
70 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks (" | 69 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks (" |
71 | " query BYTEA NOT NULL DEFAULT ''," | 70 | " query BYTEA NOT NULL DEFAULT ''," |
72 | " block BYTEA NOT NULL DEFAULT ''," | 71 | " block BYTEA NOT NULL DEFAULT ''," |
73 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 72 | " expiration_time BIGINT NOT NULL DEFAULT 0" |
74 | ")" | 73 | ")"); |
75 | "WITH OIDS"); | ||
76 | const struct GNUNET_PQ_ExecuteStatement *cr; | 74 | const struct GNUNET_PQ_ExecuteStatement *cr; |
77 | 75 | ||
78 | if (GNUNET_YES == | 76 | if (GNUNET_YES == |
@@ -155,11 +153,11 @@ namecache_postgres_expire_blocks (struct Plugin *plugin) | |||
155 | static void | 153 | static void |
156 | delete_old_block (struct Plugin *plugin, | 154 | delete_old_block (struct Plugin *plugin, |
157 | const struct GNUNET_HashCode *query, | 155 | const struct GNUNET_HashCode *query, |
158 | struct GNUNET_TIME_AbsoluteNBO expiration_time) | 156 | struct GNUNET_TIME_Absolute expiration_time) |
159 | { | 157 | { |
160 | struct GNUNET_PQ_QueryParam params[] = { | 158 | struct GNUNET_PQ_QueryParam params[] = { |
161 | GNUNET_PQ_query_param_auto_from_type (query), | 159 | GNUNET_PQ_query_param_auto_from_type (query), |
162 | GNUNET_PQ_query_param_absolute_time_nbo (&expiration_time), | 160 | GNUNET_PQ_query_param_absolute_time (&expiration_time), |
163 | GNUNET_PQ_query_param_end | 161 | GNUNET_PQ_query_param_end |
164 | }; | 162 | }; |
165 | enum GNUNET_DB_QueryStatus res; | 163 | enum GNUNET_DB_QueryStatus res; |
@@ -184,21 +182,20 @@ namecache_postgres_cache_block (void *cls, | |||
184 | { | 182 | { |
185 | struct Plugin *plugin = cls; | 183 | struct Plugin *plugin = cls; |
186 | struct GNUNET_HashCode query; | 184 | struct GNUNET_HashCode query; |
187 | size_t block_size = ntohl (block->purpose.size) | 185 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
188 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | 186 | struct GNUNET_TIME_Absolute exp; |
189 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 187 | exp = GNUNET_GNSRECORD_block_get_expiration (block); |
190 | struct GNUNET_PQ_QueryParam params[] = { | 188 | struct GNUNET_PQ_QueryParam params[] = { |
191 | GNUNET_PQ_query_param_auto_from_type (&query), | 189 | GNUNET_PQ_query_param_auto_from_type (&query), |
192 | GNUNET_PQ_query_param_fixed_size (block, block_size), | 190 | GNUNET_PQ_query_param_fixed_size (block, block_size), |
193 | GNUNET_PQ_query_param_absolute_time_nbo (&block->expiration_time), | 191 | GNUNET_PQ_query_param_absolute_time (&exp), |
194 | GNUNET_PQ_query_param_end | 192 | GNUNET_PQ_query_param_end |
195 | }; | 193 | }; |
196 | enum GNUNET_DB_QueryStatus res; | 194 | enum GNUNET_DB_QueryStatus res; |
197 | 195 | ||
198 | namecache_postgres_expire_blocks (plugin); | 196 | namecache_postgres_expire_blocks (plugin); |
199 | GNUNET_CRYPTO_hash (&block->derived_key, | 197 | GNUNET_GNSRECORD_query_from_block (block, |
200 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 198 | &query); |
201 | &query); | ||
202 | if (block_size > 64 * 65536) | 199 | if (block_size > 64 * 65536) |
203 | { | 200 | { |
204 | GNUNET_break (0); | 201 | GNUNET_break (0); |
@@ -206,7 +203,7 @@ namecache_postgres_cache_block (void *cls, | |||
206 | } | 203 | } |
207 | delete_old_block (plugin, | 204 | delete_old_block (plugin, |
208 | &query, | 205 | &query, |
209 | block->expiration_time); | 206 | exp); |
210 | 207 | ||
211 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 208 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, |
212 | "cache_block", | 209 | "cache_block", |
@@ -265,10 +262,7 @@ namecache_postgres_lookup_block (void *cls, | |||
265 | "Ending iteration (no more results)\n"); | 262 | "Ending iteration (no more results)\n"); |
266 | return GNUNET_NO; | 263 | return GNUNET_NO; |
267 | } | 264 | } |
268 | if ((bsize < sizeof(*block)) || | 265 | if ((bsize < sizeof(*block))) |
269 | (bsize != ntohl (block->purpose.size) | ||
270 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
271 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))) | ||
272 | { | 266 | { |
273 | GNUNET_break (0); | 267 | GNUNET_break (0); |
274 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 268 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/namecache/plugin_namecache_sqlite.c b/src/namecache/plugin_namecache_sqlite.c index c9d79ba2d..82008c837 100644 --- a/src/namecache/plugin_namecache_sqlite.c +++ b/src/namecache/plugin_namecache_sqlite.c | |||
@@ -332,9 +332,7 @@ namecache_sqlite_cache_block (void *cls, | |||
332 | struct Plugin *plugin = cls; | 332 | struct Plugin *plugin = cls; |
333 | struct GNUNET_HashCode query; | 333 | struct GNUNET_HashCode query; |
334 | struct GNUNET_TIME_Absolute expiration; | 334 | struct GNUNET_TIME_Absolute expiration; |
335 | size_t block_size = ntohl (block->purpose.size) | 335 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
336 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
337 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | ||
338 | struct GNUNET_SQ_QueryParam del_params[] = { | 336 | struct GNUNET_SQ_QueryParam del_params[] = { |
339 | GNUNET_SQ_query_param_auto_from_type (&query), | 337 | GNUNET_SQ_query_param_auto_from_type (&query), |
340 | GNUNET_SQ_query_param_absolute_time (&expiration), | 338 | GNUNET_SQ_query_param_absolute_time (&expiration), |
@@ -356,10 +354,9 @@ namecache_sqlite_cache_block (void *cls, | |||
356 | last_expire = GNUNET_TIME_absolute_get (); | 354 | last_expire = GNUNET_TIME_absolute_get (); |
357 | namecache_sqlite_expire_blocks (plugin); | 355 | namecache_sqlite_expire_blocks (plugin); |
358 | } | 356 | } |
359 | GNUNET_CRYPTO_hash (&block->derived_key, | 357 | GNUNET_assert (GNUNET_OK == |
360 | sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey), | 358 | GNUNET_GNSRECORD_query_from_block (block, &query)); |
361 | &query); | 359 | expiration = GNUNET_GNSRECORD_block_get_expiration (block); |
362 | expiration = GNUNET_TIME_absolute_ntoh (block->expiration_time); | ||
363 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 360 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
364 | "Caching new version of block %s (expires %s)\n", | 361 | "Caching new version of block %s (expires %s)\n", |
365 | GNUNET_h2s (&query), | 362 | GNUNET_h2s (&query), |
@@ -498,10 +495,7 @@ namecache_sqlite_lookup_block (void *cls, | |||
498 | GNUNET_break (0); | 495 | GNUNET_break (0); |
499 | ret = GNUNET_SYSERR; | 496 | ret = GNUNET_SYSERR; |
500 | } | 497 | } |
501 | else if ((block_size < sizeof(struct GNUNET_GNSRECORD_Block)) || | 498 | else if ((block_size < sizeof(struct GNUNET_GNSRECORD_Block))) |
502 | (ntohl (block->purpose.size) | ||
503 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) | ||
504 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) != block_size)) | ||
505 | { | 499 | { |
506 | GNUNET_break (0); | 500 | GNUNET_break (0); |
507 | GNUNET_SQ_cleanup_result (rs); | 501 | GNUNET_SQ_cleanup_result (rs); |
diff --git a/src/namecache/test_namecache_api_cache_block.c b/src/namecache/test_namecache_api_cache_block.c index 12b72d93b..310c4de42 100644 --- a/src/namecache/test_namecache_api_cache_block.c +++ b/src/namecache/test_namecache_api_cache_block.c | |||
@@ -39,9 +39,9 @@ static struct GNUNET_NAMECACHE_Handle *nsh; | |||
39 | 39 | ||
40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; | 40 | static struct GNUNET_SCHEDULER_Task *endbadly_task; |
41 | 41 | ||
42 | static struct GNUNET_CRYPTO_EcdsaPrivateKey privkey; | 42 | static struct GNUNET_IDENTITY_PrivateKey privkey; |
43 | 43 | ||
44 | static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; | 44 | static struct GNUNET_IDENTITY_PublicKey pubkey; |
45 | 45 | ||
46 | static int res; | 46 | static int res; |
47 | 47 | ||
@@ -172,23 +172,13 @@ run (void *cls, | |||
172 | { | 172 | { |
173 | struct GNUNET_GNSRECORD_Data rd; | 173 | struct GNUNET_GNSRECORD_Data rd; |
174 | struct GNUNET_GNSRECORD_Block *block; | 174 | struct GNUNET_GNSRECORD_Block *block; |
175 | char *hostkey_file; | ||
176 | const char *name = "dummy.dummy.gnunet"; | 175 | const char *name = "dummy.dummy.gnunet"; |
177 | 176 | ||
178 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 177 | endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
179 | &endbadly, NULL); | 178 | &endbadly, NULL); |
180 | GNUNET_asprintf (&hostkey_file, | 179 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); |
181 | "zonefiles%s%s", | 180 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); |
182 | DIR_SEPARATOR_STR, | 181 | GNUNET_IDENTITY_key_get_public (&privkey, &pubkey); |
183 | "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); | ||
184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", | ||
185 | hostkey_file); | ||
186 | GNUNET_assert (GNUNET_SYSERR != | ||
187 | GNUNET_CRYPTO_ecdsa_key_from_file (hostkey_file, | ||
188 | GNUNET_YES, | ||
189 | &privkey)); | ||
190 | GNUNET_free (hostkey_file); | ||
191 | GNUNET_CRYPTO_ecdsa_key_get_public (&privkey, &pubkey); | ||
192 | 182 | ||
193 | 183 | ||
194 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 10000000000; | 184 | rd.expiration_time = GNUNET_TIME_absolute_get ().abs_value_us + 10000000000; |