diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-14 22:31:38 +0200 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2020-10-15 12:11:19 +0200 |
commit | 25eb1fb2acbe92b418d8643c06107ce0ab2bfb9a (patch) | |
tree | 97ba1f700217697979449cec7528b4eab5e22a22 /src/namecache | |
parent | 96c802b46be51e5c45f34e2de823f787d26c2929 (diff) | |
download | gnunet-25eb1fb2acbe92b418d8643c06107ce0ab2bfb9a.tar.gz gnunet-25eb1fb2acbe92b418d8643c06107ce0ab2bfb9a.zip |
- better wire format for rrblocks
Diffstat (limited to 'src/namecache')
-rw-r--r-- | src/namecache/gnunet-service-namecache.c | 47 | ||||
-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 | 24 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_sqlite.c | 16 |
5 files changed, 35 insertions, 91 deletions
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_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 1775561e1..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_IDENTITY_PublicKey) | ||
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_IDENTITY_PublicKey), | 320 | &query); |
324 | &query); | 321 | block_size = GNUNET_GNSRECORD_block_get_size (block); |
325 | block_size = ntohl (block->purpose.size) | ||
326 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | ||
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 3c8fc4555..ae0f71a1f 100644 --- a/src/namecache/plugin_namecache_postgres.c +++ b/src/namecache/plugin_namecache_postgres.c | |||
@@ -153,11 +153,11 @@ namecache_postgres_expire_blocks (struct Plugin *plugin) | |||
153 | static void | 153 | static void |
154 | delete_old_block (struct Plugin *plugin, | 154 | delete_old_block (struct Plugin *plugin, |
155 | const struct GNUNET_HashCode *query, | 155 | const struct GNUNET_HashCode *query, |
156 | struct GNUNET_TIME_AbsoluteNBO expiration_time) | 156 | struct GNUNET_TIME_Absolute expiration_time) |
157 | { | 157 | { |
158 | struct GNUNET_PQ_QueryParam params[] = { | 158 | struct GNUNET_PQ_QueryParam params[] = { |
159 | GNUNET_PQ_query_param_auto_from_type (query), | 159 | GNUNET_PQ_query_param_auto_from_type (query), |
160 | GNUNET_PQ_query_param_absolute_time_nbo (&expiration_time), | 160 | GNUNET_PQ_query_param_absolute_time (&expiration_time), |
161 | GNUNET_PQ_query_param_end | 161 | GNUNET_PQ_query_param_end |
162 | }; | 162 | }; |
163 | enum GNUNET_DB_QueryStatus res; | 163 | enum GNUNET_DB_QueryStatus res; |
@@ -182,21 +182,20 @@ namecache_postgres_cache_block (void *cls, | |||
182 | { | 182 | { |
183 | struct Plugin *plugin = cls; | 183 | struct Plugin *plugin = cls; |
184 | struct GNUNET_HashCode query; | 184 | struct GNUNET_HashCode query; |
185 | size_t block_size = ntohl (block->purpose.size) | 185 | size_t block_size = GNUNET_GNSRECORD_block_get_size (block); |
186 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | 186 | struct GNUNET_TIME_Absolute exp; |
187 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature); | 187 | exp = GNUNET_GNSRECORD_block_get_expiration (block); |
188 | struct GNUNET_PQ_QueryParam params[] = { | 188 | struct GNUNET_PQ_QueryParam params[] = { |
189 | GNUNET_PQ_query_param_auto_from_type (&query), | 189 | GNUNET_PQ_query_param_auto_from_type (&query), |
190 | GNUNET_PQ_query_param_fixed_size (block, block_size), | 190 | GNUNET_PQ_query_param_fixed_size (block, block_size), |
191 | GNUNET_PQ_query_param_absolute_time_nbo (&block->expiration_time), | 191 | GNUNET_PQ_query_param_absolute_time (&exp), |
192 | GNUNET_PQ_query_param_end | 192 | GNUNET_PQ_query_param_end |
193 | }; | 193 | }; |
194 | enum GNUNET_DB_QueryStatus res; | 194 | enum GNUNET_DB_QueryStatus res; |
195 | 195 | ||
196 | namecache_postgres_expire_blocks (plugin); | 196 | namecache_postgres_expire_blocks (plugin); |
197 | GNUNET_CRYPTO_hash (&block->derived_key, | 197 | GNUNET_GNSRECORD_query_from_block (block, |
198 | sizeof(struct GNUNET_IDENTITY_PublicKey), | 198 | &query); |
199 | &query); | ||
200 | if (block_size > 64 * 65536) | 199 | if (block_size > 64 * 65536) |
201 | { | 200 | { |
202 | GNUNET_break (0); | 201 | GNUNET_break (0); |
@@ -204,7 +203,7 @@ namecache_postgres_cache_block (void *cls, | |||
204 | } | 203 | } |
205 | delete_old_block (plugin, | 204 | delete_old_block (plugin, |
206 | &query, | 205 | &query, |
207 | block->expiration_time); | 206 | exp); |
208 | 207 | ||
209 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, | 208 | res = GNUNET_PQ_eval_prepared_non_select (plugin->dbh, |
210 | "cache_block", | 209 | "cache_block", |
@@ -263,10 +262,7 @@ namecache_postgres_lookup_block (void *cls, | |||
263 | "Ending iteration (no more results)\n"); | 262 | "Ending iteration (no more results)\n"); |
264 | return GNUNET_NO; | 263 | return GNUNET_NO; |
265 | } | 264 | } |
266 | if ((bsize < sizeof(*block)) || | 265 | if ((bsize < sizeof(*block))) |
267 | (bsize != ntohl (block->purpose.size) | ||
268 | + sizeof(struct GNUNET_IDENTITY_PublicKey) | ||
269 | + sizeof(struct GNUNET_CRYPTO_EcdsaSignature))) | ||
270 | { | 266 | { |
271 | GNUNET_break (0); | 267 | GNUNET_break (0); |
272 | 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 33970631b..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_IDENTITY_PublicKey) | ||
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(block->derived_key), | 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_IDENTITY_PublicKey) | ||
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); |