aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-23 15:03:53 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-23 15:03:53 +0000
commit49a261c6967a57fe5ddc0c25d4edcacb94bcd598 (patch)
treea2b63d941eceb0ef8d3912fc08cd2f4dbc7a442a /src
parent0cabde03978a09aa336071eab6aedfb0aa68672f (diff)
downloadgnunet-49a261c6967a57fe5ddc0c25d4edcacb94bcd598.tar.gz
gnunet-49a261c6967a57fe5ddc0c25d4edcacb94bcd598.zip
-make it compile against new api, added parser utils borrowed from dnsparser
Diffstat (limited to 'src')
-rw-r--r--src/gns/gns.h13
-rw-r--r--src/gns/gns_api.c8
-rw-r--r--src/gns/gns_util.c196
-rw-r--r--src/gns/gnunet-service-gns.c279
-rw-r--r--src/gns/namestore_stub_api.c180
5 files changed, 360 insertions, 316 deletions
diff --git a/src/gns/gns.h b/src/gns/gns.h
index ae7a1c670..cb47c817a 100644
--- a/src/gns/gns.h
+++ b/src/gns/gns.h
@@ -29,19 +29,6 @@
29GNUNET_NETWORK_STRUCT_BEGIN 29GNUNET_NETWORK_STRUCT_BEGIN
30 30
31/** 31/**
32 * Equivalent to GNUNET_DNSPARSER_Record
33 * FIXME typedef?
34 */
35struct GNUNET_GNS_Record
36{
37 //struct GNUNET_DNSPARSER_Record record;
38
39 //enum GNUNET_NAMESTORE_RecordFlags flags;
40
41 const struct GNUNET_NAMESTORE_SignatureLocation *sig_loc;
42
43};
44/**
45 * Message from client to GNS service to lookup records. 32 * Message from client to GNS service to lookup records.
46 */ 33 */
47struct GNUNET_GNS_ClientLookupMessage 34struct GNUNET_GNS_ClientLookupMessage
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index 50f616716..00e96a61b 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -430,7 +430,7 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
430 const struct GNUNET_GNS_ClientResultMessage *gns_msg = cls; 430 const struct GNUNET_GNS_ClientResultMessage *gns_msg = cls;
431 struct GNUNET_GNS_LookupHandle *lookup_handle = value; 431 struct GNUNET_GNS_LookupHandle *lookup_handle = value;
432 const char *name = (const char*) &lookup_handle[1]; 432 const char *name = (const char*) &lookup_handle[1];
433 const struct GNUNET_GNS_Record *records; 433 const GNUNET_GNS_Record *records;
434 uint32_t num_records; 434 uint32_t num_records;
435 size_t meta_length; 435 size_t meta_length;
436 size_t msize; 436 size_t msize;
@@ -449,10 +449,10 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
449 num_records = ntohl (gns_msg->num_records); 449 num_records = ntohl (gns_msg->num_records);
450 meta_length = 450 meta_length =
451 sizeof (struct GNUNET_GNS_ClientResultMessage) + 451 sizeof (struct GNUNET_GNS_ClientResultMessage) +
452 sizeof (struct GNUNET_GNS_Record) * (num_records); 452 sizeof (GNUNET_GNS_Record) * (num_records);
453 if ((msize < meta_length) || 453 if ((msize < meta_length) ||
454 (num_records > 454 (num_records >
455 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_GNS_Record))) 455 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (GNUNET_GNS_Record)))
456 { 456 {
457 GNUNET_break (0); 457 GNUNET_break (0);
458 return GNUNET_NO; 458 return GNUNET_NO;
@@ -461,7 +461,7 @@ process_reply (void *cls, const GNUNET_HashCode * key, void *value)
461 LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n", 461 LOG (GNUNET_ERROR_TYPE_DEBUG, "Giving %u byte reply for %s to application\n",
462 (unsigned int) (msize - meta_length), GNUNET_h2s (key)); 462 (unsigned int) (msize - meta_length), GNUNET_h2s (key));
463#endif 463#endif
464 records = (const struct GNUNET_GNS_Record *) &gns_msg[1]; 464 records = (const GNUNET_GNS_Record *) &gns_msg[1];
465 lookup_handle->iter (lookup_handle->iter_cls, name, records, num_records); 465 lookup_handle->iter (lookup_handle->iter_cls, name, records, num_records);
466 return GNUNET_YES; 466 return GNUNET_YES;
467} 467}
diff --git a/src/gns/gns_util.c b/src/gns/gns_util.c
new file mode 100644
index 000000000..b2f5e1f38
--- /dev/null
+++ b/src/gns/gns_util.c
@@ -0,0 +1,196 @@
1#include "gns.h"
2
3/**
4 * Add a DNS name to the buffer at the given location.
5 *
6 * @param dst where to write the name
7 * @param dst_len number of bytes in dst
8 * @param off pointer to offset where to write the name (increment by bytes used)
9 * must not be changed if there is an error
10 * @param name name to write
11 * @return GNUNET_SYSERR if 'name' is invalid
12 * GNUNET_NO if 'name' did not fit
13 * GNUNET_OK if 'name' was added to 'dst'
14 */
15static int
16add_name (char *dst,
17 size_t dst_len,
18 size_t *off,
19 const char *name)
20{
21 const char *dot;
22 size_t start;
23 size_t pos;
24 size_t len;
25
26 if (NULL == name)
27 return GNUNET_SYSERR;
28 start = *off;
29 if (start + strlen (name) + 2 > dst_len)
30 return GNUNET_NO;
31 pos = start;
32 do
33 {
34 dot = strchr (name, '.');
35 if (NULL == dot)
36 len = strlen (name);
37 else
38 len = dot - name;
39 if ( (len >= 64) || (len == 0) )
40 return GNUNET_NO; /* segment too long or empty */
41 dst[pos++] = (char) (uint8_t) len;
42 memcpy (&dst[pos], name, len);
43 pos += len;
44 name += len + 1; /* also skip dot */
45 }
46 while (NULL != dot);
47 dst[pos++] = '\0'; /* terminator */
48 *off = pos;
49 return GNUNET_OK;
50}
51
52/**
53 * Add an MX record to the buffer at the given location.
54 *
55 * @param dst where to write the mx record
56 * @param dst_len number of bytes in dst
57 * @param off pointer to offset where to write the mx information (increment by bytes used);
58 * can also change if there was an error
59 * @param mx mx information to write
60 * @return GNUNET_SYSERR if 'mx' is invalid
61 * GNUNET_NO if 'mx' did not fit
62 * GNUNET_OK if 'mx' was added to 'dst'
63 */
64static int
65add_mx (char *dst,
66 size_t dst_len,
67 size_t *off,
68 const struct GNUNET_DNSPARSER_MxRecord *mx)
69{
70 uint16_t mxpref;
71
72 if (*off + sizeof (uint16_t) > dst_len)
73 return GNUNET_NO;
74 mxpref = htons (mx->preference);
75 memcpy (&dst[*off], &mxpref, sizeof (mxpref));
76 (*off) += sizeof (mxpref);
77 return add_name (dst, dst_len, off, mx->mxhost);
78}
79
80
81/**
82 * Add an SOA record to the buffer at the given location.
83 *
84 * @param dst where to write the SOA record
85 * @param dst_len number of bytes in dst
86 * @param off pointer to offset where to write the SOA information (increment by bytes used)
87 * can also change if there was an error
88 * @param soa SOA information to write
89 * @return GNUNET_SYSERR if 'soa' is invalid
90 * GNUNET_NO if 'soa' did not fit
91 * GNUNET_OK if 'soa' was added to 'dst'
92 */
93static int
94add_soa (char *dst,
95 size_t dst_len,
96 size_t *off,
97 const struct GNUNET_DNSPARSER_SoaRecord *soa)
98{
99 struct soa_data sd;
100 int ret;
101
102 if ( (GNUNET_OK != (ret = add_name (dst,
103 dst_len,
104 off,
105 soa->mname))) ||
106 (GNUNET_OK != (ret = add_name (dst,
107 dst_len,
108 off,
109 soa->rname)) ) )
110 return ret;
111 if (*off + sizeof (struct soa_data) > dst_len)
112 return GNUNET_NO;
113 sd.serial = htonl (soa->serial);
114 sd.refresh = htonl (soa->refresh);
115 sd.retry = htonl (soa->retry);
116 sd.expire = htonl (soa->expire);
117 sd.minimum = htonl (soa->minimum_ttl);
118 memcpy (&dst[*off], &sd, sizeof (sd));
119 (*off) += sizeof (sd);
120 return GNUNET_OK;
121}
122
123/**
124 * Add a DNS record to the buffer at the given location.
125 *
126 * @param dst where to write the record
127 * @param dst_len number of bytes in dst
128 * @param off pointer to offset where to write the query (increment by bytes used)
129 * must not be changed if there is an error
130 * @param record record to write
131 * @return GNUNET_SYSERR if 'record' is invalid
132 * GNUNET_NO if 'record' did not fit
133 * GNUNET_OK if 'record' was added to 'dst'
134 */
135static int
136parse_record (char *dst,
137 size_t dst_len,
138 size_t *off,
139 const struct GNUNET_GNS_Record *record)
140{
141 int ret;
142 size_t start;
143 size_t pos;
144 struct record_line rl;
145
146 start = *off;
147 ret = add_name (dst, dst_len - sizeof (struct record_line), off, record->name);
148 if (ret != GNUNET_OK)
149 return ret;
150 /* '*off' is now the position where we will need to write the record line */
151
152 pos = *off + sizeof (struct record_line);
153 switch (record->type)
154 {
155 case GNUNET_DNSPARSER_TYPE_MX:
156 ret = add_mx (dst, dst_len, &pos, record->data.mx);
157 break;
158 case GNUNET_DNSPARSER_TYPE_SOA:
159 ret = add_soa (dst, dst_len, &pos, record->data.soa);
160 break;
161 case GNUNET_DNSPARSER_TYPE_NS:
162 case GNUNET_DNSPARSER_TYPE_CNAME:
163 case GNUNET_DNSPARSER_TYPE_PTR:
164 ret = add_name (dst, dst_len, &pos, record->data.hostname);
165 break;
166 default:
167 if (pos + record->data.raw.data_len > dst_len)
168 {
169 ret = GNUNET_NO;
170 break;
171 }
172 memcpy (&dst[pos], record->data.raw.data, record->data.raw.data_len);
173 pos += record->data.raw.data_len;
174 ret = GNUNET_OK;
175 break;
176 }
177 if (ret != GNUNET_OK)
178 {
179 *off = start;
180 return GNUNET_NO;
181 }
182
183 if (pos - (*off + sizeof (struct record_line)) > UINT16_MAX)
184 {
185 /* record data too long */
186 *off = start;
187 return GNUNET_NO;
188 }
189 rl.type = htons (record->type);
190 rl.class = htons (record->class);
191 rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value / 1000); /* in seconds */
192 rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct record_line))));
193 memcpy (&dst[*off], &rl, sizeof (struct record_line));
194 *off = pos;
195 return GNUNET_OK;
196}
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 198e4c33b..cb82439c4 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -52,7 +52,7 @@ struct GNUNET_GNS_QueryRecordList
52 struct GNUNET_GNS_QueryRecordList * next; 52 struct GNUNET_GNS_QueryRecordList * next;
53 struct GNUNET_GNS_QueryRecordList * prev; 53 struct GNUNET_GNS_QueryRecordList * prev;
54 54
55 struct GNUNET_DNSPARSER_Record * record; 55 GNUNET_GNS_Record * record;
56}; 56};
57 57
58/** 58/**
@@ -103,8 +103,6 @@ struct GNUNET_DNS_Handle *dns_handle;
103 */ 103 */
104struct GNUNET_DHT_Handle *dht_handle; 104struct GNUNET_DHT_Handle *dht_handle;
105 105
106struct GNUNET_TIME_Relative dht_update_interval;
107
108/** 106/**
109 * Our zone's private key 107 * Our zone's private key
110 */ 108 */
@@ -115,6 +113,8 @@ struct GNUNET_CRYPTO_RsaPrivateKey *zone_key;
115 */ 113 */
116struct GNUNET_NAMESTORE_Handle *namestore_handle; 114struct GNUNET_NAMESTORE_Handle *namestore_handle;
117 115
116struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter;
117
118/** 118/**
119 * The configuration the GNS service is running with 119 * The configuration the GNS service is running with
120 */ 120 */
@@ -136,6 +136,12 @@ GNUNET_HashCode zone_hash;
136const char* gnunet_tld = ".gnunet"; 136const char* gnunet_tld = ".gnunet";
137 137
138/** 138/**
139 * Useful for zone update for DHT put
140 */
141static int num_public_records = 3600;
142struct GNUNET_TIME_Relative dht_update_interval;
143
144/**
139 * Task run during shutdown. 145 * Task run during shutdown.
140 * 146 *
141 * @param cls unused 147 * @param cls unused
@@ -313,20 +319,24 @@ resolve_name(struct GNUNET_GNS_PendingQuery *query, GNUNET_HashCode *zone);
313 * @param data the record data 319 * @param data the record data
314 */ 320 */
315void 321void
316process_authority_lookup(void* cls, const GNUNET_HashCode *zone, 322process_authority_lookup(void* cls,
317 const char *name, uint32_t record_type, 323 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
318 struct GNUNET_TIME_Absolute expiration, 324 struct GNUNET_TIME_Absolute expiration,
319 enum GNUNET_NAMESTORE_RecordFlags flags, 325 const char *name,
320 size_t size, const void *data) 326 unsigned int rd_count,
327 const struct GNUNET_NAMESTORE_RecordData *rd,
328 const struct GNUNET_CRYPTO_RsaSignature *signature)
321{ 329{
322 struct GNUNET_GNS_PendingQuery *query; 330 struct GNUNET_GNS_PendingQuery *query;
331 GNUNET_HashCode zone;
323 332
324 query = (struct GNUNET_GNS_PendingQuery *)cls; 333 query = (struct GNUNET_GNS_PendingQuery *)cls;
334 GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone);
325 335
326 /** 336 /**
327 * No authority found in namestore. 337 * No authority found in namestore.
328 */ 338 */
329 if (NULL == data) 339 if (rd_count == 0)
330 { 340 {
331 if (query->authority_found) 341 if (query->authority_found)
332 { 342 {
@@ -337,11 +347,10 @@ process_authority_lookup(void* cls, const GNUNET_HashCode *zone,
337 347
338 /** 348 /**
339 * We did not find an authority in the namestore 349 * We did not find an authority in the namestore
340 * _IF_ the current authoritative zone is us. 350 * _IF_ the current authoritative zone is us we cannot resolve
341 * we cannot resolve 351 * _ELSE_ we can still check the dht
342 * _ELSE_ we cannot still check the dht
343 */ 352 */
344 if (GNUNET_CRYPTO_hash_cmp(zone, &zone_hash)) 353 if (GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash))
345 { 354 {
346 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Authority unknown\n"); 355 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Authority unknown\n");
347 //FIXME return NX answer 356 //FIXME return NX answer
@@ -351,14 +360,23 @@ process_authority_lookup(void* cls, const GNUNET_HashCode *zone,
351 resolve_authority_dht(query, name); 360 resolve_authority_dht(query, name);
352 return; 361 return;
353 } 362 }
354 363
364 //Note only 1 pkey should have been returned.. anything else would be strange
355 /** 365 /**
356 * We found an authority that may be able to help us 366 * We found an authority that may be able to help us
357 * move on with query 367 * move on with query
358 */ 368 */
359 query->authority_found = 1; 369 GNUNET_GNS_Record *record
360 GNUNET_HashCode *key = (GNUNET_HashCode*) data; //FIXME i assume this works 370 = GNUNET_malloc(sizeof(GNUNET_GNS_Record));
361 query->authority = key; 371
372
373 //FIXME todo
374 //parse_record(rd[0]->data, rd[0]->data_size, 0, record);
375 //FIXME this cast will not work we have to define how a PKEY record looks like
376 //In reality this also returns a pubkey not a hash
377 GNUNET_HashCode *k = (GNUNET_HashCode*)record->data.raw.data;
378 query->authority = k;
379 resolve_name(query, query->authority);
362 380
363} 381}
364 382
@@ -449,40 +467,38 @@ reply_to_dns(struct GNUNET_GNS_PendingQuery *answer)
449 * @param data the record data 467 * @param data the record data
450 */ 468 */
451static void 469static void
452process_authoritative_result(void* cls, const GNUNET_HashCode *zone, 470process_authoritative_result(void* cls,
453 const char *name, uint32_t record_type, 471 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
454 struct GNUNET_TIME_Absolute expiration, 472 struct GNUNET_TIME_Absolute expiration,
455 enum GNUNET_NAMESTORE_RecordFlags flags, 473 const char *name, unsigned int rd_count,
456 size_t size, const void *data) 474 const struct GNUNET_NAMESTORE_RecordData *rd,
475 const struct GNUNET_CRYPTO_RsaSignature *signature)
457{ 476{
458 struct GNUNET_GNS_PendingQuery *query; 477 struct GNUNET_GNS_PendingQuery *query;
459 struct GNUNET_GNS_QueryRecordList *qrecord; 478 struct GNUNET_GNS_QueryRecordList *qrecord;
460 struct GNUNET_DNSPARSER_Record *record; 479 struct GNUNET_DNSPARSER_Record *record;
480 GNUNET_HashCode zone;
461 query = (struct GNUNET_GNS_PendingQuery *) cls; 481 query = (struct GNUNET_GNS_PendingQuery *) cls;
482 GNUNET_CRYPTO_hash(key, GNUNET_CRYPTO_RSA_KEY_LENGTH, &zone);
462 483
484 //FIXME Handle results in rd
463 485
464 if (NULL == data) 486 if (rd_count == 0)
465 { 487 {
466 /** 488 /**
467 * FIXME 489 * FIXME
468 * Lookup terminated 490 * Lookup terminated and no results
469 * Do we have what we need to answer? 491 * -> DHT Phase unless data is recent
470 * If not -> DHT Phase
471 * if full_name == next_name and not anwered we cannot resolve 492 * if full_name == next_name and not anwered we cannot resolve
472 */ 493 */
473 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 494 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
474 "Namestore lookup terminated. (answered=%d)", query->answered); 495 "Namestore lookup terminated. without results\n");
475 if (query->answered) 496
476 {
477 reply_to_dns(query);
478 return;
479 }
480
481 /** 497 /**
482 * if this is not our zone we cannot rely on the namestore to be 498 * if this is not our zone we cannot rely on the namestore to be
483 * complete. -> Query DHT 499 * complete. -> Query DHT
484 */ 500 */
485 if (!GNUNET_CRYPTO_hash_cmp(zone, &zone_hash)) 501 if (!GNUNET_CRYPTO_hash_cmp(&zone, &zone_hash))
486 { 502 {
487 //FIXME todo 503 //FIXME todo
488 resolve_name_dht(query, name); 504 resolve_name_dht(query, name);
@@ -500,54 +516,36 @@ process_authoritative_result(void* cls, const GNUNET_HashCode *zone,
500 { 516 {
501 /** 517 /**
502 * Record found 518 * Record found
519 *
520 * FIXME Check record expiration and dht expiration
521 * consult dht if necessary
503 */ 522 */
504 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 523 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
505 "Processing additional result for %s from namestore\n", name); 524 "Processing additional result for %s from namestore\n", name);
506 525 int i;
507 qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList)); 526 for (i=0; i<rd_count;i++)
508 record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record));
509 qrecord->record = record;
510
511 record->name = (char*)query->original_name;
512
513 /**
514 * FIXME for gns records this requires the dnsparser to be modified!
515 * or use RAW. But RAW data need serialization!
516 * maybe store record data appropriately in namestore to avoid a
517 * huge switch statement?
518 */
519 if (record_type == GNUNET_DNSPARSER_TYPE_A)
520 {
521 record->data.raw.data = (char*)data;
522 record->data.raw.data_len = size;
523 }
524 record->expiration_time = expiration;
525 record->type = record_type;
526 record->class = GNUNET_DNSPARSER_CLASS_INTERNET; /* srsly? */
527
528 //FIXME authoritative answer if we find a result in namestore
529 if (flags == GNUNET_NAMESTORE_RF_AUTHORITY)
530 { 527 {
531 //query->num_authority_records++; 528 // A time will come when this has to be freed
529 qrecord = GNUNET_malloc(sizeof(struct GNUNET_GNS_QueryRecordList));
530 record = GNUNET_malloc(sizeof(struct GNUNET_DNSPARSER_Record));
531 qrecord->record = record;
532
533 //fixme into gns_util
534 //parse_record(rd[i]->data, rd[i]->data_size, 0, record);
535 GNUNET_CONTAINER_DLL_insert(query->records_head,
536 query->records_tail,
537 qrecord);
538 query->num_records++;
539
540 //TODO really?
541 //we need to resolve to the original name in the end though...
542 //record->name = (char*)query->original_name;
532 } 543 }
533 544
534 /**
535 * This seems to take into account that the result could
536 * be different in name and or record type...
537 * but to me this does not make sense
538 */
539 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found answer to query!\n"); 545 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found answer to query!\n");
540 query->answered = 1; 546 query->answered = 1;
541 547
542 query->num_records++; 548 reply_to_dns(query);
543
544 /**
545 * FIXME watch for leaks
546 * properly free pendingquery when the time comes
547 */
548 GNUNET_CONTAINER_DLL_insert(query->records_head,
549 query->records_tail,
550 qrecord);
551 } 549 }
552} 550}
553 551
@@ -749,40 +747,41 @@ put_some_records(void)
749 /* put a few records into namestore */ 747 /* put a few records into namestore */
750 char* ipA = "1.2.3.4"; 748 char* ipA = "1.2.3.4";
751 char* ipB = "5.6.7.8"; 749 char* ipB = "5.6.7.8";
752 struct in_addr *alice = GNUNET_malloc(sizeof(struct in_addr)); 750 GNUNET_GNS_Record *alice = GNUNET_malloc(sizeof(GNUNET_GNS_Record));
753 struct in_addr *bob = GNUNET_malloc(sizeof(struct in_addr)); 751 GNUNET_GNS_Record *bob = GNUNET_malloc(sizeof(GNUNET_GNS_Record));
754 GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice)); 752 struct GNUNET_NAMESTORE_RecordData *rda = NULL;
755 GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob)); 753 struct GNUNET_NAMESTORE_RecordData *rdb = NULL;
756 GNUNET_NAMESTORE_record_put (namestore_handle, 754 rda = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_RecordData));
757 &zone_hash, 755
756 //FIXME here we would have to parse the gns record and put it into
757 //the rd struct
758
759 //FIXME this is not enough! but too mucht atm
760 GNUNET_assert(1 == inet_pton (AF_INET, ipA, alice->data.raw.data));
761 GNUNET_assert(1 == inet_pton (AF_INET, ipB, bob->data.raw.data));
762
763 GNUNET_NAMESTORE_record_create (namestore_handle,
764 zone_key,
758 "alice", 765 "alice",
759 GNUNET_GNS_RECORD_TYPE_A, 766 rda,
760 GNUNET_TIME_absolute_get_forever(),
761 GNUNET_NAMESTORE_RF_AUTHORITY,
762 sizeof(struct in_addr),
763 alice,
764 NULL, 767 NULL,
765 NULL); 768 NULL);
766 GNUNET_NAMESTORE_record_put (namestore_handle, 769 GNUNET_NAMESTORE_record_create (namestore_handle,
767 &zone_hash, 770 zone_key,
768 "bob", 771 "bob",
769 GNUNET_GNS_RECORD_TYPE_A, 772 rdb,
770 GNUNET_TIME_absolute_get_forever(),
771 GNUNET_NAMESTORE_RF_AUTHORITY,
772 sizeof(struct in_addr),
773 bob,
774 NULL, 773 NULL,
775 NULL); 774 NULL);
776} 775}
777 776
778//Prototype... needed in put function 777void
779static void 778update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
780update_zone_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 779{
780 GNUNET_NAMESTORE_zone_iterator_next(namestore_iter);
781}
781 782
782/** 783/**
783 * Function used to put all records successively into the DHT. 784 * Function used to put all records successively into the DHT.
784 * FIXME also serializes records. maybe do this somewhere else...
785 * FIXME don't store private records (maybe zone transfer does this)
786 * 785 *
787 * @param cls the closure (NULL) 786 * @param cls the closure (NULL)
788 * @param zone our root zone hash 787 * @param zone our root zone hash
@@ -795,77 +794,37 @@ update_zone_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
795 * @param record_data the record data 794 * @param record_data the record data
796 */ 795 */
797void 796void
798put_gns_record(void *cls, const GNUNET_HashCode *zone, const char *name, 797put_gns_record(void *cls,
799 uint32_t record_type, struct GNUNET_TIME_Absolute expiration, 798 const const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key,
800 enum GNUNET_NAMESTORE_RecordFlags flags, 799 struct GNUNET_TIME_Absolute expiration,
801 size_t size, const void *record_data) 800 const char *name,
801 unsigned int rd_count,
802 const struct GNUNET_NAMESTORE_RecordData *rd,
803 const struct GNUNET_CRYPTO_RsaSignature *signature)
802{ 804{
803 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Putting a record into the DHT\n"); 805 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Putting records into the DHT\n");
804 struct GNUNET_TIME_Relative timeout; 806 struct GNUNET_TIME_Relative timeout;
805
806 char* data;
807 char* data_ptr;
808 struct GNUNET_TIME_AbsoluteNBO exp_nbo;
809 exp_nbo = GNUNET_TIME_absolute_hton (expiration);
810 uint32_t namelen = htonl(strlen(name));
811 uint16_t flags_nbo = htons(flags);
812 GNUNET_HashCode name_hash; 807 GNUNET_HashCode name_hash;
813 GNUNET_HashCode xor_hash; 808 GNUNET_HashCode xor_hash;
814 809
815 /** 810 if (NULL == name) //We're done
816 * I guess this can be done prettier 811 {
817 * FIXME extract into function, maybe even into different file 812 GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter);
818 */ 813 return;
819 size_t record_len = sizeof(size_t) + sizeof(uint32_t) + 814 }
820 sizeof(uint16_t) +
821 sizeof(uint32_t) + strlen(name) + size;
822
823 record_type = htonl(record_type);
824
825 data = GNUNET_malloc(record_len);
826
827 /* -_- */
828 data_ptr = data;
829 memcpy(data_ptr, &namelen, sizeof(size_t));
830 data_ptr += sizeof(size_t);
831
832 memcpy(data_ptr, name, namelen);
833 data_ptr += namelen;
834
835 memcpy(data_ptr, &record_type, sizeof(uint32_t));
836 data_ptr += sizeof(uint32_t);
837
838 memcpy(data_ptr, &exp_nbo, sizeof(struct GNUNET_TIME_AbsoluteNBO));
839 data_ptr += sizeof(struct GNUNET_TIME_AbsoluteNBO);
840
841 memcpy(data_ptr, &flags_nbo, sizeof(uint16_t));
842 data_ptr += sizeof(uint16_t);
843
844 memcpy(data_ptr, &size, sizeof(uint32_t));
845 data_ptr += sizeof(uint32_t);
846
847 /**
848 * FIXME note that this only works with raw data in nbo
849 * write helper function that converts properly and returns buffer
850 */
851 memcpy(data_ptr, record_data, size);
852 data_ptr += size;
853 /*Doing this made me sad...*/
854
855 /** 815 /**
856 * FIXME magic number 20 move to config file 816 * FIXME magic number 20 move to config file
857 */ 817 */
858 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); 818 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20);
859
860 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); 819 GNUNET_CRYPTO_hash(name, strlen(name), &name_hash);
861 GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash); 820 GNUNET_CRYPTO_hash_xor(&zone_hash, &name_hash, &xor_hash);
862 GNUNET_DHT_put (dht_handle, &xor_hash, 821 GNUNET_DHT_put (dht_handle, &xor_hash,
863 5, //replication level 822 5, //replication level
864 GNUNET_DHT_RO_NONE, 823 GNUNET_DHT_RO_NONE,
865 GNUNET_BLOCK_TYPE_TEST, //FIXME todo block plugin 824 GNUNET_BLOCK_TYPE_TEST, //FIXME todo block plugin
866 (data_ptr-data), 825 rd->data_size,
867 data, 826 rd->data,
868 expiration, //FIXME from record makes sense? is absolute? 827 expiration,
869 timeout, 828 timeout,
870 NULL, //FIXME continuation needed? success check? yes ofc 829 NULL, //FIXME continuation needed? success check? yes ofc
871 NULL); //cls for cont 830 NULL); //cls for cont
@@ -874,7 +833,7 @@ put_gns_record(void *cls, const GNUNET_HashCode *zone, const char *name,
874 * Reschedule periodic put 833 * Reschedule periodic put
875 */ 834 */
876 GNUNET_SCHEDULER_add_delayed (dht_update_interval, 835 GNUNET_SCHEDULER_add_delayed (dht_update_interval,
877 &update_zone_dht, 836 &update_zone_dht_next,
878 NULL); 837 NULL);
879 838
880} 839}
@@ -886,12 +845,17 @@ put_gns_record(void *cls, const GNUNET_HashCode *zone, const char *name,
886 * @param tc task context 845 * @param tc task context
887 */ 846 */
888static void 847static void
889update_zone_dht(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 848update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
890{ 849{
891 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Update zone!\n"); 850 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Update zone!\n");
892 GNUNET_NAMESTORE_zone_transfer (namestore_handle, &zone_hash, 851 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
893 &put_gns_record, 852 (3600/num_public_records));
894 NULL); 853 namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore_handle,
854 &zone_hash,
855 GNUNET_NAMESTORE_RF_AUTHORITY,
856 GNUNET_NAMESTORE_RF_PRIVATE,
857 &put_gns_record,
858 NULL);
895} 859}
896 860
897/** 861/**
@@ -960,11 +924,12 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
960 /** 924 /**
961 * Schedule periodic put 925 * Schedule periodic put
962 * for our records 926 * for our records
927 * We have roughly an hour for all records;
963 */ 928 */
964 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 929 dht_update_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
965 60); //FIXME from cfg 930 60); //FIXME from cfg
966 GNUNET_SCHEDULER_add_delayed (dht_update_interval, 931 GNUNET_SCHEDULER_add_delayed (dht_update_interval,
967 &update_zone_dht, 932 &update_zone_dht_start,
968 NULL); 933 NULL);
969 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "GNS Init done!\n"); 934 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "GNS Init done!\n");
970 935
diff --git a/src/gns/namestore_stub_api.c b/src/gns/namestore_stub_api.c
index 29a785a8a..d08de04cb 100644
--- a/src/gns/namestore_stub_api.c
+++ b/src/gns/namestore_stub_api.c
@@ -146,56 +146,40 @@ struct GNUNET_NAMESTORE_QueueEntry *
146GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h, 146GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
147 const GNUNET_HashCode *zone, 147 const GNUNET_HashCode *zone,
148 const char *name, 148 const char *name,
149 uint32_t record_type,
150 struct GNUNET_TIME_Absolute expiration, 149 struct GNUNET_TIME_Absolute expiration,
151 enum GNUNET_NAMESTORE_RecordFlags flags, 150 unsigned int rd_count,
152 size_t data_size, 151 const struct GNUNET_NAMESTORE_RecordData *rd,
153 const void *data, 152 const struct GNUNET_CRYPTO_RsaSignature *signature,
154 GNUNET_NAMESTORE_ContinuationWithStatus cont, 153 GNUNET_NAMESTORE_ContinuationWithStatus cont,
155 void *cont_cls) 154 void *cont_cls)
156{ 155{
157 struct GNUNET_NAMESTORE_QueueEntry *qe; 156 struct GNUNET_NAMESTORE_QueueEntry *qe;
158 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 157 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
159 158 //FIXME
160 struct GNUNET_NAMESTORE_SimpleRecord *sr;
161 sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord));
162 sr->name = name;
163 sr->record_type = record_type;
164 sr->expiration = expiration;
165 sr->flags = flags;
166 sr->data_size = data_size;
167 sr->data = data;
168 GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
169 return qe; 159 return qe;
170} 160}
171 161
172/** 162int
173 * Store a signature in the namestore. 163GNUNET_NAMESTORE_verify_signature (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key,
174 * 164 const char *name,
175 * @param h handle to the namestore 165 unsigned int rd_count,
176 * @param zone hash of the public key of the zone 166 const struct GNUNET_NAMESTORE_RecordData *rd,
177 * @param name name that is being mapped (at most 255 characters long) 167 const struct GNUNET_CRYPTO_RsaSignature *signature)
178 * @param record_type type of the record (A, AAAA, PKEY, etc.) 168{
179 * @param expiration expiration time for the content 169 return GNUNET_OK;
180 * @param flags flags for the content 170}
181 * @param data_size number of bytes in data 171
182 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
183 * GNS specification for GNS extensions)
184 * @param cont continuation to call when done
185 * @param cont_cls closure for cont
186 * @return handle to abort the request
187 */
188struct GNUNET_NAMESTORE_QueueEntry * 172struct GNUNET_NAMESTORE_QueueEntry *
189GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h, 173GNUNET_NAMESTORE_record_create (struct GNUNET_NAMESTORE_Handle *h,
190 const GNUNET_HashCode *zone, 174 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
191 const char *name, 175 const char *name,
192 struct GNUNET_CRYPTO_RsaSignature sig, 176 const struct GNUNET_NAMESTORE_RecordData *rd,
193 GNUNET_NAMESTORE_ContinuationWithStatus cont, 177 GNUNET_NAMESTORE_ContinuationWithStatus cont,
194 void *cont_cls) 178 void *cont_cls)
195{ 179{
196 struct GNUNET_NAMESTORE_QueueEntry *qe; 180 struct GNUNET_NAMESTORE_QueueEntry *qe;
197 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 181 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
198 182 //FIXME
199 return qe; 183 return qe;
200} 184}
201 185
@@ -217,30 +201,16 @@ GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h,
217 */ 201 */
218struct GNUNET_NAMESTORE_QueueEntry * 202struct GNUNET_NAMESTORE_QueueEntry *
219GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h, 203GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
220 const GNUNET_HashCode *zone, 204 const struct GNUNET_CRYPTO_RsaPrivateKey *pkey,
221 const char *name, 205 const char *name,
222 uint32_t record_type, 206 const struct GNUNET_NAMESTORE_RecordData *rd,
223 size_t size, 207 GNUNET_NAMESTORE_ContinuationWithStatus cont,
224 const void *data,
225 GNUNET_NAMESTORE_ContinuationWithStatus cont,
226 void *cont_cls) 208 void *cont_cls)
227{ 209{
228 struct GNUNET_NAMESTORE_QueueEntry *qe; 210 struct GNUNET_NAMESTORE_QueueEntry *qe;
229 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 211 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
230 212
231 struct GNUNET_NAMESTORE_SimpleRecord *iter; 213 //FIXME
232 for (iter=h->records_head; iter != NULL; iter=iter->next)
233 {
234 if (strcmp ( iter->name, name ) &&
235 iter->record_type == record_type &&
236 GNUNET_CRYPTO_hash_cmp (iter->zone, zone))
237 break;
238 }
239 if (iter)
240 GNUNET_CONTAINER_DLL_remove(h->records_head,
241 h->records_tail,
242 iter);
243
244 return qe; 214 return qe;
245} 215}
246 216
@@ -268,107 +238,33 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
268 struct GNUNET_NAMESTORE_QueueEntry *qe; 238 struct GNUNET_NAMESTORE_QueueEntry *qe;
269 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); 239 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
270 240
271 struct GNUNET_NAMESTORE_SimpleRecord *iter; 241 //FIXME
272 for (iter=h->records_head; iter != NULL; iter=iter->next)
273 {
274 if (strcmp(iter->name, name))
275 continue;
276
277 if (iter->record_type != record_type)
278 continue;
279
280 proc(proc_cls, iter->zone, iter->name, iter->record_type,
281 iter->expiration,
282 iter->flags,
283 iter->data_size /*size*/,
284 iter->data /* data */);
285 }
286 proc(proc_cls, zone, name, record_type,
287 GNUNET_TIME_absolute_get_forever(), 0, 0, NULL); /*TERMINATE*/
288
289 return qe; 242 return qe;
290} 243}
291 244
292struct GNUNET_NAMESTORE_QueueEntry * 245struct GNUNET_NAMESTORE_ZoneIterator *
293GNUNET_NAMESTORE_lookup_signature (struct GNUNET_NAMESTORE_Handle *h, 246GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h,
294 const GNUNET_HashCode *zone, 247 const GNUNET_HashCode *zone,
295 const char* name, 248 enum GNUNET_NAMESTORE_RecordFlags must_have_flags,
296 GNUNET_NAMESTORE_SignatureProcessor proc, 249 enum GNUNET_NAMESTORE_RecordFlags must_not_have_flags,
297 void *proc_cls) 250 GNUNET_NAMESTORE_RecordProcessor proc,
251 void *proc_cls)
298{ 252{
299 return NULL; 253 struct GNUNET_NAMESTORE_ZoneIterator *it;
254 it = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_ZoneIterator));
255 return it;
300} 256}
301 257
302
303/**
304 * Get the hash of a record (what will be signed in the Stree for
305 * the record).
306 *
307 * @param zone hash of the public key of the zone
308 * @param name name that is being mapped (at most 255 characters long)
309 * @param record_type type of the record (A, AAAA, PKEY, etc.)
310 * @param expiration expiration time for the content
311 * @param flags flags for the content
312 * @param data_size number of bytes in data
313 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and.
314 * GNS specification for GNS extensions)
315 * @param record_hash hash of the record (set)
316 */
317void 258void
318GNUNET_NAMESTORE_record_hash (struct GNUNET_NAMESTORE_Handle *h, 259GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it)
319 const GNUNET_HashCode *zone,
320 const char *name,
321 uint32_t record_type,
322 struct GNUNET_TIME_Absolute expiration,
323 enum GNUNET_NAMESTORE_RecordFlags flags,
324 size_t data_size,
325 const void *data,
326 GNUNET_HashCode *record_hash)
327{ 260{
328 char* teststring = "namestore-stub";
329 GNUNET_CRYPTO_hash(teststring, strlen(teststring), record_hash);
330} 261}
331 262
332 263void
333/** 264GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
334 * Get all records of a zone.
335 *
336 * @param h handle to the namestore
337 * @param zone zone to access
338 * @param proc function to call on a random value; it
339 * will be called repeatedly with a value (if available)
340 * and always once at the end with a zone and name of NULL.
341 * @param proc_cls closure for proc
342 * @return a handle that can be used to
343 * cancel
344 */
345struct GNUNET_NAMESTORE_QueueEntry *
346GNUNET_NAMESTORE_zone_transfer (struct GNUNET_NAMESTORE_Handle *h,
347 const GNUNET_HashCode *zone,
348 GNUNET_NAMESTORE_RecordProcessor proc,
349 void *proc_cls)
350{ 265{
351 struct GNUNET_NAMESTORE_QueueEntry *qe;
352 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
353 return qe;
354} 266}
355 267
356struct GNUNET_NAMESTORE_ZoneIterator *
357GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h,
358 const GNUNET_HashCode *zone,
359 GNUNET_NAMESTORE_RecordProcessor proc,
360 void *proc_cls);
361
362int
363GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it);
364
365void
366GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it);
367
368void
369GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
370
371
372/** 268/**
373 * Cancel a namestore operation. The final callback from the 269 * Cancel a namestore operation. The final callback from the
374 * operation must not have been done yet. 270 * operation must not have been done yet.