From d95214984656e24aaff69870e400752965a38d09 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Fri, 24 Feb 2012 10:51:42 +0000 Subject: [PATCH] -fixes, implemented new stub --- src/gns/gnunet-service-gns.c | 33 +++++++------ src/gns/namestore_stub_api.c | 90 ++++++++++++++++++++++++++++++++---- 2 files changed, 98 insertions(+), 25 deletions(-) diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 4bdf1daf3..21791a6fa 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c @@ -141,7 +141,8 @@ static int num_public_records = 3600; struct GNUNET_TIME_Relative dht_update_interval; -void reply_to_dns(struct GNUNET_GNS_PendingQuery *answer); +void reply_to_dns(struct GNUNET_GNS_PendingQuery *answer, uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd); void resolve_name(struct GNUNET_GNS_PendingQuery *query, GNUNET_HashCode *zone); @@ -440,7 +441,7 @@ process_name_dht_result(void* cls, //FIXME: add records to query handle, but on stack! //do we need records in query handle? can't we just //pass them to reply_to_dns? - reply_to_dns(query); + reply_to_dns(query, num_records, rd); } /** @@ -562,11 +563,11 @@ process_authority_lookup(void* cls, * @param answer the pending query used in the lookup */ void -reply_to_dns(struct GNUNET_GNS_PendingQuery *answer) +reply_to_dns(struct GNUNET_GNS_PendingQuery *answer, uint32_t rd_count, + const struct GNUNET_NAMESTORE_RecordData *rd) { - struct GNUNET_GNS_QueryRecordList *i; struct GNUNET_DNSPARSER_Flags dnsflags; - int j; + int i; size_t len; int ret; char *buf; @@ -575,19 +576,17 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer) packet.answers = answer_records; len = sizeof(struct GNUNET_DNSPARSER_Record*); - j = 0; - for (i=answer->records_head; i != NULL; i=i->next) + for (i=0; i < rd_count; i++) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Adding type %d to DNS response\n", i->record->record_type); - answer_records[j].name = answer->original_name; //FIXME yes? - answer_records[j].type = i->record->record_type; - answer_records[j].data.raw.data_len = i->record->data_size; - answer_records[j].data.raw.data = (char*)i->record->data; - answer_records[j].expiration_time = i->record->expiration; - answer_records[j].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn + "Adding type %d to DNS response\n", rd[i].record_type); + 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].data.raw.data = (char*)rd[i].data; + answer_records[i].expiration_time = rd[i].expiration; + answer_records[i].class = GNUNET_DNSPARSER_CLASS_INTERNET;//hmmn //GNUNET_free(i->record); DO this later! - j++; } GNUNET_log(GNUNET_ERROR_TYPE_INFO, "after memcpy\n"); /* FIXME how to handle auth, additional etc */ @@ -695,7 +694,7 @@ process_authoritative_result(void* cls, * FIXME modify query to say NX */ GNUNET_assert(query->answered == 0); - reply_to_dns(query); //answered should be 0 + reply_to_dns(query, 0, NULL); //answered should be 0 return; } @@ -747,7 +746,7 @@ process_authoritative_result(void* cls, GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found answer to query!\n"); query->answered = 1; - reply_to_dns(query); + reply_to_dns(query, rd_count, rd); } } diff --git a/src/gns/namestore_stub_api.c b/src/gns/namestore_stub_api.c index d08de04cb..e511bef31 100644 --- a/src/gns/namestore_stub_api.c +++ b/src/gns/namestore_stub_api.c @@ -67,11 +67,19 @@ struct GNUNET_NAMESTORE_Handle struct GNUNET_NAMESTORE_SimpleRecord * records_head; struct GNUNET_NAMESTORE_SimpleRecord * records_tail; + uint32_t locked; + }; struct GNUNET_NAMESTORE_ZoneIterator { struct GNUNET_NAMESTORE_Handle *handle; + GNUNET_NAMESTORE_RecordProcessor proc; + void* proc_cls; + const GNUNET_HashCode * zone; + uint32_t no_flags; + uint32_t flags; + struct GNUNET_NAMESTORE_Handle *h; }; struct GNUNET_NAMESTORE_SimpleRecord @@ -88,13 +96,12 @@ struct GNUNET_NAMESTORE_SimpleRecord const char *name; const GNUNET_HashCode *zone; - uint32_t record_type; - struct GNUNET_TIME_Absolute expiration; - enum GNUNET_NAMESTORE_RecordFlags flags; - size_t data_size; - const void *data; + const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key; + uint32_t rd_count; + struct GNUNET_NAMESTORE_RecordData rd[100]; }; + /** * Initialize the connection with the NAMESTORE service. * @@ -111,7 +118,6 @@ GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) return handle; } - /** * Shutdown connection with the NAMESTORE service. * @@ -179,7 +185,34 @@ GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h, { struct GNUNET_NAMESTORE_QueueEntry *qe; qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); - //FIXME + struct GNUNET_NAMESTORE_SimpleRecord* sr; + + sr = h->records_head; + for (; sr != NULL; sr = sr->next) + { + if (strcmp(sr->name, name) && (sr->zone == NULL)) + { + memcpy (&(sr->rd[sr->rd_count]), rd, + sizeof(struct GNUNET_NAMESTORE_RecordData)); + + sr->rd_count++; + return qe; + } + } + + sr = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_SimpleRecord*)); + + sr->rd_count = 0; + sr->name = GNUNET_malloc(strlen(name)); + sr->zone = NULL; + sr->zone_key = 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); + return qe; } @@ -237,7 +270,21 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, { struct GNUNET_NAMESTORE_QueueEntry *qe; qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); - + struct GNUNET_NAMESTORE_SimpleRecord *sr; + + sr = h->records_head; + for (; sr != NULL; sr = sr->next) + { + if (strcmp(sr->name, name) && + (GNUNET_CRYPTO_hash_cmp(sr->zone, zone))) + { + //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; + } + } + proc(proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, name, 0, NULL, NULL); //FIXME return qe; } @@ -251,18 +298,45 @@ GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, void *proc_cls) { struct GNUNET_NAMESTORE_ZoneIterator *it; + h->locked = 1; it = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_ZoneIterator)); + it->h = h; + it->proc = proc; + it->proc_cls = proc_cls; + it->zone = zone; + it->no_flags = must_not_have_flags; + it->flags = must_have_flags; + GNUNET_NAMESTORE_zone_iterator_next(it); return it; } void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it) { + struct GNUNET_NAMESTORE_SimpleRecord *sr; + + if (it->h->locked == 0) + return; + + sr = it->h->records_head; + for (; sr != NULL; sr = sr->next) + { + if (GNUNET_CRYPTO_hash_cmp(sr->zone, it->zone)) + { + //Simply always return all records + //check flags + it->proc(it->proc_cls, sr->zone_key, GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME + sr->name, sr->rd_count, sr->rd, NULL); + } + } + it->proc(it->proc_cls, NULL, GNUNET_TIME_UNIT_ZERO_ABS, NULL, 0, NULL, NULL); } void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it) { + it->h->locked = 0; + GNUNET_free(it); } /** -- 2.25.1