aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2012-10-26 22:13:01 +0000
committergrothoff <grothoff@140774ce-b5e7-0310-ab8b-a85725594a96>2012-10-26 22:13:01 +0000
commit38ef1d735d91ed90ec71f41562793f6028ba32b6 (patch)
tree83093d92761d5c1b8b2fded713adaa19af29274c
parent05123118a344d73e34c3a8cb15c078ecb273844d (diff)
-bugfixes, code cleanup
git-svn-id: https://gnunet.org/svn/gnunet@24573 140774ce-b5e7-0310-ab8b-a85725594a96
-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 b43a482baf..5ad4096817 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -30,12 +30,6 @@
#include "arm.h"
/**
- * Threshold after which exponential backoff shouldn't increase (in ms); 30m
- */
-#define EXPONENTIAL_BACKOFF_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
-
-
-/**
* List of our services.
*/
struct ServiceList;
@@ -1023,10 +1017,7 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
pos->name, statstr, statcode, pos->backoff.rel_value);
/* schedule restart */
pos->restart_at = GNUNET_TIME_relative_to_absolute (pos->backoff);
- pos->backoff =
- GNUNET_TIME_relative_min (EXPONENTIAL_BACKOFF_THRESHOLD,
- GNUNET_TIME_relative_multiply
- (pos->backoff, 2));
+ pos->backoff = GNUNET_TIME_STD_BACKOFF (pos->backoff);
}
if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
GNUNET_SCHEDULER_cancel (child_restart_task);
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 4d1a5493f1..d2f5119ac4 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -440,9 +440,7 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
while (NULL != (pr = h->ready_peer_head))
GNUNET_CONTAINER_DLL_remove (h->ready_peer_head, h->ready_peer_tail, pr);
GNUNET_assert (h->control_pending_head == NULL);
- h->retry_backoff =
- GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->retry_backoff);
- h->retry_backoff = GNUNET_TIME_relative_multiply (h->retry_backoff, 2);
+ h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff);
}
@@ -1174,7 +1172,6 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
h->hcnt = 0;
h->currently_down = GNUNET_YES;
h->peers = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
- h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
if (NULL != handlers)
while (handlers[h->hcnt].callback != NULL)
h->hcnt++;
diff --git a/src/datastore/datastore_api.c b/src/datastore/datastore_api.c
index fcfc076d27..8ff96d639c 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)
{
struct GNUNET_DATASTORE_Handle *h = cls;
- if (h->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value)
- h->retry_time = GNUNET_CONSTANTS_SERVICE_RETRY;
- else
- h->retry_time = GNUNET_TIME_relative_multiply (h->retry_time, 2);
- if (h->retry_time.rel_value > GNUNET_CONSTANTS_SERVICE_TIMEOUT.rel_value)
- h->retry_time = GNUNET_CONSTANTS_SERVICE_TIMEOUT;
+ h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
h->client = GNUNET_CLIENT_connect ("datastore", h->cfg);
if (h->client == NULL)
@@ -802,7 +797,7 @@ process_status_message (void *cls, const struct GNUNET_MessageHeader *msg)
GNUNET_STATISTICS_update (h->stats,
gettext_noop ("# status messages received"), 1,
GNUNET_NO);
- h->retry_time.rel_value = 0;
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
process_queue (h);
if (rc.cont != NULL)
rc.cont (rc.cont_cls, status,
@@ -1184,7 +1179,7 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
free_queue_entry (qe);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Received end of result set, new queue size is %u\n", h->queue_size);
- h->retry_time.rel_value = 0;
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
h->result_count = 0;
process_queue (h);
if (rc.proc != NULL)
@@ -1231,7 +1226,7 @@ process_result_message (void *cls, const struct GNUNET_MessageHeader *msg)
(unsigned long long) GNUNET_ntohll (dm->uid), ntohl (dm->type),
ntohl (dm->size), GNUNET_h2s (&dm->key));
free_queue_entry (qe);
- h->retry_time.rel_value = 0;
+ h->retry_time = GNUNET_TIME_UNIT_ZERO;
process_queue (h);
if (rc.proc != NULL)
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 023ffe60d7..0905486d12 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)
struct GNUNET_DHT_Handle *handle = cls;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting with DHT %p\n", handle);
- handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
- if (handle->retry_time.rel_value < GNUNET_CONSTANTS_SERVICE_RETRY.rel_value)
- handle->retry_time = GNUNET_CONSTANTS_SERVICE_RETRY;
- else
- handle->retry_time = GNUNET_TIME_relative_multiply (handle->retry_time, 2);
- if (handle->retry_time.rel_value > GNUNET_CONSTANTS_SERVICE_TIMEOUT.rel_value)
- handle->retry_time = GNUNET_CONSTANTS_SERVICE_TIMEOUT;
+ handle->retry_time = GNUNET_TIME_STD_BACKOFF (handle->retry_time);
handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_YES != try_connect (handle))
{
@@ -438,8 +432,9 @@ do_disconnect (struct GNUNET_DHT_Handle *handle)
GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
handle->th = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from DHT service, will try to reconnect in %llu ms\n",
- (unsigned long long) handle->retry_time.rel_value);
+ "Disconnecting from DHT service, will try to reconnect in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (handle->retry_time,
+ GNUNET_YES));
GNUNET_CLIENT_disconnect (handle->client);
handle->client = NULL;
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index 4359db33cc..a8c8d8922d 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)
/**
- * Test if the given AF is supported by this system.
- *
- * @param af to test
- * @return GNUNET_OK if the AF is supported
- */
-static int
-test_af (int af)
-{
- int s;
-
- s = socket (af, SOCK_STREAM, 0);
- if (-1 == s)
- {
- if (EAFNOSUPPORT == errno)
- return GNUNET_NO;
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "socket");
- return GNUNET_SYSERR;
- }
- close (s);
- return GNUNET_OK;
-}
-
-
-/**
* @brief Main function that will be run by the scheduler.
*
* @param cls closure
@@ -3042,7 +3017,7 @@ run (void *cls, char *const *args GNUNET_UNUSED,
ipv6_enabled = GNUNET_CONFIGURATION_get_value_yesno (cfg, "exit", "ENABLE_IPV6");
if ( (ipv4_exit || ipv4_enabled) &&
- GNUNET_OK != test_af (AF_INET))
+ GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("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,
ipv4_enabled = GNUNET_NO;
}
if ( (ipv6_exit || ipv6_enabled) &&
- GNUNET_OK != test_af (AF_INET6))
+ GNUNET_OK != GNUNET_NETWORK_test_pf (PF_INET6))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("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 ecb5c5f8aa..ee301d4d05 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -1439,9 +1439,8 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
if (0 == dc->reconnect_backoff.rel_value)
dc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
else
- dc->reconnect_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (dc->reconnect_backoff, 2),
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10));
-
+ dc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (dc->reconnect_backoff);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will try to reconnect in %s\n",
GNUNET_STRINGS_relative_time_to_string (dc->reconnect_backoff, GNUNET_YES));
dc->task =
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 370fd2f5c6..d7124b68ec 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -1158,12 +1158,7 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc)
GNUNET_CLIENT_disconnect (sc->client);
sc->client = NULL;
}
- if (0 == sc->reconnect_backoff.rel_value)
- sc->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
- else
- sc->reconnect_backoff = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (sc->reconnect_backoff, 2),
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10));
-
+ sc->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (sc->reconnect_backoff);
sc->task =
GNUNET_SCHEDULER_add_delayed (sc->reconnect_backoff,
&do_reconnect,
diff --git a/src/gns/gns.conf.in b/src/gns/gns.conf.in
index 303fbf90b6..9746c07af0 100644
--- a/src/gns/gns.conf.in
+++ b/src/gns/gns.conf.in
@@ -12,7 +12,7 @@ HIJACK_DNS = NO
AUTO_IMPORT_PKEY = YES
AUTO_IMPORT_CONFIRMATION_REQ = NO
MAX_PARALLEL_BACKGROUND_QUERIES = 25
-DEFAULT_LOOKUP_TIMEOUT = 10
+DEFAULT_LOOKUP_TIMEOUT = 10 s
ZONE_PUBLISH_TIME_WINDOW = 4 h
# PREFIX = valgrind --leak-check=full --track-origins=yes
diff --git a/src/gns/gns.h b/src/gns/gns.h
index 2f4ce39289..10119800d5 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -27,14 +27,32 @@
#include "gnunet_gns_service.h"
+/**
+ * Name of the GADS TLD.
+ */
#define GNUNET_GNS_TLD "gads"
+
+/**
+ * Name of the zone key TLD.
+ */
#define GNUNET_GNS_TLD_ZKEY "zkey"
+
+/**
+ * TLD name used to indicate relative names.
+ */
#define GNUNET_GNS_TLD_PLUS "+"
-#define GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL 3600
+/**
+ * Maximum length of a label in DNS.
+ */
#define MAX_DNS_LABEL_LENGTH 63
+
+/**
+ * Maximum length of a name in DNS.
+ */
#define MAX_DNS_NAME_LENGTH 253
+
GNUNET_NETWORK_STRUCT_BEGIN
/**
@@ -43,7 +61,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
struct GNUNET_GNS_ClientLookupMessage
{
/**
- * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP
+ * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP
*/
struct GNUNET_MessageHeader header;
@@ -107,13 +125,14 @@ struct GNUNET_GNS_ClientLookupResultMessage
};
+
/**
* Message from client to GNS service to shorten names.
*/
struct GNUNET_GNS_ClientShortenMessage
{
/**
- * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN
+ * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN
*/
struct GNUNET_MessageHeader header;
@@ -152,7 +171,7 @@ struct GNUNET_GNS_ClientShortenMessage
struct GNUNET_GNS_ClientShortenResultMessage
{
/**
- * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN_RESULT
+ * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_SHORTEN_RESULT
*/
struct GNUNET_MessageHeader header;
@@ -165,13 +184,14 @@ struct GNUNET_GNS_ClientShortenResultMessage
};
+
/**
* Message from client to GNS service to lookup an authority of a name.
*/
struct GNUNET_GNS_ClientGetAuthMessage
{
/**
- * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH
+ * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH
*/
struct GNUNET_MessageHeader header;
@@ -190,7 +210,7 @@ struct GNUNET_GNS_ClientGetAuthMessage
struct GNUNET_GNS_ClientGetAuthResultMessage
{
/**
- * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH_RESULT
+ * Header of type GNUNET_MESSAGE_TYPE_GNS_CLIENT_GET_AUTH_RESULT
*/
struct GNUNET_MessageHeader header;
@@ -202,6 +222,7 @@ struct GNUNET_GNS_ClientGetAuthResultMessage
/* followed by the authority part of the name or '\0' for no result*/
};
+
GNUNET_NETWORK_STRUCT_END
#endif
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index fef7b866df..b3173a554f 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -68,7 +68,7 @@ struct GNUNET_GNS_LookupRequest
/**
* request id
*/
- uint64_t r_id;
+ uint32_t r_id;
};
@@ -106,7 +106,7 @@ struct GNUNET_GNS_ShortenRequest
/**
* request id
*/
- uint64_t r_id;
+ uint32_t r_id;
};
@@ -165,14 +165,14 @@ struct PendingMessage
struct PendingMessage *next;
/**
- * request id
+ * Size of the message.
*/
- uint64_t r_id;
+ size_t size;
/**
- * Size of the message.
+ * request id
*/
- size_t size;
+ uint32_t r_id;
/**
* This message has been transmitted. GNUNET_NO if the message is
@@ -249,8 +249,16 @@ struct GNUNET_GNS_Handle
* Reconnect task
*/
GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
+
+ /**
+ * How long do we wait until we try to reconnect?
+ */
+ struct GNUNET_TIME_Relative reconnect_backoff;
- uint32_t r_id;
+ /**
+ * Request Id generator. Incremented by one for each request.
+ */
+ uint32_t r_id_gen;
/**
* Did we start our receive loop yet?
@@ -319,7 +327,7 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
h->in_receive = GNUNET_NO;
for (st = h->shorten_head; NULL != st; st = st->next)
{
- p = (struct PendingMessage*) &st[1];
+ p = (struct PendingMessage *) &st[1];
if (GNUNET_NO == p->transmitted)
continue;
p->transmitted = GNUNET_NO;
@@ -329,7 +337,7 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
}
for (lh = h->lookup_head; NULL != lh; lh = lh->next)
{
- p = (struct PendingMessage*) &lh[1];
+ p = (struct PendingMessage *) &lh[1];
if (GNUNET_NO == p->transmitted)
continue;
p->transmitted = GNUNET_NO;
@@ -339,7 +347,7 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
}
for (ga = h->get_auth_head; NULL != ga; ga = ga->next)
{
- p = (struct PendingMessage*) &ga[1];
+ p = (struct PendingMessage *) &ga[1];
if (GNUNET_NO == p->transmitted)
continue;
p->transmitted = GNUNET_NO;
@@ -347,8 +355,8 @@ force_reconnect (struct GNUNET_GNS_Handle *h)
h->pending_tail,
p);
}
- /* FIXME: 1s too long, exponential-backoff, starting at 1ms! (max = 1s might be OK) */
- h->reconnect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ h->reconnect_backoff = GNUNET_TIME_STD_BACKOFF (h->reconnect_backoff);
+ h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_backoff,
&reconnect_task,
h);
}
@@ -618,7 +626,7 @@ process_message (void *cls, const struct GNUNET_MessageHeader *msg)
const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg;
const struct GNUNET_GNS_ClientShortenResultMessage *shorten_msg;
const struct GNUNET_GNS_ClientGetAuthResultMessage *get_auth_msg;
- uint64_t r_id;
+ uint32_t r_id;
if (NULL == msg)
{
@@ -860,7 +868,7 @@ GNUNET_GNS_lookup_zone (struct GNUNET_GNS_Handle *handle,
lr->gns_handle = handle;
lr->lookup_proc = proc;
lr->proc_cls = proc_cls;
- lr->r_id = handle->r_id++;
+ lr->r_id = handle->r_id_gen++;
pending = (struct PendingMessage *)&lr[1];
pending->size = msize;
pending->r_id = lr->r_id;
@@ -975,7 +983,7 @@ GNUNET_GNS_shorten_zone (struct GNUNET_GNS_Handle *handle,
sr->gns_handle = handle;
sr->shorten_proc = proc;
sr->proc_cls = proc_cls;
- sr->r_id = handle->r_id++;
+ sr->r_id = handle->r_id_gen++;
GNUNET_CONTAINER_DLL_insert_tail (handle->shorten_head,
handle->shorten_tail, sr);
pending = (struct PendingMessage *)&sr[1];
@@ -1070,7 +1078,7 @@ GNUNET_GNS_get_authority (struct GNUNET_GNS_Handle *handle,
gar->gns_handle = handle;
gar->auth_proc = proc;
gar->proc_cls = proc_cls;
- gar->r_id = handle->r_id++;
+ gar->r_id = handle->r_id_gen++;
GNUNET_CONTAINER_DLL_insert_tail (handle->get_auth_head,
handle->get_auth_tail, gar);
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 47d1493306..fb7b80e16d 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)
}
-/**
-// FIXME: use cURL API
- * Escape given 0-terminated string
- *
- * @param to_esc string to escapse
- * @return allocated new escaped string (MUST free!)
- */
-static char*
-escape_to_urlenc (const char *to_esc)
-{
- char *pos = (char*)to_esc;
- char *res = GNUNET_malloc (strlen (to_esc) * 3 + 1);
- char *rpos = res;
-
- while ('\0' != *pos)
- {
- if (isalnum (*pos) ||
- ('-' == *pos) || ('_' == *pos) ||
- ('.' == *pos) || ('~' == *pos))
- *rpos++ = *pos;
- else if (' ' == *pos)
- *rpos++ = '+';
- else
- {
- *rpos++ = '%';
- *rpos++ = i_to_hexchar (*pos >> 4);
- *rpos++ = i_to_hexchar (*pos >> 15);
- }
- pos++;
- }
- *rpos = '\0';
- return res;
-}
-
-
static int
con_post_data_iter (void *cls,
enum MHD_ValueKind kind,
@@ -610,9 +575,14 @@ con_post_data_iter (void *cls,
if (0 == off)
{
+ enc = curl_easy_escape (ctask->curl, key, 0);
+ if (NULL == enc)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
/* a key */
pdata = GNUNET_malloc (sizeof (struct ProxyUploadData));
- enc = escape_to_urlenc (key);
pdata->value = GNUNET_malloc (strlen (enc) + 3);
if (NULL != ctask->upload_data_head)
{
@@ -624,7 +594,7 @@ con_post_data_iter (void *cls,
pdata->value[strlen (pdata->value)] = '=';
pdata->bytes_left = strlen (pdata->value);
pdata->total_bytes = pdata->bytes_left;
- GNUNET_free (enc);
+ curl_free (enc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Escaped POST key: '%s'\n",
@@ -636,13 +606,18 @@ con_post_data_iter (void *cls,
}
/* a value */
+ enc = curl_easy_escape (ctask->curl, data, 0);
+ if (NULL == enc)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
pdata = GNUNET_malloc (sizeof (struct ProxyUploadData));
- enc = escape_to_urlenc (data);
pdata->value = GNUNET_malloc (strlen (enc) + 1);
memcpy (pdata->value, enc, strlen (enc));
pdata->bytes_left = strlen (pdata->value);
pdata->total_bytes = pdata->bytes_left;
- GNUNET_free (enc);
+ curl_free (enc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Escaped POST value: '%s'\n",
@@ -1341,6 +1316,7 @@ postprocess_buffer (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
run_mhd_now (ctask->mhd);
}
+
/**
* Handle data from cURL
*
@@ -1592,7 +1568,6 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
struct ProxyCurlTask *ctask;
int num_ctasks;
long resp_code;
-
struct ProxyCurlTask *clean_head = NULL;
struct ProxyCurlTask *clean_tail = NULL;
@@ -1602,8 +1577,8 @@ curl_task_download (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Shutdown requested while trying to download\n");
- //TODO cleanup
- return;
+ //TODO cleanup
+ return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Ready to dl\n");
@@ -2392,13 +2367,11 @@ do_write (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
len);
}
else
- {
-
+ {
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "write");
s5r->cleanup = GNUNET_YES;
s5r->cleanup_sock = GNUNET_YES;
- cleanup_s5r (s5r);
-
+ cleanup_s5r (s5r);
return;
}
@@ -2429,8 +2402,6 @@ do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
struct Socks5Request *s5r = cls;
s5r->fwdrtask = GNUNET_SCHEDULER_NO_TASK;
-
-
if ((NULL != tc->write_ready) &&
(GNUNET_NETWORK_fdset_isset (tc->read_ready, s5r->remote_sock)) &&
(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)
}
else
{
- if (s5r->wbuf_len == 0)
+ if (0 == s5r->wbuf_len)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"0 bytes received from remote... graceful shutdown!\n");
if (s5r->fwdwtask != GNUNET_SCHEDULER_NO_TASK)
@@ -2460,8 +2431,7 @@ do_read_remote (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
s5r->wtask = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
s5r->sock,
- &do_write, s5r);
-
+ &do_write, s5r);
}
@@ -2699,7 +2669,7 @@ accept_cb (void* cls, const struct sockaddr *addr, socklen_t addrlen)
static int
add_handle_to_ssl_mhd (struct GNUNET_NETWORK_Handle *h, const char* domain)
{
- struct MhdHttpList *hd = NULL;
+ struct MhdHttpList *hd;
struct ProxyGNSCertificate *pgc;
struct NetworkHandleList *nh;
@@ -2781,7 +2751,6 @@ do_read (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
struct socks5_server_hello *s_hello;
struct socks5_client_request *c_req;
struct socks5_server_response *s_resp;
-
int ret;
char domain[256];
uint8_t dom_len;
@@ -2790,7 +2759,6 @@ do_read (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
uint32_t remote_ip;
struct sockaddr_in remote_addr;
struct in_addr *r_sin_addr;
-
struct NetworkHandleList *nh;
s5r->rtask = GNUNET_SCHEDULER_NO_TASK;
@@ -3100,7 +3068,6 @@ static void
do_shutdown (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
-
struct MhdHttpList *hd;
struct MhdHttpList *tmp_hd;
struct NetworkHandleList *nh;
@@ -3111,9 +3078,6 @@ do_shutdown (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Shutting down...\n");
-
- gnutls_global_deinit ();
-
if (NULL != local_gns_zone)
GNUNET_free (local_gns_zone);
if (NULL != local_private_zone)
@@ -3142,13 +3106,11 @@ do_shutdown (void *cls,
GNUNET_SCHEDULER_cancel (hd->httpd_task);
hd->httpd_task = GNUNET_SCHEDULER_NO_TASK;
}
-
if (NULL != hd->daemon)
{
MHD_stop_daemon (hd->daemon);
hd->daemon = NULL;
}
-
for (nh = hd->socket_handles_head; nh != NULL; nh = tmp_nh)
{
tmp_nh = nh->next;
@@ -3200,12 +3162,11 @@ do_shutdown (void *cls,
GNUNET_free_non_null (pdata->value);
GNUNET_free (pdata);
}
-
GNUNET_free (ctask);
}
curl_multi_cleanup (curl_multi);
-
GNUNET_GNS_disconnect (gns_handle);
+ gnutls_global_deinit ();
}
@@ -3243,9 +3204,9 @@ static int
load_local_zone_key (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *keyfile;
- struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
+ struct GNUNET_CRYPTO_RsaPrivateKey *key;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
- struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
+ struct GNUNET_CRYPTO_ShortHashCode *zone;
struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
@@ -3361,9 +3322,7 @@ run (void *cls, char *const *args, const char *cfgfile,
struct sockaddr_un mhd_unix_sock_addr;
#endif
- curl_multi = curl_multi_init ();
-
- if (NULL == curl_multi)
+ if (NULL == (curl_multi = curl_multi_init ()))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to create cURL multo handle!\n");
@@ -3376,8 +3335,8 @@ run (void *cls, char *const *args, const char *cfgfile,
if (NULL == cafile)
{
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns-proxy",
- "PROXY_CACERT",
- &cafile_cfg))
+ "PROXY_CACERT",
+ &cafile_cfg))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unable to load proxy CA config value!\n");
@@ -3408,19 +3367,16 @@ run (void *cls, char *const *args, const char *cfgfile,
compile_regex (&re_dotplus, (char*) RE_A_HREF);
- gns_handle = GNUNET_GNS_connect (cfg);
-
- if (GNUNET_NO == load_local_zone_key (cfg))
+ if (NULL == (gns_handle = GNUNET_GNS_connect (cfg)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to load zone!\n");
+ "Unable to connect to GNS!\n");
return;
}
-
- if (NULL == gns_handle)
+ if (GNUNET_NO == load_local_zone_key (cfg))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unable to connect to GNS!\n");
+ "Unable to load zone!\n");
return;
}
@@ -3477,12 +3433,9 @@ run (void *cls, char *const *args, const char *cfgfile,
"Specify PROXY_UNIXPATH in gns-proxy config section!\n");
return;
}
-
- mhd_unix_socket = GNUNET_NETWORK_socket_create (AF_UNIX,
- SOCK_STREAM,
- 0);
-
- if (NULL == mhd_unix_socket)
+ if (NULL == (mhd_unix_socket = GNUNET_NETWORK_socket_create (AF_UNIX,
+ SOCK_STREAM,
+ 0)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unable to create unix domain socket!\n");
@@ -3500,7 +3453,6 @@ run (void *cls, char *const *args, const char *cfgfile,
#endif
len = strlen (proxy_sockfile) + sizeof(AF_UNIX);
-
GNUNET_free (proxy_sockfile);
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 068a9266ec..ba30b56fb7 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -44,7 +44,6 @@ static char *shorten_name;
*/
static char *lookup_name;
-
/**
* record type to look up (-t option)
*/
@@ -60,15 +59,24 @@ static char *auth_name;
*/
static int raw;
+/**
+ * Requested record type.
+ */
static enum GNUNET_GNS_RecordType rtype;
-/* Handle to lookup request */
+/**
+ * Handle to lookup request
+ */
static struct GNUNET_GNS_LookupRequest *lookup_request;
-/* Handle to shorten request */
+/**
+ * Handle to shorten request
+ */
static struct GNUNET_GNS_ShortenRequest *shorten_request;
-/* Handle to get authority request */
+/**
+ * Handle to get authority request
+ */
static struct GNUNET_GNS_GetAuthRequest *getauth_request;
@@ -83,21 +91,37 @@ do_shutdown (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
if (NULL != lookup_request)
+ {
GNUNET_GNS_cancel_lookup_request (lookup_request);
-
+ lookup_request = NULL;
+ }
if (NULL != shorten_request)
+ {
GNUNET_GNS_cancel_shorten_request (shorten_request);
-
+ shorten_request = NULL;
+ }
if (NULL != getauth_request)
+ {
GNUNET_GNS_cancel_get_auth_request (getauth_request);
-
+ getauth_request = NULL;
+ }
if (NULL != gns)
+ {
GNUNET_GNS_disconnect (gns);
+ gns = NULL;
+ }
}
+/**
+ * Function called with the result of a shorten operation.
+ * Prints the result.
+ *
+ * @param cls a 'const char *' with the original (long) name
+ * @param nshort the shortened name
+ */
static void
-process_shorten_result (void* cls, const char* nshort)
+process_shorten_result (void* cls, const char *nshort)
{
const char *original_name = cls;
@@ -110,6 +134,13 @@ process_shorten_result (void* cls, const char* nshort)
}
+/**
+ * Function called with the result of a GADS lookup.
+ *
+ * @param cls the 'const char *' name that was resolved
+ * @param rd_count number of records returned
+ * @param rd array of 'rd_count' records with the results
+ */
static void
process_lookup_result (void* cls, uint32_t rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
@@ -122,7 +153,7 @@ process_lookup_result (void* cls, uint32_t rd_count,
lookup_request = NULL;
if (!raw)
{
- if (rd_count == 0)
+ if (0 == rd_count)
printf("No results.\n");
else
printf("%s:\n", name);
@@ -143,8 +174,16 @@ process_lookup_result (void* cls, uint32_t rd_count,
}
+/**
+ * Function called with the result of an authority lookup.
+ *
+ * @param cls the 'const char *' with the name for which the
+ * authority was resolved
+ * @param auth name of the authority
+ */
static void
-process_auth_result (void* cls, const char* auth)
+process_auth_result (void* cls,
+ const char *auth)
{
getauth_request = NULL;
printf ("%s\n", auth);
@@ -254,14 +293,16 @@ run (void *cls, char *const *args, const char *cfgfile,
else
rtype = GNUNET_GNS_RECORD_A;
- if ((NULL != shorten_name) && (NULL != shorten_zone) && (NULL != private_zone))
+ if ( (NULL != shorten_name) &&
+ (NULL != shorten_zone) &&
+ (NULL != private_zone) )
{
shorten_request = GNUNET_GNS_shorten_zone (gns, shorten_name,
- private_zone,
- shorten_zone,
- zone,
- &process_shorten_result,
- shorten_name);
+ private_zone,
+ shorten_zone,
+ zone,
+ &process_shorten_result,
+ shorten_name);
}
if (NULL != lookup_name)
{
@@ -270,7 +311,8 @@ run (void *cls, char *const *args, const char *cfgfile,
rtype,
GNUNET_NO, /* Use DHT */
shorten_key,
- &process_lookup_result, lookup_name);
+ &process_lookup_result,
+ lookup_name);
}
if (NULL != auth_name)
{
@@ -285,16 +327,15 @@ run (void *cls, char *const *args, const char *cfgfile,
if (NULL != private_zone)
GNUNET_free (private_zone);
- if ((NULL == auth_name) &&
- (NULL == shorten_name) &&
- (NULL == lookup_name))
+ if ( (NULL == auth_name) &&
+ (NULL == shorten_name) &&
+ (NULL == lookup_name))
{
fprintf (stderr,
_("Please specify lookup, shorten or authority operation!\n"));
GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
-
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&do_shutdown, NULL);
}
@@ -328,7 +369,6 @@ main (int argc, char *const *argv)
&GNUNET_GETOPT_set_one, &raw},
GNUNET_GETOPT_OPTION_END
};
-
int ret;
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 88e1f9d580..dc22efdab8 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -72,6 +72,7 @@ struct ClientShortenHandle
* List for all shorten requests
*/
struct ClientShortenHandle *next;
+
/**
* List for all shorten requests
*/
@@ -83,9 +84,29 @@ struct ClientShortenHandle
struct GNUNET_SERVER_Client *client;
/**
+ * Namestore lookup task
+ */
+ struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
+
+ /**
+ * master zone
+ */
+ struct GNUNET_CRYPTO_ShortHashCode root_zone;
+
+ /**
+ * private zone
+ */
+ struct GNUNET_CRYPTO_ShortHashCode private_zone;
+
+ /**
+ * shorten zone
+ */
+ struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
+
+ /**
* The request id
*/
- uint64_t request_id;
+ uint32_t request_id;
/**
* request type
@@ -106,26 +127,7 @@ struct ClientShortenHandle
* name of shorten zone (relative to root)
*/
char shorten_zone_id[MAX_DNS_NAME_LENGTH];
-
- /**
- * master zone
- */
- struct GNUNET_CRYPTO_ShortHashCode root_zone;
-
- /**
- * private zone
- */
- struct GNUNET_CRYPTO_ShortHashCode private_zone;
-
- /**
- * shorten zone
- */
- struct GNUNET_CRYPTO_ShortHashCode shorten_zone;
- /**
- * Namestore lookup task
- */
- struct GNUNET_NAMESTORE_QueueEntry *namestore_task;
};
@@ -135,18 +137,20 @@ struct ClientShortenHandle
struct ClientGetAuthHandle
{
/**
- * Handle to the requesting client */
+ * Handle to the requesting client
+ */
struct GNUNET_SERVER_Client *client;
/**
- * request id
+ * name to lookup authority
*/
- uint64_t request_id;
+ char *name;
/**
- * name to lookup authority
+ * request id
*/
- char *name;
+ uint32_t request_id;
+
};
@@ -162,34 +166,34 @@ struct ClientLookupHandle
struct GNUNET_SERVER_Client *client;
/**
- * The zone we look up in
+ * optional zone private key used for shorten
*/
- struct GNUNET_CRYPTO_ShortHashCode zone;
+ struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
/**
- * GNUNET_YES if we only want to lookup from local cache
+ * the name to look up
*/
- int only_cached;
+ char *name;
/**
- * request id
+ * The zone we look up in
*/
- uint64_t request_id;
+ struct GNUNET_CRYPTO_ShortHashCode zone;
/**
- * request type
+ * request id
*/
- enum GNUNET_GNS_RecordType type;
+ uint32_t request_id;
/**
- * optional zone private key used for shorten
+ * GNUNET_YES if we only want to lookup from local cache
*/
- struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key;
+ int only_cached;
/**
- * the name to look up
+ * request type
*/
- char *name;
+ enum GNUNET_GNS_RecordType type;
};
@@ -306,19 +310,36 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
while (NULL != (csh_tmp = csh_head))
{
GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh_tmp);
- GNUNET_free(csh_tmp);
+ GNUNET_free (csh_tmp);
}
GNUNET_SERVER_notification_context_destroy (nc);
gns_interceptor_stop ();
gns_resolver_cleanup ();
if (NULL != statistics)
+ {
GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
- if (zone_publish_task != GNUNET_SCHEDULER_NO_TASK)
+ statistics = NULL;
+ }
+ if (GNUNET_SCHEDULER_NO_TASK != zone_publish_task)
+ {
GNUNET_SCHEDULER_cancel (zone_publish_task);
+ zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
+ }
if (NULL != namestore_iter)
+ {
GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
- GNUNET_NAMESTORE_disconnect(namestore_handle);
- GNUNET_DHT_disconnect(dht_handle);
+ namestore_iter = NULL;
+ }
+ if (NULL != namestore_handle)
+ {
+ GNUNET_NAMESTORE_disconnect (namestore_handle);
+ namestore_handle = NULL;
+ }
+ if (NULL != dht_handle)
+ {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
+ }
}
@@ -345,7 +366,7 @@ publish_zone_dht_next (void *cls,
*/
static void
publish_zone_dht_start (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
@@ -360,7 +381,7 @@ publish_zone_dht_start (void *cls,
* @param signature the signature for the record data
*/
static void
-put_gns_record(void *cls,
+put_gns_record (void *cls,
const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
struct GNUNET_TIME_Absolute expiration,
const char *name,
@@ -389,19 +410,17 @@ put_gns_record(void *cls,
* we can safely set the interval to the value for a single
* record
*/
- put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
- 1);
-
+ put_interval = zone_publish_time_window;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"No records in db.\n");
}
else
{
put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
- num_public_records);
+ num_public_records);
}
put_interval = GNUNET_TIME_relative_max (MINIMUM_ZONE_ITERATION_INTERVAL,
- put_interval);
+ put_interval);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Zone iteration finished. Adjusted zone iteration interval to %s\n",
@@ -484,7 +503,8 @@ put_gns_record(void *cls,
GNUNET_STRINGS_relative_time_to_string (DHT_OPERATION_TIMEOUT, GNUNET_YES));
GNUNET_STATISTICS_update (statistics,
- "Record bytes put into DHT", rd_payload_length, GNUNET_NO);
+ "Record bytes put into DHT",
+ rd_payload_length, GNUNET_NO);
(void) GNUNET_DHT_put (dht_handle, &dht_key,
DHT_GNS_REPLICATION_LEVEL,
@@ -505,7 +525,7 @@ put_gns_record(void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Last record count was lower than current record count. Reducing interval.\n");
put_interval = GNUNET_TIME_relative_divide (zone_publish_time_window,
- num_public_records);
+ num_public_records);
next_put_interval = GNUNET_TIME_relative_divide (put_interval,
LATE_ITERATION_SPEEDUP_FACTOR);
}
@@ -517,8 +537,8 @@ put_gns_record(void *cls,
next_put_interval.rel_value,
GNUNET_NO);
zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval,
- &publish_zone_dht_next,
- NULL);
+ &publish_zone_dht_next,
+ NULL);
}
@@ -529,11 +549,13 @@ put_gns_record(void *cls,
* @param tc task context
*/
static void
-publish_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+publish_zone_dht_start (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
zone_publish_task = GNUNET_SCHEDULER_NO_TASK;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling DHT zone update!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Scheduling DHT zone update!\n");
/* start counting again */
num_public_records = 0;
namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
@@ -561,7 +583,8 @@ send_shorten_response (void* cls, const char* name)
struct GNUNET_GNS_ClientShortenResultMessage *rmsg;
size_t name_len;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message with %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending `%s' message with %s\n",
"SHORTEN_RESULT", name);
if (NULL == name)
name_len = 0;
@@ -616,9 +639,8 @@ process_shorten_in_private_zone_lookup (void *cls,
csh->namestore_task = NULL;
if (0 == strcmp (csh->private_zone_id, ""))
- pzone = NULL;
-
- if (rd_count == 0)
+ pzone = NULL;
+ if (0 == rd_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No shorten zone in private zone!\n");
@@ -627,17 +649,14 @@ process_shorten_in_private_zone_lookup (void *cls,
}
else
{
- GNUNET_assert (rd_count == 1);
-
+ GNUNET_break (1 == rd_count);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shorten zone %s found in private zone %s\n",
name, csh->private_zone_id);
sprintf (csh->shorten_zone_id, "%s.%s", name, csh->private_zone_id);
}
-
GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
-
gns_resolver_shorten_name (&csh->root_zone,
pzone,
szone,
@@ -663,12 +682,12 @@ process_shorten_in_private_zone_lookup (void *cls,
*/
static void
process_shorten_in_root_zone_lookup (void *cls,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
- struct GNUNET_TIME_Absolute expiration,
- const char *name,
- unsigned int rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd,
- const struct GNUNET_CRYPTO_RsaSignature *signature)
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
+ struct GNUNET_TIME_Absolute expiration,
+ const char *name,
+ unsigned int rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd,
+ const struct GNUNET_CRYPTO_RsaSignature *signature)
{
struct ClientShortenHandle *csh = cls;
struct GNUNET_CRYPTO_ShortHashCode *szone = &csh->shorten_zone;
@@ -677,17 +696,14 @@ process_shorten_in_root_zone_lookup (void *cls,
csh->namestore_task = NULL;
if (0 == strcmp (csh->private_zone_id, ""))
pzone = NULL;
-
- if (rd_count == 0)
+ if (0 == rd_count)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No shorten zone in zone and no private zone!\n");
strcpy (csh->shorten_zone_id, "");
-
GNUNET_CONTAINER_DLL_remove (csh_head, csh_tail, csh);
szone = NULL;
-
gns_resolver_shorten_name (&csh->root_zone,
pzone,
szone,
@@ -697,19 +713,15 @@ process_shorten_in_root_zone_lookup (void *cls,
&send_shorten_response, csh);
return;
}
-
- GNUNET_assert (rd_count == 1);
-
+ GNUNET_break (rd_count == 1);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Private zone %s found in root zone\n", name);
-
strcpy (csh->private_zone_id, name);
-
csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
- pzone,
- szone,
- &process_shorten_in_private_zone_lookup,
- csh);
+ pzone,
+ szone,
+ &process_shorten_in_private_zone_lookup,
+ csh);
}
@@ -723,7 +735,6 @@ process_shorten_in_root_zone_lookup (void *cls,
* @param rd_count number of records found
* @param rd record data
* @param signature
- *
*/
static void
process_private_in_root_zone_lookup (void *cls,
@@ -763,25 +774,6 @@ process_private_in_root_zone_lookup (void *cls,
/**
- * Lookup the zone infos and shorten name
- *
- * @param csh the shorten handle
- *
- */
-static void
-start_shorten_name (struct ClientShortenHandle *csh)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Looking for private zone name in root zone\n");
- csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
- &csh->root_zone,
- &csh->private_zone,
- &process_private_in_root_zone_lookup,
- csh);
-}
-
-
-/**
* Handle a shorten message from the api
*
* @param cls the closure (unused)
@@ -800,7 +792,8 @@ handle_shorten (void *cls,
uint16_t msg_size;
const struct GNUNET_GNS_ClientShortenMessage *sh_msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "SHORTEN");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' message\n", "SHORTEN");
msg_size = ntohs (message->size);
if (msg_size < sizeof (struct GNUNET_GNS_ClientShortenMessage))
{
@@ -861,7 +854,11 @@ handle_shorten (void *cls,
csh->root_zone = zone_hash; //Default zone
else
csh->root_zone = sh_msg->zone;
- start_shorten_name (csh);
+ csh->namestore_task = GNUNET_NAMESTORE_zone_to_name (namestore_handle,
+ &csh->root_zone,
+ &csh->private_zone,
+ &process_private_in_root_zone_lookup,
+ csh);
GNUNET_STATISTICS_update (statistics,
"Name shorten attempts", 1, GNUNET_NO);
GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -872,10 +869,11 @@ handle_shorten (void *cls,
* Send get authority response back to client
*
* @param cls the closure containing a client get auth handle
- * @param name the shortened name result or NULL if cannot be shortened
+ * @param name the name of the authority, or NULL on error
*/
static void
-send_get_auth_response(void *cls, const char* name)
+send_get_auth_response (void *cls,
+ const char* name)
{
struct ClientGetAuthHandle *cah = cls;
struct GNUNET_GNS_ClientGetAuthResultMessage *rmsg;
@@ -890,21 +888,20 @@ send_get_auth_response(void *cls, const char* name)
}
if (NULL == name)
name = "";
- rmsg = GNUNET_malloc(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage)
- + strlen(name) + 1);
+ rmsg = GNUNET_malloc (sizeof (struct GNUNET_GNS_ClientGetAuthResultMessage)
+ + strlen (name) + 1);
rmsg->id = cah->request_id;
rmsg->header.type = htons(GNUNET_MESSAGE_TYPE_GNS_GET_AUTH_RESULT);
rmsg->header.size =
htons(sizeof(struct GNUNET_GNS_ClientGetAuthResultMessage) +
- strlen(name) + 1);
+ strlen (name) + 1);
strcpy ((char*)&rmsg[1], name);
GNUNET_SERVER_notification_context_unicast (nc, cah->client,
&rmsg->header,
GNUNET_NO);
GNUNET_SERVER_receive_done (cah->client, GNUNET_OK);
-
GNUNET_free(rmsg);
GNUNET_free_non_null(cah->name);
GNUNET_free(cah);
@@ -930,12 +927,13 @@ handle_get_authority (void *cls,
uint16_t msg_size;
const struct GNUNET_GNS_ClientGetAuthMessage *sh_msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "GET_AUTH");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' message\n", "GET_AUTH");
msg_size = ntohs(message->size);
if (msg_size < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
{
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
GNUNET_SERVER_notification_context_add (nc, client);
@@ -967,17 +965,17 @@ handle_get_authority (void *cls,
send_get_auth_response(cah, name);
return;
}
- if (0 != strcmp (name + strlen (name) - strlen(GNUNET_GNS_TLD),
+ if (0 != strcmp (name + strlen (name) - strlen (GNUNET_GNS_TLD),
GNUNET_GNS_TLD))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GET_AUTH: %s is not our domain. Returning\n", name);
cah->name = NULL;
- send_get_auth_response(cah, name);
+ send_get_auth_response (cah, name);
return;
}
- if (0 == strcmp(name, GNUNET_GNS_TLD))
+ if (0 == strcmp (name, GNUNET_GNS_TLD))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GET_AUTH: %s is us. Returning\n", name);
@@ -988,8 +986,8 @@ handle_get_authority (void *cls,
cah->name = GNUNET_malloc (strlen (name)
- strlen (GNUNET_GNS_TLD) + 1);
- memcpy(cah->name, name,
- strlen (name) - strlen (GNUNET_GNS_TLD));
+ memcpy (cah->name, name,
+ strlen (name) - strlen (GNUNET_GNS_TLD));
/* Start delegation resolution in our namestore */
gns_resolver_get_authority (zone_hash, zone_hash, name,
@@ -999,7 +997,6 @@ handle_get_authority (void *cls,
}
-
/**
* Reply to client with the result from our lookup.
*
@@ -1008,9 +1005,9 @@ handle_get_authority (void *cls,
* @param rd the record data
*/
static void
-send_lookup_response(void* cls,
- uint32_t rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd)
+send_lookup_response (void* cls,
+ uint32_t rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd)
{
struct ClientLookupHandle* clh = cls;
struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
@@ -1020,8 +1017,7 @@ send_lookup_response(void* cls,
"LOOKUP_RESULT", rd_count);
len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
- rmsg = GNUNET_malloc (
- len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
+ rmsg = GNUNET_malloc (len + sizeof (struct GNUNET_GNS_ClientLookupResultMessage));
rmsg->id = clh->request_id;
rmsg->rd_count = htonl(rd_count);
@@ -1041,11 +1037,10 @@ send_lookup_response(void* cls,
if (NULL != clh->shorten_key)
GNUNET_CRYPTO_rsa_key_free (clh->shorten_key);
- GNUNET_free(clh);
-
+ GNUNET_free (clh);
GNUNET_STATISTICS_update (statistics,
"Completed lookups", 1, GNUNET_NO);
- if (rd != NULL)
+ if (NULL != rd)
GNUNET_STATISTICS_update (statistics,
"Records resolved", rd_count, GNUNET_NO);
}
@@ -1059,9 +1054,9 @@ send_lookup_response(void* cls,
* @param message the message
*/
static void
-handle_lookup(void *cls,
- struct GNUNET_SERVER_Client * client,
- const struct GNUNET_MessageHeader * message)
+handle_lookup (void *cls,
+ struct GNUNET_SERVER_Client * client,
+ const struct GNUNET_MessageHeader * message)
{
size_t namelen;
char name[MAX_DNS_NAME_LENGTH];
@@ -1075,13 +1070,13 @@ handle_lookup(void *cls,
uint16_t msg_size;
const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "LOOKUP");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' message\n", "LOOKUP");
msg_size = ntohs(message->size);
if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage))
{
GNUNET_break (0);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message;
@@ -1103,10 +1098,10 @@ handle_lookup(void *cls,
GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
return;
}
- GNUNET_STRINGS_utf8_tolower(utf_in, &nameptr);
+ GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
}
- namelen = strlen(name)+1;
+ namelen = strlen (name) + 1;
clh = GNUNET_malloc (sizeof (struct ClientLookupHandle));
memset (clh, 0, sizeof (struct ClientLookupHandle));
clh->client = client;
@@ -1126,7 +1121,7 @@ handle_lookup(void *cls,
return;
}
- if ((clh->type == GNUNET_GNS_RECORD_A) &&
+ if ((GNUNET_GNS_RECORD_A == clh->type) &&
(GNUNET_OK != v4_enabled))
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
@@ -1136,7 +1131,7 @@ handle_lookup(void *cls,
return;
}
- if ((clh->type == GNUNET_GNS_RECORD_AAAA) &&
+ if ((GNUNET_GNS_RECORD_AAAA == clh->type) &&
(GNUNET_OK != v6_enabled))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1167,44 +1162,15 @@ handle_lookup(void *cls,
only_cached,
&send_lookup_response, clh);
}
-
GNUNET_STATISTICS_update (statistics,
"Record lookup attempts", 1, GNUNET_NO);
}
/**
- * Test if the given AF is supported by this system.
- *
- * @param af to test
- * @return GNUNET_OK if the AF is supported
- */
-static int
-test_af (int af)
-{
- int s;
-
- s = socket (af, SOCK_STREAM, 0);
- if (-1 == s)
- {
- if (EAFNOSUPPORT == errno)
- return GNUNET_NO;
- fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
- return GNUNET_SYSERR;
- }
-#if WINDOWS
- closesocket (s);
-#else
- close (s);
-#endif
- return GNUNET_OK;
-}
-
-
-/**
* Process GNS requests.
*
- * @param cls closure)
+ * @param cls closure
* @param server the initialized server
* @param c configuration to use
*/
@@ -1212,23 +1178,21 @@ static void
run (void *cls, struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
- char* keyfile;
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
- unsigned long long max_parallel_bg_queries = 0;
- unsigned long long default_lookup_timeout_secs = 0;
- int ignore_pending = GNUNET_NO;
-
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
{&handle_shorten, NULL, GNUNET_MESSAGE_TYPE_GNS_SHORTEN, 0},
{&handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
{&handle_get_authority, NULL, GNUNET_MESSAGE_TYPE_GNS_GET_AUTH, 0}
};
+ char* keyfile;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+ unsigned long long max_parallel_bg_queries = 0;
+ int ignore_pending = GNUNET_NO;
- v6_enabled = test_af (AF_INET6);
- v4_enabled = test_af (AF_INET);
+ v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
+ v4_enabled = GNUNET_NETWORK_test_pf (PF_INET);
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "gns",
- "ZONEKEY", &keyfile))
+ "ZONEKEY", &keyfile))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No private key for root zone specified!\n");
@@ -1241,7 +1205,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
zone_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
GNUNET_CRYPTO_rsa_key_get_public (zone_key, &pkey);
-
GNUNET_CRYPTO_short_hash(&pkey,
sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&zone_hash);
@@ -1260,76 +1223,69 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
"AUTO_IMPORT_PKEY"))
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Automatic PKEY import is enabled.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Automatic PKEY import is enabled.\n");
auto_import_pkey = GNUNET_YES;
-
}
-
put_interval = INITIAL_PUT_INTERVAL;
-
zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_time (c, "gns",
- "ZONE_PUBLISH_TIME_WINDOW",
- &zone_publish_time_window))
+ "ZONE_PUBLISH_TIME_WINDOW",
+ &zone_publish_time_window))
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Time window for zone iteration: %s\n",
GNUNET_STRINGS_relative_time_to_string (zone_publish_time_window, GNUNET_YES));
}
-
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_number (c, "gns",
"MAX_PARALLEL_BACKGROUND_QUERIES",
&max_parallel_bg_queries))
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Number of allowed parallel background queries: %llu\n",
- max_parallel_bg_queries);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Number of allowed parallel background queries: %llu\n",
+ max_parallel_bg_queries);
}
if (GNUNET_YES ==
GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
"AUTO_IMPORT_CONFIRMATION_REQ"))
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Auto import requires user confirmation\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Auto import requires user confirmation\n");
ignore_pending = GNUNET_YES;
}
if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number(c, "gns",
- "DEFAULT_LOOKUP_TIMEOUT",
- &default_lookup_timeout_secs))
+ GNUNET_CONFIGURATION_get_value_time (c, "gns",
+ "DEFAULT_LOOKUP_TIMEOUT",
+ &default_lookup_timeout))
{
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Default lookup timeout: %llus\n", default_lookup_timeout_secs);
- default_lookup_timeout = GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS,
- default_lookup_timeout_secs);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Default lookup timeout: %s\n",
+ GNUNET_STRINGS_relative_time_to_string (default_lookup_timeout,
+ GNUNET_YES));
}
- /**
- * handle to the dht
- */
- dht_handle = GNUNET_DHT_connect(c,
- //max_parallel_bg_queries); //FIXME get ht_len from cfg
- 1024);
-
+ dht_handle = GNUNET_DHT_connect (c,
+ (unsigned int) max_parallel_bg_queries);
if (NULL == dht_handle)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to DHT!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not connect to DHT!\n"));
+ GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ return;
}
- if (gns_resolver_init(namestore_handle, dht_handle, zone_hash, c,
- max_parallel_bg_queries,
- ignore_pending)
- == GNUNET_SYSERR)
+ if (GNUNET_SYSERR ==
+ gns_resolver_init (namestore_handle, dht_handle, zone_hash, c,
+ max_parallel_bg_queries,
+ ignore_pending))
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Unable to initialize resolver!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Unable to initialize resolver!\n"));
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
return;
}
@@ -1354,18 +1310,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
*/
first_zone_iteration = GNUNET_YES;
zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start, NULL);
-
GNUNET_SERVER_add_handlers (server, handlers);
-
- //FIXME
- //GNUNET_SERVER_disconnect_notify (server,
- // &client_disconnect_notification,
- // NULL);
-
statistics = GNUNET_STATISTICS_create ("gns", c);
-
nc = GNUNET_SERVER_notification_context_create (server, 1);
-
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
NULL);
}
diff --git a/src/gns/gnunet-service-gns_interceptor.c b/src/gns/gnunet-service-gns_interceptor.c
index 0081bc8332..9c1c3a6666 100644
--- a/src/gns/gnunet-service-gns_interceptor.c
+++ b/src/gns/gnunet-service-gns_interceptor.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+ (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -17,9 +17,7 @@
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
-
/**
- *
* @file gns/gnunet-service-gns_interceptor.c
* @brief GNUnet GNS interceptor logic
* @author Martin Schanzenbach
@@ -86,8 +84,8 @@ static struct GNUNET_TIME_Relative default_lookup_timeout;
* @param rd the record data
*/
static void
-reply_to_dns(void* cls, uint32_t rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd)
+reply_to_dns (void* cls, uint32_t rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd)
{
uint32_t i;
size_t len;
@@ -199,23 +197,25 @@ reply_to_dns(void* cls, uint32_t rd_count,
1024, /* FIXME magic from dns redirector */
&buf,
&len);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Built DNS response! (ret=%d,len=%d)\n", ret, len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Built DNS response! (ret=%d,len=%d)\n",
+ ret, len);
if (ret == GNUNET_OK)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Answering DNS request\n");
- GNUNET_DNS_request_answer(ilh->request_handle,
- len,
- buf);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Answering DNS request\n");
+ GNUNET_DNS_request_answer (ilh->request_handle,
+ len,
+ buf);
- GNUNET_free(buf);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Answered DNS request\n");
+ GNUNET_free (buf);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Answered DNS request\n");
}
else
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Error building DNS response! (ret=%d)", ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error building DNS response! (ret=%d)", ret);
}
packet->num_answers = 0;
@@ -236,8 +236,8 @@ reply_to_dns(void* cls, uint32_t rd_count,
* @param q the DNS query we received parsed from p
*/
static void
-start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
- struct GNUNET_DNSPARSER_Packet *p,
+start_resolution_for_dns (struct GNUNET_DNS_RequestHandle *request,
+ struct GNUNET_DNSPARSER_Packet *p,
struct GNUNET_DNSPARSER_Query *q)
{
struct InterceptLookupHandle* ilh;
@@ -245,7 +245,6 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting resolution for %s (type=%d)!\n",
q->name, q->type);
-
ilh = GNUNET_malloc(sizeof(struct InterceptLookupHandle));
ilh->packet = p;
ilh->query = q;
@@ -260,7 +259,6 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
}
-
/**
* The DNS request handler
* Called for every incoming DNS request.
@@ -271,17 +269,16 @@ start_resolution_for_dns(struct GNUNET_DNS_RequestHandle *request,
* @param request udp payload of the DNS request
*/
static void
-handle_dns_request(void *cls,
- struct GNUNET_DNS_RequestHandle *rh,
- size_t request_length,
- const char *request)
+handle_dns_request (void *cls,
+ struct GNUNET_DNS_RequestHandle *rh,
+ size_t request_length,
+ const char *request)
{
struct GNUNET_DNSPARSER_Packet *p;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hijacked a DNS request...processing\n");
- p = GNUNET_DNSPARSER_parse (request, request_length);
-
- if (NULL == p)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Hijacked a DNS request...processing\n");
+ if (NULL == (p = GNUNET_DNSPARSER_parse (request, request_length)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Received malformed DNS packet, leaving it untouched\n");
@@ -302,7 +299,7 @@ handle_dns_request(void *cls,
* The way it is implemented here now is buggy and will lead to erratic
* behaviour (if multiple queries are present).
*/
- if (p->num_queries == 0)
+ if (0 == p->num_queries)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"No Queries in DNS packet... forwarding\n");
@@ -311,14 +308,6 @@ handle_dns_request(void *cls,
return;
}
- if (p->num_queries > 1)
- {
- /* Note: We could also look for .gads */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- ">1 queriy in DNS packet... odd. We only process #1\n");
- }
-
-
/**
* Check for .gads/.zkey
*/
@@ -327,19 +316,23 @@ handle_dns_request(void *cls,
(is_zkey_tld(p->queries[0].name) == GNUNET_YES) ||
(strcmp(p->queries[0].name, GNUNET_GNS_TLD) == 0))
{
- start_resolution_for_dns(rh, p, p->queries);
- }
- else
- {
- /**
- * This request does not concern us. Forward to real DNS.
- */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Request for %s is forwarded to DNS\n", p->queries[0].name);
- GNUNET_DNS_request_forward (rh);
- GNUNET_DNSPARSER_free_packet (p);
+ if (p->num_queries > 1)
+ {
+ /* Note: We could also look for .gads */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ ">1 queriy in DNS packet... odd. We only process #1\n");
+ }
+ start_resolution_for_dns (rh, p, p->queries);
+ return;
}
-
+ /**
+ * This request does not concern us. Forward to real DNS.
+ */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Request for %s is forwarded to DNS\n",
+ p->queries[0].name);
+ GNUNET_DNS_request_forward (rh);
+ GNUNET_DNSPARSER_free_packet (p);
}
@@ -352,53 +345,48 @@ handle_dns_request(void *cls,
* @return GNUNET_OK on success
*/
int
-gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone,
- struct GNUNET_CRYPTO_RsaPrivateKey *key,
- const struct GNUNET_CONFIGURATION_Handle *c)
+gns_interceptor_init (struct GNUNET_CRYPTO_ShortHashCode zone,
+ struct GNUNET_CRYPTO_RsaPrivateKey *key,
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
- unsigned long long default_lookup_timeout_secs = 0;
-
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
"DNS hijacking enabled... connecting to service.\n");
-
our_zone = zone;
our_key = key;
/**
* Do gnunet dns init here
*/
- dns_handle = GNUNET_DNS_connect(c,
- GNUNET_DNS_FLAG_PRE_RESOLUTION,
- &handle_dns_request, /* rh */
- NULL); /* Closure */
-
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_number(c, "gns",
- "DEFAULT_LOOKUP_TIMEOUT",
- &default_lookup_timeout_secs))
- {
- default_lookup_timeout = GNUNET_TIME_relative_multiply(
- GNUNET_TIME_UNIT_SECONDS,
- default_lookup_timeout_secs);
- }
-
+ dns_handle = GNUNET_DNS_connect (c,
+ GNUNET_DNS_FLAG_PRE_RESOLUTION,
+ &handle_dns_request, /* rh */
+ NULL); /* Closure */
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (c, "gns",
+ "DEFAULT_LOOKUP_TIMEOUT",
+ &default_lookup_timeout))
+ default_lookup_timeout = GNUNET_TIME_UNIT_ZERO;
if (NULL == dns_handle)
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
"Failed to connect to the dnsservice!\n");
return GNUNET_SYSERR;
}
-
return GNUNET_YES;
}
+
/**
* Disconnect from interceptor
*/
void
-gns_interceptor_stop(void)
+gns_interceptor_stop ()
{
- if (dns_handle)
+ if (NULL != dns_handle)
+ {
GNUNET_DNS_disconnect(dns_handle);
+ dns_handle = NULL;
+ }
}
/* end of gns_interceptor.c */
diff --git a/src/gns/gnunet-service-gns_interceptor.h b/src/gns/gnunet-service-gns_interceptor.h
index dc39aecefa..613ce8cdc8 100644
--- a/src/gns/gnunet-service-gns_interceptor.h
+++ b/src/gns/gnunet-service-gns_interceptor.h
@@ -1,6 +1,32 @@
+/*
+ This file is part of GNUnet.
+ (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file gns/gnunet-service-gns_interceptor.h
+ * @brief GNUnet GNS service
+ * @author Martin Schanzenbach
+ */
#ifndef GNUNET_GNS_INTERCEPTOR_H
#define GNUNET_GNS_INTERCEPTOR_H
+#include "gnunet_util_lib.h"
+
/**
* Initialize dns interceptor
*
@@ -10,14 +36,14 @@
* @return GNUNET_YES on success GNUNET_SYSERR on error
*/
int
-gns_interceptor_init(struct GNUNET_CRYPTO_ShortHashCode zone,
- struct GNUNET_CRYPTO_RsaPrivateKey *key,
- const struct GNUNET_CONFIGURATION_Handle *c);
+gns_interceptor_init (struct GNUNET_CRYPTO_ShortHashCode zone,
+ struct GNUNET_CRYPTO_RsaPrivateKey *key,
+ const struct GNUNET_CONFIGURATION_Handle *c);
/**
* Stops the interceptor
*/
void
-gns_interceptor_stop(void);
+gns_interceptor_stop (void);
#endif
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 964f798d0f..7391efbf81 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)
return ret;
}
+
/**
* Determine if this name is canonical (is a legal name in a zone, without delegation);
* 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,
finish_lookup (rh, rlh, 1, &rd);
}
+
/**
* Resolve DNS name via local stub resolver
*
@@ -3960,7 +3962,7 @@ process_zone_to_name_shorten_root (void *cls,
* @param rd_count number of results (0)
* @param rd data (NULL)
*/
-void
+static void
handle_delegation_ns_shorten (void* cls,
struct ResolverHandle *rh,
uint32_t rd_count,
@@ -4289,7 +4291,7 @@ finish_get_auth (struct ResolverHandle *rh,
* @param rd_count number of results (0)
* @param rd data (NULL)
*/
-void
+static void
handle_delegation_result_ns_get_auth(void* cls,
struct ResolverHandle *rh,
uint32_t rd_count,
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index b24fd12746..e8bb746975 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -1,3 +1,27 @@
+/*
+ This file is part of GNUnet.
+ (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+/**
+ * @file gns/gnunet-service-gns_resolver.h
+ * @brief GNUnet GNS service
+ * @author Martin Schanzenbach
+ */
#ifndef GNS_RESOLVER_H
#define GNS_RESOLVER_H
@@ -5,12 +29,16 @@
#include "gnunet_dht_service.h"
#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
+
#define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
+
#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
+
#define DHT_GNS_REPLICATION_LEVEL 5
#define GNUNET_GNS_MAX_PARALLEL_LOOKUPS 500
+
#define GNUNET_GNS_MAX_NS_TASKS 500
/*
@@ -23,17 +51,26 @@ struct AuthorityChain
struct AuthorityChain *next;
- /* the zone hash of the authority */
+ /**
+ * the zone hash of the authority
+ */
struct GNUNET_CRYPTO_ShortHashCode zone;
- /* (local) name of the authority */
+ /**
+ * (local) name of the authority
+ */
char name[MAX_DNS_LABEL_LENGTH];
- /* was the ns entry fresh */
+ /**
+ * was the ns entry fresh
+ */
int fresh;
};
-/* handle to a resolution process */
+
+/**
+ * handle to a resolution process
+ */
struct ResolverHandle;
@@ -45,8 +82,8 @@ struct ResolverHandle;
* @param rd result data
*/
typedef void (*RecordLookupProcessor) (void *cls,
- uint32_t rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd);
+ uint32_t rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd);
/**
@@ -55,16 +92,18 @@ typedef void (*RecordLookupProcessor) (void *cls,
* @param cls the closure
* @param name shortened name
*/
-typedef void (*ShortenResultProcessor) (void *cls, const char* name);
+typedef void (*ShortenResultProcessor) (void *cls,
+ const char* name);
/**
* processor for an authority result
*
* @param cls the closure
- * @param name name
+ * @param name name of the authority
*/
-typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
+typedef void (*GetAuthorityResultProcessor) (void *cls,
+ const char* name);
/**
* processor for a resolution result
@@ -72,34 +111,57 @@ typedef void (*GetAuthorityResultProcessor) (void *cls, const char* name);
* @param cls the closure
* @param rh the resolution handle
* @param rd_count number of results
- * @param rd result data
+ * @param rd result data (array of 'rd_count' records)
*/
typedef void (*ResolutionResultProcessor) (void *cls,
- struct ResolverHandle *rh,
- uint32_t rd_count,
- const struct GNUNET_NAMESTORE_RecordData *rd);
+ struct ResolverHandle *rh,
+ uint32_t rd_count,
+ const struct GNUNET_NAMESTORE_RecordData *rd);
/**
* Resolution status indicator
- * RSL_RECORD_EXISTS: the name to lookup exists
- * RSL_RECORD_EXPIRED: the name in the record expired
- * RSL_TIMED_OUT: resolution timed out
- * RSL_DELEGATE_VPN: Found VPN delegation
- * RSL_DELEGATE_NS: Found NS delegation
- * RSL_DELEGATE_PKEY: Found PKEY delegation
- * RSL_CNAME_FOUND: Found CNAME record
- * RSL_PKEY_REVOKED: Found PKEY has been revoked
*/
enum ResolutionStatus
{
+ /**
+ * the name to lookup exists
+ */
RSL_RECORD_EXISTS = 1,
+
+ /**
+ * the name in the record expired
+ */
RSL_RECORD_EXPIRED = 2,
+
+ /**
+ * resolution timed out
+ */
RSL_TIMED_OUT = 4,
+
+ /**
+ * Found VPN delegation
+ */
RSL_DELEGATE_VPN = 8,
+
+ /**
+ * Found NS delegation
+ */
RSL_DELEGATE_NS = 16,
+
+ /**
+ * Found PKEY delegation
+ */
RSL_DELEGATE_PKEY = 32,
+
+ /**
+ * Found CNAME record
+ */
RSL_CNAME_FOUND = 64,
+
+ /**
+ * Found PKEY has been revoked
+ */
RSL_PKEY_REVOKED = 128
};
@@ -116,91 +178,149 @@ enum ResolutionStatus
struct ResolverHandle
{
- /* DLL */
+ /**
+ * DLL
+ */
struct ResolverHandle *next;
- /* DLL */
+ /**
+ * DLL
+ */
struct ResolverHandle *prev;
- /* Last record data found */
+ /**
+ * Last record data found
+ */
struct GNUNET_NAMESTORE_RecordData rd;
- /* Number of last record data found */
+ /**
+ * Number of last record data found
+ */
unsigned int rd_count;
- /* The name to resolve */
+ /**
+ * The name to resolve
+ */
char name[MAX_DNS_NAME_LENGTH];
- /* has this query been answered? how many matches */
+ /**
+ * has this query been answered? how many matches
+ */
int answered;
- /* Use only cache */
+ /**
+ * Use only cache
+ */
int only_cached;
- /* the authoritative zone to query */
+ /**
+ * the authoritative zone to query
+ */
struct GNUNET_CRYPTO_ShortHashCode authority;
- /* the name of the authoritative zone to query */
+ /**
+ * the name of the authoritative zone to query
+ */
char authority_name[MAX_DNS_LABEL_LENGTH];
- /* a handle for dht lookups. should be NULL if no lookups are in progress */
+ /**
+ * a handle for dht lookups. should be NULL if no lookups are in progress
+ */
struct GNUNET_DHT_GetHandle *get_handle;
- /* timeout set for this lookup task */
+ /**
+ * timeout set for this lookup task
+ */
struct GNUNET_TIME_Relative timeout;
- /* a handle to a vpn request */
+ /**
+ * a handle to a vpn request
+ */
struct GNUNET_VPN_RedirectionRequest *vpn_handle;
- /* a socket for a dns request */
+ /**
+ * a socket for a dns request
+ */
struct GNUNET_NETWORK_Handle *dns_sock;
- /* a synthesized dns name */
+ /**
+ * a synthesized dns name
+ */
char dns_name[MAX_DNS_NAME_LENGTH];
- /* the authoritative dns zone */
+ /**
+ * the authoritative dns zone
+ */
char dns_zone[MAX_DNS_NAME_LENGTH];
- /* the address of the DNS server FIXME not needed? */
+ /**
+ * the address of the DNS server FIXME not needed?
+ */
struct sockaddr_in dns_addr;
- /* handle to the local stub resolver request */
+ /**
+ * handle to the local stub resolver request
+ */
struct GNUNET_RESOLVER_RequestHandle *dns_resolver_handle;
- /* select task for DNS */
+ /**
+ * select task for DNS
+ */
GNUNET_SCHEDULER_TaskIdentifier dns_read_task;
- /* pointer to raw dns query payload FIXME needs to be freed/NULL */
+ /**
+ * pointer to raw dns query payload FIXME needs to be freed/NULL
+ */
char *dns_raw_packet;
- /* size of the raw dns query */
+ /**
+ * size of the raw dns query
+ */
size_t dns_raw_packet_size;
- /* timeout task for the lookup */
+ /**
+ * timeout task for the lookup
+ */
GNUNET_SCHEDULER_TaskIdentifier timeout_task;
- /* continuation to call on timeout */
+ /**
+ * continuation to call on timeout
+ */
GNUNET_SCHEDULER_Task timeout_cont;
- /* closure for timeout cont */
+ /**
+ * closure for timeout cont
+ */
void* timeout_cont_cls;
- /* called when resolution phase finishes */
+ /**
+ * called when resolution phase finishes
+ */
ResolutionResultProcessor proc;
- /* closure passed to proc */
+ /**
+ * closure passed to proc
+ */
void* proc_cls;
- /* DLL to store the authority chain */
+ /**
+ * DLL to store the authority chain
+ */
struct AuthorityChain *authority_chain_head;
- /* DLL to store the authority chain */
+ /**
+ * DLL to store the authority chain
+ */
struct AuthorityChain *authority_chain_tail;
- /* status of the resolution result */
+ /**
+ * status of the resolution result
+ */
enum ResolutionStatus status;
- /* The provate local zone of this request */
+ /**
+ * The provate local zone of this request
+ */
struct GNUNET_CRYPTO_ShortHashCode private_local_zone;
/**
@@ -233,16 +353,24 @@ struct ResolverHandle
*/
struct RecordLookupHandle
{
- /* the record type to look up */
+ /**
+ * the record type to look up
+ */
enum GNUNET_GNS_RecordType record_type;
- /* the name to look up */
+ /**
+ * the name to look up
+ */
char name[MAX_DNS_NAME_LENGTH];
- /* Method to call on record resolution result */
+ /**
+ * Method to call on record resolution result
+ */
RecordLookupProcessor proc;
- /* closure to pass to proc */
+ /**
+ * closure to pass to proc
+ */
void* proc_cls;
};
@@ -253,98 +381,150 @@ struct RecordLookupHandle
*/
struct NameShortenHandle
{
- /* Method to call on shorten result */
+ /**
+ * Method to call on shorten result
+ */
ShortenResultProcessor proc;
- /* closure to pass to proc */
+ /**
+ * closure to pass to proc
+ */
void* proc_cls;
- /* result of shorten */
+ /**
+ * result of shorten
+ */
char result[MAX_DNS_NAME_LENGTH];
- /* root zone */
+ /**
+ * root zone
+ */
struct GNUNET_CRYPTO_ShortHashCode *root_zone;
- /* private zone */
+ /**
+ * private zone
+ */
struct GNUNET_CRYPTO_ShortHashCode *private_zone;
- /* name of private zone */
+ /**
+ * name of private zone
+ */
char private_zone_name[MAX_DNS_LABEL_LENGTH];
- /* shorten zone */
+ /**
+ * shorten zone
+ */
struct GNUNET_CRYPTO_ShortHashCode *shorten_zone;
- /* name of shorten zone */
+ /**
+ * name of shorten zone
+ */
char shorten_zone_name[MAX_DNS_LABEL_LENGTH];
};
+
/**
* Handle to a get authority context
*/
struct GetNameAuthorityHandle
{
- /* the name to look up authority for */
+ /**
+ * the name to look up authority for
+ */
char name[MAX_DNS_NAME_LENGTH];
- /* the result */
+ /**
+ * the result
+ */
char result[MAX_DNS_NAME_LENGTH];
- /* Method to call on result */
+ /**
+ * Method to call on result
+ */
GetAuthorityResultProcessor proc;
- /* closure to pass to proc */
+ /**
+ * closure to pass to proc
+ */
void* proc_cls;
};
+
/**
* Handle to a pseu lookup
*/
struct GetPseuAuthorityHandle
{
- /* DLL */
+ /**
+ * DLL
+ */
struct GetPseuAuthorityHandle *next;
- /* DLL */
+ /**
+ * DLL
+ */
struct GetPseuAuthorityHandle *prev;
- /* the name to store the zone under */
+ /**
+ * the name to store the zone under
+ */
char name[MAX_DNS_LABEL_LENGTH];
- /* test name to store the zone under */
+ /**
+ * test name to store the zone under
+ */
char test_name[MAX_DNS_LABEL_LENGTH];
- /* the zone of our authority */
+ /**
+ * the zone of our authority
+ */
struct GNUNET_CRYPTO_ShortHashCode our_zone;
- /* the private key of the zone to store the pseu in */
+ /**
+ * the private key of the zone to store the pseu in
+ */
struct GNUNET_CRYPTO_RsaPrivateKey *key;
- /* a handle for dht lookups. should be NULL if no lookups are in progress */
+ /**
+ * a handle for dht lookups. should be NULL if no lookups are in progress
+ */
struct GNUNET_DHT_GetHandle *get_handle;
- /* timeout task for lookup */
+ /**
+ * timeout task for lookup
+ */
GNUNET_SCHEDULER_TaskIdentifier timeout;
- /* Authority to shorten */
+ /**
+ * Authority to shorten
+ */
struct AuthorityChain *auth;
- /* handle to namestore request */
+ /**
+ * handle to namestore request
+ */
struct GNUNET_NAMESTORE_QueueEntry* namestore_task;
};
+
/**
* Namestore queue entries in background
*/
struct NamestoreBGTask
{
- /* node in heap */
+ /**
+ * node in heap
+ */
struct GNUNET_CONTAINER_HeapNode *node;
- /* queue entry */
+ /**
+ * queue entry
+ */
struct GNUNET_NAMESTORE_QueueEntry *qe;
};
+
/**
* Initialize the resolver
* MUST be called before other gns_resolver_* methods
@@ -359,18 +539,20 @@ struct NamestoreBGTask
* @returns GNUNET_OK on success
*/
int
-gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh,
- struct GNUNET_DHT_Handle *dh,
- struct GNUNET_CRYPTO_ShortHashCode lz,
- const struct GNUNET_CONFIGURATION_Handle *c,
- unsigned long long max_bg_queries,
- int ignore_pending);
+gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
+ struct GNUNET_DHT_Handle *dh,
+ struct GNUNET_CRYPTO_ShortHashCode lz,
+ const struct GNUNET_CONFIGURATION_Handle *c,
+ unsigned long long max_bg_queries,
+ int ignore_pending);
+
/**
* Cleanup resolver: Terminate pending lookups
*/
void
-gns_resolver_cleanup(void);
+gns_resolver_cleanup (void);
+
/**
* Lookup of a record in a specific zone
@@ -387,15 +569,16 @@ gns_resolver_cleanup(void);
* @param cls the closure to pass to proc
*/
void
-gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
- struct GNUNET_CRYPTO_ShortHashCode pzone,
- uint32_t record_type,
- const char* name,
- struct GNUNET_CRYPTO_RsaPrivateKey *key,
- struct GNUNET_TIME_Relative timeout,
- int only_cached,
- RecordLookupProcessor proc,
- void* cls);
+gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
+ struct GNUNET_CRYPTO_ShortHashCode pzone,
+ uint32_t record_type,
+ const char* name,
+ struct GNUNET_CRYPTO_RsaPrivateKey *key,
+ struct GNUNET_TIME_Relative timeout,
+ int only_cached,
+ RecordLookupProcessor proc,
+ void* cls);
+
/**
* Shortens a name if possible. If the shortening fails
@@ -414,14 +597,15 @@ gns_resolver_lookup_record(struct GNUNET_CRYPTO_ShortHashCode zone,
* @param proc_cls the closure to pass to proc
*/
void
-gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
- struct GNUNET_CRYPTO_ShortHashCode *pzone,
- struct GNUNET_CRYPTO_ShortHashCode *szone,
- const char* name,
- const char* private_zone_name,
- const char* shorten_zone_name,
- ShortenResultProcessor proc,
- void* proc_cls);
+gns_resolver_shorten_name (struct GNUNET_CRYPTO_ShortHashCode *zone,
+ struct GNUNET_CRYPTO_ShortHashCode *pzone,
+ struct GNUNET_CRYPTO_ShortHashCode *szone,
+ const char* name,
+ const char* private_zone_name,
+ const char* shorten_zone_name,
+ ShortenResultProcessor proc,
+ void* proc_cls);
+
/**
* Tries to resolve the authority for name
@@ -434,11 +618,11 @@ gns_resolver_shorten_name(struct GNUNET_CRYPTO_ShortHashCode *zone,
* @param proc_cls the closure to pass to the processor
*/
void
-gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
- struct GNUNET_CRYPTO_ShortHashCode pzone,
- const char* name,
- GetAuthorityResultProcessor proc,
- void* proc_cls);
+gns_resolver_get_authority (struct GNUNET_CRYPTO_ShortHashCode zone,
+ struct GNUNET_CRYPTO_ShortHashCode pzone,
+ const char* name,
+ GetAuthorityResultProcessor proc,
+ void* proc_cls);
/**
* Generic function to check for TLDs
@@ -448,7 +632,9 @@ gns_resolver_get_authority(struct GNUNET_CRYPTO_ShortHashCode zone,
* @return GNUNET_YES or GNUNET_NO
*/
int
-is_tld(const char* name, const char* tld);
+is_tld (const char* name,
+ const char* tld);
+
/**
* Checks for gnunet/zkey
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index a2faecf2d6..d8da01f5b5 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- (C) 2010 Christian Grothoff (and other contributing authors)
+ (C) 2010, 2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
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,
size_t xquery_size, const void *reply_block,
size_t reply_block_size)
{
+ const struct GNSNameRecordBlock *nrb;
const char* name;
+ const char *name_end;
+ const char *rd_data;
struct GNUNET_HashCode query_key;
struct GNUNET_HashCode mhash;
struct GNUNET_HashCode chash;
struct GNUNET_CRYPTO_ShortHashCode pkey_hash;
- struct GNSNameRecordBlock *nrb;
struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp;
struct GNUNET_CRYPTO_HashAsciiEncoded xor_got;
uint32_t rd_count;
- char* rd_data = NULL;
- int rd_len;
+ size_t rd_len;
+ size_t name_len;
uint32_t record_xquery;
unsigned int record_match;
@@ -97,9 +99,15 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
/* this is a reply */
- nrb = (struct GNSNameRecordBlock *)reply_block;
- name = (const char*)&nrb[1];
-
+ nrb = (const struct GNSNameRecordBlock *)reply_block;
+ name = (const char*) &nrb[1];
+ name_end = memchr (name, 0, reply_block_size - sizeof (struct GNSNameRecordBlock));
+ if (NULL == name_end)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
+ }
+ name_len = (name_end - name) + 1;
GNUNET_CRYPTO_short_hash (&nrb->public_key,
sizeof(nrb->public_key),
&pkey_hash);
@@ -121,9 +129,8 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
record_match = 0;
rd_count = ntohl(nrb->rd_count);
- rd_data = (char*)&nrb[1];
- rd_data += strlen(name) + 1;
- rd_len = reply_block_size - (strlen(name) + 1
+ rd_data = &name[name_len];
+ rd_len = reply_block_size - (name_len
+ sizeof(struct GNSNameRecordBlock));
{
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 73085bdf50..0000000000
--- a/src/gns/proxy/gnunet-gns-proxy.py
+++ /dev/null
@@ -1,226 +0,0 @@
-#!/usr/bin/python
-
-"""
-Copyright (c) 2001 SUZUKI Hisao
-
-Permission 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:
-
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-
-THE 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.
-"""
-
-__doc__ = """Tiny HTTP Proxy.
-
-This module implements GET, HEAD, POST, PUT and DELETE methods
-on BaseHTTPServer, and behaves as an HTTP proxy. The CONNECT
-method is also implemented experimentally, but has not been
-tested yet.
-
-Any help will be greatly appreciated. SUZUKI Hisao
-"""
-
-__version__ = "0.2.1"
-
-import BaseHTTPServer, select, socket, SocketServer, urlparse, re, string, os, sys
-
-class ProxyHandler (BaseHTTPServer.BaseHTTPRequestHandler):
- __base = BaseHTTPServer.BaseHTTPRequestHandler
- __base_handle = __base.handle
-
- server_version = "TinyHTTPProxy/" + __version__
- rbufsize = 0 # self.rfile Be unbuffered
- host_port = ()
-
- def handle(self):
- (ip, port) = self.client_address
- if hasattr(self, 'allowed_clients') and ip not in self.allowed_clients:
- self.raw_requestline = self.rfile.readline()
- if self.parse_request(): self.send_error(403)
- else:
- self.__base_handle()
-
- def _connect_to(self, netloc, soc):
- i = netloc.find(':')
- to_replace = ""
- if i >= 0:
- self.host_port = netloc[:i], int(netloc[i+1:])
- if (re.match("(\w+\.)*gnunet$", self.host_port[0])):
- print 'calling gnunet-gns -a '+netloc[:i]
- auth = os.popen("gnunet-gns -a "+netloc[:i])
- lines = auth.readlines()
- if (len(lines) > 0):
- print 'result: '+lines[0].split(" ")[-1].rstrip()
- to_replace = lines[0].split(" ")[-1].rstrip()
- else:
- to_replace = "+"
- else:
- self.host_port = netloc, 80
- if (re.match("(\w+\.)*gnunet$", self.host_port[0])):
- print 'calling gnunet-gns -a '+netloc
- auth = os.popen("gnunet-gns -a "+netloc)
- lines = auth.readlines()
- if (len(lines) > 0):
- print 'result: '+lines[0].split(" ")[-1].rstrip()
- to_replace = lines[0].split(" ")[-1].rstrip()
- else:
- to_replace = "+"
-
- print "\t" "connect to %s:%d" % self.host_port
- try: soc.connect(self.host_port)
- except socket.error, arg:
- try: msg = arg[1]
- except: msg = arg
- self.send_error(404, msg)
- return (0, 0)
- return (1, to_replace)
-
- def do_CONNECT(self):
- soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- res, to_repl = self._connect_to(self.path, soc)
- if res:
- self.log_request(200)
- self.wfile.write(self.protocol_version +
- " 200 Connection established\r\n")
- self.wfile.write("Proxy-agent: %s\r\n" % self.version_string())
- self.wfile.write("\r\n")
- self._read_write(soc, to_repl, 300)
- finally:
- print "\t" "bye"
- soc.close()
- self.connection.close()
-
- def test_re2(self, mo):
- short = os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', ""))
- lines = short.readlines()
- if (len(lines) < 1):
- return mo.group(1)
- elif (len(lines[0].split(" ")) > 0):
- return 'a href="http://'+lines[0].split(" ")[-1].rstrip()
- else:
- return mo.group(1)
-
- def shorten_zkey(self):
- return lambda mo: self.test_re2(mo)
- #return lambda mo: 'a href="http://'+os.popen("gnunet-gns -s"+string.replace(mo.group(1), 'a href="http://', "")).readlines()[0].split(" ")[-1].rstrip()
-
- def test_re(self, to_repl, mo):
- short = os.popen("gnunet-gns -s "+string.replace(mo.group(1)+to_repl, 'a href="http://', ""))
- lines = short.readlines()
- if (len(lines) < 1):
- return to_repl
- elif (len(lines[0].split(" ")) > 0):
- return 'a href="http://'+lines[0].split(" ")[-1].rstrip()
- else:
- return to_repl
-
- def replace_and_shorten(self, to_repl):
- return lambda mo: self.test_re(to_repl, mo)
- # 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()
- #full = string.replace(mo.group(1)+to_repl, 'a href="http://', "")
- #print 'calling gnunet-gns -s '+full
- #s = os.popen("gnunet-gns -s "+full)
- #lines = s.readlines()
- #print 'short: '+lines[0].split(" ")[-1].rstrip()
- #return 'a href="'+lines[0].split(" ")[-1].rstrip()
-
- def do_GET(self):
- (scm, netloc, path, params, query, fragment) = urlparse.urlparse(
- self.path, 'http')
- if scm != 'http' or fragment or not netloc:
- self.send_error(400, "bad url %s" % self.path)
- return
- soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- res, to_repl = self._connect_to(netloc, soc)
- if res:
- self.log_request()
- soc.send("%s %s %s\r\n" % (
- self.command,
- urlparse.urlunparse(('', '', path, params, query, '')),
- self.request_version))
- if (re.match("(\w+\.)*gnunet$", self.headers['Host'])):
- leho = os.popen("gnunet-gns -t LEHO -u "+self.headers['Host']).readlines()
- if (len(leho) < 2):
- print "Legacy hostname lookup failed!"
- elif (len(leho) == 1):
- print "Legacy hostname not present!"
- else:
- newhost = leho[1].split(" ")[-1].rstrip()
- print "Changing Host: "+self.headers['Host']+" to "+newhost
- self.headers['Host'] = newhost
- self.headers['Connection'] = 'close'
- del self.headers['Proxy-Connection']
- del self.headers['Accept-Encoding']
- for key_val in self.headers.items():
- soc.send("%s: %s\r\n" % key_val)
- soc.send("\r\n")
- self._read_write(soc, to_repl)
- finally:
- print "\t" "bye"
- soc.close()
- self.connection.close()
-
- def _read_write(self, soc, to_repl="", max_idling=20):
- iw = [self.connection, soc]
- ow = []
- count = 0
- msg = ''
- while 1:
- count += 1
- (ins, _, exs) = select.select(iw, ow, iw, 3)
- if exs:
- break
- if ins:
- for i in ins:
- if i is soc:
- out = self.connection
- else:
- out = soc
- data = i.recv(8192)
- if data:
- #try:
- data = re.sub(r'\nAccept-Ranges: \w+', r'', data)
- data = re.sub('(a href="http://(\w+\.)*zkey)',
- self.shorten_zkey(), data)
- if (re.match("(\w+\.)*gnunet$", self.host_port[0])):
- arr = self.host_port[0].split('.')
- arr.pop(0)
- data = re.sub('(a href="http://(\w+\.)*)(\+)',
- self.replace_and_shorten(to_repl), data)
- out.send(data)
- count = 0
- #except:
- # print "GNS exception:", sys.exc_info()[0]
-
- else:
- print "\t" "idle", count
- print msg
- if count == max_idling: break
-
- do_HEAD = do_GET
- do_POST = do_GET
- do_PUT = do_GET
- do_DELETE=do_GET
-
-class ThreadingHTTPServer (SocketServer.ThreadingMixIn,
- BaseHTTPServer.HTTPServer): pass
-
-if __name__ == '__main__':
- from sys import argv
- if argv[1:] and argv[1] in ('-h', '--help'):
- print argv[0], "[port [allowed_client_name ...]]"
- else:
- if argv[2:]:
- allowed = []
- for name in argv[2:]:
- client = socket.gethostbyname(name)
- allowed.append(client)
- print "Accept: %s (%s)" % (client, name)
- ProxyHandler.allowed_clients = allowed
- del argv[2:]
- else:
- print "Any clients will be served..."
- BaseHTTPServer.test(ProxyHandler, ThreadingHTTPServer)
-
diff --git a/src/gns/proxy/test_cert.pem b/src/gns/proxy/test_cert.pem
deleted file mode 100644
index 806fd48ff7..0000000000
--- a/src/gns/proxy/test_cert.pem
+++ /dev/null
@@ -1,51 +0,0 @@
------BEGIN CERTIFICATE-----
-MIIEBzCCAu+gAwIBAgIJAI38FT23eNxGMA0GCSqGSIb3DQEBBQUAMIGZMQswCQYD
-VQQGEwJERTEQMA4GA1UECAwHQmF2YXJpYTEPMA0GA1UEBwwGTXVuaWNoMR0wGwYD
-VQQKDBRHTlVuZXQgTmFtaW5nIFN5c3RlbTEPMA0GA1UECwwGR05VbmV0MRUwEwYD
-VQQDDAxHTlMgUHJveHkgQ0ExIDAeBgkqhkiG9w0BCQEWEWJvdW5jZUBnbnVuZXQu
-b3JnMB4XDTEyMDcxNDIwMTQxN1oXDTIyMDcxMjIwMTQxN1owgZkxCzAJBgNVBAYT
-AkRFMRAwDgYDVQQIDAdCYXZhcmlhMQ8wDQYDVQQHDAZNdW5pY2gxHTAbBgNVBAoM
-FEdOVW5ldCBOYW1pbmcgU3lzdGVtMQ8wDQYDVQQLDAZHTlVuZXQxFTATBgNVBAMM
-DEdOUyBQcm94eSBDQTEgMB4GCSqGSIb3DQEJARYRYm91bmNlQGdudW5ldC5vcmcw
-ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDXPUIPuAKOMSJkgPUPBJ6K
-axnhZ+uQ461AA6P+8YAIJFgN+rlWdeJPEmQwBAsu4tFGwQ+QwPRlPUffyLl4GA24
-8sHcrGImTnLaybKrqLMud7ti4aqct/w3r2gwJiaGDJguav/mOLyqRNlsqxVUjOC+
-6T39PaFofILekk2YQUnngl5Tvp4F20MhpziRPuHeObHDQHSzGxzirubvFb36bI3V
-DA4HeMaom/oAU47mkx72JE0S1xlIa7H+d7n7oS73uO7oufB+H0FAnNJa+S9PF8t+
-bezCnfBSxwIpP3fUtUOq3lbRc6wx3Bm1hkQ1M86H+XuWXCy6HLz54P3GrYiw9sOX
-AgMBAAGjUDBOMB0GA1UdDgQWBBRZs/qlW1u7P99aF6pcEQuCU1avXDAfBgNVHSME
-GDAWgBRZs/qlW1u7P99aF6pcEQuCU1avXDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3
-DQEBBQUAA4IBAQCfx7JL7fX2CnLIyvs9cqEsu/8zFGwSg4NRj53IgE3K7z2pP3Wb
-NdTo5JmlVOgy3ywQYPXPqveFXGIZR4+fPSRFIYNRuaqiRp6brx9h4xAVwbfp7UF5
-vZEGCcPnuXt2ZL+EE7JJNyCTp6ZfjnvTkAoKOQtMz5YfhaM65uIsA/Rr1fs7nk8z
-qq9LQU8+sYzgzpGXFVrv48vuq+/d4V2wj+d2z4Q3VA1smsa3gstebEQUgyiFtMYB
-+OHI0RFLQY97c5CyQRqZsgMto7IPoKwaTWTVvlQcxikx+Xs1SG9vYndBaI1ClLSI
-xrbu7Gk2bwLfUXxdaJSOTrgKHLXTx14FXPbT
------END CERTIFICATE-----
------BEGIN RSA PRIVATE KEY-----
-MIIEowIBAAKCAQEA1z1CD7gCjjEiZID1DwSeimsZ4WfrkOOtQAOj/vGACCRYDfq5
-VnXiTxJkMAQLLuLRRsEPkMD0ZT1H38i5eBgNuPLB3KxiJk5y2smyq6izLne7YuGq
-nLf8N69oMCYmhgyYLmr/5ji8qkTZbKsVVIzgvuk9/T2haHyC3pJNmEFJ54JeU76e
-BdtDIac4kT7h3jmxw0B0sxsc4q7m7xW9+myN1QwOB3jGqJv6AFOO5pMe9iRNEtcZ
-SGux/ne5+6Eu97ju6Lnwfh9BQJzSWvkvTxfLfm3swp3wUscCKT931LVDqt5W0XOs
-MdwZtYZENTPOh/l7llwsuhy8+eD9xq2IsPbDlwIDAQABAoIBAG6s9iIlCVNaWof5
-c4lEY81jIwyvpgZ7vCNVe+dlAOOu5IRTryeROExWdaPnAGUchmXucfWJ8mF4cFPW
-39+r5qp6UUsKbPGrlw1/d1sjRPeY44cF6Pfq90se6+EOTPLS2RHNPUaBWCnpey+Q
-jUhLpGkmgBSOs0eJ9rVB35pxv/HFOxnFQO80sAJElixEZlGL1jgLKCFDW/5BDKrO
-oKiRylugTC75pcAW6tvqZtE/WCPr1xaJP2AOfLlWQY/STR1NyeJxs4JSsQlCZNBY
-RTam0kVQhs64QGYh+XKhQtvaqTfN22flCiJHuOy3sDlst8dPrlEW8bHVTCDE18y0
-ZzwVcVkCgYEA6ts1crJ/69RuvZd7c5//b1ptjaXQhRTRYGDLdAaTY+cSP29bc5CG
-fx/Zohg+5hpD/1fhiWkQPY5u88XQkLxnLSiSt0WDOslTxWLAnDJa6VakldTOV8Fl
-4KmeXU1jG2gYmTiFf5nz7FqAudld0Mim1qWGu4rtVeaaEyFoyfndw1sCgYEA6p3u
-dyT5dNSJFdHO5auvzexRukBOjnaUTz7fVukzs44hnW8hv3hYAR5o7u2Ye5f0Xclr
-tLyeZfeiiBGkANy592ljI4ZeDnkkrWH9HH+fk3nJUs1VsP7viJSouhpvGZpz2sU9
-Axz4oUb9/1bDA2BSs0cEFGZ9K4RWoTg7aL11YXUCgYAaguBHsEqsbnCJyl3PMZJ+
-GXEgekVNoIn6HTMaR9u/fUgcDQ//vaLRGuFQYPhItVJTsrHs9wU0Ta3MqtneXMYw
-3NGjCp/DtRJVx84CU9TbXkJ5/2nDkjtT3xHXanLzlw6fzTeUreZRGe5KDHWAqgXb
-WRgad5ZPChb+bdkMY75a3QKBgQCYTc3wKmCGJzKWp4zYK4wE8dRcREK62N+OUhJK
-KTkW5r2LpgkSct0uXL9h23uRQCOyfn8c5RUuvIMWMd11cdSHeDKTbTbBzoKwy1u0
-lGTTJ8w5pHJsZBK7Z0XhCif1Rv7Olhv1WWlNyPg6Oeh+2JjXKNLNK3s2NMLIBekL
-JXJ9wQKBgGsvTzH5cUG7dIiIH7X6UQ/RN9eY7y5se5g+JUYZwGljZcLM0svanxW1
-UpPA2weyrFrWvDUEupMVg7rrocBMMJ205OUaymKdrSaVeWQxevzigEt6ZX67G6Xw
-uj+MLQ3+yj87JlVqoDRvAHlltLfz9AzPM2sSGOdaqC2q14DJXVOU
------END RSA PRIVATE KEY-----
diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c
index 69d7b873e8..7b871963f4 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)
left -= cpy;
if (download_pos < sizeof (struct GNUNET_MessageHeader))
{
- GNUNET_assert (left == 0);
+ GNUNET_assert (0 == left);
break;
}
msg = (const struct GNUNET_MessageHeader *) download_buffer;
diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h
index 93eec8ded2..f104834249 100644
--- a/src/include/gnunet_constants.h
+++ b/src/include/gnunet_constants.h
@@ -52,30 +52,11 @@ extern "C"
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/**
- * After how long do we consider a connection to a peer dead
- * if we got an explicit disconnect and were unable to reconnect?
- */
-#define GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
-
-/**
* How long do we delay reading more from a peer after a quota violation?
*/
#define GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
/**
- * How long do we wait after a FORK+EXEC before testing for the
- * resulting process to be up (port open, waitpid, etc.)?
- */
-#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
-
-/**
- * After how long do we retry a service connection that was
- * unavailable? Used in cases where an exponential back-off
- * seems inappropriate.
- */
-#define GNUNET_CONSTANTS_SERVICE_RETRY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
-
-/**
* After how long do we consider a service unresponsive
* even if we assume that the service commonly does not
* respond instantly (DNS, Database, etc.).
@@ -119,18 +100,6 @@ extern "C"
#define GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE (24 + sizeof (struct GNUNET_HashCode))
/**
- * Size of the 'struct OutboundMessage' of the transport
- * (which, in combination with the
- * GNUNET_CONSTANTS_CORE_SIZE_ENCRYPTED_MESSAGE) defines
- * the headers that must be pre-pendable to all GNUnet
- * messages. Taking GNUNET_SERVER_MAX_MESSAGE_SIZE
- * and subtracting these two constants defines the largest
- * message core can handle.
- */
-#define GNUNET_CONSTANTS_TRANSPORT_SIZE_OUTBOUND_MESSAGE (16 + sizeof (struct GNUNET_PeerIdentity))
-
-
-/**
* What is the maximum size for encrypted messages? Note that this
* number imposes a clear limit on the maximum size of any message.
* 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 3bb60d9e5c..ff7bffdbbd 100644
--- a/src/include/gnunet_crypto_lib.h
+++ b/src/include/gnunet_crypto_lib.h
@@ -71,7 +71,6 @@ enum GNUNET_CRYPTO_Quality
*/
#define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8)
-
/**
* @brief Length of RSA encrypted data (2048 bit)
*
@@ -84,30 +83,27 @@ enum GNUNET_CRYPTO_Quality
*/
#define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256
-
/**
* Length of an RSA KEY (n,e,len), 2048 bit (=256 octests) key n, 2 byte e
*/
#define GNUNET_CRYPTO_RSA_KEY_LENGTH 258
-
/**
* Length of a hash value
*/
#define GNUNET_CRYPTO_HASH_LENGTH 512/8
-
/**
* FIXME: what is an acceptable value here?
* Note: round to multiple of 8 minus 2.
*/
-#define GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH 510
+#define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 138
/**
* FIXME: what is an acceptable value here?
* Maximum length of the public key (q-point, Q = dP) when encoded.
*/
-#define GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH 254
+#define GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH 140
/**
@@ -277,7 +273,7 @@ struct GNUNET_CRYPTO_EccSignature
/**
* S-expression, padded with zeros.
*/
- char sexpr[GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH];
+ char sexpr[GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH];
};
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index 06a5ce9038..1618b24421 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -73,6 +73,16 @@ struct GNUNET_NETWORK_FDSet
/**
+ * Test if the given protocol family is supported by this system.
+ *
+ * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX)
+ * @return GNUNET_OK if the PF is supported
+ */
+int
+GNUNET_NETWORK_test_pf (int pf);
+
+
+/**
* Given a unixpath that is too long (larger than UNIX_PATH_MAX),
* shorten it to an acceptable length while keeping it unique
* 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 da22ab31eb..d131e4eef4 100644
--- a/src/include/gnunet_time_lib.h
+++ b/src/include/gnunet_time_lib.h
@@ -150,6 +150,22 @@ GNUNET_NETWORK_STRUCT_END
#define GNUNET_TIME_UNIT_FOREVER_ABS GNUNET_TIME_absolute_get_forever_ ()
+
+/**
+ * Threshold after which exponential backoff should not increase (15 m).
+ */
+#define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+
+/**
+ * Perform our standard exponential back-off calculation, starting at 1mst
+ * and then going by a factor of 2 up unto a maximum of 1s.
+ *
+ * @param r current backoff time, initially zero
+ */
+#define GNUNET_TIME_STD_BACKOFF(r) GNUNET_TIME_relative_min (GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD, \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS, (r)), 2));
+
/**
* Return relative time of 0ms.
*/
diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c
index ca6a174eef..c0b20268b0 100644
--- a/src/namestore/test_namestore_api.c
+++ b/src/namestore/test_namestore_api.c
@@ -49,6 +49,24 @@ static int res;
static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
+
+static void
+cleanup ()
+{
+ if (NULL != nsh)
+ {
+ GNUNET_NAMESTORE_disconnect (nsh);
+ nsh = NULL;
+ }
+ if (NULL != privkey)
+ {
+ GNUNET_CRYPTO_rsa_key_free (privkey);
+ privkey = NULL;
+ }
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Re-establish the connection to the service.
*
@@ -63,17 +81,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
GNUNET_NAMESTORE_cancel (nsqe);
nsqe = NULL;
}
- if (nsh != NULL)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
- if (privkey != NULL)
- {
- GNUNET_CRYPTO_rsa_key_free (privkey);
- privkey = NULL;
- }
- GNUNET_SCHEDULER_shutdown ();
+ cleanup ();
res = 1;
}
@@ -81,21 +89,7 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
static void
end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_NO_TASK;
- }
- if (privkey != NULL)
- {
- GNUNET_CRYPTO_rsa_key_free (privkey);
- privkey = NULL;
- }
- if (nsh != NULL)
- {
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- }
+ cleanup ();
res = 0;
}
@@ -113,8 +107,12 @@ name_lookup_proc (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Namestore lookup result %p `%s' %i %p %p\n",
zone_key, name, rd_count, rd, signature);
- res = 0;
- GNUNET_SCHEDULER_add_now(&end, NULL);
+ if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
@@ -124,9 +122,11 @@ put_cont (void *cls, int32_t success, const char *emsg)
const char *name = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
-
- nsqe = GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL);
+ "Name store added record for `%s': %s\n",
+ name,
+ (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
+ nsqe = GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0,
+ &name_lookup_proc, NULL);
}
@@ -142,19 +142,21 @@ run (void *cls,
endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
&endbadly, NULL);
- GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR,
- "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
+ GNUNET_asprintf (&hostkey_file,
+ "zonefiles%s%s",
+ DIR_SEPARATOR_STR,
+ "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file);
- privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file);
+ privkey = GNUNET_CRYPTO_rsa_key_create_from_file (hostkey_file);
GNUNET_free (hostkey_file);
GNUNET_assert (privkey != NULL);
- GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
+ GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey);
GNUNET_CRYPTO_short_hash (&pubkey, sizeof (pubkey), &zone);
memset (&signature, '\0', sizeof (signature));
rd.expiration_time = GNUNET_TIME_absolute_get().abs_value;
rd.record_type = TEST_RECORD_TYPE;
rd.data_size = TEST_RECORD_DATALEN;
- rd.data = GNUNET_malloc(TEST_RECORD_DATALEN);
+ rd.data = GNUNET_malloc (TEST_RECORD_DATALEN);
memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c
index 6828e034cf..0f1c133bbc 100644
--- a/src/namestore/test_namestore_api_lookup.c
+++ b/src/namestore/test_namestore_api_lookup.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2009 Christian Grothoff (and other contributing authors)
+ (C) 2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -18,7 +18,7 @@
Boston, MA 02111-1307, USA.
*/
/**
- * @file namestore/test_namestore_api.c
+ * @file namestore/test_namestore_api_lookup.c
* @brief testcase for namestore_api.c
*/
#include "platform.h"
@@ -53,11 +53,30 @@ static struct GNUNET_CRYPTO_ShortHashCode s_zone;
static struct GNUNET_NAMESTORE_RecordData *s_rd;
+static struct GNUNET_NAMESTORE_QueueEntry *nsqe;
+
static char *s_name;
static int res;
+static void
+cleanup ()
+{
+ if (NULL != nsh)
+ {
+ GNUNET_NAMESTORE_disconnect (nsh);
+ nsh = NULL;
+ }
+ if (NULL != privkey)
+ {
+ GNUNET_CRYPTO_rsa_key_free (privkey);
+ privkey = NULL;
+ }
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
/**
* Re-establish the connection to the service.
*
@@ -67,12 +86,7 @@ static int res;
static void
endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if (nsh != NULL)
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
- if (privkey != NULL)
- GNUNET_CRYPTO_rsa_key_free (privkey);
- privkey = NULL;
+ cleanup ();
res = 1;
}
@@ -80,22 +94,12 @@ endbadly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
static void
end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- int c;
+ unsigned int c;
- if (endbadly_task != GNUNET_SCHEDULER_NO_TASK)
- {
- GNUNET_SCHEDULER_cancel (endbadly_task);
- endbadly_task = GNUNET_SCHEDULER_NO_TASK;
- }
for (c = 0; c < RECORDS; c++)
GNUNET_free_non_null((void *) s_rd[c].data);
GNUNET_free (s_rd);
- if (privkey != NULL)
- GNUNET_CRYPTO_rsa_key_free (privkey);
- privkey = NULL;
- if (nsh != NULL)
- GNUNET_NAMESTORE_disconnect (nsh);
- nsh = NULL;
+ cleanup ();
}
@@ -111,19 +115,21 @@ name_lookup_proc (void *cls,
static int found = GNUNET_NO;
int c;
- if (n != NULL)
+ if (NULL != n)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking returned results\n");
- if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
+ if (0 != memcmp (zone_key, &pubkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
{
GNUNET_break (0);
}
GNUNET_assert (NULL != signature);
- if (0 != memcmp (signature, s_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)))
+ if (0 != memcmp (signature, s_signature,
+ sizeof (struct GNUNET_CRYPTO_RsaSignature)))
{
GNUNET_break (0);
}
- if (0 != strcmp(n, s_name))
+ if (0 != strcmp (n, s_name))
{
GNUNET_break (0);
}
@@ -143,14 +149,20 @@ name_lookup_proc (void *cls,
}
else
{
- if (found != GNUNET_YES)
+ if (GNUNET_YES != found)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to lookup records for name `%s'\n", s_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to lookup records for name `%s'\n", s_name);
res = 1;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Lookup done for name %s'\n", s_name);
}
- GNUNET_SCHEDULER_add_now(&end, NULL);
+ if (GNUNET_SCHEDULER_NO_TASK != endbadly_task)
+ {
+ GNUNET_SCHEDULER_cancel (endbadly_task);
+ endbadly_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ GNUNET_SCHEDULER_add_now (&end, NULL);
}
@@ -159,17 +171,22 @@ put_cont (void *cls, int32_t success, const char *emsg)
{
char * name = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
- if (success == GNUNET_OK)
+ nsqe = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Name store added record for `%s': %s\n", name,
+ (GNUNET_OK == success) ? "SUCCESS" : "FAIL");
+ if (GNUNET_OK == success)
{
res = 0;
- GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0, &name_lookup_proc, NULL);
+ GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, 0,
+ &name_lookup_proc, NULL);
}
else
{
res = 1;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
- GNUNET_SCHEDULER_add_now(&end, NULL);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to put records for name `%s'\n", name);
+ GNUNET_SCHEDULER_shutdown ();
}
}
@@ -200,12 +217,14 @@ run (void *cls,
{
size_t rd_ser_len;
struct GNUNET_TIME_Absolute et;
+ char rd_ser[rd_ser_len];
- endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
+ endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+ &endbadly, NULL);
/* load privat key from file not included in zonekey dir */
privkey = GNUNET_CRYPTO_rsa_key_create_from_file("test_hostkey");
- GNUNET_assert (privkey != NULL);
+ GNUNET_assert (NULL != privkey);
/* get public key */
GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey);
@@ -214,24 +233,23 @@ run (void *cls,
s_rd = create_record (RECORDS);
rd_ser_len = GNUNET_NAMESTORE_records_get_size(RECORDS, s_rd);
- char rd_ser[rd_ser_len];
GNUNET_NAMESTORE_records_serialize(RECORDS, s_rd, rd_ser_len, rd_ser);
/* sign */
et.abs_value = s_rd[0].expiration_time;
- s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, s_rd, RECORDS);
+ s_signature = GNUNET_NAMESTORE_create_signature (privkey, et, s_name,
+ s_rd, RECORDS);
/* create random zone hash */
- GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
+ GNUNET_CRYPTO_short_hash (&pubkey,
+ sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ &s_zone);
nsh = GNUNET_NAMESTORE_connect (cfg);
GNUNET_break (NULL != nsh);
-
- GNUNET_break (s_rd != NULL);
- GNUNET_break (s_name != NULL);
-
- GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
- GNUNET_TIME_UNIT_FOREVER_ABS,
- RECORDS, s_rd, s_signature, put_cont, s_name);
+ nsqe = GNUNET_NAMESTORE_record_put (nsh, &pubkey, s_name,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ RECORDS, s_rd, s_signature,
+ &put_cont, s_name);
}
@@ -251,4 +269,4 @@ main (int argc, char *argv[])
}
-/* end of test_namestore_api.c */
+/* end of test_namestore_api_lookup.c */
diff --git a/src/nat/nat.c b/src/nat/nat.c
index eeafc5b97f..2379960bbd 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)
h->server_stdout = NULL;
h->server_stdout_handle = NULL;
/* now try to restart it */
- h->server_retry_delay =
- GNUNET_TIME_relative_multiply (h->server_retry_delay, 2);
- h->server_retry_delay =
- GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_HOURS,
- h->server_retry_delay);
+ h->server_retry_delay = GNUNET_TIME_STD_BACKOFF (h->server_retry_delay);
h->server_read_task =
GNUNET_SCHEDULER_add_delayed (h->server_retry_delay,
&restart_nat_server, h);
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index 9a44197c01..136f4b622c 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -154,16 +154,7 @@ reschedule_connect (struct GNUNET_NSE_Handle *h)
h->reconnect_delay.rel_value);
h->reconnect_task =
GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
- if (h->reconnect_delay.rel_value == 0)
- {
- h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
- }
- else
- {
- h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
- h->reconnect_delay =
- GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->reconnect_delay);
- }
+ h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c
index 7d2cd7ba4b..32283bad48 100644
--- a/src/pt/test_gns_vpn.c
+++ b/src/pt/test_gns_vpn.c
@@ -415,30 +415,6 @@ run (void *cls,
/**
- * Test if the given AF is supported by this system.
- *
- * @param af to test
- * @return GNUNET_OK if the AF is supported
- */
-static int
-test_af (int af)
-{
- int s;
-
- s = socket (af, SOCK_STREAM, 0);
- if (-1 == s)
- {
- if (EAFNOSUPPORT == errno)
- return GNUNET_NO;
- fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
- return GNUNET_SYSERR;
- }
- close (s);
- return GNUNET_OK;
-}
-
-
-/**
* Open '/dev/null' and make the result the given
* file descriptor.
*
@@ -579,13 +555,13 @@ main (int argc, char *const *argv)
dest_af = AF_INET;
src_af = AF_INET;
- if (GNUNET_OK == test_af (AF_INET6))
+ if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
use_v6 = GNUNET_YES;
else
use_v6 = GNUNET_NO;
- if ( (GNUNET_OK != test_af (src_af)) ||
- (GNUNET_OK != test_af (dest_af)) )
+ if ( (GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
+ (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)) )
{
fprintf (stderr,
"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 72551e3531..8b9bb2b204 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,
}
-/**
- * Test if the given AF is supported by this system.
- *
- * @param af to test
- * @return GNUNET_OK if the AF is supported
- */
-static int
-test_af (int af)
-{
- int s;
-
- s = socket (af, SOCK_STREAM, 0);
- if (-1 == s)
- {
- if (EAFNOSUPPORT == errno)
- return GNUNET_NO;
- fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
- return GNUNET_SYSERR;
- }
- close (s);
- return GNUNET_OK;
-}
-
-
int
main (int argc, char *const *argv)
{
@@ -476,7 +452,8 @@ main (int argc, char *const *argv)
fprintf (stderr, "invalid binary suffix `%s'\n", type);
return 1;
}
- if ((GNUNET_OK != test_af (src_af)) || (GNUNET_OK != test_af (dest_af)))
+ if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
+ (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)))
{
fprintf (stderr,
"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 0f4149ead2..305c6f3a5c 100644
--- a/src/statistics/statistics_api.c
+++ b/src/statistics/statistics_api.c
@@ -516,9 +516,7 @@ reconnect_later (struct GNUNET_STATISTICS_Handle *h)
}
h->backoff_task =
GNUNET_SCHEDULER_add_delayed (h->backoff, &reconnect_task, h);
- h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
- h->backoff =
- GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
+ h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff);
}
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c
index a5ca040b9e..b712eb3d88 100644
--- a/src/stream/stream_api.c
+++ b/src/stream/stream_api.c
@@ -895,6 +895,7 @@ write_data (struct GNUNET_STREAM_Socket *socket)
packet++;
}
io_handle->packets_sent = packet;
+ // FIXME: 8s is not good, should use GNUNET_TIME_STD_BACKOFF...
if (GNUNET_SCHEDULER_NO_TASK == socket->data_retransmission_task_id)
socket->data_retransmission_task_id =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
diff --git a/src/testing_old/testing.c b/src/testing_old/testing.c
index 78f58f47bf..5a30959356 100644
--- a/src/testing_old/testing.c
+++ b/src/testing_old/testing.c
@@ -45,6 +45,20 @@
*/
#define EMPTY_HACK GNUNET_YES
+
+/**
+ * After how long do we retry a service connection that was
+ * unavailable? Used in cases where an exponential back-off
+ * seems inappropriate.
+ */
+#define GNUNET_CONSTANTS_SERVICE_RETRY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
+
+/**
+ * How long do we wait after a FORK+EXEC before testing for the
+ * resulting process to be up (port open, waitpid, etc.)?
+ */
+#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
+
/**
* How long do we wait after starting gnunet-service-arm
* for the core service to be alive?
diff --git a/src/testing_old/testing_group.c b/src/testing_old/testing_group.c
index f5c2258762..66c498256c 100644
--- a/src/testing_old/testing_group.c
+++ b/src/testing_old/testing_group.c
@@ -41,6 +41,12 @@
/**
+ * How long do we wait after a FORK+EXEC before testing for the
+ * resulting process to be up (port open, waitpid, etc.)?
+ */
+#define GNUNET_CONSTANTS_EXEC_WAIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200)
+
+/**
* Lowest port used for GNUnet testing. Should be high enough to not
* conflict with other applications running on the hosts but be low
* 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 49f82e66b7..16463f6462 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)
h->reconnect_delay.rel_value);
h->reconnect_task =
GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
- if (h->reconnect_delay.rel_value == 0)
- {
- h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
- }
- else
- {
- h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
- h->reconnect_delay =
- GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, h->reconnect_delay);
- }
+ h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 655be833f2..217aecdb5e 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)
GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
GNUNET_CLIENT_disconnect (pal_ctx->client);
pal_ctx->client = NULL;
- pal_ctx->backoff = GNUNET_TIME_relative_max (GNUNET_TIME_UNIT_MILLISECONDS,
- GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (pal_ctx->backoff, 2),
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)));
+ pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff,
&do_connect,
pal_ctx);
diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c
index 60f70e0834..56cb3c7094 100644
--- a/src/util/crypto_ecc.c
+++ b/src/util/crypto_ecc.c
@@ -25,7 +25,9 @@
*
* This is just a first, completely untested, draft hack for future ECC support.
* TODO:
- * - adjust encoding length and other parameters
+ * - fix public key generation; somehow the result is currently considered invalid by libgcrypt
+ * => suspect that libgcrypt does NOT take pabgn from "CURVE" for public key if not
+ * explicitly given!
* - actually test it!
*/
#include "platform.h"
@@ -65,26 +67,6 @@ struct GNUNET_CRYPTO_EccPrivateKey
/**
- * If target != size, move target bytes to the
- * end of the size-sized buffer and zero out the
- * first target-size bytes.
- *
- * @param buf original buffer
- * @param size number of bytes in the buffer
- * @param target target size of the buffer
- */
-static void
-adjust (unsigned char *buf, size_t size, size_t target)
-{
- if (size < target)
- {
- memmove (&buf[target - size], buf, size);
- memset (buf, 0, target - size);
- }
-}
-
-
-/**
* Free memory occupied by ECC key
*
* @param privatekey pointer to the memory to free
@@ -171,6 +153,7 @@ GNUNET_CRYPTO_ecc_key_get_public (const struct GNUNET_CRYPTO_EccPrivateKey *priv
size_t size;
int rc;
+ memset (pub, 0, sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
rc = key_from_sexp (&skey, priv->sexp, "public-key", "q");
if (rc)
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
gcry_mpi_print (GCRYMPI_FMT_USG, pub->key, size, &size,
skey));
pub->len = htons (size);
- adjust (&pub->key[0], size, GNUNET_CRYPTO_ECC_MAX_PUBLIC_KEY_LENGTH);
gcry_mpi_release (skey);
}
@@ -245,7 +227,7 @@ GNUNET_CRYPTO_ecc_public_key_from_string (const char *enc,
sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
return GNUNET_SYSERR;
if ( (ntohs (pub->size) != sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) ||
- (ntohs (pub->len) > GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH) )
+ (ntohs (pub->len) > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH) )
return GNUNET_SYSERR;
return GNUNET_OK;
}
@@ -267,24 +249,38 @@ decode_public_key (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded *publicK
size_t erroff;
int rc;
- if (ntohs (publicKey->len) > GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH)
+ if (ntohs (publicKey->len) > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH)
{
GNUNET_break (0);
return NULL;
}
- size = ntohs (publicKey->size);
+ size = ntohs (publicKey->len);
if (0 != (rc = gcry_mpi_scan (&q, GCRYMPI_FMT_USG, publicKey->key, size, &size)))
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
return NULL;
}
- rc = gcry_sexp_build (&result, &erroff, "(public-key(ecc((curve \"" CURVE "\")(q %m)))", q);
+
+ rc = gcry_sexp_build (&result, &erroff,
+ "(public-key(ecdsa(curve \"" CURVE "\")(q %m)))",
+ q);
gcry_mpi_release (q);
if (0 != rc)
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc); /* erroff gives more info */
return NULL;
}
+ // FIXME: is this key expected to pass pk_testkey?
+#if 0
+#if EXTRA_CHECKS
+ if (0 != (rc = gcry_pk_testkey (result)))
+ {
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_pk_testkey", rc);
+ gcry_sexp_release (result);
+ return NULL;
+ }
+#endif
+#endif
return result;
}
@@ -386,7 +382,7 @@ ecc_key_create ()
int rc;
if (0 != (rc = gcry_sexp_build (&s_keyparam, NULL,
- "(genkey(ecdsa(curve 10:NIST P-521)))")))
+ "(genkey(ecdsa(curve \"" CURVE "\")))")))
{
LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_sexp_build", rc);
return NULL;
@@ -428,7 +424,7 @@ try_read_key (const char *filename)
if (GNUNET_YES != GNUNET_DISK_file_test (filename))
return NULL;
- /* hostkey file exists already, read it! */
+ /* key file exists already, read it! */
if (NULL == (fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE)))
{
@@ -582,12 +578,9 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
GNUNET_CRYPTO_ecc_key_get_public (ret, &pub);
GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("I am host `%s'. Stored new private key in `%s'.\n"),
- GNUNET_i2s (&pid), filename);
return ret;
}
- /* hostkey file exists already, read it! */
+ /* key file exists already, read it! */
fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
if (NULL == fd)
@@ -611,7 +604,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
STRERROR (ec));
LOG (GNUNET_ERROR_TYPE_ERROR,
_
- ("This may be ok if someone is currently generating a hostkey.\n"));
+ ("This may be ok if someone is currently generating a private key.\n"));
}
short_wait ();
continue;
@@ -632,7 +625,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
fs = 0;
if (fs < sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded))
{
- /* maybe we got the read lock before the hostkey generating
+ /* maybe we got the read lock before the key generating
* process had a chance to get the write lock; give it up! */
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd, 0,
@@ -642,12 +635,12 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_
- ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"),
+ ("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
filename, (unsigned int) fs,
(unsigned int) sizeof (struct GNUNET_CRYPTO_EccPrivateKeyBinaryEncoded));
LOG (GNUNET_ERROR_TYPE_ERROR,
_
- ("This may be ok if someone is currently generating a hostkey.\n"));
+ ("This may be ok if someone is currently generating a key.\n"));
}
short_wait (); /* wait a bit longer! */
continue;
@@ -679,9 +672,6 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename)
{
GNUNET_CRYPTO_ecc_key_get_public (ret, &pub);
GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("I am host `%s'. Read private key from `%s'.\n"), GNUNET_i2s (&pid),
- filename);
}
return ret;
}
@@ -909,15 +899,15 @@ GNUNET_CRYPTO_ecc_key_create_start (const char *filename,
/**
- * Setup a hostkey file for a peer given the name of the
+ * Setup a key file for a peer given the name of the
* configuration file (!). This function is used so that
* at a later point code can be certain that reading a
- * hostkey is fast (for example in time-dependent testcases).
+ * key is fast (for example in time-dependent testcases).
*
* @param cfg_name name of the configuration file to use
*/
void
-GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name)
+GNUNET_CRYPTO_ecc_setup_key (const char *cfg_name)
{
struct GNUNET_CONFIGURATION_Handle *cfg;
struct GNUNET_CRYPTO_EccPrivateKey *pk;
@@ -947,12 +937,12 @@ GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name)
static gcry_sexp_t
data_to_pkcs1 (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
{
- struct GNUNET_HashCode hc;
+ struct GNUNET_CRYPTO_ShortHashCode hc;
size_t bufSize;
gcry_sexp_t data;
- GNUNET_CRYPTO_hash (purpose, ntohl (purpose->size), &hc);
-#define FORMATSTRING "(4:data(5:flags5:pkcs1)(4:hash6:sha51264:0123456789012345678901234567890123456789012345678901234567890123))"
+ GNUNET_CRYPTO_short_hash (purpose, ntohl (purpose->size), &hc);
+#define FORMATSTRING "(4:data(5:flags5:pkcs1)(4:hash6:sha25632:01234567890123456789012345678901))"
bufSize = strlen (FORMATSTRING) + 1;
{
char buff[bufSize];
@@ -961,8 +951,8 @@ data_to_pkcs1 (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose)
memcpy (&buff
[bufSize -
strlen
- ("0123456789012345678901234567890123456789012345678901234567890123))")
- - 1], &hc, sizeof (struct GNUNET_HashCode));
+ ("01234567890123456789012345678901))")
+ - 1], &hc, sizeof (struct GNUNET_CRYPTO_ShortHashCode));
GNUNET_assert (0 == gcry_sexp_new (&data, buff, bufSize, 0));
}
#undef FORMATSTRING
@@ -986,14 +976,20 @@ GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *key,
gcry_sexp_t result;
gcry_sexp_t data;
size_t ssize;
+ int rc;
data = data_to_pkcs1 (purpose);
- GNUNET_assert (0 == gcry_pk_sign (&result, data, key->sexp));
+ if (0 != (rc = gcry_pk_sign (&result, data, key->sexp)))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("ECC signing failed at %s:%d: %s\n"), __FILE__,
+ __LINE__, gcry_strerror (rc));
+ }
gcry_sexp_release (data);
ssize = gcry_sexp_sprint (result,
GCRYSEXP_FMT_DEFAULT,
sig->sexpr,
- GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH);
+ GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH);
if (0 == ssize)
{
GNUNET_break (0);
@@ -1001,7 +997,7 @@ GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *key,
}
sig->size = htons ((uint16_t) (ssize + sizeof (uint16_t)));
/* padd with zeros */
- memset (&sig->sexpr[ssize], 0, GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH - ssize);
+ memset (&sig->sexpr[ssize], 0, GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH - ssize);
gcry_sexp_release (result);
return GNUNET_OK;
}
@@ -1035,7 +1031,7 @@ GNUNET_CRYPTO_ecc_verify (uint32_t purpose,
return GNUNET_SYSERR; /* purpose mismatch */
size = ntohs (sig->size);
if ( (size < sizeof (uint16_t)) ||
- (size > GNUNET_CRYPTO_ECC_DATA_ENCODING_LENGTH - sizeof (uint16_t)) )
+ (size > GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH - sizeof (uint16_t)) )
return GNUNET_SYSERR; /* size out of range */
data = data_to_pkcs1 (validate);
GNUNET_assert (0 ==
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index cb782282ec..b5a8c85dea 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
* Encode the private key in a format suitable for
* storing it into a file.
*
- * @returns encoding of the private key.
+ * @return encoding of the private key.
* The first 4 bytes give the size of the array, as usual.
*/
struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *
@@ -778,9 +778,6 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("I am host `%s'. Stored new private key in `%s'.\n"),
- GNUNET_i2s (&pid), filename);
return ret;
}
/* hostkey file exists already, read it! */
@@ -807,7 +804,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
STRERROR (ec));
LOG (GNUNET_ERROR_TYPE_ERROR,
_
- ("This may be ok if someone is currently generating a hostkey.\n"));
+ ("This may be ok if someone is currently generating a private key.\n"));
}
short_wait ();
continue;
@@ -828,7 +825,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
fs = 0;
if (fs < sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded))
{
- /* maybe we got the read lock before the hostkey generating
+ /* maybe we got the read lock before the key generating
* process had a chance to get the write lock; give it up! */
if (GNUNET_YES !=
GNUNET_DISK_file_unlock (fd, 0,
@@ -838,12 +835,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
{
LOG (GNUNET_ERROR_TYPE_ERROR,
_
- ("When trying to read hostkey file `%s' I found %u bytes but I need at least %u.\n"),
+ ("When trying to read key file `%s' I found %u bytes but I need at least %u.\n"),
filename, (unsigned int) fs,
(unsigned int) sizeof (struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded));
LOG (GNUNET_ERROR_TYPE_ERROR,
_
- ("This may be ok if someone is currently generating a hostkey.\n"));
+ ("This may be ok if someone is currently generating a private key.\n"));
}
short_wait (); /* wait a bit longer! */
continue;
@@ -875,9 +872,6 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
{
GNUNET_CRYPTO_rsa_key_get_public (ret, &pub);
GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey);
- LOG (GNUNET_ERROR_TYPE_INFO,
- _("I am host `%s'. Read private key from `%s'.\n"), GNUNET_i2s (&pid),
- filename);
}
return ret;
}
@@ -1105,10 +1099,10 @@ GNUNET_CRYPTO_rsa_key_create_stop (struct GNUNET_CRYPTO_RsaKeyGenerationContext
/**
- * Setup a hostkey file for a peer given the name of the
+ * Setup a key file for a peer given the name of the
* configuration file (!). This function is used so that
* at a later point code can be certain that reading a
- * hostkey is fast (for example in time-dependent testcases).
+ * key is fast (for example in time-dependent testcases).
*
* @param cfg_name name of the configuration file to use
*/
@@ -1184,7 +1178,7 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
/**
- * Decrypt a given block with the hostkey.
+ * Decrypt a given block with the key.
*
* @param key the key with which to decrypt this block
* @param block the data to decrypt, encoded as returned by encrypt
diff --git a/src/util/network.c b/src/util/network.c
index 491e4fffd3..fd6687c0f7 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -67,6 +67,34 @@ struct GNUNET_NETWORK_Handle
/**
+ * Test if the given protocol family is supported by this system.
+ *
+ * @param pf protocol family to test (PF_INET, PF_INET6, PF_UNIX)
+ * @return GNUNET_OK if the PF is supported
+ */
+int
+GNUNET_NETWORK_test_pf (int pf)
+{
+ int s;
+
+ s = socket (pf, SOCK_STREAM, 0);
+ if (-1 == s)
+ {
+ if (EAFNOSUPPORT == errno)
+ return GNUNET_NO;
+ fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
+ return GNUNET_SYSERR;
+ }
+#if WINDOWS
+ closesocket (s);
+#else
+ close (s);
+#endif
+ return GNUNET_OK;
+}
+
+
+/**
* Given a unixpath that is too long (larger than UNIX_PATH_MAX),
* shorten it to an acceptable length while keeping it unique
* 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 87b76f12de..2247b49c6e 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -707,7 +707,7 @@ reconnect ()
(unsigned long long) backoff.rel_value);
GNUNET_assert (NULL != resolver_cfg);
r_task = GNUNET_SCHEDULER_add_delayed (backoff, &reconnect_task, NULL);
- backoff = GNUNET_TIME_relative_multiply (backoff, 2);
+ backoff = GNUNET_TIME_STD_BACKOFF (backoff);
}
diff --git a/src/util/test_crypto_ecc.c b/src/util/test_crypto_ecc.c
index 4cb8f1dbc3..44ece1658a 100644
--- a/src/util/test_crypto_ecc.c
+++ b/src/util/test_crypto_ecc.c
@@ -203,4 +203,6 @@ main (int argc, char *argv[])
return -1;
}
return 0;
-} /* end of main */
+}
+
+/* end of test_crypto_ecc.c */
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 5a52a6cda9..abdc16d79a 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)
/**
- * Test if the given AF is supported by this system.
- *
- * @param af to test
- * @return GNUNET_OK if the AF is supported
- */
-static int
-test_af (int af)
-{
- int s;
-
- s = socket (af, SOCK_STREAM, 0);
- if (-1 == s)
- {
- if (EAFNOSUPPORT == errno)
- return GNUNET_NO;
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "socket");
- return GNUNET_SYSERR;
- }
- (void) close (s);
- return GNUNET_OK;
-}
-
-
-/**
* Main function that will be run by the scheduler.
*
* @param cls closure
@@ -3100,7 +3075,7 @@ run (void *cls,
return;
}
vpn_argv[1] = ifname;
- if (GNUNET_OK == test_af (AF_INET6))
+ if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
{
if ( (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV6ADDR",
@@ -3140,7 +3115,7 @@ run (void *cls,
vpn_argv[2] = GNUNET_strdup ("-");
vpn_argv[3] = GNUNET_strdup ("-");
}
- if (GNUNET_OK == test_af (AF_INET))
+ if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET))
{
if ( (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_get_value_string (cfg, "vpn", "IPV4ADDR",