diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-04-18 10:52:49 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-04-18 10:52:49 +0000 |
commit | faf6fc865e0964435b0079278c35c9d397d614f0 (patch) | |
tree | 061a9ff56abc8d9707cbc9933cb432cd561ba72b /src/mesh | |
parent | d07b918c8cbbd2fb3a3fcbfc3366fd85734ddfe8 (diff) | |
download | gnunet-faf6fc865e0964435b0079278c35c9d397d614f0.tar.gz gnunet-faf6fc865e0964435b0079278c35c9d397d614f0.zip |
WiP
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 84 |
1 files changed, 68 insertions, 16 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 1bc740512..e119e6fc6 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -542,6 +542,20 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
542 | /******************************************************************************/ | 542 | /******************************************************************************/ |
543 | 543 | ||
544 | /** | 544 | /** |
545 | * Client exisits | ||
546 | * @param client the client to check | ||
547 | * @return non-zero if client exists in the global DLL | ||
548 | */ | ||
549 | int | ||
550 | client_exists (struct GNUNET_SERVER_Client *client) { | ||
551 | struct Client *c; | ||
552 | for (c = clients_head; c != clients_head; c = c->next) { | ||
553 | if(c->handle == client) return 1; | ||
554 | } | ||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | /** | ||
545 | * Handler for client disconnection | 559 | * Handler for client disconnection |
546 | * | 560 | * |
547 | * @param cls closure | 561 | * @param cls closure |
@@ -633,16 +647,11 @@ handle_local_tunnel_create (void *cls, | |||
633 | struct GNUNET_SERVER_Client *client, | 647 | struct GNUNET_SERVER_Client *client, |
634 | const struct GNUNET_MessageHeader *message) | 648 | const struct GNUNET_MessageHeader *message) |
635 | { | 649 | { |
636 | struct Client *c; | ||
637 | struct GNUNET_MESH_TunnelMessage *tunnel_msg; | 650 | struct GNUNET_MESH_TunnelMessage *tunnel_msg; |
638 | struct MESH_tunnel *t; | 651 | struct MESH_tunnel *t; |
639 | 652 | ||
640 | /* Sanity check for client registration */ | 653 | /* Sanity check for client registration */ |
641 | /* TODO: refactor into new function */ | 654 | if(!client_exists(client)) { |
642 | for (c = clients_head; c != clients_head; c = c->next) { | ||
643 | if(c->handle == client) break; | ||
644 | } | ||
645 | if(c->handle != client) { /* Client hasn't registered, not a good thing */ | ||
646 | GNUNET_break(0); | 655 | GNUNET_break(0); |
647 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 656 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
648 | return; | 657 | return; |
@@ -684,7 +693,7 @@ handle_local_tunnel_create (void *cls, | |||
684 | t->in_tail = NULL; | 693 | t->in_tail = NULL; |
685 | t->out_head = NULL; | 694 | t->out_head = NULL; |
686 | t->out_tail = NULL; | 695 | t->out_tail = NULL; |
687 | 696 | ||
688 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 697 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
689 | return; | 698 | return; |
690 | } | 699 | } |
@@ -701,6 +710,12 @@ handle_local_tunnel_destroy (void *cls, | |||
701 | struct GNUNET_SERVER_Client *client, | 710 | struct GNUNET_SERVER_Client *client, |
702 | const struct GNUNET_MessageHeader *message) | 711 | const struct GNUNET_MessageHeader *message) |
703 | { | 712 | { |
713 | /* Sanity check for client registration */ | ||
714 | if(!client_exists(client)) { | ||
715 | GNUNET_break(0); | ||
716 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
717 | return; | ||
718 | } | ||
704 | return; | 719 | return; |
705 | } | 720 | } |
706 | 721 | ||
@@ -709,16 +724,55 @@ handle_local_tunnel_destroy (void *cls, | |||
709 | * | 724 | * |
710 | * @param cls closure | 725 | * @param cls closure |
711 | * @param client identification of the client | 726 | * @param client identification of the client |
712 | * @param message the actual message | 727 | * @param message the actual message (PeerControl) |
713 | */ | 728 | */ |
714 | static void | 729 | static void |
715 | handle_local_connect (void *cls, | 730 | handle_local_connect_add (void *cls, |
716 | struct GNUNET_SERVER_Client *client, | 731 | struct GNUNET_SERVER_Client *client, |
717 | const struct GNUNET_MessageHeader *message) | 732 | const struct GNUNET_MessageHeader *message) |
718 | { | 733 | { |
734 | /* Sanity check for client registration */ | ||
735 | if(!client_exists(client)) { | ||
736 | GNUNET_break(0); | ||
737 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
738 | return; | ||
739 | } | ||
719 | return; | 740 | return; |
720 | } | 741 | } |
721 | 742 | ||
743 | |||
744 | /** | ||
745 | * Handler for disconnection requests of peers in a tunnel | ||
746 | * | ||
747 | * @param cls closure | ||
748 | * @param client identification of the client | ||
749 | * @param message the actual message (PeerControl) | ||
750 | */ | ||
751 | static void | ||
752 | handle_local_connect_del (void *cls, | ||
753 | struct GNUNET_SERVER_Client *client, | ||
754 | const struct GNUNET_MessageHeader *message) | ||
755 | { | ||
756 | return; | ||
757 | } | ||
758 | |||
759 | |||
760 | /** | ||
761 | * Handler for connection requests to new peers by type | ||
762 | * | ||
763 | * @param cls closure | ||
764 | * @param client identification of the client | ||
765 | * @param message the actual message (ConnectPeerByType) | ||
766 | */ | ||
767 | static void | ||
768 | handle_local_connect_by_type (void *cls, | ||
769 | struct GNUNET_SERVER_Client *client, | ||
770 | const struct GNUNET_MessageHeader *message) | ||
771 | { | ||
772 | return; | ||
773 | } | ||
774 | |||
775 | |||
722 | /** | 776 | /** |
723 | * Handler for client traffic | 777 | * Handler for client traffic |
724 | * | 778 | * |
@@ -743,15 +797,13 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | |||
743 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 0}, | 797 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 0}, |
744 | {&handle_local_tunnel_destroy, NULL, | 798 | {&handle_local_tunnel_destroy, NULL, |
745 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, 0}, | 799 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, 0}, |
746 | {&handle_local_connect, NULL, | 800 | {&handle_local_connect_add, NULL, |
747 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, | 801 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, |
748 | {&handle_local_connect, NULL, | 802 | {&handle_local_connect_del, NULL, |
749 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, | 803 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, |
750 | {&handle_local_connect, NULL, | 804 | {&handle_local_connect_by_type, NULL, |
751 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, | 805 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, |
752 | sizeof(struct GNUNET_MESH_ConnectPeerByType)}, | 806 | sizeof(struct GNUNET_MESH_ConnectPeerByType)}, |
753 | {&handle_local_connect, NULL, | ||
754 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, 0}, | ||
755 | {&handle_local_network_traffic, NULL, | 807 | {&handle_local_network_traffic, NULL, |
756 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ | 808 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ |
757 | {&handle_local_network_traffic, NULL, | 809 | {&handle_local_network_traffic, NULL, |