gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13303 - gnunet/src/vpn


From: gnunet
Subject: [GNUnet-SVN] r13303 - gnunet/src/vpn
Date: Tue, 19 Oct 2010 23:16:46 +0200

Author: toelke
Date: 2010-10-19 23:16:46 +0200 (Tue, 19 Oct 2010)
New Revision: 13303

Modified:
   gnunet/src/vpn/gnunet-service-dns-p.h
   gnunet/src/vpn/gnunet-service-dns.c
Log:
send an dns-response from the dht

Modified: gnunet/src/vpn/gnunet-service-dns-p.h
===================================================================
--- gnunet/src/vpn/gnunet-service-dns-p.h       2010-10-19 21:16:45 UTC (rev 
13302)
+++ gnunet/src/vpn/gnunet-service-dns-p.h       2010-10-19 21:16:46 UTC (rev 
13303)
@@ -23,7 +23,12 @@
     /**
      * Answers of this type contain a dns-packet that just has to be 
transmitted
      */
-    GNUNET_DNS_ANSWER_TYPE_IP
+    GNUNET_DNS_ANSWER_TYPE_IP,
+
+    /**
+     * Answers of this type contain an struct GNUNET_DNS_Record
+     */
+    GNUNET_DNS_ANSWER_TYPE_SERVICE
 };
 
 struct answer_packet {

Modified: gnunet/src/vpn/gnunet-service-dns.c
===================================================================
--- gnunet/src/vpn/gnunet-service-dns.c 2010-10-19 21:16:45 UTC (rev 13302)
+++ gnunet/src/vpn/gnunet-service-dns.c 2010-10-19 21:16:46 UTC (rev 13303)
@@ -55,6 +55,7 @@
        unsigned valid:1;
        struct GNUNET_SERVER_Client* client;
        unsigned local_ip:32;
+       unsigned remote_ip:32;
        unsigned local_port:16;
 };
 static struct dns_query_id_state query_states[65536]; /* This is < 1MiB */
@@ -75,6 +76,8 @@
        GNUNET_OS_start_process(NULL, NULL, "gnunet-helper-hijack-dns", 
"gnunet-hijack-dns", "-d", port_s, NULL);
 }
 
+size_t send_answer(void* cls, size_t size, void* buf);
+
 void receive_dht(void *cls,
                 struct GNUNET_TIME_Absolute exp,
                 const GNUNET_HashCode *key,
@@ -84,9 +87,33 @@
                 size_t size,
                 const void *data)
 {
+  unsigned short id = *((unsigned short*)cls);
+  GNUNET_free(cls);
+
   GNUNET_assert(type == GNUNET_BLOCK_TYPE_DNS);
+
+  if (query_states[id].valid != GNUNET_YES) return;
+  query_states[id].valid = GNUNET_NO;
+
   const struct GNUNET_DNS_Record* rec = data;
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got block of size %d, peer: %08x, desc: 
%08x\n", size, *((unsigned int*)&rec->peer), *((unsigned 
int*)&rec->service_descriptor));
+
+  size_t len = sizeof(struct answer_packet) + size - 1; /* 1 for the unsigned 
char data[1]; */
+  struct answer_packet_list* answer = GNUNET_malloc(len + 2*sizeof(struct 
answer_packet_list*));
+  answer->pkt.hdr.type = htons(GNUNET_MESSAGE_TYPE_LOCAL_RESPONSE_DNS);
+  answer->pkt.hdr.size = htons(len);
+  answer->pkt.subtype = GNUNET_DNS_ANSWER_TYPE_SERVICE;
+
+  answer->pkt.from = query_states[id].remote_ip;
+
+  answer->pkt.to = query_states[id].local_ip;
+  answer->pkt.dst_port = query_states[id].local_port;
+
+  memcpy(answer->pkt.data, data, size);
+
+  GNUNET_CONTAINER_DLL_insert_after(mycls.head, mycls.tail, mycls.tail, 
answer);
+
+  /* struct GNUNET_CONNECTION_TransmitHandle* th = */ 
GNUNET_SERVER_notify_transmit_ready(query_states[id].client, len, 
GNUNET_TIME_UNIT_FOREVER_REL, &send_answer, query_states[id].client);
 }
 
 /**
@@ -98,8 +125,18 @@
        struct dns_pkt* dns = (struct dns_pkt*)pkt->data;
        struct dns_pkt_parsed* pdns = parse_dns_packet(dns);
 
+       query_states[dns->s.id].valid = 1;
+       query_states[dns->s.id].client = client;
+       query_states[dns->s.id].local_ip = pkt->orig_from;
+       query_states[dns->s.id].local_port = pkt->src_port;
+       query_states[dns->s.id].remote_ip = pkt->orig_to;
+
        if (pdns->queries[0]->namelen > 9 &&
            0 == strncmp(pdns->queries[0]->name+(pdns->queries[0]->namelen - 
9), ".gnunet.", 9)) {
+
+           unsigned short* id = GNUNET_malloc(sizeof(unsigned short));
+           *id = dns->s.id;
+
            GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Query for .gnunet!\n");
            GNUNET_HashCode key;
            GNUNET_CRYPTO_hash(pdns->queries[0]->name, 
pdns->queries[0]->namelen, &key);
@@ -114,10 +151,11 @@
                                 NULL,
                                 0,
                                 receive_dht,
-                                NULL);
+                                id);
            goto out;
        }
 
+       /* The query should be sent to the network */
        GNUNET_free(pdns);
 
        struct sockaddr_in dest;
@@ -125,11 +163,6 @@
        dest.sin_port = htons(53);
        dest.sin_addr.s_addr = pkt->orig_to;
 
-       query_states[dns->s.id].valid = 1;
-       query_states[dns->s.id].client = client;
-       query_states[dns->s.id].local_ip = pkt->orig_from;
-       query_states[dns->s.id].local_port = pkt->src_port;
-
        /* int r = */ GNUNET_NETWORK_socket_sendto(mycls.dnsout, dns, 
ntohs(pkt->hdr.size) - sizeof(struct query_packet) + 1, (struct sockaddr*) 
&dest, sizeof dest);
 
 out:




reply via email to

[Prev in Thread] Current Thread [Next in Thread]