aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/namestore_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r--src/namestore/namestore_api.c841
1 files changed, 419 insertions, 422 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 6c64062ea..c80ca0bd5 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file namestore/namestore_api.c 22 * @file namestore/namestore_api.c
@@ -38,7 +38,7 @@
38#include "namestore.h" 38#include "namestore.h"
39 39
40 40
41#define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__) 41#define LOG(kind, ...) GNUNET_log_from(kind, "namestore-api", __VA_ARGS__)
42 42
43/** 43/**
44 * We grant the namestore up to 1 minute of latency, if it is slower than 44 * We grant the namestore up to 1 minute of latency, if it is slower than
@@ -50,9 +50,7 @@
50 * An QueueEntry used to store information for a pending 50 * An QueueEntry used to store information for a pending
51 * NAMESTORE record operation 51 * NAMESTORE record operation
52 */ 52 */
53struct GNUNET_NAMESTORE_QueueEntry 53struct GNUNET_NAMESTORE_QueueEntry {
54{
55
56 /** 54 /**
57 * Kept in a DLL. 55 * Kept in a DLL.
58 */ 56 */
@@ -119,9 +117,7 @@ struct GNUNET_NAMESTORE_QueueEntry
119/** 117/**
120 * Handle for a zone iterator operation 118 * Handle for a zone iterator operation
121 */ 119 */
122struct GNUNET_NAMESTORE_ZoneIterator 120struct GNUNET_NAMESTORE_ZoneIterator {
123{
124
125 /** 121 /**
126 * Kept in a DLL. 122 * Kept in a DLL.
127 */ 123 */
@@ -188,9 +184,7 @@ struct GNUNET_NAMESTORE_ZoneIterator
188/** 184/**
189 * Connection to the NAMESTORE service. 185 * Connection to the NAMESTORE service.
190 */ 186 */
191struct GNUNET_NAMESTORE_Handle 187struct GNUNET_NAMESTORE_Handle {
192{
193
194 /** 188 /**
195 * Configuration to use. 189 * Configuration to use.
196 */ 190 */
@@ -249,7 +243,7 @@ struct GNUNET_NAMESTORE_Handle
249 * @param h our handle 243 * @param h our handle
250 */ 244 */
251static void 245static void
252force_reconnect (struct GNUNET_NAMESTORE_Handle *h); 246force_reconnect(struct GNUNET_NAMESTORE_Handle *h);
253 247
254 248
255/** 249/**
@@ -260,7 +254,7 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h);
260 * @return NULL if @a rid was not found 254 * @return NULL if @a rid was not found
261 */ 255 */
262static struct GNUNET_NAMESTORE_QueueEntry * 256static struct GNUNET_NAMESTORE_QueueEntry *
263find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) 257find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
264{ 258{
265 struct GNUNET_NAMESTORE_QueueEntry *qe; 259 struct GNUNET_NAMESTORE_QueueEntry *qe;
266 260
@@ -279,7 +273,7 @@ find_qe (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
279 * @return NULL if @a rid was not found 273 * @return NULL if @a rid was not found
280 */ 274 */
281static struct GNUNET_NAMESTORE_ZoneIterator * 275static struct GNUNET_NAMESTORE_ZoneIterator *
282find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid) 276find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
283{ 277{
284 struct GNUNET_NAMESTORE_ZoneIterator *ze; 278 struct GNUNET_NAMESTORE_ZoneIterator *ze;
285 279
@@ -296,16 +290,16 @@ find_zi (struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
296 * @param qe entry to free 290 * @param qe entry to free
297 */ 291 */
298static void 292static void
299free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe) 293free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
300{ 294{
301 struct GNUNET_NAMESTORE_Handle *h = qe->h; 295 struct GNUNET_NAMESTORE_Handle *h = qe->h;
302 296
303 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, qe); 297 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
304 if (NULL != qe->env) 298 if (NULL != qe->env)
305 GNUNET_MQ_discard (qe->env); 299 GNUNET_MQ_discard(qe->env);
306 if (NULL != qe->timeout_task) 300 if (NULL != qe->timeout_task)
307 GNUNET_SCHEDULER_cancel (qe->timeout_task); 301 GNUNET_SCHEDULER_cancel(qe->timeout_task);
308 GNUNET_free (qe); 302 GNUNET_free(qe);
309} 303}
310 304
311 305
@@ -315,14 +309,14 @@ free_qe (struct GNUNET_NAMESTORE_QueueEntry *qe)
315 * @param ze entry to free 309 * @param ze entry to free
316 */ 310 */
317static void 311static void
318free_ze (struct GNUNET_NAMESTORE_ZoneIterator *ze) 312free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
319{ 313{
320 struct GNUNET_NAMESTORE_Handle *h = ze->h; 314 struct GNUNET_NAMESTORE_Handle *h = ze->h;
321 315
322 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, ze); 316 GNUNET_CONTAINER_DLL_remove(h->z_head, h->z_tail, ze);
323 if (NULL != ze->env) 317 if (NULL != ze->env)
324 GNUNET_MQ_discard (ze->env); 318 GNUNET_MQ_discard(ze->env);
325 GNUNET_free (ze); 319 GNUNET_free(ze);
326} 320}
327 321
328 322
@@ -336,16 +330,16 @@ free_ze (struct GNUNET_NAMESTORE_ZoneIterator *ze)
336 * @return #GNUNET_OK if @a rd_buf is well-formed 330 * @return #GNUNET_OK if @a rd_buf is well-formed
337 */ 331 */
338static int 332static int
339check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count) 333check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
340{ 334{
341 struct GNUNET_GNSRECORD_Data rd[rd_count]; 335 struct GNUNET_GNSRECORD_Data rd[rd_count];
342 336
343 if (GNUNET_OK != 337 if (GNUNET_OK !=
344 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_buf, rd_count, rd)) 338 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_buf, rd_count, rd))
345 { 339 {
346 GNUNET_break (0); 340 GNUNET_break(0);
347 return GNUNET_SYSERR; 341 return GNUNET_SYSERR;
348 } 342 }
349 return GNUNET_OK; 343 return GNUNET_OK;
350} 344}
351 345
@@ -358,27 +352,27 @@ check_rd (size_t rd_len, const void *rd_buf, unsigned int rd_count)
358 * @param msg the message we received 352 * @param msg the message we received
359 */ 353 */
360static void 354static void
361handle_record_store_response (void *cls, 355handle_record_store_response(void *cls,
362 const struct RecordStoreResponseMessage *msg) 356 const struct RecordStoreResponseMessage *msg)
363{ 357{
364 struct GNUNET_NAMESTORE_Handle *h = cls; 358 struct GNUNET_NAMESTORE_Handle *h = cls;
365 struct GNUNET_NAMESTORE_QueueEntry *qe; 359 struct GNUNET_NAMESTORE_QueueEntry *qe;
366 int res; 360 int res;
367 const char *emsg; 361 const char *emsg;
368 362
369 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 363 qe = find_qe(h, ntohl(msg->gns_header.r_id));
370 res = ntohl (msg->op_result); 364 res = ntohl(msg->op_result);
371 LOG (GNUNET_ERROR_TYPE_DEBUG, 365 LOG(GNUNET_ERROR_TYPE_DEBUG,
372 "Received RECORD_STORE_RESPONSE with result %d\n", 366 "Received RECORD_STORE_RESPONSE with result %d\n",
373 res); 367 res);
374 /* TODO: add actual error message from namestore to response... */ 368 /* TODO: add actual error message from namestore to response... */
375 if (GNUNET_SYSERR == res) 369 if (GNUNET_SYSERR == res)
376 emsg = _ ("Namestore failed to store record\n"); 370 emsg = _("Namestore failed to store record\n");
377 else 371 else
378 emsg = NULL; 372 emsg = NULL;
379 if (NULL != qe->cont) 373 if (NULL != qe->cont)
380 qe->cont (qe->cont_cls, res, emsg); 374 qe->cont(qe->cont_cls, res, emsg);
381 free_qe (qe); 375 free_qe(qe);
382} 376}
383 377
384 378
@@ -391,7 +385,7 @@ handle_record_store_response (void *cls,
391 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 385 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
392 */ 386 */
393static int 387static int
394check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) 388check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
395{ 389{
396 const char *name; 390 const char *name;
397 size_t exp_msg_len; 391 size_t exp_msg_len;
@@ -399,32 +393,32 @@ check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
399 size_t name_len; 393 size_t name_len;
400 size_t rd_len; 394 size_t rd_len;
401 395
402 (void) cls; 396 (void)cls;
403 rd_len = ntohs (msg->rd_len); 397 rd_len = ntohs(msg->rd_len);
404 msg_len = ntohs (msg->gns_header.header.size); 398 msg_len = ntohs(msg->gns_header.header.size);
405 name_len = ntohs (msg->name_len); 399 name_len = ntohs(msg->name_len);
406 exp_msg_len = sizeof (*msg) + name_len + rd_len; 400 exp_msg_len = sizeof(*msg) + name_len + rd_len;
407 if (msg_len != exp_msg_len) 401 if (msg_len != exp_msg_len)
408 { 402 {
409 GNUNET_break (0); 403 GNUNET_break(0);
410 return GNUNET_SYSERR; 404 return GNUNET_SYSERR;
411 } 405 }
412 name = (const char *) &msg[1]; 406 name = (const char *)&msg[1];
413 if ((name_len > 0) && ('\0' != name[name_len - 1])) 407 if ((name_len > 0) && ('\0' != name[name_len - 1]))
414 {
415 GNUNET_break (0);
416 return GNUNET_SYSERR;
417 }
418 if (GNUNET_NO == ntohs (msg->found))
419 {
420 if (0 != ntohs (msg->rd_count))
421 { 408 {
422 GNUNET_break (0); 409 GNUNET_break(0);
423 return GNUNET_SYSERR; 410 return GNUNET_SYSERR;
424 } 411 }
425 return GNUNET_OK; 412 if (GNUNET_NO == ntohs(msg->found))
426 } 413 {
427 return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count)); 414 if (0 != ntohs(msg->rd_count))
415 {
416 GNUNET_break(0);
417 return GNUNET_SYSERR;
418 }
419 return GNUNET_OK;
420 }
421 return check_rd(rd_len, &name[name_len], ntohs(msg->rd_count));
428} 422}
429 423
430 424
@@ -436,7 +430,7 @@ check_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
436 * @param msg the message we received 430 * @param msg the message we received
437 */ 431 */
438static void 432static void
439handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg) 433handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
440{ 434{
441 struct GNUNET_NAMESTORE_Handle *h = cls; 435 struct GNUNET_NAMESTORE_Handle *h = cls;
442 struct GNUNET_NAMESTORE_QueueEntry *qe; 436 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -446,40 +440,40 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
446 size_t rd_len; 440 size_t rd_len;
447 unsigned int rd_count; 441 unsigned int rd_count;
448 442
449 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n"); 443 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_LOOKUP_RESULT\n");
450 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 444 qe = find_qe(h, ntohl(msg->gns_header.r_id));
451 if (NULL == qe) 445 if (NULL == qe)
452 return; 446 return;
453 rd_len = ntohs (msg->rd_len); 447 rd_len = ntohs(msg->rd_len);
454 rd_count = ntohs (msg->rd_count); 448 rd_count = ntohs(msg->rd_count);
455 name_len = ntohs (msg->name_len); 449 name_len = ntohs(msg->name_len);
456 name = (const char *) &msg[1]; 450 name = (const char *)&msg[1];
457 if (GNUNET_NO == ntohs (msg->found)) 451 if (GNUNET_NO == ntohs(msg->found))
458 { 452 {
459 /* label was not in namestore */ 453 /* label was not in namestore */
460 if (NULL != qe->proc) 454 if (NULL != qe->proc)
461 qe->proc (qe->proc_cls, &msg->private_key, name, 0, NULL); 455 qe->proc(qe->proc_cls, &msg->private_key, name, 0, NULL);
462 free_qe (qe); 456 free_qe(qe);
463 return; 457 return;
464 } 458 }
465 459
466 rd_tmp = &name[name_len]; 460 rd_tmp = &name[name_len];
467 { 461 {
468 struct GNUNET_GNSRECORD_Data rd[rd_count]; 462 struct GNUNET_GNSRECORD_Data rd[rd_count];
469 463
470 GNUNET_assert ( 464 GNUNET_assert(
471 GNUNET_OK == 465 GNUNET_OK ==
472 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd)); 466 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd));
473 if (0 == name_len) 467 if (0 == name_len)
474 name = NULL; 468 name = NULL;
475 if (NULL != qe->proc) 469 if (NULL != qe->proc)
476 qe->proc (qe->proc_cls, 470 qe->proc(qe->proc_cls,
477 &msg->private_key, 471 &msg->private_key,
478 name, 472 name,
479 rd_count, 473 rd_count,
480 (rd_count > 0) ? rd : NULL); 474 (rd_count > 0) ? rd : NULL);
481 } 475 }
482 free_qe (qe); 476 free_qe(qe);
483} 477}
484 478
485 479
@@ -492,7 +486,7 @@ handle_lookup_result (void *cls, const struct LabelLookupResponseMessage *msg)
492 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 486 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
493 */ 487 */
494static int 488static int
495check_record_result (void *cls, const struct RecordResultMessage *msg) 489check_record_result(void *cls, const struct RecordResultMessage *msg)
496{ 490{
497 static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy; 491 static struct GNUNET_CRYPTO_EcdsaPrivateKey priv_dummy;
498 const char *name; 492 const char *name;
@@ -500,32 +494,32 @@ check_record_result (void *cls, const struct RecordResultMessage *msg)
500 size_t name_len; 494 size_t name_len;
501 size_t rd_len; 495 size_t rd_len;
502 496
503 (void) cls; 497 (void)cls;
504 rd_len = ntohs (msg->rd_len); 498 rd_len = ntohs(msg->rd_len);
505 msg_len = ntohs (msg->gns_header.header.size); 499 msg_len = ntohs(msg->gns_header.header.size);
506 name_len = ntohs (msg->name_len); 500 name_len = ntohs(msg->name_len);
507 if (0 != ntohs (msg->reserved)) 501 if (0 != ntohs(msg->reserved))
508 { 502 {
509 GNUNET_break (0); 503 GNUNET_break(0);
510 return GNUNET_SYSERR; 504 return GNUNET_SYSERR;
511 } 505 }
512 if (msg_len != sizeof (struct RecordResultMessage) + name_len + rd_len) 506 if (msg_len != sizeof(struct RecordResultMessage) + name_len + rd_len)
513 { 507 {
514 GNUNET_break (0); 508 GNUNET_break(0);
515 return GNUNET_SYSERR; 509 return GNUNET_SYSERR;
516 } 510 }
517 name = (const char *) &msg[1]; 511 name = (const char *)&msg[1];
518 if ((0 == name_len) || ('\0' != name[name_len - 1])) 512 if ((0 == name_len) || ('\0' != name[name_len - 1]))
519 { 513 {
520 GNUNET_break (0); 514 GNUNET_break(0);
521 return GNUNET_SYSERR; 515 return GNUNET_SYSERR;
522 } 516 }
523 if (0 == GNUNET_memcmp (&msg->private_key, &priv_dummy)) 517 if (0 == GNUNET_memcmp(&msg->private_key, &priv_dummy))
524 { 518 {
525 GNUNET_break (0); 519 GNUNET_break(0);
526 return GNUNET_SYSERR; 520 return GNUNET_SYSERR;
527 } 521 }
528 return check_rd (rd_len, &name[name_len], ntohs (msg->rd_count)); 522 return check_rd(rd_len, &name[name_len], ntohs(msg->rd_count));
529} 523}
530 524
531 525
@@ -537,7 +531,7 @@ check_record_result (void *cls, const struct RecordResultMessage *msg)
537 * @param msg the message we received 531 * @param msg the message we received
538 */ 532 */
539static void 533static void
540handle_record_result (void *cls, const struct RecordResultMessage *msg) 534handle_record_result(void *cls, const struct RecordResultMessage *msg)
541{ 535{
542 struct GNUNET_NAMESTORE_Handle *h = cls; 536 struct GNUNET_NAMESTORE_Handle *h = cls;
543 struct GNUNET_NAMESTORE_QueueEntry *qe; 537 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -548,49 +542,49 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
548 size_t rd_len; 542 size_t rd_len;
549 unsigned int rd_count; 543 unsigned int rd_count;
550 544
551 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n"); 545 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT\n");
552 rd_len = ntohs (msg->rd_len); 546 rd_len = ntohs(msg->rd_len);
553 rd_count = ntohs (msg->rd_count); 547 rd_count = ntohs(msg->rd_count);
554 name_len = ntohs (msg->name_len); 548 name_len = ntohs(msg->name_len);
555 ze = find_zi (h, ntohl (msg->gns_header.r_id)); 549 ze = find_zi(h, ntohl(msg->gns_header.r_id));
556 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 550 qe = find_qe(h, ntohl(msg->gns_header.r_id));
557 if ((NULL == ze) && (NULL == qe)) 551 if ((NULL == ze) && (NULL == qe))
558 return; /* rid not found */ 552 return; /* rid not found */
559 if ((NULL != ze) && (NULL != qe)) 553 if ((NULL != ze) && (NULL != qe))
560 { 554 {
561 GNUNET_break (0); /* rid ambigous */ 555 GNUNET_break(0); /* rid ambigous */
562 force_reconnect (h); 556 force_reconnect(h);
563 return; 557 return;
564 } 558 }
565 name = (const char *) &msg[1]; 559 name = (const char *)&msg[1];
566 rd_tmp = &name[name_len]; 560 rd_tmp = &name[name_len];
567 { 561 {
568 struct GNUNET_GNSRECORD_Data rd[rd_count]; 562 struct GNUNET_GNSRECORD_Data rd[rd_count];
569 563
570 GNUNET_assert ( 564 GNUNET_assert(
571 GNUNET_OK == 565 GNUNET_OK ==
572 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_tmp, rd_count, rd)); 566 GNUNET_GNSRECORD_records_deserialize(rd_len, rd_tmp, rd_count, rd));
573 if (0 == name_len) 567 if (0 == name_len)
574 name = NULL; 568 name = NULL;
575 if (NULL != qe) 569 if (NULL != qe)
576 { 570 {
577 if (NULL != qe->proc) 571 if (NULL != qe->proc)
578 qe->proc (qe->proc_cls, 572 qe->proc(qe->proc_cls,
579 &msg->private_key, 573 &msg->private_key,
580 name, 574 name,
581 rd_count, 575 rd_count,
582 (rd_count > 0) ? rd : NULL); 576 (rd_count > 0) ? rd : NULL);
583 free_qe (qe); 577 free_qe(qe);
584 return; 578 return;
585 } 579 }
586 if (NULL != ze) 580 if (NULL != ze)
587 { 581 {
588 if (NULL != ze->proc) 582 if (NULL != ze->proc)
589 ze->proc (ze->proc_cls, &msg->private_key, name, rd_count, rd); 583 ze->proc(ze->proc_cls, &msg->private_key, name, rd_count, rd);
590 return; 584 return;
591 } 585 }
592 } 586 }
593 GNUNET_assert (0); 587 GNUNET_assert(0);
594} 588}
595 589
596 590
@@ -602,33 +596,33 @@ handle_record_result (void *cls, const struct RecordResultMessage *msg)
602 * @param msg the message we received 596 * @param msg the message we received
603 */ 597 */
604static void 598static void
605handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg) 599handle_record_result_end(void *cls, const struct GNUNET_NAMESTORE_Header *msg)
606{ 600{
607 struct GNUNET_NAMESTORE_Handle *h = cls; 601 struct GNUNET_NAMESTORE_Handle *h = cls;
608 struct GNUNET_NAMESTORE_QueueEntry *qe; 602 struct GNUNET_NAMESTORE_QueueEntry *qe;
609 struct GNUNET_NAMESTORE_ZoneIterator *ze; 603 struct GNUNET_NAMESTORE_ZoneIterator *ze;
610 604
611 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n"); 605 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received RECORD_RESULT_END\n");
612 ze = find_zi (h, ntohl (msg->r_id)); 606 ze = find_zi(h, ntohl(msg->r_id));
613 qe = find_qe (h, ntohl (msg->r_id)); 607 qe = find_qe(h, ntohl(msg->r_id));
614 if ((NULL == ze) && (NULL == qe)) 608 if ((NULL == ze) && (NULL == qe))
615 return; /* rid not found */ 609 return; /* rid not found */
616 if ((NULL != ze) && (NULL != qe)) 610 if ((NULL != ze) && (NULL != qe))
617 { 611 {
618 GNUNET_break (0); /* rid ambigous */ 612 GNUNET_break(0); /* rid ambigous */
619 force_reconnect (h); 613 force_reconnect(h);
620 return; 614 return;
621 } 615 }
622 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n"); 616 LOG(GNUNET_ERROR_TYPE_DEBUG, "Zone iteration completed!\n");
623 if (NULL == ze) 617 if (NULL == ze)
624 { 618 {
625 GNUNET_break (0); 619 GNUNET_break(0);
626 force_reconnect (h); 620 force_reconnect(h);
627 return; 621 return;
628 } 622 }
629 if (NULL != ze->finish_cb) 623 if (NULL != ze->finish_cb)
630 ze->finish_cb (ze->finish_cb_cls); 624 ze->finish_cb(ze->finish_cb_cls);
631 free_ze (ze); 625 free_ze(ze);
632} 626}
633 627
634 628
@@ -641,31 +635,31 @@ handle_record_result_end (void *cls, const struct GNUNET_NAMESTORE_Header *msg)
641 * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed 635 * @return #GNUNET_OK on success, #GNUNET_SYSERR if message malformed
642 */ 636 */
643static int 637static int
644check_zone_to_name_response (void *cls, 638check_zone_to_name_response(void *cls,
645 const struct ZoneToNameResponseMessage *msg) 639 const struct ZoneToNameResponseMessage *msg)
646{ 640{
647 size_t name_len; 641 size_t name_len;
648 size_t rd_ser_len; 642 size_t rd_ser_len;
649 const char *name_tmp; 643 const char *name_tmp;
650 644
651 (void) cls; 645 (void)cls;
652 if (GNUNET_OK != ntohs (msg->res)) 646 if (GNUNET_OK != ntohs(msg->res))
653 return GNUNET_OK; 647 return GNUNET_OK;
654 name_len = ntohs (msg->name_len); 648 name_len = ntohs(msg->name_len);
655 rd_ser_len = ntohs (msg->rd_len); 649 rd_ser_len = ntohs(msg->rd_len);
656 if (ntohs (msg->gns_header.header.size) != 650 if (ntohs(msg->gns_header.header.size) !=
657 sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len) 651 sizeof(struct ZoneToNameResponseMessage) + name_len + rd_ser_len)
658 { 652 {
659 GNUNET_break (0); 653 GNUNET_break(0);
660 return GNUNET_SYSERR; 654 return GNUNET_SYSERR;
661 } 655 }
662 name_tmp = (const char *) &msg[1]; 656 name_tmp = (const char *)&msg[1];
663 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1])) 657 if ((name_len > 0) && ('\0' != name_tmp[name_len - 1]))
664 { 658 {
665 GNUNET_break (0); 659 GNUNET_break(0);
666 return GNUNET_SYSERR; 660 return GNUNET_SYSERR;
667 } 661 }
668 return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (msg->rd_count)); 662 return check_rd(rd_ser_len, &name_tmp[name_len], ntohs(msg->rd_count));
669} 663}
670 664
671 665
@@ -677,8 +671,8 @@ check_zone_to_name_response (void *cls,
677 * @param msg the message we received 671 * @param msg the message we received
678 */ 672 */
679static void 673static void
680handle_zone_to_name_response (void *cls, 674handle_zone_to_name_response(void *cls,
681 const struct ZoneToNameResponseMessage *msg) 675 const struct ZoneToNameResponseMessage *msg)
682{ 676{
683 struct GNUNET_NAMESTORE_Handle *h = cls; 677 struct GNUNET_NAMESTORE_Handle *h = cls;
684 struct GNUNET_NAMESTORE_QueueEntry *qe; 678 struct GNUNET_NAMESTORE_QueueEntry *qe;
@@ -689,54 +683,57 @@ handle_zone_to_name_response (void *cls,
689 const char *name_tmp; 683 const char *name_tmp;
690 const char *rd_tmp; 684 const char *rd_tmp;
691 685
692 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n"); 686 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received ZONE_TO_NAME_RESPONSE\n");
693 qe = find_qe (h, ntohl (msg->gns_header.r_id)); 687 qe = find_qe(h, ntohl(msg->gns_header.r_id));
694 res = ntohs (msg->res); 688 res = ntohs(msg->res);
695 switch (res) 689 switch (res)
696 {
697 case GNUNET_SYSERR:
698 LOG (GNUNET_ERROR_TYPE_DEBUG,
699 "An error occurred during zone to name operation\n");
700 break;
701 case GNUNET_NO:
702 LOG (GNUNET_ERROR_TYPE_DEBUG,
703 "Namestore has no result for zone to name mapping \n");
704 if (NULL != qe->proc)
705 qe->proc (qe->proc_cls, &msg->zone, NULL, 0, NULL);
706 free_qe (qe);
707 return;
708 case GNUNET_YES:
709 LOG (GNUNET_ERROR_TYPE_DEBUG,
710 "Namestore has result for zone to name mapping \n");
711 name_len = ntohs (msg->name_len);
712 rd_count = ntohs (msg->rd_count);
713 rd_ser_len = ntohs (msg->rd_len);
714 name_tmp = (const char *) &msg[1];
715 rd_tmp = &name_tmp[name_len];
716 { 690 {
717 struct GNUNET_GNSRECORD_Data rd[rd_count]; 691 case GNUNET_SYSERR:
692 LOG(GNUNET_ERROR_TYPE_DEBUG,
693 "An error occurred during zone to name operation\n");
694 break;
695
696 case GNUNET_NO:
697 LOG(GNUNET_ERROR_TYPE_DEBUG,
698 "Namestore has no result for zone to name mapping \n");
699 if (NULL != qe->proc)
700 qe->proc(qe->proc_cls, &msg->zone, NULL, 0, NULL);
701 free_qe(qe);
702 return;
718 703
719 GNUNET_assert (GNUNET_OK == 704 case GNUNET_YES:
720 GNUNET_GNSRECORD_records_deserialize (rd_ser_len, 705 LOG(GNUNET_ERROR_TYPE_DEBUG,
706 "Namestore has result for zone to name mapping \n");
707 name_len = ntohs(msg->name_len);
708 rd_count = ntohs(msg->rd_count);
709 rd_ser_len = ntohs(msg->rd_len);
710 name_tmp = (const char *)&msg[1];
711 rd_tmp = &name_tmp[name_len];
712 {
713 struct GNUNET_GNSRECORD_Data rd[rd_count];
714
715 GNUNET_assert(GNUNET_OK ==
716 GNUNET_GNSRECORD_records_deserialize(rd_ser_len,
721 rd_tmp, 717 rd_tmp,
722 rd_count, 718 rd_count,
723 rd)); 719 rd));
724 /* normal end, call continuation with result */ 720 /* normal end, call continuation with result */
725 if (NULL != qe->proc) 721 if (NULL != qe->proc)
726 qe->proc (qe->proc_cls, &msg->zone, name_tmp, rd_count, rd); 722 qe->proc(qe->proc_cls, &msg->zone, name_tmp, rd_count, rd);
727 /* return is important here: break would call continuation with error! */ 723 /* return is important here: break would call continuation with error! */
728 free_qe (qe); 724 free_qe(qe);
725 return;
726 }
727
728 default:
729 GNUNET_break(0);
730 force_reconnect(h);
729 return; 731 return;
730 } 732 }
731 default:
732 GNUNET_break (0);
733 force_reconnect (h);
734 return;
735 }
736 /* error case, call continuation with error */ 733 /* error case, call continuation with error */
737 if (NULL != qe->error_cb) 734 if (NULL != qe->error_cb)
738 qe->error_cb (qe->error_cb_cls); 735 qe->error_cb(qe->error_cb_cls);
739 free_qe (qe); 736 free_qe(qe);
740} 737}
741 738
742 739
@@ -749,12 +746,12 @@ handle_zone_to_name_response (void *cls,
749 * @param error error code 746 * @param error error code
750 */ 747 */
751static void 748static void
752mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 749mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
753{ 750{
754 struct GNUNET_NAMESTORE_Handle *h = cls; 751 struct GNUNET_NAMESTORE_Handle *h = cls;
755 752
756 (void) error; 753 (void)error;
757 force_reconnect (h); 754 force_reconnect(h);
758} 755}
759 756
760 757
@@ -764,49 +761,49 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
764 * @param h the handle to the NAMESTORE service 761 * @param h the handle to the NAMESTORE service
765 */ 762 */
766static void 763static void
767reconnect (struct GNUNET_NAMESTORE_Handle *h) 764reconnect(struct GNUNET_NAMESTORE_Handle *h)
768{ 765{
769 struct GNUNET_MQ_MessageHandler handlers[] = 766 struct GNUNET_MQ_MessageHandler handlers[] =
770 {GNUNET_MQ_hd_fixed_size (record_store_response, 767 { GNUNET_MQ_hd_fixed_size(record_store_response,
771 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE, 768 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE,
772 struct RecordStoreResponseMessage, 769 struct RecordStoreResponseMessage,
773 h),
774 GNUNET_MQ_hd_var_size (zone_to_name_response,
775 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE,
776 struct ZoneToNameResponseMessage,
777 h),
778 GNUNET_MQ_hd_var_size (record_result,
779 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
780 struct RecordResultMessage,
781 h), 770 h),
782 GNUNET_MQ_hd_fixed_size (record_result_end, 771 GNUNET_MQ_hd_var_size(zone_to_name_response,
783 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END, 772 GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE,
784 struct GNUNET_NAMESTORE_Header, 773 struct ZoneToNameResponseMessage,
785 h), 774 h),
786 GNUNET_MQ_hd_var_size (lookup_result, 775 GNUNET_MQ_hd_var_size(record_result,
787 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE, 776 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT,
788 struct LabelLookupResponseMessage, 777 struct RecordResultMessage,
778 h),
779 GNUNET_MQ_hd_fixed_size(record_result_end,
780 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END,
781 struct GNUNET_NAMESTORE_Header,
789 h), 782 h),
790 GNUNET_MQ_handler_end ()}; 783 GNUNET_MQ_hd_var_size(lookup_result,
784 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE,
785 struct LabelLookupResponseMessage,
786 h),
787 GNUNET_MQ_handler_end() };
791 struct GNUNET_NAMESTORE_ZoneIterator *it; 788 struct GNUNET_NAMESTORE_ZoneIterator *it;
792 struct GNUNET_NAMESTORE_QueueEntry *qe; 789 struct GNUNET_NAMESTORE_QueueEntry *qe;
793 790
794 GNUNET_assert (NULL == h->mq); 791 GNUNET_assert(NULL == h->mq);
795 h->mq = 792 h->mq =
796 GNUNET_CLIENT_connect (h->cfg, "namestore", handlers, &mq_error_handler, h); 793 GNUNET_CLIENT_connect(h->cfg, "namestore", handlers, &mq_error_handler, h);
797 if (NULL == h->mq) 794 if (NULL == h->mq)
798 return; 795 return;
799 /* re-transmit pending requests that waited for a reconnect... */ 796 /* re-transmit pending requests that waited for a reconnect... */
800 for (it = h->z_head; NULL != it; it = it->next) 797 for (it = h->z_head; NULL != it; it = it->next)
801 { 798 {
802 GNUNET_MQ_send (h->mq, it->env); 799 GNUNET_MQ_send(h->mq, it->env);
803 it->env = NULL; 800 it->env = NULL;
804 } 801 }
805 for (qe = h->op_head; NULL != qe; qe = qe->next) 802 for (qe = h->op_head; NULL != qe; qe = qe->next)
806 { 803 {
807 GNUNET_MQ_send (h->mq, qe->env); 804 GNUNET_MQ_send(h->mq, qe->env);
808 qe->env = NULL; 805 qe->env = NULL;
809 } 806 }
810} 807}
811 808
812 809
@@ -816,12 +813,12 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h)
816 * @param cls handle to use to re-connect. 813 * @param cls handle to use to re-connect.
817 */ 814 */
818static void 815static void
819reconnect_task (void *cls) 816reconnect_task(void *cls)
820{ 817{
821 struct GNUNET_NAMESTORE_Handle *h = cls; 818 struct GNUNET_NAMESTORE_Handle *h = cls;
822 819
823 h->reconnect_task = NULL; 820 h->reconnect_task = NULL;
824 reconnect (h); 821 reconnect(h);
825} 822}
826 823
827 824
@@ -831,34 +828,34 @@ reconnect_task (void *cls)
831 * @param h our handle 828 * @param h our handle
832 */ 829 */
833static void 830static void
834force_reconnect (struct GNUNET_NAMESTORE_Handle *h) 831force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
835{ 832{
836 struct GNUNET_NAMESTORE_ZoneIterator *ze; 833 struct GNUNET_NAMESTORE_ZoneIterator *ze;
837 struct GNUNET_NAMESTORE_QueueEntry *qe; 834 struct GNUNET_NAMESTORE_QueueEntry *qe;
838 835
839 GNUNET_MQ_destroy (h->mq); 836 GNUNET_MQ_destroy(h->mq);
840 h->mq = NULL; 837 h->mq = NULL;
841 while (NULL != (ze = h->z_head)) 838 while (NULL != (ze = h->z_head))
842 { 839 {
843 if (NULL != ze->error_cb) 840 if (NULL != ze->error_cb)
844 ze->error_cb (ze->error_cb_cls); 841 ze->error_cb(ze->error_cb_cls);
845 free_ze (ze); 842 free_ze(ze);
846 } 843 }
847 while (NULL != (qe = h->op_head)) 844 while (NULL != (qe = h->op_head))
848 { 845 {
849 if (NULL != qe->error_cb) 846 if (NULL != qe->error_cb)
850 qe->error_cb (qe->error_cb_cls); 847 qe->error_cb(qe->error_cb_cls);
851 if (NULL != qe->cont) 848 if (NULL != qe->cont)
852 qe->cont (qe->cont_cls, 849 qe->cont(qe->cont_cls,
853 GNUNET_SYSERR, 850 GNUNET_SYSERR,
854 "failure in communication with namestore service"); 851 "failure in communication with namestore service");
855 free_qe (qe); 852 free_qe(qe);
856 } 853 }
857 854
858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n"); 855 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Reconnecting to namestore\n");
859 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); 856 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay);
860 h->reconnect_task = 857 h->reconnect_task =
861 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect_task, h); 858 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect_task, h);
862} 859}
863 860
864 861
@@ -869,7 +866,7 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
869 * @return next operation id to use 866 * @return next operation id to use
870 */ 867 */
871static uint32_t 868static uint32_t
872get_op_id (struct GNUNET_NAMESTORE_Handle *h) 869get_op_id(struct GNUNET_NAMESTORE_Handle *h)
873{ 870{
874 return h->last_op_id_used++; 871 return h->last_op_id_used++;
875} 872}
@@ -882,18 +879,18 @@ get_op_id (struct GNUNET_NAMESTORE_Handle *h)
882 * @return handle to the GNS service, or NULL on error 879 * @return handle to the GNS service, or NULL on error
883 */ 880 */
884struct GNUNET_NAMESTORE_Handle * 881struct GNUNET_NAMESTORE_Handle *
885GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 882GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
886{ 883{
887 struct GNUNET_NAMESTORE_Handle *h; 884 struct GNUNET_NAMESTORE_Handle *h;
888 885
889 h = GNUNET_new (struct GNUNET_NAMESTORE_Handle); 886 h = GNUNET_new(struct GNUNET_NAMESTORE_Handle);
890 h->cfg = cfg; 887 h->cfg = cfg;
891 reconnect (h); 888 reconnect(h);
892 if (NULL == h->mq) 889 if (NULL == h->mq)
893 { 890 {
894 GNUNET_free (h); 891 GNUNET_free(h);
895 return NULL; 892 return NULL;
896 } 893 }
897 return h; 894 return h;
898} 895}
899 896
@@ -905,35 +902,35 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
905 * @param h handle to the namestore 902 * @param h handle to the namestore
906 */ 903 */
907void 904void
908GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) 905GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
909{ 906{
910 struct GNUNET_NAMESTORE_QueueEntry *q; 907 struct GNUNET_NAMESTORE_QueueEntry *q;
911 struct GNUNET_NAMESTORE_ZoneIterator *z; 908 struct GNUNET_NAMESTORE_ZoneIterator *z;
912 909
913 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 910 LOG(GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
914 GNUNET_break (NULL == h->op_head); 911 GNUNET_break(NULL == h->op_head);
915 while (NULL != (q = h->op_head)) 912 while (NULL != (q = h->op_head))
916 { 913 {
917 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q); 914 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, q);
918 GNUNET_free (q); 915 GNUNET_free(q);
919 } 916 }
920 GNUNET_break (NULL == h->z_head); 917 GNUNET_break(NULL == h->z_head);
921 while (NULL != (z = h->z_head)) 918 while (NULL != (z = h->z_head))
922 { 919 {
923 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z); 920 GNUNET_CONTAINER_DLL_remove(h->z_head, h->z_tail, z);
924 GNUNET_free (z); 921 GNUNET_free(z);
925 } 922 }
926 if (NULL != h->mq) 923 if (NULL != h->mq)
927 { 924 {
928 GNUNET_MQ_destroy (h->mq); 925 GNUNET_MQ_destroy(h->mq);
929 h->mq = NULL; 926 h->mq = NULL;
930 } 927 }
931 if (NULL != h->reconnect_task) 928 if (NULL != h->reconnect_task)
932 { 929 {
933 GNUNET_SCHEDULER_cancel (h->reconnect_task); 930 GNUNET_SCHEDULER_cancel(h->reconnect_task);
934 h->reconnect_task = NULL; 931 h->reconnect_task = NULL;
935 } 932 }
936 GNUNET_free (h); 933 GNUNET_free(h);
937} 934}
938 935
939 936
@@ -944,21 +941,21 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
944 * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *` 941 * @param cls a `struct GNUNET_NAMESTORE_QueueEntry *`
945 */ 942 */
946static void 943static void
947warn_delay (void *cls) 944warn_delay(void *cls)
948{ 945{
949 struct GNUNET_NAMESTORE_QueueEntry *qe = cls; 946 struct GNUNET_NAMESTORE_QueueEntry *qe = cls;
950 947
951 qe->timeout_task = NULL; 948 qe->timeout_task = NULL;
952 LOG (GNUNET_ERROR_TYPE_WARNING, 949 LOG(GNUNET_ERROR_TYPE_WARNING,
953 "Did not receive response from namestore after %s!\n", 950 "Did not receive response from namestore after %s!\n",
954 GNUNET_STRINGS_relative_time_to_string (NAMESTORE_DELAY_TOLERANCE, 951 GNUNET_STRINGS_relative_time_to_string(NAMESTORE_DELAY_TOLERANCE,
955 GNUNET_YES)); 952 GNUNET_YES));
956 if (NULL != qe->cont) 953 if (NULL != qe->cont)
957 { 954 {
958 qe->cont (qe->cont_cls, GNUNET_SYSERR, "timeout"); 955 qe->cont(qe->cont_cls, GNUNET_SYSERR, "timeout");
959 qe->cont = NULL; 956 qe->cont = NULL;
960 } 957 }
961 GNUNET_NAMESTORE_cancel (qe); 958 GNUNET_NAMESTORE_cancel(qe);
962} 959}
963 960
964 961
@@ -977,7 +974,7 @@ warn_delay (void *cls)
977 * @return handle to abort the request 974 * @return handle to abort the request
978 */ 975 */
979struct GNUNET_NAMESTORE_QueueEntry * 976struct GNUNET_NAMESTORE_QueueEntry *
980GNUNET_NAMESTORE_records_store ( 977GNUNET_NAMESTORE_records_store(
981 struct GNUNET_NAMESTORE_Handle *h, 978 struct GNUNET_NAMESTORE_Handle *h,
982 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 979 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
983 const char *label, 980 const char *label,
@@ -996,69 +993,69 @@ GNUNET_NAMESTORE_records_store (
996 struct RecordStoreMessage *msg; 993 struct RecordStoreMessage *msg;
997 ssize_t sret; 994 ssize_t sret;
998 995
999 name_len = strlen (label) + 1; 996 name_len = strlen(label) + 1;
1000 if (name_len > MAX_NAME_LEN) 997 if (name_len > MAX_NAME_LEN)
1001 { 998 {
1002 GNUNET_break (0); 999 GNUNET_break(0);
1003 return NULL; 1000 return NULL;
1004 } 1001 }
1005 rd_ser_len = GNUNET_GNSRECORD_records_get_size (rd_count, rd); 1002 rd_ser_len = GNUNET_GNSRECORD_records_get_size(rd_count, rd);
1006 if (rd_ser_len < 0) 1003 if (rd_ser_len < 0)
1007 { 1004 {
1008 GNUNET_break (0); 1005 GNUNET_break(0);
1009 return NULL; 1006 return NULL;
1010 } 1007 }
1011 if (rd_ser_len > UINT16_MAX) 1008 if (rd_ser_len > UINT16_MAX)
1012 { 1009 {
1013 GNUNET_break (0); 1010 GNUNET_break(0);
1014 return NULL; 1011 return NULL;
1015 } 1012 }
1016 rid = get_op_id (h); 1013 rid = get_op_id(h);
1017 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1014 qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry);
1018 qe->h = h; 1015 qe->h = h;
1019 qe->cont = cont; 1016 qe->cont = cont;
1020 qe->cont_cls = cont_cls; 1017 qe->cont_cls = cont_cls;
1021 qe->op_id = rid; 1018 qe->op_id = rid;
1022 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1019 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
1023 1020
1024 /* setup msg */ 1021 /* setup msg */
1025 env = GNUNET_MQ_msg_extra (msg, 1022 env = GNUNET_MQ_msg_extra(msg,
1026 name_len + rd_ser_len, 1023 name_len + rd_ser_len,
1027 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE); 1024 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE);
1028 msg->gns_header.r_id = htonl (rid); 1025 msg->gns_header.r_id = htonl(rid);
1029 msg->name_len = htons (name_len); 1026 msg->name_len = htons(name_len);
1030 msg->rd_count = htons (rd_count); 1027 msg->rd_count = htons(rd_count);
1031 msg->rd_len = htons (rd_ser_len); 1028 msg->rd_len = htons(rd_ser_len);
1032 msg->reserved = htons (0); 1029 msg->reserved = htons(0);
1033 msg->private_key = *pkey; 1030 msg->private_key = *pkey;
1034 1031
1035 name_tmp = (char *) &msg[1]; 1032 name_tmp = (char *)&msg[1];
1036 GNUNET_memcpy (name_tmp, label, name_len); 1033 GNUNET_memcpy(name_tmp, label, name_len);
1037 rd_ser = &name_tmp[name_len]; 1034 rd_ser = &name_tmp[name_len];
1038 sret = GNUNET_GNSRECORD_records_serialize (rd_count, rd, rd_ser_len, rd_ser); 1035 sret = GNUNET_GNSRECORD_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1039 if ((0 > sret) || (sret != rd_ser_len)) 1036 if ((0 > sret) || (sret != rd_ser_len))
1040 { 1037 {
1041 GNUNET_break (0); 1038 GNUNET_break(0);
1042 GNUNET_free (env); 1039 GNUNET_free(env);
1043 return NULL; 1040 return NULL;
1044 } 1041 }
1045 GNUNET_assert (rd_ser_len == sret); 1042 GNUNET_assert(rd_ser_len == sret);
1046 LOG (GNUNET_ERROR_TYPE_DEBUG, 1043 LOG(GNUNET_ERROR_TYPE_DEBUG,
1047 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", 1044 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1048 label, 1045 label,
1049 rd_count); 1046 rd_count);
1050 qe->timeout_task = 1047 qe->timeout_task =
1051 GNUNET_SCHEDULER_add_delayed (NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe); 1048 GNUNET_SCHEDULER_add_delayed(NAMESTORE_DELAY_TOLERANCE, &warn_delay, qe);
1052 if (NULL == h->mq) 1049 if (NULL == h->mq)
1053 { 1050 {
1054 qe->env = env; 1051 qe->env = env;
1055 LOG (GNUNET_ERROR_TYPE_WARNING, 1052 LOG(GNUNET_ERROR_TYPE_WARNING,
1056 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n"); 1053 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1057 } 1054 }
1058 else 1055 else
1059 { 1056 {
1060 GNUNET_MQ_send (h->mq, env); 1057 GNUNET_MQ_send(h->mq, env);
1061 } 1058 }
1062 return qe; 1059 return qe;
1063} 1060}
1064 1061
@@ -1074,29 +1071,29 @@ GNUNET_NAMESTORE_records_store (
1074 * @return handle to abort the request 1071 * @return handle to abort the request
1075 */ 1072 */
1076struct GNUNET_NAMESTORE_QueueEntry * 1073struct GNUNET_NAMESTORE_QueueEntry *
1077GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h, 1074GNUNET_NAMESTORE_set_nick(struct GNUNET_NAMESTORE_Handle *h,
1078 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 1075 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
1079 const char *nick, 1076 const char *nick,
1080 GNUNET_NAMESTORE_ContinuationWithStatus cont, 1077 GNUNET_NAMESTORE_ContinuationWithStatus cont,
1081 void *cont_cls) 1078 void *cont_cls)
1082{ 1079{
1083 struct GNUNET_GNSRECORD_Data rd; 1080 struct GNUNET_GNSRECORD_Data rd;
1084 1081
1085 if (NULL == h->mq) 1082 if (NULL == h->mq)
1086 return NULL; 1083 return NULL;
1087 memset (&rd, 0, sizeof (rd)); 1084 memset(&rd, 0, sizeof(rd));
1088 rd.data = nick; 1085 rd.data = nick;
1089 rd.data_size = strlen (nick) + 1; 1086 rd.data_size = strlen(nick) + 1;
1090 rd.record_type = GNUNET_GNSRECORD_TYPE_NICK; 1087 rd.record_type = GNUNET_GNSRECORD_TYPE_NICK;
1091 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 1088 rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
1092 rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE; 1089 rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE;
1093 return GNUNET_NAMESTORE_records_store (h, 1090 return GNUNET_NAMESTORE_records_store(h,
1094 pkey, 1091 pkey,
1095 GNUNET_GNS_EMPTY_LABEL_AT, 1092 GNUNET_GNS_EMPTY_LABEL_AT,
1096 1, 1093 1,
1097 &rd, 1094 &rd,
1098 cont, 1095 cont,
1099 cont_cls); 1096 cont_cls);
1100} 1097}
1101 1098
1102 1099
@@ -1113,7 +1110,7 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h,
1113 * @return handle to abort the request 1110 * @return handle to abort the request
1114 */ 1111 */
1115struct GNUNET_NAMESTORE_QueueEntry * 1112struct GNUNET_NAMESTORE_QueueEntry *
1116GNUNET_NAMESTORE_records_lookup ( 1113GNUNET_NAMESTORE_records_lookup(
1117 struct GNUNET_NAMESTORE_Handle *h, 1114 struct GNUNET_NAMESTORE_Handle *h,
1118 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, 1115 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey,
1119 const char *label, 1116 const char *label,
@@ -1127,32 +1124,32 @@ GNUNET_NAMESTORE_records_lookup (
1127 struct LabelLookupMessage *msg; 1124 struct LabelLookupMessage *msg;
1128 size_t label_len; 1125 size_t label_len;
1129 1126
1130 if (1 == (label_len = strlen (label) + 1)) 1127 if (1 == (label_len = strlen(label) + 1))
1131 { 1128 {
1132 GNUNET_break (0); 1129 GNUNET_break(0);
1133 return NULL; 1130 return NULL;
1134 } 1131 }
1135 1132
1136 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1133 qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry);
1137 qe->h = h; 1134 qe->h = h;
1138 qe->error_cb = error_cb; 1135 qe->error_cb = error_cb;
1139 qe->error_cb_cls = error_cb_cls; 1136 qe->error_cb_cls = error_cb_cls;
1140 qe->proc = rm; 1137 qe->proc = rm;
1141 qe->proc_cls = rm_cls; 1138 qe->proc_cls = rm_cls;
1142 qe->op_id = get_op_id (h); 1139 qe->op_id = get_op_id(h);
1143 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1140 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
1144 1141
1145 env = GNUNET_MQ_msg_extra (msg, 1142 env = GNUNET_MQ_msg_extra(msg,
1146 label_len, 1143 label_len,
1147 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP); 1144 GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP);
1148 msg->gns_header.r_id = htonl (qe->op_id); 1145 msg->gns_header.r_id = htonl(qe->op_id);
1149 msg->zone = *pkey; 1146 msg->zone = *pkey;
1150 msg->label_len = htonl (label_len); 1147 msg->label_len = htonl(label_len);
1151 GNUNET_memcpy (&msg[1], label, label_len); 1148 GNUNET_memcpy(&msg[1], label, label_len);
1152 if (NULL == h->mq) 1149 if (NULL == h->mq)
1153 qe->env = env; 1150 qe->env = env;
1154 else 1151 else
1155 GNUNET_MQ_send (h->mq, env); 1152 GNUNET_MQ_send(h->mq, env);
1156 return qe; 1153 return qe;
1157} 1154}
1158 1155
@@ -1173,7 +1170,7 @@ GNUNET_NAMESTORE_records_lookup (
1173 * cancel 1170 * cancel
1174 */ 1171 */
1175struct GNUNET_NAMESTORE_QueueEntry * 1172struct GNUNET_NAMESTORE_QueueEntry *
1176GNUNET_NAMESTORE_zone_to_name ( 1173GNUNET_NAMESTORE_zone_to_name(
1177 struct GNUNET_NAMESTORE_Handle *h, 1174 struct GNUNET_NAMESTORE_Handle *h,
1178 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1175 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1179 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, 1176 const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone,
@@ -1187,24 +1184,24 @@ GNUNET_NAMESTORE_zone_to_name (
1187 struct ZoneToNameMessage *msg; 1184 struct ZoneToNameMessage *msg;
1188 uint32_t rid; 1185 uint32_t rid;
1189 1186
1190 rid = get_op_id (h); 1187 rid = get_op_id(h);
1191 qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); 1188 qe = GNUNET_new(struct GNUNET_NAMESTORE_QueueEntry);
1192 qe->h = h; 1189 qe->h = h;
1193 qe->error_cb = error_cb; 1190 qe->error_cb = error_cb;
1194 qe->error_cb_cls = error_cb_cls; 1191 qe->error_cb_cls = error_cb_cls;
1195 qe->proc = proc; 1192 qe->proc = proc;
1196 qe->proc_cls = proc_cls; 1193 qe->proc_cls = proc_cls;
1197 qe->op_id = rid; 1194 qe->op_id = rid;
1198 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); 1195 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe);
1199 1196
1200 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME); 1197 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME);
1201 msg->gns_header.r_id = htonl (rid); 1198 msg->gns_header.r_id = htonl(rid);
1202 msg->zone = *zone; 1199 msg->zone = *zone;
1203 msg->value_zone = *value_zone; 1200 msg->value_zone = *value_zone;
1204 if (NULL == h->mq) 1201 if (NULL == h->mq)
1205 qe->env = env; 1202 qe->env = env;
1206 else 1203 else
1207 GNUNET_MQ_send (h->mq, env); 1204 GNUNET_MQ_send(h->mq, env);
1208 return qe; 1205 return qe;
1209} 1206}
1210 1207
@@ -1229,7 +1226,7 @@ GNUNET_NAMESTORE_zone_to_name (
1229 * @return an iterator handle to use for iteration 1226 * @return an iterator handle to use for iteration
1230 */ 1227 */
1231struct GNUNET_NAMESTORE_ZoneIterator * 1228struct GNUNET_NAMESTORE_ZoneIterator *
1232GNUNET_NAMESTORE_zone_iteration_start ( 1229GNUNET_NAMESTORE_zone_iteration_start(
1233 struct GNUNET_NAMESTORE_Handle *h, 1230 struct GNUNET_NAMESTORE_Handle *h,
1234 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 1231 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
1235 GNUNET_SCHEDULER_TaskCallback error_cb, 1232 GNUNET_SCHEDULER_TaskCallback error_cb,
@@ -1244,9 +1241,9 @@ GNUNET_NAMESTORE_zone_iteration_start (
1244 struct ZoneIterationStartMessage *msg; 1241 struct ZoneIterationStartMessage *msg;
1245 uint32_t rid; 1242 uint32_t rid;
1246 1243
1247 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n"); 1244 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_START message\n");
1248 rid = get_op_id (h); 1245 rid = get_op_id(h);
1249 it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator); 1246 it = GNUNET_new(struct GNUNET_NAMESTORE_ZoneIterator);
1250 it->h = h; 1247 it->h = h;
1251 it->error_cb = error_cb; 1248 it->error_cb = error_cb;
1252 it->error_cb_cls = error_cb_cls; 1249 it->error_cb_cls = error_cb_cls;
@@ -1257,15 +1254,15 @@ GNUNET_NAMESTORE_zone_iteration_start (
1257 it->op_id = rid; 1254 it->op_id = rid;
1258 if (NULL != zone) 1255 if (NULL != zone)
1259 it->zone = *zone; 1256 it->zone = *zone;
1260 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it); 1257 GNUNET_CONTAINER_DLL_insert_tail(h->z_head, h->z_tail, it);
1261 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START); 1258 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START);
1262 msg->gns_header.r_id = htonl (rid); 1259 msg->gns_header.r_id = htonl(rid);
1263 if (NULL != zone) 1260 if (NULL != zone)
1264 msg->zone = *zone; 1261 msg->zone = *zone;
1265 if (NULL == h->mq) 1262 if (NULL == h->mq)
1266 it->env = env; 1263 it->env = env;
1267 else 1264 else
1268 GNUNET_MQ_send (h->mq, env); 1265 GNUNET_MQ_send(h->mq, env);
1269 return it; 1266 return it;
1270} 1267}
1271 1268
@@ -1279,20 +1276,20 @@ GNUNET_NAMESTORE_zone_iteration_start (
1279 * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again) 1276 * (before #GNUNET_NAMESTORE_zone_iterator_next is to be called again)
1280 */ 1277 */
1281void 1278void
1282GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it, 1279GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it,
1283 uint64_t limit) 1280 uint64_t limit)
1284{ 1281{
1285 struct GNUNET_NAMESTORE_Handle *h = it->h; 1282 struct GNUNET_NAMESTORE_Handle *h = it->h;
1286 struct ZoneIterationNextMessage *msg; 1283 struct ZoneIterationNextMessage *msg;
1287 struct GNUNET_MQ_Envelope *env; 1284 struct GNUNET_MQ_Envelope *env;
1288 1285
1289 LOG (GNUNET_ERROR_TYPE_DEBUG, 1286 LOG(GNUNET_ERROR_TYPE_DEBUG,
1290 "Sending ZONE_ITERATION_NEXT message with limit %llu\n", 1287 "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
1291 (unsigned long long) limit); 1288 (unsigned long long)limit);
1292 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); 1289 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT);
1293 msg->gns_header.r_id = htonl (it->op_id); 1290 msg->gns_header.r_id = htonl(it->op_id);
1294 msg->limit = GNUNET_htonll (limit); 1291 msg->limit = GNUNET_htonll(limit);
1295 GNUNET_MQ_send (h->mq, env); 1292 GNUNET_MQ_send(h->mq, env);
1296} 1293}
1297 1294
1298 1295
@@ -1302,21 +1299,21 @@ GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it,
1302 * @param it the iterator 1299 * @param it the iterator
1303 */ 1300 */
1304void 1301void
1305GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it) 1302GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
1306{ 1303{
1307 struct GNUNET_NAMESTORE_Handle *h = it->h; 1304 struct GNUNET_NAMESTORE_Handle *h = it->h;
1308 struct GNUNET_MQ_Envelope *env; 1305 struct GNUNET_MQ_Envelope *env;
1309 struct ZoneIterationStopMessage *msg; 1306 struct ZoneIterationStopMessage *msg;
1310 1307
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n"); 1308 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending ZONE_ITERATION_STOP message\n");
1312 if (NULL != h->mq) 1309 if (NULL != h->mq)
1313 { 1310 {
1314 env = 1311 env =
1315 GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); 1312 GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP);
1316 msg->gns_header.r_id = htonl (it->op_id); 1313 msg->gns_header.r_id = htonl(it->op_id);
1317 GNUNET_MQ_send (h->mq, env); 1314 GNUNET_MQ_send(h->mq, env);
1318 } 1315 }
1319 free_ze (it); 1316 free_ze(it);
1320} 1317}
1321 1318
1322 1319
@@ -1327,9 +1324,9 @@ GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
1327 * @param qe operation to cancel 1324 * @param qe operation to cancel
1328 */ 1325 */
1329void 1326void
1330GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe) 1327GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
1331{ 1328{
1332 free_qe (qe); 1329 free_qe(qe);
1333} 1330}
1334 1331
1335 1332