aboutsummaryrefslogtreecommitdiff
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
parentef6f05f63769263a5201636c4b7f71eaa455cdf3 (diff)
downloadgnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.tar.gz
gnunet-64d3e46cfb99a711e500fa1f114e7c44bdf10040.zip
-bugfixes, code cleanup
-rw-r--r--src/arm/gnunet-service-arm.c11
-rw-r--r--src/core/core_api.c5
-rw-r--r--src/datastore/datastore_api.c13
-rw-r--r--src/dht/dht_api.c13
-rw-r--r--src/exit/gnunet-daemon-exit.c29
-rw-r--r--src/fs/fs_download.c5
-rw-r--r--src/fs/fs_search.c7
-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
-rw-r--r--src/hostlist/hostlist-client.c2
-rw-r--r--src/include/gnunet_constants.h31
-rw-r--r--src/include/gnunet_crypto_lib.h10
-rw-r--r--src/include/gnunet_network_lib.h10
-rw-r--r--src/include/gnunet_time_lib.h16
-rw-r--r--src/namestore/test_namestore_api.c74
-rw-r--r--src/namestore/test_namestore_api_lookup.c108
-rw-r--r--src/nat/nat.c6
-rw-r--r--src/nse/nse_api.c11
-rw-r--r--src/pt/test_gns_vpn.c30
-rw-r--r--src/pt/test_gnunet_vpn.c27
-rw-r--r--src/statistics/statistics_api.c4
-rw-r--r--src/stream/stream_api.c1
-rw-r--r--src/testing_old/testing.c14
-rw-r--r--src/testing_old/testing_group.c6
-rw-r--r--src/transport/transport_api.c11
-rw-r--r--src/transport/transport_api_address_lookup.c4
-rw-r--r--src/util/crypto_ecc.c98
-rw-r--r--src/util/crypto_rsa.c22
-rw-r--r--src/util/network.c28
-rw-r--r--src/util/resolver_api.c2
-rw-r--r--src/util/test_crypto_ecc.c4
-rw-r--r--src/vpn/gnunet-service-vpn.c29
43 files changed, 988 insertions, 1187 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index b43a482ba..5ad409681 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -30,12 +30,6 @@
30#include "arm.h" 30#include "arm.h"
31 31
32/** 32/**
33 * Threshold after which exponential backoff shouldn't increase (in ms); 30m
34 */
35#define EXPONENTIAL_BACKOFF_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
36
37
38/**
39 * List of our services. 33 * List of our services.
40 */ 34 */
41struct ServiceList; 35struct ServiceList;
@@ -1023,10 +1017,7 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1023 pos->name, statstr, statcode, pos->backoff.rel_value); 1017 pos->name, statstr, statcode, pos->backoff.rel_value);
1024 /* schedule restart */ 1018 /* schedule restart */
1025 pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff); 1019 pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff);
1026 pos->backoff = 1020 pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff);
1027 GNUNET_TIME_relative_min (EXPONENTIAL_BACKOFF_THRESHOLD,
1028 GNUNET_TIME_relative_multiply
1029 (pos->backoff, 2));
1030 } 1021 }
1031 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task) 1022 if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
1032 GNUNET_SCHEDULER_cancel (child_restart_task); 1023 GNUNET_SCHEDULER_cancel (child_restart_task);
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 4d1a5493f..d2f5119ac 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -440,9 +440,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
440 while (NULL != (pr = h->ready_peer_head)) 440 while (NULL != (pr = h->ready_peer_head))
441 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr); 441 GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
442 GNUNET_assert (h->control_pending_head == NULL); 442 GNUNET_assert (h->control_pending_head == NULL);
443 h->retry_backoff = 443 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
444 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->retry_backoff);
445 h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2);
446} 444}
447 445
448 446
@@ -1174,7 +1172,6 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1174 h->hcnt = 0; 1172 h->hcnt = 0;
1175 h->currently_down = GNUNET_YES; 1173 h->currently_down = GNUNET_YES;
1176 h->peers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); 1174 h->peers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
1177 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
1178 if (NULL != handlers) 1175 if (NULL != handlers)
1179 while (handlers[h->hcnt].callback != NULL) 1176 while (handlers[h->hcnt].callback != NULL)
1180 h->hcnt++; 1177 h->hcnt++;
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index fcfc076d2..8ff96d639 100644
--- a/src/datastore/datastore_api.c
+++ b/src/datastore/datastore_api.c
@@ -512,12 +512,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
512{ 512{
513 struct GNUNET_DATASTORE_Handle *h = cls; 513 struct GNUNET_DATASTORE_Handle *h = cls;
514 514
515 if (h->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value) 515 h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
516 h->retry_time = GNUNET_CONSTANTS_SERVICE_RETRY;
517 else
518 h->retry_time = GNUNET_TIME_relative_multiply (h->retry_time, 2);
519 if (h->retry_time.rel_value > GNUNET_CONSTANTS_SERVICE_TIMEOUT.rel_value)
520 h->retry_time = GNUNET_CONSTANTS_SERVICE_TIMEOUT;
521 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 516 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
522 h->client = GNUNET_CLIENT_connect ("datastore", h->cfg); 517 h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
523 if (h->client == NULL) 518 if (h->client == NULL)
@@ -802,7 +797,7 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
802 GNUNET_STATISTICS_update (h->stats, 797 GNUNET_STATISTICS_update (h->stats,
803 gettext_noop ("# status messages received"), 1, 798 gettext_noop ("# status messages received"), 1,
804 GNUNET_NO); 799 GNUNET_NO);
805 h->retry_time.rel_value = 0; 800 h->retry_time = GNUNET_TIME_UNIT_ZERO;
806 process_queue (h); 801 process_queue (h);
807 if (rc.cont != NULL) 802 if (rc.cont != NULL)
808 rc.cont (rc.cont_cls, status, 803 rc.cont (rc.cont_cls, status,
@@ -1184,7 +1179,7 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
1184 free_queue_entry (qe); 1179 free_queue_entry (qe);
1185 LOG (GNUNET_ERROR_TYPE_DEBUG, 1180 LOG (GNUNET_ERROR_TYPE_DEBUG,
1186 "Received end of result set, new queue size is %u\n", h->queue_size); 1181 "Received end of result set, new queue size is %u\n", h->queue_size);
1187 h->retry_time.rel_value = 0; 1182 h->retry_time = GNUNET_TIME_UNIT_ZERO;
1188 h->result_count = 0; 1183 h->result_count = 0;
1189 process_queue (h); 1184 process_queue (h);
1190 if (rc.proc != NULL) 1185 if (rc.proc != NULL)
@@ -1231,7 +1226,7 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
1231 (unsigned long long) GNUNET_ntohll (dm->uid), ntohl (dm->type), 1226 (unsigned long long) GNUNET_ntohll (dm->uid), ntohl (dm->type),
1232 ntohl (dm->size), GNUNET_h2s (&dm->key)); 1227 ntohl (dm->size), GNUNET_h2s (&dm->key));
1233 free_queue_entry (qe); 1228 free_queue_entry (qe);
1234 h->retry_time.rel_value = 0; 1229 h->retry_time = GNUNET_TIME_UNIT_ZERO;
1235 process_queue (h); 1230 process_queue (h);
1236 if (rc.proc != NULL) 1231 if (rc.proc != NULL)
1237 rc.proc (rc.proc_cls, &dm->key, ntohl (dm->size), &dm[1], ntohl (dm->type), 1232 rc.proc (rc.proc_cls, &dm->key, ntohl (dm->size), &dm[1], ntohl (dm->type),
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 023ffe60d..0905486d1 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -401,13 +401,7 @@ try_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
401 struct GNUNET_DHT_Handle *handle = cls; 401 struct GNUNET_DHT_Handle *handle = cls;
402 402
403 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle); 403 LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle);
404 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 404 handle->retry_time = GNUNET_TIME_STD_BACKOFF (handle->retry_time);
405 if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value)
406 handle->retry_time = GNUNET_CONSTANTS_SERVICE_RETRY;
407 else
408 handle->retry_time = GNUNET_TIME_relative_multiply (handle->retry_time, 2);
409 if (handle->retry_time.rel_value > GNUNET_CONSTANTS_SERVICE_TIMEOUT.rel_value)
410 handle->retry_time = GNUNET_CONSTANTS_SERVICE_TIMEOUT;
411 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 405 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
412 if (GNUNET_YES != try_connect (handle)) 406 if (GNUNET_YES != try_connect (handle))
413 { 407 {
@@ -438,8 +432,9 @@ do_disconnect (struct GNUNET_DHT_Handle *handle)
438 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th); 432 GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
439 handle->th = NULL; 433 handle->th = NULL;
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Disconnecting from DHT service, will try to reconnect in %llu ms\n", 435 "Disconnecting from DHT service, will try to reconnect in %s\n",
442 (unsigned long long) handle->retry_time.rel_value); 436 GNUNET_STRINGS_relative_time_to_string (handle->retry_time,
437 GNUNET_YES));
443 GNUNET_CLIENT_disconnect (handle->client); 438 GNUNET_CLIENT_disconnect (handle->client);
444 handle->client = NULL; 439 handle->client = NULL;
445 440
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index 4359db33c..a8c8d8922 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -2964,31 +2964,6 @@ read_service_conf (void *cls GNUNET_UNUSED, const char *section)
2964 2964
2965 2965
2966/** 2966/**
2967 * Test if the given AF is supported by this system.
2968 *
2969 * @param af to test
2970 * @return GNUNET_OK if the AF is supported
2971 */
2972static int
2973test_af (int af)
2974{
2975 int s;
2976
2977 s = socket (af, SOCK_STREAM, 0);
2978 if (-1 == s)
2979 {
2980 if (EAFNOSUPPORT == errno)
2981 return GNUNET_NO;
2982 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
2983 "socket");
2984 return GNUNET_SYSERR;
2985 }
2986 close (s);
2987 return GNUNET_OK;
2988}
2989
2990
2991/**
2992 * @brief Main function that will be run by the scheduler. 2967 * @brief Main function that will be run by the scheduler.
2993 * 2968 *
2994 * @param cls closure 2969 * @param cls closure
@@ -3042,7 +3017,7 @@ run (void *cls, char *const *args GNUNET_UNUSED,
3042 ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_IPV6"); 3017 ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_IPV6");
3043 3018
3044 if ( (ipv4_exit || ipv4_enabled) && 3019 if ( (ipv4_exit || ipv4_enabled) &&
3045 GNUNET_OK != test_af (AF_INET)) 3020 GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET))
3046 { 3021 {
3047 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3022 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3048 _("This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n")); 3023 _("This system does not support IPv4, will disable IPv4 functions despite them being enabled in the configuration\n"));
@@ -3050,7 +3025,7 @@ run (void *cls, char *const *args GNUNET_UNUSED,
3050 ipv4_enabled = GNUNET_NO; 3025 ipv4_enabled = GNUNET_NO;
3051 } 3026 }
3052 if ( (ipv6_exit || ipv6_enabled) && 3027 if ( (ipv6_exit || ipv6_enabled) &&
3053 GNUNET_OK != test_af (AF_INET6)) 3028 GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET6))
3054 { 3029 {
3055 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3030 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3056 _("This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n")); 3031 _("This system does not support IPv6, will disable IPv6 functions despite them being enabled in the configuration\n"));
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index ecb5c5f8a..ee301d4d0 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -1439,9 +1439,8 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
1439 if (0 == dc->reconnect_backoff.rel_value) 1439 if (0 == dc->reconnect_backoff.rel_value)
1440 dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 1440 dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
1441 else 1441 else
1442 dc->reconnect_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (dc->reconnect_backoff, 2), 1442 dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (dc->reconnect_backoff);
1443 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10)); 1443
1444
1445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in %s\n", 1444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in %s\n",
1446 GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, GNUNET_YES)); 1445 GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, GNUNET_YES));
1447 dc->task = 1446 dc->task =
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 370fd2f5c..d7124b68e 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -1158,12 +1158,7 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc)
1158 GNUNET_CLIENT_disconnect (sc->client); 1158 GNUNET_CLIENT_disconnect (sc->client);
1159 sc->client = NULL; 1159 sc->client = NULL;
1160 } 1160 }
1161 if (0 == sc->reconnect_backoff.rel_value) 1161 sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (sc->reconnect_backoff);
1162 sc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
1163 else
1164 sc->reconnect_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (sc->reconnect_backoff, 2),
1165 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10));
1166
1167 sc->task = 1162 sc->task =
1168 GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff, 1163 GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff,
1169 &do_reconnect, 1164 &do_reconnect,
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-----
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 69d7b873e..7b871963f 100644
--- a/src/hostlist/hostlist-client.c
+++ b/src/hostlist/hostlist-client.c
@@ -298,7 +298,7 @@ callback_download (void *ptr, size_t size, size_t nmemb, void *ctx)
298 left -= cpy; 298 left -= cpy;
299 if (download_pos < sizeof (struct GNUNET_MessageHeader)) 299 if (download_pos < sizeof (struct GNUNET_MessageHeader))
300 { 300 {
301 GNUNET_assert (left == 0); 301 GNUNET_assert (0 == left);
302 break; 302 break;
303 } 303 }
304 msg = (const struct GNUNET_MessageHeader *) download_buffer; 304 msg = (const struct GNUNET_MessageHeader *) download_buffer;
diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h
index 93eec8ded..f10483424 100644
--- a/src/include/gnunet_constants.h
+++ b/src/include/gnunet_constants.h
@@ -52,30 +52,11 @@ extern "C"
52#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 52#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
53 53
54/** 54/**
55 * After how long do we consider a connection to a peer dead
56 * if we got an explicit disconnect and were unable to reconnect?
57 */
58#define GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
59
60/**
61 * How long do we delay reading more from a peer after a quota violation? 55 * How long do we delay reading more from a peer after a quota violation?
62 */ 56 */
63#define GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) 57#define GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
64 58
65/** 59/**
66 * How long do we wait after a FORK+EXEC before testing for the
67 * resulting process to be up (port open, waitpid, etc.)?
68 */
69#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
70
71/**
72 * After how long do we retry a service connection that was
73 * unavailable? Used in cases where an exponential back-off
74 * seems inappropriate.
75 */
76#define GNUNET_CONSTANTS_SERVICE_RETRY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
77
78/**
79 * After how long do we consider a service unresponsive 60 * After how long do we consider a service unresponsive
80 * even if we assume that the service commonly does not 61 * even if we assume that the service commonly does not
81 * respond instantly (DNS, Database, etc.). 62 * respond instantly (DNS, Database, etc.).
@@ -119,18 +100,6 @@ extern "C"
119#define GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE (24 + sizeof (struct GNUNET_HashCode)) 100#define GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE (24 + sizeof (struct GNUNET_HashCode))
120 101
121/** 102/**
122 * Size of the 'struct OutboundMessage' of the transport
123 * (which, in combination with the
124 * GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE) defines
125 * the headers that must be pre-pendable to all GNUnet
126 * messages. Taking GNUNET_SERVER_MAX_MESSAGE_SIZE
127 * and subtracting these two constants defines the largest
128 * message core can handle.
129 */
130#define GNUNET_CONSTANTS_TRANSPORT_SIZE_OUTBOUND_MESSAGE (16 + sizeof (struct GNUNET_PeerIdentity))
131
132
133/**
134 * What is the maximum size for encrypted messages? Note that this 103 * What is the maximum size for encrypted messages? Note that this
135 * number imposes a clear limit on the maximum size of any message. 104 * number imposes a clear limit on the maximum size of any message.
136 * Set to a value close to 64k but not so close that transports will 105 * Set to a value close to 64k but not so close that transports will
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h
index 3bb60d9e5..ff7bffdbb 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -71,7 +71,6 @@ enum GNUNET_CRYPTO_Quality
71 */ 71 */
72#define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8) 72#define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8)
73 73
74
75/** 74/**
76 * @brief Length of RSA encrypted data (2048 bit) 75 * @brief Length of RSA encrypted data (2048 bit)
77 * 76 *
@@ -84,30 +83,27 @@ enum GNUNET_CRYPTO_Quality
84 */ 83 */
85#define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256 84#define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256
86 85
87
88/** 86/**
89 * Length of an RSA KEY (n,e,len), 2048 bit (=256 octests) key n, 2 byte e 87 * Length of an RSA KEY (n,e,len), 2048 bit (=256 octests) key n, 2 byte e
90 */ 88 */
91#define GNUNET_CRYPTO_RSA_KEY_LENGTH 258 89#define GNUNET_CRYPTO_RSA_KEY_LENGTH 258
92 90
93
94/** 91/**
95 * Length of a hash value 92 * Length of a hash value
96 */ 93 */
97#define GNUNET_CRYPTO_HASH_LENGTH 512/8 94#define GNUNET_CRYPTO_HASH_LENGTH 512/8
98 95
99
100/** 96/**
101 * FIXME: what is an acceptable value here? 97 * FIXME: what is an acceptable value here?
102 * Note: round to multiple of 8 minus 2. 98 * Note: round to multiple of 8 minus 2.
103 */ 99 */
104#define GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH 510 100#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 138
105 101
106/** 102/**
107 * FIXME: what is an acceptable value here? 103 * FIXME: what is an acceptable value here?
108 * Maximum length of the public key (q-point, Q = dP) when encoded. 104 * Maximum length of the public key (q-point, Q = dP) when encoded.
109 */ 105 */
110#define GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH 254 106#define GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH 140
111 107
112 108
113/** 109/**
@@ -277,7 +273,7 @@ struct GNUNET_CRYPTO_EccSignature
277 /** 273 /**
278 * S-expression, padded with zeros. 274 * S-expression, padded with zeros.
279 */ 275 */
280 char sexpr[GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH]; 276 char sexpr[GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH];
281}; 277};
282 278
283 279
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index 06a5ce903..1618b2442 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -73,6 +73,16 @@ struct GNUNET_NETWORK_FDSet
73 73
74 74
75/** 75/**
76 * Test if the given protocol family is supported by this system.
77 *
78 * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX)
79 * @return GNUNET_OK if the PF is supported
80 */
81int
82GNUNET_NETWORK_test_pf (int pf);
83
84
85/**
76 * Given a unixpath that is too long (larger than UNIX_PATH_MAX), 86 * Given a unixpath that is too long (larger than UNIX_PATH_MAX),
77 * shorten it to an acceptable length while keeping it unique 87 * shorten it to an acceptable length while keeping it unique
78 * and making sure it remains a valid filename (if possible). 88 * and making sure it remains a valid filename (if possible).
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h
index da22ab31e..d131e4eef 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -150,6 +150,22 @@ GNUNET_NETWORK_STRUCT_END
150#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ () 150#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ ()
151 151
152 152
153
154/**
155 * Threshold after which exponential backoff should not increase (15 m).
156 */
157#define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
158
159
160/**
161 * Perform our standard exponential back-off calculation, starting at 1mst
162 * and then going by a factor of 2 up unto a maximum of 1s.
163 *
164 * @param r current backoff time, initially zero
165 */
166#define GNUNET_TIME_STD_BACKOFF(r) GNUNET_TIME_relative_min (GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \
167 GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2));
168
153/** 169/**
154 * Return relative time of 0ms. 170 * Return relative time of 0ms.
155 */ 171 */
diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c
index ca6a174ee..c0b20268b 100644
--- a/src/namestore/test_namestore_api.c
+++ b/src/namestore/test_namestore_api.c
@@ -49,6 +49,24 @@ static int res;
49 49
50static struct GNUNET_NAMESTORE_QueueEntry *nsqe; 50static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
51 51
52
53static void
54cleanup ()
55{
56 if (NULL != nsh)
57 {
58 GNUNET_NAMESTORE_disconnect (nsh);
59 nsh = NULL;
60 }
61 if (NULL != privkey)
62 {
63 GNUNET_CRYPTO_rsa_key_free (privkey);
64 privkey = NULL;
65 }
66 GNUNET_SCHEDULER_shutdown ();
67}
68
69
52/** 70/**
53 * Re-establish the connection to the service. 71 * Re-establish the connection to the service.
54 * 72 *
@@ -63,17 +81,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
63 GNUNET_NAMESTORE_cancel (nsqe); 81 GNUNET_NAMESTORE_cancel (nsqe);
64 nsqe = NULL; 82 nsqe = NULL;
65 } 83 }
66 if (nsh != NULL) 84 cleanup ();
67 {
68 GNUNET_NAMESTORE_disconnect (nsh);
69 nsh = NULL;
70 }
71 if (privkey != NULL)
72 {
73 GNUNET_CRYPTO_rsa_key_free (privkey);
74 privkey = NULL;
75 }
76 GNUNET_SCHEDULER_shutdown ();
77 res = 1; 85 res = 1;
78} 86}
79 87
@@ -81,21 +89,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
81static void 89static void
82end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 90end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
83{ 91{
84 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) 92 cleanup ();
85 {
86 GNUNET_SCHEDULER_cancel (endbadly_task);
87 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
88 }
89 if (privkey != NULL)
90 {
91 GNUNET_CRYPTO_rsa_key_free (privkey);
92 privkey = NULL;
93 }
94 if (nsh != NULL)
95 {
96 GNUNET_NAMESTORE_disconnect (nsh);
97 nsh = NULL;
98 }
99 res = 0; 93 res = 0;
100} 94}
101 95
@@ -113,8 +107,12 @@ name_lookup_proc (void *cls,
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
114 "Namestore lookup result %p `%s' %i %p %p\n", 108 "Namestore lookup result %p `%s' %i %p %p\n",
115 zone_key, name, rd_count, rd, signature); 109 zone_key, name, rd_count, rd, signature);
116 res = 0; 110 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
117 GNUNET_SCHEDULER_add_now(&end, NULL); 111 {
112 GNUNET_SCHEDULER_cancel (endbadly_task);
113 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
114 }
115 GNUNET_SCHEDULER_add_now (&end, NULL);
118} 116}
119 117
120 118
@@ -124,9 +122,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
124 const char *name = cls; 122 const char *name = cls;
125 123
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 125 "Name store added record for `%s': %s\n",
128 126 name,
129 nsqe = GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL); 127 (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
128 nsqe = GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0,
129 &name_lookup_proc, NULL);
130} 130}
131 131
132 132
@@ -142,19 +142,21 @@ run (void *cls,
142 142
143 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 143 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
144 &endbadly, NULL); 144 &endbadly, NULL);
145 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 145 GNUNET_asprintf (&hostkey_file,
146 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 146 "zonefiles%s%s",
147 DIR_SEPARATOR_STR,
148 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); 149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
148 privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file); 150 privkey = GNUNET_CRYPTO_rsa_key_create_from_file (hostkey_file);
149 GNUNET_free (hostkey_file); 151 GNUNET_free (hostkey_file);
150 GNUNET_assert (privkey != NULL); 152 GNUNET_assert (privkey != NULL);
151 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); 153 GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey);
152 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (pubkey), &zone); 154 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (pubkey), &zone);
153 memset (&signature, '\0', sizeof (signature)); 155 memset (&signature, '\0', sizeof (signature));
154 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value; 156 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value;
155 rd.record_type = TEST_RECORD_TYPE; 157 rd.record_type = TEST_RECORD_TYPE;
156 rd.data_size = TEST_RECORD_DATALEN; 158 rd.data_size = TEST_RECORD_DATALEN;
157 rd.data = GNUNET_malloc(TEST_RECORD_DATALEN); 159 rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
158 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); 160 memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
159 nsh = GNUNET_NAMESTORE_connect (cfg); 161 nsh = GNUNET_NAMESTORE_connect (cfg);
160 GNUNET_break (NULL != nsh); 162 GNUNET_break (NULL != nsh);
diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c
index 6828e034c..0f1c133bb 100644
--- a/src/namestore/test_namestore_api_lookup.c
+++ b/src/namestore/test_namestore_api_lookup.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors) 3 (C) 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
@@ -18,7 +18,7 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file namestore/test_namestore_api.c 21 * @file namestore/test_namestore_api_lookup.c
22 * @brief testcase for namestore_api.c 22 * @brief testcase for namestore_api.c
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
@@ -53,11 +53,30 @@ static struct GNUNET_CRYPTO_ShortHashCode s_zone;
53 53
54static struct GNUNET_NAMESTORE_RecordData *s_rd; 54static struct GNUNET_NAMESTORE_RecordData *s_rd;
55 55
56static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
57
56static char *s_name; 58static char *s_name;
57 59
58static int res; 60static int res;
59 61
60 62
63static void
64cleanup ()
65{
66 if (NULL != nsh)
67 {
68 GNUNET_NAMESTORE_disconnect (nsh);
69 nsh = NULL;
70 }
71 if (NULL != privkey)
72 {
73 GNUNET_CRYPTO_rsa_key_free (privkey);
74 privkey = NULL;
75 }
76 GNUNET_SCHEDULER_shutdown ();
77}
78
79
61/** 80/**
62 * Re-establish the connection to the service. 81 * Re-establish the connection to the service.
63 * 82 *
@@ -67,12 +86,7 @@ static int res;
67static void 86static void
68endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 87endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
69{ 88{
70 if (nsh != NULL) 89 cleanup ();
71 GNUNET_NAMESTORE_disconnect (nsh);
72 nsh = NULL;
73 if (privkey != NULL)
74 GNUNET_CRYPTO_rsa_key_free (privkey);
75 privkey = NULL;
76 res = 1; 90 res = 1;
77} 91}
78 92
@@ -80,22 +94,12 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
80static void 94static void
81end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 95end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
82{ 96{
83 int c; 97 unsigned int c;
84 98
85 if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
86 {
87 GNUNET_SCHEDULER_cancel (endbadly_task);
88 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
89 }
90 for (c = 0; c < RECORDS; c++) 99 for (c = 0; c < RECORDS; c++)
91 GNUNET_free_non_null((void *) s_rd[c].data); 100 GNUNET_free_non_null((void *) s_rd[c].data);
92 GNUNET_free (s_rd); 101 GNUNET_free (s_rd);
93 if (privkey != NULL) 102 cleanup ();
94 GNUNET_CRYPTO_rsa_key_free (privkey);
95 privkey = NULL;
96 if (nsh != NULL)
97 GNUNET_NAMESTORE_disconnect (nsh);
98 nsh = NULL;
99} 103}
100 104
101 105
@@ -111,19 +115,21 @@ name_lookup_proc (void *cls,
111 static int found = GNUNET_NO; 115 static int found = GNUNET_NO;
112 int c; 116 int c;
113 117
114 if (n != NULL) 118 if (NULL != n)
115 { 119 {
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n"); 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
117 if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) 121 if (0 != memcmp (zone_key, &pubkey,
122 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
118 { 123 {
119 GNUNET_break (0); 124 GNUNET_break (0);
120 } 125 }
121 GNUNET_assert (NULL != signature); 126 GNUNET_assert (NULL != signature);
122 if (0 != memcmp (signature, s_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature))) 127 if (0 != memcmp (signature, s_signature,
128 sizeof (struct GNUNET_CRYPTO_RsaSignature)))
123 { 129 {
124 GNUNET_break (0); 130 GNUNET_break (0);
125 } 131 }
126 if (0 != strcmp(n, s_name)) 132 if (0 != strcmp (n, s_name))
127 { 133 {
128 GNUNET_break (0); 134 GNUNET_break (0);
129 } 135 }
@@ -143,14 +149,20 @@ name_lookup_proc (void *cls,
143 } 149 }
144 else 150 else
145 { 151 {
146 if (found != GNUNET_YES) 152 if (GNUNET_YES != found)
147 { 153 {
148 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", s_name); 154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "Failed to lookup records for name `%s'\n", s_name);
149 res = 1; 156 res = 1;
150 } 157 }
151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name); 158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name);
152 } 159 }
153 GNUNET_SCHEDULER_add_now(&end, NULL); 160 if (GNUNET_SCHEDULER_NO_TASK != endbadly_task)
161 {
162 GNUNET_SCHEDULER_cancel (endbadly_task);
163 endbadly_task = GNUNET_SCHEDULER_NO_TASK;
164 }
165 GNUNET_SCHEDULER_add_now (&end, NULL);
154} 166}
155 167
156 168
@@ -159,17 +171,22 @@ put_cont (void *cls, int32_t success, const char *emsg)
159{ 171{
160 char * name = cls; 172 char * name = cls;
161 173
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 174 nsqe = NULL;
163 if (success == GNUNET_OK) 175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
176 "Name store added record for `%s': %s\n", name,
177 (GNUNET_OK == success) ? "SUCCESS" : "FAIL");
178 if (GNUNET_OK == success)
164 { 179 {
165 res = 0; 180 res = 0;
166 GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_proc, NULL); 181 GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0,
182 &name_lookup_proc, NULL);
167 } 183 }
168 else 184 else
169 { 185 {
170 res = 1; 186 res = 1;
171 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name); 187 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
172 GNUNET_SCHEDULER_add_now(&end, NULL); 188 "Failed to put records for name `%s'\n", name);
189 GNUNET_SCHEDULER_shutdown ();
173 } 190 }
174} 191}
175 192
@@ -200,12 +217,14 @@ run (void *cls,
200{ 217{
201 size_t rd_ser_len; 218 size_t rd_ser_len;
202 struct GNUNET_TIME_Absolute et; 219 struct GNUNET_TIME_Absolute et;
220 char rd_ser[rd_ser_len];
203 221
204 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 222 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
223 &endbadly, NULL);
205 224
206 /* load privat key from file not included in zonekey dir */ 225 /* load privat key from file not included in zonekey dir */
207 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("test_hostkey"); 226 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("test_hostkey");
208 GNUNET_assert (privkey != NULL); 227 GNUNET_assert (NULL != privkey);
209 /* get public key */ 228 /* get public key */
210 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); 229 GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
211 230
@@ -214,24 +233,23 @@ run (void *cls,
214 s_rd = create_record (RECORDS); 233 s_rd = create_record (RECORDS);
215 234
216 rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd); 235 rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd);
217 char rd_ser[rd_ser_len];
218 GNUNET_NAMESTORE_records_serialize(RECORDS, s_rd, rd_ser_len, rd_ser); 236 GNUNET_NAMESTORE_records_serialize(RECORDS, s_rd, rd_ser_len, rd_ser);
219 237
220 /* sign */ 238 /* sign */
221 et.abs_value = s_rd[0].expiration_time; 239 et.abs_value = s_rd[0].expiration_time;
222 s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_rd, RECORDS); 240 s_signature = GNUNET_NAMESTORE_create_signature (privkey, et, s_name,
241 s_rd, RECORDS);
223 242
224 /* create random zone hash */ 243 /* create random zone hash */
225 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); 244 GNUNET_CRYPTO_short_hash (&pubkey,
245 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
246 &s_zone);
226 nsh = GNUNET_NAMESTORE_connect (cfg); 247 nsh = GNUNET_NAMESTORE_connect (cfg);
227 GNUNET_break (NULL != nsh); 248 GNUNET_break (NULL != nsh);
228 249 nsqe = GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
229 GNUNET_break (s_rd != NULL); 250 GNUNET_TIME_UNIT_FOREVER_ABS,
230 GNUNET_break (s_name != NULL); 251 RECORDS, s_rd, s_signature,
231 252 &put_cont, s_name);
232 GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
233 GNUNET_TIME_UNIT_FOREVER_ABS,
234 RECORDS, s_rd, s_signature, put_cont, s_name);
235} 253}
236 254
237 255
@@ -251,4 +269,4 @@ main (int argc, char *argv[])
251} 269}
252 270
253 271
254/* end of test_namestore_api.c */ 272/* end of test_namestore_api_lookup.c */
diff --git a/src/nat/nat.c b/src/nat/nat.c
index eeafc5b97..2379960bb 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -759,11 +759,7 @@ nat_server_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
759 h->server_stdout = NULL; 759 h->server_stdout = NULL;
760 h->server_stdout_handle = NULL; 760 h->server_stdout_handle = NULL;
761 /* now try to restart it */ 761 /* now try to restart it */
762 h->server_retry_delay = 762 h->server_retry_delay = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay);
763 GNUNET_TIME_relative_multiply (h->server_retry_delay, 2);
764 h->server_retry_delay =
765 GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_HOURS,
766 h->server_retry_delay);
767 h->server_read_task = 763 h->server_read_task =
768 GNUNET_SCHEDULER_add_delayed (h->server_retry_delay, 764 GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
769 &restart_nat_server, h); 765 &restart_nat_server, h);
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index 9a44197c0..136f4b622 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -154,16 +154,7 @@ reschedule_connect (struct GNUNET_NSE_Handle *h)
154 h->reconnect_delay.rel_value); 154 h->reconnect_delay.rel_value);
155 h->reconnect_task = 155 h->reconnect_task =
156 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 156 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
157 if (h->reconnect_delay.rel_value == 0) 157 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
158 {
159 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
160 }
161 else
162 {
163 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
164 h->reconnect_delay =
165 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->reconnect_delay);
166 }
167} 158}
168 159
169 160
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c
index 7d2cd7ba4..32283bad4 100644
--- a/src/pt/test_gns_vpn.c
+++ b/src/pt/test_gns_vpn.c
@@ -415,30 +415,6 @@ run (void *cls,
415 415
416 416
417/** 417/**
418 * Test if the given AF is supported by this system.
419 *
420 * @param af to test
421 * @return GNUNET_OK if the AF is supported
422 */
423static int
424test_af (int af)
425{
426 int s;
427
428 s = socket (af, SOCK_STREAM, 0);
429 if (-1 == s)
430 {
431 if (EAFNOSUPPORT == errno)
432 return GNUNET_NO;
433 fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
434 return GNUNET_SYSERR;
435 }
436 close (s);
437 return GNUNET_OK;
438}
439
440
441/**
442 * Open '/dev/null' and make the result the given 418 * Open '/dev/null' and make the result the given
443 * file descriptor. 419 * file descriptor.
444 * 420 *
@@ -579,13 +555,13 @@ main (int argc, char *const *argv)
579 dest_af = AF_INET; 555 dest_af = AF_INET;
580 src_af = AF_INET; 556 src_af = AF_INET;
581 557
582 if (GNUNET_OK == test_af (AF_INET6)) 558 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
583 use_v6 = GNUNET_YES; 559 use_v6 = GNUNET_YES;
584 else 560 else
585 use_v6 = GNUNET_NO; 561 use_v6 = GNUNET_NO;
586 562
587 if ( (GNUNET_OK != test_af (src_af)) || 563 if ( (GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
588 (GNUNET_OK != test_af (dest_af)) ) 564 (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)) )
589 { 565 {
590 fprintf (stderr, 566 fprintf (stderr,
591 "Required address families not supported by this system, skipping test.\n"); 567 "Required address families not supported by this system, skipping test.\n");
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c
index 72551e353..8b9bb2b20 100644
--- a/src/pt/test_gnunet_vpn.c
+++ b/src/pt/test_gnunet_vpn.c
@@ -390,30 +390,6 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
390} 390}
391 391
392 392
393/**
394 * Test if the given AF is supported by this system.
395 *
396 * @param af to test
397 * @return GNUNET_OK if the AF is supported
398 */
399static int
400test_af (int af)
401{
402 int s;
403
404 s = socket (af, SOCK_STREAM, 0);
405 if (-1 == s)
406 {
407 if (EAFNOSUPPORT == errno)
408 return GNUNET_NO;
409 fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
410 return GNUNET_SYSERR;
411 }
412 close (s);
413 return GNUNET_OK;
414}
415
416
417int 393int
418main (int argc, char *const *argv) 394main (int argc, char *const *argv)
419{ 395{
@@ -476,7 +452,8 @@ main (int argc, char *const *argv)
476 fprintf (stderr, "invalid binary suffix `%s'\n", type); 452 fprintf (stderr, "invalid binary suffix `%s'\n", type);
477 return 1; 453 return 1;
478 } 454 }
479 if ((GNUNET_OK != test_af (src_af)) || (GNUNET_OK != test_af (dest_af))) 455 if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
456 (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)))
480 { 457 {
481 fprintf (stderr, 458 fprintf (stderr,
482 "Required address families not supported by this system, skipping test.\n"); 459 "Required address families not supported by this system, skipping test.\n");
diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c
index 0f4149ead..305c6f3a5 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -516,9 +516,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h)
516 } 516 }
517 h->backoff_task = 517 h->backoff_task =
518 GNUNET_SCHEDULER_add_delayed (h->backoff, &reconnect_task, h); 518 GNUNET_SCHEDULER_add_delayed (h->backoff, &reconnect_task, h);
519 h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2); 519 h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff);
520 h->backoff =
521 GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
522} 520}
523 521
524 522
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c
index a5ca040b9..b712eb3d8 100644
--- a/src/stream/stream_api.c
+++ b/src/stream/stream_api.c
@@ -895,6 +895,7 @@ write_data (struct GNUNET_STREAM_Socket *socket)
895 packet++; 895 packet++;
896 } 896 }
897 io_handle->packets_sent = packet; 897 io_handle->packets_sent = packet;
898 // FIXME: 8s is not good, should use GNUNET_TIME_STD_BACKOFF...
898 if (GNUNET_SCHEDULER_NO_TASK == socket->data_retransmission_task_id) 899 if (GNUNET_SCHEDULER_NO_TASK == socket->data_retransmission_task_id)
899 socket->data_retransmission_task_id = 900 socket->data_retransmission_task_id =
900 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 901 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
diff --git a/src/testing_old/testing.c b/src/testing_old/testing.c
index 78f58f47b..5a3095935 100644
--- a/src/testing_old/testing.c
+++ b/src/testing_old/testing.c
@@ -45,6 +45,20 @@
45 */ 45 */
46#define EMPTY_HACK GNUNET_YES 46#define EMPTY_HACK GNUNET_YES
47 47
48
49/**
50 * After how long do we retry a service connection that was
51 * unavailable? Used in cases where an exponential back-off
52 * seems inappropriate.
53 */
54#define GNUNET_CONSTANTS_SERVICE_RETRY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
55
56/**
57 * How long do we wait after a FORK+EXEC before testing for the
58 * resulting process to be up (port open, waitpid, etc.)?
59 */
60#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
61
48/** 62/**
49 * How long do we wait after starting gnunet-service-arm 63 * How long do we wait after starting gnunet-service-arm
50 * for the core service to be alive? 64 * for the core service to be alive?
diff --git a/src/testing_old/testing_group.c b/src/testing_old/testing_group.c
index f5c225876..66c498256 100644
--- a/src/testing_old/testing_group.c
+++ b/src/testing_old/testing_group.c
@@ -41,6 +41,12 @@
41 41
42 42
43/** 43/**
44 * How long do we wait after a FORK+EXEC before testing for the
45 * resulting process to be up (port open, waitpid, etc.)?
46 */
47#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
48
49/**
44 * Lowest port used for GNUnet testing. Should be high enough to not 50 * Lowest port used for GNUnet testing. Should be high enough to not
45 * conflict with other applications running on the hosts but be low 51 * conflict with other applications running on the hosts but be low
46 * enough to not conflict with client-ports (typically starting around 52 * enough to not conflict with client-ports (typically starting around
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 49f82e66b..16463f646 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -951,16 +951,7 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
951 h->reconnect_delay.rel_value); 951 h->reconnect_delay.rel_value);
952 h->reconnect_task = 952 h->reconnect_task =
953 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 953 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
954 if (h->reconnect_delay.rel_value == 0) 954 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
955 {
956 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
957 }
958 else
959 {
960 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
961 h->reconnect_delay =
962 GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->reconnect_delay);
963 }
964} 955}
965 956
966 957
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 655be833f..217aecdb5 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -157,9 +157,7 @@ reconnect (struct GNUNET_TRANSPORT_PeerIterateContext *pal_ctx)
157 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot); 157 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
158 GNUNET_CLIENT_disconnect (pal_ctx->client); 158 GNUNET_CLIENT_disconnect (pal_ctx->client);
159 pal_ctx->client = NULL; 159 pal_ctx->client = NULL;
160 pal_ctx->backoff = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, 160 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
161 GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (pal_ctx->backoff, 2),
162 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)));
163 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff, 161 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff,
164 &do_connect, 162 &do_connect,
165 pal_ctx); 163 pal_ctx);
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 60f70e083..56cb3c709 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -25,7 +25,9 @@
25 * 25 *
26 * This is just a first, completely untested, draft hack for future ECC support. 26 * This is just a first, completely untested, draft hack for future ECC support.
27 * TODO: 27 * TODO:
28 * - adjust encoding length and other parameters 28 * - fix public key generation; somehow the result is currently considered invalid by libgcrypt
29 * => suspect that libgcrypt does NOT take pabgn from "CURVE" for public key if not
30 * explicitly given!
29 * - actually test it! 31 * - actually test it!
30 */ 32 */
31#include "platform.h" 33#include "platform.h"
@@ -65,26 +67,6 @@ struct GNUNET_CRYPTO_EccPrivateKey
65 67
66 68
67/** 69/**
68 * If target != size, move target bytes to the
69 * end of the size-sized buffer and zero out the
70 * first target-size bytes.
71 *
72 * @param buf original buffer
73 * @param size number of bytes in the buffer
74 * @param target target size of the buffer
75 */
76static void
77adjust (unsigned char *buf, size_t size, size_t target)
78{
79 if (size < target)
80 {
81 memmove (&buf[target - size], buf, size);
82 memset (buf, 0, target - size);
83 }
84}
85
86
87/**
88 * Free memory occupied by ECC key 70 * Free memory occupied by ECC key
89 * 71 *
90 * @param privatekey pointer to the memory to free 72 * @param privatekey pointer to the memory to free
@@ -171,6 +153,7 @@ GNUNET_CRYPTO_ecc_key_get_public (const struct GNUNET_CRYPTO_EccPrivateKey *priv
171 size_t size; 153 size_t size;
172 int rc; 154 int rc;
173 155
156 memset (pub, 0, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
174 rc = key_from_sexp (&skey, priv->sexp, "public-key", "q"); 157 rc = key_from_sexp (&skey, priv->sexp, "public-key", "q");
175 if (rc) 158 if (rc)
176 rc = key_from_sexp (&skey, priv->sexp, "private-key", "q"); 159 rc = key_from_sexp (&skey, priv->sexp, "private-key", "q");
@@ -183,7 +166,6 @@ GNUNET_CRYPTO_ecc_key_get_public (const struct GNUNET_CRYPTO_EccPrivateKey *priv
183 gcry_mpi_print (GCRYMPI_FMT_USG, pub->key, size, &size, 166 gcry_mpi_print (GCRYMPI_FMT_USG, pub->key, size, &size,
184 skey)); 167 skey));
185 pub->len = htons (size); 168 pub->len = htons (size);
186 adjust (&pub->key[0], size, GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH);
187 gcry_mpi_release (skey); 169 gcry_mpi_release (skey);
188} 170}
189 171
@@ -245,7 +227,7 @@ GNUNET_CRYPTO_ecc_public_key_from_string (const char *enc,
245 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded))) 227 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
246 return GNUNET_SYSERR; 228 return GNUNET_SYSERR;
247 if ( (ntohs (pub->size) != sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) || 229 if ( (ntohs (pub->size) != sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) ||
248 (ntohs (pub->len) > GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH) ) 230 (ntohs (pub->len) > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH) )
249 return GNUNET_SYSERR; 231 return GNUNET_SYSERR;
250 return GNUNET_OK; 232 return GNUNET_OK;
251} 233}
@@ -267,24 +249,38 @@ decode_public_key (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *publicK
267 size_t erroff; 249 size_t erroff;
268 int rc; 250 int rc;
269 251
270 if (ntohs (publicKey->len) > GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH) 252 if (ntohs (publicKey->len) > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH)
271 { 253 {
272 GNUNET_break (0); 254 GNUNET_break (0);
273 return NULL; 255 return NULL;
274 } 256 }
275 size = ntohs (publicKey->size); 257 size = ntohs (publicKey->len);
276 if (0 != (rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, publicKey->key, size, &size))) 258 if (0 != (rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, publicKey->key, size, &size)))
277 { 259 {
278 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 260 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
279 return NULL; 261 return NULL;
280 } 262 }
281 rc = gcry_sexp_build (&result, &erroff, "(public-key(ecc((curve \"" CURVE "\")(q %m)))", q); 263
264 rc = gcry_sexp_build (&result, &erroff,
265 "(public-key(ecdsa(curve \"" CURVE "\")(q %m)))",
266 q);
282 gcry_mpi_release (q); 267 gcry_mpi_release (q);
283 if (0 != rc) 268 if (0 != rc)
284 { 269 {
285 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */ 270 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */
286 return NULL; 271 return NULL;
287 } 272 }
273 // FIXME: is this key expected to pass pk_testkey?
274#if 0
275#if EXTRA_CHECKS
276 if (0 != (rc = gcry_pk_testkey (result)))
277 {
278 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
279 gcry_sexp_release (result);
280 return NULL;
281 }
282#endif
283#endif
288 return result; 284 return result;
289} 285}
290 286
@@ -386,7 +382,7 @@ ecc_key_create ()
386 int rc; 382 int rc;
387 383
388 if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL, 384 if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL,
389 "(genkey(ecdsa(curve 10:NIST P-521)))"))) 385 "(genkey(ecdsa(curve \"" CURVE "\")))")))
390 { 386 {
391 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); 387 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
392 return NULL; 388 return NULL;
@@ -428,7 +424,7 @@ try_read_key (const char *filename)
428 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 424 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
429 return NULL; 425 return NULL;
430 426
431 /* hostkey file exists already, read it! */ 427 /* key file exists already, read it! */
432 if (NULL == (fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 428 if (NULL == (fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
433 GNUNET_DISK_PERM_NONE))) 429 GNUNET_DISK_PERM_NONE)))
434 { 430 {
@@ -582,12 +578,9 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
582 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 578 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
583 GNUNET_CRYPTO_ecc_key_get_public (ret, &pub); 579 GNUNET_CRYPTO_ecc_key_get_public (ret, &pub);
584 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); 580 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
585 LOG (GNUNET_ERROR_TYPE_INFO,
586 _("I am host `%s'. Stored new private key in `%s'.\n"),
587 GNUNET_i2s (&pid), filename);
588 return ret; 581 return ret;
589 } 582 }
590 /* hostkey file exists already, read it! */ 583 /* key file exists already, read it! */
591 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 584 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
592 GNUNET_DISK_PERM_NONE); 585 GNUNET_DISK_PERM_NONE);
593 if (NULL == fd) 586 if (NULL == fd)
@@ -611,7 +604,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
611 STRERROR (ec)); 604 STRERROR (ec));
612 LOG (GNUNET_ERROR_TYPE_ERROR, 605 LOG (GNUNET_ERROR_TYPE_ERROR,
613 _ 606 _
614 ("This may be ok if someone is currently generating a hostkey.\n")); 607 ("This may be ok if someone is currently generating a private key.\n"));
615 } 608 }
616 short_wait (); 609 short_wait ();
617 continue; 610 continue;
@@ -632,7 +625,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
632 fs = 0; 625 fs = 0;
633 if (fs < sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded)) 626 if (fs < sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded))
634 { 627 {
635 /* maybe we got the read lock before the hostkey generating 628 /* maybe we got the read lock before the key generating
636 * process had a chance to get the write lock; give it up! */ 629 * process had a chance to get the write lock; give it up! */
637 if (GNUNET_YES != 630 if (GNUNET_YES !=
638 GNUNET_DISK_file_unlock (fd, 0, 631 GNUNET_DISK_file_unlock (fd, 0,
@@ -642,12 +635,12 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
642 { 635 {
643 LOG (GNUNET_ERROR_TYPE_ERROR, 636 LOG (GNUNET_ERROR_TYPE_ERROR,
644 _ 637 _
645 ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"), 638 ("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
646 filename, (unsigned int) fs, 639 filename, (unsigned int) fs,
647 (unsigned int) sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded)); 640 (unsigned int) sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded));
648 LOG (GNUNET_ERROR_TYPE_ERROR, 641 LOG (GNUNET_ERROR_TYPE_ERROR,
649 _ 642 _
650 ("This may be ok if someone is currently generating a hostkey.\n")); 643 ("This may be ok if someone is currently generating a key.\n"));
651 } 644 }
652 short_wait (); /* wait a bit longer! */ 645 short_wait (); /* wait a bit longer! */
653 continue; 646 continue;
@@ -679,9 +672,6 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
679 { 672 {
680 GNUNET_CRYPTO_ecc_key_get_public (ret, &pub); 673 GNUNET_CRYPTO_ecc_key_get_public (ret, &pub);
681 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); 674 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
682 LOG (GNUNET_ERROR_TYPE_INFO,
683 _("I am host `%s'. Read private key from `%s'.\n"), GNUNET_i2s (&pid),
684 filename);
685 } 675 }
686 return ret; 676 return ret;
687} 677}
@@ -909,15 +899,15 @@ GNUNET_CRYPTO_ecc_key_create_start (const char *filename,
909 899
910 900
911/** 901/**
912 * Setup a hostkey file for a peer given the name of the 902 * Setup a key file for a peer given the name of the
913 * configuration file (!). This function is used so that 903 * configuration file (!). This function is used so that
914 * at a later point code can be certain that reading a 904 * at a later point code can be certain that reading a
915 * hostkey is fast (for example in time-dependent testcases). 905 * key is fast (for example in time-dependent testcases).
916 * 906 *
917 * @param cfg_name name of the configuration file to use 907 * @param cfg_name name of the configuration file to use
918 */ 908 */
919void 909void
920GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name) 910GNUNET_CRYPTO_ecc_setup_key (const char *cfg_name)
921{ 911{
922 struct GNUNET_CONFIGURATION_Handle *cfg; 912 struct GNUNET_CONFIGURATION_Handle *cfg;
923 struct GNUNET_CRYPTO_EccPrivateKey *pk; 913 struct GNUNET_CRYPTO_EccPrivateKey *pk;
@@ -947,12 +937,12 @@ GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name)
947static gcry_sexp_t 937static gcry_sexp_t
948data_to_pkcs1 (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose) 938data_to_pkcs1 (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
949{ 939{
950 struct GNUNET_HashCode hc; 940 struct GNUNET_CRYPTO_ShortHashCode hc;
951 size_t bufSize; 941 size_t bufSize;
952 gcry_sexp_t data; 942 gcry_sexp_t data;
953 943
954 GNUNET_CRYPTO_hash (purpose, ntohl (purpose->size), &hc); 944 GNUNET_CRYPTO_short_hash (purpose, ntohl (purpose->size), &hc);
955#define FORMATSTRING "(4:data(5:flags5:pkcs1)(4:hash6:sha51264:0123456789012345678901234567890123456789012345678901234567890123))" 945#define FORMATSTRING "(4:data(5:flags5:pkcs1)(4:hash6:sha25632:01234567890123456789012345678901))"
956 bufSize = strlen (FORMATSTRING) + 1; 946 bufSize = strlen (FORMATSTRING) + 1;
957 { 947 {
958 char buff[bufSize]; 948 char buff[bufSize];
@@ -961,8 +951,8 @@ data_to_pkcs1 (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
961 memcpy (&buff 951 memcpy (&buff
962 [bufSize - 952 [bufSize -
963 strlen 953 strlen
964 ("0123456789012345678901234567890123456789012345678901234567890123))") 954 ("01234567890123456789012345678901))")
965 - 1], &hc, sizeof (struct GNUNET_HashCode)); 955 - 1], &hc, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
966 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0)); 956 GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
967 } 957 }
968#undef FORMATSTRING 958#undef FORMATSTRING
@@ -986,14 +976,20 @@ GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *key,
986 gcry_sexp_t result; 976 gcry_sexp_t result;
987 gcry_sexp_t data; 977 gcry_sexp_t data;
988 size_t ssize; 978 size_t ssize;
979 int rc;
989 980
990 data = data_to_pkcs1 (purpose); 981 data = data_to_pkcs1 (purpose);
991 GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp)); 982 if (0 != (rc = gcry_pk_sign (&result, data, key->sexp)))
983 {
984 LOG (GNUNET_ERROR_TYPE_WARNING,
985 _("ECC signing failed at %s:%d: %s\n"), __FILE__,
986 __LINE__, gcry_strerror (rc));
987 }
992 gcry_sexp_release (data); 988 gcry_sexp_release (data);
993 ssize = gcry_sexp_sprint (result, 989 ssize = gcry_sexp_sprint (result,
994 GCRYSEXP_FMT_DEFAULT, 990 GCRYSEXP_FMT_DEFAULT,
995 sig->sexpr, 991 sig->sexpr,
996 GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH); 992 GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH);
997 if (0 == ssize) 993 if (0 == ssize)
998 { 994 {
999 GNUNET_break (0); 995 GNUNET_break (0);
@@ -1001,7 +997,7 @@ GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *key,
1001 } 997 }
1002 sig->size = htons ((uint16_t) (ssize + sizeof (uint16_t))); 998 sig->size = htons ((uint16_t) (ssize + sizeof (uint16_t)));
1003 /* padd with zeros */ 999 /* padd with zeros */
1004 memset (&sig->sexpr[ssize], 0, GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH - ssize); 1000 memset (&sig->sexpr[ssize], 0, GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH - ssize);
1005 gcry_sexp_release (result); 1001 gcry_sexp_release (result);
1006 return GNUNET_OK; 1002 return GNUNET_OK;
1007} 1003}
@@ -1035,7 +1031,7 @@ GNUNET_CRYPTO_ecc_verify (uint32_t purpose,
1035 return GNUNET_SYSERR; /* purpose mismatch */ 1031 return GNUNET_SYSERR; /* purpose mismatch */
1036 size = ntohs (sig->size); 1032 size = ntohs (sig->size);
1037 if ( (size < sizeof (uint16_t)) || 1033 if ( (size < sizeof (uint16_t)) ||
1038 (size > GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH - sizeof (uint16_t)) ) 1034 (size > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH - sizeof (uint16_t)) )
1039 return GNUNET_SYSERR; /* size out of range */ 1035 return GNUNET_SYSERR; /* size out of range */
1040 data = data_to_pkcs1 (validate); 1036 data = data_to_pkcs1 (validate);
1041 GNUNET_assert (0 == 1037 GNUNET_assert (0 ==
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index cb782282e..b5a8c85de 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -315,7 +315,7 @@ decode_public_key (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicK
315 * Encode the private key in a format suitable for 315 * Encode the private key in a format suitable for
316 * storing it into a file. 316 * storing it into a file.
317 * 317 *
318 * @returns encoding of the private key. 318 * @return encoding of the private key.
319 * The first 4 bytes give the size of the array, as usual. 319 * The first 4 bytes give the size of the array, as usual.
320 */ 320 */
321struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded * 321struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *
@@ -778,9 +778,6 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
778 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 778 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
779 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); 779 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
780 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); 780 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
781 LOG (GNUNET_ERROR_TYPE_INFO,
782 _("I am host `%s'. Stored new private key in `%s'.\n"),
783 GNUNET_i2s (&pid), filename);
784 return ret; 781 return ret;
785 } 782 }
786 /* hostkey file exists already, read it! */ 783 /* hostkey file exists already, read it! */
@@ -807,7 +804,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
807 STRERROR (ec)); 804 STRERROR (ec));
808 LOG (GNUNET_ERROR_TYPE_ERROR, 805 LOG (GNUNET_ERROR_TYPE_ERROR,
809 _ 806 _
810 ("This may be ok if someone is currently generating a hostkey.\n")); 807 ("This may be ok if someone is currently generating a private key.\n"));
811 } 808 }
812 short_wait (); 809 short_wait ();
813 continue; 810 continue;
@@ -828,7 +825,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
828 fs = 0; 825 fs = 0;
829 if (fs < sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded)) 826 if (fs < sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded))
830 { 827 {
831 /* maybe we got the read lock before the hostkey generating 828 /* maybe we got the read lock before the key generating
832 * process had a chance to get the write lock; give it up! */ 829 * process had a chance to get the write lock; give it up! */
833 if (GNUNET_YES != 830 if (GNUNET_YES !=
834 GNUNET_DISK_file_unlock (fd, 0, 831 GNUNET_DISK_file_unlock (fd, 0,
@@ -838,12 +835,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
838 { 835 {
839 LOG (GNUNET_ERROR_TYPE_ERROR, 836 LOG (GNUNET_ERROR_TYPE_ERROR,
840 _ 837 _
841 ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"), 838 ("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
842 filename, (unsigned int) fs, 839 filename, (unsigned int) fs,
843 (unsigned int) sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded)); 840 (unsigned int) sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded));
844 LOG (GNUNET_ERROR_TYPE_ERROR, 841 LOG (GNUNET_ERROR_TYPE_ERROR,
845 _ 842 _
846 ("This may be ok if someone is currently generating a hostkey.\n")); 843 ("This may be ok if someone is currently generating a private key.\n"));
847 } 844 }
848 short_wait (); /* wait a bit longer! */ 845 short_wait (); /* wait a bit longer! */
849 continue; 846 continue;
@@ -875,9 +872,6 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
875 { 872 {
876 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub); 873 GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
877 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); 874 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
878 LOG (GNUNET_ERROR_TYPE_INFO,
879 _("I am host `%s'. Read private key from `%s'.\n"), GNUNET_i2s (&pid),
880 filename);
881 } 875 }
882 return ret; 876 return ret;
883} 877}
@@ -1105,10 +1099,10 @@ GNUNET_CRYPTO_rsa_key_create_stop (struct GNUNET_CRYPTO_RsaKeyGenerationContext
1105 1099
1106 1100
1107/** 1101/**
1108 * Setup a hostkey file for a peer given the name of the 1102 * Setup a key file for a peer given the name of the
1109 * configuration file (!). This function is used so that 1103 * configuration file (!). This function is used so that
1110 * at a later point code can be certain that reading a 1104 * at a later point code can be certain that reading a
1111 * hostkey is fast (for example in time-dependent testcases). 1105 * key is fast (for example in time-dependent testcases).
1112 * 1106 *
1113 * @param cfg_name name of the configuration file to use 1107 * @param cfg_name name of the configuration file to use
1114 */ 1108 */
@@ -1184,7 +1178,7 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
1184 1178
1185 1179
1186/** 1180/**
1187 * Decrypt a given block with the hostkey. 1181 * Decrypt a given block with the key.
1188 * 1182 *
1189 * @param key the key with which to decrypt this block 1183 * @param key the key with which to decrypt this block
1190 * @param block the data to decrypt, encoded as returned by encrypt 1184 * @param block the data to decrypt, encoded as returned by encrypt
diff --git a/src/util/network.c b/src/util/network.c
index 491e4fffd..fd6687c0f 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -67,6 +67,34 @@ struct GNUNET_NETWORK_Handle
67 67
68 68
69/** 69/**
70 * Test if the given protocol family is supported by this system.
71 *
72 * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX)
73 * @return GNUNET_OK if the PF is supported
74 */
75int
76GNUNET_NETWORK_test_pf (int pf)
77{
78 int s;
79
80 s = socket (pf, SOCK_STREAM, 0);
81 if (-1 == s)
82 {
83 if (EAFNOSUPPORT == errno)
84 return GNUNET_NO;
85 fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
86 return GNUNET_SYSERR;
87 }
88#if WINDOWS
89 closesocket (s);
90#else
91 close (s);
92#endif
93 return GNUNET_OK;
94}
95
96
97/**
70 * Given a unixpath that is too long (larger than UNIX_PATH_MAX), 98 * Given a unixpath that is too long (larger than UNIX_PATH_MAX),
71 * shorten it to an acceptable length while keeping it unique 99 * shorten it to an acceptable length while keeping it unique
72 * and making sure it remains a valid filename (if possible). 100 * and making sure it remains a valid filename (if possible).
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index 87b76f12d..2247b49c6 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -707,7 +707,7 @@ reconnect ()
707 (unsigned long long) backoff.rel_value); 707 (unsigned long long) backoff.rel_value);
708 GNUNET_assert (NULL != resolver_cfg); 708 GNUNET_assert (NULL != resolver_cfg);
709 r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL); 709 r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL);
710 backoff = GNUNET_TIME_relative_multiply (backoff, 2); 710 backoff = GNUNET_TIME_STD_BACKOFF (backoff);
711} 711}
712 712
713 713
diff --git a/src/util/test_crypto_ecc.c b/src/util/test_crypto_ecc.c
index 4cb8f1dbc..44ece1658 100644
--- a/src/util/test_crypto_ecc.c
+++ b/src/util/test_crypto_ecc.c
@@ -203,4 +203,6 @@ main (int argc, char *argv[])
203 return -1; 203 return -1;
204 } 204 }
205 return 0; 205 return 0;
206} /* end of main */ 206}
207
208/* end of test_crypto_ecc.c */
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 5a52a6cda..abdc16d79 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -3003,31 +3003,6 @@ client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
3003 3003
3004 3004
3005/** 3005/**
3006 * Test if the given AF is supported by this system.
3007 *
3008 * @param af to test
3009 * @return GNUNET_OK if the AF is supported
3010 */
3011static int
3012test_af (int af)
3013{
3014 int s;
3015
3016 s = socket (af, SOCK_STREAM, 0);
3017 if (-1 == s)
3018 {
3019 if (EAFNOSUPPORT == errno)
3020 return GNUNET_NO;
3021 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
3022 "socket");
3023 return GNUNET_SYSERR;
3024 }
3025 (void) close (s);
3026 return GNUNET_OK;
3027}
3028
3029
3030/**
3031 * Main function that will be run by the scheduler. 3006 * Main function that will be run by the scheduler.
3032 * 3007 *
3033 * @param cls closure 3008 * @param cls closure
@@ -3100,7 +3075,7 @@ run (void *cls,
3100 return; 3075 return;
3101 } 3076 }
3102 vpn_argv[1] = ifname; 3077 vpn_argv[1] = ifname;
3103 if (GNUNET_OK == test_af (AF_INET6)) 3078 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
3104 { 3079 {
3105 if ( (GNUNET_SYSERR == 3080 if ( (GNUNET_SYSERR ==
3106 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR", 3081 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
@@ -3140,7 +3115,7 @@ run (void *cls,
3140 vpn_argv[2] = GNUNET_strdup ("-"); 3115 vpn_argv[2] = GNUNET_strdup ("-");
3141 vpn_argv[3] = GNUNET_strdup ("-"); 3116 vpn_argv[3] = GNUNET_strdup ("-");
3142 } 3117 }
3143 if (GNUNET_OK == test_af (AF_INET)) 3118 if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET))
3144 { 3119 {
3145 if ( (GNUNET_SYSERR == 3120 if ( (GNUNET_SYSERR ==
3146 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR", 3121 GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR",