diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-01 12:35:16 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-01 12:35:16 +0000 |
commit | d6ca9464f42ffcb4c89bbc1c66c3cd2508da6393 (patch) | |
tree | df566020e6cd4341deb138754c702d022827192f /src/gns/gnunet-service-gns.c | |
parent | 206054928a4b151286d4af3eba3665b2b4d24155 (diff) | |
download | gnunet-d6ca9464f42ffcb4c89bbc1c66c3cd2508da6393.tar.gz gnunet-d6ca9464f42ffcb4c89bbc1c66c3cd2508da6393.zip |
-use common serialization, defines
Diffstat (limited to 'src/gns/gnunet-service-gns.c')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 315 |
1 files changed, 159 insertions, 156 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 7eaf603d9..8af37d489 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -39,7 +39,8 @@ | |||
39 | #include "block_gns.h" | 39 | #include "block_gns.h" |
40 | #include "gns.h" | 40 | #include "gns.h" |
41 | 41 | ||
42 | #define DHT_LOOKUP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 42 | #define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
43 | #define DHT_GNS_REPLICATION_LEVEL 5 | ||
43 | 44 | ||
44 | /* Ignore for now not used anyway and probably never will */ | 45 | /* Ignore for now not used anyway and probably never will */ |
45 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 | 46 | #define GNUNET_MESSAGE_TYPE_GNS_CLIENT_LOOKUP 23 |
@@ -138,9 +139,10 @@ struct GNUNET_TIME_Relative dht_update_interval; | |||
138 | GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; | 139 | GNUNET_SCHEDULER_TaskIdentifier zone_update_taskid = GNUNET_SCHEDULER_NO_TASK; |
139 | 140 | ||
140 | /* Prototypes */ | 141 | /* Prototypes */ |
141 | void reply_to_dns(struct GNUNET_GNS_ResolverHandle *answer, uint32_t rd_count, | 142 | static void reply_to_dns(struct GNUNET_GNS_ResolverHandle *answer, |
142 | const struct GNUNET_NAMESTORE_RecordData *rd); | 143 | uint32_t rd_count, |
143 | void resolve_name(struct GNUNET_GNS_ResolverHandle *rh); | 144 | const struct GNUNET_NAMESTORE_RecordData *rd); |
145 | static void resolve_name(struct GNUNET_GNS_ResolverHandle *rh); | ||
144 | 146 | ||
145 | /** | 147 | /** |
146 | * Task run during shutdown. | 148 | * Task run during shutdown. |
@@ -202,7 +204,7 @@ on_namestore_record_put_result(void *cls, | |||
202 | * @param size the size of the record | 204 | * @param size the size of the record |
203 | * @param data the record data | 205 | * @param data the record data |
204 | */ | 206 | */ |
205 | void | 207 | static void |
206 | process_authority_dht_result(void* cls, | 208 | process_authority_dht_result(void* cls, |
207 | struct GNUNET_TIME_Absolute exp, | 209 | struct GNUNET_TIME_Absolute exp, |
208 | const GNUNET_HashCode * key, | 210 | const GNUNET_HashCode * key, |
@@ -215,10 +217,11 @@ process_authority_dht_result(void* cls, | |||
215 | { | 217 | { |
216 | struct GNUNET_GNS_ResolverHandle *rh; | 218 | struct GNUNET_GNS_ResolverHandle *rh; |
217 | struct GNSNameRecordBlock *nrb; | 219 | struct GNSNameRecordBlock *nrb; |
218 | struct GNSRecordBlock *rb; | ||
219 | uint32_t num_records; | 220 | uint32_t num_records; |
220 | char* name = NULL; | 221 | char* name = NULL; |
222 | char* rd_data = (char*) data; | ||
221 | int i; | 223 | int i; |
224 | int rd_size; | ||
222 | GNUNET_HashCode zone, name_hash; | 225 | GNUNET_HashCode zone, name_hash; |
223 | 226 | ||
224 | if (data == NULL) | 227 | if (data == NULL) |
@@ -230,60 +233,70 @@ process_authority_dht_result(void* cls, | |||
230 | nrb = (struct GNSNameRecordBlock*)data; | 233 | nrb = (struct GNSNameRecordBlock*)data; |
231 | 234 | ||
232 | GNUNET_DHT_get_stop (rh->get_handle); | 235 | GNUNET_DHT_get_stop (rh->get_handle); |
236 | |||
233 | rh->get_handle = NULL; | 237 | rh->get_handle = NULL; |
234 | num_records = ntohl(nrb->rd_count); | 238 | num_records = ntohl(nrb->rd_count); |
235 | struct GNUNET_NAMESTORE_RecordData rd[num_records]; | ||
236 | name = (char*)&nrb[1]; | 239 | name = (char*)&nrb[1]; |
237 | rb = (struct GNSRecordBlock *)&name[strlen(name) + 1]; | ||
238 | |||
239 | for (i=0; i<num_records; i++) | ||
240 | { | 240 | { |
241 | 241 | struct GNUNET_NAMESTORE_RecordData rd[num_records]; | |
242 | rd[i].record_type = ntohl(rb->type); | ||
243 | rd[i].data_size = ntohl(rb->data_length); | ||
244 | rd[i].data = &rb[1]; | ||
245 | rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration); | ||
246 | rd[i].flags = ntohl(rb->flags); | ||
247 | 242 | ||
243 | rd_data += strlen(name) + sizeof(struct GNSNameRecordBlock); | ||
244 | rd_size = size - strlen(name) - sizeof(struct GNSNameRecordBlock); | ||
245 | |||
246 | if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, | ||
247 | rd_data, | ||
248 | num_records, | ||
249 | rd)) | ||
250 | { | ||
251 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error deserializing data!\n"); | ||
252 | return; | ||
253 | } | ||
254 | |||
248 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 255 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
249 | "Got name: %s (wanted %s)\n", name, rh->authority_name); | 256 | "Got name: %s (wanted %s)\n", name, rh->authority_name); |
250 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 257 | for (i=0; i<num_records; i++) |
251 | "Got type: %d raw %d (wanted %d)\n", | ||
252 | rd[i].record_type, rb->type, GNUNET_GNS_RECORD_PKEY); | ||
253 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
254 | "Got data length: %d\n", rd[i].data_size); | ||
255 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
256 | "Got flag %d\n", rd[i].flags); | ||
257 | |||
258 | if ((strcmp(name, rh->authority_name) == 0) && | ||
259 | (rd[i].record_type == GNUNET_GNS_RECORD_PKEY)) | ||
260 | { | 258 | { |
261 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Authority found in DHT\n"); | 259 | |
262 | rh->answered = 1; | 260 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
263 | GNUNET_CRYPTO_hash( | 261 | "Got name: %s (wanted %s)\n", name, rh->authority_name); |
264 | (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *)rd[i].data, | 262 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
265 | rd[i].data_size, | 263 | "Got type: %d (wanted %d)\n", |
266 | &rh->authority); | 264 | rd[i].record_type, GNUNET_GNS_RECORD_PKEY); |
265 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
266 | "Got data length: %d\n", rd[i].data_size); | ||
267 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
268 | "Got flag %d\n", rd[i].flags); | ||
269 | |||
270 | if ((strcmp(name, rh->authority_name) == 0) && | ||
271 | (rd[i].record_type == GNUNET_GNS_RECORD_PKEY)) | ||
272 | { | ||
273 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Authority found in DHT\n"); | ||
274 | rh->answered = 1; | ||
275 | GNUNET_CRYPTO_hash( | ||
276 | (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *)rd[i].data, | ||
277 | rd[i].data_size, | ||
278 | &rh->authority); | ||
279 | } | ||
280 | |||
267 | } | 281 | } |
268 | rb = (struct GNSRecordBlock*)((char*)&rb[1] + rd[i].data_size); | ||
269 | 282 | ||
270 | } | ||
271 | 283 | ||
272 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); | 284 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); |
273 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); | 285 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); |
274 | 286 | ||
275 | /* Save to namestore */ | 287 | /* Save to namestore */ |
276 | if (0 == GNUNET_CRYPTO_hash_cmp(&zone_hash, &zone)) | 288 | if (0 == GNUNET_CRYPTO_hash_cmp(&zone_hash, &zone)) |
277 | { | 289 | { |
278 | GNUNET_NAMESTORE_record_put (namestore_handle, | 290 | GNUNET_NAMESTORE_record_put (namestore_handle, |
279 | &nrb->public_key, | 291 | &nrb->public_key, |
280 | name, | 292 | name, |
281 | exp, | 293 | exp, |
282 | num_records, | 294 | num_records, |
283 | rd, | 295 | rd, |
284 | &nrb->signature, | 296 | &nrb->signature, |
285 | &on_namestore_record_put_result, //cont | 297 | &on_namestore_record_put_result, //cont |
286 | NULL); //cls | 298 | NULL); //cls |
299 | } | ||
287 | } | 300 | } |
288 | 301 | ||
289 | if (rh->answered) | 302 | if (rh->answered) |
@@ -303,11 +316,10 @@ process_authority_dht_result(void* cls, | |||
303 | * @param rh the pending gns query | 316 | * @param rh the pending gns query |
304 | * @param name the name of the PKEY record | 317 | * @param name the name of the PKEY record |
305 | */ | 318 | */ |
306 | void | 319 | static void |
307 | resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh) | 320 | resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh) |
308 | { | 321 | { |
309 | uint32_t xquery; | 322 | uint32_t xquery; |
310 | struct GNUNET_TIME_Relative timeout; | ||
311 | GNUNET_HashCode name_hash; | 323 | GNUNET_HashCode name_hash; |
312 | GNUNET_HashCode lookup_key; | 324 | GNUNET_HashCode lookup_key; |
313 | 325 | ||
@@ -316,14 +328,14 @@ resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh) | |||
316 | &name_hash); | 328 | &name_hash); |
317 | GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); | 329 | GNUNET_CRYPTO_hash_xor(&name_hash, &rh->authority, &lookup_key); |
318 | 330 | ||
319 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5); | ||
320 | 331 | ||
321 | xquery = htonl(GNUNET_GNS_RECORD_PKEY); | 332 | xquery = htonl(GNUNET_GNS_RECORD_PKEY); |
322 | //FIXME how long to wait for results? | 333 | //FIXME how long to wait for results? |
323 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, timeout, | 334 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
335 | DHT_OPERATION_TIMEOUT, | ||
324 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 336 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
325 | &lookup_key, | 337 | &lookup_key, |
326 | 5, //Replication level FIXME | 338 | DHT_GNS_REPLICATION_LEVEL, |
327 | GNUNET_DHT_RO_NONE, | 339 | GNUNET_DHT_RO_NONE, |
328 | &xquery, | 340 | &xquery, |
329 | sizeof(xquery), | 341 | sizeof(xquery), |
@@ -347,7 +359,7 @@ resolve_authority_dht(struct GNUNET_GNS_ResolverHandle *rh) | |||
347 | * @param size the size of the record | 359 | * @param size the size of the record |
348 | * @param data the record data | 360 | * @param data the record data |
349 | */ | 361 | */ |
350 | void | 362 | static void |
351 | process_name_dht_result(void* cls, | 363 | process_name_dht_result(void* cls, |
352 | struct GNUNET_TIME_Absolute exp, | 364 | struct GNUNET_TIME_Absolute exp, |
353 | const GNUNET_HashCode * key, | 365 | const GNUNET_HashCode * key, |
@@ -360,10 +372,12 @@ process_name_dht_result(void* cls, | |||
360 | { | 372 | { |
361 | struct GNUNET_GNS_ResolverHandle *rh; | 373 | struct GNUNET_GNS_ResolverHandle *rh; |
362 | struct GNSNameRecordBlock *nrb; | 374 | struct GNSNameRecordBlock *nrb; |
363 | struct GNSRecordBlock *rb; | ||
364 | uint32_t num_records; | 375 | uint32_t num_records; |
365 | char* name = NULL; | 376 | char* name = NULL; |
377 | char* rd_data = (char*)data; | ||
366 | int i; | 378 | int i; |
379 | int rd_size; | ||
380 | |||
367 | GNUNET_HashCode zone, name_hash; | 381 | GNUNET_HashCode zone, name_hash; |
368 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got dht result (size=%d)\n", size); | 382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "got dht result (size=%d)\n", size); |
369 | 383 | ||
@@ -376,65 +390,69 @@ process_name_dht_result(void* cls, | |||
376 | nrb = (struct GNSNameRecordBlock*)data; | 390 | nrb = (struct GNSNameRecordBlock*)data; |
377 | 391 | ||
378 | GNUNET_DHT_get_stop (rh->get_handle); | 392 | GNUNET_DHT_get_stop (rh->get_handle); |
393 | |||
379 | rh->get_handle = NULL; | 394 | rh->get_handle = NULL; |
395 | name = (char*)&nrb[1]; | ||
380 | num_records = ntohl(nrb->rd_count); | 396 | num_records = ntohl(nrb->rd_count); |
381 | struct GNUNET_NAMESTORE_RecordData rd[num_records]; | 397 | { |
398 | struct GNUNET_NAMESTORE_RecordData rd[num_records]; | ||
382 | 399 | ||
383 | name = (char*)&nrb[1]; | 400 | rd_data += strlen(name) + sizeof(struct GNSNameRecordBlock); |
384 | rb = (struct GNSRecordBlock*)&name[strlen(name) + 1]; | 401 | rd_size = size - strlen(name) - sizeof(struct GNSNameRecordBlock); |
385 | 402 | ||
386 | for (i=0; i<num_records; i++) | 403 | if (GNUNET_SYSERR == GNUNET_NAMESTORE_records_deserialize (rd_size, |
387 | { | 404 | rd_data, |
388 | rd[i].record_type = ntohl(rb->type); | 405 | num_records, |
389 | rd[i].data_size = ntohl(rb->data_length); | 406 | rd)) |
390 | rd[i].data = (char*)&rb[1]; | 407 | { |
391 | rd[i].expiration = GNUNET_TIME_absolute_ntoh(rb->expiration); | 408 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error deserializing data!\n"); |
392 | rd[i].flags = ntohl(rb->flags); | 409 | return; |
393 | 410 | } | |
394 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 411 | |
412 | for (i=0; i<num_records; i++) | ||
413 | { | ||
414 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
395 | "Got name: %s (wanted %s)\n", name, rh->name); | 415 | "Got name: %s (wanted %s)\n", name, rh->name); |
396 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 416 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
397 | "Got type: %d raw %d (wanted %d)\n", | 417 | "Got type: %d (wanted %d)\n", |
398 | rd[i].record_type, rb->type, rh->query->type); | 418 | rd[i].record_type, rh->query->type); |
399 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 419 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
400 | "Got data length: %d\n", rd[i].data_size); | 420 | "Got data length: %d\n", rd[i].data_size); |
401 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 421 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
402 | "Got flag %d\n", rd[i].flags); | 422 | "Got flag %d\n", rd[i].flags); |
403 | 423 | ||
404 | /* FIXME class? */ | 424 | if ((strcmp(name, rh->name) == 0) && |
405 | if ((strcmp(name, rh->name) == 0) && | 425 | (rd[i].record_type == rh->query->type)) |
406 | (rd[i].record_type == rh->query->type)) | 426 | { |
407 | { | 427 | rh->answered++; |
408 | rh->answered++; | 428 | } |
409 | } | ||
410 | |||
411 | rb = (struct GNSRecordBlock*)((char*)&rb[1] + rd[i].data_size); | ||
412 | 429 | ||
413 | } | 430 | } |
414 | 431 | ||
415 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); | 432 | GNUNET_CRYPTO_hash(name, strlen(name), &name_hash); |
416 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); | 433 | GNUNET_CRYPTO_hash_xor(key, &name_hash, &zone); |
417 | 434 | ||
418 | /** | 435 | /** |
419 | * FIXME check pubkey against existing key in namestore? | 436 | * FIXME check pubkey against existing key in namestore? |
420 | * https://gnunet.org/bugs/view.php?id=2179 | 437 | * https://gnunet.org/bugs/view.php?id=2179 |
421 | */ | 438 | */ |
422 | 439 | ||
423 | /* Save to namestore */ | 440 | /* Save to namestore */ |
424 | GNUNET_NAMESTORE_record_put (namestore_handle, | 441 | GNUNET_NAMESTORE_record_put (namestore_handle, |
425 | &nrb->public_key, | 442 | &nrb->public_key, |
426 | name, | 443 | name, |
427 | exp, | 444 | exp, |
428 | num_records, | 445 | num_records, |
429 | rd, | 446 | rd, |
430 | &nrb->signature, | 447 | &nrb->signature, |
431 | &on_namestore_record_put_result, //cont | 448 | &on_namestore_record_put_result, //cont |
432 | NULL); //cls | 449 | NULL); //cls |
433 | 450 | ||
434 | if (rh->answered) | 451 | if (rh->answered) |
435 | reply_to_dns(rh, num_records, rd); | 452 | reply_to_dns(rh, num_records, rd); |
436 | else | 453 | else |
437 | reply_to_dns(rh, 0, NULL); | 454 | reply_to_dns(rh, 0, NULL); |
455 | } | ||
438 | 456 | ||
439 | } | 457 | } |
440 | 458 | ||
@@ -464,10 +482,10 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) | |||
464 | xquery = htonl(rh->query->type); | 482 | xquery = htonl(rh->query->type); |
465 | //FIXME how long to wait for results? | 483 | //FIXME how long to wait for results? |
466 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, | 484 | rh->get_handle = GNUNET_DHT_get_start(dht_handle, |
467 | DHT_LOOKUP_TIMEOUT, | 485 | DHT_OPERATION_TIMEOUT, |
468 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 486 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
469 | &lookup_key, | 487 | &lookup_key, |
470 | 5, //Replication level FIXME | 488 | DHT_GNS_REPLICATION_LEVEL, |
471 | GNUNET_DHT_RO_NONE, | 489 | GNUNET_DHT_RO_NONE, |
472 | &xquery, | 490 | &xquery, |
473 | sizeof(xquery), | 491 | sizeof(xquery), |
@@ -477,7 +495,7 @@ resolve_name_dht(struct GNUNET_GNS_ResolverHandle *rh, const char* name) | |||
477 | } | 495 | } |
478 | 496 | ||
479 | //Prototype | 497 | //Prototype |
480 | void | 498 | static void |
481 | resolve_name(struct GNUNET_GNS_ResolverHandle *rh); | 499 | resolve_name(struct GNUNET_GNS_ResolverHandle *rh); |
482 | 500 | ||
483 | /** | 501 | /** |
@@ -493,7 +511,7 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *rh); | |||
493 | * @param rd the record data | 511 | * @param rd the record data |
494 | * @param signature the signature of the authority for the record data | 512 | * @param signature the signature of the authority for the record data |
495 | */ | 513 | */ |
496 | void | 514 | static void |
497 | process_authority_lookup(void* cls, | 515 | process_authority_lookup(void* cls, |
498 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, | 516 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, |
499 | struct GNUNET_TIME_Absolute expiration, | 517 | struct GNUNET_TIME_Absolute expiration, |
@@ -588,7 +606,7 @@ process_authority_lookup(void* cls, | |||
588 | * @param rd_count the number of records to return | 606 | * @param rd_count the number of records to return |
589 | * @param rd the record data | 607 | * @param rd the record data |
590 | */ | 608 | */ |
591 | void | 609 | static void |
592 | reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count, | 610 | reply_to_dns(struct GNUNET_GNS_ResolverHandle *rh, uint32_t rd_count, |
593 | const struct GNUNET_NAMESTORE_RecordData *rd) | 611 | const struct GNUNET_NAMESTORE_RecordData *rd) |
594 | { | 612 | { |
@@ -804,7 +822,7 @@ process_authoritative_result(void* cls, | |||
804 | * @param name the name to test | 822 | * @param name the name to test |
805 | * @return 1 if canonical | 823 | * @return 1 if canonical |
806 | */ | 824 | */ |
807 | int | 825 | static int |
808 | is_canonical(char* name) | 826 | is_canonical(char* name) |
809 | { | 827 | { |
810 | uint32_t len = strlen(name); | 828 | uint32_t len = strlen(name); |
@@ -825,7 +843,8 @@ is_canonical(char* name) | |||
825 | * @param name the domain | 843 | * @param name the domain |
826 | * @return the tld | 844 | * @return the tld |
827 | */ | 845 | */ |
828 | char* pop_tld(char* name) | 846 | static char* |
847 | pop_tld(char* name) | ||
829 | { | 848 | { |
830 | uint32_t len; | 849 | uint32_t len; |
831 | 850 | ||
@@ -855,7 +874,7 @@ char* pop_tld(char* name) | |||
855 | * | 874 | * |
856 | * @param rh the pending lookup | 875 | * @param rh the pending lookup |
857 | */ | 876 | */ |
858 | void | 877 | static void |
859 | resolve_name(struct GNUNET_GNS_ResolverHandle *rh) | 878 | resolve_name(struct GNUNET_GNS_ResolverHandle *rh) |
860 | { | 879 | { |
861 | if (is_canonical(rh->name)) | 880 | if (is_canonical(rh->name)) |
@@ -889,7 +908,7 @@ resolve_name(struct GNUNET_GNS_ResolverHandle *rh) | |||
889 | * @param p the DNS query packet we received | 908 | * @param p the DNS query packet we received |
890 | * @param q the DNS query we received parsed from p | 909 | * @param q the DNS query we received parsed from p |
891 | */ | 910 | */ |
892 | void | 911 | static void |
893 | start_resolution(struct GNUNET_DNS_RequestHandle *request, | 912 | start_resolution(struct GNUNET_DNS_RequestHandle *request, |
894 | struct GNUNET_DNSPARSER_Packet *p, | 913 | struct GNUNET_DNSPARSER_Packet *p, |
895 | struct GNUNET_DNSPARSER_Query *q) | 914 | struct GNUNET_DNSPARSER_Query *q) |
@@ -926,7 +945,7 @@ start_resolution(struct GNUNET_DNS_RequestHandle *request, | |||
926 | * @param request_length number of bytes in request | 945 | * @param request_length number of bytes in request |
927 | * @param request udp payload of the DNS request | 946 | * @param request udp payload of the DNS request |
928 | */ | 947 | */ |
929 | void | 948 | static void |
930 | handle_dns_request(void *cls, | 949 | handle_dns_request(void *cls, |
931 | struct GNUNET_DNS_RequestHandle *rh, | 950 | struct GNUNET_DNS_RequestHandle *rh, |
932 | size_t request_length, | 951 | size_t request_length, |
@@ -1002,7 +1021,7 @@ handle_dns_request(void *cls, | |||
1002 | * This will also be replaced by a test progrm that | 1021 | * This will also be replaced by a test progrm that |
1003 | * directl interfaces with the namestore | 1022 | * directl interfaces with the namestore |
1004 | */ | 1023 | */ |
1005 | void | 1024 | static void |
1006 | put_some_records(void) | 1025 | put_some_records(void) |
1007 | { | 1026 | { |
1008 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Populating namestore\n"); | 1027 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Populating namestore\n"); |
@@ -1034,7 +1053,7 @@ put_some_records(void) | |||
1034 | * @param cls closure | 1053 | * @param cls closure |
1035 | * @param tc task context | 1054 | * @param tc task context |
1036 | */ | 1055 | */ |
1037 | void | 1056 | static void |
1038 | update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1057 | update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1039 | { | 1058 | { |
1040 | GNUNET_NAMESTORE_zone_iterator_next(namestore_iter); | 1059 | GNUNET_NAMESTORE_zone_iterator_next(namestore_iter); |
@@ -1046,7 +1065,7 @@ update_zone_dht_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1046 | * @param cls closure | 1065 | * @param cls closure |
1047 | * @param tc task context | 1066 | * @param tc task context |
1048 | */ | 1067 | */ |
1049 | void | 1068 | static void |
1050 | record_dht_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1069 | record_dht_put(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1051 | { | 1070 | { |
1052 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n"); | 1071 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "put request transmitted\n"); |
@@ -1058,7 +1077,6 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
1058 | 1077 | ||
1059 | /** | 1078 | /** |
1060 | * Function used to put all records successively into the DHT. | 1079 | * Function used to put all records successively into the DHT. |
1061 | * FIXME bug here | ||
1062 | * | 1080 | * |
1063 | * @param cls the closure (NULL) | 1081 | * @param cls the closure (NULL) |
1064 | * @param key the public key of the authority (ours) | 1082 | * @param key the public key of the authority (ours) |
@@ -1068,7 +1086,7 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
1068 | * @param rd the record data | 1086 | * @param rd the record data |
1069 | * @param signature the signature for the record data | 1087 | * @param signature the signature for the record data |
1070 | */ | 1088 | */ |
1071 | void | 1089 | static void |
1072 | put_gns_record(void *cls, | 1090 | put_gns_record(void *cls, |
1073 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, | 1091 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *key, |
1074 | struct GNUNET_TIME_Absolute expiration, | 1092 | struct GNUNET_TIME_Absolute expiration, |
@@ -1077,16 +1095,13 @@ put_gns_record(void *cls, | |||
1077 | const struct GNUNET_NAMESTORE_RecordData *rd, | 1095 | const struct GNUNET_NAMESTORE_RecordData *rd, |
1078 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 1096 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
1079 | { | 1097 | { |
1080 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1098 | |
1081 | "Putting records for %s into the DHT\n", name); | ||
1082 | struct GNUNET_TIME_Relative timeout; | ||
1083 | struct GNSNameRecordBlock *nrb; | 1099 | struct GNSNameRecordBlock *nrb; |
1084 | struct GNSRecordBlock *rb; | ||
1085 | GNUNET_HashCode name_hash; | 1100 | GNUNET_HashCode name_hash; |
1086 | GNUNET_HashCode xor_hash; | 1101 | GNUNET_HashCode xor_hash; |
1087 | struct GNUNET_CRYPTO_HashAsciiEncoded xor_hash_string; | 1102 | struct GNUNET_CRYPTO_HashAsciiEncoded xor_hash_string; |
1088 | int i; | ||
1089 | uint32_t rd_payload_length; | 1103 | uint32_t rd_payload_length; |
1104 | char* nrb_data = NULL; | ||
1090 | 1105 | ||
1091 | /* we're done */ | 1106 | /* we're done */ |
1092 | if (NULL == name) | 1107 | if (NULL == name) |
@@ -1098,48 +1113,36 @@ put_gns_record(void *cls, | |||
1098 | return; | 1113 | return; |
1099 | } | 1114 | } |
1100 | 1115 | ||
1101 | rd_payload_length = rd_count * sizeof(struct GNSRecordBlock); | 1116 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1102 | rd_payload_length += strlen(name) + 1 + sizeof(struct GNSNameRecordBlock); | 1117 | "Putting records for %s into the DHT\n", name); |
1103 | 1118 | ||
1104 | /* calculate payload size */ | 1119 | rd_payload_length = GNUNET_NAMESTORE_records_get_size (rd_count, rd); |
1105 | for (i=0; i<rd_count; i++) | ||
1106 | { | ||
1107 | rd_payload_length += rd[i].data_size; | ||
1108 | } | ||
1109 | 1120 | ||
1110 | nrb = GNUNET_malloc(rd_payload_length); | 1121 | nrb = GNUNET_malloc(rd_payload_length + strlen(name) + 1 |
1122 | + sizeof(struct GNSNameRecordBlock)); | ||
1111 | 1123 | ||
1112 | if (signature != NULL) | 1124 | if (signature != NULL) |
1113 | memcpy(&nrb->signature, signature, | 1125 | nrb->signature = *signature; |
1114 | sizeof(struct GNUNET_CRYPTO_RsaSignature)); | 1126 | |
1115 | //FIXME signature purpose | 1127 | nrb->public_key = *key; |
1116 | memcpy(&nrb->public_key, key, | ||
1117 | sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
1118 | 1128 | ||
1119 | nrb->rd_count = htonl(rd_count); | 1129 | nrb->rd_count = htonl(rd_count); |
1130 | |||
1131 | memset(&nrb[1], 0, strlen(name) + 1); | ||
1132 | memcpy(&nrb[1], name, strlen(name)); | ||
1120 | 1133 | ||
1121 | memcpy(&nrb[1], name, strlen(name) + 1); //FIXME is this 0 terminated?? | 1134 | nrb_data = (char*)&nrb[1]; |
1122 | 1135 | nrb_data += strlen(name) + 1; | |
1123 | rb = (struct GNSRecordBlock *)((char*)&nrb[1] + strlen(name) + 1); | ||
1124 | 1136 | ||
1125 | for (i=0; i<rd_count; i++) | 1137 | if (-1 == GNUNET_NAMESTORE_records_serialize (rd_count, |
1138 | rd, | ||
1139 | rd_payload_length, | ||
1140 | nrb_data)) | ||
1126 | { | 1141 | { |
1127 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Read record with type %d\n", | 1142 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Recor serialization failed!\n"); |
1128 | rd[i].record_type); | ||
1129 | rb->type = htonl(rd[i].record_type); | ||
1130 | rb->expiration = GNUNET_TIME_absolute_hton(rd[i].expiration); | ||
1131 | rb->data_length = htonl(rd[i].data_size); | ||
1132 | rb->flags = htonl(rd[i].flags); | ||
1133 | memcpy(&rb[1], rd[i].data, rd[i].data_size); | ||
1134 | rb = &rb[1] + rd[i].data_size; | ||
1135 | } | 1143 | } |
1136 | 1144 | ||
1137 | /** | 1145 | |
1138 | * FIXME magic number 20 move to config file | ||
1139 | * DHT_WAIT_TIMEOUT | ||
1140 | */ | ||
1141 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); | ||
1142 | |||
1143 | /* | 1146 | /* |
1144 | * calculate DHT key: H(name) xor H(pubkey) | 1147 | * calculate DHT key: H(name) xor H(pubkey) |
1145 | */ | 1148 | */ |
@@ -1151,13 +1154,13 @@ put_gns_record(void *cls, | |||
1151 | name, (char*)&xor_hash_string, rd_payload_length); | 1154 | name, (char*)&xor_hash_string, rd_payload_length); |
1152 | 1155 | ||
1153 | GNUNET_DHT_put (dht_handle, &xor_hash, | 1156 | GNUNET_DHT_put (dht_handle, &xor_hash, |
1154 | 5, //replication level | 1157 | DHT_GNS_REPLICATION_LEVEL, |
1155 | GNUNET_DHT_RO_NONE, | 1158 | GNUNET_DHT_RO_NONE, |
1156 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, //FIXME todo block plugin | 1159 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
1157 | rd_payload_length, | 1160 | rd_payload_length, |
1158 | (char*)nrb, | 1161 | (char*)nrb, |
1159 | expiration, | 1162 | expiration, |
1160 | timeout, | 1163 | DHT_OPERATION_TIMEOUT, |
1161 | &record_dht_put, //FIXME continuation needed? success check? yes ofc | 1164 | &record_dht_put, //FIXME continuation needed? success check? yes ofc |
1162 | NULL); //cls for cont | 1165 | NULL); //cls for cont |
1163 | 1166 | ||
@@ -1181,7 +1184,7 @@ put_gns_record(void *cls, | |||
1181 | * @param name name of entity | 1184 | * @param name name of entity |
1182 | * @param keyfile keyfile | 1185 | * @param keyfile keyfile |
1183 | */ | 1186 | */ |
1184 | void | 1187 | static void |
1185 | put_trusted(char* name, char* keyfile) | 1188 | put_trusted(char* name, char* keyfile) |
1186 | { | 1189 | { |
1187 | struct GNUNET_NAMESTORE_RecordData rd; | 1190 | struct GNUNET_NAMESTORE_RecordData rd; |