diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-23 17:31:14 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-02-23 17:31:14 +0000 |
commit | 0c3dc8571333312dcfe3bf18e383ca85a1fc79b0 (patch) | |
tree | acb5bc285ca9fa526ac6b7a465682b260e5d3684 | |
parent | 37488aed2cecebf4472d8e7bef0ebea2a92c9c01 (diff) | |
download | gnunet-0c3dc8571333312dcfe3bf18e383ca85a1fc79b0.tar.gz gnunet-0c3dc8571333312dcfe3bf18e383ca85a1fc79b0.zip |
-more dht
-rw-r--r-- | src/gns/gnunet-service-gns.c | 112 |
1 files changed, 104 insertions, 8 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index c37ad2a56..c0a1317e9 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -141,6 +141,11 @@ const char* gnunet_tld = ".gnunet"; | |||
141 | static int num_public_records = 3600; | 141 | static int num_public_records = 3600; |
142 | struct GNUNET_TIME_Relative dht_update_interval; | 142 | struct GNUNET_TIME_Relative dht_update_interval; |
143 | 143 | ||
144 | |||
145 | void reply_to_dns(struct GNUNET_GNS_PendingQuery *answer); | ||
146 | void resolve_name(struct GNUNET_GNS_PendingQuery *query, | ||
147 | GNUNET_HashCode *zone); | ||
148 | |||
144 | /** | 149 | /** |
145 | * Task run during shutdown. | 150 | * Task run during shutdown. |
146 | * | 151 | * |
@@ -181,9 +186,88 @@ process_authority_dht_result(void* cls, | |||
181 | enum GNUNET_BLOCK_Type type, | 186 | enum GNUNET_BLOCK_Type type, |
182 | size_t size, const void *data) | 187 | size_t size, const void *data) |
183 | { | 188 | { |
189 | struct GNUNET_GNS_PendingQuery *query; | ||
190 | uint32_t num_records; | ||
191 | uint16_t namelen; | ||
192 | char* name = NULL; | ||
193 | struct GNUNET_CRYPTO_RsaSignature *signature; | ||
194 | int i; | ||
195 | char* pos; | ||
196 | GNUNET_HashCode zone, name_hash; | ||
197 | |||
184 | if (data == NULL) | 198 | if (data == NULL) |
185 | return; | 199 | return; |
200 | |||
201 | query = (struct GNUNET_GNS_PendingQuery *)cls; | ||
202 | pos = (char*)data; | ||
203 | |||
204 | num_records = ntohl(*pos); | ||
205 | struct GNUNET_NAMESTORE_RecordData rd[num_records]; | ||
206 | |||
207 | pos += sizeof(uint32_t); | ||
208 | |||
209 | for (i=0; i<num_records; i++) | ||
210 | { | ||
211 | namelen = ntohs(*pos); | ||
212 | pos += sizeof(uint16_t); | ||
213 | |||
214 | //name must be 0 terminated | ||
215 | name = pos; | ||
216 | pos += namelen; | ||
217 | |||
218 | rd[i].record_type = ntohl(*pos); | ||
219 | pos += sizeof(uint32_t); | ||
220 | |||
221 | rd[i].data_size = ntohl(*pos); | ||
222 | pos += sizeof(uint32_t); | ||
223 | |||
224 | rd[i].data = pos; | ||
225 | pos += rd[i].data_size; | ||
226 | |||
227 | rd[i].expiration = GNUNET_TIME_absolute_ntoh( | ||
228 | *((struct GNUNET_TIME_AbsoluteNBO*)pos)); | ||
229 | pos += sizeof(struct GNUNET_TIME_AbsoluteNBO); | ||
186 | 230 | ||
231 | rd[i].flags = ntohs(*pos); | ||
232 | pos += sizeof(uint16_t); | ||
233 | //FIXME class? | ||
234 | // | ||
235 | if (strcmp(name, query->name) && rd[i].record_type == query->type) | ||
236 | { | ||
237 | query->answered = 1; | ||
238 | } | ||
239 | |||
240 | } | ||
241 | |||
242 | if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature)) | ||
243 | { | ||
244 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
245 | "Cannot parse signature in DHT response. Corrupted or Missing"); | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | signature = (struct GNUNET_CRYPTO_RsaSignature*)pos; | ||
250 | |||
251 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); | ||
252 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); | ||
253 | |||
254 | //Save to namestore | ||
255 | GNUNET_NAMESTORE_record_put (namestore_handle, | ||
256 | &zone, | ||
257 | name, | ||
258 | exp, | ||
259 | num_records, | ||
260 | rd, | ||
261 | signature, | ||
262 | NULL, //cont | ||
263 | NULL); //cls | ||
264 | |||
265 | if (query->answered) | ||
266 | { | ||
267 | query->answered = 0; | ||
268 | memcpy(query->authority, &zone, sizeof(GNUNET_HashCode)); | ||
269 | resolve_name(query, query->authority); | ||
270 | } | ||
187 | /** | 271 | /** |
188 | * data is a serialized PKEY record (probably) | 272 | * data is a serialized PKEY record (probably) |
189 | * parse, put into namestore | 273 | * parse, put into namestore |
@@ -255,6 +339,7 @@ process_name_dht_result(void* cls, | |||
255 | enum GNUNET_BLOCK_Type type, | 339 | enum GNUNET_BLOCK_Type type, |
256 | size_t size, const void *data) | 340 | size_t size, const void *data) |
257 | { | 341 | { |
342 | struct GNUNET_GNS_PendingQuery *query; | ||
258 | uint32_t num_records; | 343 | uint32_t num_records; |
259 | uint16_t namelen; | 344 | uint16_t namelen; |
260 | char* name = NULL; | 345 | char* name = NULL; |
@@ -266,6 +351,7 @@ process_name_dht_result(void* cls, | |||
266 | if (data == NULL) | 351 | if (data == NULL) |
267 | return; | 352 | return; |
268 | 353 | ||
354 | query = (struct GNUNET_GNS_PendingQuery *)cls; | ||
269 | pos = (char*)data; | 355 | pos = (char*)data; |
270 | 356 | ||
271 | num_records = ntohl(*pos); | 357 | num_records = ntohl(*pos); |
@@ -298,6 +384,12 @@ process_name_dht_result(void* cls, | |||
298 | rd[i].flags = ntohs(*pos); | 384 | rd[i].flags = ntohs(*pos); |
299 | pos += sizeof(uint16_t); | 385 | pos += sizeof(uint16_t); |
300 | //FIXME class? | 386 | //FIXME class? |
387 | // | ||
388 | if (strcmp(name, query->name) && rd[i].record_type == query->type) | ||
389 | { | ||
390 | query->answered = 1; | ||
391 | } | ||
392 | |||
301 | } | 393 | } |
302 | 394 | ||
303 | if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature)) | 395 | if ((((char*)data)-pos) < sizeof(struct GNUNET_CRYPTO_RsaSignature)) |
@@ -322,6 +414,14 @@ process_name_dht_result(void* cls, | |||
322 | signature, | 414 | signature, |
323 | NULL, //cont | 415 | NULL, //cont |
324 | NULL); //cls | 416 | NULL); //cls |
417 | |||
418 | if (query->answered) | ||
419 | { | ||
420 | //FIXME: add records to query handle, but on stack! | ||
421 | //do we need records in query handle? can't we just | ||
422 | //pass them to reply_to_dns? | ||
423 | reply_to_dns(query); | ||
424 | } | ||
325 | 425 | ||
326 | /** | 426 | /** |
327 | * data is a serialized GNS record of type | 427 | * data is a serialized GNS record of type |
@@ -401,13 +501,6 @@ process_authority_lookup(void* cls, | |||
401 | */ | 501 | */ |
402 | if (rd_count == 0) | 502 | if (rd_count == 0) |
403 | { | 503 | { |
404 | if (query->authority_found) | ||
405 | { | ||
406 | query->authority_found = 0; | ||
407 | resolve_name(query, query->authority); | ||
408 | return; | ||
409 | } | ||
410 | |||
411 | /** | 504 | /** |
412 | * We did not find an authority in the namestore | 505 | * We did not find an authority in the namestore |
413 | * _IF_ the current authoritative zone is us we cannot resolve | 506 | * _IF_ the current authoritative zone is us we cannot resolve |
@@ -419,7 +512,10 @@ process_authority_lookup(void* cls, | |||
419 | //FIXME return NX answer | 512 | //FIXME return NX answer |
420 | return; | 513 | return; |
421 | } | 514 | } |
422 | 515 | ||
516 | /** | ||
517 | * Last hope | ||
518 | */ | ||
423 | resolve_authority_dht(query, name); | 519 | resolve_authority_dht(query, name); |
424 | return; | 520 | return; |
425 | } | 521 | } |