#include "gnunet_resolver_service.h"
#include "gnunet_revocation_service.h"
#include "gnunet_dnsparser_lib.h"
+#include "gnunet_tun_lib.h"
#include "gnunet_gns_service.h"
#include "gns.h"
#include "gnunet-service-gns_resolver.h"
*/
static struct CacheOps *co_tail;
+/**
+ * Use namecache
+ */
+static int use_cache;
/**
* Global configuration.
case GNUNET_GNSRECORD_TYPE_VPN:
{
af = (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ? AF_INET : AF_INET6;
- if (sizeof (struct GNUNET_TUN_GnsVpnRecord) <
+ if (sizeof (struct GNUNET_TUN_GnsVpnRecord) >
rd[i].data_size)
{
GNUNET_break_op (0);
GNS_resolver_lookup_cancel (rh);
return;
}
- GNUNET_CRYPTO_hash (vname,
- strlen (vname), // FIXME: +1?
- &vhash);
+ GNUNET_TUN_service_name_to_hash (vname,
+ &vhash);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Attempting VPN allocation for %s-%s (AF: %d, proto %d)\n",
+ GNUNET_i2s (&vpn->peer),
+ vname,
+ (int) af,
+ (int) ntohs (vpn->proto));
vpn_ctx = GNUNET_new (struct VpnContext);
rh->vpn_ctx = vpn_ctx;
vpn_ctx->rh = rh;
vpn_ctx->rd_data_size = GNUNET_GNSRECORD_records_get_size (rd_count,
rd);
vpn_ctx->rd_data = GNUNET_malloc (vpn_ctx->rd_data_size);
- (void) GNUNET_GNSRECORD_records_serialize (rd_count,
- rd,
- vpn_ctx->rd_data_size,
- vpn_ctx->rd_data);
+ vpn_ctx->rd_count = rd_count;
+ GNUNET_assert (vpn_ctx->rd_data_size ==
+ GNUNET_GNSRECORD_records_serialize (rd_count,
+ rd,
+ vpn_ctx->rd_data_size,
+ vpn_ctx->rd_data));
vpn_ctx->vpn_request = GNUNET_VPN_redirect_to_peer (vpn_handle,
af,
ntohs (vpn->proto),
&vhash,
GNUNET_TIME_relative_to_absolute (VPN_TIMEOUT),
&vpn_allocation_cb,
- rh);
+ vpn_ctx);
return;
}
case GNUNET_GNSRECORD_TYPE_GNS2DNS:
}
/* Cache well-formed blocks */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Caching response from the DHT in namestore\n");
+ "Caching response from the DHT in namecache\n");
co = GNUNET_new (struct CacheOps);
co->namecache_qe_cache = GNUNET_NAMECACHE_block_cache (namecache_handle,
block,
}
+/**
+ * Initiate a DHT query for a set of GNS records.
+ *
+ * @param rh resolution handle
+ * @param query key to use in the DHT lookup
+ */
+static void
+start_dht_request (struct GNS_ResolverHandle *rh,
+ const struct GNUNET_HashCode *query)
+{
+ struct GNS_ResolverHandle *rx;
+
+ GNUNET_assert (NULL == rh->get_handle);
+ rh->get_handle = GNUNET_DHT_get_start (dht_handle,
+ GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
+ query,
+ DHT_GNS_REPLICATION_LEVEL,
+ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
+ NULL, 0,
+ &handle_dht_response, rh);
+ rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
+ rh,
+ GNUNET_TIME_absolute_get ().abs_value_us);
+ if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries)
+ {
+ /* fail longest-standing DHT request */
+ rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap);
+ GNUNET_assert (NULL != rx);
+ rx->proc (rx->proc_cls, 0, NULL);
+ GNS_resolver_lookup_cancel (rx);
+ }
+}
+
+
+/**
+ * Process a records that were decrypted from a block that we
+ * got from the namecache. If the desired record type is not
+ * included, we should query the DHT. Otherwise, we should
+ * simply call #handle_gns_resolution_result().
+ *
+ * @param cls closure with the `struct GNS_ResolverHandle`
+ * @param rd_count number of entries in @a rd array
+ * @param rd array of records with data to store
+ */
+static void
+handle_gns_namecache_resolution_result (void *cls,
+ unsigned int rd_count,
+ const struct GNUNET_GNSRECORD_Data *rd)
+{
+ struct GNS_ResolverHandle *rh = cls;
+ unsigned int i;
+ int found;
+
+ found = GNUNET_NO;
+ for (i=0;i<rd_count;i++)
+ {
+ if (rd[i].record_type == rh->record_type)
+ {
+ found = GNUNET_YES;
+ break;
+ }
+ switch (rd[i].record_type)
+ {
+ case GNUNET_GNSRECORD_TYPE_VPN:
+ if ( (GNUNET_DNSPARSER_TYPE_A == rh->record_type) ||
+ (GNUNET_DNSPARSER_TYPE_AAAA == rh->record_type) )
+ {
+ found = GNUNET_YES;
+ break;
+ }
+ break;
+ case GNUNET_DNSPARSER_TYPE_CNAME:
+ case GNUNET_GNSRECORD_TYPE_PKEY:
+ case GNUNET_GNSRECORD_TYPE_GNS2DNS:
+ /* delegations always count as 'found' */
+ found = GNUNET_YES;
+ break;
+ default:
+ break;
+ }
+ }
+ if (GNUNET_YES == found)
+ {
+ handle_gns_resolution_result (rh,
+ rd_count,
+ rd);
+ }
+ else
+ {
+ /* try DHT */
+ struct AuthorityChain *ac = rh->ac_tail;
+ const char *label = ac->label;
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority;
+ struct GNUNET_HashCode query;
+
+ GNUNET_GNSRECORD_query_from_public_key (auth,
+ label,
+ &query);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
+ ac->label,
+ GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
+ GNUNET_h2s (&query));
+ start_dht_request (rh, &query);
+ }
+}
+
+
/**
* Process a record that was stored in the namecache.
*
* @param block block that was stored in the namecache
*/
static void
-handle_namestore_block_response (void *cls,
+handle_namecache_block_response (void *cls,
const struct GNUNET_GNSRECORD_Block *block)
{
struct GNS_ResolverHandle *rh = cls;
- struct GNS_ResolverHandle *rx;
struct AuthorityChain *ac = rh->ac_tail;
const char *label = ac->label;
const struct GNUNET_CRYPTO_EcdsaPublicKey *auth = &ac->authority_info.gns_authority;
struct GNUNET_HashCode query;
- GNUNET_GNSRECORD_query_from_public_key (auth,
- label,
- &query);
GNUNET_assert (NULL != rh->namecache_qe);
rh->namecache_qe = NULL;
if ( (GNUNET_NO == rh->only_cached) &&
(0 == GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (block->expiration_time)).rel_value_us) ) )
{
/* namecache knows nothing; try DHT lookup */
+ GNUNET_GNSRECORD_query_from_public_key (auth,
+ label,
+ &query);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
- ac->label,
- GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
- GNUNET_h2s (&query));
- GNUNET_assert (NULL == rh->get_handle);
- rh->get_handle = GNUNET_DHT_get_start (dht_handle,
- GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
- &query,
- DHT_GNS_REPLICATION_LEVEL,
- GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
- NULL, 0,
- &handle_dht_response, rh);
- rh->dht_heap_node = GNUNET_CONTAINER_heap_insert (dht_lookup_heap,
- rh,
- GNUNET_TIME_absolute_get ().abs_value_us);
- if (GNUNET_CONTAINER_heap_get_size (dht_lookup_heap) > max_allowed_background_queries)
- {
- /* fail longest-standing DHT request */
- rx = GNUNET_CONTAINER_heap_peek (dht_lookup_heap);
- GNUNET_assert (NULL != rx);
- rx->proc (rx->proc_cls, 0, NULL);
- GNS_resolver_lookup_cancel (rx);
- }
+ "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
+ ac->label,
+ GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
+ GNUNET_h2s (&query));
+ start_dht_request (rh, &query);
return;
}
GNUNET_GNSRECORD_block_decrypt (block,
auth,
label,
- &handle_gns_resolution_result,
+ &handle_gns_namecache_resolution_result,
rh))
{
GNUNET_break_op (0); /* block was ill-formed */
- rh->proc (rh->proc_cls, 0, NULL);
- GNS_resolver_lookup_cancel (rh);
+ /* try DHT instead */
+ GNUNET_GNSRECORD_query_from_public_key (auth,
+ label,
+ &query);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting DHT lookup for `%s' in zone `%s' under key `%s'\n",
+ ac->label,
+ GNUNET_GNSRECORD_z2s (&ac->authority_info.gns_authority),
+ GNUNET_h2s (&query));
+ start_dht_request (rh, &query);
return;
}
}
GNUNET_GNSRECORD_query_from_public_key (&ac->authority_info.gns_authority,
ac->label,
&query);
- rh->namecache_qe = GNUNET_NAMECACHE_lookup_block (namecache_handle,
+ if (GNUNET_YES == use_cache)
+ {
+ rh->namecache_qe = GNUNET_NAMECACHE_lookup_block (namecache_handle,
&query,
- &handle_namestore_block_response,
+ &handle_namecache_block_response,
rh);
- GNUNET_assert (NULL != rh->namecache_qe);
+ GNUNET_assert (NULL != rh->namecache_qe);
+ }
+ else
+ {
+ start_dht_request (rh, &query);
+ }
}
dht_lookup_heap =
GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
max_allowed_background_queries = max_bg_queries;
+ if (GNUNET_SYSERR == (use_cache = GNUNET_CONFIGURATION_get_value_yesno (c,
+ "gns",
+ "USE_CACHE")))
+ use_cache = GNUNET_YES;
+ if (GNUNET_NO == use_cache)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Namecache disabled\n");
+
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (c,
"gns",