*/
/**
- *
- *
* @file gns/gnunet-service-gns_resolver.c
* @brief GNUnet GNS resolver logic
* @author Martin Schanzenbach
*/
static unsigned long long rid = 0;
+/*
+ * Check if name is in srv format (_x._y.xxx)
+ *
+ * @param name
+ * @return GNUNET_YES if true
+ */
static int
is_srv (char* name)
{
char* ndup;
- int ret = 1;
+ int ret = GNUNET_YES;
if (*name != '_')
- return 0;
+ return GNUNET_NO;
if (NULL == strstr (name, "._"))
- return 0;
+ return GNUNET_NO;
ndup = GNUNET_strdup (name);
strtok (ndup, ".");
if (NULL == strtok (NULL, "."))
- ret = 0;
+ ret = GNUNET_NO;
if (NULL == strtok (NULL, "."))
- ret = 0;
+ ret = GNUNET_NO;
if (NULL != strtok (NULL, "."))
- ret = 0;
+ ret = GNUNET_NO;
+
+ GNUNET_free (ndup);
return ret;
}
* a = canonical
*
* @param name the name to test
- * @return 1 if canonical
+ * @return GNUNET_YES if canonical
*/
static int
-is_canonical(char* name)
+is_canonical (char* name)
{
char* ndup;
char* tok;
if (*tok == '_')
continue;
GNUNET_free (ndup);
- return 0;
+ return GNUNET_NO;
}
GNUNET_free (ndup);
- return 1;
+ return GNUNET_YES;
}
GNUNET_NETWORK_socket_close (rh->dns_sock);
if (NULL != rh->dns_resolver_handle)
GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
+
+ if (NULL != rh->rd.data)
+ GNUNET_free ((void*)(rh->rd.data));
GNUNET_free(rh);
}
rh->private_local_zone,
rlh->record_type,
new_name,
- rh->priv_key,
+ NULL,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_NO,
&background_lookup_result_processor,
rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
/* Start shortening */
- if ((rh->priv_key != NULL) && is_canonical (rh->name))
+ if ((rh->priv_key != NULL) &&
+ (is_canonical (rh->name) == GNUNET_YES))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_REC_DNS-%llu: Trying to shorten authority chain\n",
rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
/* Start shortening */
- if ((rh->priv_key != NULL) && is_canonical (rh->name))
+ if ((rh->priv_key != NULL) &&
+ (is_canonical (rh->name) == GNUNET_YES))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_REC_VPN-%llu: Trying to shorten authority chain\n",
rh->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
/* Start shortening */
- if ((rh->priv_key != NULL) && is_canonical (rh->name))
+ if ((rh->priv_key != NULL) &&
+ (is_canonical (rh->name) == GNUNET_YES))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_REC-%llu: Trying to shorten authority chain\n",
rh->private_local_zone,
rlh->record_type,
new_name,
- rh->priv_key,
+ NULL,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_NO,
&background_lookup_result_processor,
rh->private_local_zone,
GNUNET_GNS_RECORD_REV,
GNUNET_GNS_TLD,
- rh->priv_key,
+ NULL,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_NO,
&background_lookup_result_processor,
* else resolve again with new authority
*/
if (strcmp (rh->name, "") == 0)
- rh->proc (rh->proc_cls, rh, 0, NULL);
+ rh->proc (rh->proc_cls, rh, rh->rd_count, &rh->rd);
else
resolve_delegation_ns (rh);
+
return;
}
rh->authority_chain_tail,
auth);
+ if (NULL != rh->rd.data)
+ GNUNET_free ((void*)rh->rd.data);
+
+ memcpy (&rh->rd, &rd[i], sizeof (struct GNUNET_NAMESTORE_RecordData));
+ rh->rd.data = GNUNET_malloc (rd[i].data_size);
+ memcpy ((void*)(rh->rd.data), rd[i].data, rd[i].data_size);
+ rh->rd_count = 1;
+
/** try to import pkey if private key available */
//if (rh->priv_key && is_canonical (rh->name))
// process_discovered_authority(name, auth->zone,
if (strcmp(rh->name, "") == 0)
{
/* Start shortening */
- if ((rh->priv_key != NULL) && is_canonical (rh->name))
+ if ((rh->priv_key != NULL) &&
+ (is_canonical (rh->name) == GNUNET_YES))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_DHT-%llu: Trying to shorten authority chain\n",
else
rh->proc = &handle_delegation_ns;
+
/* Check for key revocation and delegate */
rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
&rh->authority,
&rh->private_local_zone))
check_dht = GNUNET_NO;
- if ((strcmp (rh->name, "+") != 0) && (is_srv (rh->name) != 0))
+ if ((strcmp (rh->name, "+") != 0) && (is_srv (rh->name) == GNUNET_YES))
check_dht = GNUNET_NO;
{
uint32_t len;
- if (is_canonical (name))
+ if (is_canonical (name) == GNUNET_YES)
{
strcpy(dest, name);
strcpy(name, "");
/**
* we still have some left
**/
- if (is_canonical(rh->name))
+ if (is_canonical (rh->name) == GNUNET_YES)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_DHT-%llu: Resolving canonical record %s in ns\n",
}
else if (rlh->record_type == GNUNET_GNS_RECORD_PKEY)
{
- GNUNET_assert(rd_count == 1);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_NS-%llu: Resolved queried PKEY in NS.\n",
rh->id);
if (check_dht == GNUNET_NO)
{
- if (is_canonical(rh->name))
+ if (is_canonical (rh->name) == GNUNET_YES)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_NS-%llu: Resolving canonical record %s\n",
GNUNET_CONTAINER_DLL_insert (rh->authority_chain_head,
rh->authority_chain_tail,
auth);
+ if (NULL != rh->rd.data)
+ GNUNET_free ((void*)(rh->rd.data));
+ memcpy (&rh->rd, &rd[i], sizeof (struct GNUNET_NAMESTORE_RecordData));
+ rh->rd.data = GNUNET_malloc (rd[i].data_size);
+ memcpy ((void*)rh->rd.data, rd[i].data, rd[i].data_size);
+ rh->rd_count = 1;
/* Check for key revocation and delegate */
rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
&rh->authority,
* If we have found some records for the LAST label
* we return the results. Else null.
*/
- if (strcmp(rh->name, "") == 0)
+ if (strcmp (rh->name, "") == 0)
{
/* Start shortening */
- if ((rh->priv_key != NULL) && is_canonical (rh->name))
+ if ((rh->priv_key != NULL) &&
+ (is_canonical (rh->name) == GNUNET_YES))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_DELEGATE_NS-%llu: Trying to shorten authority chain\n",
rh->priv_key);
}
/* simply promote back */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "GNS_PHASE_DELEGATE_NS-%llu: Promoting %s back to name\n",
- rh->id, rh->authority_name);
- strcpy(rh->name, rh->authority_name);
- rh->proc(rh->proc_cls, rh, rd_count, rd);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "GNS_PHASE_DELEGATE_NS-%llu: Promoting %s back to name\n",
+ rh->id, rh->authority_name);
+ strcpy (rh->name, rh->authority_name);
+ rh->proc (rh->proc_cls, rh, rd_count, rd);
}
else
{
- rh->proc(rh->proc_cls, rh, 0, NULL);
+ GNUNET_snprintf (new_name, MAX_DNS_NAME_LENGTH,
+ "%s.%s", rh->name, rh->authority_name);
+ strcpy (rh->name, new_name);
+ rh->proc (rh->proc_cls, rh, 0, NULL);
}
}
name, record_type);
- if (is_canonical((char*)name) && (strcmp(GNUNET_GNS_TLD, name) != 0))
+ if ((is_canonical ((char*)name) == GNUNET_YES) &&
+ (strcmp(GNUNET_GNS_TLD, name) != 0))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s is canonical and not gnunet -> cannot resolve!\n", name);
rh->private_local_zone = pzone;
rh->only_cached = only_cached;
rh->namestore_task = NULL;
+ rh->rd.data = NULL;
GNUNET_CONTAINER_DLL_insert (rlh_head, rlh_tail, rh);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Cannot handle this TLD %s\n", string_hash);
+ if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
+ GNUNET_SCHEDULER_cancel (rh->timeout_task);
GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);
GNUNET_free (rh);
GNUNET_free (rlh);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting shorten for %s!\n", name);
- if (is_canonical ((char*)name))
+ if (is_canonical ((char*)name) == GNUNET_YES)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s is canonical. Returning verbatim\n", name);
return;
}
- else
+ else if (is_gnunet_tld (name) == GNUNET_YES)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"TLD is gnunet\n");
memcpy (rh->name, name,
strlen (name)-strlen (GNUNET_GNS_TLD) - 1);
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unknown TLD in %s\n", name);
+ GNUNET_free (rh);
+ GNUNET_free (nsh);
+ GNUNET_CONTAINER_DLL_remove (nsh_head, nsh_tail, rh);
+ proc (proc_cls, name);
+ return;
+ }
rh->authority_chain_head = GNUNET_malloc (sizeof (struct AuthorityChain));
rh->authority_chain_tail = rh->authority_chain_head;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Building response!\n");
- if (is_canonical(rh->name))
+ if (is_canonical (rh->name) == GNUNET_YES)
{
/**
* We successfully resolved the authority in the ns