aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_peer.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2016-10-29 23:46:44 +0000
committerBart Polot <bart@net.in.tum.de>2016-10-29 23:46:44 +0000
commitf7f26f6ca1b76d2734463d4989b9541df48a6773 (patch)
treeefcbc1e51bbe162577b981dd3e601aec81a348a8 /src/cadet/gnunet-service-cadet_peer.c
parenta3735db333033ccefc95c56148ec3118bf7a0ccd (diff)
downloadgnunet-f7f26f6ca1b76d2734463d4989b9541df48a6773.tar.gz
gnunet-f7f26f6ca1b76d2734463d4989b9541df48a6773.zip
Refactor encrypted traffic handling
- eliminate encapsulation for KX/DATA - simplify cases - remove dead code - Organize message types
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.c')
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c86
1 files changed, 30 insertions, 56 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index da9b1bbe1..c312d56bf 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -548,32 +548,6 @@ handle_poll (void *cls, const struct GNUNET_CADET_Poll *msg)
548 548
549 549
550/** 550/**
551 * Check if the Key eXchange message has the appropriate size.
552 *
553 * @param cls Closure (unused).
554 * @param msg Message to check.
555 *
556 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
557 */
558static int
559check_kx (void *cls, const struct GNUNET_CADET_KX *msg)
560{
561 uint16_t size;
562 uint16_t expected_size;
563
564 size = ntohs (msg->header.size);
565 expected_size = sizeof (struct GNUNET_CADET_KX)
566 + sizeof (struct GNUNET_MessageHeader);
567
568 if (size < expected_size)
569 {
570 GNUNET_break_op (0);
571 return GNUNET_NO;
572 }
573 return GNUNET_YES;
574}
575
576/**
577 * Handle for #GNUNET_MESSAGE_TYPE_CADET_KX 551 * Handle for #GNUNET_MESSAGE_TYPE_CADET_KX
578 * 552 *
579 * @param cls Closure (CadetPeer for neighbor that sent the message). 553 * @param cls Closure (CadetPeer for neighbor that sent the message).
@@ -596,13 +570,13 @@ handle_kx (void *cls, const struct GNUNET_CADET_KX *msg)
596 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise. 570 * @return #GNUNET_YES if size is correct, #GNUNET_NO otherwise.
597 */ 571 */
598static int 572static int
599check_encrypted (void *cls, const struct GNUNET_CADET_AX *msg) 573check_encrypted (void *cls, const struct GNUNET_CADET_Encrypted *msg)
600{ 574{
601 uint16_t size; 575 uint16_t size;
602 uint16_t minimum_size; 576 uint16_t minimum_size;
603 577
604 size = ntohs (msg->header.size); 578 size = ntohs (msg->header.size);
605 minimum_size = sizeof (struct GNUNET_CADET_AX) 579 minimum_size = sizeof (struct GNUNET_CADET_Encrypted)
606 + sizeof (struct GNUNET_MessageHeader); 580 + sizeof (struct GNUNET_MessageHeader);
607 581
608 if (size < minimum_size) 582 if (size < minimum_size)
@@ -614,13 +588,13 @@ check_encrypted (void *cls, const struct GNUNET_CADET_AX *msg)
614} 588}
615 589
616/** 590/**
617 * Handle for #GNUNET_MESSAGE_TYPE_CADET_AX (AXolotl encrypted traffic). 591 * Handle for #GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED.
618 * 592 *
619 * @param cls Closure (CadetPeer for neighbor that sent the message). 593 * @param cls Closure (CadetPeer for neighbor that sent the message).
620 * @param msg Message itself. 594 * @param msg Message itself.
621 */ 595 */
622static void 596static void
623handle_encrypted (void *cls, const struct GNUNET_CADET_AX *msg) 597handle_encrypted (void *cls, const struct GNUNET_CADET_Encrypted *msg)
624{ 598{
625 struct CadetPeer *peer = cls; 599 struct CadetPeer *peer = cls;
626 GCC_handle_encrypted (peer, msg); 600 GCC_handle_encrypted (peer, msg);
@@ -643,37 +617,37 @@ connect_to_core (const struct GNUNET_CONFIGURATION_Handle *c)
643{ 617{
644 struct GNUNET_MQ_MessageHandler core_handlers[] = { 618 struct GNUNET_MQ_MessageHandler core_handlers[] = {
645 GNUNET_MQ_hd_var_size (create, 619 GNUNET_MQ_hd_var_size (create,
646 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE, 620 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE,
647 struct GNUNET_CADET_ConnectionCreate, 621 struct GNUNET_CADET_ConnectionCreate,
648 NULL), 622 NULL),
649 GNUNET_MQ_hd_fixed_size (confirm, 623 GNUNET_MQ_hd_fixed_size (confirm,
650 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK, 624 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK,
651 struct GNUNET_CADET_ConnectionACK, 625 struct GNUNET_CADET_ConnectionACK,
652 NULL), 626 NULL),
653 GNUNET_MQ_hd_fixed_size (broken, 627 GNUNET_MQ_hd_fixed_size (broken,
654 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN, 628 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
655 struct GNUNET_CADET_ConnectionBroken, 629 struct GNUNET_CADET_ConnectionBroken,
656 NULL), 630 NULL),
657 GNUNET_MQ_hd_fixed_size (destroy, 631 GNUNET_MQ_hd_fixed_size (destroy,
658 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY, 632 GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY,
659 struct GNUNET_CADET_ConnectionDestroy, 633 struct GNUNET_CADET_ConnectionDestroy,
660 NULL), 634 NULL),
661 GNUNET_MQ_hd_fixed_size (ack, 635 GNUNET_MQ_hd_fixed_size (ack,
662 GNUNET_MESSAGE_TYPE_CADET_ACK, 636 GNUNET_MESSAGE_TYPE_CADET_ACK,
663 struct GNUNET_CADET_ACK, 637 struct GNUNET_CADET_ACK,
664 NULL), 638 NULL),
665 GNUNET_MQ_hd_fixed_size (poll, 639 GNUNET_MQ_hd_fixed_size (poll,
666 GNUNET_MESSAGE_TYPE_CADET_POLL, 640 GNUNET_MESSAGE_TYPE_CADET_POLL,
667 struct GNUNET_CADET_Poll, 641 struct GNUNET_CADET_Poll,
668 NULL), 642 NULL),
669 GNUNET_MQ_hd_var_size (kx, 643 GNUNET_MQ_hd_fixed_size (kx,
670 GNUNET_MESSAGE_TYPE_CADET_KX, 644 GNUNET_MESSAGE_TYPE_CADET_KX,
671 struct GNUNET_CADET_KX, 645 struct GNUNET_CADET_KX,
672 NULL), 646 NULL),
673 GNUNET_MQ_hd_var_size (encrypted, 647 GNUNET_MQ_hd_var_size (encrypted,
674 GNUNET_MESSAGE_TYPE_CADET_AX, 648 GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED,
675 struct GNUNET_CADET_AX, 649 struct GNUNET_CADET_Encrypted,
676 NULL), 650 NULL),
677 GNUNET_MQ_handler_end () 651 GNUNET_MQ_handler_end ()
678 }; 652 };
679 core_handle = GNUNET_CORE_connecT (c, NULL, 653 core_handle = GNUNET_CORE_connecT (c, NULL,
@@ -755,7 +729,7 @@ get_priority (struct CadetPeerQueue *q)
755 } 729 }
756 730
757 /* Bulky payload has lower priority, control traffic has higher. */ 731 /* Bulky payload has lower priority, control traffic has higher. */
758 if (GNUNET_MESSAGE_TYPE_CADET_AX == q->type) 732 if (GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED == q->type)
759 return low; 733 return low;
760 return high; 734 return high;
761} 735}