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