aboutsummaryrefslogtreecommitdiff
path: root/src/namestore
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-06-27 13:32:10 +0000
committerChristian Grothoff <christian@grothoff.org>2012-06-27 13:32:10 +0000
commita28d8a9c7e4e2160d31dc80cbb635b95f2f2dd8c (patch)
treecedb8a33b957d94aea576e8584783e2f418ad08f /src/namestore
parentf315953dd3ec50b6cf6482834b6403680238d9da (diff)
downloadgnunet-a28d8a9c7e4e2160d31dc80cbb635b95f2f2dd8c.tar.gz
gnunet-a28d8a9c7e4e2160d31dc80cbb635b95f2f2dd8c.zip
-major cleanup and various minor bugfixes for namestore_api
Diffstat (limited to 'src/namestore')
-rw-r--r--src/namestore/namestore_api.c938
1 files changed, 397 insertions, 541 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 0fbea6fec..d699c6ee3 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -23,6 +23,7 @@
23 * @brief API to access the NAMESTORE service 23 * @brief API to access the NAMESTORE service
24 * @author Martin Schanzenbach 24 * @author Martin Schanzenbach
25 * @author Matthias Wachs 25 * @author Matthias Wachs
26 * @author Christian Grothoff
26 */ 27 */
27 28
28#include "platform.h" 29#include "platform.h"
@@ -39,6 +40,12 @@
39#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__) 40#define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
40 41
41/** 42/**
43 * Maximum length of any name, including 0-termination.
44 */
45#define MAX_NAME_LEN 256
46
47
48/**
42 * An QueueEntry used to store information for a pending 49 * An QueueEntry used to store information for a pending
43 * NAMESTORE record operation 50 * NAMESTORE record operation
44 */ 51 */
@@ -253,83 +260,70 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h);
253 * @param qe the respective entry in the message queue 260 * @param qe the respective entry in the message queue
254 * @param msg the message we received 261 * @param msg the message we received
255 * @param size the message size 262 * @param size the message size
263 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
256 */ 264 */
257static void 265static int
258handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, 266handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
259 struct LookupNameResponseMessage * msg, 267 const struct LookupNameResponseMessage * msg,
260 size_t size) 268 size_t size)
261{ 269{
262 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 270 const char *name;
263 char *name; 271 const char * rd_tmp;
264 char * rd_tmp; 272 const struct GNUNET_CRYPTO_RsaSignature *signature;
265 struct GNUNET_CRYPTO_RsaSignature *signature = NULL;
266 struct GNUNET_TIME_Absolute expire; 273 struct GNUNET_TIME_Absolute expire;
267 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key_tmp; 274 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key_tmp;
268 size_t exp_msg_len; 275 size_t exp_msg_len;
269 size_t msg_len = 0; 276 size_t msg_len;
270 size_t name_len = 0; 277 size_t name_len;
271 size_t rd_len = 0; 278 size_t rd_len;
272 int contains_sig = GNUNET_NO; 279 int contains_sig;
273 int rd_count = 0; 280 int rd_count;
274 281
275 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", 282 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n", "LOOKUP_NAME_RESPONSE");
276 "LOOKUP_NAME_RESPONSE");
277 /* Operation done, remove */
278 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
279 rd_len = ntohs (msg->rd_len); 283 rd_len = ntohs (msg->rd_len);
280 rd_count = ntohs (msg->rd_count); 284 rd_count = ntohs (msg->rd_count);
281 msg_len = ntohs (msg->gns_header.header.size); 285 msg_len = ntohs (msg->gns_header.header.size);
282 name_len = ntohs (msg->name_len); 286 name_len = ntohs (msg->name_len);
283 contains_sig = ntohs (msg->contains_sig); 287 contains_sig = ntohs (msg->contains_sig);
284 expire = GNUNET_TIME_absolute_ntoh(msg->expire); 288 expire = GNUNET_TIME_absolute_ntoh (msg->expire);
285
286 exp_msg_len = sizeof (struct LookupNameResponseMessage) + 289 exp_msg_len = sizeof (struct LookupNameResponseMessage) +
287 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 290 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
288 name_len + rd_len; 291 name_len + rd_len;
289
290 if (msg_len != exp_msg_len) 292 if (msg_len != exp_msg_len)
291 { 293 {
292 LOG (GNUNET_ERROR_TYPE_DEBUG, "Message size describes with `%u' bytes but calculated size is %u bytes \n", 294 GNUNET_break (0);
293 msg_len, exp_msg_len); 295 return GNUNET_SYSERR;
294 GNUNET_break_op (0);
295 return;
296 } 296 }
297 297 name = (const char *) &msg[1];
298 name = (char *) &msg[1]; 298 if ( (name_len > 0) &&
299 if (name_len > 0) 299 ('\0' != name[name_len -1]) )
300 { 300 {
301 GNUNET_assert ('\0' == name[name_len -1]); 301 GNUNET_break (0);
302 GNUNET_assert ((name_len - 1) == strlen(name)); 302 return GNUNET_SYSERR;
303 } 303 }
304 rd_tmp = &name[name_len]; 304 rd_tmp = &name[name_len];
305
306 /* deserialize records */
307 { 305 {
308 struct GNUNET_NAMESTORE_RecordData rd[rd_count]; 306 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
307
309 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_len, rd_tmp, rd_count, rd)) 308 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_len, rd_tmp, rd_count, rd))
310 { 309 {
311 GNUNET_break_op (0); 310 GNUNET_break (0);
312 return; 311 return GNUNET_SYSERR;
313 } 312 }
314
315
316 /* reset values if values not contained */
317 if (GNUNET_NO == contains_sig) 313 if (GNUNET_NO == contains_sig)
318 signature = NULL; 314 signature = NULL;
319 else 315 else
320 signature = &msg->signature; 316 signature = &msg->signature;
321 if (0 == name_len) 317 if (0 == name_len)
322 name = NULL; 318 name = NULL;
323
324 if (NULL != name) 319 if (NULL != name)
325 public_key_tmp = &msg->public_key; 320 public_key_tmp = &msg->public_key;
326 else 321 else
327 public_key_tmp = NULL; 322 public_key_tmp = NULL;
328
329 if (NULL != qe->proc) 323 if (NULL != qe->proc)
330 qe->proc (qe->proc_cls, public_key_tmp, expire, name, rd_count, (rd_count > 0) ? rd : NULL, signature); 324 qe->proc (qe->proc_cls, public_key_tmp, expire, name, rd_count, (rd_count > 0) ? rd : NULL, signature);
331 } 325 }
332 GNUNET_free (qe); 326 return GNUNET_OK;
333} 327}
334 328
335 329
@@ -339,43 +333,22 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
339 * @param qe the respective entry in the message queue 333 * @param qe the respective entry in the message queue
340 * @param msg the message we received 334 * @param msg the message we received
341 * @param size the message size 335 * @param size the message size
336 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
342 */ 337 */
343static void 338static int
344handle_record_put_response (struct GNUNET_NAMESTORE_QueueEntry *qe, 339handle_record_put_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
345 struct RecordPutResponseMessage* msg, 340 const struct RecordPutResponseMessage* msg,
346 size_t size) 341 size_t size)
347{ 342{
348 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", 343 int res;
349 "RECORD_PUT_RESPONSE");
350
351 struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
352 /* Operation done, remove */
353 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
354
355 int res = ntohl (msg->op_result);
356
357 if (res == GNUNET_OK)
358 {
359 if (qe->cont != NULL)
360 {
361 qe->cont (qe->cont_cls, res, _("Namestore added record successfully"));
362 }
363
364 }
365 else if (res == GNUNET_SYSERR)
366 {
367 if (qe->cont != NULL)
368 {
369 qe->cont (qe->cont_cls, res, _("Namestore failed to add record"));
370 }
371 }
372 else
373 {
374 GNUNET_break_op (0);
375 return;
376 }
377 344
378 GNUNET_free (qe); 345 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
346 "RECORD_PUT_RESPONSE");
347 res = ntohl (msg->op_result);
348 /* TODO: add actual error message from namestore to response... */
349 if (NULL != qe->cont)
350 qe->cont (qe->cont_cls, res, (GNUNET_OK == res) ? NULL : _("Namestore failed to add record"));
351 return GNUNET_OK;
379} 352}
380 353
381 354
@@ -385,44 +358,27 @@ handle_record_put_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
385 * @param qe the respective entry in the message queue 358 * @param qe the respective entry in the message queue
386 * @param msg the message we received 359 * @param msg the message we received
387 * @param size the message size 360 * @param size the message size
361 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
388 */ 362 */
389static void 363static int
390handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe, 364handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
391 struct RecordCreateResponseMessage* msg, 365 const struct RecordCreateResponseMessage* msg,
392 size_t size) 366 size_t size)
393{ 367{
394 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 368 int res;
395 369 const char *emsg;
396 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", 370
371 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
397 "RECORD_CREATE_RESPONSE"); 372 "RECORD_CREATE_RESPONSE");
398 /* Operation done, remove */ 373 /* TODO: add actual error message from namestore to response... */
399 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); 374 res = ntohl (msg->op_result);
400 375 if (GNUNET_SYSERR == res)
401 int res = ntohl (msg->op_result); 376 emsg = _("Namestore failed to add record\n");
402 if (res == GNUNET_YES)
403 {
404 if (qe->cont != NULL)
405 {
406 qe->cont (qe->cont_cls, res, _("Namestore added record successfully"));
407 }
408
409 }
410 else if (res == GNUNET_NO)
411 {
412 if (qe->cont != NULL)
413 {
414 qe->cont (qe->cont_cls, res, _("Namestore record already existed"));
415 }
416 }
417 else 377 else
418 { 378 emsg = NULL;
419 if (qe->cont != NULL) 379 if (NULL != qe->cont)
420 { 380 qe->cont (qe->cont_cls, res, emsg);
421 qe->cont (qe->cont_cls, GNUNET_SYSERR, _("Namestore failed to add record\n")); 381 return GNUNET_OK;
422 }
423 }
424
425 GNUNET_free (qe);
426} 382}
427 383
428 384
@@ -432,70 +388,62 @@ handle_record_create_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
432 * @param qe the respective entry in the message queue 388 * @param qe the respective entry in the message queue
433 * @param msg the message we received 389 * @param msg the message we received
434 * @param size the message size 390 * @param size the message size
391 * @return GNUNET_OK on success, GNUNET_SYSERR on error and we did NOT notify the client
435 */ 392 */
436static void 393static int
437handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe, 394handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
438 struct RecordRemoveResponseMessage* msg, 395 const struct RecordRemoveResponseMessage* msg,
439 size_t size) 396 size_t size)
440{ 397{
441 398 int res;
442 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 399 int ret;
400 const char *emsg;
443 401
444 /* Operation done, remove */ 402 /* Operation done, remove */
445 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", 403 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
446 "RECORD_REMOVE_RESPONSE"); 404 "RECORD_REMOVE_RESPONSE");
447 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); 405 /*
448 406 * results:
449 int res = ntohl (msg->op_result);
450 /**
451 * result:
452 * 0 : successful 407 * 0 : successful
453 * 1 : No records for entry 408 * 1 : No records for entry
454 * 2 : Could not find record to remove 409 * 2 : Could not find record to remove
455 * 3 : Failed to create new signature 410 * 3 : Failed to create new signature
456 * 4 : Failed to put new set of records in database 411 * 4 : Failed to put new set of records in database
457 */ 412 */
458 switch (res) { 413 res = ntohl (msg->op_result);
459 case 0: 414 switch (res)
460 if (qe->cont != NULL) 415 {
461 { 416 case 0:
462 qe->cont (qe->cont_cls, GNUNET_YES, _("Namestore removed record successfully")); 417 ret = GNUNET_OK;
463 } 418 emsg = NULL;
464 419 break;
465 break; 420 case 1:
466 case 1: 421 ret = GNUNET_NO;
467 if (qe->cont != NULL) 422 emsg = NULL;
468 { 423 break;
469 qe->cont (qe->cont_cls, GNUNET_NO, _("No records for entry")); 424 case 2:
470 } 425 ret = GNUNET_NO;
471 426 emsg = NULL;
472 break; 427 break;
473 case 2: 428 case 3:
474 if (qe->cont != NULL) 429 ret = GNUNET_SYSERR;
475 { 430 emsg = _("Failed to create new signature");
476 qe->cont (qe->cont_cls, GNUNET_NO, _("Could not find record to remove")); 431 break;
477 } 432 case 4:
478 433 ret = GNUNET_SYSERR;
479 break; 434 emsg = _("Failed to put new set of records in database");
480 case 3: 435 break;
481 if (qe->cont != NULL) 436 default:
482 { 437 GNUNET_break (0);
483 qe->cont (qe->cont_cls, GNUNET_SYSERR, _("Failed to create new signature")); 438 ret = GNUNET_SYSERR;
484 } 439 emsg = _("Protocol error");
485 440 if (NULL != qe->cont)
486 break; 441 qe->cont (qe->cont_cls, GNUNET_SYSERR, _("Protocol error"));
487 case 4: 442 return GNUNET_NO;
488 if (qe->cont != NULL)
489 {
490 qe->cont (qe->cont_cls, GNUNET_SYSERR, _("Failed to put new set of records in database"));
491 }
492 break;
493 default:
494 GNUNET_break_op (0);
495 break;
496 } 443 }
497 444 if (NULL != qe->cont)
498 GNUNET_free (qe); 445 qe->cont (qe->cont_cls, ret, emsg);
446 return GNUNET_OK;
499} 447}
500 448
501 449
@@ -505,69 +453,69 @@ handle_record_remove_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
505 * @param qe the respective entry in the message queue 453 * @param qe the respective entry in the message queue
506 * @param msg the message we received 454 * @param msg the message we received
507 * @param size the message size 455 * @param size the message size
456 * @return GNUNET_OK on success, GNUNET_NO if we notified the client about
457 * the error, GNUNET_SYSERR on error and we did NOT notify the client
508 */ 458 */
509static void 459static int
510handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, 460handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
511 struct ZoneToNameResponseMessage* msg, 461 const struct ZoneToNameResponseMessage* msg,
512 size_t size) 462 size_t size)
513{ 463{
514 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 464 int res;
515 int res = ntohs (msg->res);
516 struct GNUNET_TIME_Absolute expire; 465 struct GNUNET_TIME_Absolute expire;
517 size_t name_len; 466 size_t name_len;
518 size_t rd_ser_len; 467 size_t rd_ser_len;
519 unsigned int rd_count; 468 unsigned int rd_count;
469 const char * name_tmp;
470 const char * rd_tmp;
520 471
521 char * name_tmp; 472 LOG (GNUNET_ERROR_TYPE_DEBUG,
522 char * rd_tmp; 473 "Received `%s'\n",
523
524 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n",
525 "ZONE_TO_NAME_RESPONSE"); 474 "ZONE_TO_NAME_RESPONSE");
526 /* Operation done, remove */ 475 res = ntohs (msg->res);
527 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); 476 switch (res)
528 if (res == GNUNET_SYSERR)
529 { 477 {
478 case GNUNET_SYSERR:
530 LOG (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to name operation\n"); 479 LOG (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to name operation\n");
531 if (qe->proc != NULL) 480 break;
532 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL); 481 case GNUNET_NO:
533 }
534 else if (res == GNUNET_NO)
535 {
536 LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n"); 482 LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n");
537 if (qe->proc != NULL) 483 break;
538 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL); 484 case GNUNET_YES:
539 }
540 else if (res == GNUNET_YES)
541 {
542 LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has result for zone to name mapping \n"); 485 LOG (GNUNET_ERROR_TYPE_DEBUG, "Namestore has result for zone to name mapping \n");
543
544 name_len = ntohs (msg->name_len); 486 name_len = ntohs (msg->name_len);
545 rd_count = ntohs (msg->rd_count); 487 rd_count = ntohs (msg->rd_count);
546 rd_ser_len = ntohs (msg->rd_len); 488 rd_ser_len = ntohs (msg->rd_len);
547 expire = GNUNET_TIME_absolute_ntoh(msg->expire); 489 expire = GNUNET_TIME_absolute_ntoh(msg->expire);
548 490 name_tmp = (const char *) &msg[1];
549 name_tmp = (char *) &msg[1]; 491 if ( (name_len > 0) &&
550 if (name_len > 0) 492 ('\0' != name_tmp[name_len -1]) )
551 { 493 {
552 GNUNET_assert ('\0' == name_tmp[name_len -1]); 494 GNUNET_break (0);
553 GNUNET_assert (name_len -1 == strlen(name_tmp)); 495 return GNUNET_SYSERR;
554 } 496 }
555 rd_tmp = &name_tmp[name_len]; 497 rd_tmp = &name_tmp[name_len];
556
557 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
558 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_tmp, rd_count, rd))
559 { 498 {
560 GNUNET_break_op (0); 499 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
561 return; 500 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_tmp, rd_count, rd))
501 {
502 GNUNET_break (0);
503 return GNUNET_SYSERR;
504 }
505 /* normal end, call continuation with result */
506 if (NULL != qe->proc)
507 qe->proc (qe->proc_cls, &msg->zone_key, expire, name_tmp, rd_count, rd, &msg->signature);
508 /* return is important here: break would call continuation with error! */
509 return GNUNET_OK;
562 } 510 }
563 511 default:
564 if (qe->proc != NULL) 512 GNUNET_break (0);
565 qe->proc (qe->proc_cls, &msg->zone_key, expire, name_tmp, rd_count, rd, &msg->signature); 513 return GNUNET_SYSERR;
566 } 514 }
567 else 515 /* error case, call continuation with error */
568 GNUNET_break_op (0); 516 if (NULL != qe->proc)
569 517 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL);
570 GNUNET_free (qe); 518 return GNUNET_OK;
571} 519}
572 520
573 521
@@ -578,58 +526,56 @@ handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
578 * @param msg the message we received 526 * @param msg the message we received
579 * @param type the message type in HBO 527 * @param type the message type in HBO
580 * @param size the message size 528 * @param size the message size
529 * @return GNUNET_OK on success, GNUNET_NO if we notified the client about
530 * the error, GNUNET_SYSERR on error and we did NOT notify the client
581 */ 531 */
582static void 532static int
583manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, 533manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe,
584 const struct GNUNET_MessageHeader *msg, 534 const struct GNUNET_MessageHeader *msg,
585 int type, size_t size) 535 uint16_t type,
536 size_t size)
586{ 537{
587
588 /* handle different message type */ 538 /* handle different message type */
589 switch (type) { 539 switch (type)
590 case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE: 540 {
591 if (size < sizeof (struct LookupNameResponseMessage)) 541 case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE:
592 { 542 if (size < sizeof (struct LookupNameResponseMessage))
593 GNUNET_break_op (0); 543 {
594 break; 544 GNUNET_break (0);
595 } 545 return GNUNET_SYSERR;
596 handle_lookup_name_response (qe, (struct LookupNameResponseMessage *) msg, size); 546 }
597 break; 547 return handle_lookup_name_response (qe, (const struct LookupNameResponseMessage *) msg, size);
598 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE: 548 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT_RESPONSE:
599 if (size != sizeof (struct RecordPutResponseMessage)) 549 if (size != sizeof (struct RecordPutResponseMessage))
600 { 550 {
601 GNUNET_break_op (0); 551 GNUNET_break (0);
602 break; 552 return GNUNET_SYSERR;
603 } 553 }
604 handle_record_put_response (qe, (struct RecordPutResponseMessage *) msg, size); 554 return handle_record_put_response (qe, (const struct RecordPutResponseMessage *) msg, size);
605 break; 555 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE:
606 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE: 556 if (size != sizeof (struct RecordCreateResponseMessage))
607 if (size != sizeof (struct RecordCreateResponseMessage)) 557 {
608 { 558 GNUNET_break (0);
609 GNUNET_break_op (0); 559 return GNUNET_SYSERR;
610 break; 560 }
611 } 561 return handle_record_create_response (qe, (const struct RecordCreateResponseMessage *) msg, size);
612 handle_record_create_response (qe, (struct RecordCreateResponseMessage *) msg, size); 562 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE:
613 break; 563 if (size != sizeof (struct RecordRemoveResponseMessage))
614 case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE: 564 {
615 if (size != sizeof (struct RecordRemoveResponseMessage)) 565 GNUNET_break (0);
616 { 566 return GNUNET_SYSERR;
617 GNUNET_break_op (0); 567 }
618 break; 568 return handle_record_remove_response (qe, (const struct RecordRemoveResponseMessage *) msg, size);
619 } 569 case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE:
620 handle_record_remove_response (qe, (struct RecordRemoveResponseMessage *) msg, size); 570 if (size < sizeof (struct ZoneToNameResponseMessage))
621 break; 571 {
622 case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE: 572 GNUNET_break (0);
623 if (size < sizeof (struct ZoneToNameResponseMessage)) 573 return GNUNET_SYSERR;
624 { 574 }
625 GNUNET_break_op (0); 575 return handle_zone_to_name_response (qe, (const struct ZoneToNameResponseMessage *) msg, size);
626 break; 576 default:
627 } 577 GNUNET_break (0);
628 handle_zone_to_name_response (qe, (struct ZoneToNameResponseMessage *) msg, size); 578 return GNUNET_SYSERR;
629 break;
630 default:
631 GNUNET_break_op (0);
632 break;
633 } 579 }
634} 580}
635 581
@@ -640,74 +586,65 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe,
640 * @param ze the respective iterator for this operation 586 * @param ze the respective iterator for this operation
641 * @param msg the message containing the respoonse 587 * @param msg the message containing the respoonse
642 * @param size the message size 588 * @param size the message size
589 * @return GNUNET_YES on success, 'ze' should be kept, GNUNET_NO on success if 'ze' should
590 * not be kept any longer, GNUNET_SYSERR on error (disconnect) and 'ze' should be kept
643 */ 591 */
644static void 592static int
645handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze, 593handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze,
646 struct ZoneIterationResponseMessage *msg, 594 const struct ZoneIterationResponseMessage *msg,
647 size_t size) 595 size_t size)
648{ 596{
649 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubdummy; 597 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubdummy;
650 size_t msg_len = 0; 598 size_t msg_len;
651 size_t exp_msg_len = 0; 599 size_t exp_msg_len;
652 size_t name_len = 0; 600 size_t name_len;
653 size_t rd_len = 0; 601 size_t rd_len;
654 unsigned rd_count = 0; 602 unsigned rd_count;
655 char *name_tmp; 603 const char *name_tmp;
656 char *rd_ser_tmp; 604 const char *rd_ser_tmp;
657 struct GNUNET_TIME_Absolute expire; 605 struct GNUNET_TIME_Absolute expire;
658 606
659 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' \n", 607 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s'\n",
660 "ZONE_ITERATION_RESPONSE"); 608 "ZONE_ITERATION_RESPONSE");
661 msg_len = ntohs (msg->gns_header.header.size); 609 msg_len = ntohs (msg->gns_header.header.size);
662 rd_len = ntohs (msg->rd_len); 610 rd_len = ntohs (msg->rd_len);
663 rd_count = ntohs (msg->rd_count); 611 rd_count = ntohs (msg->rd_count);
664 name_len = ntohs (msg->name_len); 612 name_len = ntohs (msg->name_len);
665 expire = GNUNET_TIME_absolute_ntoh (msg->expire); 613 expire = GNUNET_TIME_absolute_ntoh (msg->expire);
666
667 exp_msg_len = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_len; 614 exp_msg_len = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_len;
668 if (msg_len != exp_msg_len) 615 if (msg_len != exp_msg_len)
669 { 616 {
670 LOG (GNUNET_ERROR_TYPE_DEBUG, "Message size describes with `%u' bytes but calculated size is %u bytes \n", 617 GNUNET_break (0);
671 msg_len, exp_msg_len); 618 return GNUNET_SYSERR;
672 GNUNET_break_op (0);
673 return;
674 }
675 if (0 != ntohs (msg->reserved))
676 {
677 GNUNET_break_op (0);
678 return;
679 } 619 }
680 620 GNUNET_break (0 == ntohs (msg->reserved));
681 memset (&pubdummy, '\0', sizeof (pubdummy)); 621 memset (&pubdummy, '\0', sizeof (pubdummy));
682 if ((0 == name_len) && (0 == (memcmp (&msg->public_key, &pubdummy, sizeof (pubdummy))))) 622 if ((0 == name_len) && (0 == (memcmp (&msg->public_key, &pubdummy, sizeof (pubdummy)))))
683 { 623 {
684 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n"); 624 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zone iteration is completed!\n");
685 625 if (NULL != ze->proc)
686 GNUNET_CONTAINER_DLL_remove(ze->h->z_head, ze->h->z_tail, ze);
687
688 if (ze->proc != NULL)
689 ze->proc(ze->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL , 0, NULL, NULL); 626 ze->proc(ze->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL , 0, NULL, NULL);
690 627 return GNUNET_NO;
691 GNUNET_free (ze);
692 return;
693 } 628 }
694 629 name_tmp = (const char *) &msg[1];
695 name_tmp = (char *) &msg[1]; 630 if ((name_tmp[name_len -1] != '\0') || (name_len > MAX_NAME_LEN))
696 if ((name_tmp[name_len -1] != '\0') || (name_len > 256))
697 { 631 {
698 GNUNET_break_op (0); 632 GNUNET_break (0);
699 return; 633 return GNUNET_SYSERR;
700 } 634 }
701 rd_ser_tmp = (char *) &name_tmp[name_len]; 635 rd_ser_tmp = (const char *) &name_tmp[name_len];
702 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
703 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
704 { 636 {
705 GNUNET_break_op (0); 637 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
706 return;
707 }
708 638
709 if (ze->proc != NULL) 639 if (GNUNET_OK != GNUNET_NAMESTORE_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
710 ze->proc(ze->proc_cls, &msg->public_key, expire, name_tmp, rd_count, rd, &msg->signature); 640 {
641 GNUNET_break (0);
642 return GNUNET_SYSERR;
643 }
644 if (NULL != ze->proc)
645 ze->proc(ze->proc_cls, &msg->public_key, expire, name_tmp, rd_count, rd, &msg->signature);
646 return GNUNET_YES;
647 }
711} 648}
712 649
713 650
@@ -718,26 +655,27 @@ handle_zone_iteration_response (struct GNUNET_NAMESTORE_ZoneIterator *ze,
718 * @param msg the message we received 655 * @param msg the message we received
719 * @param type the message type in HBO 656 * @param type the message type in HBO
720 * @param size the message size 657 * @param size the message size
658 * @return GNUNET_YES on success, 'ze' should be kept, GNUNET_NO on success if 'ze' should
659 * not be kept any longer, GNUNET_SYSERR on error (disconnect) and 'ze' should be kept
721 */ 660 */
722static void 661static int
723manage_zone_operations (struct GNUNET_NAMESTORE_ZoneIterator *ze, 662manage_zone_operations (struct GNUNET_NAMESTORE_ZoneIterator *ze,
724 const struct GNUNET_MessageHeader *msg, 663 const struct GNUNET_MessageHeader *msg,
725 int type, size_t size) 664 int type, size_t size)
726{ 665{
727
728 /* handle different message type */ 666 /* handle different message type */
729 switch (type) { 667 switch (type)
730 case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE: 668 {
731 if (size < sizeof (struct ZoneIterationResponseMessage)) 669 case GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE:
732 { 670 if (size < sizeof (struct ZoneIterationResponseMessage))
733 GNUNET_break_op (0); 671 {
734 break; 672 GNUNET_break (0);
735 } 673 return GNUNET_SYSERR;
736 handle_zone_iteration_response (ze, (struct ZoneIterationResponseMessage *) msg, size); 674 }
737 break; 675 return handle_zone_iteration_response (ze, (const struct ZoneIterationResponseMessage *) msg, size);
738 default: 676 default:
739 GNUNET_break_op (0); 677 GNUNET_break (0);
740 break; 678 return GNUNET_SYSERR;
741 } 679 }
742} 680}
743 681
@@ -753,22 +691,21 @@ static void
753process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg) 691process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
754{ 692{
755 struct GNUNET_NAMESTORE_Handle *h = cls; 693 struct GNUNET_NAMESTORE_Handle *h = cls;
756 struct GNUNET_NAMESTORE_Header * gm; 694 const struct GNUNET_NAMESTORE_Header *gm;
757 struct GNUNET_NAMESTORE_QueueEntry *qe; 695 struct GNUNET_NAMESTORE_QueueEntry *qe;
758 struct GNUNET_NAMESTORE_ZoneIterator *ze; 696 struct GNUNET_NAMESTORE_ZoneIterator *ze;
759 uint16_t size; 697 uint16_t size;
760 uint16_t type; 698 uint16_t type;
761 uint32_t r_id = UINT32_MAX; 699 uint32_t r_id;
700 int ret;
762 701
763 if (NULL == msg) 702 if (NULL == msg)
764 { 703 {
765 force_reconnect (h); 704 force_reconnect (h);
766 return; 705 return;
767 } 706 }
768
769 size = ntohs (msg->size); 707 size = ntohs (msg->size);
770 type = ntohs (msg->type); 708 type = ntohs (msg->type);
771
772 if (size < sizeof (struct GNUNET_NAMESTORE_Header)) 709 if (size < sizeof (struct GNUNET_NAMESTORE_Header))
773 { 710 {
774 GNUNET_break_op (0); 711 GNUNET_break_op (0);
@@ -776,50 +713,64 @@ process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg)
776 GNUNET_TIME_UNIT_FOREVER_REL); 713 GNUNET_TIME_UNIT_FOREVER_REL);
777 return; 714 return;
778 } 715 }
779 716 gm = (const struct GNUNET_NAMESTORE_Header *) msg;
780 gm = (struct GNUNET_NAMESTORE_Header *) msg;
781 r_id = ntohl (gm->r_id); 717 r_id = ntohl (gm->r_id);
782 718
783 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message type %i size %i op %u\n", type, size, r_id); 719 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received message type %u size %u op %u\n",
784 720 (unsigned int) type,
785 /* Find matching operation */ 721 (unsigned int) size,
786 if (r_id > h->last_op_id_used) 722 (unsigned int) r_id);
787 {
788 /* No matching pending operation found */
789 GNUNET_break_op (0);
790 GNUNET_CLIENT_receive (h->client, &process_namestore_message, h,
791 GNUNET_TIME_UNIT_FOREVER_REL);
792 return;
793 }
794 723
795 /* Is it a record related operation ? */ 724 /* Is it a record related operation ? */
796 for (qe = h->op_head; qe != NULL; qe = qe->next) 725 for (qe = h->op_head; qe != NULL; qe = qe->next)
797 {
798 if (qe->op_id == r_id) 726 if (qe->op_id == r_id)
799 break; 727 break;
800 } 728 if (NULL != qe)
801 if (qe != NULL)
802 { 729 {
803 manage_record_operations (qe, msg, type, size); 730 ret = manage_record_operations (qe, msg, type, size);
731 if (GNUNET_OK != ret)
732 {
733 /* protocol error, need to reconnect */
734 h->reconnect = GNUNET_YES;
735 }
736 if (GNUNET_SYSERR != ret)
737 {
738 /* client was notified about success or failure, clean up 'qe' */
739 GNUNET_CONTAINER_DLL_remove (h->op_head,
740 h->op_tail,
741 qe);
742 GNUNET_free (qe);
743 }
804 } 744 }
805 745
806 /* Is it a zone iteration operation ? */ 746 /* Is it a zone iteration operation ? */
807 for (ze = h->z_head; ze != NULL; ze = ze->next) 747 for (ze = h->z_head; ze != NULL; ze = ze->next)
808 {
809 if (ze->op_id == r_id) 748 if (ze->op_id == r_id)
810 break; 749 break;
750 if (NULL != ze)
751 {
752 ret = manage_zone_operations (ze, msg, type, size);
753 if (GNUNET_NO == ret)
754 {
755 /* end of iteration, clean up 'ze' */
756 GNUNET_CONTAINER_DLL_remove (h->z_head,
757 h->z_tail,
758 ze);
759 GNUNET_free (ze);
760 }
761 if (GNUNET_SYSERR == ret)
762 {
763 /* protocol error, need to reconnect */
764 h->reconnect = GNUNET_YES;
765 }
811 } 766 }
812 if (ze != NULL) 767 if (GNUNET_YES == h->reconnect)
813 { 768 {
814 manage_zone_operations (ze, msg, type, size); 769 force_reconnect (h);
770 return;
815 } 771 }
816
817 GNUNET_CLIENT_receive (h->client, &process_namestore_message, h, 772 GNUNET_CLIENT_receive (h->client, &process_namestore_message, h,
818 GNUNET_TIME_UNIT_FOREVER_REL); 773 GNUNET_TIME_UNIT_FOREVER_REL);
819
820 if (GNUNET_YES == h->reconnect)
821 force_reconnect (h);
822
823} 774}
824 775
825 776
@@ -850,7 +801,7 @@ transmit_message_to_namestore (void *cls, size_t size, void *buf)
850 char *cbuf; 801 char *cbuf;
851 802
852 h->th = NULL; 803 h->th = NULL;
853 if ((size == 0) || (buf == NULL)) 804 if ((0 == size) || (NULL == buf))
854 { 805 {
855 force_reconnect (h); 806 force_reconnect (h);
856 return 0; 807 return 0;
@@ -885,12 +836,11 @@ do_transmit (struct GNUNET_NAMESTORE_Handle *h)
885 struct PendingMessage *p; 836 struct PendingMessage *p;
886 837
887 if (NULL != h->th) 838 if (NULL != h->th)
888 return; 839 return; /* transmission request already pending */
889 if (NULL == (p = h->pending_head)) 840 if (NULL == (p = h->pending_head))
890 return; 841 return; /* transmission queue empty */
891 if (NULL == h->client) 842 if (NULL == h->client)
892 return; /* currently reconnecting */ 843 return; /* currently reconnecting */
893
894 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, p->size, 844 h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, p->size,
895 GNUNET_TIME_UNIT_FOREVER_REL, 845 GNUNET_TIME_UNIT_FOREVER_REL,
896 GNUNET_NO, &transmit_message_to_namestore, 846 GNUNET_NO, &transmit_message_to_namestore,
@@ -912,7 +862,6 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h)
912 GNUNET_assert (NULL == h->client); 862 GNUNET_assert (NULL == h->client);
913 h->client = GNUNET_CLIENT_connect ("namestore", h->cfg); 863 h->client = GNUNET_CLIENT_connect ("namestore", h->cfg);
914 GNUNET_assert (NULL != h->client); 864 GNUNET_assert (NULL != h->client);
915
916 if ((NULL == (p = h->pending_head)) || (GNUNET_YES != p->is_init)) 865 if ((NULL == (p = h->pending_head)) || (GNUNET_YES != p->is_init))
917 { 866 {
918 p = GNUNET_malloc (sizeof (struct PendingMessage) + 867 p = GNUNET_malloc (sizeof (struct PendingMessage) +
@@ -927,6 +876,7 @@ reconnect (struct GNUNET_NAMESTORE_Handle *h)
927 do_transmit (h); 876 do_transmit (h);
928} 877}
929 878
879
930/** 880/**
931 * Re-establish the connection to the service. 881 * Re-establish the connection to the service.
932 * 882 *
@@ -955,22 +905,21 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h)
955 GNUNET_CLIENT_disconnect (h->client); 905 GNUNET_CLIENT_disconnect (h->client);
956 h->client = NULL; 906 h->client = NULL;
957 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 907 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
958 &reconnect_task, 908 &reconnect_task,
959 h); 909 h);
960} 910}
961 911
962 912
963/** 913/**
964 * Get an unused operation id to distinguish between namestore requests 914 * Get a fresh operation id to distinguish between namestore requests
915 *
965 * @param h the namestore handle 916 * @param h the namestore handle
966 * @return operation id 917 * @return next operation id to use
967 */ 918 */
968static uint32_t 919static uint32_t
969get_op_id (struct GNUNET_NAMESTORE_Handle *h) 920get_op_id (struct GNUNET_NAMESTORE_Handle *h)
970{ 921{
971 uint32_t op_id = h->last_op_id_used; 922 return h->last_op_id_used++;
972 h->last_op_id_used ++;
973 return op_id;
974} 923}
975 924
976 925
@@ -993,26 +942,33 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
993} 942}
994 943
995 944
996static void 945/**
997clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 946 * Disconnect from the namestore service (and free associated
947 * resources).
948 *
949 * @param h handle to the namestore
950 */
951void
952GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
998{ 953{
999 struct GNUNET_NAMESTORE_Handle *h = cls;
1000 struct PendingMessage *p; 954 struct PendingMessage *p;
1001 struct GNUNET_NAMESTORE_QueueEntry *q; 955 struct GNUNET_NAMESTORE_QueueEntry *q;
1002 struct GNUNET_NAMESTORE_ZoneIterator *z; 956 struct GNUNET_NAMESTORE_ZoneIterator *z;
1003 957
1004 GNUNET_assert (h != NULL);
1005 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n"); 958 LOG (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
959 GNUNET_assert (NULL != h);
1006 while (NULL != (p = h->pending_head)) 960 while (NULL != (p = h->pending_head))
1007 { 961 {
1008 GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, p); 962 GNUNET_CONTAINER_DLL_remove (h->pending_head, h->pending_tail, p);
1009 GNUNET_free (p); 963 GNUNET_free (p);
1010 } 964 }
965 GNUNET_break (NULL == h->op_head);
1011 while (NULL != (q = h->op_head)) 966 while (NULL != (q = h->op_head))
1012 { 967 {
1013 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q); 968 GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, q);
1014 GNUNET_free (q); 969 GNUNET_free (q);
1015 } 970 }
971 GNUNET_break (NULL == h->z_head);
1016 while (NULL != (z = h->z_head)) 972 while (NULL != (z = h->z_head))
1017 { 973 {
1018 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z); 974 GNUNET_CONTAINER_DLL_remove (h->z_head, h->z_tail, z);
@@ -1028,22 +984,7 @@ clean_up_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1028 GNUNET_SCHEDULER_cancel (h->reconnect_task); 984 GNUNET_SCHEDULER_cancel (h->reconnect_task);
1029 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 985 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1030 } 986 }
1031 GNUNET_free(h); 987 GNUNET_free (h);
1032 h = NULL;
1033}
1034
1035
1036/**
1037 * Disconnect from the namestore service (and free associated
1038 * resources).
1039 *
1040 * @param h handle to the namestore
1041 */
1042void
1043GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h)
1044{
1045 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from namestore service\n");
1046 GNUNET_SCHEDULER_add_now (&clean_up_task, h);
1047} 988}
1048 989
1049 990
@@ -1078,14 +1019,13 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
1078{ 1019{
1079 struct GNUNET_NAMESTORE_QueueEntry *qe; 1020 struct GNUNET_NAMESTORE_QueueEntry *qe;
1080 struct PendingMessage *pe; 1021 struct PendingMessage *pe;
1081 1022 struct RecordPutMessage * msg;
1082 /* pointer to elements */ 1023 char * rd_ser;
1083 char * rd_tmp;
1084 char * name_tmp; 1024 char * name_tmp;
1085 size_t msg_size = 0; 1025 size_t msg_size;
1086 size_t name_len = 0; 1026 size_t name_len;
1087 size_t rd_ser_len = 0; 1027 size_t rd_ser_len;
1088 uint32_t rid = 0; 1028 uint32_t rid;
1089 1029
1090 GNUNET_assert (NULL != h); 1030 GNUNET_assert (NULL != h);
1091 GNUNET_assert (NULL != zone_key); 1031 GNUNET_assert (NULL != zone_key);
@@ -1097,36 +1037,26 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
1097 rd_count, 1037 rd_count,
1098 name); 1038 name);
1099 name_len = strlen(name) + 1; 1039 name_len = strlen(name) + 1;
1100 if (name_len > 256) 1040 if (name_len > MAX_NAME_LEN)
1101 { 1041 {
1102 GNUNET_break (0); 1042 GNUNET_break (0);
1103 return NULL; 1043 return NULL;
1104 } 1044 }
1105 1045 rid = get_op_id (h);
1106 rid = get_op_id(h);
1107 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 1046 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1108 qe->nsh = h; 1047 qe->nsh = h;
1109 qe->cont = cont; 1048 qe->cont = cont;
1110 qe->cont_cls = cont_cls; 1049 qe->cont_cls = cont_cls;
1111 qe->op_id = rid; 1050 qe->op_id = rid;
1112 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); 1051 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1113 1052
1114 /* set msg_size*/ 1053 /* setup msg */
1115 rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd); 1054 rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd);
1116 char rd_ser[rd_ser_len];
1117 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1118
1119 struct RecordPutMessage * msg;
1120 msg_size = sizeof (struct RecordPutMessage) + name_len + rd_ser_len; 1055 msg_size = sizeof (struct RecordPutMessage) + name_len + rd_ser_len;
1121
1122 /* create msg here */
1123 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1056 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1124 pe->size = msg_size; 1057 pe->size = msg_size;
1125 pe->is_init = GNUNET_NO; 1058 pe->is_init = GNUNET_NO;
1126 msg = (struct RecordPutMessage *) &pe[1]; 1059 msg = (struct RecordPutMessage *) &pe[1];
1127 name_tmp = (char *) &msg[1];
1128 rd_tmp = &name_tmp[name_len];
1129
1130 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT); 1060 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT);
1131 msg->gns_header.header.size = htons (msg_size); 1061 msg->gns_header.header.size = htons (msg_size);
1132 msg->gns_header.r_id = htonl (rid); 1062 msg->gns_header.r_id = htonl (rid);
@@ -1135,16 +1065,17 @@ GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
1135 msg->expire = GNUNET_TIME_absolute_hton (freshness); 1065 msg->expire = GNUNET_TIME_absolute_hton (freshness);
1136 msg->rd_len = htons (rd_ser_len); 1066 msg->rd_len = htons (rd_ser_len);
1137 msg->rd_count = htons (rd_count); 1067 msg->rd_count = htons (rd_count);
1138
1139 msg->public_key = *zone_key; 1068 msg->public_key = *zone_key;
1069 name_tmp = (char *) &msg[1];
1140 memcpy (name_tmp, name, name_len); 1070 memcpy (name_tmp, name, name_len);
1141 memcpy (rd_tmp, rd_ser, rd_ser_len); 1071 rd_ser = &name_tmp[name_len];
1142 1072 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1143 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s' with size %u\n", "NAMESTORE_RECORD_PUT", name, msg_size); 1073 LOG (GNUNET_ERROR_TYPE_DEBUG,
1144 1074 "Sending `%s' message for name `%s' with size %u\n",
1075 "NAMESTORE_RECORD_PUT",
1076 name, msg_size);
1145 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1077 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1146 do_transmit(h); 1078 do_transmit(h);
1147
1148 return qe; 1079 return qe;
1149} 1080}
1150 1081
@@ -1169,11 +1100,10 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary
1169 const struct GNUNET_NAMESTORE_RecordData *rd, 1100 const struct GNUNET_NAMESTORE_RecordData *rd,
1170 const struct GNUNET_CRYPTO_RsaSignature *signature) 1101 const struct GNUNET_CRYPTO_RsaSignature *signature)
1171{ 1102{
1172 int res;
1173 size_t rd_ser_len; 1103 size_t rd_ser_len;
1174 size_t name_len; 1104 size_t name_len;
1175 char * name_tmp; 1105 char * name_tmp;
1176 char * rd_tmp; 1106 char * rd_ser;
1177 struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose; 1107 struct GNUNET_CRYPTO_RsaSignaturePurpose *sig_purpose;
1178 struct GNUNET_TIME_AbsoluteNBO *expire_tmp; 1108 struct GNUNET_TIME_AbsoluteNBO *expire_tmp;
1179 struct GNUNET_TIME_AbsoluteNBO expire_nbo = GNUNET_TIME_absolute_hton (freshness); 1109 struct GNUNET_TIME_AbsoluteNBO expire_nbo = GNUNET_TIME_absolute_hton (freshness);
@@ -1184,35 +1114,31 @@ GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinary
1184 GNUNET_assert (NULL != rd); 1114 GNUNET_assert (NULL != rd);
1185 GNUNET_assert (NULL != signature); 1115 GNUNET_assert (NULL != signature);
1186 name_len = strlen (name) + 1; 1116 name_len = strlen (name) + 1;
1187 if (name_len > 256) 1117 if (name_len > MAX_NAME_LEN)
1188 { 1118 {
1189 GNUNET_break (0); 1119 GNUNET_break (0);
1190 return GNUNET_SYSERR; 1120 return GNUNET_SYSERR;
1191 } 1121 }
1192 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 1122 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1123 sig_len = sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + rd_ser_len + name_len;
1193 { 1124 {
1194 char rd_ser[rd_ser_len]; 1125 char sig_buf[rd_ser_len] GNUNET_ALIGN;
1195 1126
1196 GNUNET_assert (rd_ser_len == 1127 sig_purpose = (struct GNUNET_CRYPTO_RsaSignaturePurpose *) sig_buf;
1197 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser));
1198 sig_len = sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + rd_ser_len + name_len;
1199 sig_purpose = GNUNET_malloc (sig_len);
1200 sig_purpose->size = htonl (sig_len); 1128 sig_purpose->size = htonl (sig_len);
1201 sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); 1129 sig_purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN);
1202 expire_tmp = (struct GNUNET_TIME_AbsoluteNBO *) &sig_purpose[1]; 1130 expire_tmp = (struct GNUNET_TIME_AbsoluteNBO *) &sig_purpose[1];
1203 memcpy (expire_tmp, &expire_nbo, sizeof (struct GNUNET_TIME_AbsoluteNBO)); 1131 memcpy (expire_tmp, &expire_nbo, sizeof (struct GNUNET_TIME_AbsoluteNBO));
1204 name_tmp = (char *) &expire_tmp[1]; 1132 name_tmp = (char *) &expire_tmp[1];
1205 memcpy (name_tmp, name, name_len); 1133 memcpy (name_tmp, name, name_len);
1206 rd_tmp = &name_tmp[name_len]; 1134 rd_ser = &name_tmp[name_len];
1207 memcpy (rd_tmp, rd_ser, rd_ser_len); 1135 GNUNET_assert (rd_ser_len ==
1208 res = GNUNET_CRYPTO_rsa_verify(GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, sig_purpose, signature, public_key); 1136 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser));
1209 1137 return GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN, sig_purpose, signature, public_key);
1210 } 1138 }
1211 GNUNET_free (sig_purpose);
1212
1213 return res;
1214} 1139}
1215 1140
1141
1216/** 1142/**
1217 * Store an item in the namestore. If the item is already present, 1143 * Store an item in the namestore. If the item is already present,
1218 * the expiration time is updated to the max of the existing time and 1144 * the expiration time is updated to the max of the existing time and
@@ -1238,12 +1164,14 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
1238 struct PendingMessage *pe; 1164 struct PendingMessage *pe;
1239 char * name_tmp; 1165 char * name_tmp;
1240 char * pkey_tmp; 1166 char * pkey_tmp;
1241 char * rd_tmp; 1167 char * rd_ser;
1242 size_t rd_ser_len = 0; 1168 size_t rd_ser_len;
1243 size_t msg_size = 0; 1169 size_t msg_size;
1244 size_t name_len = 0; 1170 size_t name_len;
1245 size_t key_len = 0; 1171 size_t key_len;
1246 uint32_t rid = 0; 1172 uint32_t rid;
1173 struct RecordCreateMessage * msg;
1174 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * pkey_enc;
1247 1175
1248 GNUNET_assert (NULL != h); 1176 GNUNET_assert (NULL != h);
1249 GNUNET_assert (NULL != pkey); 1177 GNUNET_assert (NULL != pkey);
@@ -1254,42 +1182,30 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
1254 rd->record_type, 1182 rd->record_type,
1255 name); 1183 name);
1256 name_len = strlen(name) + 1; 1184 name_len = strlen(name) + 1;
1257 if (name_len > 256) 1185 if (name_len > MAX_NAME_LEN)
1258 { 1186 {
1259 GNUNET_break (0); 1187 GNUNET_break (0);
1260 return NULL; 1188 return NULL;
1261 } 1189 }
1262
1263 rid = get_op_id(h); 1190 rid = get_op_id(h);
1264 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 1191 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1265 qe->nsh = h; 1192 qe->nsh = h;
1266 qe->cont = cont; 1193 qe->cont = cont;
1267 qe->cont_cls = cont_cls; 1194 qe->cont_cls = cont_cls;
1268 qe->op_id = rid; 1195 qe->op_id = rid;
1269 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); 1196 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1270 1197
1271 /* set msg_size*/ 1198 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (pkey);
1272 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * pkey_enc = GNUNET_CRYPTO_rsa_encode_key (pkey); 1199 GNUNET_assert (NULL != pkey_enc);
1273 GNUNET_assert (pkey_enc != NULL);
1274 key_len = ntohs (pkey_enc->len);
1275 1200
1201 /* setup msg */
1202 key_len = ntohs (pkey_enc->len);
1276 rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, rd); 1203 rd_ser_len = GNUNET_NAMESTORE_records_get_size(1, rd);
1277 char rd_ser[rd_ser_len];
1278 GNUNET_NAMESTORE_records_serialize(1, rd, rd_ser_len, rd_ser);
1279
1280 struct RecordCreateMessage * msg;
1281 msg_size = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len; 1204 msg_size = sizeof (struct RecordCreateMessage) + key_len + name_len + rd_ser_len;
1282
1283 /* create msg here */
1284 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1205 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1285 pe->size = msg_size; 1206 pe->size = msg_size;
1286 pe->is_init = GNUNET_NO; 1207 pe->is_init = GNUNET_NO;
1287 msg = (struct RecordCreateMessage *) &pe[1]; 1208 msg = (struct RecordCreateMessage *) &pe[1];
1288
1289 pkey_tmp = (char *) &msg[1];
1290 name_tmp = &pkey_tmp[key_len];
1291 rd_tmp = &name_tmp[name_len];
1292
1293 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE); 1209 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE);
1294 msg->gns_header.header.size = htons (msg_size); 1210 msg->gns_header.header.size = htons (msg_size);
1295 msg->gns_header.r_id = htonl (rid); 1211 msg->gns_header.r_id = htonl (rid);
@@ -1298,9 +1214,13 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
1298 msg->rd_len = htons (rd_ser_len); 1214 msg->rd_len = htons (rd_ser_len);
1299 msg->pkey_len = htons (key_len); 1215 msg->pkey_len = htons (key_len);
1300 msg->expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS); 1216 msg->expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS);
1217 pkey_tmp = (char *) &msg[1];
1301 memcpy (pkey_tmp, pkey_enc, key_len); 1218 memcpy (pkey_tmp, pkey_enc, key_len);
1219 name_tmp = &pkey_tmp[key_len];
1302 memcpy (name_tmp, name, name_len); 1220 memcpy (name_tmp, name, name_len);
1303 memcpy (rd_tmp, rd_ser, rd_ser_len); 1221 rd_ser = &name_tmp[name_len];
1222 GNUNET_NAMESTORE_records_serialize(1, rd, rd_ser_len, rd_ser);
1223
1304 GNUNET_free (pkey_enc); 1224 GNUNET_free (pkey_enc);
1305 1225
1306 LOG (GNUNET_ERROR_TYPE_DEBUG, 1226 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1336,16 +1256,18 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
1336 void *cont_cls) 1256 void *cont_cls)
1337{ 1257{
1338 struct GNUNET_NAMESTORE_QueueEntry *qe; 1258 struct GNUNET_NAMESTORE_QueueEntry *qe;
1259 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * pkey_enc;
1339 struct PendingMessage *pe; 1260 struct PendingMessage *pe;
1261 struct RecordRemoveMessage * msg;
1340 char *pkey_tmp; 1262 char *pkey_tmp;
1341 char *rd_tmp; 1263 char *rd_ser;
1342 char *name_tmp; 1264 char *name_tmp;
1343 size_t rd_ser_len = 0; 1265 size_t rd_ser_len;
1344 size_t msg_size = 0; 1266 size_t msg_size;
1345 size_t name_len = 0; 1267 size_t name_len;
1346 size_t key_len = 0; 1268 size_t key_len;
1347 uint32_t rid = 0; 1269 uint32_t rid;
1348 uint16_t rd_count = 1; 1270 uint16_t rd_count;
1349 1271
1350 GNUNET_assert (NULL != h); 1272 GNUNET_assert (NULL != h);
1351 if (NULL != rd) 1273 if (NULL != rd)
@@ -1363,36 +1285,20 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
1363 qe->cont = cont; 1285 qe->cont = cont;
1364 qe->cont_cls = cont_cls; 1286 qe->cont_cls = cont_cls;
1365 qe->op_id = rid; 1287 qe->op_id = rid;
1366 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); 1288 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1367 1289
1368 /* set msg_size*/ 1290 pkey_enc = GNUNET_CRYPTO_rsa_encode_key (pkey);
1369 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * pkey_enc = GNUNET_CRYPTO_rsa_encode_key (pkey); 1291 GNUNET_assert (NULL != pkey_enc);
1370 GNUNET_assert (pkey_enc != NULL);
1371 key_len = ntohs (pkey_enc->len); 1292 key_len = ntohs (pkey_enc->len);
1372 1293
1373 if (NULL == rd) 1294 rd_count = (NULL == rd) ? 0 : 1;
1374 rd_count = 0;
1375 else
1376 rd_count = 1;
1377 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 1295 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1378 char rd_ser[rd_ser_len];
1379 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
1380
1381 name_len = strlen (name) + 1; 1296 name_len = strlen (name) + 1;
1382
1383 struct RecordRemoveMessage * msg;
1384 msg_size = sizeof (struct RecordRemoveMessage) + key_len + name_len + rd_ser_len; 1297 msg_size = sizeof (struct RecordRemoveMessage) + key_len + name_len + rd_ser_len;
1385
1386 /* create msg here */
1387 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1298 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1388 pe->size = msg_size; 1299 pe->size = msg_size;
1389 pe->is_init = GNUNET_NO; 1300 pe->is_init = GNUNET_NO;
1390 msg = (struct RecordRemoveMessage *) &pe[1]; 1301 msg = (struct RecordRemoveMessage *) &pe[1];
1391
1392 pkey_tmp = (char *) &msg[1];
1393 name_tmp = &pkey_tmp[key_len];
1394 rd_tmp = &name_tmp[name_len];
1395
1396 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE); 1302 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE);
1397 msg->gns_header.header.size = htons (msg_size); 1303 msg->gns_header.header.size = htons (msg_size);
1398 msg->gns_header.r_id = htonl (rid); 1304 msg->gns_header.r_id = htonl (rid);
@@ -1400,16 +1306,18 @@ GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
1400 msg->rd_len = htons (rd_ser_len); 1306 msg->rd_len = htons (rd_ser_len);
1401 msg->rd_count = htons (rd_count); 1307 msg->rd_count = htons (rd_count);
1402 msg->pkey_len = htons (key_len); 1308 msg->pkey_len = htons (key_len);
1309 pkey_tmp = (char *) &msg[1];
1403 memcpy (pkey_tmp, pkey_enc, key_len); 1310 memcpy (pkey_tmp, pkey_enc, key_len);
1311 name_tmp = &pkey_tmp[key_len];
1404 memcpy (name_tmp, name, name_len); 1312 memcpy (name_tmp, name, name_len);
1405 memcpy (rd_tmp, rd_ser, rd_ser_len); 1313 rd_ser = &name_tmp[name_len];
1314 GNUNET_NAMESTORE_records_serialize (rd_count, rd, rd_ser_len, rd_ser);
1406 1315
1407 GNUNET_free (pkey_enc); 1316 GNUNET_free (pkey_enc);
1408 1317
1409 LOG (GNUNET_ERROR_TYPE_DEBUG, 1318 LOG (GNUNET_ERROR_TYPE_DEBUG,
1410 "Sending `%s' message for name `%s' with size %u\n", 1319 "Sending `%s' message for name `%s' with size %u\n",
1411 "NAMESTORE_RECORD_REMOVE", name, msg_size); 1320 "NAMESTORE_RECORD_REMOVE", name, msg_size);
1412
1413 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1321 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1414 do_transmit(h); 1322 do_transmit(h);
1415 return qe; 1323 return qe;
@@ -1439,9 +1347,10 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
1439{ 1347{
1440 struct GNUNET_NAMESTORE_QueueEntry *qe; 1348 struct GNUNET_NAMESTORE_QueueEntry *qe;
1441 struct PendingMessage *pe; 1349 struct PendingMessage *pe;
1442 size_t msg_size = 0; 1350 struct LookupNameMessage * msg;
1443 size_t name_len = 0; 1351 size_t msg_size;
1444 uint32_t rid = 0; 1352 size_t name_len;
1353 uint32_t rid;
1445 1354
1446 GNUNET_assert (NULL != h); 1355 GNUNET_assert (NULL != h);
1447 GNUNET_assert (NULL != zone); 1356 GNUNET_assert (NULL != zone);
@@ -1450,9 +1359,8 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
1450 "Looking for record of type %u under name `%s'\n", 1359 "Looking for record of type %u under name `%s'\n",
1451 record_type, 1360 record_type,
1452 name); 1361 name);
1453
1454 name_len = strlen (name) + 1; 1362 name_len = strlen (name) + 1;
1455 if ((name_len == 0) || (name_len > 256)) 1363 if ((name_len == 0) || (name_len > MAX_NAME_LEN))
1456 { 1364 {
1457 GNUNET_break (0); 1365 GNUNET_break (0);
1458 return NULL; 1366 return NULL;
@@ -1464,14 +1372,10 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
1464 qe->proc = proc; 1372 qe->proc = proc;
1465 qe->proc_cls = proc_cls; 1373 qe->proc_cls = proc_cls;
1466 qe->op_id = rid; 1374 qe->op_id = rid;
1467 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); 1375 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1468 1376
1469 /* set msg_size*/
1470 msg_size = sizeof (struct LookupNameMessage) + name_len; 1377 msg_size = sizeof (struct LookupNameMessage) + name_len;
1471 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1378 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1472
1473 /* create msg here */
1474 struct LookupNameMessage * msg;
1475 pe->size = msg_size; 1379 pe->size = msg_size;
1476 pe->is_init = GNUNET_NO; 1380 pe->is_init = GNUNET_NO;
1477 msg = (struct LookupNameMessage *) &pe[1]; 1381 msg = (struct LookupNameMessage *) &pe[1];
@@ -1485,11 +1389,8 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
1485 1389
1486 LOG (GNUNET_ERROR_TYPE_DEBUG, 1390 LOG (GNUNET_ERROR_TYPE_DEBUG,
1487 "Sending `%s' message for name `%s'\n", "NAMESTORE_LOOKUP_NAME", name); 1391 "Sending `%s' message for name `%s'\n", "NAMESTORE_LOOKUP_NAME", name);
1488
1489 /* transmit message */
1490 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1392 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1491 do_transmit(h); 1393 do_transmit(h);
1492
1493 return qe; 1394 return qe;
1494} 1395}
1495 1396
@@ -1515,27 +1416,23 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
1515{ 1416{
1516 struct GNUNET_NAMESTORE_QueueEntry *qe; 1417 struct GNUNET_NAMESTORE_QueueEntry *qe;
1517 struct PendingMessage *pe; 1418 struct PendingMessage *pe;
1518 size_t msg_size = 0; 1419 struct ZoneToNameMessage * msg;
1519 uint32_t rid = 0; 1420 size_t msg_size;
1421 uint32_t rid;
1520 1422
1521 GNUNET_assert (NULL != h); 1423 GNUNET_assert (NULL != h);
1522 GNUNET_assert (NULL != zone); 1424 GNUNET_assert (NULL != zone);
1523 GNUNET_assert (NULL != value_zone); 1425 GNUNET_assert (NULL != value_zone);
1524
1525 rid = get_op_id(h); 1426 rid = get_op_id(h);
1526 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 1427 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
1527 qe->nsh = h; 1428 qe->nsh = h;
1528 qe->proc = proc; 1429 qe->proc = proc;
1529 qe->proc_cls = proc_cls; 1430 qe->proc_cls = proc_cls;
1530 qe->op_id = rid; 1431 qe->op_id = rid;
1531 GNUNET_CONTAINER_DLL_insert_tail(h->op_head, h->op_tail, qe); 1432 GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe);
1532 1433
1533 /* set msg_size*/
1534 msg_size = sizeof (struct ZoneToNameMessage); 1434 msg_size = sizeof (struct ZoneToNameMessage);
1535 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1435 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1536
1537 /* create msg here */
1538 struct ZoneToNameMessage * msg;
1539 pe->size = msg_size; 1436 pe->size = msg_size;
1540 pe->is_init = GNUNET_NO; 1437 pe->is_init = GNUNET_NO;
1541 msg = (struct ZoneToNameMessage *) &pe[1]; 1438 msg = (struct ZoneToNameMessage *) &pe[1];
@@ -1545,23 +1442,13 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h,
1545 msg->zone = *zone; 1442 msg->zone = *zone;
1546 msg->value_zone = *value_zone; 1443 msg->value_zone = *value_zone;
1547 1444
1548 char * z_tmp = GNUNET_strdup (GNUNET_short_h2s (zone));
1549 LOG (GNUNET_ERROR_TYPE_DEBUG,
1550 "Sending `%s' message for zone `%s' in zone `%s'\n",
1551 "NAMESTORE_ZONE_TO_NAME",
1552 z_tmp,
1553 GNUNET_short_h2s (value_zone));
1554 GNUNET_free (z_tmp);
1555
1556 /* transmit message */ 1445 /* transmit message */
1557 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1446 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1558 do_transmit(h); 1447 do_transmit(h);
1559
1560 return qe; 1448 return qe;
1561} 1449}
1562 1450
1563 1451
1564
1565/** 1452/**
1566 * Starts a new zone iteration (used to periodically PUT all of our 1453 * Starts a new zone iteration (used to periodically PUT all of our
1567 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle 1454 * records into our DHT). This MUST lock the GNUNET_NAMESTORE_Handle
@@ -1590,8 +1477,9 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1590{ 1477{
1591 struct GNUNET_NAMESTORE_ZoneIterator *it; 1478 struct GNUNET_NAMESTORE_ZoneIterator *it;
1592 struct PendingMessage *pe; 1479 struct PendingMessage *pe;
1593 size_t msg_size = 0; 1480 struct ZoneIterationStartMessage * msg;
1594 uint32_t rid = 0; 1481 size_t msg_size;
1482 uint32_t rid;
1595 1483
1596 GNUNET_assert (NULL != h); 1484 GNUNET_assert (NULL != h);
1597 rid = get_op_id(h); 1485 rid = get_op_id(h);
@@ -1600,7 +1488,6 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1600 it->proc = proc; 1488 it->proc = proc;
1601 it->proc_cls = proc_cls; 1489 it->proc_cls = proc_cls;
1602 it->op_id = rid; 1490 it->op_id = rid;
1603
1604 if (NULL != zone) 1491 if (NULL != zone)
1605 { 1492 {
1606 it->zone = *zone; 1493 it->zone = *zone;
@@ -1611,14 +1498,10 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1611 memset (&it->zone, '\0', sizeof (it->zone)); 1498 memset (&it->zone, '\0', sizeof (it->zone));
1612 it->has_zone = GNUNET_NO; 1499 it->has_zone = GNUNET_NO;
1613 } 1500 }
1614 GNUNET_CONTAINER_DLL_insert_tail(h->z_head, h->z_tail, it); 1501 GNUNET_CONTAINER_DLL_insert_tail (h->z_head, h->z_tail, it);
1615 1502
1616 /* set msg_size*/
1617 msg_size = sizeof (struct ZoneIterationStartMessage); 1503 msg_size = sizeof (struct ZoneIterationStartMessage);
1618 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1504 pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
1619
1620 /* create msg here */
1621 struct ZoneIterationStartMessage * msg;
1622 pe->size = msg_size; 1505 pe->size = msg_size;
1623 pe->is_init = GNUNET_NO; 1506 pe->is_init = GNUNET_NO;
1624 msg = (struct ZoneIterationStartMessage *) &pe[1]; 1507 msg = (struct ZoneIterationStartMessage *) &pe[1];
@@ -1640,11 +1523,8 @@ GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h,
1640 } 1523 }
1641 msg->must_have_flags = ntohs (must_have_flags); 1524 msg->must_have_flags = ntohs (must_have_flags);
1642 msg->must_not_have_flags = ntohs (must_not_have_flags); 1525 msg->must_not_have_flags = ntohs (must_not_have_flags);
1643
1644 /* transmit message */
1645 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1526 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1646 do_transmit(h); 1527 do_transmit(h);
1647
1648 return it; 1528 return it;
1649} 1529}
1650 1530
@@ -1659,37 +1539,21 @@ void
1659GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it) 1539GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it)
1660{ 1540{
1661 struct GNUNET_NAMESTORE_Handle *h; 1541 struct GNUNET_NAMESTORE_Handle *h;
1542 struct ZoneIterationNextMessage * msg;
1662 struct PendingMessage *pe; 1543 struct PendingMessage *pe;
1663 size_t msg_size = 0; 1544 size_t msg_size;
1664 1545
1665 GNUNET_assert (NULL != it); 1546 GNUNET_assert (NULL != it);
1666 h = it->h; 1547 h = it->h;
1667 struct GNUNET_NAMESTORE_ZoneIterator *tmp = it->h->z_head;
1668
1669 while (tmp != NULL)
1670 {
1671 if (tmp == it)
1672 break;
1673 tmp = tmp->next;
1674 }
1675 GNUNET_assert (NULL != tmp);
1676
1677 /* set msg_size*/
1678 msg_size = sizeof (struct ZoneIterationNextMessage); 1548 msg_size = sizeof (struct ZoneIterationNextMessage);
1679 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1549 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1680
1681 /* create msg here */
1682 struct ZoneIterationNextMessage * msg;
1683 pe->size = msg_size; 1550 pe->size = msg_size;
1684 pe->is_init = GNUNET_NO; 1551 pe->is_init = GNUNET_NO;
1685 msg = (struct ZoneIterationNextMessage *) &pe[1]; 1552 msg = (struct ZoneIterationNextMessage *) &pe[1];
1686 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT); 1553 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT);
1687 msg->gns_header.header.size = htons (msg_size); 1554 msg->gns_header.header.size = htons (msg_size);
1688 msg->gns_header.r_id = htonl (it->op_id); 1555 msg->gns_header.r_id = htonl (it->op_id);
1689
1690 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_NEXT"); 1556 LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_NEXT");
1691
1692 /* transmit message */
1693 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1557 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1694 do_transmit(h); 1558 do_transmit(h);
1695} 1559}
@@ -1703,41 +1567,33 @@ GNUNET_NAMESTORE_zone_iterator_next (struct GNUNET_NAMESTORE_ZoneIterator *it)
1703void 1567void
1704GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it) 1568GNUNET_NAMESTORE_zone_iteration_stop (struct GNUNET_NAMESTORE_ZoneIterator *it)
1705{ 1569{
1706 GNUNET_assert (NULL != it); 1570 struct GNUNET_NAMESTORE_Handle *h;
1707 struct PendingMessage *pe; 1571 struct PendingMessage *pe;
1708 size_t msg_size = 0; 1572 size_t msg_size;
1709 struct GNUNET_NAMESTORE_Handle *h = it->h; 1573 struct ZoneIterationStopMessage * msg;
1710 struct GNUNET_NAMESTORE_ZoneIterator *tmp = it->h->z_head;
1711
1712 while (tmp != NULL)
1713 {
1714 if (tmp == it)
1715 break;
1716 tmp = tmp->next;
1717 }
1718 GNUNET_assert (NULL != tmp);
1719 1574
1720 /* set msg_size*/ 1575 GNUNET_assert (NULL != it);
1576 h = it->h;
1577 GNUNET_CONTAINER_DLL_remove (h->z_head,
1578 h->z_tail,
1579 it);
1721 msg_size = sizeof (struct ZoneIterationStopMessage); 1580 msg_size = sizeof (struct ZoneIterationStopMessage);
1722 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); 1581 pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size);
1723
1724 /* create msg here */
1725 struct ZoneIterationStopMessage * msg;
1726 pe->size = msg_size; 1582 pe->size = msg_size;
1727 pe->is_init = GNUNET_NO; 1583 pe->is_init = GNUNET_NO;
1728 msg = (struct ZoneIterationStopMessage *) &pe[1]; 1584 msg = (struct ZoneIterationStopMessage *) &pe[1];
1729 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP); 1585 msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP);
1730 msg->gns_header.header.size = htons (msg_size); 1586 msg->gns_header.header.size = htons (msg_size);
1731 msg->gns_header.r_id = htonl (it->op_id); 1587 msg->gns_header.r_id = htonl (it->op_id);
1732
1733 if (GNUNET_YES == it->has_zone) 1588 if (GNUNET_YES == it->has_zone)
1734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_STOP", GNUNET_short_h2s(&it->zone)); 1589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1590 "Sending `%s' message for zone `%s'\n", "ZONE_ITERATION_STOP", GNUNET_short_h2s(&it->zone));
1735 else 1591 else
1736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for all zones\n", "ZONE_ITERATION_STOP"); 1592 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1737 1593 "Sending `%s' message for all zones\n", "ZONE_ITERATION_STOP");
1738 /* transmit message */
1739 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); 1594 GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe);
1740 do_transmit(h); 1595 do_transmit(h);
1596 GNUNET_free (it);
1741} 1597}
1742 1598
1743 1599
@@ -1752,7 +1608,7 @@ GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe)
1752{ 1608{
1753 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 1609 struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
1754 1610
1755 GNUNET_assert (qe != NULL); 1611 GNUNET_assert (NULL != qe);
1756 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); 1612 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
1757 GNUNET_free(qe); 1613 GNUNET_free(qe);
1758} 1614}