diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-04-18 22:29:05 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-04-18 22:29:05 +0000 |
commit | a70c061da5313f7011a81f815f8266ff6ee30657 (patch) | |
tree | c3d5f3330c5c9e364969e38cf509578f98dc9f70 /src/mesh | |
parent | d8b16564cca78061941fbe996c836e73a4c84626 (diff) | |
download | gnunet-a70c061da5313f7011a81f815f8266ff6ee30657.tar.gz gnunet-a70c061da5313f7011a81f815f8266ff6ee30657.zip |
WiP
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/Makefile.am | 1 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 144 |
2 files changed, 98 insertions, 47 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 26da9138c..4bb972f8c 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am | |||
@@ -30,5 +30,6 @@ gnunet_service_mesh_SOURCES = \ | |||
30 | 30 | ||
31 | gnunet_service_mesh_LDADD = \ | 31 | gnunet_service_mesh_LDADD = \ |
32 | $(top_builddir)/src/core/libgnunetcore.la\ | 32 | $(top_builddir)/src/core/libgnunetcore.la\ |
33 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
33 | $(top_builddir)/src/util/libgnunetutil.la | 34 | $(top_builddir)/src/util/libgnunetutil.la |
34 | 35 | ||
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index e119e6fc6..08d2ae216 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -45,8 +45,9 @@ | |||
45 | #include "gnunet_peer_lib.h" | 45 | #include "gnunet_peer_lib.h" |
46 | #include "gnunet_core_service.h" | 46 | #include "gnunet_core_service.h" |
47 | #include "gnunet_protocols.h" | 47 | #include "gnunet_protocols.h" |
48 | #include "mesh.h" | ||
49 | 48 | ||
49 | #include "mesh.h" | ||
50 | #include "gnunet_dht_service.h" | ||
50 | 51 | ||
51 | /******************************************************************************/ | 52 | /******************************************************************************/ |
52 | /******************** MESH NETWORK MESSAGES **************************/ | 53 | /******************** MESH NETWORK MESSAGES **************************/ |
@@ -431,20 +432,35 @@ struct Client | |||
431 | /** | 432 | /** |
432 | * All the clients | 433 | * All the clients |
433 | */ | 434 | */ |
434 | static struct Client *clients_head; | 435 | static struct Client *clients_head; |
435 | static struct Client *clients_tail; | 436 | static struct Client *clients_tail; |
436 | 437 | ||
437 | /** | 438 | /** |
438 | * All the tunnels | 439 | * All the tunnels |
439 | */ | 440 | */ |
440 | static struct MESH_tunnel *tunnels_head; | 441 | static struct MESH_tunnel *tunnels_head; |
441 | static struct MESH_tunnel *tunnels_tail; | 442 | static struct MESH_tunnel *tunnels_tail; |
442 | 443 | ||
443 | /** | 444 | /** |
444 | * All the paths (for future path optimization) | 445 | * All the paths (for future path optimization) |
445 | */ | 446 | */ |
446 | // static struct Path *paths_head; | 447 | // static struct Path *paths_head; |
447 | // static struct Path *paths_tail; | 448 | // static struct Path *paths_tail; |
449 | |||
450 | /** | ||
451 | * Handle to communicate with core | ||
452 | */ | ||
453 | static struct GNUNET_CORE_Handle *core_handle; | ||
454 | |||
455 | /** | ||
456 | * Handle to use DHT | ||
457 | */ | ||
458 | static struct GNUNET_DHT_Handle *dht_handle; | ||
459 | |||
460 | /** | ||
461 | * Local peer own ID (memory efficient handle) | ||
462 | */ | ||
463 | static GNUNET_PEER_Id myid; | ||
448 | 464 | ||
449 | /******************************************************************************/ | 465 | /******************************************************************************/ |
450 | /******************** MESH NETWORK HANDLERS **************************/ | 466 | /******************** MESH NETWORK HANDLERS **************************/ |
@@ -469,28 +485,6 @@ handle_mesh_path_create (void *cls, | |||
469 | const struct GNUNET_TRANSPORT_ATS_Information | 485 | const struct GNUNET_TRANSPORT_ATS_Information |
470 | *atsi) | 486 | *atsi) |
471 | { | 487 | { |
472 | /* | ||
473 | * EXAMPLE OF USING THE API | ||
474 | * NOT ACTUAL CODE!!!!! | ||
475 | */ | ||
476 | /*client *c; | ||
477 | tunnel *t; | ||
478 | |||
479 | t = new; | ||
480 | GNUNET_CONTAINER_DLL_insert (c->my_tunnels_head, | ||
481 | c->my_tunnels_tail, | ||
482 | t); | ||
483 | |||
484 | while (NULL != (t = c->my_tunnels_head)) | ||
485 | { | ||
486 | GNUNET_CONTAINER_DLL_remove (c->my_tunnels_head, | ||
487 | c->my_tunnels_tail, | ||
488 | t); | ||
489 | GNUNET_free (t); | ||
490 | } | ||
491 | */ | ||
492 | |||
493 | |||
494 | /* Extract path */ | 488 | /* Extract path */ |
495 | /* Find origin & self */ | 489 | /* Find origin & self */ |
496 | /* Search for origin in local tunnels */ | 490 | /* Search for origin in local tunnels */ |
@@ -542,17 +536,17 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
542 | /******************************************************************************/ | 536 | /******************************************************************************/ |
543 | 537 | ||
544 | /** | 538 | /** |
545 | * Client exisits | 539 | * Check if client has registered with the service and has not disconnected |
546 | * @param client the client to check | 540 | * @param client the client to check |
547 | * @return non-zero if client exists in the global DLL | 541 | * @return non-NULL if client exists in the global DLL |
548 | */ | 542 | */ |
549 | int | 543 | struct Client * |
550 | client_exists (struct GNUNET_SERVER_Client *client) { | 544 | client_retrieve (struct GNUNET_SERVER_Client *client) { |
551 | struct Client *c; | 545 | struct Client *c; |
552 | for (c = clients_head; c != clients_head; c = c->next) { | 546 | for (c = clients_head; c != clients_head; c = c->next) { |
553 | if(c->handle == client) return 1; | 547 | if(c->handle == client) return c; |
554 | } | 548 | } |
555 | return 0; | 549 | return NULL; |
556 | } | 550 | } |
557 | 551 | ||
558 | /** | 552 | /** |
@@ -651,7 +645,7 @@ handle_local_tunnel_create (void *cls, | |||
651 | struct MESH_tunnel *t; | 645 | struct MESH_tunnel *t; |
652 | 646 | ||
653 | /* Sanity check for client registration */ | 647 | /* Sanity check for client registration */ |
654 | if(!client_exists(client)) { | 648 | if(NULL == client_retrieve(client)) { |
655 | GNUNET_break(0); | 649 | GNUNET_break(0); |
656 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 650 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
657 | return; | 651 | return; |
@@ -682,7 +676,7 @@ handle_local_tunnel_create (void *cls, | |||
682 | /* FIXME: calloc? is NULL != 0 on any platform? */ | 676 | /* FIXME: calloc? is NULL != 0 on any platform? */ |
683 | t = GNUNET_malloc(sizeof(struct MESH_tunnel)); | 677 | t = GNUNET_malloc(sizeof(struct MESH_tunnel)); |
684 | t->tid = ntohl(tunnel_msg->tunnel_id); | 678 | t->tid = ntohl(tunnel_msg->tunnel_id); |
685 | /* FIXME: t->oid = selfid;*/ | 679 | t->oid = myid; |
686 | t->peers_ready = 0; | 680 | t->peers_ready = 0; |
687 | t->peers_total = 0; | 681 | t->peers_total = 0; |
688 | t->peers_head = NULL; | 682 | t->peers_head = NULL; |
@@ -710,12 +704,17 @@ handle_local_tunnel_destroy (void *cls, | |||
710 | struct GNUNET_SERVER_Client *client, | 704 | struct GNUNET_SERVER_Client *client, |
711 | const struct GNUNET_MessageHeader *message) | 705 | const struct GNUNET_MessageHeader *message) |
712 | { | 706 | { |
707 | struct GNUNET_MESH_TunnelMessage *tunnel_msg; | ||
708 | |||
713 | /* Sanity check for client registration */ | 709 | /* Sanity check for client registration */ |
714 | if(!client_exists(client)) { | 710 | if(NULL == client_retrieve(client)) { |
715 | GNUNET_break(0); | 711 | GNUNET_break(0); |
716 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 712 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
717 | return; | 713 | return; |
718 | } | 714 | } |
715 | tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; | ||
716 | |||
717 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
719 | return; | 718 | return; |
720 | } | 719 | } |
721 | 720 | ||
@@ -732,11 +731,12 @@ handle_local_connect_add (void *cls, | |||
732 | const struct GNUNET_MessageHeader *message) | 731 | const struct GNUNET_MessageHeader *message) |
733 | { | 732 | { |
734 | /* Sanity check for client registration */ | 733 | /* Sanity check for client registration */ |
735 | if(!client_exists(client)) { | 734 | if(NULL == client_retrieve(client)) { |
736 | GNUNET_break(0); | 735 | GNUNET_break(0); |
737 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 736 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
738 | return; | 737 | return; |
739 | } | 738 | } |
739 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
740 | return; | 740 | return; |
741 | } | 741 | } |
742 | 742 | ||
@@ -753,6 +753,13 @@ handle_local_connect_del (void *cls, | |||
753 | struct GNUNET_SERVER_Client *client, | 753 | struct GNUNET_SERVER_Client *client, |
754 | const struct GNUNET_MessageHeader *message) | 754 | const struct GNUNET_MessageHeader *message) |
755 | { | 755 | { |
756 | /* Sanity check for client registration */ | ||
757 | if(NULL == client_retrieve(client)) { | ||
758 | GNUNET_break(0); | ||
759 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
760 | return; | ||
761 | } | ||
762 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
756 | return; | 763 | return; |
757 | } | 764 | } |
758 | 765 | ||
@@ -769,12 +776,19 @@ handle_local_connect_by_type (void *cls, | |||
769 | struct GNUNET_SERVER_Client *client, | 776 | struct GNUNET_SERVER_Client *client, |
770 | const struct GNUNET_MessageHeader *message) | 777 | const struct GNUNET_MessageHeader *message) |
771 | { | 778 | { |
779 | /* Sanity check for client registration */ | ||
780 | if(NULL == client_retrieve(client)) { | ||
781 | GNUNET_break(0); | ||
782 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
783 | return; | ||
784 | } | ||
785 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
772 | return; | 786 | return; |
773 | } | 787 | } |
774 | 788 | ||
775 | 789 | ||
776 | /** | 790 | /** |
777 | * Handler for client traffic | 791 | * Handler for client traffic directed to one peer |
778 | * | 792 | * |
779 | * @param cls closure | 793 | * @param cls closure |
780 | * @param client identification of the client | 794 | * @param client identification of the client |
@@ -785,6 +799,35 @@ handle_local_network_traffic (void *cls, | |||
785 | struct GNUNET_SERVER_Client *client, | 799 | struct GNUNET_SERVER_Client *client, |
786 | const struct GNUNET_MessageHeader *message) | 800 | const struct GNUNET_MessageHeader *message) |
787 | { | 801 | { |
802 | /* Sanity check for client registration */ | ||
803 | if(NULL == client_retrieve(client)) { | ||
804 | GNUNET_break(0); | ||
805 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
806 | return; | ||
807 | } | ||
808 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
809 | return; | ||
810 | } | ||
811 | |||
812 | /** | ||
813 | * Handler for client traffic directed to all peers in a tunnel | ||
814 | * | ||
815 | * @param cls closure | ||
816 | * @param client identification of the client | ||
817 | * @param message the actual message | ||
818 | */ | ||
819 | static void | ||
820 | handle_local_network_traffic_bcast (void *cls, | ||
821 | struct GNUNET_SERVER_Client *client, | ||
822 | const struct GNUNET_MessageHeader *message) | ||
823 | { | ||
824 | /* Sanity check for client registration */ | ||
825 | if(NULL == client_retrieve(client)) { | ||
826 | GNUNET_break(0); | ||
827 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
828 | return; | ||
829 | } | ||
830 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | ||
788 | return; | 831 | return; |
789 | } | 832 | } |
790 | 833 | ||
@@ -805,9 +848,9 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | |||
805 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, | 848 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, |
806 | sizeof(struct GNUNET_MESH_ConnectPeerByType)}, | 849 | sizeof(struct GNUNET_MESH_ConnectPeerByType)}, |
807 | {&handle_local_network_traffic, NULL, | 850 | {&handle_local_network_traffic, NULL, |
808 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ | 851 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, |
809 | {&handle_local_network_traffic, NULL, | 852 | {&handle_local_network_traffic_bcast, NULL, |
810 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST, 0}, /* FIXME needed? */ | 853 | GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA_BROADCAST, 0}, |
811 | {NULL, NULL, 0, 0} | 854 | {NULL, NULL, 0, 0} |
812 | }; | 855 | }; |
813 | 856 | ||
@@ -826,6 +869,8 @@ core_init (void *cls, | |||
826 | const struct GNUNET_PeerIdentity *identity, | 869 | const struct GNUNET_PeerIdentity *identity, |
827 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 870 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
828 | { | 871 | { |
872 | core_handle = server; | ||
873 | myid = GNUNET_PEER_intern(identity); | ||
829 | return; | 874 | return; |
830 | } | 875 | } |
831 | 876 | ||
@@ -874,11 +919,10 @@ run (void *cls, | |||
874 | struct GNUNET_SERVER_Handle *server, | 919 | struct GNUNET_SERVER_Handle *server, |
875 | const struct GNUNET_CONFIGURATION_Handle *c) | 920 | const struct GNUNET_CONFIGURATION_Handle *c) |
876 | { | 921 | { |
877 | struct GNUNET_CORE_Handle *core; | ||
878 | 922 | ||
879 | GNUNET_SERVER_add_handlers (server, plugin_handlers); | 923 | GNUNET_SERVER_add_handlers (server, plugin_handlers); |
880 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 924 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
881 | core = GNUNET_CORE_connect (c, /* Main configuration */ | 925 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ |
882 | 32, /* queue size */ | 926 | 32, /* queue size */ |
883 | NULL, /* Closure passed to MESH functions */ | 927 | NULL, /* Closure passed to MESH functions */ |
884 | &core_init, /* Call core_init once connected */ | 928 | &core_init, /* Call core_init once connected */ |
@@ -891,8 +935,14 @@ run (void *cls, | |||
891 | GNUNET_NO, /* For header-only out notification */ | 935 | GNUNET_NO, /* For header-only out notification */ |
892 | core_handlers); /* Register these handlers */ | 936 | core_handlers); /* Register these handlers */ |
893 | 937 | ||
894 | if (core == NULL) | 938 | if (core_handle == NULL) { |
895 | return; | 939 | GNUNET_break(0); |
940 | } | ||
941 | |||
942 | dht_handle = GNUNET_DHT_connect(c, 100); /* FIXME ht len correct size? */ | ||
943 | if (dht_handle == NULL) { | ||
944 | GNUNET_break(0); | ||
945 | } | ||
896 | } | 946 | } |
897 | 947 | ||
898 | /** | 948 | /** |