diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pt/Makefile.am | 1 | ||||
-rw-r--r-- | src/pt/gnunet-daemon-pt.c | 239 |
2 files changed, 154 insertions, 86 deletions
diff --git a/src/pt/Makefile.am b/src/pt/Makefile.am index 19c8e527b..19c331c22 100644 --- a/src/pt/Makefile.am +++ b/src/pt/Makefile.am | |||
@@ -25,6 +25,7 @@ gnunet_daemon_pt_SOURCES = \ | |||
25 | gnunet_daemon_pt_LDADD = \ | 25 | gnunet_daemon_pt_LDADD = \ |
26 | $(top_builddir)/src/vpn/libgnunetvpn.la \ | 26 | $(top_builddir)/src/vpn/libgnunetvpn.la \ |
27 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | 27 | $(top_builddir)/src/mesh/libgnunetmesh.la \ |
28 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
28 | $(top_builddir)/src/dns/libgnunetdns.la \ | 29 | $(top_builddir)/src/dns/libgnunetdns.la \ |
29 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ | 30 | $(top_builddir)/src/dns/libgnunetdnsparser.la \ |
30 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 31 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c index dc7eef061..14f6e0885 100644 --- a/src/pt/gnunet-daemon-pt.c +++ b/src/pt/gnunet-daemon-pt.c | |||
@@ -29,9 +29,11 @@ | |||
29 | #include "gnunet_dnsparser_lib.h" | 29 | #include "gnunet_dnsparser_lib.h" |
30 | #include "gnunet_mesh_service.h" | 30 | #include "gnunet_mesh_service.h" |
31 | #include "gnunet_tun_lib.h" | 31 | #include "gnunet_tun_lib.h" |
32 | #include "gnunet_dht_service.h" | ||
32 | #include "gnunet_vpn_service.h" | 33 | #include "gnunet_vpn_service.h" |
33 | #include "gnunet_statistics_service.h" | 34 | #include "gnunet_statistics_service.h" |
34 | #include "gnunet_applications.h" | 35 | #include "gnunet_applications.h" |
36 | #include "block_dns.h" | ||
35 | 37 | ||
36 | #define PORT_PT 4242 // FIXME | 38 | #define PORT_PT 4242 // FIXME |
37 | 39 | ||
@@ -56,27 +58,27 @@ | |||
56 | * Which group of DNS records are we currently processing? | 58 | * Which group of DNS records are we currently processing? |
57 | */ | 59 | */ |
58 | enum RequestGroup | 60 | enum RequestGroup |
59 | { | 61 | { |
60 | /** | 62 | /** |
61 | * DNS answers | 63 | * DNS answers |
62 | */ | 64 | */ |
63 | ANSWERS = 0, | 65 | ANSWERS = 0, |
64 | 66 | ||
65 | /** | 67 | /** |
66 | * DNS authority records | 68 | * DNS authority records |
67 | */ | 69 | */ |
68 | AUTHORITY_RECORDS = 1, | 70 | AUTHORITY_RECORDS = 1, |
69 | 71 | ||
70 | /** | 72 | /** |
71 | * DNS additional records | 73 | * DNS additional records |
72 | */ | 74 | */ |
73 | ADDITIONAL_RECORDS = 2, | 75 | ADDITIONAL_RECORDS = 2, |
74 | 76 | ||
75 | /** | 77 | /** |
76 | * We're done processing. | 78 | * We're done processing. |
77 | */ | 79 | */ |
78 | END = 3 | 80 | END = 3 |
79 | }; | 81 | }; |
80 | 82 | ||
81 | 83 | ||
82 | /** | 84 | /** |
@@ -154,8 +156,8 @@ struct RequestContext | |||
154 | uint16_t dns_id; | 156 | uint16_t dns_id; |
155 | 157 | ||
156 | /** | 158 | /** |
157 | * GNUNET_NO if this request is still in the transmit_queue, | 159 | * #GNUNET_NO if this request is still in the transmit_queue, |
158 | * GNUNET_YES if we are in the receive_queue. | 160 | * #GNUNET_YES if we are in the receive_queue. |
159 | */ | 161 | */ |
160 | int16_t was_transmitted; | 162 | int16_t was_transmitted; |
161 | 163 | ||
@@ -179,6 +181,8 @@ static struct GNUNET_MESH_Handle *mesh_handle; | |||
179 | 181 | ||
180 | /** | 182 | /** |
181 | * Tunnel we use for DNS requests over MESH. | 183 | * Tunnel we use for DNS requests over MESH. |
184 | * FIXME: we might want to keep multiple tunnels open | ||
185 | * at all times... | ||
182 | */ | 186 | */ |
183 | static struct GNUNET_MESH_Tunnel *mesh_tunnel; | 187 | static struct GNUNET_MESH_Tunnel *mesh_tunnel; |
184 | 188 | ||
@@ -223,6 +227,16 @@ static struct GNUNET_DNS_Handle *dns_post_handle; | |||
223 | static struct GNUNET_DNS_Handle *dns_pre_handle; | 227 | static struct GNUNET_DNS_Handle *dns_pre_handle; |
224 | 228 | ||
225 | /** | 229 | /** |
230 | * Handle to access the DHT. | ||
231 | */ | ||
232 | static struct GNUNET_DHT_Handle *dht; | ||
233 | |||
234 | /** | ||
235 | * Our DHT GET operation to find DNS exits. | ||
236 | */ | ||
237 | static struct GNUNET_DHT_GetHandle *dht_get; | ||
238 | |||
239 | /** | ||
226 | * Are we doing IPv4-pt? | 240 | * Are we doing IPv4-pt? |
227 | */ | 241 | */ |
228 | static int ipv4_pt; | 242 | static int ipv4_pt; |
@@ -519,7 +533,7 @@ dns_post_request_handler (void *cls, | |||
519 | GNUNET_DNSPARSER_free_packet (dns); | 533 | GNUNET_DNSPARSER_free_packet (dns); |
520 | return; | 534 | return; |
521 | } | 535 | } |
522 | rc = GNUNET_malloc (sizeof (struct ReplyContext)); | 536 | rc = GNUNET_new (struct ReplyContext); |
523 | rc->rh = rh; | 537 | rc->rh = rh; |
524 | rc->dns = dns; | 538 | rc->dns = dns; |
525 | rc->offset = 0; | 539 | rc->offset = 0; |
@@ -769,62 +783,18 @@ abort_all_requests () | |||
769 | 783 | ||
770 | 784 | ||
771 | /** | 785 | /** |
772 | * Method called whenever a peer has disconnected from the tunnel. | ||
773 | * | ||
774 | * FIXME merge with inbound cleaner | ||
775 | * | ||
776 | * @param cls closure | ||
777 | * @param peer peer identity the tunnel stopped working with | ||
778 | */ | ||
779 | void | ||
780 | mesh_disconnect_handler (void *cls, | ||
781 | const struct | ||
782 | GNUNET_PeerIdentity * peer) | ||
783 | { | ||
784 | GNUNET_assert (dns_exit_available > 0); | ||
785 | dns_exit_available--; | ||
786 | if (0 == dns_exit_available) | ||
787 | { | ||
788 | if (NULL != mesh_th) | ||
789 | { | ||
790 | GNUNET_MESH_notify_transmit_ready_cancel (mesh_th); | ||
791 | mesh_th = NULL; | ||
792 | } | ||
793 | abort_all_requests (); | ||
794 | } | ||
795 | } | ||
796 | |||
797 | |||
798 | /** | ||
799 | * Method called whenever a peer has connected to the tunnel. | ||
800 | * | ||
801 | * FIXME find anouther way (in tmt_ready_callback ?) | ||
802 | * | ||
803 | * @param cls closure | ||
804 | * @param peer peer identity the tunnel was created to, NULL on timeout | ||
805 | * @param atsi performance data for the connection | ||
806 | */ | ||
807 | void | ||
808 | mesh_connect_handler (void *cls, | ||
809 | const struct GNUNET_PeerIdentity | ||
810 | * peer, | ||
811 | const struct | ||
812 | GNUNET_ATS_Information * atsi) | ||
813 | { | ||
814 | dns_exit_available++; | ||
815 | } | ||
816 | |||
817 | |||
818 | /** | ||
819 | * Function scheduled as very last function, cleans up after us | 786 | * Function scheduled as very last function, cleans up after us |
787 | * | ||
788 | * @param cls closure, NULL | ||
789 | * @param tskctx scheduler context, unused | ||
820 | */ | 790 | */ |
821 | static void | 791 | static void |
822 | cleanup (void *cls GNUNET_UNUSED, | 792 | cleanup (void *cls, |
823 | const struct GNUNET_SCHEDULER_TaskContext *tskctx) | 793 | const struct GNUNET_SCHEDULER_TaskContext *tskctx) |
824 | { | 794 | { |
825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
826 | "Protocol translation daemon is shutting down now\n"); | 796 | "Protocol translation daemon is shutting down now\n"); |
827 | if (vpn_handle != NULL) | 797 | if (NULL != vpn_handle) |
828 | { | 798 | { |
829 | GNUNET_VPN_disconnect (vpn_handle); | 799 | GNUNET_VPN_disconnect (vpn_handle); |
830 | vpn_handle = NULL; | 800 | vpn_handle = NULL; |
@@ -839,27 +809,112 @@ cleanup (void *cls GNUNET_UNUSED, | |||
839 | GNUNET_MESH_tunnel_destroy (mesh_tunnel); | 809 | GNUNET_MESH_tunnel_destroy (mesh_tunnel); |
840 | mesh_tunnel = NULL; | 810 | mesh_tunnel = NULL; |
841 | } | 811 | } |
842 | if (mesh_handle != NULL) | 812 | if (NULL != mesh_handle) |
843 | { | 813 | { |
844 | GNUNET_MESH_disconnect (mesh_handle); | 814 | GNUNET_MESH_disconnect (mesh_handle); |
845 | mesh_handle = NULL; | 815 | mesh_handle = NULL; |
846 | } | 816 | } |
847 | abort_all_requests (); | 817 | abort_all_requests (); |
848 | if (dns_post_handle != NULL) | 818 | if (NULL != dns_post_handle) |
849 | { | 819 | { |
850 | GNUNET_DNS_disconnect (dns_post_handle); | 820 | GNUNET_DNS_disconnect (dns_post_handle); |
851 | dns_post_handle = NULL; | 821 | dns_post_handle = NULL; |
852 | } | 822 | } |
853 | if (dns_pre_handle != NULL) | 823 | if (NULL != dns_pre_handle) |
854 | { | 824 | { |
855 | GNUNET_DNS_disconnect (dns_pre_handle); | 825 | GNUNET_DNS_disconnect (dns_pre_handle); |
856 | dns_pre_handle = NULL; | 826 | dns_pre_handle = NULL; |
857 | } | 827 | } |
858 | if (stats != NULL) | 828 | if (NULL != stats) |
859 | { | 829 | { |
860 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); | 830 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); |
861 | stats = NULL; | 831 | stats = NULL; |
862 | } | 832 | } |
833 | if (NULL != dht_get) | ||
834 | { | ||
835 | GNUNET_DHT_get_stop (dht_get); | ||
836 | dht_get = NULL; | ||
837 | } | ||
838 | if (NULL != dht) | ||
839 | { | ||
840 | GNUNET_DHT_disconnect (dht); | ||
841 | dht = NULL; | ||
842 | } | ||
843 | } | ||
844 | |||
845 | |||
846 | |||
847 | /** | ||
848 | * Function called whenever a tunnel is destroyed. Should clean up | ||
849 | * the associated state and attempt to build a new one. | ||
850 | * | ||
851 | * It must NOT call #GNUNET_MESH_tunnel_destroy on the tunnel. | ||
852 | * | ||
853 | * @param cls closure (set from #GNUNET_MESH_connect) | ||
854 | * @param tunnel connection to the other end (henceforth invalid) | ||
855 | * @param tunnel_ctx place where local state associated | ||
856 | * with the tunnel is stored | ||
857 | */ | ||
858 | static void | ||
859 | mesh_tunnel_end_cb (void *cls, | ||
860 | const struct GNUNET_MESH_Tunnel *tunnel, | ||
861 | void *tunnel_ctx) | ||
862 | { | ||
863 | // FIXME: do cleanup here! | ||
864 | } | ||
865 | |||
866 | |||
867 | /** | ||
868 | * Function called whenever we find an advertisement for a | ||
869 | * DNS exit in the DHT. If we don't have a mesh tunnel, | ||
870 | * we should build one; otherwise, we should save the | ||
871 | * advertisement for later use. | ||
872 | * | ||
873 | * @param cls closure | ||
874 | * @param exp when will this value expire | ||
875 | * @param key key of the result | ||
876 | * @param get_path peers on reply path (or NULL if not recorded) | ||
877 | * [0] = datastore's first neighbor, [length - 1] = local peer | ||
878 | * @param get_path_length number of entries in @a get_path | ||
879 | * @param put_path peers on the PUT path (or NULL if not recorded) | ||
880 | * [0] = origin, [length - 1] = datastore | ||
881 | * @param put_path_length number of entries in @a put_path | ||
882 | * @param type type of the result | ||
883 | * @param size number of bytes in @a data | ||
884 | * @param data pointer to the result data | ||
885 | */ | ||
886 | static void | ||
887 | handle_dht_result (void *cls, | ||
888 | struct GNUNET_TIME_Absolute exp, | ||
889 | const struct GNUNET_HashCode *key, | ||
890 | const struct GNUNET_PeerIdentity *get_path, | ||
891 | unsigned int get_path_length, | ||
892 | const struct GNUNET_PeerIdentity *put_path, | ||
893 | unsigned int put_path_length, | ||
894 | enum GNUNET_BLOCK_Type type, | ||
895 | size_t size, const void *data) | ||
896 | { | ||
897 | const struct GNUNET_DNS_Advertisement *ad; | ||
898 | struct GNUNET_PeerIdentity pid; | ||
899 | |||
900 | if (sizeof (struct GNUNET_DNS_Advertisement) != size) | ||
901 | { | ||
902 | GNUNET_break (0); | ||
903 | return; | ||
904 | } | ||
905 | ad = data; | ||
906 | GNUNET_CRYPTO_hash (&ad->peer, | ||
907 | sizeof (struct GNUNET_CRYPTO_EccPublicSignKey), | ||
908 | &pid.hashPubKey); | ||
909 | /* FIXME: decide between creating more mesh tunnels and | ||
910 | just remembering the peer ID */ | ||
911 | mesh_tunnel = GNUNET_MESH_tunnel_create (mesh_handle, | ||
912 | NULL /* FIXME: tunnel ctx */, | ||
913 | &pid, | ||
914 | PORT_PT, /* FIXME: DNS port, right? */ | ||
915 | GNUNET_YES /* no buffer */, | ||
916 | GNUNET_NO /* reliable */); | ||
917 | |||
863 | } | 918 | } |
864 | 919 | ||
865 | 920 | ||
@@ -876,6 +931,8 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
876 | const char *cfgfile GNUNET_UNUSED, | 931 | const char *cfgfile GNUNET_UNUSED, |
877 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 932 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
878 | { | 933 | { |
934 | struct GNUNET_HashCode dns_key; | ||
935 | |||
879 | cfg = cfg_; | 936 | cfg = cfg_; |
880 | stats = GNUNET_STATISTICS_create ("pt", cfg); | 937 | stats = GNUNET_STATISTICS_create ("pt", cfg); |
881 | ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV4"); | 938 | ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, "pt", "TUNNEL_IPV4"); |
@@ -932,7 +989,8 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
932 | GNUNET_SCHEDULER_shutdown (); | 989 | GNUNET_SCHEDULER_shutdown (); |
933 | return; | 990 | return; |
934 | } | 991 | } |
935 | mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, NULL, // FIXME use end handler | 992 | mesh_handle = GNUNET_MESH_connect (cfg, NULL, NULL, |
993 | &mesh_tunnel_end_cb, | ||
936 | mesh_handlers, NULL); | 994 | mesh_handlers, NULL); |
937 | if (NULL == mesh_handle) | 995 | if (NULL == mesh_handle) |
938 | { | 996 | { |
@@ -942,14 +1000,23 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
942 | GNUNET_SCHEDULER_shutdown (); | 1000 | GNUNET_SCHEDULER_shutdown (); |
943 | return; | 1001 | return; |
944 | } | 1002 | } |
945 | mesh_tunnel = GNUNET_MESH_tunnel_create (mesh_handle, | 1003 | dht = GNUNET_DHT_connect (cfg, 1); |
946 | NULL, | 1004 | if (NULL == dht) |
947 | NULL, /* FIXME peer ID*/ | 1005 | { |
948 | PORT_PT, | 1006 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
949 | GNUNET_YES, | 1007 | _("Failed to connect to %s service. Exiting.\n"), |
950 | GNUNET_NO); | 1008 | "DHT"); |
951 | // GNUNET_MESH_peer_request_connect_by_type (mesh_tunnel, FIXME use regex | 1009 | GNUNET_SCHEDULER_shutdown (); |
952 | // GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER); | 1010 | return; |
1011 | } | ||
1012 | GNUNET_CRYPTO_hash ("dns", strlen ("dns"), &dns_key); | ||
1013 | dht_get = GNUNET_DHT_get_start (dht, | ||
1014 | GNUNET_BLOCK_TYPE_DNS, | ||
1015 | &dns_key, | ||
1016 | 1, | ||
1017 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
1018 | NULL, 0, | ||
1019 | &handle_dht_result, NULL); | ||
953 | } | 1020 | } |
954 | } | 1021 | } |
955 | 1022 | ||