*/
/**
* @file gns/gnunet-service-gns.c
- * @brief GNUnet GNS service
+ * @brief GNU Name System (main service)
* @author Martin Schanzenbach
* @author Christian Grothoff
- *
- * TODO:
- * - conversion of private to public records does NOT check if the
- * records are actually public
*/
#include "platform.h"
#include "gnunet_util_lib.h"
-#include "gnunet_transport_service.h"
#include "gnunet_dns_service.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_gns_service.h"
#include "gnunet_statistics_service.h"
#include "gns.h"
-#include "gns_common.h"
#include "gnunet-service-gns_resolver.h"
+#include "gnunet-service-gns_shorten.h"
#include "gnunet-service-gns_interceptor.h"
#include "gnunet_protocols.h"
struct GNS_ResolverHandle *lookup;
/**
- * request id
+ * request id
*/
uint32_t request_id;
*/
static int first_zone_iteration;
-/**
- * The lookup timeout
- */
-static struct GNUNET_TIME_Relative default_lookup_timeout;
-
/**
* #GNUNET_YES if ipv6 is supported
*/
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shutting down!\n");
- GNUNET_SERVER_notification_context_destroy (nc);
+ GNUNET_SERVER_notification_context_destroy (nc);
while (NULL != (clh = clh_head))
{
+ GNUNET_SERVER_client_set_user_context (clh->client, NULL);
GNS_resolver_lookup_cancel (clh->lookup);
GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
GNUNET_free (clh);
GNS_interceptor_done ();
GNS_resolver_done ();
+ GNS_shorten_done ();
if (NULL != statistics)
{
GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
* @param tc task context
*/
static void
-publish_zone_dht_start (void *cls,
+publish_zone_dht_start (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc);
dht_put_continuation (void *cls,
int success)
{
- struct GNUNET_TIME_Relative next_put_interval;
+ struct GNUNET_TIME_Relative next_put_interval;
- num_public_records++;
+ active_put = NULL;
+ num_public_records++;
if ( (num_public_records > last_num_public_records) &&
(GNUNET_NO == first_zone_iteration) )
{
GNUNET_STATISTICS_set (statistics,
"Current zone iteration interval (ms)",
next_put_interval.rel_value_us / 1000LL,
- GNUNET_NO);
+ GNUNET_NO);
zone_publish_task = GNUNET_SCHEDULER_add_delayed (next_put_interval,
&publish_zone_dht_next,
NULL);
*/
static void
put_gns_record (void *cls,
- const struct GNUNET_CRYPTO_EccPrivateKey *key,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
const char *name,
unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
-{
+{
struct GNUNET_NAMESTORE_Block *block;
struct GNUNET_HashCode query;
- struct GNUNET_TIME_Absolute expire;
+ struct GNUNET_TIME_Absolute expire;
+ struct GNUNET_TIME_Absolute now;
size_t block_size;
+ struct GNUNET_NAMESTORE_RecordData rd_public[rd_count];
+ unsigned int rd_public_count;
+ unsigned int i;
if (NULL == name)
{
put_interval.rel_value_us / 1000LL,
GNUNET_NO);
GNUNET_STATISTICS_update (statistics,
- "Number of zone iterations",
- 1,
+ "Number of zone iterations",
+ 1,
GNUNET_NO);
GNUNET_STATISTICS_set (statistics,
"Number of public records in DHT",
&publish_zone_dht_start,
NULL);
else
- zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+ zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
NULL);
return;
}
- /* FIXME: filter out records that are not public! */
+ /* filter out records that are not public, and convert to
+ absolute expiration time. */
+ rd_public_count = 0;
+ now = GNUNET_TIME_absolute_get ();
+ for (i=0;i<rd_count;i++)
+ if (0 == (rd[i].flags & (GNUNET_NAMESTORE_RF_PRIVATE |
+ GNUNET_NAMESTORE_RF_PENDING)))
+ {
+ rd_public[rd_public_count] = rd[i];
+ if (0 != (rd[i].flags & GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION))
+ {
+ rd_public[rd_public_count].flags &= ~GNUNET_NAMESTORE_RF_RELATIVE_EXPIRATION;
+ rd_public[rd_public_count].expiration_time += now.abs_value_us;
+ }
+ rd_public_count++;
+ }
/* We got a set of records to publish */
- if (0 == rd_count)
+ if (0 == rd_public_count)
{
zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_next,
NULL);
return;
}
- expire = GNUNET_NAMESTORE_record_get_expiration_time (rd_count,
- rd);
+ expire = GNUNET_NAMESTORE_record_get_expiration_time (rd_public_count,
+ rd_public);
block = GNUNET_NAMESTORE_block_create (key,
expire,
name,
- rd,
- rd_count);
- block_size = ntohl (block->purpose.size)
- + sizeof (struct GNUNET_CRYPTO_EccSignature)
- + sizeof (struct GNUNET_CRYPTO_EccPublicKey);
+ rd_public,
+ rd_public_count);
+ block_size = ntohl (block->purpose.size)
+ + sizeof (struct GNUNET_CRYPTO_EcdsaSignature)
+ + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
GNUNET_NAMESTORE_query_from_private_key (key,
name,
&query);
expire,
DHT_OPERATION_TIMEOUT,
&dht_put_continuation,
- NULL);
+ NULL);
if (NULL == active_put)
{
GNUNET_break (0);
* @param tc task context
*/
static void
-publish_zone_dht_start (void *cls,
+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,
* Reply to client with the result from our lookup.
*
* @param cls the closure (our client lookup handle)
- * @param rd_count the number of records
+ * @param rd_count the number of records in @a rd
* @param rd the record data
*/
static void
struct ClientLookupHandle *clh = cls;
struct GNUNET_GNS_ClientLookupResultMessage *rmsg;
size_t len;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending `%s' message with %d results\n",
- "LOOKUP_RESULT",
+ "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->header.type = htons (GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT);
rmsg->header.size = htons (len + sizeof(struct GNUNET_GNS_ClientLookupResultMessage));
rmsg->id = clh->request_id;
- rmsg->rd_count = htonl (rd_count);
- GNUNET_NAMESTORE_records_serialize (rd_count, rd, len,
+ rmsg->rd_count = htonl (rd_count);
+ GNUNET_NAMESTORE_records_serialize (rd_count, rd, len,
(char*) &rmsg[1]);
- GNUNET_SERVER_notification_context_unicast (nc,
+ GNUNET_SERVER_notification_context_unicast (nc,
clh->client,
&rmsg->header,
GNUNET_NO);
GNUNET_free (rmsg);
- GNUNET_SERVER_receive_done (clh->client,
- GNUNET_OK);
GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
+ GNUNET_SERVER_client_set_user_context (clh->client, NULL);
GNUNET_free (clh);
GNUNET_STATISTICS_update (statistics,
- "Completed lookups", 1,
+ "Completed lookups", 1,
GNUNET_NO);
GNUNET_STATISTICS_update (statistics,
- "Records resolved",
- rd_count,
+ "Records resolved",
+ rd_count,
GNUNET_NO);
}
struct ClientLookupHandle *clh;
char *nameptr = name;
const char *utf_in;
- const struct GNUNET_CRYPTO_EccPrivateKey *key;
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *key;
uint16_t msg_size;
const struct GNUNET_GNS_ClientLookupMessage *sh_msg;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received `%s' message\n",
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' message\n",
"LOOKUP");
msg_size = ntohs (message->size);
if (msg_size < sizeof (struct GNUNET_GNS_ClientLookupMessage))
}
sh_msg = (const struct GNUNET_GNS_ClientLookupMessage *) message;
GNUNET_SERVER_notification_context_add (nc, client);
- if (GNUNET_YES == ntohl (sh_msg->have_key))
+ if (GNUNET_YES == ntohs (sh_msg->have_key))
key = &sh_msg->shorten_key;
else
key = NULL;
return;
}
GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
-
+ GNUNET_SERVER_receive_done (client, GNUNET_OK);
+
clh = GNUNET_new (struct ClientLookupHandle);
GNUNET_SERVER_client_set_user_context (client, clh);
GNUNET_CONTAINER_DLL_insert (clh_head, clh_tail, clh);
"LOOKUP: Query for A record but AF_INET not supported!");
send_lookup_response (clh, 0, NULL);
return;
- }
+ }
if ( (GNUNET_DNSPARSER_TYPE_AAAA == ntohl (sh_msg->type)) &&
(GNUNET_OK != v6_enabled) )
{
send_lookup_response (clh, 0, NULL);
return;
}
- clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
+ clh->lookup = GNS_resolver_lookup (&sh_msg->zone,
ntohl (sh_msg->type),
name,
key,
ntohl (sh_msg->only_cached),
&send_lookup_response, clh);
GNUNET_STATISTICS_update (statistics,
- "Lookup attempts",
+ "Lookup attempts",
1, GNUNET_NO);
}
{ &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
{NULL, NULL, 0, 0}
};
- struct GNUNET_CRYPTO_EccPublicKey dns_root;
+ struct GNUNET_CRYPTO_EcdsaPublicKey dns_root;
unsigned long long max_parallel_bg_queries = 0;
char *dns_root_name;
GNUNET_SCHEDULER_shutdown ();
return;
}
-
+
put_interval = INITIAL_PUT_INTERVAL;
zone_publish_time_window = DEFAULT_ZONE_PUBLISH_TIME_WINDOW;
max_parallel_bg_queries);
}
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_time (c, "gns",
- "DEFAULT_LOOKUP_TIMEOUT",
- &default_lookup_timeout))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Default lookup timeout: %s\n",
- GNUNET_STRINGS_relative_time_to_string (default_lookup_timeout,
- GNUNET_YES));
- }
-
dht_handle = GNUNET_DHT_connect (c,
(unsigned int) max_parallel_bg_queries);
if (NULL == dht_handle)
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
return;
}
-
+
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_string (c, "gns", "DNS_ROOT",
&dns_root_name))
{
if (GNUNET_OK !=
- GNUNET_CRYPTO_ecc_public_key_from_string (dns_root_name,
+ GNUNET_CRYPTO_ecdsa_public_key_from_string (dns_root_name,
strlen (dns_root_name),
&dns_root))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "gns", "DNS_ROOT",
+ "gns", "DNS_ROOT",
_("valid public key required"));
GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
GNUNET_free (dns_root_name);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"DNS hijacking with root `%s' enabled. Connecting to DNS service.\n",
dns_root_name);
- GNUNET_free (dns_root_name);
+ GNUNET_free (dns_root_name);
if (GNUNET_SYSERR ==
GNS_interceptor_init (&dns_root, c))
{
return;
}
}
- /* FIXME: install client disconnect handle to clean up pending
- lookups on client disconnect! */
- GNS_resolver_init (namestore_handle, dht_handle,
+ GNS_resolver_init (namestore_handle, dht_handle,
c,
max_parallel_bg_queries);
+ GNS_shorten_init (namestore_handle, dht_handle);
GNUNET_SERVER_disconnect_notify (server,
¬ify_client_disconnect,
NULL);
- /* Schedule periodic put for our records. */
+ /* Schedule periodic put for our records. */
first_zone_iteration = GNUNET_YES;
GNUNET_SERVER_add_handlers (server, handlers);
statistics = GNUNET_STATISTICS_create ("gns", c);
nc = GNUNET_SERVER_notification_context_create (server, 1);
- zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
+ zone_publish_task = GNUNET_SCHEDULER_add_now (&publish_zone_dht_start,
NULL);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task, NULL);
}