diff options
author | Philipp Tölke <toelke@in.tum.de> | 2010-10-08 09:03:37 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2010-10-08 09:03:37 +0000 |
commit | 3b705c3009d4ae1c185889292088d52b68283370 (patch) | |
tree | 87f9f4f0036ebdcf1c038c9a60daf156e29c8374 /src/vpn/gnunet-service-dns.c | |
parent | b58d0e83e888c877626533d54a41e7dc359c9de2 (diff) | |
download | gnunet-3b705c3009d4ae1c185889292088d52b68283370.tar.gz gnunet-3b705c3009d4ae1c185889292088d52b68283370.zip |
lookup .gnunet-addresses in the dht
Diffstat (limited to 'src/vpn/gnunet-service-dns.c')
-rw-r--r-- | src/vpn/gnunet-service-dns.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 1545d6cb2..1bf94ce48 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c | |||
@@ -33,12 +33,17 @@ | |||
33 | #include "gnunet-vpn-pretty-print.h" | 33 | #include "gnunet-vpn-pretty-print.h" |
34 | #include "gnunet_container_lib.h" | 34 | #include "gnunet_container_lib.h" |
35 | #include "gnunet-dns-parser.h" | 35 | #include "gnunet-dns-parser.h" |
36 | #include "gnunet_dht_service.h" | ||
37 | #include "gnunet_block_lib.h" | ||
38 | #include "gnunet_block_dns.h" | ||
36 | 39 | ||
37 | struct dns_cls { | 40 | struct dns_cls { |
38 | struct GNUNET_SCHEDULER_Handle *sched; | 41 | struct GNUNET_SCHEDULER_Handle *sched; |
39 | 42 | ||
40 | struct GNUNET_NETWORK_Handle *dnsout; | 43 | struct GNUNET_NETWORK_Handle *dnsout; |
41 | 44 | ||
45 | struct GNUNET_DHT_Handle *dht; | ||
46 | |||
42 | unsigned short dnsoutport; | 47 | unsigned short dnsoutport; |
43 | 48 | ||
44 | struct answer_packet_list *head; | 49 | struct answer_packet_list *head; |
@@ -70,6 +75,20 @@ void unhijack(unsigned short port) { | |||
70 | GNUNET_OS_start_process(NULL, NULL, "gnunet-helper-hijack-dns", "gnunet-hijack-dns", "-d", port_s, NULL); | 75 | GNUNET_OS_start_process(NULL, NULL, "gnunet-helper-hijack-dns", "gnunet-hijack-dns", "-d", port_s, NULL); |
71 | } | 76 | } |
72 | 77 | ||
78 | void receive_dht(void *cls, | ||
79 | struct GNUNET_TIME_Absolute exp, | ||
80 | const GNUNET_HashCode *key, | ||
81 | const struct GNUNET_PeerIdentity *const *get_path, | ||
82 | const struct GNUNET_PeerIdentity *const *put_path, | ||
83 | enum GNUNET_BLOCK_Type type, | ||
84 | size_t size, | ||
85 | const void *data) | ||
86 | { | ||
87 | GNUNET_assert(type == GNUNET_BLOCK_TYPE_DNS); | ||
88 | const struct GNUNET_DNS_Record* rec = data; | ||
89 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got block of size %s, peer: %08x, desc: %08x\n", size, *((unsigned int*)&rec->peer), *((unsigned int*)&rec->service_descriptor)); | ||
90 | } | ||
91 | |||
73 | /** | 92 | /** |
74 | * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket | 93 | * This receives the dns-payload from the daemon-vpn and sends it on over the udp-socket |
75 | */ | 94 | */ |
@@ -82,6 +101,20 @@ void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct | |||
82 | if (pdns->queries[0]->namelen > 9 && | 101 | if (pdns->queries[0]->namelen > 9 && |
83 | 0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - 9), ".gnunet.", 9)) { | 102 | 0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - 9), ".gnunet.", 9)) { |
84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n"); | 103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n"); |
104 | GNUNET_HashCode key; | ||
105 | GNUNET_CRYPTO_hash(pdns->queries[0]->name, pdns->queries[0]->namelen, &key); | ||
106 | GNUNET_DHT_get_start(mycls.dht, | ||
107 | GNUNET_TIME_UNIT_MINUTES, | ||
108 | GNUNET_BLOCK_TYPE_DNS, | ||
109 | &key, | ||
110 | GNUNET_DHT_RO_NONE, | ||
111 | NULL, | ||
112 | 0, | ||
113 | NULL, | ||
114 | 0, | ||
115 | receive_dht, | ||
116 | NULL); | ||
117 | goto out; | ||
85 | } | 118 | } |
86 | 119 | ||
87 | GNUNET_free(pdns); | 120 | GNUNET_free(pdns); |
@@ -98,6 +131,7 @@ void receive_query(void *cls, struct GNUNET_SERVER_Client *client, const struct | |||
98 | 131 | ||
99 | /* int r = */ GNUNET_NETWORK_socket_sendto(mycls.dnsout, dns, ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1, (struct sockaddr*) &dest, sizeof dest); | 132 | /* int r = */ GNUNET_NETWORK_socket_sendto(mycls.dnsout, dns, ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1, (struct sockaddr*) &dest, sizeof dest); |
100 | 133 | ||
134 | out: | ||
101 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 135 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
102 | } | 136 | } |
103 | 137 | ||
@@ -168,6 +202,7 @@ cleanup_task (void *cls, | |||
168 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 202 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
169 | { | 203 | { |
170 | unhijack(mycls.dnsoutport); | 204 | unhijack(mycls.dnsoutport); |
205 | GNUNET_DHT_disconnect(mycls.dht); | ||
171 | } | 206 | } |
172 | 207 | ||
173 | /** | 208 | /** |
@@ -195,6 +230,8 @@ run (void *cls, | |||
195 | } | 230 | } |
196 | } | 231 | } |
197 | 232 | ||
233 | mycls.dht = GNUNET_DHT_connect(sched, cfg, 1024); | ||
234 | |||
198 | struct sockaddr_in addr; | 235 | struct sockaddr_in addr; |
199 | 236 | ||
200 | mycls.sched = sched; | 237 | mycls.sched = sched; |