*/
/**
* @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
- * - need to watch for client disconnects and abort operations on
- * disconnect
*/
#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"
GNS_interceptor_done ();
GNS_resolver_done ();
+ GNS_shorten_done ();
if (NULL != statistics)
{
GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
{
struct GNUNET_TIME_Relative next_put_interval;
+ active_put = NULL;
num_public_records++;
if ( (num_public_records > last_num_public_records) &&
(GNUNET_NO == first_zone_iteration) )
struct GNUNET_NAMESTORE_Block *block;
struct GNUNET_HashCode query;
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)
{
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);
+ rd_public,
+ rd_public_count);
block_size = ntohl (block->purpose.size)
+ sizeof (struct GNUNET_CRYPTO_EccSignature)
- + sizeof (struct GNUNET_CRYPTO_EccPublicKey);
+ + sizeof (struct GNUNET_CRYPTO_EccPublicSignKey);
GNUNET_NAMESTORE_query_from_private_key (key,
name,
&query);
* 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
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,
GNUNET_STRINGS_utf8_tolower (utf_in, &nameptr);
clh = GNUNET_new (struct ClientLookupHandle);
+ GNUNET_SERVER_client_set_user_context (client, clh);
GNUNET_CONTAINER_DLL_insert (clh_head, clh_tail, clh);
clh->client = client;
clh->request_id = sh_msg->id;
}
+/**
+ * One of our clients disconnected, clean up after it.
+ *
+ * @param cls NULL
+ * @param client the client that disconnected
+ */
+static void
+notify_client_disconnect (void *cls,
+ struct GNUNET_SERVER_Client *client)
+{
+ struct ClientLookupHandle *clh;
+
+ if (NULL == client)
+ return;
+ clh = GNUNET_SERVER_client_get_user_context (client, struct ClientLookupHandle);
+ if (NULL == clh)
+ return;
+ GNS_resolver_lookup_cancel (clh->lookup);
+ GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
+ GNUNET_free (clh);
+}
+
+
/**
* Process GNS requests.
*
{ &handle_lookup, NULL, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, 0},
{NULL, NULL, 0, 0}
};
- struct GNUNET_CRYPTO_EccPublicKey dns_root;
+ struct GNUNET_CRYPTO_EccPublicSignKey dns_root;
unsigned long long max_parallel_bg_queries = 0;
- int ignore_pending = GNUNET_NO;
char *dns_root_name;
v6_enabled = GNUNET_NETWORK_test_pf (PF_INET6);
max_parallel_bg_queries);
}
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (c, "gns",
- "AUTO_IMPORT_CONFIRMATION_REQ"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Auto import requires user confirmation\n");
- ignore_pending = GNUNET_YES;
- }
-
if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_time (c, "gns",
"DEFAULT_LOOKUP_TIMEOUT",
return;
}
- if (GNUNET_SYSERR ==
- GNS_resolver_init (namestore_handle, dht_handle,
- c,
- max_parallel_bg_queries,
- ignore_pending))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to initialize resolver!\n"));
- 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_ecc_public_sign_key_from_string (dns_root_name,
strlen (dns_root_name),
&dns_root))
{
return;
}
}
- /* FIXME: install client disconnect handle to clean up pending
- lookups on client disconnect! */
-
- /* Schedule periodic put for our records. */
+ 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. */
first_zone_iteration = GNUNET_YES;
GNUNET_SERVER_add_handlers (server, handlers);
statistics = GNUNET_STATISTICS_create ("gns", c);