aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-10-26 22:13:01 +0000
committerChristian Grothoff <christian@grothoff.org>2012-10-26 22:13:01 +0000
commit64d3e46cfb99a711e500fa1f114e7c44bdf10040 (patch)
tree83093d92761d5c1b8b2fded713adaa19af29274c /src/gns
parentef6f05f63769263a5201636c4b7f71eaa455cdf3 (diff)
downloadgnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.tar.gz
gnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.zip
-bugfixes, code cleanup
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gns.conf.in2
-rw-r--r--src/gns/gns.h33
-rw-r--r--src/gns/gns_api.c40
-rw-r--r--src/gns/gnunet-gns-proxy.c118
-rw-r--r--src/gns/gnunet-gns.c84
-rw-r--r--src/gns/gnunet-service-gns.c387
-rw-r--r--src/gns/gnunet-service-gns_interceptor.c134
-rw-r--r--src/gns/gnunet-service-gns_interceptor.h34
-rw-r--r--src/gns/gnunet-service-gns_resolver.c6
-rw-r--r--src/gns/gnunet-service-gns_resolver.h402
-rw-r--r--src/gns/plugin_block_gns.c27
-rw-r--r--src/gns/proxy/gnunet-gns-proxy.py226
-rw-r--r--src/gns/proxy/test_cert.pem51
13 files changed, 722 insertions, 822 deletions
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in
index 303fbf90b..9746c07af 100644
--- a/src/gns/gns.conf.in
+++ b/src/gns/gns.conf.in
@@ -12,7 +12,7 @@ HIJACK_DNS = NO
12AUTO_IMPORT_PKEY = YES 12AUTO_IMPORT_PKEY = YES
13AUTO_IMPORT_CONFIRMATION_REQ = NO 13AUTO_IMPORT_CONFIRMATION_REQ = NO
14MAX_PARALLEL_BACKGROUND_QUERIES = 25 14MAX_PARALLEL_BACKGROUND_QUERIES = 25
15DEFAULT_LOOKUP_TIMEOUT = 10 15DEFAULT_LOOKUP_TIMEOUT = 10 s
16ZONE_PUBLISH_TIME_WINDOW = 4 h 16ZONE_PUBLISH_TIME_WINDOW = 4 h
17# PREFIX = valgrind --leak-check=full --track-origins=yes 17# PREFIX = valgrind --leak-check=full --track-origins=yes
18 18
diff --git a/src/gns/gns.h b/src/gns/gns.h
index 2f4ce3928..10119800d 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -27,14 +27,32 @@
27 27
28#include "gnunet_gns_service.h" 28#include "gnunet_gns_service.h"
29 29
30/**
31 * Name of the GADS TLD.
32 */
30#define GNUNET_GNS_TLD "gads" 33#define GNUNET_GNS_TLD "gads"
34
35/**
36 * Name of the zone key TLD.
37 */
31#define GNUNET_GNS_TLD_ZKEY "zkey" 38#define GNUNET_GNS_TLD_ZKEY "zkey"
39
40/**
41 * TLD name used to indicate relative names.
42 */
32#define GNUNET_GNS_TLD_PLUS "+" 43#define GNUNET_GNS_TLD_PLUS "+"
33#define GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL 3600
34 44
45/**
46 * Maximum length of a label in DNS.
47 */
35#define MAX_DNS_LABEL_LENGTH 63 48#define MAX_DNS_LABEL_LENGTH 63
49
50/**
51 * Maximum length of a name in DNS.
52 */
36#define MAX_DNS_NAME_LENGTH 253 53#define MAX_DNS_NAME_LENGTH 253
37 54
55
38GNUNET_NETWORK_STRUCT_BEGIN 56GNUNET_NETWORK_STRUCT_BEGIN
39 57
40/** 58/**
@@ -43,7 +61,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
43struct GNUNET_GNS_ClientLookupMessage 61struct GNUNET_GNS_ClientLookupMessage
44{ 62{
45 /** 63 /**
46 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 64 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP
47 */ 65 */
48 struct GNUNET_MessageHeader header; 66 struct GNUNET_MessageHeader header;
49 67
@@ -107,13 +125,14 @@ struct GNUNET_GNS_ClientLookupResultMessage
107 125
108}; 126};
109 127
128
110/** 129/**
111 * Message from client to GNS service to shorten names. 130 * Message from client to GNS service to shorten names.
112 */ 131 */
113struct GNUNET_GNS_ClientShortenMessage 132struct GNUNET_GNS_ClientShortenMessage
114{ 133{
115 /** 134 /**
116 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN 135 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN
117 */ 136 */
118 struct GNUNET_MessageHeader header; 137 struct GNUNET_MessageHeader header;
119 138
@@ -152,7 +171,7 @@ struct GNUNET_GNS_ClientShortenMessage
152struct GNUNET_GNS_ClientShortenResultMessage 171struct GNUNET_GNS_ClientShortenResultMessage
153{ 172{
154 /** 173 /**
155 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN_RESULT 174 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN_RESULT
156 */ 175 */
157 struct GNUNET_MessageHeader header; 176 struct GNUNET_MessageHeader header;
158 177
@@ -165,13 +184,14 @@ struct GNUNET_GNS_ClientShortenResultMessage
165 184
166}; 185};
167 186
187
168/** 188/**
169 * Message from client to GNS service to lookup an authority of a name. 189 * Message from client to GNS service to lookup an authority of a name.
170 */ 190 */
171struct GNUNET_GNS_ClientGetAuthMessage 191struct GNUNET_GNS_ClientGetAuthMessage
172{ 192{
173 /** 193 /**
174 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH 194 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH
175 */ 195 */
176 struct GNUNET_MessageHeader header; 196 struct GNUNET_MessageHeader header;
177 197
@@ -190,7 +210,7 @@ struct GNUNET_GNS_ClientGetAuthMessage
190struct GNUNET_GNS_ClientGetAuthResultMessage 210struct GNUNET_GNS_ClientGetAuthResultMessage
191{ 211{
192 /** 212 /**
193 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH_RESULT 213 * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH_RESULT
194 */ 214 */
195 struct GNUNET_MessageHeader header; 215 struct GNUNET_MessageHeader header;
196 216
@@ -202,6 +222,7 @@ struct GNUNET_GNS_ClientGetAuthResultMessage
202 /* followed by the authority part of the name or '\0' for no result*/ 222 /* followed by the authority part of the name or '\0' for no result*/
203 223
204}; 224};
225
205GNUNET_NETWORK_STRUCT_END 226GNUNET_NETWORK_STRUCT_END
206 227
207#endif 228#endif
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index fef7b866d..b3173a554 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -68,7 +68,7 @@ struct GNUNET_GNS_LookupRequest
68 /** 68 /**
69 * request id 69 * request id
70 */ 70 */
71 uint64_t r_id; 71 uint32_t r_id;
72 72
73}; 73};
74 74
@@ -106,7 +106,7 @@ struct GNUNET_GNS_ShortenRequest
106 /** 106 /**
107 * request id 107 * request id
108 */ 108 */
109 uint64_t r_id; 109 uint32_t r_id;
110 110
111}; 111};
112 112
@@ -165,14 +165,14 @@ struct PendingMessage
165 struct PendingMessage *next; 165 struct PendingMessage *next;
166 166
167 /** 167 /**
168 * request id 168 * Size of the message.
169 */ 169 */
170 uint64_t r_id; 170 size_t size;
171 171
172 /** 172 /**
173 * Size of the message. 173 * request id
174 */ 174 */
175 size_t size; 175 uint32_t r_id;
176 176
177 /** 177 /**
178 * This message has been transmitted. GNUNET_NO if the message is 178 * This message has been transmitted. GNUNET_NO if the message is
@@ -249,8 +249,16 @@ struct GNUNET_GNS_Handle
249 * Reconnect task 249 * Reconnect task
250 */ 250 */
251 GNUNET_SCHEDULER_TaskIdentifier reconnect_task; 251 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
252
253 /**
254 * How long do we wait until we try to reconnect?
255 */
256 struct GNUNET_TIME_Relative reconnect_backoff;
252 257
253 uint32_t r_id; 258 /**
259 * Request Id generator. Incremented by one for each request.
260 */
261 uint32_t r_id_gen;
254 262
255 /** 263 /**
256 * Did we start our receive loop yet? 264 * Did we start our receive loop yet?
@@ -319,7 +327,7 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
319 h->in_receive = GNUNET_NO; 327 h->in_receive = GNUNET_NO;
320 for (st = h->shorten_head; NULL != st; st = st->next) 328 for (st = h->shorten_head; NULL != st; st = st->next)
321 { 329 {
322 p = (struct PendingMessage*) &st[1]; 330 p = (struct PendingMessage *) &st[1];
323 if (GNUNET_NO == p->transmitted) 331 if (GNUNET_NO == p->transmitted)
324 continue; 332 continue;
325 p->transmitted = GNUNET_NO; 333 p->transmitted = GNUNET_NO;
@@ -329,7 +337,7 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
329 } 337 }
330 for (lh = h->lookup_head; NULL != lh; lh = lh->next) 338 for (lh = h->lookup_head; NULL != lh; lh = lh->next)
331 { 339 {
332 p = (struct PendingMessage*) &lh[1]; 340 p = (struct PendingMessage *) &lh[1];
333 if (GNUNET_NO == p->transmitted) 341 if (GNUNET_NO == p->transmitted)
334 continue; 342 continue;
335 p->transmitted = GNUNET_NO; 343 p->transmitted = GNUNET_NO;
@@ -339,7 +347,7 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
339 } 347 }
340 for (ga = h->get_auth_head; NULL != ga; ga = ga->next) 348 for (ga = h->get_auth_head; NULL != ga; ga = ga->next)
341 { 349 {
342 p = (struct PendingMessage*) &ga[1]; 350 p = (struct PendingMessage *) &ga[1];
343 if (GNUNET_NO == p->transmitted) 351 if (GNUNET_NO == p->transmitted)
344 continue; 352 continue;
345 p->transmitted = GNUNET_NO; 353 p->transmitted = GNUNET_NO;
@@ -347,8 +355,8 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
347 h->pending_tail, 355 h->pending_tail,
348 p); 356 p);
349 } 357 }
350 /* FIXME: 1s too long, exponential-backoff, starting at 1ms! (max = 1s might be OK) */ 358 h->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (h->reconnect_backoff);
351 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 359 h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_backoff,
352 &reconnect_task, 360 &reconnect_task,
353 h); 361 h);
354} 362}
@@ -618,7 +626,7 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
618 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg; 626 const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
619 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg; 627 const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
620 const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg; 628 const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg;
621 uint64_t r_id; 629 uint32_t r_id;
622 630
623 if (NULL == msg) 631 if (NULL == msg)
624 { 632 {
@@ -860,7 +868,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
860 lr->gns_handle = handle; 868 lr->gns_handle = handle;
861 lr->lookup_proc = proc; 869 lr->lookup_proc = proc;
862 lr->proc_cls = proc_cls; 870 lr->proc_cls = proc_cls;
863 lr->r_id = handle->r_id++; 871 lr->r_id = handle->r_id_gen++;
864 pending = (struct PendingMessage *)&lr[1]; 872 pending = (struct PendingMessage *)&lr[1];
865 pending->size = msize; 873 pending->size = msize;
866 pending->r_id = lr->r_id; 874 pending->r_id = lr->r_id;
@@ -975,7 +983,7 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
975 sr->gns_handle = handle; 983 sr->gns_handle = handle;
976 sr->shorten_proc = proc; 984 sr->shorten_proc = proc;
977 sr->proc_cls = proc_cls; 985 sr->proc_cls = proc_cls;
978 sr->r_id = handle->r_id++; 986 sr->r_id = handle->r_id_gen++;
979 GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head, 987 GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head,
980 handle->shorten_tail, sr); 988 handle->shorten_tail, sr);
981 pending = (struct PendingMessage *)&sr[1]; 989 pending = (struct PendingMessage *)&sr[1];
@@ -1070,7 +1078,7 @@ GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
1070 gar->gns_handle = handle; 1078 gar->gns_handle = handle;
1071 gar->auth_proc = proc; 1079 gar->auth_proc = proc;
1072 gar->proc_cls = proc_cls; 1080 gar->proc_cls = proc_cls;
1073 gar->r_id = handle->r_id++; 1081 gar->r_id = handle->r_id_gen++;
1074 GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head, 1082 GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head,
1075 handle->get_auth_tail, gar); 1083 handle->get_auth_tail, gar);
1076 1084
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 47d149330..fb7b80e16 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -500,41 +500,6 @@ i_to_hexchar (unsigned char i)
500} 500}
501 501
502 502
503/**
504// FIXME: use cURL API
505 * Escape given 0-terminated string
506 *
507 * @param to_esc string to escapse
508 * @return allocated new escaped string (MUST free!)
509 */
510static char*
511escape_to_urlenc (const char *to_esc)
512{
513 char *pos = (char*)to_esc;
514 char *res = GNUNET_malloc (strlen (to_esc) * 3 + 1);
515 char *rpos = res;
516
517 while ('\0' != *pos)
518 {
519 if (isalnum (*pos) ||
520 ('-' == *pos) || ('_' == *pos) ||
521 ('.' == *pos) || ('~' == *pos))
522 *rpos++ = *pos;
523 else if (' ' == *pos)
524 *rpos++ = '+';
525 else
526 {
527 *rpos++ = '%';
528 *rpos++ = i_to_hexchar (*pos >> 4);
529 *rpos++ = i_to_hexchar (*pos >> 15);
530 }
531 pos++;
532 }
533 *rpos = '\0';
534 return res;
535}
536
537
538static int 503static int
539con_post_data_iter (void *cls, 504con_post_data_iter (void *cls,
540 enum MHD_ValueKind kind, 505 enum MHD_ValueKind kind,
@@ -610,9 +575,14 @@ con_post_data_iter (void *cls,
610 575
611 if (0 == off) 576 if (0 == off)
612 { 577 {
578 enc = curl_easy_escape (ctask->curl, key, 0);
579 if (NULL == enc)
580 {
581 GNUNET_break (0);
582 return MHD_NO;
583 }
613 /* a key */ 584 /* a key */
614 pdata = GNUNET_malloc (sizeof (struct ProxyUploadData)); 585 pdata = GNUNET_malloc (sizeof (struct ProxyUploadData));
615 enc = escape_to_urlenc (key);
616 pdata->value = GNUNET_malloc (strlen (enc) + 3); 586 pdata->value = GNUNET_malloc (strlen (enc) + 3);
617 if (NULL != ctask->upload_data_head) 587 if (NULL != ctask->upload_data_head)
618 { 588 {
@@ -624,7 +594,7 @@ con_post_data_iter (void *cls,
624 pdata->value[strlen (pdata->value)] = '='; 594 pdata->value[strlen (pdata->value)] = '=';
625 pdata->bytes_left = strlen (pdata->value); 595 pdata->bytes_left = strlen (pdata->value);
626 pdata->total_bytes = pdata->bytes_left; 596 pdata->total_bytes = pdata->bytes_left;
627 GNUNET_free (enc); 597 curl_free (enc);
628 598
629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 599 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
630 "Escaped POST key: '%s'\n", 600 "Escaped POST key: '%s'\n",
@@ -636,13 +606,18 @@ con_post_data_iter (void *cls,
636 } 606 }
637 607
638 /* a value */ 608 /* a value */
609 enc = curl_easy_escape (ctask->curl, data, 0);
610 if (NULL == enc)
611 {
612 GNUNET_break (0);
613 return MHD_NO;
614 }
639 pdata = GNUNET_malloc (sizeof (struct ProxyUploadData)); 615 pdata = GNUNET_malloc (sizeof (struct ProxyUploadData));
640 enc = escape_to_urlenc (data);
641 pdata->value = GNUNET_malloc (strlen (enc) + 1); 616 pdata->value = GNUNET_malloc (strlen (enc) + 1);
642 memcpy (pdata->value, enc, strlen (enc)); 617 memcpy (pdata->value, enc, strlen (enc));
643 pdata->bytes_left = strlen (pdata->value); 618 pdata->bytes_left = strlen (pdata->value);
644 pdata->total_bytes = pdata->bytes_left; 619 pdata->total_bytes = pdata->bytes_left;
645 GNUNET_free (enc); 620 curl_free (enc);
646 621
647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
648 "Escaped POST value: '%s'\n", 623 "Escaped POST value: '%s'\n",
@@ -1341,6 +1316,7 @@ postprocess_buffer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1341 run_mhd_now (ctask->mhd); 1316 run_mhd_now (ctask->mhd);
1342} 1317}
1343 1318
1319
1344/** 1320/**
1345 * Handle data from cURL 1321 * Handle data from cURL
1346 * 1322 *
@@ -1592,7 +1568,6 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1592 struct ProxyCurlTask *ctask; 1568 struct ProxyCurlTask *ctask;
1593 int num_ctasks; 1569 int num_ctasks;
1594 long resp_code; 1570 long resp_code;
1595
1596 struct ProxyCurlTask *clean_head = NULL; 1571 struct ProxyCurlTask *clean_head = NULL;
1597 struct ProxyCurlTask *clean_tail = NULL; 1572 struct ProxyCurlTask *clean_tail = NULL;
1598 1573
@@ -1602,8 +1577,8 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1602 { 1577 {
1603 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1578 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1604 "Shutdown requested while trying to download\n"); 1579 "Shutdown requested while trying to download\n");
1605 //TODO cleanup 1580 //TODO cleanup
1606 return; 1581 return;
1607 } 1582 }
1608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1609 "Ready to dl\n"); 1584 "Ready to dl\n");
@@ -2392,13 +2367,11 @@ do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2392 len); 2367 len);
2393 } 2368 }
2394 else 2369 else
2395 { 2370 {
2396
2397 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write"); 2371 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
2398 s5r->cleanup = GNUNET_YES; 2372 s5r->cleanup = GNUNET_YES;
2399 s5r->cleanup_sock = GNUNET_YES; 2373 s5r->cleanup_sock = GNUNET_YES;
2400 cleanup_s5r (s5r); 2374 cleanup_s5r (s5r);
2401
2402 return; 2375 return;
2403 } 2376 }
2404 2377
@@ -2429,8 +2402,6 @@ do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2429 struct Socks5Request *s5r = cls; 2402 struct Socks5Request *s5r = cls;
2430 2403
2431 s5r->fwdrtask = GNUNET_SCHEDULER_NO_TASK; 2404 s5r->fwdrtask = GNUNET_SCHEDULER_NO_TASK;
2432
2433
2434 if ((NULL != tc->write_ready) && 2405 if ((NULL != tc->write_ready) &&
2435 (GNUNET_NETWORK_fdset_isset (tc->read_ready, s5r->remote_sock)) && 2406 (GNUNET_NETWORK_fdset_isset (tc->read_ready, s5r->remote_sock)) &&
2436 (s5r->wbuf_len = GNUNET_NETWORK_socket_recv (s5r->remote_sock, s5r->wbuf, 2407 (s5r->wbuf_len = GNUNET_NETWORK_socket_recv (s5r->remote_sock, s5r->wbuf,
@@ -2442,7 +2413,7 @@ do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2442 } 2413 }
2443 else 2414 else
2444 { 2415 {
2445 if (s5r->wbuf_len == 0) 2416 if (0 == s5r->wbuf_len)
2446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2447 "0 bytes received from remote... graceful shutdown!\n"); 2418 "0 bytes received from remote... graceful shutdown!\n");
2448 if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK) 2419 if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK)
@@ -2460,8 +2431,7 @@ do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2460 2431
2461 s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 2432 s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
2462 s5r->sock, 2433 s5r->sock,
2463 &do_write, s5r); 2434 &do_write, s5r);
2464
2465} 2435}
2466 2436
2467 2437
@@ -2699,7 +2669,7 @@ accept_cb (void* cls, const struct sockaddr *addr, socklen_t addrlen)
2699static int 2669static int
2700add_handle_to_ssl_mhd (struct GNUNET_NETWORK_Handle *h, const char* domain) 2670add_handle_to_ssl_mhd (struct GNUNET_NETWORK_Handle *h, const char* domain)
2701{ 2671{
2702 struct MhdHttpList *hd = NULL; 2672 struct MhdHttpList *hd;
2703 struct ProxyGNSCertificate *pgc; 2673 struct ProxyGNSCertificate *pgc;
2704 struct NetworkHandleList *nh; 2674 struct NetworkHandleList *nh;
2705 2675
@@ -2781,7 +2751,6 @@ do_read (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2781 struct socks5_server_hello *s_hello; 2751 struct socks5_server_hello *s_hello;
2782 struct socks5_client_request *c_req; 2752 struct socks5_client_request *c_req;
2783 struct socks5_server_response *s_resp; 2753 struct socks5_server_response *s_resp;
2784
2785 int ret; 2754 int ret;
2786 char domain[256]; 2755 char domain[256];
2787 uint8_t dom_len; 2756 uint8_t dom_len;
@@ -2790,7 +2759,6 @@ do_read (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2790 uint32_t remote_ip; 2759 uint32_t remote_ip;
2791 struct sockaddr_in remote_addr; 2760 struct sockaddr_in remote_addr;
2792 struct in_addr *r_sin_addr; 2761 struct in_addr *r_sin_addr;
2793
2794 struct NetworkHandleList *nh; 2762 struct NetworkHandleList *nh;
2795 2763
2796 s5r->rtask = GNUNET_SCHEDULER_NO_TASK; 2764 s5r->rtask = GNUNET_SCHEDULER_NO_TASK;
@@ -3100,7 +3068,6 @@ static void
3100do_shutdown (void *cls, 3068do_shutdown (void *cls,
3101 const struct GNUNET_SCHEDULER_TaskContext *tc) 3069 const struct GNUNET_SCHEDULER_TaskContext *tc)
3102{ 3070{
3103
3104 struct MhdHttpList *hd; 3071 struct MhdHttpList *hd;
3105 struct MhdHttpList *tmp_hd; 3072 struct MhdHttpList *tmp_hd;
3106 struct NetworkHandleList *nh; 3073 struct NetworkHandleList *nh;
@@ -3111,9 +3078,6 @@ do_shutdown (void *cls,
3111 3078
3112 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3079 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3113 "Shutting down...\n"); 3080 "Shutting down...\n");
3114
3115 gnutls_global_deinit ();
3116
3117 if (NULL != local_gns_zone) 3081 if (NULL != local_gns_zone)
3118 GNUNET_free (local_gns_zone); 3082 GNUNET_free (local_gns_zone);
3119 if (NULL != local_private_zone) 3083 if (NULL != local_private_zone)
@@ -3142,13 +3106,11 @@ do_shutdown (void *cls,
3142 GNUNET_SCHEDULER_cancel (hd->httpd_task); 3106 GNUNET_SCHEDULER_cancel (hd->httpd_task);
3143 hd->httpd_task = GNUNET_SCHEDULER_NO_TASK; 3107 hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
3144 } 3108 }
3145
3146 if (NULL != hd->daemon) 3109 if (NULL != hd->daemon)
3147 { 3110 {
3148 MHD_stop_daemon (hd->daemon); 3111 MHD_stop_daemon (hd->daemon);
3149 hd->daemon = NULL; 3112 hd->daemon = NULL;
3150 } 3113 }
3151
3152 for (nh = hd->socket_handles_head; nh != NULL; nh = tmp_nh) 3114 for (nh = hd->socket_handles_head; nh != NULL; nh = tmp_nh)
3153 { 3115 {
3154 tmp_nh = nh->next; 3116 tmp_nh = nh->next;
@@ -3200,12 +3162,11 @@ do_shutdown (void *cls,
3200 GNUNET_free_non_null (pdata->value); 3162 GNUNET_free_non_null (pdata->value);
3201 GNUNET_free (pdata); 3163 GNUNET_free (pdata);
3202 } 3164 }
3203
3204 GNUNET_free (ctask); 3165 GNUNET_free (ctask);
3205 } 3166 }
3206 curl_multi_cleanup (curl_multi); 3167 curl_multi_cleanup (curl_multi);
3207
3208 GNUNET_GNS_disconnect (gns_handle); 3168 GNUNET_GNS_disconnect (gns_handle);
3169 gnutls_global_deinit ();
3209} 3170}
3210 3171
3211 3172
@@ -3243,9 +3204,9 @@ static int
3243load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg) 3204load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg)
3244{ 3205{
3245 char *keyfile; 3206 char *keyfile;
3246 struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL; 3207 struct GNUNET_CRYPTO_RsaPrivateKey *key;
3247 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; 3208 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
3248 struct GNUNET_CRYPTO_ShortHashCode *zone = NULL; 3209 struct GNUNET_CRYPTO_ShortHashCode *zone;
3249 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename; 3210 struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
3250 3211
3251 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", 3212 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
@@ -3361,9 +3322,7 @@ run (void *cls, char *const *args, const char *cfgfile,
3361 struct sockaddr_un mhd_unix_sock_addr; 3322 struct sockaddr_un mhd_unix_sock_addr;
3362#endif 3323#endif
3363 3324
3364 curl_multi = curl_multi_init (); 3325 if (NULL == (curl_multi = curl_multi_init ()))
3365
3366 if (NULL == curl_multi)
3367 { 3326 {
3368 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3369 "Failed to create cURL multo handle!\n"); 3328 "Failed to create cURL multo handle!\n");
@@ -3376,8 +3335,8 @@ run (void *cls, char *const *args, const char *cfgfile,
3376 if (NULL == cafile) 3335 if (NULL == cafile)
3377 { 3336 {
3378 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy", 3337 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
3379 "PROXY_CACERT", 3338 "PROXY_CACERT",
3380 &cafile_cfg)) 3339 &cafile_cfg))
3381 { 3340 {
3382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3341 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3383 "Unable to load proxy CA config value!\n"); 3342 "Unable to load proxy CA config value!\n");
@@ -3408,19 +3367,16 @@ run (void *cls, char *const *args, const char *cfgfile,
3408 3367
3409 compile_regex (&re_dotplus, (char*) RE_A_HREF); 3368 compile_regex (&re_dotplus, (char*) RE_A_HREF);
3410 3369
3411 gns_handle = GNUNET_GNS_connect (cfg); 3370 if (NULL == (gns_handle = GNUNET_GNS_connect (cfg)))
3412
3413 if (GNUNET_NO == load_local_zone_key (cfg))
3414 { 3371 {
3415 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3372 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3416 "Unable to load zone!\n"); 3373 "Unable to connect to GNS!\n");
3417 return; 3374 return;
3418 } 3375 }
3419 3376 if (GNUNET_NO == load_local_zone_key (cfg))
3420 if (NULL == gns_handle)
3421 { 3377 {
3422 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3423 "Unable to connect to GNS!\n"); 3379 "Unable to load zone!\n");
3424 return; 3380 return;
3425 } 3381 }
3426 3382
@@ -3477,12 +3433,9 @@ run (void *cls, char *const *args, const char *cfgfile,
3477 "Specify PROXY_UNIXPATH in gns-proxy config section!\n"); 3433 "Specify PROXY_UNIXPATH in gns-proxy config section!\n");
3478 return; 3434 return;
3479 } 3435 }
3480 3436 if (NULL == (mhd_unix_socket = GNUNET_NETWORK_socket_create (AF_UNIX,
3481 mhd_unix_socket = GNUNET_NETWORK_socket_create (AF_UNIX, 3437 SOCK_STREAM,
3482 SOCK_STREAM, 3438 0)))
3483 0);
3484
3485 if (NULL == mhd_unix_socket)
3486 { 3439 {
3487 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3440 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3488 "Unable to create unix domain socket!\n"); 3441 "Unable to create unix domain socket!\n");
@@ -3500,7 +3453,6 @@ run (void *cls, char *const *args, const char *cfgfile,
3500#endif 3453#endif
3501 3454
3502 len = strlen (proxy_sockfile) + sizeof(AF_UNIX); 3455 len = strlen (proxy_sockfile) + sizeof(AF_UNIX);
3503
3504 GNUNET_free (proxy_sockfile); 3456 GNUNET_free (proxy_sockfile);
3505 3457
3506 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (mhd_unix_socket, 3458 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (mhd_unix_socket,
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 068a9266e..ba30b56fb 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -44,7 +44,6 @@ static char *shorten_name;
44 */ 44 */
45static char *lookup_name; 45static char *lookup_name;
46 46
47
48/** 47/**
49 * record type to look up (-t option) 48 * record type to look up (-t option)
50 */ 49 */
@@ -60,15 +59,24 @@ static char *auth_name;
60 */ 59 */
61static int raw; 60static int raw;
62 61
62/**
63 * Requested record type.
64 */
63static enum GNUNET_GNS_RecordType rtype; 65static enum GNUNET_GNS_RecordType rtype;
64 66
65/* Handle to lookup request */ 67/**
68 * Handle to lookup request
69 */
66static struct GNUNET_GNS_LookupRequest *lookup_request; 70static struct GNUNET_GNS_LookupRequest *lookup_request;
67 71
68/* Handle to shorten request */ 72/**
73 * Handle to shorten request
74 */
69static struct GNUNET_GNS_ShortenRequest *shorten_request; 75static struct GNUNET_GNS_ShortenRequest *shorten_request;
70 76
71/* Handle to get authority request */ 77/**
78 * Handle to get authority request
79 */
72static struct GNUNET_GNS_GetAuthRequest *getauth_request; 80static struct GNUNET_GNS_GetAuthRequest *getauth_request;
73 81
74 82
@@ -83,21 +91,37 @@ do_shutdown (void *cls,
83 const struct GNUNET_SCHEDULER_TaskContext *tc) 91 const struct GNUNET_SCHEDULER_TaskContext *tc)
84{ 92{
85 if (NULL != lookup_request) 93 if (NULL != lookup_request)
94 {
86 GNUNET_GNS_cancel_lookup_request (lookup_request); 95 GNUNET_GNS_cancel_lookup_request (lookup_request);
87 96 lookup_request = NULL;
97 }
88 if (NULL != shorten_request) 98 if (NULL != shorten_request)
99 {
89 GNUNET_GNS_cancel_shorten_request (shorten_request); 100 GNUNET_GNS_cancel_shorten_request (shorten_request);
90 101 shorten_request = NULL;
102 }
91 if (NULL != getauth_request) 103 if (NULL != getauth_request)
104 {
92 GNUNET_GNS_cancel_get_auth_request (getauth_request); 105 GNUNET_GNS_cancel_get_auth_request (getauth_request);
93 106 getauth_request = NULL;
107 }
94 if (NULL != gns) 108 if (NULL != gns)
109 {
95 GNUNET_GNS_disconnect (gns); 110 GNUNET_GNS_disconnect (gns);
111 gns = NULL;
112 }
96} 113}
97 114
98 115
116/**
117 * Function called with the result of a shorten operation.
118 * Prints the result.
119 *
120 * @param cls a 'const char *' with the original (long) name
121 * @param nshort the shortened name
122 */
99static void 123static void
100process_shorten_result (void* cls, const char* nshort) 124process_shorten_result (void* cls, const char *nshort)
101{ 125{
102 const char *original_name = cls; 126 const char *original_name = cls;
103 127
@@ -110,6 +134,13 @@ process_shorten_result (void* cls, const char* nshort)
110} 134}
111 135
112 136
137/**
138 * Function called with the result of a GADS lookup.
139 *
140 * @param cls the 'const char *' name that was resolved
141 * @param rd_count number of records returned
142 * @param rd array of 'rd_count' records with the results
143 */
113static void 144static void
114process_lookup_result (void* cls, uint32_t rd_count, 145process_lookup_result (void* cls, uint32_t rd_count,
115 const struct GNUNET_NAMESTORE_RecordData *rd) 146 const struct GNUNET_NAMESTORE_RecordData *rd)
@@ -122,7 +153,7 @@ process_lookup_result (void* cls, uint32_t rd_count,
122 lookup_request = NULL; 153 lookup_request = NULL;
123 if (!raw) 154 if (!raw)
124 { 155 {
125 if (rd_count == 0) 156 if (0 == rd_count)
126 printf("No results.\n"); 157 printf("No results.\n");
127 else 158 else
128 printf("%s:\n", name); 159 printf("%s:\n", name);
@@ -143,8 +174,16 @@ process_lookup_result (void* cls, uint32_t rd_count,
143} 174}
144 175
145 176
177/**
178 * Function called with the result of an authority lookup.
179 *
180 * @param cls the 'const char *' with the name for which the
181 * authority was resolved
182 * @param auth name of the authority
183 */
146static void 184static void
147process_auth_result (void* cls, const char* auth) 185process_auth_result (void* cls,
186 const char *auth)
148{ 187{
149 getauth_request = NULL; 188 getauth_request = NULL;
150 printf ("%s\n", auth); 189 printf ("%s\n", auth);
@@ -254,14 +293,16 @@ run (void *cls, char *const *args, const char *cfgfile,
254 else 293 else
255 rtype = GNUNET_GNS_RECORD_A; 294 rtype = GNUNET_GNS_RECORD_A;
256 295
257 if ((NULL != shorten_name) && (NULL != shorten_zone) && (NULL != private_zone)) 296 if ( (NULL != shorten_name) &&
297 (NULL != shorten_zone) &&
298 (NULL != private_zone) )
258 { 299 {
259 shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name, 300 shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name,
260 private_zone, 301 private_zone,
261 shorten_zone, 302 shorten_zone,
262 zone, 303 zone,
263 &process_shorten_result, 304 &process_shorten_result,
264 shorten_name); 305 shorten_name);
265 } 306 }
266 if (NULL != lookup_name) 307 if (NULL != lookup_name)
267 { 308 {
@@ -270,7 +311,8 @@ run (void *cls, char *const *args, const char *cfgfile,
270 rtype, 311 rtype,
271 GNUNET_NO, /* Use DHT */ 312 GNUNET_NO, /* Use DHT */
272 shorten_key, 313 shorten_key,
273 &process_lookup_result, lookup_name); 314 &process_lookup_result,
315 lookup_name);
274 } 316 }
275 if (NULL != auth_name) 317 if (NULL != auth_name)
276 { 318 {
@@ -285,16 +327,15 @@ run (void *cls, char *const *args, const char *cfgfile,
285 if (NULL != private_zone) 327 if (NULL != private_zone)
286 GNUNET_free (private_zone); 328 GNUNET_free (private_zone);
287 329
288 if ((NULL == auth_name) && 330 if ( (NULL == auth_name) &&
289 (NULL == shorten_name) && 331 (NULL == shorten_name) &&
290 (NULL == lookup_name)) 332 (NULL == lookup_name))
291 { 333 {
292 fprintf (stderr, 334 fprintf (stderr,
293 _("Please specify lookup, shorten or authority operation!\n")); 335 _("Please specify lookup, shorten or authority operation!\n"));
294 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 336 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
295 return; 337 return;
296 } 338 }
297
298 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 339 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
299 &do_shutdown, NULL); 340 &do_shutdown, NULL);
300} 341}
@@ -328,7 +369,6 @@ main (int argc, char *const *argv)
328 &GNUNET_GETOPT_set_one, &raw}, 369 &GNUNET_GETOPT_set_one, &raw},
329 GNUNET_GETOPT_OPTION_END 370 GNUNET_GETOPT_OPTION_END
330 }; 371 };
331
332 int ret; 372 int ret;
333 373
334 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 374 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 88e1f9d58..dc22efdab 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -72,6 +72,7 @@ struct ClientShortenHandle
72 * List for all shorten requests 72 * List for all shorten requests
73 */ 73 */
74 struct ClientShortenHandle *next; 74 struct ClientShortenHandle *next;
75
75 /** 76 /**
76 * List for all shorten requests 77 * List for all shorten requests
77 */ 78 */
@@ -83,9 +84,29 @@ struct ClientShortenHandle
83 struct GNUNET_SERVER_Client *client; 84 struct GNUNET_SERVER_Client *client;
84 85
85 /** 86 /**
87 * Namestore lookup task
88 */
89 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
90
91 /**
92 * master zone
93 */
94 struct GNUNET_CRYPTO_ShortHashCode root_zone;
95
96 /**
97 * private zone
98 */
99 struct GNUNET_CRYPTO_ShortHashCode private_zone;
100
101 /**
102 * shorten zone
103 */
104 struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
105
106 /**
86 * The request id 107 * The request id
87 */ 108 */
88 uint64_t request_id; 109 uint32_t request_id;
89 110
90 /** 111 /**
91 * request type 112 * request type
@@ -106,26 +127,7 @@ struct ClientShortenHandle
106 * name of shorten zone (relative to root) 127 * name of shorten zone (relative to root)
107 */ 128 */
108 char shorten_zone_id[MAX_DNS_NAME_LENGTH]; 129 char shorten_zone_id[MAX_DNS_NAME_LENGTH];
109
110 /**
111 * master zone
112 */
113 struct GNUNET_CRYPTO_ShortHashCode root_zone;
114
115 /**
116 * private zone
117 */
118 struct GNUNET_CRYPTO_ShortHashCode private_zone;
119
120 /**
121 * shorten zone
122 */
123 struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
124 130
125 /**
126 * Namestore lookup task
127 */
128 struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
129}; 131};
130 132
131 133
@@ -135,18 +137,20 @@ struct ClientShortenHandle
135struct ClientGetAuthHandle 137struct ClientGetAuthHandle
136{ 138{
137 /** 139 /**
138 * Handle to the requesting client */ 140 * Handle to the requesting client
141 */
139 struct GNUNET_SERVER_Client *client; 142 struct GNUNET_SERVER_Client *client;
140 143
141 /** 144 /**
142 * request id 145 * name to lookup authority
143 */ 146 */
144 uint64_t request_id; 147 char *name;
145 148
146 /** 149 /**
147 * name to lookup authority 150 * request id
148 */ 151 */
149 char *name; 152 uint32_t request_id;
153
150}; 154};
151 155
152 156
@@ -162,34 +166,34 @@ struct ClientLookupHandle
162 struct GNUNET_SERVER_Client *client; 166 struct GNUNET_SERVER_Client *client;
163 167
164 /** 168 /**
165 * The zone we look up in 169 * optional zone private key used for shorten
166 */ 170 */
167 struct GNUNET_CRYPTO_ShortHashCode zone; 171 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
168 172
169 /** 173 /**
170 * GNUNET_YES if we only want to lookup from local cache 174 * the name to look up
171 */ 175 */
172 int only_cached; 176 char *name;
173 177
174 /** 178 /**
175 * request id 179 * The zone we look up in
176 */ 180 */
177 uint64_t request_id; 181 struct GNUNET_CRYPTO_ShortHashCode zone;
178 182
179 /** 183 /**
180 * request type 184 * request id
181 */ 185 */
182 enum GNUNET_GNS_RecordType type; 186 uint32_t request_id;
183 187
184 /** 188 /**
185 * optional zone private key used for shorten 189 * GNUNET_YES if we only want to lookup from local cache
186 */ 190 */
187 struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key; 191 int only_cached;
188 192
189 /** 193 /**
190 * the name to look up 194 * request type
191 */ 195 */
192 char *name; 196 enum GNUNET_GNS_RecordType type;
193}; 197};
194 198
195 199
@@ -306,19 +310,36 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
306 while (NULL != (csh_tmp = csh_head)) 310 while (NULL != (csh_tmp = csh_head))
307 { 311 {
308 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp); 312 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp);
309 GNUNET_free(csh_tmp); 313 GNUNET_free (csh_tmp);
310 } 314 }
311 GNUNET_SERVER_notification_context_destroy (nc); 315 GNUNET_SERVER_notification_context_destroy (nc);
312 gns_interceptor_stop (); 316 gns_interceptor_stop ();
313 gns_resolver_cleanup (); 317 gns_resolver_cleanup ();
314 if (NULL != statistics) 318 if (NULL != statistics)
319 {
315 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO); 320 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
316 if (zone_publish_task != GNUNET_SCHEDULER_NO_TASK) 321 statistics = NULL;
322 }
323 if (GNUNET_SCHEDULER_NO_TASK != zone_publish_task)
324 {
317 GNUNET_SCHEDULER_cancel (zone_publish_task); 325 GNUNET_SCHEDULER_cancel (zone_publish_task);
326 zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
327 }
318 if (NULL != namestore_iter) 328 if (NULL != namestore_iter)
329 {
319 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); 330 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
320 GNUNET_NAMESTORE_disconnect(namestore_handle); 331 namestore_iter = NULL;
321 GNUNET_DHT_disconnect(dht_handle); 332 }
333 if (NULL != namestore_handle)
334 {
335 GNUNET_NAMESTORE_disconnect (namestore_handle);
336 namestore_handle = NULL;
337 }
338 if (NULL != dht_handle)
339 {
340 GNUNET_DHT_disconnect (dht_handle);
341 dht_handle = NULL;
342 }
322} 343}
323 344
324 345
@@ -345,7 +366,7 @@ publish_zone_dht_next (void *cls,
345 */ 366 */
346static void 367static void
347publish_zone_dht_start (void *cls, 368publish_zone_dht_start (void *cls,
348 const struct GNUNET_SCHEDULER_TaskContext *tc); 369 const struct GNUNET_SCHEDULER_TaskContext *tc);
349 370
350 371
351/** 372/**
@@ -360,7 +381,7 @@ publish_zone_dht_start (void *cls,
360 * @param signature the signature for the record data 381 * @param signature the signature for the record data
361 */ 382 */
362static void 383static void
363put_gns_record(void *cls, 384put_gns_record (void *cls,
364 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 385 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
365 struct GNUNET_TIME_Absolute expiration, 386 struct GNUNET_TIME_Absolute expiration,
366 const char *name, 387 const char *name,
@@ -389,19 +410,17 @@ put_gns_record(void *cls,
389 * we can safely set the interval to the value for a single 410 * we can safely set the interval to the value for a single
390 * record 411 * record
391 */ 412 */
392 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, 413 put_interval = zone_publish_time_window;
393 1);
394
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
396 "No records in db.\n"); 415 "No records in db.\n");
397 } 416 }
398 else 417 else
399 { 418 {
400 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, 419 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
401 num_public_records); 420 num_public_records);
402 } 421 }
403 put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL, 422 put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
404 put_interval); 423 put_interval);
405 424
406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
407 "Zone iteration finished. Adjusted zone iteration interval to %s\n", 426 "Zone iteration finished. Adjusted zone iteration interval to %s\n",
@@ -484,7 +503,8 @@ put_gns_record(void *cls,
484 GNUNET_STRINGS_relative_time_to_string (DHT_OPERATION_TIMEOUT, GNUNET_YES)); 503 GNUNET_STRINGS_relative_time_to_string (DHT_OPERATION_TIMEOUT, GNUNET_YES));
485 504
486 GNUNET_STATISTICS_update (statistics, 505 GNUNET_STATISTICS_update (statistics,
487 "Record bytes put into DHT", rd_payload_length, GNUNET_NO); 506 "Record bytes put into DHT",
507 rd_payload_length, GNUNET_NO);
488 508
489 (void) GNUNET_DHT_put (dht_handle, &dht_key, 509 (void) GNUNET_DHT_put (dht_handle, &dht_key,
490 DHT_GNS_REPLICATION_LEVEL, 510 DHT_GNS_REPLICATION_LEVEL,
@@ -505,7 +525,7 @@ put_gns_record(void *cls,
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
506 "Last record count was lower than current record count. Reducing interval.\n"); 526 "Last record count was lower than current record count. Reducing interval.\n");
507 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window, 527 put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
508 num_public_records); 528 num_public_records);
509 next_put_interval = GNUNET_TIME_relative_divide (put_interval, 529 next_put_interval = GNUNET_TIME_relative_divide (put_interval,
510 LATE_ITERATION_SPEEDUP_FACTOR); 530 LATE_ITERATION_SPEEDUP_FACTOR);
511 } 531 }
@@ -517,8 +537,8 @@ put_gns_record(void *cls,
517 next_put_interval.rel_value, 537 next_put_interval.rel_value,
518 GNUNET_NO); 538 GNUNET_NO);
519 zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval, 539 zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval,
520 &publish_zone_dht_next, 540 &publish_zone_dht_next,
521 NULL); 541 NULL);
522} 542}
523 543
524 544
@@ -529,11 +549,13 @@ put_gns_record(void *cls,
529 * @param tc task context 549 * @param tc task context
530 */ 550 */
531static void 551static void
532publish_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 552publish_zone_dht_start (void *cls,
553 const struct GNUNET_SCHEDULER_TaskContext *tc)
533{ 554{
534 zone_publish_task = GNUNET_SCHEDULER_NO_TASK; 555 zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
535 556
536 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n"); 557 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
558 "Scheduling DHT zone update!\n");
537 /* start counting again */ 559 /* start counting again */
538 num_public_records = 0; 560 num_public_records = 0;
539 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle, 561 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
@@ -561,7 +583,8 @@ send_shorten_response (void* cls, const char* name)
561 struct GNUNET_GNS_ClientShortenResultMessage *rmsg; 583 struct GNUNET_GNS_ClientShortenResultMessage *rmsg;
562 size_t name_len; 584 size_t name_len;
563 585
564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n", 586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
587 "Sending `%s' message with %s\n",
565 "SHORTEN_RESULT", name); 588 "SHORTEN_RESULT", name);
566 if (NULL == name) 589 if (NULL == name)
567 name_len = 0; 590 name_len = 0;
@@ -616,9 +639,8 @@ process_shorten_in_private_zone_lookup (void *cls,
616 639
617 csh->namestore_task = NULL; 640 csh->namestore_task = NULL;
618 if (0 == strcmp (csh->private_zone_id, "")) 641 if (0 == strcmp (csh->private_zone_id, ""))
619 pzone = NULL; 642 pzone = NULL;
620 643 if (0 == rd_count)
621 if (rd_count == 0)
622 { 644 {
623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
624 "No shorten zone in private zone!\n"); 646 "No shorten zone in private zone!\n");
@@ -627,17 +649,14 @@ process_shorten_in_private_zone_lookup (void *cls,
627 } 649 }
628 else 650 else
629 { 651 {
630 GNUNET_assert (rd_count == 1); 652 GNUNET_break (1 == rd_count);
631
632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
633 "Shorten zone %s found in private zone %s\n", 654 "Shorten zone %s found in private zone %s\n",
634 name, csh->private_zone_id); 655 name, csh->private_zone_id);
635 656
636 sprintf (csh->shorten_zone_id, "%s.%s", name, csh->private_zone_id); 657 sprintf (csh->shorten_zone_id, "%s.%s", name, csh->private_zone_id);
637 } 658 }
638
639 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); 659 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
640
641 gns_resolver_shorten_name (&csh->root_zone, 660 gns_resolver_shorten_name (&csh->root_zone,
642 pzone, 661 pzone,
643 szone, 662 szone,
@@ -663,12 +682,12 @@ process_shorten_in_private_zone_lookup (void *cls,
663 */ 682 */
664static void 683static void
665process_shorten_in_root_zone_lookup (void *cls, 684process_shorten_in_root_zone_lookup (void *cls,
666 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, 685 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
667 struct GNUNET_TIME_Absolute expiration, 686 struct GNUNET_TIME_Absolute expiration,
668 const char *name, 687 const char *name,
669 unsigned int rd_count, 688 unsigned int rd_count,
670 const struct GNUNET_NAMESTORE_RecordData *rd, 689 const struct GNUNET_NAMESTORE_RecordData *rd,
671 const struct GNUNET_CRYPTO_RsaSignature *signature) 690 const struct GNUNET_CRYPTO_RsaSignature *signature)
672{ 691{
673 struct ClientShortenHandle *csh = cls; 692 struct ClientShortenHandle *csh = cls;
674 struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone; 693 struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
@@ -677,17 +696,14 @@ process_shorten_in_root_zone_lookup (void *cls,
677 csh->namestore_task = NULL; 696 csh->namestore_task = NULL;
678 if (0 == strcmp (csh->private_zone_id, "")) 697 if (0 == strcmp (csh->private_zone_id, ""))
679 pzone = NULL; 698 pzone = NULL;
680 699 if (0 == rd_count)
681 if (rd_count == 0)
682 { 700 {
683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
684 "No shorten zone in zone and no private zone!\n"); 702 "No shorten zone in zone and no private zone!\n");
685 703
686 strcpy (csh->shorten_zone_id, ""); 704 strcpy (csh->shorten_zone_id, "");
687
688 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh); 705 GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
689 szone = NULL; 706 szone = NULL;
690
691 gns_resolver_shorten_name (&csh->root_zone, 707 gns_resolver_shorten_name (&csh->root_zone,
692 pzone, 708 pzone,
693 szone, 709 szone,
@@ -697,19 +713,15 @@ process_shorten_in_root_zone_lookup (void *cls,
697 &send_shorten_response, csh); 713 &send_shorten_response, csh);
698 return; 714 return;
699 } 715 }
700 716 GNUNET_break (rd_count == 1);
701 GNUNET_assert (rd_count == 1);
702
703 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 717 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
704 "Private zone %s found in root zone\n", name); 718 "Private zone %s found in root zone\n", name);
705
706 strcpy (csh->private_zone_id, name); 719 strcpy (csh->private_zone_id, name);
707
708 csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle, 720 csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
709 pzone, 721 pzone,
710 szone, 722 szone,
711 &process_shorten_in_private_zone_lookup, 723 &process_shorten_in_private_zone_lookup,
712 csh); 724 csh);
713} 725}
714 726
715 727
@@ -723,7 +735,6 @@ process_shorten_in_root_zone_lookup (void *cls,
723 * @param rd_count number of records found 735 * @param rd_count number of records found
724 * @param rd record data 736 * @param rd record data
725 * @param signature 737 * @param signature
726 *
727 */ 738 */
728static void 739static void
729process_private_in_root_zone_lookup (void *cls, 740process_private_in_root_zone_lookup (void *cls,
@@ -763,25 +774,6 @@ process_private_in_root_zone_lookup (void *cls,
763 774
764 775
765/** 776/**
766 * Lookup the zone infos and shorten name
767 *
768 * @param csh the shorten handle
769 *
770 */
771static void
772start_shorten_name (struct ClientShortenHandle *csh)
773{
774 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
775 "Looking for private zone name in root zone\n");
776 csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
777 &csh->root_zone,
778 &csh->private_zone,
779 &process_private_in_root_zone_lookup,
780 csh);
781}
782
783
784/**
785 * Handle a shorten message from the api 777 * Handle a shorten message from the api
786 * 778 *
787 * @param cls the closure (unused) 779 * @param cls the closure (unused)
@@ -800,7 +792,8 @@ handle_shorten (void *cls,
800 uint16_t msg_size; 792 uint16_t msg_size;
801 const struct GNUNET_GNS_ClientShortenMessage *sh_msg; 793 const struct GNUNET_GNS_ClientShortenMessage *sh_msg;
802 794
803 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN"); 795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
796 "Received `%s' message\n", "SHORTEN");
804 msg_size = ntohs (message->size); 797 msg_size = ntohs (message->size);
805 if (msg_size < sizeof (struct GNUNET_GNS_ClientShortenMessage)) 798 if (msg_size < sizeof (struct GNUNET_GNS_ClientShortenMessage))
806 { 799 {
@@ -861,7 +854,11 @@ handle_shorten (void *cls,
861 csh->root_zone = zone_hash; //Default zone 854 csh->root_zone = zone_hash; //Default zone
862 else 855 else
863 csh->root_zone = sh_msg->zone; 856 csh->root_zone = sh_msg->zone;
864 start_shorten_name (csh); 857 csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
858 &csh->root_zone,
859 &csh->private_zone,
860 &process_private_in_root_zone_lookup,
861 csh);
865 GNUNET_STATISTICS_update (statistics, 862 GNUNET_STATISTICS_update (statistics,
866 "Name shorten attempts", 1, GNUNET_NO); 863 "Name shorten attempts", 1, GNUNET_NO);
867 GNUNET_SERVER_receive_done (client, GNUNET_OK); 864 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -872,10 +869,11 @@ handle_shorten (void *cls,
872 * Send get authority response back to client 869 * Send get authority response back to client
873 * 870 *
874 * @param cls the closure containing a client get auth handle 871 * @param cls the closure containing a client get auth handle
875 * @param name the shortened name result or NULL if cannot be shortened 872 * @param name the name of the authority, or NULL on error
876 */ 873 */
877static void 874static void
878send_get_auth_response(void *cls, const char* name) 875send_get_auth_response (void *cls,
876 const char* name)
879{ 877{
880 struct ClientGetAuthHandle *cah = cls; 878 struct ClientGetAuthHandle *cah = cls;
881 struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg; 879 struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
@@ -890,21 +888,20 @@ send_get_auth_response(void *cls, const char* name)
890 } 888 }
891 if (NULL == name) 889 if (NULL == name)
892 name = ""; 890 name = "";
893 rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) 891 rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage)
894 + strlen(name) + 1); 892 + strlen (name) + 1);
895 893
896 rmsg->id = cah->request_id; 894 rmsg->id = cah->request_id;
897 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT); 895 rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT);
898 rmsg->header.size = 896 rmsg->header.size =
899 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) + 897 htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
900 strlen(name) + 1); 898 strlen (name) + 1);
901 strcpy ((char*)&rmsg[1], name); 899 strcpy ((char*)&rmsg[1], name);
902 900
903 GNUNET_SERVER_notification_context_unicast (nc, cah->client, 901 GNUNET_SERVER_notification_context_unicast (nc, cah->client,
904 &rmsg->header, 902 &rmsg->header,
905 GNUNET_NO); 903 GNUNET_NO);
906 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK); 904 GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
907
908 GNUNET_free(rmsg); 905 GNUNET_free(rmsg);
909 GNUNET_free_non_null(cah->name); 906 GNUNET_free_non_null(cah->name);
910 GNUNET_free(cah); 907 GNUNET_free(cah);
@@ -930,12 +927,13 @@ handle_get_authority (void *cls,
930 uint16_t msg_size; 927 uint16_t msg_size;
931 const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg; 928 const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg;
932 929
933 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH"); 930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
931 "Received `%s' message\n", "GET_AUTH");
934 msg_size = ntohs(message->size); 932 msg_size = ntohs(message->size);
935 if (msg_size < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) 933 if (msg_size < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
936 { 934 {
937 GNUNET_break (0); 935 GNUNET_break (0);
938 GNUNET_SERVER_receive_done (client, GNUNET_OK); 936 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
939 return; 937 return;
940 } 938 }
941 GNUNET_SERVER_notification_context_add (nc, client); 939 GNUNET_SERVER_notification_context_add (nc, client);
@@ -967,17 +965,17 @@ handle_get_authority (void *cls,
967 send_get_auth_response(cah, name); 965 send_get_auth_response(cah, name);
968 return; 966 return;
969 } 967 }
970 if (0 != strcmp (name + strlen (name) - strlen(GNUNET_GNS_TLD), 968 if (0 != strcmp (name + strlen (name) - strlen (GNUNET_GNS_TLD),
971 GNUNET_GNS_TLD)) 969 GNUNET_GNS_TLD))
972 { 970 {
973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 971 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
974 "GET_AUTH: %s is not our domain. Returning\n", name); 972 "GET_AUTH: %s is not our domain. Returning\n", name);
975 cah->name = NULL; 973 cah->name = NULL;
976 send_get_auth_response(cah, name); 974 send_get_auth_response (cah, name);
977 return; 975 return;
978 } 976 }
979 977
980 if (0 == strcmp(name, GNUNET_GNS_TLD)) 978 if (0 == strcmp (name, GNUNET_GNS_TLD))
981 { 979 {
982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
983 "GET_AUTH: %s is us. Returning\n", name); 981 "GET_AUTH: %s is us. Returning\n", name);
@@ -988,8 +986,8 @@ handle_get_authority (void *cls,
988 986
989 cah->name = GNUNET_malloc (strlen (name) 987 cah->name = GNUNET_malloc (strlen (name)
990 - strlen (GNUNET_GNS_TLD) + 1); 988 - strlen (GNUNET_GNS_TLD) + 1);
991 memcpy(cah->name, name, 989 memcpy (cah->name, name,
992 strlen (name) - strlen (GNUNET_GNS_TLD)); 990 strlen (name) - strlen (GNUNET_GNS_TLD));
993 991
994 /* Start delegation resolution in our namestore */ 992 /* Start delegation resolution in our namestore */
995 gns_resolver_get_authority (zone_hash, zone_hash, name, 993 gns_resolver_get_authority (zone_hash, zone_hash, name,
@@ -999,7 +997,6 @@ handle_get_authority (void *cls,
999} 997}
1000 998
1001 999
1002
1003/** 1000/**
1004 * Reply to client with the result from our lookup. 1001 * Reply to client with the result from our lookup.
1005 * 1002 *
@@ -1008,9 +1005,9 @@ handle_get_authority (void *cls,
1008 * @param rd the record data 1005 * @param rd the record data
1009 */ 1006 */
1010static void 1007static void
1011send_lookup_response(void* cls, 1008send_lookup_response (void* cls,
1012 uint32_t rd_count, 1009 uint32_t rd_count,
1013 const struct GNUNET_NAMESTORE_RecordData *rd) 1010 const struct GNUNET_NAMESTORE_RecordData *rd)
1014{ 1011{
1015 struct ClientLookupHandle* clh = cls; 1012 struct ClientLookupHandle* clh = cls;
1016 struct GNUNET_GNS_ClientLookupResultMessage *rmsg; 1013 struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
@@ -1020,8 +1017,7 @@ send_lookup_response(void* cls,
1020 "LOOKUP_RESULT", rd_count); 1017 "LOOKUP_RESULT", rd_count);
1021 1018
1022 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 1019 len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1023 rmsg = GNUNET_malloc ( 1020 rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
1024 len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
1025 1021
1026 rmsg->id = clh->request_id; 1022 rmsg->id = clh->request_id;
1027 rmsg->rd_count = htonl(rd_count); 1023 rmsg->rd_count = htonl(rd_count);
@@ -1041,11 +1037,10 @@ send_lookup_response(void* cls,
1041 1037
1042 if (NULL != clh->shorten_key) 1038 if (NULL != clh->shorten_key)
1043 GNUNET_CRYPTO_rsa_key_free (clh->shorten_key); 1039 GNUNET_CRYPTO_rsa_key_free (clh->shorten_key);
1044 GNUNET_free(clh); 1040 GNUNET_free (clh);
1045
1046 GNUNET_STATISTICS_update (statistics, 1041 GNUNET_STATISTICS_update (statistics,
1047 "Completed lookups", 1, GNUNET_NO); 1042 "Completed lookups", 1, GNUNET_NO);
1048 if (rd != NULL) 1043 if (NULL != rd)
1049 GNUNET_STATISTICS_update (statistics, 1044 GNUNET_STATISTICS_update (statistics,
1050 "Records resolved", rd_count, GNUNET_NO); 1045 "Records resolved", rd_count, GNUNET_NO);
1051} 1046}
@@ -1059,9 +1054,9 @@ send_lookup_response(void* cls,
1059 * @param message the message 1054 * @param message the message
1060 */ 1055 */
1061static void 1056static void
1062handle_lookup(void *cls, 1057handle_lookup (void *cls,
1063 struct GNUNET_SERVER_Client * client, 1058 struct GNUNET_SERVER_Client * client,
1064 const struct GNUNET_MessageHeader * message) 1059 const struct GNUNET_MessageHeader * message)
1065{ 1060{
1066 size_t namelen; 1061 size_t namelen;
1067 char name[MAX_DNS_NAME_LENGTH]; 1062 char name[MAX_DNS_NAME_LENGTH];
@@ -1075,13 +1070,13 @@ handle_lookup(void *cls,
1075 uint16_t msg_size; 1070 uint16_t msg_size;
1076 const struct GNUNET_GNS_ClientLookupMessage *sh_msg; 1071 const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
1077 1072
1078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); 1073 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1079 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP"); 1074 "Received `%s' message\n", "LOOKUP");
1080 msg_size = ntohs(message->size); 1075 msg_size = ntohs(message->size);
1081 if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage)) 1076 if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage))
1082 { 1077 {
1083 GNUNET_break (0); 1078 GNUNET_break (0);
1084 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1079 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1085 return; 1080 return;
1086 } 1081 }
1087 sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message; 1082 sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message;
@@ -1103,10 +1098,10 @@ handle_lookup(void *cls,
1103 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1098 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1104 return; 1099 return;
1105 } 1100 }
1106 GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr); 1101 GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
1107 } 1102 }
1108 1103
1109 namelen = strlen(name)+1; 1104 namelen = strlen (name) + 1;
1110 clh = GNUNET_malloc (sizeof (struct ClientLookupHandle)); 1105 clh = GNUNET_malloc (sizeof (struct ClientLookupHandle));
1111 memset (clh, 0, sizeof (struct ClientLookupHandle)); 1106 memset (clh, 0, sizeof (struct ClientLookupHandle));
1112 clh->client = client; 1107 clh->client = client;
@@ -1126,7 +1121,7 @@ handle_lookup(void *cls,
1126 return; 1121 return;
1127 } 1122 }
1128 1123
1129 if ((clh->type == GNUNET_GNS_RECORD_A) && 1124 if ((GNUNET_GNS_RECORD_A == clh->type) &&
1130 (GNUNET_OK != v4_enabled)) 1125 (GNUNET_OK != v4_enabled))
1131 { 1126 {
1132 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1127 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -1136,7 +1131,7 @@ handle_lookup(void *cls,
1136 return; 1131 return;
1137 } 1132 }
1138 1133
1139 if ((clh->type == GNUNET_GNS_RECORD_AAAA) && 1134 if ((GNUNET_GNS_RECORD_AAAA == clh->type) &&
1140 (GNUNET_OK != v6_enabled)) 1135 (GNUNET_OK != v6_enabled))
1141 { 1136 {
1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1167,44 +1162,15 @@ handle_lookup(void *cls,
1167 only_cached, 1162 only_cached,
1168 &send_lookup_response, clh); 1163 &send_lookup_response, clh);
1169 } 1164 }
1170
1171 GNUNET_STATISTICS_update (statistics, 1165 GNUNET_STATISTICS_update (statistics,
1172 "Record lookup attempts", 1, GNUNET_NO); 1166 "Record lookup attempts", 1, GNUNET_NO);
1173} 1167}
1174 1168
1175 1169
1176/** 1170/**
1177 * Test if the given AF is supported by this system.
1178 *
1179 * @param af to test
1180 * @return GNUNET_OK if the AF is supported
1181 */
1182static int
1183test_af (int af)
1184{
1185 int s;
1186
1187 s = socket (af, SOCK_STREAM, 0);
1188 if (-1 == s)
1189 {
1190 if (EAFNOSUPPORT == errno)
1191 return GNUNET_NO;
1192 fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
1193 return GNUNET_SYSERR;
1194 }
1195#if WINDOWS
1196 closesocket (s);
1197#else
1198 close (s);
1199#endif
1200 return GNUNET_OK;
1201}
1202
1203
1204/**
1205 * Process GNS requests. 1171 * Process GNS requests.
1206 * 1172 *
1207 * @param cls closure) 1173 * @param cls closure
1208 * @param server the initialized server 1174 * @param server the initialized server
1209 * @param c configuration to use 1175 * @param c configuration to use
1210 */ 1176 */
@@ -1212,23 +1178,21 @@ static void
1212run (void *cls, struct GNUNET_SERVER_Handle *server, 1178run (void *cls, struct GNUNET_SERVER_Handle *server,
1213 const struct GNUNET_CONFIGURATION_Handle *c) 1179 const struct GNUNET_CONFIGURATION_Handle *c)
1214{ 1180{
1215 char* keyfile;
1216 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
1217 unsigned long long max_parallel_bg_queries = 0;
1218 unsigned long long default_lookup_timeout_secs = 0;
1219 int ignore_pending = GNUNET_NO;
1220
1221 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 1181 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
1222 {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0}, 1182 {&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0},
1223 {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0}, 1183 {&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
1224 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0} 1184 {&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
1225 }; 1185 };
1186 char* keyfile;
1187 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
1188 unsigned long long max_parallel_bg_queries = 0;
1189 int ignore_pending = GNUNET_NO;
1226 1190
1227 v6_enabled = test_af (AF_INET6); 1191 v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
1228 v4_enabled = test_af (AF_INET); 1192 v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
1229 1193
1230 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns", 1194 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
1231 "ZONEKEY", &keyfile)) 1195 "ZONEKEY", &keyfile))
1232 { 1196 {
1233 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1234 "No private key for root zone specified!\n"); 1198 "No private key for root zone specified!\n");
@@ -1241,7 +1205,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1241 1205
1242 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1206 zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1243 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey); 1207 GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
1244
1245 GNUNET_CRYPTO_short_hash(&pkey, 1208 GNUNET_CRYPTO_short_hash(&pkey,
1246 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1209 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1247 &zone_hash); 1210 &zone_hash);
@@ -1260,76 +1223,69 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1260 GNUNET_CONFIGURATION_get_value_yesno (c, "gns", 1223 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
1261 "AUTO_IMPORT_PKEY")) 1224 "AUTO_IMPORT_PKEY"))
1262 { 1225 {
1263 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1264 "Automatic PKEY import is enabled.\n"); 1227 "Automatic PKEY import is enabled.\n");
1265 auto_import_pkey = GNUNET_YES; 1228 auto_import_pkey = GNUNET_YES;
1266
1267 } 1229 }
1268
1269 put_interval = INITIAL_PUT_INTERVAL; 1230 put_interval = INITIAL_PUT_INTERVAL;
1270
1271 zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW; 1231 zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
1272 1232
1273 if (GNUNET_OK == 1233 if (GNUNET_OK ==
1274 GNUNET_CONFIGURATION_get_value_time (c, "gns", 1234 GNUNET_CONFIGURATION_get_value_time (c, "gns",
1275 "ZONE_PUBLISH_TIME_WINDOW", 1235 "ZONE_PUBLISH_TIME_WINDOW",
1276 &zone_publish_time_window)) 1236 &zone_publish_time_window))
1277 { 1237 {
1278 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1279 "Time window for zone iteration: %s\n", 1239 "Time window for zone iteration: %s\n",
1280 GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window, GNUNET_YES)); 1240 GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window, GNUNET_YES));
1281 } 1241 }
1282
1283 if (GNUNET_OK == 1242 if (GNUNET_OK ==
1284 GNUNET_CONFIGURATION_get_value_number (c, "gns", 1243 GNUNET_CONFIGURATION_get_value_number (c, "gns",
1285 "MAX_PARALLEL_BACKGROUND_QUERIES", 1244 "MAX_PARALLEL_BACKGROUND_QUERIES",
1286 &max_parallel_bg_queries)) 1245 &max_parallel_bg_queries))
1287 { 1246 {
1288 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1289 "Number of allowed parallel background queries: %llu\n", 1248 "Number of allowed parallel background queries: %llu\n",
1290 max_parallel_bg_queries); 1249 max_parallel_bg_queries);
1291 } 1250 }
1292 1251
1293 if (GNUNET_YES == 1252 if (GNUNET_YES ==
1294 GNUNET_CONFIGURATION_get_value_yesno (c, "gns", 1253 GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
1295 "AUTO_IMPORT_CONFIRMATION_REQ")) 1254 "AUTO_IMPORT_CONFIRMATION_REQ"))
1296 { 1255 {
1297 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1298 "Auto import requires user confirmation\n"); 1257 "Auto import requires user confirmation\n");
1299 ignore_pending = GNUNET_YES; 1258 ignore_pending = GNUNET_YES;
1300 } 1259 }
1301 1260
1302 if (GNUNET_OK == 1261 if (GNUNET_OK ==
1303 GNUNET_CONFIGURATION_get_value_number(c, "gns", 1262 GNUNET_CONFIGURATION_get_value_time (c, "gns",
1304 "DEFAULT_LOOKUP_TIMEOUT", 1263 "DEFAULT_LOOKUP_TIMEOUT",
1305 &default_lookup_timeout_secs)) 1264 &default_lookup_timeout))
1306 { 1265 {
1307 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1308 "Default lookup timeout: %llus\n", default_lookup_timeout_secs); 1267 "Default lookup timeout: %s\n",
1309 default_lookup_timeout = GNUNET_TIME_relative_multiply( 1268 GNUNET_STRINGS_relative_time_to_string (default_lookup_timeout,
1310 GNUNET_TIME_UNIT_SECONDS, 1269 GNUNET_YES));
1311 default_lookup_timeout_secs);
1312 } 1270 }
1313 1271
1314 /** 1272 dht_handle = GNUNET_DHT_connect (c,
1315 * handle to the dht 1273 (unsigned int) max_parallel_bg_queries);
1316 */
1317 dht_handle = GNUNET_DHT_connect(c,
1318 //max_parallel_bg_queries); //FIXME get ht_len from cfg
1319 1024);
1320
1321 if (NULL == dht_handle) 1274 if (NULL == dht_handle)
1322 { 1275 {
1323 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n"); 1276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1277 _("Could not connect to DHT!\n"));
1278 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
1279 return;
1324 } 1280 }
1325 1281
1326 if (gns_resolver_init(namestore_handle, dht_handle, zone_hash, c, 1282 if (GNUNET_SYSERR ==
1327 max_parallel_bg_queries, 1283 gns_resolver_init (namestore_handle, dht_handle, zone_hash, c,
1328 ignore_pending) 1284 max_parallel_bg_queries,
1329 == GNUNET_SYSERR) 1285 ignore_pending))
1330 { 1286 {
1331 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1287 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1332 "Unable to initialize resolver!\n"); 1288 _("Unable to initialize resolver!\n"));
1333 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 1289 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
1334 return; 1290 return;
1335 } 1291 }
@@ -1354,18 +1310,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1354 */ 1310 */
1355 first_zone_iteration = GNUNET_YES; 1311 first_zone_iteration = GNUNET_YES;
1356 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL); 1312 zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL);
1357
1358 GNUNET_SERVER_add_handlers (server, handlers); 1313 GNUNET_SERVER_add_handlers (server, handlers);
1359
1360 //FIXME
1361 //GNUNET_SERVER_disconnect_notify (server,
1362 // &client_disconnect_notification,
1363 // NULL);
1364
1365 statistics = GNUNET_STATISTICS_create ("gns", c); 1314 statistics = GNUNET_STATISTICS_create ("gns", c);
1366
1367 nc = GNUNET_SERVER_notification_context_create (server, 1); 1315 nc = GNUNET_SERVER_notification_context_create (server, 1);
1368
1369 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 1316 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
1370 NULL); 1317 NULL);
1371} 1318}
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index 0081bc833..9c1c3a666 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) 3 (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -17,9 +17,7 @@
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20
21/** 20/**
22 *
23 * @file gns/gnunet-service-gns_interceptor.c 21 * @file gns/gnunet-service-gns_interceptor.c
24 * @brief GNUnet GNS interceptor logic 22 * @brief GNUnet GNS interceptor logic
25 * @author Martin Schanzenbach 23 * @author Martin Schanzenbach
@@ -86,8 +84,8 @@ static struct GNUNET_TIME_Relative default_lookup_timeout;
86 * @param rd the record data 84 * @param rd the record data
87 */ 85 */
88static void 86static void
89reply_to_dns(void* cls, uint32_t rd_count, 87reply_to_dns (void* cls, uint32_t rd_count,
90 const struct GNUNET_NAMESTORE_RecordData *rd) 88 const struct GNUNET_NAMESTORE_RecordData *rd)
91{ 89{
92 uint32_t i; 90 uint32_t i;
93 size_t len; 91 size_t len;
@@ -199,23 +197,25 @@ reply_to_dns(void* cls, uint32_t rd_count,
199 1024, /* FIXME magic from dns redirector */ 197 1024, /* FIXME magic from dns redirector */
200 &buf, 198 &buf,
201 &len); 199 &len);
202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
203 "Built DNS response! (ret=%d,len=%d)\n", ret, len); 201 "Built DNS response! (ret=%d,len=%d)\n",
202 ret, len);
204 if (ret == GNUNET_OK) 203 if (ret == GNUNET_OK)
205 { 204 {
206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Answering DNS request\n"); 206 "Answering DNS request\n");
208 GNUNET_DNS_request_answer(ilh->request_handle, 207 GNUNET_DNS_request_answer (ilh->request_handle,
209 len, 208 len,
210 buf); 209 buf);
211 210
212 GNUNET_free(buf); 211 GNUNET_free (buf);
213 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answered DNS request\n"); 212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "Answered DNS request\n");
214 } 214 }
215 else 215 else
216 { 216 {
217 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
218 "Error building DNS response! (ret=%d)", ret); 218 "Error building DNS response! (ret=%d)", ret);
219 } 219 }
220 220
221 packet->num_answers = 0; 221 packet->num_answers = 0;
@@ -236,8 +236,8 @@ reply_to_dns(void* cls, uint32_t rd_count,
236 * @param q the DNS query we received parsed from p 236 * @param q the DNS query we received parsed from p
237 */ 237 */
238static void 238static void
239start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request, 239start_resolution_for_dns (struct GNUNET_DNS_RequestHandle *request,
240 struct GNUNET_DNSPARSER_Packet *p, 240 struct GNUNET_DNSPARSER_Packet *p,
241 struct GNUNET_DNSPARSER_Query *q) 241 struct GNUNET_DNSPARSER_Query *q)
242{ 242{
243 struct InterceptLookupHandle* ilh; 243 struct InterceptLookupHandle* ilh;
@@ -245,7 +245,6 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
246 "Starting resolution for %s (type=%d)!\n", 246 "Starting resolution for %s (type=%d)!\n",
247 q->name, q->type); 247 q->name, q->type);
248
249 ilh = GNUNET_malloc(sizeof(struct InterceptLookupHandle)); 248 ilh = GNUNET_malloc(sizeof(struct InterceptLookupHandle));
250 ilh->packet = p; 249 ilh->packet = p;
251 ilh->query = q; 250 ilh->query = q;
@@ -260,7 +259,6 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
260} 259}
261 260
262 261
263
264/** 262/**
265 * The DNS request handler 263 * The DNS request handler
266 * Called for every incoming DNS request. 264 * Called for every incoming DNS request.
@@ -271,17 +269,16 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
271 * @param request udp payload of the DNS request 269 * @param request udp payload of the DNS request
272 */ 270 */
273static void 271static void
274handle_dns_request(void *cls, 272handle_dns_request (void *cls,
275 struct GNUNET_DNS_RequestHandle *rh, 273 struct GNUNET_DNS_RequestHandle *rh,
276 size_t request_length, 274 size_t request_length,
277 const char *request) 275 const char *request)
278{ 276{
279 struct GNUNET_DNSPARSER_Packet *p; 277 struct GNUNET_DNSPARSER_Packet *p;
280 278
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacked a DNS request...processing\n"); 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
282 p = GNUNET_DNSPARSER_parse (request, request_length); 280 "Hijacked a DNS request...processing\n");
283 281 if (NULL == (p = GNUNET_DNSPARSER_parse (request, request_length)))
284 if (NULL == p)
285 { 282 {
286 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 283 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
287 "Received malformed DNS packet, leaving it untouched\n"); 284 "Received malformed DNS packet, leaving it untouched\n");
@@ -302,7 +299,7 @@ handle_dns_request(void *cls,
302 * The way it is implemented here now is buggy and will lead to erratic 299 * The way it is implemented here now is buggy and will lead to erratic
303 * behaviour (if multiple queries are present). 300 * behaviour (if multiple queries are present).
304 */ 301 */
305 if (p->num_queries == 0) 302 if (0 == p->num_queries)
306 { 303 {
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "No Queries in DNS packet... forwarding\n"); 305 "No Queries in DNS packet... forwarding\n");
@@ -311,14 +308,6 @@ handle_dns_request(void *cls,
311 return; 308 return;
312 } 309 }
313 310
314 if (p->num_queries > 1)
315 {
316 /* Note: We could also look for .gads */
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
318 ">1 queriy in DNS packet... odd. We only process #1\n");
319 }
320
321
322 /** 311 /**
323 * Check for .gads/.zkey 312 * Check for .gads/.zkey
324 */ 313 */
@@ -327,19 +316,23 @@ handle_dns_request(void *cls,
327 (is_zkey_tld(p->queries[0].name) == GNUNET_YES) || 316 (is_zkey_tld(p->queries[0].name) == GNUNET_YES) ||
328 (strcmp(p->queries[0].name, GNUNET_GNS_TLD) == 0)) 317 (strcmp(p->queries[0].name, GNUNET_GNS_TLD) == 0))
329 { 318 {
330 start_resolution_for_dns(rh, p, p->queries); 319 if (p->num_queries > 1)
331 } 320 {
332 else 321 /* Note: We could also look for .gads */
333 { 322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
334 /** 323 ">1 queriy in DNS packet... odd. We only process #1\n");
335 * This request does not concern us. Forward to real DNS. 324 }
336 */ 325 start_resolution_for_dns (rh, p, p->queries);
337 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 326 return;
338 "Request for %s is forwarded to DNS\n", p->queries[0].name);
339 GNUNET_DNS_request_forward (rh);
340 GNUNET_DNSPARSER_free_packet (p);
341 } 327 }
342 328 /**
329 * This request does not concern us. Forward to real DNS.
330 */
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Request for %s is forwarded to DNS\n",
333 p->queries[0].name);
334 GNUNET_DNS_request_forward (rh);
335 GNUNET_DNSPARSER_free_packet (p);
343} 336}
344 337
345 338
@@ -352,53 +345,48 @@ handle_dns_request(void *cls,
352 * @return GNUNET_OK on success 345 * @return GNUNET_OK on success
353 */ 346 */
354int 347int
355gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone, 348gns_interceptor_init (struct GNUNET_CRYPTO_ShortHashCode zone,
356 struct GNUNET_CRYPTO_RsaPrivateKey *key, 349 struct GNUNET_CRYPTO_RsaPrivateKey *key,
357 const struct GNUNET_CONFIGURATION_Handle *c) 350 const struct GNUNET_CONFIGURATION_Handle *c)
358{ 351{
359 unsigned long long default_lookup_timeout_secs = 0;
360
361 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 352 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
362 "DNS hijacking enabled... connecting to service.\n"); 353 "DNS hijacking enabled... connecting to service.\n");
363
364 our_zone = zone; 354 our_zone = zone;
365 our_key = key; 355 our_key = key;
366 /** 356 /**
367 * Do gnunet dns init here 357 * Do gnunet dns init here
368 */ 358 */
369 dns_handle = GNUNET_DNS_connect(c, 359 dns_handle = GNUNET_DNS_connect (c,
370 GNUNET_DNS_FLAG_PRE_RESOLUTION, 360 GNUNET_DNS_FLAG_PRE_RESOLUTION,
371 &handle_dns_request, /* rh */ 361 &handle_dns_request, /* rh */
372 NULL); /* Closure */ 362 NULL); /* Closure */
373 363
374 if (GNUNET_OK == 364 if (GNUNET_OK !=
375 GNUNET_CONFIGURATION_get_value_number(c, "gns", 365 GNUNET_CONFIGURATION_get_value_time (c, "gns",
376 "DEFAULT_LOOKUP_TIMEOUT", 366 "DEFAULT_LOOKUP_TIMEOUT",
377 &default_lookup_timeout_secs)) 367 &default_lookup_timeout))
378 { 368 default_lookup_timeout = GNUNET_TIME_UNIT_ZERO;
379 default_lookup_timeout = GNUNET_TIME_relative_multiply(
380 GNUNET_TIME_UNIT_SECONDS,
381 default_lookup_timeout_secs);
382 }
383
384 if (NULL == dns_handle) 369 if (NULL == dns_handle)
385 { 370 {
386 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 371 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
387 "Failed to connect to the dnsservice!\n"); 372 "Failed to connect to the dnsservice!\n");
388 return GNUNET_SYSERR; 373 return GNUNET_SYSERR;
389 } 374 }
390
391 return GNUNET_YES; 375 return GNUNET_YES;
392} 376}
393 377
378
394/** 379/**
395 * Disconnect from interceptor 380 * Disconnect from interceptor
396 */ 381 */
397void 382void
398gns_interceptor_stop(void) 383gns_interceptor_stop ()
399{ 384{
400 if (dns_handle) 385 if (NULL != dns_handle)
386 {
401 GNUNET_DNS_disconnect(dns_handle); 387 GNUNET_DNS_disconnect(dns_handle);
388 dns_handle = NULL;
389 }
402} 390}
403 391
404/* end of gns_interceptor.c */ 392/* end of gns_interceptor.c */
diff --git a/src/gns/gnunet-service-gns_interceptor.h b/src/gns/gnunet-service-gns_interceptor.h
index dc39aecef..613ce8cdc 100644
--- a/src/gns/gnunet-service-gns_interceptor.h
+++ b/src/gns/gnunet-service-gns_interceptor.h
@@ -1,6 +1,32 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_interceptor.h
22 * @brief GNUnet GNS service
23 * @author Martin Schanzenbach
24 */
1#ifndef GNUNET_GNS_INTERCEPTOR_H 25#ifndef GNUNET_GNS_INTERCEPTOR_H
2#define GNUNET_GNS_INTERCEPTOR_H 26#define GNUNET_GNS_INTERCEPTOR_H
3 27
28#include "gnunet_util_lib.h"
29
4/** 30/**
5 * Initialize dns interceptor 31 * Initialize dns interceptor
6 * 32 *
@@ -10,14 +36,14 @@
10 * @return GNUNET_YES on success GNUNET_SYSERR on error 36 * @return GNUNET_YES on success GNUNET_SYSERR on error
11 */ 37 */
12int 38int
13gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone, 39gns_interceptor_init (struct GNUNET_CRYPTO_ShortHashCode zone,
14 struct GNUNET_CRYPTO_RsaPrivateKey *key, 40 struct GNUNET_CRYPTO_RsaPrivateKey *key,
15 const struct GNUNET_CONFIGURATION_Handle *c); 41 const struct GNUNET_CONFIGURATION_Handle *c);
16 42
17/** 43/**
18 * Stops the interceptor 44 * Stops the interceptor
19 */ 45 */
20void 46void
21gns_interceptor_stop(void); 47gns_interceptor_stop (void);
22 48
23#endif 49#endif
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 964f798d0..7391efbf8 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -186,6 +186,7 @@ is_srv (char* name)
186 return ret; 186 return ret;
187} 187}
188 188
189
189/** 190/**
190 * Determine if this name is canonical (is a legal name in a zone, without delegation); 191 * Determine if this name is canonical (is a legal name in a zone, without delegation);
191 * note that we do not test that the name does not contain illegal characters, we only 192 * note that we do not test that the name does not contain illegal characters, we only
@@ -1490,6 +1491,7 @@ handle_dns_resolver (void *cls,
1490 finish_lookup (rh, rlh, 1, &rd); 1491 finish_lookup (rh, rlh, 1, &rd);
1491} 1492}
1492 1493
1494
1493/** 1495/**
1494 * Resolve DNS name via local stub resolver 1496 * Resolve DNS name via local stub resolver
1495 * 1497 *
@@ -3960,7 +3962,7 @@ process_zone_to_name_shorten_root (void *cls,
3960 * @param rd_count number of results (0) 3962 * @param rd_count number of results (0)
3961 * @param rd data (NULL) 3963 * @param rd data (NULL)
3962 */ 3964 */
3963void 3965static void
3964handle_delegation_ns_shorten (void* cls, 3966handle_delegation_ns_shorten (void* cls,
3965 struct ResolverHandle *rh, 3967 struct ResolverHandle *rh,
3966 uint32_t rd_count, 3968 uint32_t rd_count,
@@ -4289,7 +4291,7 @@ finish_get_auth (struct ResolverHandle *rh,
4289 * @param rd_count number of results (0) 4291 * @param rd_count number of results (0)
4290 * @param rd data (NULL) 4292 * @param rd data (NULL)
4291 */ 4293 */
4292void 4294static void
4293handle_delegation_result_ns_get_auth(void* cls, 4295handle_delegation_result_ns_get_auth(void* cls,
4294 struct ResolverHandle *rh, 4296 struct ResolverHandle *rh,
4295 uint32_t rd_count, 4297 uint32_t rd_count,
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index b24fd1274..e8bb74697 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -1,3 +1,27 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file gns/gnunet-service-gns_resolver.h
22 * @brief GNUnet GNS service
23 * @author Martin Schanzenbach
24 */
1#ifndef GNS_RESOLVER_H 25#ifndef GNS_RESOLVER_H
2#define GNS_RESOLVER_H 26#define GNS_RESOLVER_H
3 27
@@ -5,12 +29,16 @@
5#include "gnunet_dht_service.h" 29#include "gnunet_dht_service.h"
6 30
7#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 31#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
32
8#define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \ 33#define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \
9 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
35
10#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT 36#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
37
11#define DHT_GNS_REPLICATION_LEVEL 5 38#define DHT_GNS_REPLICATION_LEVEL 5
12 39
13#define GNUNET_GNS_MAX_PARALLEL_LOOKUPS 500 40#define GNUNET_GNS_MAX_PARALLEL_LOOKUPS 500
41
14#define GNUNET_GNS_MAX_NS_TASKS 500 42#define GNUNET_GNS_MAX_NS_TASKS 500
15 43
16/* 44/*
@@ -23,17 +51,26 @@ struct AuthorityChain
23 51
24 struct AuthorityChain *next; 52 struct AuthorityChain *next;
25 53
26 /* the zone hash of the authority */ 54 /**
55 * the zone hash of the authority
56 */
27 struct GNUNET_CRYPTO_ShortHashCode zone; 57 struct GNUNET_CRYPTO_ShortHashCode zone;
28 58
29 /* (local) name of the authority */ 59 /**
60 * (local) name of the authority
61 */
30 char name[MAX_DNS_LABEL_LENGTH]; 62 char name[MAX_DNS_LABEL_LENGTH];
31 63
32 /* was the ns entry fresh */ 64 /**
65 * was the ns entry fresh
66 */
33 int fresh; 67 int fresh;
34}; 68};
35 69
36/* handle to a resolution process */ 70
71/**
72 * handle to a resolution process
73 */
37struct ResolverHandle; 74struct ResolverHandle;
38 75
39 76
@@ -45,8 +82,8 @@ struct ResolverHandle;
45 * @param rd result data 82 * @param rd result data
46 */ 83 */
47typedef void (*RecordLookupProcessor) (void *cls, 84typedef void (*RecordLookupProcessor) (void *cls,
48 uint32_t rd_count, 85 uint32_t rd_count,
49 const struct GNUNET_NAMESTORE_RecordData *rd); 86 const struct GNUNET_NAMESTORE_RecordData *rd);
50 87
51 88
52/** 89/**
@@ -55,16 +92,18 @@ typedef void (*RecordLookupProcessor) (void *cls,
55 * @param cls the closure 92 * @param cls the closure
56 * @param name shortened name 93 * @param name shortened name
57 */ 94 */
58typedef void (*ShortenResultProcessor) (void *cls, const char* name); 95typedef void (*ShortenResultProcessor) (void *cls,
96 const char* name);
59 97
60 98
61/** 99/**
62 * processor for an authority result 100 * processor for an authority result
63 * 101 *
64 * @param cls the closure 102 * @param cls the closure
65 * @param name name 103 * @param name name of the authority
66 */ 104 */
67typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name); 105typedef void (*GetAuthorityResultProcessor) (void *cls,
106 const char* name);
68 107
69/** 108/**
70 * processor for a resolution result 109 * processor for a resolution result
@@ -72,34 +111,57 @@ typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
72 * @param cls the closure 111 * @param cls the closure
73 * @param rh the resolution handle 112 * @param rh the resolution handle
74 * @param rd_count number of results 113 * @param rd_count number of results
75 * @param rd result data 114 * @param rd result data (array of 'rd_count' records)
76 */ 115 */
77typedef void (*ResolutionResultProcessor) (void *cls, 116typedef void (*ResolutionResultProcessor) (void *cls,
78 struct ResolverHandle *rh, 117 struct ResolverHandle *rh,
79 uint32_t rd_count, 118 uint32_t rd_count,
80 const struct GNUNET_NAMESTORE_RecordData *rd); 119 const struct GNUNET_NAMESTORE_RecordData *rd);
81 120
82 121
83/** 122/**
84 * Resolution status indicator 123 * Resolution status indicator
85 * RSL_RECORD_EXISTS: the name to lookup exists
86 * RSL_RECORD_EXPIRED: the name in the record expired
87 * RSL_TIMED_OUT: resolution timed out
88 * RSL_DELEGATE_VPN: Found VPN delegation
89 * RSL_DELEGATE_NS: Found NS delegation
90 * RSL_DELEGATE_PKEY: Found PKEY delegation
91 * RSL_CNAME_FOUND: Found CNAME record
92 * RSL_PKEY_REVOKED: Found PKEY has been revoked
93 */ 124 */
94enum ResolutionStatus 125enum ResolutionStatus
95{ 126{
127 /**
128 * the name to lookup exists
129 */
96 RSL_RECORD_EXISTS = 1, 130 RSL_RECORD_EXISTS = 1,
131
132 /**
133 * the name in the record expired
134 */
97 RSL_RECORD_EXPIRED = 2, 135 RSL_RECORD_EXPIRED = 2,
136
137 /**
138 * resolution timed out
139 */
98 RSL_TIMED_OUT = 4, 140 RSL_TIMED_OUT = 4,
141
142 /**
143 * Found VPN delegation
144 */
99 RSL_DELEGATE_VPN = 8, 145 RSL_DELEGATE_VPN = 8,
146
147 /**
148 * Found NS delegation
149 */
100 RSL_DELEGATE_NS = 16, 150 RSL_DELEGATE_NS = 16,
151
152 /**
153 * Found PKEY delegation
154 */
101 RSL_DELEGATE_PKEY = 32, 155 RSL_DELEGATE_PKEY = 32,
156
157 /**
158 * Found CNAME record
159 */
102 RSL_CNAME_FOUND = 64, 160 RSL_CNAME_FOUND = 64,
161
162 /**
163 * Found PKEY has been revoked
164 */
103 RSL_PKEY_REVOKED = 128 165 RSL_PKEY_REVOKED = 128
104}; 166};
105 167
@@ -116,91 +178,149 @@ enum ResolutionStatus
116struct ResolverHandle 178struct ResolverHandle
117{ 179{
118 180
119 /* DLL */ 181 /**
182 * DLL
183 */
120 struct ResolverHandle *next; 184 struct ResolverHandle *next;
121 185
122 /* DLL */ 186 /**
187 * DLL
188 */
123 struct ResolverHandle *prev; 189 struct ResolverHandle *prev;
124 190
125 /* Last record data found */ 191 /**
192 * Last record data found
193 */
126 struct GNUNET_NAMESTORE_RecordData rd; 194 struct GNUNET_NAMESTORE_RecordData rd;
127 195
128 /* Number of last record data found */ 196 /**
197 * Number of last record data found
198 */
129 unsigned int rd_count; 199 unsigned int rd_count;
130 200
131 /* The name to resolve */ 201 /**
202 * The name to resolve
203 */
132 char name[MAX_DNS_NAME_LENGTH]; 204 char name[MAX_DNS_NAME_LENGTH];
133 205
134 /* has this query been answered? how many matches */ 206 /**
207 * has this query been answered? how many matches
208 */
135 int answered; 209 int answered;
136 210
137 /* Use only cache */ 211 /**
212 * Use only cache
213 */
138 int only_cached; 214 int only_cached;
139 215
140 /* the authoritative zone to query */ 216 /**
217 * the authoritative zone to query
218 */
141 struct GNUNET_CRYPTO_ShortHashCode authority; 219 struct GNUNET_CRYPTO_ShortHashCode authority;
142 220
143 /* the name of the authoritative zone to query */ 221 /**
222 * the name of the authoritative zone to query
223 */
144 char authority_name[MAX_DNS_LABEL_LENGTH]; 224 char authority_name[MAX_DNS_LABEL_LENGTH];
145 225
146 /* a handle for dht lookups. should be NULL if no lookups are in progress */ 226 /**
227 * a handle for dht lookups. should be NULL if no lookups are in progress
228 */
147 struct GNUNET_DHT_GetHandle *get_handle; 229 struct GNUNET_DHT_GetHandle *get_handle;
148 230
149 /* timeout set for this lookup task */ 231 /**
232 * timeout set for this lookup task
233 */
150 struct GNUNET_TIME_Relative timeout; 234 struct GNUNET_TIME_Relative timeout;
151 235
152 /* a handle to a vpn request */ 236 /**
237 * a handle to a vpn request
238 */
153 struct GNUNET_VPN_RedirectionRequest *vpn_handle; 239 struct GNUNET_VPN_RedirectionRequest *vpn_handle;
154 240
155 /* a socket for a dns request */ 241 /**
242 * a socket for a dns request
243 */
156 struct GNUNET_NETWORK_Handle *dns_sock; 244 struct GNUNET_NETWORK_Handle *dns_sock;
157 245
158 /* a synthesized dns name */ 246 /**
247 * a synthesized dns name
248 */
159 char dns_name[MAX_DNS_NAME_LENGTH]; 249 char dns_name[MAX_DNS_NAME_LENGTH];
160 250
161 /* the authoritative dns zone */ 251 /**
252 * the authoritative dns zone
253 */
162 char dns_zone[MAX_DNS_NAME_LENGTH]; 254 char dns_zone[MAX_DNS_NAME_LENGTH];
163 255
164 /* the address of the DNS server FIXME not needed? */ 256 /**
257 * the address of the DNS server FIXME not needed?
258 */
165 struct sockaddr_in dns_addr; 259 struct sockaddr_in dns_addr;
166 260
167 /* handle to the local stub resolver request */ 261 /**
262 * handle to the local stub resolver request
263 */
168 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle; 264 struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
169 265
170 /* select task for DNS */ 266 /**
267 * select task for DNS
268 */
171 GNUNET_SCHEDULER_TaskIdentifier dns_read_task; 269 GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
172 270
173 /* pointer to raw dns query payload FIXME needs to be freed/NULL */ 271 /**
272 * pointer to raw dns query payload FIXME needs to be freed/NULL
273 */
174 char *dns_raw_packet; 274 char *dns_raw_packet;
175 275
176 /* size of the raw dns query */ 276 /**
277 * size of the raw dns query
278 */
177 size_t dns_raw_packet_size; 279 size_t dns_raw_packet_size;
178 280
179 /* timeout task for the lookup */ 281 /**
282 * timeout task for the lookup
283 */
180 GNUNET_SCHEDULER_TaskIdentifier timeout_task; 284 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
181 285
182 /* continuation to call on timeout */ 286 /**
287 * continuation to call on timeout
288 */
183 GNUNET_SCHEDULER_Task timeout_cont; 289 GNUNET_SCHEDULER_Task timeout_cont;
184 290
185 /* closure for timeout cont */ 291 /**
292 * closure for timeout cont
293 */
186 void* timeout_cont_cls; 294 void* timeout_cont_cls;
187 295
188 /* called when resolution phase finishes */ 296 /**
297 * called when resolution phase finishes
298 */
189 ResolutionResultProcessor proc; 299 ResolutionResultProcessor proc;
190 300
191 /* closure passed to proc */ 301 /**
302 * closure passed to proc
303 */
192 void* proc_cls; 304 void* proc_cls;
193 305
194 /* DLL to store the authority chain */ 306 /**
307 * DLL to store the authority chain
308 */
195 struct AuthorityChain *authority_chain_head; 309 struct AuthorityChain *authority_chain_head;
196 310
197 /* DLL to store the authority chain */ 311 /**
312 * DLL to store the authority chain
313 */
198 struct AuthorityChain *authority_chain_tail; 314 struct AuthorityChain *authority_chain_tail;
199 315
200 /* status of the resolution result */ 316 /**
317 * status of the resolution result
318 */
201 enum ResolutionStatus status; 319 enum ResolutionStatus status;
202 320
203 /* The provate local zone of this request */ 321 /**
322 * The provate local zone of this request
323 */
204 struct GNUNET_CRYPTO_ShortHashCode private_local_zone; 324 struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
205 325
206 /** 326 /**
@@ -233,16 +353,24 @@ struct ResolverHandle
233 */ 353 */
234struct RecordLookupHandle 354struct RecordLookupHandle
235{ 355{
236 /* the record type to look up */ 356 /**
357 * the record type to look up
358 */
237 enum GNUNET_GNS_RecordType record_type; 359 enum GNUNET_GNS_RecordType record_type;
238 360
239 /* the name to look up */ 361 /**
362 * the name to look up
363 */
240 char name[MAX_DNS_NAME_LENGTH]; 364 char name[MAX_DNS_NAME_LENGTH];
241 365
242 /* Method to call on record resolution result */ 366 /**
367 * Method to call on record resolution result
368 */
243 RecordLookupProcessor proc; 369 RecordLookupProcessor proc;
244 370
245 /* closure to pass to proc */ 371 /**
372 * closure to pass to proc
373 */
246 void* proc_cls; 374 void* proc_cls;
247 375
248}; 376};
@@ -253,98 +381,150 @@ struct RecordLookupHandle
253 */ 381 */
254struct NameShortenHandle 382struct NameShortenHandle
255{ 383{
256 /* Method to call on shorten result */ 384 /**
385 * Method to call on shorten result
386 */
257 ShortenResultProcessor proc; 387 ShortenResultProcessor proc;
258 388
259 /* closure to pass to proc */ 389 /**
390 * closure to pass to proc
391 */
260 void* proc_cls; 392 void* proc_cls;
261 393
262 /* result of shorten */ 394 /**
395 * result of shorten
396 */
263 char result[MAX_DNS_NAME_LENGTH]; 397 char result[MAX_DNS_NAME_LENGTH];
264 398
265 /* root zone */ 399 /**
400 * root zone
401 */
266 struct GNUNET_CRYPTO_ShortHashCode *root_zone; 402 struct GNUNET_CRYPTO_ShortHashCode *root_zone;
267 403
268 /* private zone */ 404 /**
405 * private zone
406 */
269 struct GNUNET_CRYPTO_ShortHashCode *private_zone; 407 struct GNUNET_CRYPTO_ShortHashCode *private_zone;
270 408
271 /* name of private zone */ 409 /**
410 * name of private zone
411 */
272 char private_zone_name[MAX_DNS_LABEL_LENGTH]; 412 char private_zone_name[MAX_DNS_LABEL_LENGTH];
273 413
274 /* shorten zone */ 414 /**
415 * shorten zone
416 */
275 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone; 417 struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
276 418
277 /* name of shorten zone */ 419 /**
420 * name of shorten zone
421 */
278 char shorten_zone_name[MAX_DNS_LABEL_LENGTH]; 422 char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
279 423
280}; 424};
281 425
426
282/** 427/**
283 * Handle to a get authority context 428 * Handle to a get authority context
284 */ 429 */
285struct GetNameAuthorityHandle 430struct GetNameAuthorityHandle
286{ 431{
287 /* the name to look up authority for */ 432 /**
433 * the name to look up authority for
434 */
288 char name[MAX_DNS_NAME_LENGTH]; 435 char name[MAX_DNS_NAME_LENGTH];
289 436
290 /* the result */ 437 /**
438 * the result
439 */
291 char result[MAX_DNS_NAME_LENGTH]; 440 char result[MAX_DNS_NAME_LENGTH];
292 441
293 /* Method to call on result */ 442 /**
443 * Method to call on result
444 */
294 GetAuthorityResultProcessor proc; 445 GetAuthorityResultProcessor proc;
295 446
296 /* closure to pass to proc */ 447 /**
448 * closure to pass to proc
449 */
297 void* proc_cls; 450 void* proc_cls;
298}; 451};
299 452
453
300/** 454/**
301 * Handle to a pseu lookup 455 * Handle to a pseu lookup
302 */ 456 */
303struct GetPseuAuthorityHandle 457struct GetPseuAuthorityHandle
304{ 458{
305 /* DLL */ 459 /**
460 * DLL
461 */
306 struct GetPseuAuthorityHandle *next; 462 struct GetPseuAuthorityHandle *next;
307 463
308 /* DLL */ 464 /**
465 * DLL
466 */
309 struct GetPseuAuthorityHandle *prev; 467 struct GetPseuAuthorityHandle *prev;
310 468
311 /* the name to store the zone under */ 469 /**
470 * the name to store the zone under
471 */
312 char name[MAX_DNS_LABEL_LENGTH]; 472 char name[MAX_DNS_LABEL_LENGTH];
313 473
314 /* test name to store the zone under */ 474 /**
475 * test name to store the zone under
476 */
315 char test_name[MAX_DNS_LABEL_LENGTH]; 477 char test_name[MAX_DNS_LABEL_LENGTH];
316 478
317 /* the zone of our authority */ 479 /**
480 * the zone of our authority
481 */
318 struct GNUNET_CRYPTO_ShortHashCode our_zone; 482 struct GNUNET_CRYPTO_ShortHashCode our_zone;
319 483
320 /* the private key of the zone to store the pseu in */ 484 /**
485 * the private key of the zone to store the pseu in
486 */
321 struct GNUNET_CRYPTO_RsaPrivateKey *key; 487 struct GNUNET_CRYPTO_RsaPrivateKey *key;
322 488
323 /* a handle for dht lookups. should be NULL if no lookups are in progress */ 489 /**
490 * a handle for dht lookups. should be NULL if no lookups are in progress
491 */
324 struct GNUNET_DHT_GetHandle *get_handle; 492 struct GNUNET_DHT_GetHandle *get_handle;
325 493
326 /* timeout task for lookup */ 494 /**
495 * timeout task for lookup
496 */
327 GNUNET_SCHEDULER_TaskIdentifier timeout; 497 GNUNET_SCHEDULER_TaskIdentifier timeout;
328 498
329 /* Authority to shorten */ 499 /**
500 * Authority to shorten
501 */
330 struct AuthorityChain *auth; 502 struct AuthorityChain *auth;
331 503
332 /* handle to namestore request */ 504 /**
505 * handle to namestore request
506 */
333 struct GNUNET_NAMESTORE_QueueEntry* namestore_task; 507 struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
334}; 508};
335 509
510
336/** 511/**
337 * Namestore queue entries in background 512 * Namestore queue entries in background
338 */ 513 */
339struct NamestoreBGTask 514struct NamestoreBGTask
340{ 515{
341 /* node in heap */ 516 /**
517 * node in heap
518 */
342 struct GNUNET_CONTAINER_HeapNode *node; 519 struct GNUNET_CONTAINER_HeapNode *node;
343 520
344 /* queue entry */ 521 /**
522 * queue entry
523 */
345 struct GNUNET_NAMESTORE_QueueEntry *qe; 524 struct GNUNET_NAMESTORE_QueueEntry *qe;
346}; 525};
347 526
527
348/** 528/**
349 * Initialize the resolver 529 * Initialize the resolver
350 * MUST be called before other gns_resolver_* methods 530 * MUST be called before other gns_resolver_* methods
@@ -359,18 +539,20 @@ struct NamestoreBGTask
359 * @returns GNUNET_OK on success 539 * @returns GNUNET_OK on success
360 */ 540 */
361int 541int
362gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, 542gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
363 struct GNUNET_DHT_Handle *dh, 543 struct GNUNET_DHT_Handle *dh,
364 struct GNUNET_CRYPTO_ShortHashCode lz, 544 struct GNUNET_CRYPTO_ShortHashCode lz,
365 const struct GNUNET_CONFIGURATION_Handle *c, 545 const struct GNUNET_CONFIGURATION_Handle *c,
366 unsigned long long max_bg_queries, 546 unsigned long long max_bg_queries,
367 int ignore_pending); 547 int ignore_pending);
548
368 549
369/** 550/**
370 * Cleanup resolver: Terminate pending lookups 551 * Cleanup resolver: Terminate pending lookups
371 */ 552 */
372void 553void
373gns_resolver_cleanup(void); 554gns_resolver_cleanup (void);
555
374 556
375/** 557/**
376 * Lookup of a record in a specific zone 558 * Lookup of a record in a specific zone
@@ -387,15 +569,16 @@ gns_resolver_cleanup(void);
387 * @param cls the closure to pass to proc 569 * @param cls the closure to pass to proc
388 */ 570 */
389void 571void
390gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone, 572gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
391 struct GNUNET_CRYPTO_ShortHashCode pzone, 573 struct GNUNET_CRYPTO_ShortHashCode pzone,
392 uint32_t record_type, 574 uint32_t record_type,
393 const char* name, 575 const char* name,
394 struct GNUNET_CRYPTO_RsaPrivateKey *key, 576 struct GNUNET_CRYPTO_RsaPrivateKey *key,
395 struct GNUNET_TIME_Relative timeout, 577 struct GNUNET_TIME_Relative timeout,
396 int only_cached, 578 int only_cached,
397 RecordLookupProcessor proc, 579 RecordLookupProcessor proc,
398 void* cls); 580 void* cls);
581
399 582
400/** 583/**
401 * Shortens a name if possible. If the shortening fails 584 * Shortens a name if possible. If the shortening fails
@@ -414,14 +597,15 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
414 * @param proc_cls the closure to pass to proc 597 * @param proc_cls the closure to pass to proc
415 */ 598 */
416void 599void
417gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone, 600gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
418 struct GNUNET_CRYPTO_ShortHashCode *pzone, 601 struct GNUNET_CRYPTO_ShortHashCode *pzone,
419 struct GNUNET_CRYPTO_ShortHashCode *szone, 602 struct GNUNET_CRYPTO_ShortHashCode *szone,
420 const char* name, 603 const char* name,
421 const char* private_zone_name, 604 const char* private_zone_name,
422 const char* shorten_zone_name, 605 const char* shorten_zone_name,
423 ShortenResultProcessor proc, 606 ShortenResultProcessor proc,
424 void* proc_cls); 607 void* proc_cls);
608
425 609
426/** 610/**
427 * Tries to resolve the authority for name 611 * Tries to resolve the authority for name
@@ -434,11 +618,11 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
434 * @param proc_cls the closure to pass to the processor 618 * @param proc_cls the closure to pass to the processor
435 */ 619 */
436void 620void
437gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone, 621gns_resolver_get_authority (struct GNUNET_CRYPTO_ShortHashCode zone,
438 struct GNUNET_CRYPTO_ShortHashCode pzone, 622 struct GNUNET_CRYPTO_ShortHashCode pzone,
439 const char* name, 623 const char* name,
440 GetAuthorityResultProcessor proc, 624 GetAuthorityResultProcessor proc,
441 void* proc_cls); 625 void* proc_cls);
442 626
443/** 627/**
444 * Generic function to check for TLDs 628 * Generic function to check for TLDs
@@ -448,7 +632,9 @@ gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
448 * @return GNUNET_YES or GNUNET_NO 632 * @return GNUNET_YES or GNUNET_NO
449 */ 633 */
450int 634int
451is_tld(const char* name, const char* tld); 635is_tld (const char* name,
636 const char* tld);
637
452 638
453/** 639/**
454 * Checks for gnunet/zkey 640 * Checks for gnunet/zkey
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index a2faecf2d..d8da01f5b 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010, 2012 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -63,17 +63,19 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
63 size_t xquery_size, const void *reply_block, 63 size_t xquery_size, const void *reply_block,
64 size_t reply_block_size) 64 size_t reply_block_size)
65{ 65{
66 const struct GNSNameRecordBlock *nrb;
66 const char* name; 67 const char* name;
68 const char *name_end;
69 const char *rd_data;
67 struct GNUNET_HashCode query_key; 70 struct GNUNET_HashCode query_key;
68 struct GNUNET_HashCode mhash; 71 struct GNUNET_HashCode mhash;
69 struct GNUNET_HashCode chash; 72 struct GNUNET_HashCode chash;
70 struct GNUNET_CRYPTO_ShortHashCode pkey_hash; 73 struct GNUNET_CRYPTO_ShortHashCode pkey_hash;
71 struct GNSNameRecordBlock *nrb;
72 struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp; 74 struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp;
73 struct GNUNET_CRYPTO_HashAsciiEncoded xor_got; 75 struct GNUNET_CRYPTO_HashAsciiEncoded xor_got;
74 uint32_t rd_count; 76 uint32_t rd_count;
75 char* rd_data = NULL; 77 size_t rd_len;
76 int rd_len; 78 size_t name_len;
77 uint32_t record_xquery; 79 uint32_t record_xquery;
78 unsigned int record_match; 80 unsigned int record_match;
79 81
@@ -97,9 +99,15 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
97 99
98 /* this is a reply */ 100 /* this is a reply */
99 101
100 nrb = (struct GNSNameRecordBlock *)reply_block; 102 nrb = (const struct GNSNameRecordBlock *)reply_block;
101 name = (const char*)&nrb[1]; 103 name = (const char*) &nrb[1];
102 104 name_end = memchr (name, 0, reply_block_size - sizeof (struct GNSNameRecordBlock));
105 if (NULL == name_end)
106 {
107 GNUNET_break_op (0);
108 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
109 }
110 name_len = (name_end - name) + 1;
103 GNUNET_CRYPTO_short_hash (&nrb->public_key, 111 GNUNET_CRYPTO_short_hash (&nrb->public_key,
104 sizeof(nrb->public_key), 112 sizeof(nrb->public_key),
105 &pkey_hash); 113 &pkey_hash);
@@ -121,9 +129,8 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
121 129
122 record_match = 0; 130 record_match = 0;
123 rd_count = ntohl(nrb->rd_count); 131 rd_count = ntohl(nrb->rd_count);
124 rd_data = (char*)&nrb[1]; 132 rd_data = &name[name_len];
125 rd_data += strlen(name) + 1; 133 rd_len = reply_block_size - (name_len
126 rd_len = reply_block_size - (strlen(name) + 1
127 + sizeof(struct GNSNameRecordBlock)); 134 + sizeof(struct GNSNameRecordBlock));
128 { 135 {
129 struct GNUNET_NAMESTORE_RecordData rd[rd_count]; 136 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
diff --git a/src/gns/proxy/gnunet-gns-proxy.py b/src/gns/proxy/gnunet-gns-proxy.py
deleted file mode 100644
index 73085bdf5..000000000
--- a/src/gns/proxy/gnunet-gns-proxy.py
+++ /dev/null
@@ -1,226 +0,0 @@
1#!/usr/bin/python
2
3"""
4Copyright (c) 2001 SUZUKI Hisao
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
8The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
10THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11"""
12
13__doc__ = """Tiny HTTP Proxy.
14
15This module implements GET, HEAD, POST, PUT and DELETE methods
16on BaseHTTPServer, and behaves as an HTTP proxy. The CONNECT
17method is also implemented experimentally, but has not been
18tested yet.
19
20Any help will be greatly appreciated. SUZUKI Hisao
21"""
22
23__version__ = "0.2.1"
24
25import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os, sys
26
27class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
28 __base = BaseHTTPServer.BaseHTTPRequestHandler
29 __base_handle = __base.handle
30
31 server_version = "TinyHTTPProxy/" + __version__
32 rbufsize = 0 # self.rfile Be unbuffered
33 host_port = ()
34
35 def handle(self):
36 (ip, port) = self.client_address
37 if hasattr(self, 'allowed_clients') and ip not in self.allowed_clients:
38 self.raw_requestline = self.rfile.readline()
39 if self.parse_request(): self.send_error(403)
40 else:
41 self.__base_handle()
42
43 def _connect_to(self, netloc, soc):
44 i = netloc.find(':')
45 to_replace = ""
46 if i >= 0:
47 self.host_port = netloc[:i], int(netloc[i+1:])
48 if (re.match("(\w+\.)*gnunet$", self.host_port[0])):
49 print 'calling gnunet-gns -a '+netloc[:i]
50 auth = os.popen("gnunet-gns -a "+netloc[:i])
51 lines = auth.readlines()
52 if (len(lines) > 0):
53 print 'result: '+lines[0].split(" ")[-1].rstrip()
54 to_replace = lines[0].split(" ")[-1].rstrip()
55 else:
56 to_replace = "+"
57 else:
58 self.host_port = netloc, 80
59 if (re.match("(\w+\.)*gnunet$", self.host_port[0])):
60 print 'calling gnunet-gns -a '+netloc
61 auth = os.popen("gnunet-gns -a "+netloc)
62 lines = auth.readlines()
63 if (len(lines) > 0):
64 print 'result: '+lines[0].split(" ")[-1].rstrip()
65 to_replace = lines[0].split(" ")[-1].rstrip()
66 else:
67 to_replace = "+"
68
69 print "\t" "connect to %s:%d" % self.host_port
70 try: soc.connect(self.host_port)
71 except socket.error, arg:
72 try: msg = arg[1]
73 except: msg = arg
74 self.send_error(404, msg)
75 return (0, 0)
76 return (1, to_replace)
77
78 def do_CONNECT(self):
79 soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
80 try:
81 res, to_repl = self._connect_to(self.path, soc)
82 if res:
83 self.log_request(200)
84 self.wfile.write(self.protocol_version +
85 " 200 Connection established\r\n")
86 self.wfile.write("Proxy-agent: %s\r\n" % self.version_string())
87 self.wfile.write("\r\n")
88 self._read_write(soc, to_repl, 300)
89 finally:
90 print "\t" "bye"
91 soc.close()
92 self.connection.close()
93
94 def test_re2(self, mo):
95 short = os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', ""))
96 lines = short.readlines()
97 if (len(lines) < 1):
98 return mo.group(1)
99 elif (len(lines[0].split(" ")) > 0):
100 return 'a href="http://'+lines[0].split(" ")[-1].rstrip()
101 else:
102 return mo.group(1)
103
104 def shorten_zkey(self):
105 return lambda mo: self.test_re2(mo)
106 #return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip()
107
108 def test_re(self, to_repl, mo):
109 short = os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', ""))
110 lines = short.readlines()
111 if (len(lines) < 1):
112 return to_repl
113 elif (len(lines[0].split(" ")) > 0):
114 return 'a href="http://'+lines[0].split(" ")[-1].rstrip()
115 else:
116 return to_repl
117
118 def replace_and_shorten(self, to_repl):
119 return lambda mo: self.test_re(to_repl, mo)
120 # return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip()
121 #full = string.replace(mo.group(1)+to_repl, 'a href="http://', "")
122 #print 'calling gnunet-gns -s '+full
123 #s = os.popen("gnunet-gns -s "+full)
124 #lines = s.readlines()
125 #print 'short: '+lines[0].split(" ")[-1].rstrip()
126 #return 'a href="'+lines[0].split(" ")[-1].rstrip()
127
128 def do_GET(self):
129 (scm, netloc, path, params, query, fragment) = urlparse.urlparse(
130 self.path, 'http')
131 if scm != 'http' or fragment or not netloc:
132 self.send_error(400, "bad url %s" % self.path)
133 return
134 soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
135 try:
136 res, to_repl = self._connect_to(netloc, soc)
137 if res:
138 self.log_request()
139 soc.send("%s %s %s\r\n" % (
140 self.command,
141 urlparse.urlunparse(('', '', path, params, query, '')),
142 self.request_version))
143 if (re.match("(\w+\.)*gnunet$", self.headers['Host'])):
144 leho = os.popen("gnunet-gns -t LEHO -u "+self.headers['Host']).readlines()
145 if (len(leho) < 2):
146 print "Legacy hostname lookup failed!"
147 elif (len(leho) == 1):
148 print "Legacy hostname not present!"
149 else:
150 newhost = leho[1].split(" ")[-1].rstrip()
151 print "Changing Host: "+self.headers['Host']+" to "+newhost
152 self.headers['Host'] = newhost
153 self.headers['Connection'] = 'close'
154 del self.headers['Proxy-Connection']
155 del self.headers['Accept-Encoding']
156 for key_val in self.headers.items():
157 soc.send("%s: %s\r\n" % key_val)
158 soc.send("\r\n")
159 self._read_write(soc, to_repl)
160 finally:
161 print "\t" "bye"
162 soc.close()
163 self.connection.close()
164
165 def _read_write(self, soc, to_repl="", max_idling=20):
166 iw = [self.connection, soc]
167 ow = []
168 count = 0
169 msg = ''
170 while 1:
171 count += 1
172 (ins, _, exs) = select.select(iw, ow, iw, 3)
173 if exs:
174 break
175 if ins:
176 for i in ins:
177 if i is soc:
178 out = self.connection
179 else:
180 out = soc
181 data = i.recv(8192)
182 if data:
183 #try:
184 data = re.sub(r'\nAccept-Ranges: \w+', r'', data)
185 data = re.sub('(a href="http://(\w+\.)*zkey)',
186 self.shorten_zkey(), data)
187 if (re.match("(\w+\.)*gnunet$", self.host_port[0])):
188 arr = self.host_port[0].split('.')
189 arr.pop(0)
190 data = re.sub('(a href="http://(\w+\.)*)(\+)',
191 self.replace_and_shorten(to_repl), data)
192 out.send(data)
193 count = 0
194 #except:
195 # print "GNS exception:", sys.exc_info()[0]
196
197 else:
198 print "\t" "idle", count
199 print msg
200 if count == max_idling: break
201
202 do_HEAD = do_GET
203 do_POST = do_GET
204 do_PUT = do_GET
205 do_DELETE=do_GET
206
207class ThreadingHTTPServer (SocketServer.ThreadingMixIn,
208 BaseHTTPServer.HTTPServer): pass
209
210if __name__ == '__main__':
211 from sys import argv
212 if argv[1:] and argv[1] in ('-h', '--help'):
213 print argv[0], "[port [allowed_client_name ...]]"
214 else:
215 if argv[2:]:
216 allowed = []
217 for name in argv[2:]:
218 client = socket.gethostbyname(name)
219 allowed.append(client)
220 print "Accept: %s (%s)" % (client, name)
221 ProxyHandler.allowed_clients = allowed
222 del argv[2:]
223 else:
224 print "Any clients will be served..."
225 BaseHTTPServer.test(ProxyHandler, ThreadingHTTPServer)
226
diff --git a/src/gns/proxy/test_cert.pem b/src/gns/proxy/test_cert.pem
deleted file mode 100644
index 806fd48ff..000000000
--- a/src/gns/proxy/test_cert.pem
+++ /dev/null
@@ -1,51 +0,0 @@
1-----BEGIN CERTIFICATE-----
2MIIEBzCCAu+gAwIBAgIJAI38FT23eNxGMA0GCSqGSIb3DQEBBQUAMIGZMQswCQYD
3VQQGEwJERTEQMA4GA1UECAwHQmF2YXJpYTEPMA0GA1UEBwwGTXVuaWNoMR0wGwYD
4VQQKDBRHTlVuZXQgTmFtaW5nIFN5c3RlbTEPMA0GA1UECwwGR05VbmV0MRUwEwYD
5VQQDDAxHTlMgUHJveHkgQ0ExIDAeBgkqhkiG9w0BCQEWEWJvdW5jZUBnbnVuZXQu
6b3JnMB4XDTEyMDcxNDIwMTQxN1oXDTIyMDcxMjIwMTQxN1owgZkxCzAJBgNVBAYT
7AkRFMRAwDgYDVQQIDAdCYXZhcmlhMQ8wDQYDVQQHDAZNdW5pY2gxHTAbBgNVBAoM
8FEdOVW5ldCBOYW1pbmcgU3lzdGVtMQ8wDQYDVQQLDAZHTlVuZXQxFTATBgNVBAMM
9DEdOUyBQcm94eSBDQTEgMB4GCSqGSIb3DQEJARYRYm91bmNlQGdudW5ldC5vcmcw
10ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDXPUIPuAKOMSJkgPUPBJ6K
11axnhZ+uQ461AA6P+8YAIJFgN+rlWdeJPEmQwBAsu4tFGwQ+QwPRlPUffyLl4GA24
128sHcrGImTnLaybKrqLMud7ti4aqct/w3r2gwJiaGDJguav/mOLyqRNlsqxVUjOC+
136T39PaFofILekk2YQUnngl5Tvp4F20MhpziRPuHeObHDQHSzGxzirubvFb36bI3V
14DA4HeMaom/oAU47mkx72JE0S1xlIa7H+d7n7oS73uO7oufB+H0FAnNJa+S9PF8t+
15bezCnfBSxwIpP3fUtUOq3lbRc6wx3Bm1hkQ1M86H+XuWXCy6HLz54P3GrYiw9sOX
16AgMBAAGjUDBOMB0GA1UdDgQWBBRZs/qlW1u7P99aF6pcEQuCU1avXDAfBgNVHSME
17GDAWgBRZs/qlW1u7P99aF6pcEQuCU1avXDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3
18DQEBBQUAA4IBAQCfx7JL7fX2CnLIyvs9cqEsu/8zFGwSg4NRj53IgE3K7z2pP3Wb
19NdTo5JmlVOgy3ywQYPXPqveFXGIZR4+fPSRFIYNRuaqiRp6brx9h4xAVwbfp7UF5
20vZEGCcPnuXt2ZL+EE7JJNyCTp6ZfjnvTkAoKOQtMz5YfhaM65uIsA/Rr1fs7nk8z
21qq9LQU8+sYzgzpGXFVrv48vuq+/d4V2wj+d2z4Q3VA1smsa3gstebEQUgyiFtMYB
22+OHI0RFLQY97c5CyQRqZsgMto7IPoKwaTWTVvlQcxikx+Xs1SG9vYndBaI1ClLSI
23xrbu7Gk2bwLfUXxdaJSOTrgKHLXTx14FXPbT
24-----END CERTIFICATE-----
25-----BEGIN RSA PRIVATE KEY-----
26MIIEowIBAAKCAQEA1z1CD7gCjjEiZID1DwSeimsZ4WfrkOOtQAOj/vGACCRYDfq5
27VnXiTxJkMAQLLuLRRsEPkMD0ZT1H38i5eBgNuPLB3KxiJk5y2smyq6izLne7YuGq
28nLf8N69oMCYmhgyYLmr/5ji8qkTZbKsVVIzgvuk9/T2haHyC3pJNmEFJ54JeU76e
29BdtDIac4kT7h3jmxw0B0sxsc4q7m7xW9+myN1QwOB3jGqJv6AFOO5pMe9iRNEtcZ
30SGux/ne5+6Eu97ju6Lnwfh9BQJzSWvkvTxfLfm3swp3wUscCKT931LVDqt5W0XOs
31MdwZtYZENTPOh/l7llwsuhy8+eD9xq2IsPbDlwIDAQABAoIBAG6s9iIlCVNaWof5
32c4lEY81jIwyvpgZ7vCNVe+dlAOOu5IRTryeROExWdaPnAGUchmXucfWJ8mF4cFPW
3339+r5qp6UUsKbPGrlw1/d1sjRPeY44cF6Pfq90se6+EOTPLS2RHNPUaBWCnpey+Q
34jUhLpGkmgBSOs0eJ9rVB35pxv/HFOxnFQO80sAJElixEZlGL1jgLKCFDW/5BDKrO
35oKiRylugTC75pcAW6tvqZtE/WCPr1xaJP2AOfLlWQY/STR1NyeJxs4JSsQlCZNBY
36RTam0kVQhs64QGYh+XKhQtvaqTfN22flCiJHuOy3sDlst8dPrlEW8bHVTCDE18y0
37ZzwVcVkCgYEA6ts1crJ/69RuvZd7c5//b1ptjaXQhRTRYGDLdAaTY+cSP29bc5CG
38fx/Zohg+5hpD/1fhiWkQPY5u88XQkLxnLSiSt0WDOslTxWLAnDJa6VakldTOV8Fl
394KmeXU1jG2gYmTiFf5nz7FqAudld0Mim1qWGu4rtVeaaEyFoyfndw1sCgYEA6p3u
40dyT5dNSJFdHO5auvzexRukBOjnaUTz7fVukzs44hnW8hv3hYAR5o7u2Ye5f0Xclr
41tLyeZfeiiBGkANy592ljI4ZeDnkkrWH9HH+fk3nJUs1VsP7viJSouhpvGZpz2sU9
42Axz4oUb9/1bDA2BSs0cEFGZ9K4RWoTg7aL11YXUCgYAaguBHsEqsbnCJyl3PMZJ+
43GXEgekVNoIn6HTMaR9u/fUgcDQ//vaLRGuFQYPhItVJTsrHs9wU0Ta3MqtneXMYw
443NGjCp/DtRJVx84CU9TbXkJ5/2nDkjtT3xHXanLzlw6fzTeUreZRGe5KDHWAqgXb
45WRgad5ZPChb+bdkMY75a3QKBgQCYTc3wKmCGJzKWp4zYK4wE8dRcREK62N+OUhJK
46KTkW5r2LpgkSct0uXL9h23uRQCOyfn8c5RUuvIMWMd11cdSHeDKTbTbBzoKwy1u0
47lGTTJ8w5pHJsZBK7Z0XhCif1Rv7Olhv1WWlNyPg6Oeh+2JjXKNLNK3s2NMLIBekL
48JXJ9wQKBgGsvTzH5cUG7dIiIH7X6UQ/RN9eY7y5se5g+JUYZwGljZcLM0svanxW1
49UpPA2weyrFrWvDUEupMVg7rrocBMMJ205OUaymKdrSaVeWQxevzigEt6ZX67G6Xw
50uj+MLQ3+yj87JlVqoDRvAHlltLfz9AzPM2sSGOdaqC2q14DJXVOU
51-----END RSA PRIVATE KEY-----