diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-04-08 23:11:14 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-04-08 23:11:14 +0000 |
commit | 9d34b3289c7c9dd1c888d605993a8b53fa905c11 (patch) | |
tree | d05c8b55d951219a1479fe01e0e0d108875610d7 /src/mesh | |
parent | 726f073f6c0fd2f5901a316ec747ee53b1655119 (diff) | |
download | gnunet-9d34b3289c7c9dd1c888d605993a8b53fa905c11.tar.gz gnunet-9d34b3289c7c9dd1c888d605993a8b53fa905c11.zip |
WiP (create tunnel)
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 115 |
1 files changed, 108 insertions, 7 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 079c5a1fa..0619dfdd6 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -410,8 +410,8 @@ static struct Client *clients_tail; | |||
410 | /** | 410 | /** |
411 | * All the tunnels | 411 | * All the tunnels |
412 | */ | 412 | */ |
413 | // static struct MESH_tunnel *tunnel_participation_head; | 413 | static struct MESH_tunnel *tunnels_head; |
414 | // static struct MESH_tunnel *tunnel_participation_tail; | 414 | static struct MESH_tunnel *tunnels_tail; |
415 | 415 | ||
416 | /** | 416 | /** |
417 | * All the paths (for future path optimization) | 417 | * All the paths (for future path optimization) |
@@ -524,7 +524,31 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
524 | static void | 524 | static void |
525 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | 525 | handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) |
526 | { | 526 | { |
527 | /* Remove client from list, delete all timers and queues associated */ | 527 | struct Client *c, *next; |
528 | struct MESH_tunnel *t; | ||
529 | |||
530 | /* If there are no clients registered, something is wrong... or is it? | ||
531 | * FIXME: what happens if a client connects, doesn't send a MESH_Connect | ||
532 | * and disconnects? Does the service get a disconnect notification anyway? | ||
533 | */ | ||
534 | GNUNET_assert(NULL != clients_head); | ||
535 | for (c = clients_head; c != clients_head; c = next) { | ||
536 | if (c->handle == client) { | ||
537 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); | ||
538 | while (NULL != (t = c->tunnels_head)) { | ||
539 | GNUNET_CONTAINER_DLL_remove (c->tunnels_head, c->tunnels_tail, t); | ||
540 | GNUNET_CONTAINER_DLL_remove (tunnels_head, tunnels_tail, t); | ||
541 | /* TODO free paths and other tunnel dynamic structures */ | ||
542 | GNUNET_free (t); | ||
543 | } | ||
544 | GNUNET_free (c->messages_subscribed); | ||
545 | next = c->next; | ||
546 | GNUNET_free (c); | ||
547 | } else { | ||
548 | next = c->next; | ||
549 | } | ||
550 | } | ||
551 | |||
528 | return; | 552 | return; |
529 | } | 553 | } |
530 | 554 | ||
@@ -546,7 +570,7 @@ handle_local_new_client (void *cls, | |||
546 | // struct GNUNET_MESH_Connect *connect_msg; | 570 | // struct GNUNET_MESH_Connect *connect_msg; |
547 | // | 571 | // |
548 | // connect_msg = (struct GNUNET_MESH_Connect *) message; | 572 | // connect_msg = (struct GNUNET_MESH_Connect *) message; |
549 | 573 | ||
550 | /* FIXME: is this a good idea? */ | 574 | /* FIXME: is this a good idea? */ |
551 | GNUNET_assert(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT == message->type); | 575 | GNUNET_assert(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT == message->type); |
552 | 576 | ||
@@ -578,7 +602,82 @@ handle_local_new_client (void *cls, | |||
578 | } | 602 | } |
579 | 603 | ||
580 | /** | 604 | /** |
581 | * Handler for connection requests | 605 | * Handler for requests of new tunnels |
606 | * | ||
607 | * @param cls closure | ||
608 | * @param client identification of the client | ||
609 | * @param message the actual message | ||
610 | */ | ||
611 | static void | ||
612 | handle_local_tunnel_create (void *cls, | ||
613 | struct GNUNET_SERVER_Client *client, | ||
614 | const struct GNUNET_MessageHeader *message) | ||
615 | { | ||
616 | struct Client *c; | ||
617 | struct GNUNET_MESH_TunnelMessage *tunnel_msg; | ||
618 | struct MESH_tunnel *t; | ||
619 | |||
620 | /* Sanity check for client registration */ | ||
621 | /* TODO: refactor into new function */ | ||
622 | for (c = clients_head; c != clients_head; c = c->next) { | ||
623 | if(c->handle == client) break; | ||
624 | } | ||
625 | if(c->handle != client) { /* Client hasn't registered, not a good thing */ | ||
626 | GNUNET_break(0); | ||
627 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
628 | return; | ||
629 | } | ||
630 | |||
631 | /* Message sanity check */ | ||
632 | /* FIXME: two different checks, to know why it fails? */ | ||
633 | if(sizeof(struct GNUNET_MESH_TunnelMessage) != message->size || | ||
634 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE != message->type) { | ||
635 | GNUNET_break(0); | ||
636 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
637 | return; | ||
638 | } | ||
639 | |||
640 | tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; | ||
641 | /* Sanity check for tunnel numbering */ | ||
642 | if(0 == (tunnel_msg->tunnel_id & 0x80000000)) { | ||
643 | GNUNET_break(0); | ||
644 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
645 | return; | ||
646 | } | ||
647 | /* Sanity check for duplicate tunnel IDs */ | ||
648 | for (t = tunnels_head; t != tunnels_head; t = t->next) { | ||
649 | /* TODO - maybe this is not enough, need to consider the whole | ||
650 | * local/global numbering system, but probably it's ok (WiP) | ||
651 | */ | ||
652 | if(t->tid == tunnel_msg->tunnel_id) { | ||
653 | GNUNET_break(0); | ||
654 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
655 | return; | ||
656 | } | ||
657 | } | ||
658 | //tunnel_msg->tunnel_id; | ||
659 | |||
660 | |||
661 | return; | ||
662 | } | ||
663 | |||
664 | /** | ||
665 | * Handler for requests of deleting tunnels | ||
666 | * | ||
667 | * @param cls closure | ||
668 | * @param client identification of the client | ||
669 | * @param message the actual message | ||
670 | */ | ||
671 | static void | ||
672 | handle_local_tunnel_destroy (void *cls, | ||
673 | struct GNUNET_SERVER_Client *client, | ||
674 | const struct GNUNET_MessageHeader *message) | ||
675 | { | ||
676 | return; | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * Handler for connection requests to new peers | ||
582 | * | 681 | * |
583 | * @param cls closure | 682 | * @param cls closure |
584 | * @param client identification of the client | 683 | * @param client identification of the client |
@@ -612,6 +711,10 @@ handle_local_network_traffic (void *cls, | |||
612 | */ | 711 | */ |
613 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | 712 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { |
614 | {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, | 713 | {&handle_local_new_client, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, |
714 | {&handle_local_tunnel_create, NULL, | ||
715 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 0}, | ||
716 | {&handle_local_tunnel_destroy, NULL, | ||
717 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, 0}, | ||
615 | {&handle_local_connect, NULL, | 718 | {&handle_local_connect, NULL, |
616 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, | 719 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, |
617 | {&handle_local_connect, NULL, | 720 | {&handle_local_connect, NULL, |
@@ -622,8 +725,6 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | |||
622 | {&handle_local_connect, NULL, | 725 | {&handle_local_connect, NULL, |
623 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, 0}, | 726 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, 0}, |
624 | {&handle_local_network_traffic, NULL, | 727 | {&handle_local_network_traffic, NULL, |
625 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_TRANSMIT_READY, 0}, | ||
626 | {&handle_local_network_traffic, NULL, | ||
627 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ | 728 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ |
628 | {&handle_local_network_traffic, NULL, | 729 | {&handle_local_network_traffic, NULL, |
629 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */ | 730 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */ |