diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-08-12 19:09:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-08-12 19:09:52 +0000 |
commit | 5e05019536c0d38bf20f965613636f21ae7c2be6 (patch) | |
tree | eda1dee12e49c010171462d618162d28b21c9c6a /src/namestore/namestore_api.c | |
parent | 566dfe32be22ed1f071b974be3c4dd8bc5721151 (diff) | |
download | gnunet-5e05019536c0d38bf20f965613636f21ae7c2be6.tar.gz gnunet-5e05019536c0d38bf20f965613636f21ae7c2be6.zip |
-towards namestore support for the new privacy-preserving GNS queries
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r-- | src/namestore/namestore_api.c | 607 |
1 files changed, 244 insertions, 363 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index c5b213954..acc9b4e37 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -75,7 +75,7 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
75 | /** | 75 | /** |
76 | * Function to call with the records we get back; or NULL. | 76 | * Function to call with the records we get back; or NULL. |
77 | */ | 77 | */ |
78 | GNUNET_NAMESTORE_RecordProcessor proc; | 78 | GNUNET_NAMESTORE_RecordMonitor proc; |
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Closure for 'proc'. | 81 | * Closure for 'proc'. |
@@ -83,6 +83,16 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
83 | void *proc_cls; | 83 | void *proc_cls; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Function to call with the blocks we get back; or NULL. | ||
87 | */ | ||
88 | GNUNET_NAMESTORE_BlockProcessor block_proc; | ||
89 | |||
90 | /** | ||
91 | * Closure for 'block_proc'. | ||
92 | */ | ||
93 | void *block_proc_cls; | ||
94 | |||
95 | /** | ||
86 | * The operation id this zone iteration operation has | 96 | * The operation id this zone iteration operation has |
87 | */ | 97 | */ |
88 | uint32_t op_id; | 98 | uint32_t op_id; |
@@ -114,7 +124,7 @@ struct GNUNET_NAMESTORE_ZoneIterator | |||
114 | /** | 124 | /** |
115 | * The continuation to call with the results | 125 | * The continuation to call with the results |
116 | */ | 126 | */ |
117 | GNUNET_NAMESTORE_RecordProcessor proc; | 127 | GNUNET_NAMESTORE_RecordMonitor proc; |
118 | 128 | ||
119 | /** | 129 | /** |
120 | * Closure for 'proc'. | 130 | * Closure for 'proc'. |
@@ -122,23 +132,15 @@ struct GNUNET_NAMESTORE_ZoneIterator | |||
122 | void* proc_cls; | 132 | void* proc_cls; |
123 | 133 | ||
124 | /** | 134 | /** |
125 | * If this iterator iterates over a specific zone this value contains the | 135 | * Private key of the zone. |
126 | * short hash of the zone | ||
127 | */ | 136 | */ |
128 | struct GNUNET_CRYPTO_ShortHashCode zone; | 137 | struct GNUNET_CRYPTO_EccPrivateKey zone; |
129 | 138 | ||
130 | /** | 139 | /** |
131 | * The operation id this zone iteration operation has | 140 | * The operation id this zone iteration operation has |
132 | */ | 141 | */ |
133 | uint32_t op_id; | 142 | uint32_t op_id; |
134 | 143 | ||
135 | /** | ||
136 | * GNUNET_YES if this iterator iterates over a specific zone | ||
137 | * GNUNET_NO if this iterator iterates over all zones | ||
138 | * | ||
139 | * Zone is stored GNUNET_CRYPTO_ShortHashCode 'zone'; | ||
140 | */ | ||
141 | int has_zone; | ||
142 | }; | 144 | }; |
143 | 145 | ||
144 | 146 | ||
@@ -164,10 +166,6 @@ struct PendingMessage | |||
164 | */ | 166 | */ |
165 | size_t size; | 167 | size_t size; |
166 | 168 | ||
167 | /** | ||
168 | * Is this the 'START' message? | ||
169 | */ | ||
170 | int is_init; | ||
171 | }; | 169 | }; |
172 | 170 | ||
173 | 171 | ||
@@ -233,6 +231,11 @@ struct GNUNET_NAMESTORE_Handle | |||
233 | int reconnect; | 231 | int reconnect; |
234 | 232 | ||
235 | /** | 233 | /** |
234 | * Did we start to receive yet? | ||
235 | */ | ||
236 | int is_receiving; | ||
237 | |||
238 | /** | ||
236 | * The last operation id used for a NAMESTORE operation | 239 | * The last operation id used for a NAMESTORE operation |
237 | */ | 240 | */ |
238 | uint32_t last_op_id_used; | 241 | uint32_t last_op_id_used; |
@@ -250,7 +253,7 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h); | |||
250 | 253 | ||
251 | 254 | ||
252 | /** | 255 | /** |
253 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE' | 256 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE' |
254 | * | 257 | * |
255 | * @param qe the respective entry in the message queue | 258 | * @param qe the respective entry in the message queue |
256 | * @param msg the message we received | 259 | * @param msg the message we received |
@@ -258,73 +261,41 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h); | |||
258 | * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client | 261 | * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client |
259 | */ | 262 | */ |
260 | static int | 263 | static int |
261 | handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | 264 | handle_lookup_block_response (struct GNUNET_NAMESTORE_QueueEntry *qe, |
262 | const struct LookupNameResponseMessage * msg, | 265 | const struct LookupBlockResponseMessage *msg, |
263 | size_t size) | 266 | size_t size) |
264 | { | 267 | { |
265 | const char *name; | 268 | struct GNUNET_NAMESTORE_Block *block; |
266 | const char * rd_tmp; | 269 | char buf[size + sizeof (struct GNUNET_NAMESTORE_Block) - sizeof (struct LookupBlockResponseMessage)]; |
267 | const struct GNUNET_CRYPTO_EccSignature *signature; | ||
268 | struct GNUNET_TIME_Absolute expire; | ||
269 | const struct GNUNET_CRYPTO_EccPublicKey *public_key_tmp; | ||
270 | size_t exp_msg_len; | ||
271 | size_t msg_len; | ||
272 | size_t name_len; | ||
273 | size_t rd_len; | ||
274 | int contains_sig; | ||
275 | int rd_count; | ||
276 | 270 | ||
277 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 271 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
278 | "Received `%s'\n", | 272 | "Received `%s'\n", |
279 | "LOOKUP_NAME_RESPONSE"); | 273 | "LOOKUP_BLOCK_RESPONSE"); |
280 | rd_len = ntohs (msg->rd_len); | 274 | block = (struct GNUNET_NAMESTORE_Block *) buf; |
281 | rd_count = ntohs (msg->rd_count); | 275 | block->signature = msg->signature; |
282 | msg_len = ntohs (msg->gns_header.header.size); | 276 | block->derived_key = msg->derived_key; |
283 | name_len = ntohs (msg->name_len); | 277 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); |
284 | contains_sig = ntohs (msg->contains_sig); | 278 | block->purpose.size = htonl (size - sizeof (struct LookupBlockResponseMessage) + sizeof (struct GNUNET_TIME_AbsoluteNBO)); |
285 | expire = GNUNET_TIME_absolute_ntoh (msg->expire); | 279 | block->expiration_time = msg->expire; |
286 | exp_msg_len = sizeof (struct LookupNameResponseMessage) + | 280 | memcpy (&block[1], |
287 | name_len + rd_len; | 281 | &msg[1], |
288 | if (msg_len != exp_msg_len) | 282 | size - sizeof (struct LookupBlockResponseMessage)); |
283 | if (GNUNET_OK != | ||
284 | GNUNET_NAMESTORE_block_verify (block)) | ||
289 | { | 285 | { |
290 | GNUNET_break (0); | 286 | GNUNET_break (0); |
291 | return GNUNET_SYSERR; | 287 | return GNUNET_SYSERR; |
292 | } | 288 | } |
293 | name = (const char *) &msg[1]; | 289 | if (NULL != qe->block_proc) |
294 | if ( (name_len > 0) && | 290 | qe->block_proc (qe->proc_cls, block); |
295 | ('\0' != name[name_len -1]) ) | 291 | else |
296 | { | ||
297 | GNUNET_break (0); | 292 | GNUNET_break (0); |
298 | return GNUNET_SYSERR; | ||
299 | } | ||
300 | rd_tmp = &name[name_len]; | ||
301 | { | ||
302 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | ||
303 | |||
304 | if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_len, rd_tmp, rd_count, rd)) | ||
305 | { | ||
306 | GNUNET_break (0); | ||
307 | return GNUNET_SYSERR; | ||
308 | } | ||
309 | if (GNUNET_NO == contains_sig) | ||
310 | signature = NULL; | ||
311 | else | ||
312 | signature = &msg->signature; | ||
313 | if (0 == name_len) | ||
314 | name = NULL; | ||
315 | if (NULL != name) | ||
316 | public_key_tmp = &msg->public_key; | ||
317 | else | ||
318 | public_key_tmp = NULL; | ||
319 | if (NULL != qe->proc) | ||
320 | qe->proc (qe->proc_cls, public_key_tmp, expire, name, rd_count, (rd_count > 0) ? rd : NULL, signature); | ||
321 | } | ||
322 | return GNUNET_OK; | 293 | return GNUNET_OK; |
323 | } | 294 | } |
324 | 295 | ||
325 | 296 | ||
326 | /** | 297 | /** |
327 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE' | 298 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE' |
328 | * | 299 | * |
329 | * @param qe the respective entry in the message queue | 300 | * @param qe the respective entry in the message queue |
330 | * @param msg the message we received | 301 | * @param msg the message we received |
@@ -332,24 +303,24 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
332 | * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client | 303 | * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client |
333 | */ | 304 | */ |
334 | static int | 305 | static int |
335 | handle_record_put_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | 306 | handle_block_cache_response (struct GNUNET_NAMESTORE_QueueEntry *qe, |
336 | const struct RecordPutResponseMessage* msg, | 307 | const struct BlockCacheResponseMessage *msg, |
337 | size_t size) | 308 | size_t size) |
338 | { | 309 | { |
339 | int res; | 310 | int res; |
340 | 311 | ||
341 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n", | 312 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n", |
342 | "RECORD_PUT_RESPONSE"); | 313 | "BLOCK_CACHE_RESPONSE"); |
343 | res = ntohl (msg->op_result); | 314 | res = ntohl (msg->op_result); |
344 | /* TODO: add actual error message from namestore to response... */ | 315 | /* TODO: add actual error message from namestore to response... */ |
345 | if (NULL != qe->cont) | 316 | if (NULL != qe->cont) |
346 | qe->cont (qe->cont_cls, res, (GNUNET_OK == res) ? NULL : _("Namestore failed to add record")); | 317 | qe->cont (qe->cont_cls, res, (GNUNET_OK == res) ? NULL : _("Namestore failed to cache block")); |
347 | return GNUNET_OK; | 318 | return GNUNET_OK; |
348 | } | 319 | } |
349 | 320 | ||
350 | 321 | ||
351 | /** | 322 | /** |
352 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE' | 323 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE' |
353 | * | 324 | * |
354 | * @param qe the respective entry in the message queue | 325 | * @param qe the respective entry in the message queue |
355 | * @param msg the message we received | 326 | * @param msg the message we received |
@@ -357,19 +328,19 @@ handle_record_put_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
357 | * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client | 328 | * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client |
358 | */ | 329 | */ |
359 | static int | 330 | static int |
360 | handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | 331 | handle_record_store_response (struct GNUNET_NAMESTORE_QueueEntry *qe, |
361 | const struct RecordCreateResponseMessage* msg, | 332 | const struct RecordStoreResponseMessage* msg, |
362 | size_t size) | 333 | size_t size) |
363 | { | 334 | { |
364 | int res; | 335 | int res; |
365 | const char *emsg; | 336 | const char *emsg; |
366 | 337 | ||
367 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n", | 338 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n", |
368 | "RECORD_CREATE_RESPONSE"); | 339 | "RECORD_STORE_RESPONSE"); |
369 | /* TODO: add actual error message from namestore to response... */ | 340 | /* TODO: add actual error message from namestore to response... */ |
370 | res = ntohl (msg->op_result); | 341 | res = ntohl (msg->op_result); |
371 | if (GNUNET_SYSERR == res) | 342 | if (GNUNET_SYSERR == res) |
372 | emsg = _("Namestore failed to add record\n"); | 343 | emsg = _("Namestore failed to store record\n"); |
373 | else | 344 | else |
374 | emsg = NULL; | 345 | emsg = NULL; |
375 | if (NULL != qe->cont) | 346 | if (NULL != qe->cont) |
@@ -379,6 +350,70 @@ handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
379 | 350 | ||
380 | 351 | ||
381 | /** | 352 | /** |
353 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT' | ||
354 | * | ||
355 | * @param qe the respective entry in the message queue | ||
356 | * @param msg the message we received | ||
357 | * @param size the message size | ||
358 | * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client | ||
359 | */ | ||
360 | static int | ||
361 | handle_record_result (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
362 | const struct RecordResultMessage *msg, | ||
363 | size_t size) | ||
364 | { | ||
365 | const char *name; | ||
366 | const char *rd_tmp; | ||
367 | size_t exp_msg_len; | ||
368 | size_t msg_len; | ||
369 | size_t name_len; | ||
370 | size_t rd_len; | ||
371 | unsigned int rd_count; | ||
372 | |||
373 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
374 | "Received `%s'\n", | ||
375 | "RECORD_RESULT"); | ||
376 | rd_len = ntohs (msg->rd_len); | ||
377 | rd_count = ntohs (msg->rd_count); | ||
378 | msg_len = ntohs (msg->gns_header.header.size); | ||
379 | name_len = ntohs (msg->name_len); | ||
380 | GNUNET_break (0 == ntohs (msg->reserved)); | ||
381 | exp_msg_len = sizeof (struct RecordResultMessage) + name_len + rd_len; | ||
382 | if (msg_len != exp_msg_len) | ||
383 | { | ||
384 | GNUNET_break (0); | ||
385 | return GNUNET_SYSERR; | ||
386 | } | ||
387 | name = (const char *) &msg[1]; | ||
388 | if ( (name_len > 0) && | ||
389 | ('\0' != name[name_len -1]) ) | ||
390 | { | ||
391 | GNUNET_break (0); | ||
392 | return GNUNET_SYSERR; | ||
393 | } | ||
394 | rd_tmp = &name[name_len]; | ||
395 | { | ||
396 | struct GNUNET_NAMESTORE_RecordData rd[rd_count]; | ||
397 | |||
398 | if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_len, rd_tmp, rd_count, rd)) | ||
399 | { | ||
400 | GNUNET_break (0); | ||
401 | return GNUNET_SYSERR; | ||
402 | } | ||
403 | if (0 == name_len) | ||
404 | name = NULL; | ||
405 | if (NULL != qe->proc) | ||
406 | qe->proc (qe->proc_cls, | ||
407 | &msg->private_key, | ||
408 | name, | ||
409 | rd_count, | ||
410 | (rd_count > 0) ? rd : NULL); | ||
411 | } | ||
412 | return GNUNET_OK; | ||
413 | } | ||
414 | |||
415 | |||
416 | /** | ||
382 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE' | 417 | * Handle an incoming message of type 'GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE' |
383 | * | 418 | * |
384 | * @param qe the respective entry in the message queue | 419 | * @param qe the respective entry in the message queue |
@@ -389,16 +424,15 @@ handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
389 | */ | 424 | */ |
390 | static int | 425 | static int |
391 | handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | 426 | handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, |
392 | const struct ZoneToNameResponseMessage* msg, | 427 | const struct ZoneToNameResponseMessage *msg, |
393 | size_t size) | 428 | size_t size) |
394 | { | 429 | { |
395 | int res; | 430 | int res; |
396 | struct GNUNET_TIME_Absolute expire; | ||
397 | size_t name_len; | 431 | size_t name_len; |
398 | size_t rd_ser_len; | 432 | size_t rd_ser_len; |
399 | unsigned int rd_count; | 433 | unsigned int rd_count; |
400 | const char * name_tmp; | 434 | const char *name_tmp; |
401 | const char * rd_tmp; | 435 | const char *rd_tmp; |
402 | 436 | ||
403 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 437 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
404 | "Received `%s'\n", | 438 | "Received `%s'\n", |
@@ -417,7 +451,6 @@ handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
417 | name_len = ntohs (msg->name_len); | 451 | name_len = ntohs (msg->name_len); |
418 | rd_count = ntohs (msg->rd_count); | 452 | rd_count = ntohs (msg->rd_count); |
419 | rd_ser_len = ntohs (msg->rd_len); | 453 | rd_ser_len = ntohs (msg->rd_len); |
420 | expire = GNUNET_TIME_absolute_ntoh(msg->expire); | ||
421 | name_tmp = (const char *) &msg[1]; | 454 | name_tmp = (const char *) &msg[1]; |
422 | if ( (name_len > 0) && | 455 | if ( (name_len > 0) && |
423 | ('\0' != name_tmp[name_len -1]) ) | 456 | ('\0' != name_tmp[name_len -1]) ) |
@@ -435,7 +468,10 @@ handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
435 | } | 468 | } |
436 | /* normal end, call continuation with result */ | 469 | /* normal end, call continuation with result */ |
437 | if (NULL != qe->proc) | 470 | if (NULL != qe->proc) |
438 | qe->proc (qe->proc_cls, &msg->zone_key, expire, name_tmp, rd_count, rd, &msg->signature); | 471 | qe->proc (qe->proc_cls, |
472 | &msg->zone, | ||
473 | name_tmp, | ||
474 | rd_count, rd); | ||
439 | /* return is important here: break would call continuation with error! */ | 475 | /* return is important here: break would call continuation with error! */ |
440 | return GNUNET_OK; | 476 | return GNUNET_OK; |
441 | } | 477 | } |
@@ -445,7 +481,7 @@ handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
445 | } | 481 | } |
446 | /* error case, call continuation with error */ | 482 | /* error case, call continuation with error */ |
447 | if (NULL != qe->proc) | 483 | if (NULL != qe->proc) |
448 | qe->proc (qe->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL); | 484 | qe->proc (qe->proc_cls, NULL, NULL, 0, NULL); |
449 | return GNUNET_OK; | 485 | return GNUNET_OK; |
450 | } | 486 | } |
451 | 487 | ||
@@ -469,27 +505,27 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
469 | /* handle different message type */ | 505 | /* handle different message type */ |
470 | switch (type) | 506 | switch (type) |
471 | { | 507 | { |
472 | case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE: | 508 | case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE: |
473 | if (size < sizeof (struct LookupNameResponseMessage)) | 509 | if (size < sizeof (struct LookupBlockResponseMessage)) |
474 | { | 510 | { |
475 | GNUNET_break (0); | 511 | GNUNET_break (0); |
476 | return GNUNET_SYSERR; | 512 | return GNUNET_SYSERR; |
477 | } | 513 | } |
478 | return handle_lookup_name_response (qe, (const struct LookupNameResponseMessage *) msg, size); | 514 | return handle_lookup_block_response (qe, (const struct LookupBlockResponseMessage *) msg, size); |
479 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE: | 515 | case GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE: |
480 | if (size != sizeof (struct RecordPutResponseMessage)) | 516 | if (size != sizeof (struct BlockCacheResponseMessage)) |
481 | { | 517 | { |
482 | GNUNET_break (0); | 518 | GNUNET_break (0); |
483 | return GNUNET_SYSERR; | 519 | return GNUNET_SYSERR; |
484 | } | 520 | } |
485 | return handle_record_put_response (qe, (const struct RecordPutResponseMessage *) msg, size); | 521 | return handle_block_cache_response (qe, (const struct BlockCacheResponseMessage *) msg, size); |
486 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE: | 522 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE: |
487 | if (size != sizeof (struct RecordCreateResponseMessage)) | 523 | if (size != sizeof (struct RecordStoreResponseMessage)) |
488 | { | 524 | { |
489 | GNUNET_break (0); | 525 | GNUNET_break (0); |
490 | return GNUNET_SYSERR; | 526 | return GNUNET_SYSERR; |
491 | } | 527 | } |
492 | return handle_record_create_response (qe, (const struct RecordCreateResponseMessage *) msg, size); | 528 | return handle_record_store_response (qe, (const struct RecordStoreResponseMessage *) msg, size); |
493 | case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE: | 529 | case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE: |
494 | if (size < sizeof (struct ZoneToNameResponseMessage)) | 530 | if (size < sizeof (struct ZoneToNameResponseMessage)) |
495 | { | 531 | { |
@@ -497,6 +533,13 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
497 | return GNUNET_SYSERR; | 533 | return GNUNET_SYSERR; |
498 | } | 534 | } |
499 | return handle_zone_to_name_response (qe, (const struct ZoneToNameResponseMessage *) msg, size); | 535 | return handle_zone_to_name_response (qe, (const struct ZoneToNameResponseMessage *) msg, size); |
536 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT: | ||
537 | if (size < sizeof (struct RecordResultMessage)) | ||
538 | { | ||
539 | GNUNET_break (0); | ||
540 | return GNUNET_SYSERR; | ||
541 | } | ||
542 | return handle_record_result (qe, (const struct RecordResultMessage *) msg, size); | ||
500 | default: | 543 | default: |
501 | GNUNET_break (0); | 544 | GNUNET_break (0); |
502 | return GNUNET_SYSERR; | 545 | return GNUNET_SYSERR; |
@@ -515,10 +558,10 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
515 | */ | 558 | */ |
516 | static int | 559 | static int |
517 | handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze, | 560 | handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze, |
518 | const struct LookupNameResponseMessage *msg, | 561 | const struct RecordResultMessage *msg, |
519 | size_t size) | 562 | size_t size) |
520 | { | 563 | { |
521 | struct GNUNET_CRYPTO_EccPublicKey pubdummy; | 564 | static struct GNUNET_CRYPTO_EccPrivateKey priv_dummy; |
522 | size_t msg_len; | 565 | size_t msg_len; |
523 | size_t exp_msg_len; | 566 | size_t exp_msg_len; |
524 | size_t name_len; | 567 | size_t name_len; |
@@ -526,27 +569,25 @@ handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze, | |||
526 | unsigned rd_count; | 569 | unsigned rd_count; |
527 | const char *name_tmp; | 570 | const char *name_tmp; |
528 | const char *rd_ser_tmp; | 571 | const char *rd_ser_tmp; |
529 | struct GNUNET_TIME_Absolute expire; | ||
530 | 572 | ||
531 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n", | 573 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
574 | "Received `%s'\n", | ||
532 | "ZONE_ITERATION_RESPONSE"); | 575 | "ZONE_ITERATION_RESPONSE"); |
533 | msg_len = ntohs (msg->gns_header.header.size); | 576 | msg_len = ntohs (msg->gns_header.header.size); |
534 | rd_len = ntohs (msg->rd_len); | 577 | rd_len = ntohs (msg->rd_len); |
535 | rd_count = ntohs (msg->rd_count); | 578 | rd_count = ntohs (msg->rd_count); |
536 | name_len = ntohs (msg->name_len); | 579 | name_len = ntohs (msg->name_len); |
537 | expire = GNUNET_TIME_absolute_ntoh (msg->expire); | 580 | exp_msg_len = sizeof (struct RecordResultMessage) + name_len + rd_len; |
538 | exp_msg_len = sizeof (struct LookupNameResponseMessage) + name_len + rd_len; | ||
539 | if (msg_len != exp_msg_len) | 581 | if (msg_len != exp_msg_len) |
540 | { | 582 | { |
541 | GNUNET_break (0); | 583 | GNUNET_break (0); |
542 | return GNUNET_SYSERR; | 584 | return GNUNET_SYSERR; |
543 | } | 585 | } |
544 | memset (&pubdummy, '\0', sizeof (pubdummy)); | 586 | if ((0 == name_len) && (0 == (memcmp (&msg->private_key, &priv_dummy, sizeof (priv_dummy))))) |
545 | if ((0 == name_len) && (0 == (memcmp (&msg->public_key, &pubdummy, sizeof (pubdummy))))) | ||
546 | { | 587 | { |
547 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n"); | 588 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n"); |
548 | if (NULL != ze->proc) | 589 | if (NULL != ze->proc) |
549 | ze->proc(ze->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL , 0, NULL, NULL); | 590 | ze->proc (ze->proc_cls, NULL, NULL, 0, NULL); |
550 | return GNUNET_NO; | 591 | return GNUNET_NO; |
551 | } | 592 | } |
552 | name_tmp = (const char *) &msg[1]; | 593 | name_tmp = (const char *) &msg[1]; |
@@ -565,7 +606,7 @@ handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze, | |||
565 | return GNUNET_SYSERR; | 606 | return GNUNET_SYSERR; |
566 | } | 607 | } |
567 | if (NULL != ze->proc) | 608 | if (NULL != ze->proc) |
568 | ze->proc(ze->proc_cls, &msg->public_key, expire, name_tmp, rd_count, rd, &msg->signature); | 609 | ze->proc (ze->proc_cls, &msg->private_key, name_tmp, rd_count, rd); |
569 | return GNUNET_YES; | 610 | return GNUNET_YES; |
570 | } | 611 | } |
571 | } | 612 | } |
@@ -589,13 +630,13 @@ manage_zone_operations (struct GNUNET_NAMESTORE_ZoneIterator *ze, | |||
589 | /* handle different message type */ | 630 | /* handle different message type */ |
590 | switch (type) | 631 | switch (type) |
591 | { | 632 | { |
592 | case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE: | 633 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT: |
593 | if (size < sizeof (struct LookupNameResponseMessage)) | 634 | if (size < sizeof (struct RecordResultMessage)) |
594 | { | 635 | { |
595 | GNUNET_break (0); | 636 | GNUNET_break (0); |
596 | return GNUNET_SYSERR; | 637 | return GNUNET_SYSERR; |
597 | } | 638 | } |
598 | return handle_zone_iteration_response (ze, (const struct LookupNameResponseMessage *) msg, size); | 639 | return handle_zone_iteration_response (ze, (const struct RecordResultMessage *) msg, size); |
599 | default: | 640 | default: |
600 | GNUNET_break (0); | 641 | GNUNET_break (0); |
601 | return GNUNET_SYSERR; | 642 | return GNUNET_SYSERR; |
@@ -611,7 +652,8 @@ manage_zone_operations (struct GNUNET_NAMESTORE_ZoneIterator *ze, | |||
611 | * @param msg message received, NULL on timeout or fatal error | 652 | * @param msg message received, NULL on timeout or fatal error |
612 | */ | 653 | */ |
613 | static void | 654 | static void |
614 | process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg) | 655 | process_namestore_message (void *cls, |
656 | const struct GNUNET_MessageHeader *msg) | ||
615 | { | 657 | { |
616 | struct GNUNET_NAMESTORE_Handle *h = cls; | 658 | struct GNUNET_NAMESTORE_Handle *h = cls; |
617 | const struct GNUNET_NAMESTORE_Header *gm; | 659 | const struct GNUNET_NAMESTORE_Header *gm; |
@@ -639,7 +681,8 @@ process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
639 | gm = (const struct GNUNET_NAMESTORE_Header *) msg; | 681 | gm = (const struct GNUNET_NAMESTORE_Header *) msg; |
640 | r_id = ntohl (gm->r_id); | 682 | r_id = ntohl (gm->r_id); |
641 | 683 | ||
642 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u op %u\n", | 684 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
685 | "Received message type %u size %u op %u\n", | ||
643 | (unsigned int) type, | 686 | (unsigned int) type, |
644 | (unsigned int) size, | 687 | (unsigned int) size, |
645 | (unsigned int) r_id); | 688 | (unsigned int) r_id); |
@@ -737,9 +780,13 @@ transmit_message_to_namestore (void *cls, size_t size, void *buf) | |||
737 | ret += p->size; | 780 | ret += p->size; |
738 | size -= p->size; | 781 | size -= p->size; |
739 | GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, p); | 782 | GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, p); |
740 | if (GNUNET_YES == p->is_init) | 783 | if (GNUNET_NO == h->is_receiving) |
741 | GNUNET_CLIENT_receive (h->client, &process_namestore_message, h, | 784 | { |
785 | h->is_receiving = GNUNET_YES; | ||
786 | GNUNET_CLIENT_receive (h->client, | ||
787 | &process_namestore_message, h, | ||
742 | GNUNET_TIME_UNIT_FOREVER_REL); | 788 | GNUNET_TIME_UNIT_FOREVER_REL); |
789 | } | ||
743 | GNUNET_free (p); | 790 | GNUNET_free (p); |
744 | } | 791 | } |
745 | do_transmit (h); | 792 | do_transmit (h); |
@@ -779,23 +826,9 @@ do_transmit (struct GNUNET_NAMESTORE_Handle *h) | |||
779 | static void | 826 | static void |
780 | reconnect (struct GNUNET_NAMESTORE_Handle *h) | 827 | reconnect (struct GNUNET_NAMESTORE_Handle *h) |
781 | { | 828 | { |
782 | struct PendingMessage *p; | ||
783 | struct StartMessage *init; | ||
784 | |||
785 | GNUNET_assert (NULL == h->client); | 829 | GNUNET_assert (NULL == h->client); |
786 | h->client = GNUNET_CLIENT_connect ("namestore", h->cfg); | 830 | h->client = GNUNET_CLIENT_connect ("namestore", h->cfg); |
787 | GNUNET_assert (NULL != h->client); | 831 | GNUNET_assert (NULL != h->client); |
788 | if ((NULL == (p = h->pending_head)) || (GNUNET_YES != p->is_init)) | ||
789 | { | ||
790 | p = GNUNET_malloc (sizeof (struct PendingMessage) + | ||
791 | sizeof (struct StartMessage)); | ||
792 | p->size = sizeof (struct StartMessage); | ||
793 | p->is_init = GNUNET_YES; | ||
794 | init = (struct StartMessage *) &p[1]; | ||
795 | init->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_START); | ||
796 | init->header.size = htons (sizeof (struct StartMessage)); | ||
797 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, p); | ||
798 | } | ||
799 | do_transmit (h); | 832 | do_transmit (h); |
800 | } | 833 | } |
801 | 834 | ||
@@ -826,6 +859,7 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
826 | { | 859 | { |
827 | h->reconnect = GNUNET_NO; | 860 | h->reconnect = GNUNET_NO; |
828 | GNUNET_CLIENT_disconnect (h->client); | 861 | GNUNET_CLIENT_disconnect (h->client); |
862 | h->is_receiving = GNUNET_NO; | ||
829 | h->client = NULL; | 863 | h->client = NULL; |
830 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 864 | h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
831 | &reconnect_task, | 865 | &reconnect_task, |
@@ -857,7 +891,7 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
857 | { | 891 | { |
858 | struct GNUNET_NAMESTORE_Handle *h; | 892 | struct GNUNET_NAMESTORE_Handle *h; |
859 | 893 | ||
860 | h = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle)); | 894 | h = GNUNET_new (struct GNUNET_NAMESTORE_Handle); |
861 | h->cfg = cfg; | 895 | h->cfg = cfg; |
862 | h->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect_task, h); | 896 | h->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect_task, h); |
863 | h->last_op_id_used = 0; | 897 | h->last_op_id_used = 0; |
@@ -913,60 +947,31 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
913 | 947 | ||
914 | /** | 948 | /** |
915 | * Store an item in the namestore. If the item is already present, | 949 | * Store an item in the namestore. If the item is already present, |
916 | * the expiration time is updated to the max of the existing time and | 950 | * it is replaced with the new record. |
917 | * the new time. This API is used when we cache signatures from other | ||
918 | * authorities. | ||
919 | * | 951 | * |
920 | * @param h handle to the namestore | 952 | * @param h handle to the namestore |
921 | * @param zone_key public key of the zone | 953 | * @param block block to store |
922 | * @param name name that is being mapped (at most 255 characters long) | ||
923 | * @param freshness when does the corresponding block in the DHT expire (until | ||
924 | * when should we never do a DHT lookup for the same name again)? | ||
925 | * @param rd_count number of entries in 'rd' array | ||
926 | * @param rd array of records with data to store | ||
927 | * @param signature signature for all the records in the zone under the given name | ||
928 | * @param cont continuation to call when done | 954 | * @param cont continuation to call when done |
929 | * @param cont_cls closure for cont | 955 | * @param cont_cls closure for cont |
930 | * @return handle to abort the request | 956 | * @return handle to abort the request |
931 | */ | 957 | */ |
932 | struct GNUNET_NAMESTORE_QueueEntry * | 958 | struct GNUNET_NAMESTORE_QueueEntry * |
933 | GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | 959 | GNUNET_NAMESTORE_block_cache (struct GNUNET_NAMESTORE_Handle *h, |
934 | const struct GNUNET_CRYPTO_EccPublicKey *zone_key, | 960 | const struct GNUNET_NAMESTORE_Block *block, |
935 | const char *name, | 961 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
936 | struct GNUNET_TIME_Absolute freshness, | 962 | void *cont_cls) |
937 | unsigned int rd_count, | ||
938 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
939 | const struct GNUNET_CRYPTO_EccSignature *signature, | ||
940 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
941 | void *cont_cls) | ||
942 | { | 963 | { |
943 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 964 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
944 | struct PendingMessage *pe; | 965 | struct PendingMessage *pe; |
945 | struct RecordPutMessage * msg; | 966 | struct BlockCacheMessage *msg; |
946 | char * rd_ser; | ||
947 | char * name_tmp; | ||
948 | size_t msg_size; | ||
949 | size_t name_len; | ||
950 | size_t rd_ser_len; | ||
951 | uint32_t rid; | 967 | uint32_t rid; |
968 | size_t blen; | ||
969 | size_t msg_size; | ||
952 | 970 | ||
953 | GNUNET_assert (NULL != h); | 971 | GNUNET_assert (NULL != h); |
954 | GNUNET_assert (NULL != zone_key); | 972 | blen = ntohl (block->purpose.size) - sizeof (struct GNUNET_TIME_AbsoluteNBO); |
955 | GNUNET_assert (NULL != name); | ||
956 | GNUNET_assert (NULL != rd); | ||
957 | GNUNET_assert (NULL != signature); | ||
958 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
959 | "Storing %u records under name `%s'\n", | ||
960 | rd_count, | ||
961 | name); | ||
962 | name_len = strlen(name) + 1; | ||
963 | if (name_len > MAX_NAME_LEN) | ||
964 | { | ||
965 | GNUNET_break (0); | ||
966 | return NULL; | ||
967 | } | ||
968 | rid = get_op_id (h); | 973 | rid = get_op_id (h); |
969 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 974 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
970 | qe->nsh = h; | 975 | qe->nsh = h; |
971 | qe->cont = cont; | 976 | qe->cont = cont; |
972 | qe->cont_cls = cont_cls; | 977 | qe->cont_cls = cont_cls; |
@@ -974,29 +979,21 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
974 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); | 979 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); |
975 | 980 | ||
976 | /* setup msg */ | 981 | /* setup msg */ |
977 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd); | 982 | msg_size = sizeof (struct BlockCacheMessage) + blen; |
978 | msg_size = sizeof (struct RecordPutMessage) + name_len + rd_ser_len; | 983 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); |
979 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | ||
980 | pe->size = msg_size; | 984 | pe->size = msg_size; |
981 | pe->is_init = GNUNET_NO; | 985 | msg = (struct BlockCacheMessage *) &pe[1]; |
982 | msg = (struct RecordPutMessage *) &pe[1]; | 986 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE); |
983 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT); | ||
984 | msg->gns_header.header.size = htons (msg_size); | 987 | msg->gns_header.header.size = htons (msg_size); |
985 | msg->gns_header.r_id = htonl (rid); | 988 | msg->gns_header.r_id = htonl (rid); |
986 | msg->signature = *signature; | 989 | msg->expire = block->expiration_time; |
987 | msg->name_len = htons (name_len); | 990 | msg->signature = block->signature; |
988 | msg->expire = GNUNET_TIME_absolute_hton (freshness); | 991 | msg->derived_key = block->derived_key; |
989 | msg->rd_len = htons (rd_ser_len); | 992 | memcpy (&msg[1], &block[1], blen); |
990 | msg->rd_count = htons (rd_count); | ||
991 | msg->public_key = *zone_key; | ||
992 | name_tmp = (char *) &msg[1]; | ||
993 | memcpy (name_tmp, name, name_len); | ||
994 | rd_ser = &name_tmp[name_len]; | ||
995 | GNUNET_break (rd_ser_len == GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser)); | ||
996 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 993 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
997 | "Sending `%s' message for name `%s' with size %u\n", | 994 | "Sending `%s' message with size %u\n", |
998 | "NAMESTORE_RECORD_PUT", | 995 | "NAMESTORE_BLOCK_CACHE", |
999 | name, msg_size); | 996 | (unsigned int) msg_size); |
1000 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | 997 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); |
1001 | do_transmit(h); | 998 | do_transmit(h); |
1002 | return qe; | 999 | return qe; |
@@ -1004,86 +1001,27 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, | |||
1004 | 1001 | ||
1005 | 1002 | ||
1006 | /** | 1003 | /** |
1007 | * Check if a signature is valid. This API is used by the GNS Block | ||
1008 | * to validate signatures received from the network. | ||
1009 | * | ||
1010 | * @param public_key public key of the zone | ||
1011 | * @param freshness block expiration | ||
1012 | * @param name name that is being mapped (at most 255 characters long) | ||
1013 | * @param rd_count number of entries in 'rd' array | ||
1014 | * @param rd array of records with data to store | ||
1015 | * @param signature signature for all the records in the zone under the given name | ||
1016 | * @return GNUNET_OK if the signature is valid | ||
1017 | */ | ||
1018 | int | ||
1019 | GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_EccPublicKey *public_key, | ||
1020 | const struct GNUNET_TIME_Absolute freshness, | ||
1021 | const char *name, | ||
1022 | unsigned int rd_count, | ||
1023 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
1024 | const struct GNUNET_CRYPTO_EccSignature *signature) | ||
1025 | { | ||
1026 | size_t rd_ser_len; | ||
1027 | size_t name_len; | ||
1028 | char *name_tmp; | ||
1029 | char *rd_ser; | ||
1030 | struct GNUNET_CRYPTO_EccSignaturePurpose *sig_purpose; | ||
1031 | struct GNUNET_TIME_AbsoluteNBO *expire_tmp; | ||
1032 | struct GNUNET_TIME_AbsoluteNBO expire_nbo = GNUNET_TIME_absolute_hton (freshness); | ||
1033 | uint32_t sig_len; | ||
1034 | |||
1035 | GNUNET_assert (NULL != public_key); | ||
1036 | GNUNET_assert (NULL != name); | ||
1037 | GNUNET_assert (NULL != rd); | ||
1038 | GNUNET_assert (NULL != signature); | ||
1039 | name_len = strlen (name) + 1; | ||
1040 | if (name_len > MAX_NAME_LEN) | ||
1041 | { | ||
1042 | GNUNET_break (0); | ||
1043 | return GNUNET_SYSERR; | ||
1044 | } | ||
1045 | rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); | ||
1046 | sig_len = sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + rd_ser_len + name_len; | ||
1047 | { | ||
1048 | char sig_buf[sig_len] GNUNET_ALIGN; | ||
1049 | |||
1050 | sig_purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose *) sig_buf; | ||
1051 | sig_purpose->size = htonl (sig_len); | ||
1052 | sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
1053 | expire_tmp = (struct GNUNET_TIME_AbsoluteNBO *) &sig_purpose[1]; | ||
1054 | memcpy (expire_tmp, &expire_nbo, sizeof (struct GNUNET_TIME_AbsoluteNBO)); | ||
1055 | name_tmp = (char *) &expire_tmp[1]; | ||
1056 | memcpy (name_tmp, name, name_len); | ||
1057 | rd_ser = &name_tmp[name_len]; | ||
1058 | GNUNET_assert (rd_ser_len == | ||
1059 | GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser)); | ||
1060 | return GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, sig_purpose, signature, public_key); | ||
1061 | } | ||
1062 | } | ||
1063 | |||
1064 | |||
1065 | /** | ||
1066 | * Store an item in the namestore. If the item is already present, | 1004 | * Store an item in the namestore. If the item is already present, |
1067 | * the expiration time is updated to the max of the existing time and | 1005 | * it is replaced with the new record. Use an empty array to |
1068 | * the new time. This API is used by the authority of a zone. | 1006 | * remove all records under the given name. |
1069 | * | 1007 | * |
1070 | * @param h handle to the namestore | 1008 | * @param h handle to the namestore |
1071 | * @param pkey private key of the zone | 1009 | * @param pkey private key of the zone |
1072 | * @param name name that is being mapped (at most 255 characters long) | 1010 | * @param label name that is being mapped (at most 255 characters long) |
1073 | * @param rd_count number of records in 'rd' array | 1011 | * @param rd_count number of records in the 'rd' array |
1074 | * @param rd record data to store | 1012 | * @param rd array of records with data to store |
1075 | * @param cont continuation to call when done | 1013 | * @param cont continuation to call when done |
1076 | * @param cont_cls closure for cont | 1014 | * @param cont_cls closure for 'cont' |
1077 | * @return handle to abort the request | 1015 | * @return handle to abort the request |
1078 | */ | 1016 | */ |
1079 | struct GNUNET_NAMESTORE_QueueEntry * | 1017 | struct GNUNET_NAMESTORE_QueueEntry * |
1080 | GNUNET_NAMESTORE_record_put_by_authority (struct GNUNET_NAMESTORE_Handle *h, | 1018 | GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, |
1081 | const struct GNUNET_CRYPTO_EccPrivateKey *pkey, | 1019 | const struct GNUNET_CRYPTO_EccPrivateKey *pkey, |
1082 | const char *name, | 1020 | const char *label, |
1083 | unsigned int rd_count, | 1021 | unsigned int rd_count, |
1084 | const struct GNUNET_NAMESTORE_RecordData *rd, | 1022 | const struct GNUNET_NAMESTORE_RecordData *rd, |
1085 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | 1023 | GNUNET_NAMESTORE_ContinuationWithStatus cont, |
1086 | void *cont_cls) | 1024 | void *cont_cls) |
1087 | { | 1025 | { |
1088 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 1026 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
1089 | struct PendingMessage *pe; | 1027 | struct PendingMessage *pe; |
@@ -1093,19 +1031,19 @@ GNUNET_NAMESTORE_record_put_by_authority (struct GNUNET_NAMESTORE_Handle *h, | |||
1093 | size_t msg_size; | 1031 | size_t msg_size; |
1094 | size_t name_len; | 1032 | size_t name_len; |
1095 | uint32_t rid; | 1033 | uint32_t rid; |
1096 | struct RecordCreateMessage *msg; | 1034 | struct RecordStoreMessage *msg; |
1097 | 1035 | ||
1098 | GNUNET_assert (NULL != h); | 1036 | GNUNET_assert (NULL != h); |
1099 | GNUNET_assert (NULL != pkey); | 1037 | GNUNET_assert (NULL != pkey); |
1100 | GNUNET_assert (NULL != name); | 1038 | GNUNET_assert (NULL != label); |
1101 | name_len = strlen(name) + 1; | 1039 | name_len = strlen (label) + 1; |
1102 | if (name_len > MAX_NAME_LEN) | 1040 | if (name_len > MAX_NAME_LEN) |
1103 | { | 1041 | { |
1104 | GNUNET_break (0); | 1042 | GNUNET_break (0); |
1105 | return NULL; | 1043 | return NULL; |
1106 | } | 1044 | } |
1107 | rid = get_op_id (h); | 1045 | rid = get_op_id (h); |
1108 | qe = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 1046 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1109 | qe->nsh = h; | 1047 | qe->nsh = h; |
1110 | qe->cont = cont; | 1048 | qe->cont = cont; |
1111 | qe->cont_cls = cont_cls; | 1049 | qe->cont_cls = cont_cls; |
@@ -1114,29 +1052,27 @@ GNUNET_NAMESTORE_record_put_by_authority (struct GNUNET_NAMESTORE_Handle *h, | |||
1114 | 1052 | ||
1115 | /* setup msg */ | 1053 | /* setup msg */ |
1116 | rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); | 1054 | rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); |
1117 | msg_size = sizeof (struct RecordCreateMessage) + name_len + rd_ser_len; | 1055 | msg_size = sizeof (struct RecordStoreMessage) + name_len + rd_ser_len; |
1118 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); | 1056 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); |
1119 | pe->size = msg_size; | 1057 | pe->size = msg_size; |
1120 | pe->is_init = GNUNET_NO; | 1058 | msg = (struct RecordStoreMessage *) &pe[1]; |
1121 | msg = (struct RecordCreateMessage *) &pe[1]; | 1059 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); |
1122 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE); | ||
1123 | msg->gns_header.header.size = htons (msg_size); | 1060 | msg->gns_header.header.size = htons (msg_size); |
1124 | msg->gns_header.r_id = htonl (rid); | 1061 | msg->gns_header.r_id = htonl (rid); |
1125 | msg->name_len = htons (name_len); | 1062 | msg->name_len = htons (name_len); |
1126 | msg->rd_count = htons (rd_count); | 1063 | msg->rd_count = htons (rd_count); |
1127 | msg->rd_len = htons (rd_ser_len); | 1064 | msg->rd_len = htons (rd_ser_len); |
1128 | msg->reserved = htons (0); | 1065 | msg->reserved = htons (0); |
1129 | msg->expire = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); | ||
1130 | msg->private_key = *pkey; | 1066 | msg->private_key = *pkey; |
1131 | 1067 | ||
1132 | name_tmp = (char *) &msg[1]; | 1068 | name_tmp = (char *) &msg[1]; |
1133 | memcpy (name_tmp, name, name_len); | 1069 | memcpy (name_tmp, label, name_len); |
1134 | rd_ser = &name_tmp[name_len]; | 1070 | rd_ser = &name_tmp[name_len]; |
1135 | GNUNET_break (rd_ser_len == GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser)); | 1071 | GNUNET_break (rd_ser_len == GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser)); |
1136 | 1072 | ||
1137 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1073 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1138 | "Sending `%s' message for name `%s' with size %u\n", | 1074 | "Sending `%s' message for name `%s' with size %u\n", |
1139 | "NAMESTORE_RECORD_CREATE", name, msg_size); | 1075 | "NAMESTORE_RECORD_STORE", label, msg_size); |
1140 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | 1076 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); |
1141 | do_transmit(h); | 1077 | do_transmit(h); |
1142 | return qe; | 1078 | return qe; |
@@ -1148,66 +1084,45 @@ GNUNET_NAMESTORE_record_put_by_authority (struct GNUNET_NAMESTORE_Handle *h, | |||
1148 | * will only be called once. | 1084 | * will only be called once. |
1149 | * | 1085 | * |
1150 | * @param h handle to the namestore | 1086 | * @param h handle to the namestore |
1151 | * @param zone zone to look up a record from | 1087 | * @param derived_hash hash of zone key combined with name to lookup |
1152 | * @param name name to look up | 1088 | * @param proc function to call on the matching block, or with |
1153 | * @param record_type desired record type, 0 for all | 1089 | * NULL if there is no matching block |
1154 | * @param proc function to call on the matching records, or with | ||
1155 | * NULL (rd_count == 0) if there are no matching records | ||
1156 | * @param proc_cls closure for proc | 1090 | * @param proc_cls closure for proc |
1157 | * @return a handle that can be used to | 1091 | * @return a handle that can be used to cancel |
1158 | * cancel | ||
1159 | */ | 1092 | */ |
1160 | struct GNUNET_NAMESTORE_QueueEntry * | 1093 | struct GNUNET_NAMESTORE_QueueEntry * |
1161 | GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | 1094 | GNUNET_NAMESTORE_lookup_block (struct GNUNET_NAMESTORE_Handle *h, |
1162 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 1095 | const struct GNUNET_HashCode *derived_hash, |
1163 | const char *name, | 1096 | GNUNET_NAMESTORE_BlockProcessor proc, void *proc_cls) |
1164 | uint32_t record_type, | ||
1165 | GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) | ||
1166 | { | 1097 | { |
1098 | |||
1167 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 1099 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
1168 | struct PendingMessage *pe; | 1100 | struct PendingMessage *pe; |
1169 | struct LookupNameMessage * msg; | 1101 | struct LookupBlockMessage *msg; |
1170 | size_t msg_size; | 1102 | size_t msg_size; |
1171 | size_t name_len; | ||
1172 | uint32_t rid; | 1103 | uint32_t rid; |
1173 | 1104 | ||
1174 | GNUNET_assert (NULL != h); | 1105 | GNUNET_assert (NULL != h); |
1175 | GNUNET_assert (NULL != zone); | 1106 | GNUNET_assert (NULL != derived_hash); |
1176 | GNUNET_assert (NULL != name); | ||
1177 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1107 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1178 | "Looking for record of type %u under name `%s'\n", | 1108 | "Looking for block under %s\n", |
1179 | record_type, | 1109 | GNUNET_h2s (derived_hash)); |
1180 | name); | ||
1181 | name_len = strlen (name) + 1; | ||
1182 | if ((name_len == 0) || (name_len > MAX_NAME_LEN)) | ||
1183 | { | ||
1184 | GNUNET_break (0); | ||
1185 | return NULL; | ||
1186 | } | ||
1187 | |||
1188 | rid = get_op_id(h); | 1110 | rid = get_op_id(h); |
1189 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 1111 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1190 | qe->nsh = h; | 1112 | qe->nsh = h; |
1191 | qe->proc = proc; | 1113 | qe->block_proc = proc; |
1192 | qe->proc_cls = proc_cls; | 1114 | qe->block_proc_cls = proc_cls; |
1193 | qe->op_id = rid; | 1115 | qe->op_id = rid; |
1194 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); | 1116 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); |
1195 | 1117 | ||
1196 | msg_size = sizeof (struct LookupNameMessage) + name_len; | 1118 | msg_size = sizeof (struct LookupBlockMessage); |
1197 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 1119 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); |
1198 | pe->size = msg_size; | 1120 | pe->size = msg_size; |
1199 | pe->is_init = GNUNET_NO; | 1121 | msg = (struct LookupBlockMessage *) &pe[1]; |
1200 | msg = (struct LookupNameMessage *) &pe[1]; | 1122 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK); |
1201 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); | ||
1202 | msg->gns_header.header.size = htons (msg_size); | 1123 | msg->gns_header.header.size = htons (msg_size); |
1203 | msg->gns_header.r_id = htonl (rid); | 1124 | msg->gns_header.r_id = htonl (rid); |
1204 | msg->record_type = htonl (record_type); | 1125 | msg->query = *derived_hash; |
1205 | msg->name_len = htonl (name_len); | ||
1206 | msg->zone = *zone; | ||
1207 | memcpy (&msg[1], name, name_len); | ||
1208 | |||
1209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1210 | "Sending `%s' message for name `%s'\n", "NAMESTORE_LOOKUP_NAME", name); | ||
1211 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | 1126 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); |
1212 | do_transmit(h); | 1127 | do_transmit(h); |
1213 | return qe; | 1128 | return qe; |
@@ -1219,8 +1134,8 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
1219 | * Returns at most one result to the processor. | 1134 | * Returns at most one result to the processor. |
1220 | * | 1135 | * |
1221 | * @param h handle to the namestore | 1136 | * @param h handle to the namestore |
1222 | * @param zone hash of public key of the zone to look up in, never NULL | 1137 | * @param zone public key of the zone to look up in, never NULL |
1223 | * @param value_zone hash of the public key of the target zone (value), never NULL | 1138 | * @param value_zone public key of the target zone (value), never NULL |
1224 | * @param proc function to call on the matching records, or with | 1139 | * @param proc function to call on the matching records, or with |
1225 | * NULL (rd_count == 0) if there are no matching records | 1140 | * NULL (rd_count == 0) if there are no matching records |
1226 | * @param proc_cls closure for proc | 1141 | * @param proc_cls closure for proc |
@@ -1229,9 +1144,9 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
1229 | */ | 1144 | */ |
1230 | struct GNUNET_NAMESTORE_QueueEntry * | 1145 | struct GNUNET_NAMESTORE_QueueEntry * |
1231 | GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | 1146 | GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, |
1232 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 1147 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, |
1233 | const struct GNUNET_CRYPTO_ShortHashCode *value_zone, | 1148 | const struct GNUNET_CRYPTO_EccPublicKey *value_zone, |
1234 | GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls) | 1149 | GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls) |
1235 | { | 1150 | { |
1236 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 1151 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
1237 | struct PendingMessage *pe; | 1152 | struct PendingMessage *pe; |
@@ -1243,7 +1158,7 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | |||
1243 | GNUNET_assert (NULL != zone); | 1158 | GNUNET_assert (NULL != zone); |
1244 | GNUNET_assert (NULL != value_zone); | 1159 | GNUNET_assert (NULL != value_zone); |
1245 | rid = get_op_id(h); | 1160 | rid = get_op_id(h); |
1246 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 1161 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1247 | qe->nsh = h; | 1162 | qe->nsh = h; |
1248 | qe->proc = proc; | 1163 | qe->proc = proc; |
1249 | qe->proc_cls = proc_cls; | 1164 | qe->proc_cls = proc_cls; |
@@ -1251,9 +1166,8 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | |||
1251 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); | 1166 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); |
1252 | 1167 | ||
1253 | msg_size = sizeof (struct ZoneToNameMessage); | 1168 | msg_size = sizeof (struct ZoneToNameMessage); |
1254 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 1169 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); |
1255 | pe->size = msg_size; | 1170 | pe->size = msg_size; |
1256 | pe->is_init = GNUNET_NO; | ||
1257 | msg = (struct ZoneToNameMessage *) &pe[1]; | 1171 | msg = (struct ZoneToNameMessage *) &pe[1]; |
1258 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); | 1172 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); |
1259 | msg->gns_header.header.size = htons (msg_size); | 1173 | msg->gns_header.header.size = htons (msg_size); |
@@ -1277,9 +1191,7 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | |||
1277 | * "GNUNET_NAMESTORE_zone_iterator_next" is invoked. | 1191 | * "GNUNET_NAMESTORE_zone_iterator_next" is invoked. |
1278 | * | 1192 | * |
1279 | * @param h handle to the namestore | 1193 | * @param h handle to the namestore |
1280 | * @param zone zone to access, NULL for all zones | 1194 | * @param zone zone to access |
1281 | * @param must_have_flags flags that must be set for the record to be returned | ||
1282 | * @param must_not_have_flags flags that must NOT be set for the record to be returned | ||
1283 | * @param proc function to call on each name from the zone; it | 1195 | * @param proc function to call on each name from the zone; it |
1284 | * will be called repeatedly with a value (if available) | 1196 | * will be called repeatedly with a value (if available) |
1285 | * and always once at the end with a name of NULL. | 1197 | * and always once at the end with a name of NULL. |
@@ -1288,10 +1200,8 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | |||
1288 | */ | 1200 | */ |
1289 | struct GNUNET_NAMESTORE_ZoneIterator * | 1201 | struct GNUNET_NAMESTORE_ZoneIterator * |
1290 | GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, | 1202 | GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, |
1291 | const struct GNUNET_CRYPTO_ShortHashCode *zone, | 1203 | const struct GNUNET_CRYPTO_EccPrivateKey *zone, |
1292 | enum GNUNET_NAMESTORE_RecordFlags must_have_flags, | 1204 | GNUNET_NAMESTORE_RecordMonitor proc, |
1293 | enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags, | ||
1294 | GNUNET_NAMESTORE_RecordProcessor proc, | ||
1295 | void *proc_cls) | 1205 | void *proc_cls) |
1296 | { | 1206 | { |
1297 | struct GNUNET_NAMESTORE_ZoneIterator *it; | 1207 | struct GNUNET_NAMESTORE_ZoneIterator *it; |
@@ -1302,46 +1212,22 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, | |||
1302 | 1212 | ||
1303 | GNUNET_assert (NULL != h); | 1213 | GNUNET_assert (NULL != h); |
1304 | rid = get_op_id(h); | 1214 | rid = get_op_id(h); |
1305 | it = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_ZoneIterator)); | 1215 | it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator); |
1306 | it->h = h; | 1216 | it->h = h; |
1307 | it->proc = proc; | 1217 | it->proc = proc; |
1308 | it->proc_cls = proc_cls; | 1218 | it->proc_cls = proc_cls; |
1309 | it->op_id = rid; | 1219 | it->op_id = rid; |
1310 | if (NULL != zone) | 1220 | it->zone = *zone; |
1311 | { | ||
1312 | it->zone = *zone; | ||
1313 | it->has_zone = GNUNET_YES; | ||
1314 | } | ||
1315 | else | ||
1316 | { | ||
1317 | memset (&it->zone, '\0', sizeof (it->zone)); | ||
1318 | it->has_zone = GNUNET_NO; | ||
1319 | } | ||
1320 | GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); | 1221 | GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); |
1321 | 1222 | ||
1322 | msg_size = sizeof (struct ZoneIterationStartMessage); | 1223 | msg_size = sizeof (struct ZoneIterationStartMessage); |
1323 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); | 1224 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); |
1324 | pe->size = msg_size; | 1225 | pe->size = msg_size; |
1325 | pe->is_init = GNUNET_NO; | ||
1326 | msg = (struct ZoneIterationStartMessage *) &pe[1]; | 1226 | msg = (struct ZoneIterationStartMessage *) &pe[1]; |
1327 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); | 1227 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); |
1328 | msg->gns_header.header.size = htons (msg_size); | 1228 | msg->gns_header.header.size = htons (msg_size); |
1329 | msg->gns_header.r_id = htonl (rid); | 1229 | msg->gns_header.r_id = htonl (rid); |
1330 | if (NULL != zone) | 1230 | msg->zone = *zone; |
1331 | { | ||
1332 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1333 | "Sending `%s' message for zone `%s'\n", | ||
1334 | "ZONE_ITERATION_START", GNUNET_NAMESTORE_short_h2s(zone)); | ||
1335 | msg->zone = *zone; | ||
1336 | } | ||
1337 | else | ||
1338 | { | ||
1339 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1340 | "Sending `%s' message for all zones\n", "ZONE_ITERATION_START"); | ||
1341 | memset (&msg->zone, '\0', sizeof (msg->zone)); | ||
1342 | } | ||
1343 | msg->must_have_flags = ntohs (must_have_flags); | ||
1344 | msg->must_not_have_flags = ntohs (must_not_have_flags); | ||
1345 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | 1231 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); |
1346 | do_transmit(h); | 1232 | do_transmit(h); |
1347 | return it; | 1233 | return it; |
@@ -1365,9 +1251,8 @@ GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it) | |||
1365 | GNUNET_assert (NULL != it); | 1251 | GNUNET_assert (NULL != it); |
1366 | h = it->h; | 1252 | h = it->h; |
1367 | msg_size = sizeof (struct ZoneIterationNextMessage); | 1253 | msg_size = sizeof (struct ZoneIterationNextMessage); |
1368 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 1254 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); |
1369 | pe->size = msg_size; | 1255 | pe->size = msg_size; |
1370 | pe->is_init = GNUNET_NO; | ||
1371 | msg = (struct ZoneIterationNextMessage *) &pe[1]; | 1256 | msg = (struct ZoneIterationNextMessage *) &pe[1]; |
1372 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); | 1257 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); |
1373 | msg->gns_header.header.size = htons (msg_size); | 1258 | msg->gns_header.header.size = htons (msg_size); |
@@ -1397,19 +1282,15 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it) | |||
1397 | h->z_tail, | 1282 | h->z_tail, |
1398 | it); | 1283 | it); |
1399 | msg_size = sizeof (struct ZoneIterationStopMessage); | 1284 | msg_size = sizeof (struct ZoneIterationStopMessage); |
1400 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 1285 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); |
1401 | pe->size = msg_size; | 1286 | pe->size = msg_size; |
1402 | pe->is_init = GNUNET_NO; | ||
1403 | msg = (struct ZoneIterationStopMessage *) &pe[1]; | 1287 | msg = (struct ZoneIterationStopMessage *) &pe[1]; |
1404 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); | 1288 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); |
1405 | msg->gns_header.header.size = htons (msg_size); | 1289 | msg->gns_header.header.size = htons (msg_size); |
1406 | msg->gns_header.r_id = htonl (it->op_id); | 1290 | msg->gns_header.r_id = htonl (it->op_id); |
1407 | if (GNUNET_YES == it->has_zone) | 1291 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1292 | "Sending `%s' message\n", |
1409 | "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_STOP", GNUNET_NAMESTORE_short_h2s(&it->zone)); | 1293 | "ZONE_ITERATION_STOP"); |
1410 | else | ||
1411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1412 | "Sending `%s' message for all zones\n", "ZONE_ITERATION_STOP"); | ||
1413 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | 1294 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); |
1414 | do_transmit(h); | 1295 | do_transmit(h); |
1415 | GNUNET_free (it); | 1296 | GNUNET_free (it); |