diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-04-21 13:44:49 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-04-21 13:44:49 +0000 |
commit | 8d33b3f3ecd98f6d79633b0e259f624ad976b698 (patch) | |
tree | fcb44a075c72a8ab4bb4587cedc2885b81be2178 /src | |
parent | ef98e4c68e05e88ced677d66b9e5b57a382df70d (diff) | |
download | gnunet-8d33b3f3ecd98f6d79633b0e259f624ad976b698.tar.gz gnunet-8d33b3f3ecd98f6d79633b0e259f624ad976b698.zip |
Send queries to remote peers
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_protocols.h | 4 | ||||
-rw-r--r-- | src/vpn/Makefile.am | 1 | ||||
-rw-r--r-- | src/vpn/gnunet-service-dns.c | 118 |
3 files changed, 123 insertions, 0 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index c1e6ca0ed..4156b2c08 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -749,6 +749,10 @@ extern "C" | |||
749 | * Type of messages to instruct the local service-dns to rehijack the dns | 749 | * Type of messages to instruct the local service-dns to rehijack the dns |
750 | */ | 750 | */ |
751 | #define GNUNET_MESSAGE_TYPE_REHIJACK 207 | 751 | #define GNUNET_MESSAGE_TYPE_REHIJACK 207 |
752 | /** | ||
753 | * Type of messages to send a DNS-query to another peer | ||
754 | */ | ||
755 | #define GNUNET_MESSAGE_TYPE_REMOTE_QUERY_DNS 208 | ||
752 | 756 | ||
753 | 757 | ||
754 | /** | 758 | /** |
diff --git a/src/vpn/Makefile.am b/src/vpn/Makefile.am index 261ae8149..5430ba3b9 100644 --- a/src/vpn/Makefile.am +++ b/src/vpn/Makefile.am | |||
@@ -53,6 +53,7 @@ gnunet_service_dns_LDADD = \ | |||
53 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 53 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
54 | $(top_builddir)/src/util/libgnunetutil.la \ | 54 | $(top_builddir)/src/util/libgnunetutil.la \ |
55 | $(top_builddir)/src/dht/libgnunetdht.la \ | 55 | $(top_builddir)/src/dht/libgnunetdht.la \ |
56 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | ||
56 | $(GN_LIBINTL) | 57 | $(GN_LIBINTL) |
57 | 58 | ||
58 | gnunet_daemon_exit_SOURCES = \ | 59 | gnunet_daemon_exit_SOURCES = \ |
diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 0dd58027a..9fb88bed2 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "gnunet_os_lib.h" | 29 | #include "gnunet_os_lib.h" |
30 | #include "gnunet-service-dns-p.h" | 30 | #include "gnunet-service-dns-p.h" |
31 | #include "gnunet_protocols.h" | 31 | #include "gnunet_protocols.h" |
32 | #include "gnunet_applications.h" | ||
32 | #include "gnunet-vpn-packet.h" | 33 | #include "gnunet-vpn-packet.h" |
33 | #include "gnunet_container_lib.h" | 34 | #include "gnunet_container_lib.h" |
34 | #include "gnunet-dns-parser.h" | 35 | #include "gnunet-dns-parser.h" |
@@ -36,8 +37,11 @@ | |||
36 | #include "gnunet_block_lib.h" | 37 | #include "gnunet_block_lib.h" |
37 | #include "block_dns.h" | 38 | #include "block_dns.h" |
38 | #include "gnunet_crypto_lib.h" | 39 | #include "gnunet_crypto_lib.h" |
40 | #include "gnunet_mesh_service.h" | ||
39 | #include "gnunet_signatures.h" | 41 | #include "gnunet_signatures.h" |
40 | 42 | ||
43 | struct GNUNET_MESH_Handle *mesh_handle; | ||
44 | |||
41 | /** | 45 | /** |
42 | * The UDP-Socket through which DNS-Resolves will be sent if they are not to be | 46 | * The UDP-Socket through which DNS-Resolves will be sent if they are not to be |
43 | * sent through gnunet. The port of this socket will not be hijacked. | 47 | * sent through gnunet. The port of this socket will not be hijacked. |
@@ -190,6 +194,67 @@ send_answer(void* cls, size_t size, void* buf) { | |||
190 | return len; | 194 | return len; |
191 | } | 195 | } |
192 | 196 | ||
197 | struct tunnel_cls { | ||
198 | struct GNUNET_MESH_Tunnel *tunnel; | ||
199 | struct GNUNET_MessageHeader hdr; | ||
200 | struct dns_pkt dns; | ||
201 | }; | ||
202 | |||
203 | struct tunnel_cls *remote_pending[UINT16_MAX]; | ||
204 | |||
205 | |||
206 | static size_t | ||
207 | mesh_send (void *cls, size_t size, void *buf) | ||
208 | { | ||
209 | struct tunnel_cls *cls_ = (struct tunnel_cls *) cls; | ||
210 | |||
211 | GNUNET_assert(cls_->hdr.size <= size); | ||
212 | |||
213 | size = cls_->hdr.size; | ||
214 | cls_->hdr.size = htons(cls_->hdr.size); | ||
215 | |||
216 | memcpy(buf, &cls_->hdr, size); | ||
217 | return size; | ||
218 | } | ||
219 | |||
220 | |||
221 | void mesh_connect (void* cls, const struct GNUNET_PeerIdentity* peer, const struct GNUNET_TRANSPORT_ATS_Information *atsi) { | ||
222 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %x\n", *((unsigned long*)peer)); | ||
223 | struct tunnel_cls *cls_ = (struct tunnel_cls*)cls; | ||
224 | |||
225 | GNUNET_MESH_notify_transmit_ready(cls_->tunnel, | ||
226 | GNUNET_YES, | ||
227 | 42, | ||
228 | GNUNET_TIME_UNIT_MINUTES, | ||
229 | NULL, | ||
230 | cls_->hdr.size, | ||
231 | mesh_send, | ||
232 | cls); | ||
233 | } | ||
234 | |||
235 | |||
236 | static void | ||
237 | send_mesh_query (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
238 | { | ||
239 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
240 | return; | ||
241 | |||
242 | struct tunnel_cls *cls_ = (struct tunnel_cls*)cls; | ||
243 | |||
244 | cls_->tunnel = GNUNET_MESH_peer_request_connect_by_type(mesh_handle, | ||
245 | GNUNET_TIME_UNIT_HOURS, | ||
246 | GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, | ||
247 | mesh_connect, | ||
248 | NULL, | ||
249 | cls_); | ||
250 | |||
251 | remote_pending[cls_->dns.s.id] = cls_; | ||
252 | |||
253 | /* TODO | ||
254 | * at receive: walk through pending list, send answer | ||
255 | */ | ||
256 | } | ||
257 | |||
193 | static void | 258 | static void |
194 | send_rev_query(void * cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { | 259 | send_rev_query(void * cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { |
195 | struct dns_pkt_parsed* pdns = (struct dns_pkt_parsed*) cls; | 260 | struct dns_pkt_parsed* pdns = (struct dns_pkt_parsed*) cls; |
@@ -490,6 +555,46 @@ receive_query(void *cls, | |||
490 | } | 555 | } |
491 | } | 556 | } |
492 | 557 | ||
558 | char* virt_dns; | ||
559 | int virt_dns_bytes; | ||
560 | if (GNUNET_SYSERR == | ||
561 | GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "VIRTDNS", | ||
562 | &virt_dns)) | ||
563 | { | ||
564 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
565 | "No entry 'VIRTDNS' in configuration!\n"); | ||
566 | exit (1); | ||
567 | } | ||
568 | |||
569 | if (1 != inet_pton (AF_INET, virt_dns, &virt_dns_bytes)) | ||
570 | { | ||
571 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
572 | "Error parsing 'VIRTDNS': %s; %m!\n", virt_dns); | ||
573 | exit(1); | ||
574 | } | ||
575 | |||
576 | GNUNET_free(virt_dns); | ||
577 | |||
578 | if (virt_dns_bytes == pkt->orig_to) | ||
579 | { | ||
580 | /* This is a packet that was sent directly to the virtual dns-server | ||
581 | * | ||
582 | * This means we have to send this query over gnunet | ||
583 | */ | ||
584 | |||
585 | size_t size = sizeof(struct GNUNET_MESH_Tunnel*) + sizeof(struct GNUNET_MessageHeader) + (ntohs(message->size) - sizeof(struct query_packet) + 1); | ||
586 | struct tunnel_cls *cls_ = GNUNET_malloc(size); | ||
587 | cls_->hdr.size = size - sizeof(struct GNUNET_MESH_Tunnel*); | ||
588 | |||
589 | cls_->hdr.type = ntohs(GNUNET_MESSAGE_TYPE_REMOTE_QUERY_DNS); | ||
590 | |||
591 | memcpy(&cls_->dns, dns, cls_->hdr.size); | ||
592 | GNUNET_SCHEDULER_add_now(send_mesh_query, cls_); | ||
593 | |||
594 | goto out; | ||
595 | } | ||
596 | |||
597 | |||
493 | /* The query should be sent to the network */ | 598 | /* The query should be sent to the network */ |
494 | 599 | ||
495 | struct sockaddr_in dest; | 600 | struct sockaddr_in dest; |
@@ -874,6 +979,19 @@ run (void *cls, | |||
874 | {NULL, NULL, 0, 0} | 979 | {NULL, NULL, 0, 0} |
875 | }; | 980 | }; |
876 | 981 | ||
982 | |||
983 | const static struct GNUNET_MESH_MessageHandler mesh_handlers[] = { | ||
984 | //{receive_mesh_qery, GNUNET_MESSAGE_TYPE_REMOTE_QUERY_DNS, 0}, | ||
985 | {NULL, 0, 0} | ||
986 | }; | ||
987 | |||
988 | const static GNUNET_MESH_ApplicationType apptypes[] = | ||
989 | { GNUNET_APPLICATION_TYPE_INTERNET_RESOLVER, | ||
990 | GNUNET_APPLICATION_TYPE_END | ||
991 | }; | ||
992 | |||
993 | mesh_handle = GNUNET_MESH_connect (cfg_, NULL, NULL, mesh_handlers, apptypes); | ||
994 | |||
877 | cfg = cfg_; | 995 | cfg = cfg_; |
878 | 996 | ||
879 | unsigned int i; | 997 | unsigned int i; |