* may be able to resolve
*/
int authority_found;
+
+ struct GNUNET_DNSPARSER_Packet *p;
};
uint16_t namelen;
char* name = NULL;
struct GNUNET_CRYPTO_RsaSignature *signature;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key;
int i;
char* pos;
GNUNET_HashCode zone, name_hash;
}
- if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature))
+ if ((((char*)data)-pos) <
+ (sizeof(struct GNUNET_CRYPTO_RsaSignature) +
+ sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Cannot parse signature in DHT response. Corrupted or Missing");
+ "Cannot parse signature/key in DHT response. Corrupted or Missing");
return;
}
signature = (struct GNUNET_CRYPTO_RsaSignature*)pos;
-
+ pos += sizeof(struct GNUNET_CRYPTO_RsaSignature);
+
+ public_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded*)pos;
GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone);
//Save to namestore
GNUNET_NAMESTORE_record_put (namestore_handle,
- &zone,
+ public_key,
name,
exp,
num_records,
uint16_t namelen;
char* name = NULL;
struct GNUNET_CRYPTO_RsaSignature *signature;
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key;
int i;
char* pos;
GNUNET_HashCode zone, name_hash;
}
- if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature))
+ if ((((char*)data)-pos) <
+ (sizeof(struct GNUNET_CRYPTO_RsaSignature) +
+ sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Cannot parse signature in DHT response. Corrupted or Missing");
+ "Cannot parse signature/key in DHT response. Corrupted or Missing");
return;
}
signature = (struct GNUNET_CRYPTO_RsaSignature*)pos;
+ pos += sizeof(struct GNUNET_CRYPTO_RsaSignature);
+
+ public_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded*)pos;
GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone);
//Save to namestore
GNUNET_NAMESTORE_record_put (namestore_handle,
- &zone,
+ public_key,
name,
exp,
num_records,
size_t len;
int ret;
char *buf;
- struct GNUNET_DNSPARSER_Packet packet;
+ struct GNUNET_DNSPARSER_Packet *packet = answer->p;
struct GNUNET_DNSPARSER_Record answer_records[answer->num_records];
- packet.answers = answer_records;
+ packet->answers = answer_records;
len = sizeof(struct GNUNET_DNSPARSER_Record*);
for (i=0; i < rd_count; i++)
{
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
"Adding type %d to DNS response\n", rd[i].record_type);
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Name: %s\n", answer->name);
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "OName: %s\n", answer->original_name);
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Record %d/%d\n", i+1, rd_count);
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Record len %d\n", rd[i].data_size);
answer_records[i].name = answer->original_name; //FIXME yes?
answer_records[i].type = rd[i].record_type;
answer_records[i].data.raw.data_len = rd[i].data_size;
answer_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn
//GNUNET_free(i->record); DO this later!
}
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "after memcpy\n");
- /* FIXME how to handle auth, additional etc */
- packet.num_answers = answer->num_records;
- packet.num_authority_records = answer->num_authority_records;
+
+ /**
+ * FIXME how to handle auth, additional etc
+ * PKEY might be auth, != name,record_type additional
+ **/
+ packet->num_queries = 0;
+ packet->num_additional_records = 0;
+ packet->num_answers = rd_count; //answer->num_records;
+ //packet.num_authority_records = 0;//answer->num_authority_records;
dnsflags.authoritative_answer = 1;
+ dnsflags.message_truncated = 0;
+ dnsflags.recursion_desired = 0;
+ dnsflags.authenticated_data = 0;
+ dnsflags.checking_disabled = 1;
+ dnsflags.zero = 0;
+ dnsflags.recursion_available = 0;
dnsflags.opcode = GNUNET_DNSPARSER_OPCODE_QUERY;
- dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR; //not sure
+ if (rd == NULL)
+ dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NAME_ERROR;
+ else
+ dnsflags.return_code = GNUNET_DNSPARSER_RETURN_CODE_NO_ERROR;
dnsflags.query_or_response = 1;
- packet.flags = dnsflags;
+ packet->flags = dnsflags;
- packet.id = answer->id;
-
//FIXME this is silently discarded
- ret = GNUNET_DNSPARSER_pack (&packet,
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Building DNS response\n");
+ ret = GNUNET_DNSPARSER_pack (packet,
1024, /* FIXME magic from dns redirector */
&buf,
&len);
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Built DNS response! (ret=%d)\n", ret);
+ "Built DNS response! (ret=%d,len=%d)\n", ret, len);
if (ret == GNUNET_OK)
{
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
* -> DHT Phase unless data is recent
*/
GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Namestore lookup terminated. without results\n");
+ "Namestore lookup for %s terminated without results\n", name);
/**
* if this is not our zone we cannot rely on the namestore to be
*/
void
start_resolution(struct GNUNET_DNS_RequestHandle *rh,
+ struct GNUNET_DNSPARSER_Packet *p,
char* name, uint16_t id, uint16_t type)
{
struct GNUNET_GNS_PendingQuery *query;
query = GNUNET_malloc(sizeof (struct GNUNET_GNS_PendingQuery));
query->id = id;
query->original_name = name; //Full name of original query
+ query->p = p;
//FIXME do not forget to free!!
query->name = GNUNET_malloc(strlen(name)-strlen(gnunet_tld) + 1);
if (0 == strcmp(tldoffset, gnunet_tld))
{
- start_resolution(rh, p->queries[i].name, p->id, p->queries[i].type);
+ start_resolution(rh, p, p->queries[i].name, p->id, p->queries[i].type);
}
else
{
/* put a few records into namestore */
char* ipA = "1.2.3.4";
char* ipB = "5.6.7.8";
+ struct GNUNET_CRYPTO_RsaPrivateKey *bob_key = GNUNET_CRYPTO_rsa_key_create (); struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *bob;
+ bob = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+
+ GNUNET_CRYPTO_rsa_key_get_public (bob_key, bob);
+
+ GNUNET_HashCode *bob_zone = GNUNET_malloc(sizeof(GNUNET_HashCode));
+
+ GNUNET_CRYPTO_hash(bob, GNUNET_CRYPTO_RSA_KEY_LENGTH, bob_zone);
+
struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr));
- struct in_addr *bob = GNUNET_malloc(sizeof(struct in_addr));
- struct GNUNET_NAMESTORE_RecordData *rda;
- struct GNUNET_NAMESTORE_RecordData *rdb;
+ struct in_addr *bob_web = GNUNET_malloc(sizeof(struct in_addr));
+ struct GNUNET_NAMESTORE_RecordData rda;
+ struct GNUNET_NAMESTORE_RecordData rdb;
+ struct GNUNET_NAMESTORE_RecordData rdb_web;
- rda = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
- rdb = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
-
GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice));
- GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob));
-
- rda->data_size = sizeof(struct in_addr);
- rdb->data_size = sizeof(struct in_addr);
- rda->data = alice;
- rdb->data = bob;
- rda->record_type = GNUNET_GNS_RECORD_TYPE_A;
- rdb->record_type = GNUNET_GNS_RECORD_TYPE_A;
- rda->expiration = GNUNET_TIME_absolute_get_forever ();
- rdb->expiration = GNUNET_TIME_absolute_get_forever ();
+ GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob_web));
+
+ rda.data_size = sizeof(struct in_addr);
+ rdb_web.data_size = sizeof(struct in_addr);
+ rdb.data_size = sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded);
+ rda.data = alice;
+ rdb.data = bob;
+ rdb_web.data = bob_web;
+ rda.record_type = GNUNET_GNS_RECORD_TYPE_A;
+ rdb_web.record_type = GNUNET_GNS_RECORD_TYPE_A;
+ rdb.record_type = GNUNET_GNS_RECORD_PKEY;
+ rdb_web.expiration = GNUNET_TIME_absolute_get_forever ();
+ rda.expiration = GNUNET_TIME_absolute_get_forever ();
+ rdb.expiration = GNUNET_TIME_absolute_get_forever ();
+ //alice.gnunet A IN 1.2.3.4
GNUNET_NAMESTORE_record_create (namestore_handle,
zone_key,
"alice",
- rda,
+ &rda,
NULL,
NULL);
+
+ //www.bob.gnunet A IN 5.6.7.8
GNUNET_NAMESTORE_record_create (namestore_handle,
zone_key,
"bob",
- rdb,
+ &rdb,
NULL,
NULL);
+ GNUNET_NAMESTORE_record_put(namestore_handle,
+ bob,
+ "www",
+ GNUNET_TIME_absolute_get_forever (),
+ 1,
+ &rdb_web,
+ NULL, //Signature
+ NULL, //Cont
+ NULL); //cls
}
void
handle = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle));
handle->cfg = cfg;
+ handle->records_head = NULL;
+ handle->records_tail = NULL;
return handle;
}
*/
struct GNUNET_NAMESTORE_QueueEntry *
GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
- const GNUNET_HashCode *zone,
+ const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
const char *name,
struct GNUNET_TIME_Absolute expiration,
unsigned int rd_count,
{
struct GNUNET_NAMESTORE_QueueEntry *qe;
qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
- //FIXME
+ struct GNUNET_NAMESTORE_SimpleRecord* sr;
+ GNUNET_HashCode *zone;
+ int i;
+
+ zone = GNUNET_malloc(sizeof(GNUNET_HashCode));
+ GNUNET_CRYPTO_hash(public_key,
+ sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+ zone);
+
+ sr = h->records_head;
+ for (; sr != NULL; sr = sr->next)
+ {
+ if (GNUNET_CRYPTO_hash_cmp(zone, sr->zone) == 0)
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "records for %s already present ow\n",
+ name);
+ sr->rd_count = rd_count;
+ for (i=0; i<rd_count; i++)
+ {
+ sr->rd[i] = rd[i];
+ }
+ //Expiration, Signature etc
+ return qe;
+ }
+ }
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "new records for %s\n", name);
+ // Not present
+ sr = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_SimpleRecord));
+ sr->rd_count = rd_count;
+ sr->name = GNUNET_malloc(strlen(name));
+ sr->zone = zone;
+ sr->zone_key = public_key; //pkey FIXME;
+ sr->next = NULL;
+ sr->prev = NULL;
+ strcpy((char*)sr->name, name);
+
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "copying \n");
+ for (i=0; i<rd_count; i++)
+ sr->rd[i] = rd[i];
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "done \n");
+
+ if (h->records_head == NULL && h->records_tail == NULL)
+ {
+ h->records_head = sr;
+ h->records_tail = sr;
+ }
+ else
+ {
+ GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
+ }
+
return qe;
}
struct GNUNET_NAMESTORE_QueueEntry *
GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
- const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
+ const struct GNUNET_CRYPTO_RsaPrivateKey *key,
const char *name,
const struct GNUNET_NAMESTORE_RecordData *rd,
GNUNET_NAMESTORE_ContinuationWithStatus cont,
struct GNUNET_NAMESTORE_QueueEntry *qe;
qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
struct GNUNET_NAMESTORE_SimpleRecord* sr;
+
+ GNUNET_HashCode *zone_hash;
+
+ //memleakage.. but only stub so w/e
+ struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey;
+ pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
+ GNUNET_CRYPTO_rsa_key_get_public (key, pkey);
+
+ zone_hash = GNUNET_malloc(sizeof(GNUNET_HashCode));
+
+ GNUNET_CRYPTO_hash(pkey, GNUNET_CRYPTO_RSA_KEY_LENGTH, zone_hash);
sr = h->records_head;
for (; sr != NULL; sr = sr->next)
{
- if (strcmp(sr->name, name) && (sr->zone == NULL))
+ if (strcmp(sr->name, name) && (sr->zone == zone_hash))
{
- memcpy (&(sr->rd[sr->rd_count]), rd,
+ //Dangerous
+ memcpy (&(sr->rd[sr->rd_count-1]), rd,
sizeof(struct GNUNET_NAMESTORE_RecordData));
sr->rd_count++;
}
}
- sr = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_SimpleRecord*));
+ sr = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_SimpleRecord));
- sr->rd_count = 0;
+ sr->rd_count = 1;
sr->name = GNUNET_malloc(strlen(name));
- sr->zone = NULL;
- sr->zone_key = NULL;
+ sr->zone = zone_hash;
+ sr->zone_key = pkey;
+ sr->next = NULL;
+ sr->prev = NULL;
strcpy((char*)sr->name, name);
memcpy (&(sr->rd), rd,
sizeof(struct GNUNET_NAMESTORE_RecordData));
-
- GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
+ if (h->records_head == NULL && h->records_tail == NULL)
+ {
+ h->records_head = sr;
+ h->records_tail = sr;
+ }
+ else
+ {
+ GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
+ }
return qe;
}
qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
struct GNUNET_NAMESTORE_SimpleRecord *sr;
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Looking up %s\n", name);
sr = h->records_head;
for (; sr != NULL; sr = sr->next)
{
- if (strcmp(sr->name, name) &&
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Got %s\n", sr->name);
+ if ((strcmp(sr->name, name) == 0) &&
(GNUNET_CRYPTO_hash_cmp(sr->zone, zone)))
{
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ "Found match for %s with %d entries\n",
+ sr->name, sr->rd_count);
//Simply always return all records
proc(proc_cls, sr->zone_key, GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME
name, sr->rd_count, sr->rd, NULL);
return qe;
}
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO, "No match\n");
}
proc(proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, name, 0, NULL, NULL);
//FIXME