diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-27 16:03:12 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-27 16:03:12 +0000 |
commit | 8139f58584f3094323241763469e2ea87ebf0488 (patch) | |
tree | 1444c12e55bea8aebd40f6ec360c00d2e17d68f5 /src/namestore/gnunet-service-namestore.c | |
parent | 1b4e1f7577f04263bb959874c5ddc1ef1a9f1769 (diff) | |
download | gnunet-8139f58584f3094323241763469e2ea87ebf0488.tar.gz gnunet-8139f58584f3094323241763469e2ea87ebf0488.zip |
- more communication
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 147 |
1 files changed, 145 insertions, 2 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 1700925de..7d9eb4801 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -437,6 +437,145 @@ static void handle_record_put (void *cls, | |||
437 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 437 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
438 | } | 438 | } |
439 | 439 | ||
440 | |||
441 | static void handle_record_create (void *cls, | ||
442 | struct GNUNET_SERVER_Client * client, | ||
443 | const struct GNUNET_MessageHeader * message) | ||
444 | { | ||
445 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_CREATE"); | ||
446 | struct GNUNET_NAMESTORE_Client *nc; | ||
447 | struct RecordCreateResponseMessage rcr_msg; | ||
448 | size_t name_len; | ||
449 | size_t msg_size; | ||
450 | size_t msg_size_exp; | ||
451 | uint32_t id = 0; | ||
452 | |||
453 | int res = GNUNET_SYSERR; | ||
454 | |||
455 | if (ntohs (message->size) < sizeof (struct RecordCreateMessage)) | ||
456 | { | ||
457 | GNUNET_break_op (0); | ||
458 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
459 | return; | ||
460 | } | ||
461 | |||
462 | nc = client_lookup(client); | ||
463 | if (nc == NULL) | ||
464 | { | ||
465 | GNUNET_break_op (0); | ||
466 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
467 | return; | ||
468 | } | ||
469 | |||
470 | struct RecordCreateMessage * rp_msg = (struct RecordCreateMessage *) message; | ||
471 | id = ntohl (rp_msg->op_id); | ||
472 | name_len = ntohs (rp_msg->name_len); | ||
473 | msg_size = ntohs (message->size); | ||
474 | msg_size_exp = sizeof (struct RecordCreateMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData); | ||
475 | |||
476 | if (msg_size != msg_size_exp) | ||
477 | { | ||
478 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size); | ||
479 | GNUNET_break_op (0); | ||
480 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
481 | return; | ||
482 | } | ||
483 | |||
484 | |||
485 | if ((name_len == 0) || (name_len > 256)) | ||
486 | { | ||
487 | GNUNET_break_op (0); | ||
488 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
489 | return; | ||
490 | } | ||
491 | |||
492 | /* DO WORK HERE */ | ||
493 | |||
494 | /* Send response */ | ||
495 | |||
496 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_CREATE_RESPONSE"); | ||
497 | rcr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE_RESPONSE); | ||
498 | rcr_msg.op_id = rp_msg->op_id; | ||
499 | rcr_msg.header.size = htons (sizeof (struct RecordCreateResponseMessage)); | ||
500 | if (GNUNET_OK == res) | ||
501 | rcr_msg.op_result = htons (GNUNET_OK); | ||
502 | else | ||
503 | rcr_msg.op_result = htons (GNUNET_NO); | ||
504 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rcr_msg, GNUNET_NO); | ||
505 | |||
506 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
507 | } | ||
508 | |||
509 | static void handle_record_remove (void *cls, | ||
510 | struct GNUNET_SERVER_Client * client, | ||
511 | const struct GNUNET_MessageHeader * message) | ||
512 | { | ||
513 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_RECORD_REMOVE"); | ||
514 | struct GNUNET_NAMESTORE_Client *nc; | ||
515 | struct RecordRemoveResponseMessage rrr_msg; | ||
516 | size_t name_len; | ||
517 | size_t msg_size; | ||
518 | size_t msg_size_exp; | ||
519 | uint32_t id = 0; | ||
520 | |||
521 | int res = GNUNET_SYSERR; | ||
522 | |||
523 | if (ntohs (message->size) < sizeof (struct RecordRemoveMessage)) | ||
524 | { | ||
525 | GNUNET_break_op (0); | ||
526 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
527 | return; | ||
528 | } | ||
529 | |||
530 | nc = client_lookup(client); | ||
531 | if (nc == NULL) | ||
532 | { | ||
533 | GNUNET_break_op (0); | ||
534 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
535 | return; | ||
536 | } | ||
537 | |||
538 | struct RecordRemoveMessage * rp_msg = (struct RecordRemoveMessage *) message; | ||
539 | id = ntohl (rp_msg->op_id); | ||
540 | name_len = ntohs (rp_msg->name_len); | ||
541 | msg_size = ntohs (message->size); | ||
542 | msg_size_exp = sizeof (struct RecordRemoveMessage) + name_len + sizeof (struct GNUNET_NAMESTORE_RecordData); | ||
543 | |||
544 | if (msg_size != msg_size_exp) | ||
545 | { | ||
546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expected message %u size but message size is %u \n", msg_size_exp, msg_size); | ||
547 | GNUNET_break_op (0); | ||
548 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
549 | return; | ||
550 | } | ||
551 | |||
552 | |||
553 | if ((name_len == 0) || (name_len > 256)) | ||
554 | { | ||
555 | GNUNET_break_op (0); | ||
556 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
557 | return; | ||
558 | } | ||
559 | |||
560 | /* DO WORK HERE */ | ||
561 | |||
562 | /* Send response */ | ||
563 | |||
564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "RECORD_REMOVE_RESPONSE"); | ||
565 | rrr_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE_RESPONSE); | ||
566 | rrr_msg.op_id = rp_msg->op_id; | ||
567 | rrr_msg.header.size = htons (sizeof (struct RecordRemoveResponseMessage)); | ||
568 | if (GNUNET_OK == res) | ||
569 | rrr_msg.op_result = htons (GNUNET_OK); | ||
570 | else | ||
571 | rrr_msg.op_result = htons (GNUNET_NO); | ||
572 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &rrr_msg, GNUNET_NO); | ||
573 | |||
574 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
575 | } | ||
576 | |||
577 | |||
578 | |||
440 | /** | 579 | /** |
441 | * Process template requests. | 580 | * Process template requests. |
442 | * | 581 | * |
@@ -457,8 +596,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
457 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, | 596 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, |
458 | {&handle_lookup_name, NULL, | 597 | {&handle_lookup_name, NULL, |
459 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, | 598 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, |
460 | {&handle_record_put, NULL, | 599 | {&handle_record_put, NULL, |
461 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0}, | 600 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_PUT, 0}, |
601 | {&handle_record_create, NULL, | ||
602 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_CREATE, 0}, | ||
603 | {&handle_record_remove, NULL, | ||
604 | GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_REMOVE, 0}, | ||
462 | {NULL, NULL, 0, 0} | 605 | {NULL, NULL, 0, 0} |
463 | }; | 606 | }; |
464 | 607 | ||