/* The name to resolve */
char *name;
- /* the request handle to reply to */
- struct GNUNET_DNS_RequestHandle *request_handle;
- /* the dns parser packet received */
- struct GNUNET_DNSPARSER_Packet *packet;
-
- /* the query parsed from the packet */
-
- struct GNUNET_DNSPARSER_Query *query;
/* has this query been answered? how many matches */
int answered;
};
+/**
+ * Handle to a record lookup
+ */
+struct RecordLookupHandle
+{
+ /* the record type to look up */
+ enum GNUNET_GNS_RecordType record_type;
+
+ /* the name to look up */
+ char *name;
+
+ /* Method to call on resolution result */
+ ResolutionResultProcessor proc;
+
+ /* closure to pass to proc */
+ void* proc_cls;
+
+};
+
struct ClientShortenHandle
{
struct GNUNET_SERVER_Client *client;
uint32_t offset;
};
+struct ClientLookupHandle
+{
+ struct GNUNET_SERVER_Client *client;
+ uint64_t unique_id;
+ GNUNET_HashCode key;
+ char* name; //Needed?
+};
+
+struct InterceptLookupHandle
+{
+ /* the request handle to reply to */
+ struct GNUNET_DNS_RequestHandle *request_handle;
+
+ /* the dns parser packet received */
+ struct GNUNET_DNSPARSER_Packet *packet;
+
+ /* the query parsed from the packet */
+
+ struct GNUNET_DNSPARSER_Query *query;
+};
+
/**
* Our handle to the DNS handler library
*/
size_t len;
int ret;
char *buf;
- struct GNUNET_DNSPARSER_Packet *packet = rh->packet;
+ struct InterceptLookupHandle* ilh = (struct InterceptLookupHandle*)cls;
+ struct GNUNET_DNSPARSER_Packet *packet = ilh->packet;
struct GNUNET_DNSPARSER_Record answer_records[rh->answered];
struct GNUNET_DNSPARSER_Record additional_records[rd_count-(rh->answered)];
packet->answers = answer_records;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Adding type %d to DNS response\n", rd[i].record_type);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Name: %s\n", rh->name);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "QName: %s\n", rh->query->name);
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "QName: %s\n", ilh->query->name);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Record %d/%d\n", i+1, rd_count);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Record len %d\n", rd[i].data_size);
- if (rd[i].record_type == rh->query->type)
+ if (rd[i].record_type == ilh->query->type)
{
- answer_records[i].name = rh->query->name;
+ answer_records[i].name = ilh->query->name;
answer_records[i].type = rd[i].record_type;
answer_records[i].data.raw.data_len = rd[i].data_size;
answer_records[i].data.raw.data = (char*)rd[i].data;
}
else
{
- additional_records[i].name = rh->query->name;
+ additional_records[i].name = ilh->query->name;
additional_records[i].type = rd[i].record_type;
additional_records[i].data.raw.data_len = rd[i].data_size;
additional_records[i].data.raw.data = (char*)rd[i].data;
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Answering DNS request\n");
- GNUNET_DNS_request_answer(rh->request_handle,
+ GNUNET_DNS_request_answer(ilh->request_handle,
len,
buf);
//GNUNET_free(answer);
"Error building DNS response! (ret=%d)", ret);
}
+ //FIXME free more!
GNUNET_free(rh->name);
+ GNUNET_free(rh->proc_cls);
GNUNET_free(rh);
+ GNUNET_free(ilh);
}
struct GNUNET_GNS_ResolverHandle *rh = cls;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "dht lookup for query %s (type=%d) timed out.\n",
- rh->name, rh->query->type);
+ "dht lookup for query %s timed out.\n",
+ rh->name);
GNUNET_DHT_get_stop (rh->get_handle);
rh->proc(rh->proc_cls, rh, 0, NULL);
size_t size, const void *data)
{
struct GNUNET_GNS_ResolverHandle *rh;
+ struct RecordLookupHandle *rlh;
struct GNSNameRecordBlock *nrb;
uint32_t num_records;
char* name = NULL;
//FIXME maybe check expiration here, check block type
rh = (struct GNUNET_GNS_ResolverHandle *)cls;
+ rlh = (struct RecordLookupHandle *) rh->proc_cls;
nrb = (struct GNSNameRecordBlock*)data;
/* stop lookup and timeout task */
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Got name: %s (wanted %s)\n", name, rh->name);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Got type: %d (wanted %d)\n",
- rd[i].record_type, rh->query->type);
+ "Got type: %d\n",
+ rd[i].record_type);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Got data length: %d\n", rd[i].data_size);
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Got flag %d\n", rd[i].flags);
if ((strcmp(name, rh->name) == 0) &&
- (rd[i].record_type == rh->query->type))
+ (rd[i].record_type == rlh->record_type))
{
rh->answered++;
}
GNUNET_HashCode name_hash;
GNUNET_HashCode lookup_key;
struct GNUNET_CRYPTO_HashAsciiEncoded lookup_key_string;
+ struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls;
GNUNET_CRYPTO_hash(rh->name, strlen(rh->name), &name_hash);
GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key);
rh->dht_timeout_task = GNUNET_SCHEDULER_add_delayed(DHT_LOOKUP_TIMEOUT,
&dht_lookup_timeout, rh);
- xquery = htonl(rh->query->type);
+ xquery = htonl(rlh->record_type);
rh->get_handle = GNUNET_DHT_get_start(dht_handle,
DHT_OPERATION_TIMEOUT,
GNUNET_BLOCK_TYPE_GNS_NAMERECORD,
const struct GNUNET_CRYPTO_RsaSignature *signature)
{
struct GNUNET_GNS_ResolverHandle *rh;
+ struct RecordLookupHandle *rlh;
struct GNUNET_TIME_Relative remaining_time;
GNUNET_HashCode zone;
rh = (struct GNUNET_GNS_ResolverHandle *) cls;
+ rlh = (struct RecordLookupHandle *)rh->proc_cls;
GNUNET_CRYPTO_hash(key,
sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
&zone);
for (i=0; i<rd_count;i++)
{
- if (rd[i].record_type != rh->query->type)
+ if (rd[i].record_type != rlh->record_type)
continue;
if ((GNUNET_TIME_absolute_get_remaining (rd[i].expiration)).rel_value
static void
resolve_record_from_ns(struct GNUNET_GNS_ResolverHandle *rh)
{
-
+ struct RecordLookupHandle *rlh = (struct RecordLookupHandle *)rh->proc_cls;
/**
* Try to resolve this record in our namestore.
* The name to resolve is now in rh->authority_name
GNUNET_NAMESTORE_lookup_record(namestore_handle,
&rh->authority,
rh->name,
- rh->query->type,
+ rlh->record_type,
&process_record_lookup_ns,
rh);
struct GNUNET_GNS_ResolverHandle *rh = cls;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "dht lookup for query %s (type=%d) timed out.\n",
- rh->name, rh->query->type);
+ "dht lookup for query %s timed out.\n",
+ rh->name);
GNUNET_DHT_get_stop (rh->get_handle);
if (strcmp(rh->name, "") == 0)
unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
+ struct RecordLookupHandle* rlh;
+ rlh = (struct RecordLookupHandle*)cls;
if (rd_count == 0)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"No records for %s found in DHT. Aborting\n",
rh->name);
/* give up, cannot resolve */
- reply_to_dns(NULL, rh, 0, NULL);
+ rlh->proc(rlh->proc_cls, rh, 0, NULL);
+ //reply_to_dns(NULL, rh, 0, NULL);
return;
}
/* results found yay */
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Record resolved from namestore!");
- reply_to_dns(NULL, rh, rd_count, rd);
+ rlh->proc(rlh->proc_cls, rh, rd_count, rd);
+ //reply_to_dns(NULL, rh, rd_count, rd);
}
unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
+ struct RecordLookupHandle* rlh;
+ rlh = (struct RecordLookupHandle*) cls;
if (rd_count == 0)
{
/* ns entry expired. try dht */
return;
}
/* give up, cannot resolve */
- reply_to_dns(NULL, rh, 0, NULL);
+ rlh->proc(rlh->proc_cls, rh, 0, NULL);
+ //reply_to_dns(NULL, rh, 0, NULL);
return;
}
/* results found yay */
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Record resolved from namestore!");
- reply_to_dns(NULL, rh, rd_count, rd);
+ rlh->proc(rlh->proc_cls, rh, rd_count, rd);
+ //reply_to_dns(NULL, rh, rd_count, rd);
}
unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
+ struct RecordLookupHandle* rlh;
+ rlh = (struct RecordLookupHandle*) cls;
+
if (strcmp(rh->name, "") == 0)
{
/* We resolved full name for delegation. resolving record */
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Cannot fully resolve delegation for %s via DHT!\n",
rh->name);
- reply_to_dns(NULL, rh, 0, NULL);
+ rlh->proc(rlh->proc_cls, rh, 0, NULL);
+ //reply_to_dns(NULL, rh, 0, NULL);
}
unsigned int rd_count,
const struct GNUNET_NAMESTORE_RecordData *rd)
{
+ struct RecordLookupHandle* rlh;
+ rlh = (struct RecordLookupHandle*) cls;
+
if (strcmp(rh->name, "") == 0)
{
/* We resolved full name for delegation. resolving record */
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Cannot fully resolve delegation for %s!\n",
rh->name);
- reply_to_dns(NULL, rh, 0, NULL);
+ rlh->proc(rlh->proc_cls, rh, 0, NULL);
+ //reply_to_dns(NULL, rh, 0, NULL);
}
return;
}
struct GNUNET_DNSPARSER_Query *q)
{
struct GNUNET_GNS_ResolverHandle *rh;
+ struct RecordLookupHandle* rlh;
+ struct InterceptLookupHandle* ilh;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting resolution for %s (type=%d)!\n",
q->name, q->type);
rh = GNUNET_malloc(sizeof (struct GNUNET_GNS_ResolverHandle));
- rh->packet = p;
- rh->query = q;
- rh->authority = zone_hash;
+ rlh = GNUNET_malloc(sizeof(struct RecordLookupHandle));
+ ilh = GNUNET_malloc(sizeof(struct InterceptLookupHandle));
+ ilh->packet = p;
+ ilh->query = q;
+ ilh->request_handle = request;
+ rh->authority = zone_hash;
+
+ rlh->record_type = q->type;
+ rlh->name = q->name;
+ rlh->proc = &reply_to_dns;
+ rlh->proc_cls = ilh;
+
+ rh->proc_cls = rlh;
+ rh->authority = zone_hash;
rh->name = GNUNET_malloc(strlen(q->name)
- strlen(gnunet_tld) + 1);
memset(rh->name, 0,
strlen(q->name)-strlen(gnunet_tld));
rh->authority_name = GNUNET_malloc(sizeof(char)*MAX_DNS_LABEL_LENGTH);
-
- rh->request_handle = request;
-
+
rh->authority_chain_head = GNUNET_malloc(sizeof(struct AuthorityChain));
rh->authority_chain_tail = rh->authority_chain_head;
rh->authority_chain_head->zone = zone_hash;