diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-10-07 09:43:32 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-10-07 09:43:32 +0000 |
commit | b37e89b590b30cb4f650375807d60e1748930ba4 (patch) | |
tree | 7ec836c685f90d900241253780ffc21fa7bb23a0 /src | |
parent | 014c0a8f67696d36bf27af70537a6a71abaa1653 (diff) | |
download | gnunet-b37e89b590b30cb4f650375807d60e1748930ba4.tar.gz gnunet-b37e89b590b30cb4f650375807d60e1748930ba4.zip |
-add reverse autoadd; with test
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/gnunet-service-gns.c | 57 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_reverser.c | 250 | ||||
-rw-r--r-- | src/gns/gnunet-service-gns_reverser.h | 19 | ||||
-rwxr-xr-x | src/gns/test_gns_reverse_lookup.sh | 16 |
4 files changed, 286 insertions, 56 deletions
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c index 221d75bba..3e718dac8 100644 --- a/src/gns/gnunet-service-gns.c +++ b/src/gns/gnunet-service-gns.c | |||
@@ -301,6 +301,7 @@ shutdown_task (void *cls) | |||
301 | identity_handle = NULL; | 301 | identity_handle = NULL; |
302 | } | 302 | } |
303 | GNS_resolver_done (); | 303 | GNS_resolver_done (); |
304 | GNS_reverse_done (); | ||
304 | GNS_shorten_done (); | 305 | GNS_shorten_done (); |
305 | while (NULL != (ma = ma_head)) | 306 | while (NULL != (ma = ma_head)) |
306 | { | 307 | { |
@@ -1061,6 +1062,51 @@ handle_monitor_error (void *cls) | |||
1061 | NULL); | 1062 | NULL); |
1062 | } | 1063 | } |
1063 | 1064 | ||
1065 | /** | ||
1066 | * Method called to inform about the ego to be used for the master zone | ||
1067 | * for DNS interceptions. | ||
1068 | * | ||
1069 | * This function is only called ONCE, and 'NULL' being passed in | ||
1070 | * @a ego does indicate that interception is not configured. | ||
1071 | * If @a ego is non-NULL, we should start to intercept DNS queries | ||
1072 | * and resolve ".gnu" queries using the given ego as the master zone. | ||
1073 | * | ||
1074 | * @param cls closure, our `const struct GNUNET_CONFIGURATION_Handle *c` | ||
1075 | * @param ego ego handle | ||
1076 | * @param ctx context for application to store data for this ego | ||
1077 | * (during the lifetime of this process, initially NULL) | ||
1078 | * @param name name assigned by the user for this ego, | ||
1079 | * NULL if the user just deleted the ego and it | ||
1080 | * must thus no longer be used | ||
1081 | */ | ||
1082 | static void | ||
1083 | identity_reverse_cb (void *cls, | ||
1084 | struct GNUNET_IDENTITY_Ego *ego, | ||
1085 | void **ctx, | ||
1086 | const char *name) | ||
1087 | { | ||
1088 | identity_op = NULL; | ||
1089 | |||
1090 | if (NULL == ego) | ||
1091 | { | ||
1092 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1093 | _("No ego configured for `%s`\n"), | ||
1094 | "gns-master"); | ||
1095 | |||
1096 | return; | ||
1097 | } | ||
1098 | if (GNUNET_SYSERR == | ||
1099 | GNS_reverse_init (namestore_handle, | ||
1100 | GNUNET_IDENTITY_ego_get_private_key (ego), | ||
1101 | name)) | ||
1102 | { | ||
1103 | GNUNET_break (0); | ||
1104 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
1105 | return; | ||
1106 | } | ||
1107 | } | ||
1108 | |||
1109 | |||
1064 | 1110 | ||
1065 | /** | 1111 | /** |
1066 | * Method called to inform about the ego to be used for the master zone | 1112 | * Method called to inform about the ego to be used for the master zone |
@@ -1087,13 +1133,22 @@ identity_intercept_cb (void *cls, | |||
1087 | { | 1133 | { |
1088 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1134 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1089 | struct GNUNET_CRYPTO_EcdsaPublicKey dns_root; | 1135 | struct GNUNET_CRYPTO_EcdsaPublicKey dns_root; |
1090 | |||
1091 | identity_op = NULL; | 1136 | identity_op = NULL; |
1137 | |||
1138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1139 | "Looking for gns-intercept ego\n"); | ||
1140 | identity_op = GNUNET_IDENTITY_get (identity_handle, | ||
1141 | "gns-reverse", | ||
1142 | &identity_reverse_cb, | ||
1143 | (void*)cfg); | ||
1144 | |||
1145 | |||
1092 | if (NULL == ego) | 1146 | if (NULL == ego) |
1093 | { | 1147 | { |
1094 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1095 | _("No ego configured for `%s`\n"), | 1149 | _("No ego configured for `%s`\n"), |
1096 | "gns-intercept"); | 1150 | "gns-intercept"); |
1151 | |||
1097 | return; | 1152 | return; |
1098 | } | 1153 | } |
1099 | GNUNET_IDENTITY_ego_get_public_key (ego, | 1154 | GNUNET_IDENTITY_ego_get_public_key (ego, |
diff --git a/src/gns/gnunet-service-gns_reverser.c b/src/gns/gnunet-service-gns_reverser.c index 2e66e7fa6..28c4f4e4d 100644 --- a/src/gns/gnunet-service-gns_reverser.c +++ b/src/gns/gnunet-service-gns_reverser.c | |||
@@ -46,6 +46,11 @@ struct ReverseRecordEntry | |||
46 | */ | 46 | */ |
47 | struct GNUNET_GNSRECORD_ReverseRecord *record; | 47 | struct GNUNET_GNSRECORD_ReverseRecord *record; |
48 | 48 | ||
49 | /** | ||
50 | * Record length | ||
51 | */ | ||
52 | size_t record_len; | ||
53 | |||
49 | }; | 54 | }; |
50 | 55 | ||
51 | struct IteratorHandle | 56 | struct IteratorHandle |
@@ -61,19 +66,19 @@ struct IteratorHandle | |||
61 | struct ReverseRecordEntry *records_tail; | 66 | struct ReverseRecordEntry *records_tail; |
62 | 67 | ||
63 | /** | 68 | /** |
64 | * Current delegation to expect | 69 | * Record count |
65 | */ | 70 | */ |
66 | struct GNUNET_CRYPTO_EcdsaPublicKey target; | 71 | uint64_t record_count; |
67 | 72 | ||
68 | /** | 73 | /** |
69 | * The zone target for reverse record resolution | 74 | * Current delegation to expect |
70 | */ | 75 | */ |
71 | struct GNUNET_CRYPTO_EcdsaPublicKey myzone; | 76 | struct GNUNET_CRYPTO_EcdsaPublicKey target; |
72 | 77 | ||
73 | /** | 78 | /** |
74 | * The nick of our zone | 79 | * Queue entry |
75 | */ | 80 | */ |
76 | char *mynick; | 81 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; |
77 | 82 | ||
78 | }; | 83 | }; |
79 | 84 | ||
@@ -151,6 +156,11 @@ struct GNS_ReverserHandle | |||
151 | static struct GNUNET_SCHEDULER_Task *reverse_record_check_task; | 156 | static struct GNUNET_SCHEDULER_Task *reverse_record_check_task; |
152 | 157 | ||
153 | /** | 158 | /** |
159 | * NS iterator task | ||
160 | */ | ||
161 | static struct GNUNET_SCHEDULER_Task *it_task; | ||
162 | |||
163 | /** | ||
154 | * GNS lookup handle | 164 | * GNS lookup handle |
155 | */ | 165 | */ |
156 | static struct GNS_ResolverHandle *gns_lookup_reverse; | 166 | static struct GNS_ResolverHandle *gns_lookup_reverse; |
@@ -165,7 +175,23 @@ static struct GNUNET_NAMESTORE_Handle *ns; | |||
165 | */ | 175 | */ |
166 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; | 176 | static struct GNUNET_NAMESTORE_ZoneIterator *namestore_iter; |
167 | 177 | ||
168 | void | 178 | /** |
179 | * The zone target for reverse record resolution | ||
180 | */ | ||
181 | static struct GNUNET_CRYPTO_EcdsaPublicKey myzone; | ||
182 | |||
183 | /** | ||
184 | * The zone target for reverse record resolution | ||
185 | */ | ||
186 | static struct GNUNET_CRYPTO_EcdsaPrivateKey pzone; | ||
187 | |||
188 | /** | ||
189 | * The nick of our zone | ||
190 | */ | ||
191 | static char *mynick; | ||
192 | |||
193 | |||
194 | static void | ||
169 | cleanup_handle (struct GNS_ReverserHandle *rh) | 195 | cleanup_handle (struct GNS_ReverserHandle *rh) |
170 | { | 196 | { |
171 | struct ReverseTreeNode *rtn; | 197 | struct ReverseTreeNode *rtn; |
@@ -174,14 +200,15 @@ cleanup_handle (struct GNS_ReverserHandle *rh) | |||
174 | { | 200 | { |
175 | if (NULL != rtn->name) | 201 | if (NULL != rtn->name) |
176 | GNUNET_free (rtn->name); | 202 | GNUNET_free (rtn->name); |
177 | GNUNET_CONTAINER_DLL_remove (rh->node_queue_head, | 203 | GNUNET_CONTAINER_DLL_remove (rh->node_queue_head, |
178 | rh->node_queue_tail, | 204 | rh->node_queue_tail, |
179 | rtn); | 205 | rtn); |
180 | GNUNET_free (rtn); | 206 | GNUNET_free (rtn); |
181 | } | 207 | } |
208 | GNUNET_free (rh); | ||
182 | } | 209 | } |
183 | 210 | ||
184 | void | 211 | static void |
185 | handle_gns_result (void *cls, | 212 | handle_gns_result (void *cls, |
186 | uint32_t rd_count, | 213 | uint32_t rd_count, |
187 | const struct GNUNET_GNSRECORD_Data *rd) | 214 | const struct GNUNET_GNSRECORD_Data *rd) |
@@ -245,9 +272,10 @@ handle_gns_result (void *cls, | |||
245 | * Done here remove node from queue | 272 | * Done here remove node from queue |
246 | */ | 273 | */ |
247 | rtn = rh->node_queue_head; | 274 | rtn = rh->node_queue_head; |
248 | GNUNET_CONTAINER_DLL_remove (rh->node_queue_head, | 275 | if (NULL != rtn) |
249 | rh->node_queue_tail, | 276 | GNUNET_CONTAINER_DLL_remove (rh->node_queue_head, |
250 | rtn); | 277 | rh->node_queue_tail, |
278 | rtn); | ||
251 | if (NULL == rh->node_queue_head) | 279 | if (NULL == rh->node_queue_head) |
252 | { | 280 | { |
253 | //No luck | 281 | //No luck |
@@ -264,6 +292,16 @@ handle_gns_result (void *cls, | |||
264 | rh); | 292 | rh); |
265 | } | 293 | } |
266 | 294 | ||
295 | /** | ||
296 | * Reverse lookup of a specific zone | ||
297 | * calls RecordLookupProcessor on result or timeout | ||
298 | * | ||
299 | * @param target the zone to perform the lookup in | ||
300 | * @param authority the authority | ||
301 | * @param proc the processor to call | ||
302 | * @param proc_cls the closure to pass to @a proc | ||
303 | * @return handle to cancel operation | ||
304 | */ | ||
267 | struct GNS_ReverserHandle * | 305 | struct GNS_ReverserHandle * |
268 | GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target, | 306 | GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target, |
269 | const struct GNUNET_CRYPTO_EcdsaPublicKey *authority, | 307 | const struct GNUNET_CRYPTO_EcdsaPublicKey *authority, |
@@ -309,47 +347,62 @@ GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh) | |||
309 | return; | 347 | return; |
310 | } | 348 | } |
311 | 349 | ||
312 | void | 350 | /******************************************** |
351 | * Reverse iterator | ||
352 | * ******************************************/ | ||
353 | |||
354 | |||
355 | static void | ||
313 | next_it (void *cls); | 356 | next_it (void *cls); |
314 | 357 | ||
315 | void | 358 | static void |
316 | handle_gns_result_iter (void *cls, | 359 | handle_gns_result_iter (void *cls, |
317 | uint32_t rd_count, | 360 | uint32_t rd_count, |
318 | const struct GNUNET_GNSRECORD_Data *rd) | 361 | const struct GNUNET_GNSRECORD_Data *rd) |
319 | { | 362 | { |
320 | struct IteratorHandle *ith = cls; | 363 | struct IteratorHandle *ith = cls; |
321 | struct ReverseRecordEntry *rr; | 364 | struct ReverseRecordEntry *rr; |
365 | gns_lookup_reverse = NULL; | ||
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
367 | "GNS for REVERSE (%s)\n", mynick); | ||
368 | |||
369 | |||
322 | if ((rd_count != 1) || | 370 | if ((rd_count != 1) || |
323 | (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)) | 371 | (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)) |
324 | { | 372 | { |
373 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
374 | "GNS invalid REVERSE (%s)\n", mynick); | ||
325 | gns_lookup_reverse = NULL; | 375 | gns_lookup_reverse = NULL; |
326 | GNUNET_SCHEDULER_add_now (&next_it, NULL); | 376 | it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); |
327 | return; | 377 | return; |
328 | } | 378 | } |
329 | 379 | ||
330 | 380 | ||
331 | rr = GNUNET_new (struct ReverseRecordEntry); | 381 | rr = GNUNET_new (struct ReverseRecordEntry); |
332 | rr->record = GNUNET_malloc (sizeof (struct GNUNET_GNSRECORD_ReverseRecord) | 382 | rr->record_len = sizeof (struct GNUNET_GNSRECORD_ReverseRecord) |
333 | + strlen (ith->mynick) + 1); | 383 | + strlen (mynick) + 1; |
384 | rr->record = GNUNET_malloc (rr->record_len); | ||
334 | rr->record->pkey = ith->target; | 385 | rr->record->pkey = ith->target; |
335 | rr->record->expiration.abs_value_us = rd->expiration_time; | 386 | rr->record->expiration.abs_value_us = rd->expiration_time; |
336 | GNUNET_memcpy ((char*)&rr->record[1], | 387 | GNUNET_memcpy ((char*)&rr->record[1], |
337 | ith->mynick, | 388 | mynick, |
338 | strlen (ith->mynick)); | 389 | strlen (mynick)); |
339 | GNUNET_CONTAINER_DLL_insert (ith->records_head, | 390 | GNUNET_CONTAINER_DLL_insert (ith->records_head, |
340 | ith->records_tail, | 391 | ith->records_tail, |
341 | rr); | 392 | rr); |
342 | GNUNET_SCHEDULER_add_now (&next_it, NULL); | 393 | ith->record_count++; |
394 | it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); | ||
343 | } | 395 | } |
344 | 396 | ||
345 | void | 397 | static void |
346 | next_it (void *cls) | 398 | next_it (void *cls) |
347 | { | 399 | { |
400 | it_task = NULL; | ||
348 | GNUNET_assert (NULL != namestore_iter); | 401 | GNUNET_assert (NULL != namestore_iter); |
349 | GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); | 402 | GNUNET_NAMESTORE_zone_iterator_next (namestore_iter); |
350 | } | 403 | } |
351 | 404 | ||
352 | void | 405 | static void |
353 | iterator_cb (void *cls, | 406 | iterator_cb (void *cls, |
354 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 407 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, |
355 | const char *label, | 408 | const char *label, |
@@ -357,42 +410,68 @@ iterator_cb (void *cls, | |||
357 | const struct GNUNET_GNSRECORD_Data *rd) | 410 | const struct GNUNET_GNSRECORD_Data *rd) |
358 | { | 411 | { |
359 | struct IteratorHandle *ith = cls; | 412 | struct IteratorHandle *ith = cls; |
360 | struct GNUNET_CRYPTO_EcdsaPublicKey *target; | ||
361 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; | 413 | struct GNUNET_CRYPTO_EcdsaPublicKey zone; |
414 | char *name; | ||
415 | |||
416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
417 | "iterating for REVERSE (%s / %s)\n", | ||
418 | label, | ||
419 | mynick); | ||
420 | |||
362 | 421 | ||
363 | if ((rd_count != 1) || | 422 | if ((rd_count != 1) || |
364 | (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)) | 423 | (GNUNET_GNSRECORD_TYPE_PKEY != rd->record_type)) |
365 | { | 424 | { |
366 | GNUNET_SCHEDULER_add_now (&next_it, NULL); | 425 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
426 | "wrong format (%s)\n", mynick); | ||
427 | |||
428 | |||
429 | it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); | ||
367 | return; | 430 | return; |
368 | } | 431 | } |
369 | GNUNET_CRYPTO_ecdsa_key_get_public (key, | 432 | GNUNET_CRYPTO_ecdsa_key_get_public (key, |
370 | &zone); | 433 | &zone); |
371 | if (0 != memcmp (&zone, &ith->myzone, | 434 | if (0 != memcmp (&zone, &myzone, |
372 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | 435 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) |
373 | { | 436 | { |
374 | GNUNET_SCHEDULER_add_now (&next_it, NULL); | 437 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
438 | "wrong zone (%s)\n", mynick); | ||
439 | |||
440 | |||
441 | it_task = GNUNET_SCHEDULER_add_now (&next_it, ith); | ||
375 | return; | 442 | return; |
376 | } | 443 | } |
377 | target = (struct GNUNET_CRYPTO_EcdsaPublicKey *) rd->data; | 444 | ith->target = *((struct GNUNET_CRYPTO_EcdsaPublicKey *) rd->data); |
378 | gns_lookup_reverse = GNS_resolver_lookup (target, | 445 | GNUNET_asprintf (&name, |
446 | "%s.gnu", | ||
447 | mynick); | ||
448 | gns_lookup_reverse = GNS_resolver_lookup (&ith->target, | ||
379 | GNUNET_GNSRECORD_TYPE_PKEY, | 449 | GNUNET_GNSRECORD_TYPE_PKEY, |
380 | ith->mynick, | 450 | name, |
381 | NULL, | 451 | NULL, |
382 | GNUNET_GNS_LO_DEFAULT, | 452 | GNUNET_GNS_LO_DEFAULT, |
383 | &handle_gns_result_iter, | 453 | &handle_gns_result_iter, |
384 | ith); | 454 | ith); |
455 | GNUNET_free (name); | ||
385 | } | 456 | } |
386 | 457 | ||
387 | void check_reverse_records (void *cls); | 458 | static void check_reverse_records (void *cls); |
388 | 459 | ||
389 | void | 460 | static void |
390 | finished_cb (void *cls) | 461 | store_reverse (void *cls, |
462 | int32_t success, | ||
463 | const char *emsg) | ||
391 | { | 464 | { |
392 | struct IteratorHandle *ith = cls; | 465 | struct IteratorHandle *ith = cls; |
393 | struct ReverseRecordEntry *rr; | 466 | struct ReverseRecordEntry *rr; |
394 | 467 | ||
395 | //TODO add results to namestore! | 468 | if (GNUNET_SYSERR == success) |
469 | { | ||
470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
471 | emsg); | ||
472 | } | ||
473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stored records (%s)\n", mynick); | ||
474 | |||
396 | for (rr = ith->records_head; NULL != rr; rr = ith->records_head) | 475 | for (rr = ith->records_head; NULL != rr; rr = ith->records_head) |
397 | { | 476 | { |
398 | GNUNET_CONTAINER_DLL_remove (ith->records_head, | 477 | GNUNET_CONTAINER_DLL_remove (ith->records_head, |
@@ -404,19 +483,60 @@ finished_cb (void *cls) | |||
404 | reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS, | 483 | reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS, |
405 | &check_reverse_records, | 484 | &check_reverse_records, |
406 | NULL); | 485 | NULL); |
486 | GNUNET_free (ith); | ||
487 | } | ||
488 | |||
489 | static void | ||
490 | finished_cb (void *cls) | ||
491 | { | ||
492 | struct IteratorHandle *ith = cls; | ||
493 | struct ReverseRecordEntry *rr; | ||
494 | struct GNUNET_GNSRECORD_Data rd[ith->record_count]; | ||
495 | |||
496 | memset (rd, 0, sizeof (struct GNUNET_GNSRECORD_Data) * ith->record_count); | ||
497 | |||
498 | rr = ith->records_head; | ||
499 | for (int i = 0; i < ith->record_count; i++) | ||
500 | { | ||
501 | rd[i].data_size = rr->record_len; | ||
502 | rd[i].data = GNUNET_malloc (rr->record_len); | ||
503 | rd[i].record_type = GNUNET_GNSRECORD_TYPE_REVERSE; | ||
504 | rd[i].expiration_time = rr->record->expiration.abs_value_us; | ||
505 | GNUNET_memcpy ((char*) rd[i].data, | ||
506 | rr->record, | ||
507 | rr->record_len); | ||
508 | rr = rr->next; | ||
509 | } | ||
510 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
511 | "Finished iterating for REVERSE\n"); | ||
512 | |||
513 | ith->ns_qe = GNUNET_NAMESTORE_records_store (ns, | ||
514 | &pzone, | ||
515 | "+", | ||
516 | ith->record_count, | ||
517 | rd, | ||
518 | &store_reverse, | ||
519 | ith); | ||
520 | namestore_iter = NULL; | ||
407 | 521 | ||
408 | } | 522 | } |
409 | 523 | ||
410 | void | 524 | static void |
411 | it_error (void *cls) | 525 | it_error (void *cls) |
412 | { | 526 | { |
413 | finished_cb (cls); | 527 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
528 | "Error iterating for REVERSE\n"); | ||
414 | } | 529 | } |
415 | 530 | ||
416 | void | 531 | static void |
417 | check_reverse_records (void *cls) | 532 | check_reverse_records (void *cls) |
418 | { | 533 | { |
419 | struct IteratorHandle *ith = cls; | 534 | struct IteratorHandle *ith; |
535 | ith = GNUNET_new (struct IteratorHandle); | ||
536 | ith->record_count = 0; | ||
537 | reverse_record_check_task = NULL; | ||
538 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
539 | "Start iterating for REVERSE (%s)\n", mynick); | ||
420 | namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (ns, | 540 | namestore_iter = GNUNET_NAMESTORE_zone_iteration_start (ns, |
421 | NULL, | 541 | NULL, |
422 | &it_error, | 542 | &it_error, |
@@ -427,20 +547,48 @@ check_reverse_records (void *cls) | |||
427 | ith); | 547 | ith); |
428 | } | 548 | } |
429 | 549 | ||
430 | void | 550 | |
431 | GNS_reverse_init (const struct GNUNET_CONFIGURATION_Handle *c, | 551 | /** |
432 | const struct GNUNET_NAMESTORE_Handle *nh, | 552 | * Initialize reverser |
433 | const struct GNUNET_CRYPTO_EcdsaPublicKey *myzone, | 553 | * |
434 | const char *mynick) | 554 | * @param nh handle to a namestore |
555 | * @param key the private key of the gns-reverse zone | ||
556 | * @param name the name of the gns-reverse zone | ||
557 | * @return GNUNET_OK | ||
558 | */ | ||
559 | int | ||
560 | GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh, | ||
561 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | ||
562 | const char *nick) | ||
435 | { | 563 | { |
436 | struct IteratorHandle *ith; | 564 | GNUNET_asprintf (&mynick, |
565 | "%s", | ||
566 | nick); | ||
567 | GNUNET_CRYPTO_ecdsa_key_get_public (zone, | ||
568 | &myzone); | ||
569 | GNUNET_memcpy (&pzone, | ||
570 | zone, | ||
571 | sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey)); | ||
572 | ns = nh; | ||
573 | reverse_record_check_task = GNUNET_SCHEDULER_add_now (&check_reverse_records, | ||
574 | NULL); | ||
575 | return GNUNET_OK; | ||
576 | } | ||
437 | 577 | ||
438 | ns = ns; | 578 | /** |
439 | ith = GNUNET_new (struct IteratorHandle); | 579 | * Cleanup reverser |
440 | ith->mynick = GNUNET_strdup (mynick); | 580 | */ |
441 | ith->myzone = *myzone; | 581 | void |
442 | reverse_record_check_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_DAYS, | 582 | GNS_reverse_done () |
443 | &check_reverse_records, | 583 | { |
444 | NULL); | 584 | GNUNET_free (mynick); |
585 | if (NULL != it_task) | ||
586 | GNUNET_SCHEDULER_cancel (it_task); | ||
587 | if (NULL != reverse_record_check_task) | ||
588 | GNUNET_SCHEDULER_cancel (reverse_record_check_task); | ||
589 | if (NULL != gns_lookup_reverse) | ||
590 | GNS_resolver_lookup_cancel (gns_lookup_reverse); | ||
591 | if (NULL != namestore_iter) | ||
592 | GNUNET_NAMESTORE_zone_iteration_stop (namestore_iter); | ||
445 | } | 593 | } |
446 | 594 | ||
diff --git a/src/gns/gnunet-service-gns_reverser.h b/src/gns/gnunet-service-gns_reverser.h index ecec7d743..fc9680a29 100644 --- a/src/gns/gnunet-service-gns_reverser.h +++ b/src/gns/gnunet-service-gns_reverser.h | |||
@@ -69,4 +69,23 @@ GNS_reverse_lookup (const struct GNUNET_CRYPTO_EcdsaPublicKey *target, | |||
69 | void | 69 | void |
70 | GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh); | 70 | GNS_reverse_lookup_cancel (struct GNS_ReverserHandle *rh); |
71 | 71 | ||
72 | /** | ||
73 | * Initialize reverser | ||
74 | * | ||
75 | * @param nh handle to a namestore | ||
76 | * @param key the private key of the gns-reverse zone | ||
77 | * @param name the name of the gns-reverse zone | ||
78 | * @return GNUNET_OK | ||
79 | */ | ||
80 | int | ||
81 | GNS_reverse_init (struct GNUNET_NAMESTORE_Handle *nh, | ||
82 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | ||
83 | const char *name); | ||
84 | |||
85 | /** | ||
86 | * Cleanup reverser | ||
87 | */ | ||
88 | void | ||
89 | GNS_reverse_done (); | ||
90 | |||
72 | #endif | 91 | #endif |
diff --git a/src/gns/test_gns_reverse_lookup.sh b/src/gns/test_gns_reverse_lookup.sh index 73b829e07..bff1c0662 100755 --- a/src/gns/test_gns_reverse_lookup.sh +++ b/src/gns/test_gns_reverse_lookup.sh | |||
@@ -16,7 +16,7 @@ fi | |||
16 | 16 | ||
17 | TEST_NAME="dave.bob.alice.gnu" | 17 | TEST_NAME="dave.bob.alice.gnu" |
18 | gnunet-arm -s -c test_gns_lookup.conf | 18 | gnunet-arm -s -c test_gns_lookup.conf |
19 | gnunet-identity -C bobego -c test_gns_lookup.conf | 19 | gnunet-identity -C bob -c test_gns_lookup.conf |
20 | BOB_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep bob | awk '{print $3}') | 20 | BOB_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep bob | awk '{print $3}') |
21 | gnunet-identity -C daveego -c test_gns_lookup.conf | 21 | gnunet-identity -C daveego -c test_gns_lookup.conf |
22 | DAVE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep dave | awk '{print $3}') | 22 | DAVE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep dave | awk '{print $3}') |
@@ -24,14 +24,22 @@ gnunet-identity -C aliceego -c test_gns_lookup.conf | |||
24 | ALICE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep alice | awk '{print $3}') | 24 | ALICE_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep alice | awk '{print $3}') |
25 | gnunet-identity -C testego -c test_gns_lookup.conf | 25 | gnunet-identity -C testego -c test_gns_lookup.conf |
26 | ROOT_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep testego | awk '{print $3}') | 26 | ROOT_PKEY=$(gnunet-identity -d -c test_gns_lookup.conf | grep testego | awk '{print $3}') |
27 | |||
28 | gnunet-identity -s gns-reverse -e bob -c test_gns_lookup.conf | ||
29 | |||
27 | gnunet-namestore -p -z testego -a -n alice -t PKEY -V $ALICE_PKEY -e never -c test_gns_lookup.conf | 30 | gnunet-namestore -p -z testego -a -n alice -t PKEY -V $ALICE_PKEY -e never -c test_gns_lookup.conf |
28 | gnunet-namestore -p -z aliceego -a -n bob -t PKEY -V $BOB_PKEY -e never -c test_gns_lookup.conf | 31 | gnunet-namestore -p -z aliceego -a -n bob -t PKEY -V $BOB_PKEY -e never -c test_gns_lookup.conf |
29 | gnunet-namestore -p -z aliceego -a -n + -t REVERSE -V "alice $ROOT_PKEY 0" -e never -c test_gns_lookup.conf | 32 | gnunet-namestore -p -z aliceego -a -n + -t REVERSE -V "alice $ROOT_PKEY 0" -e never -c test_gns_lookup.conf |
30 | gnunet-namestore -p -z bobego -a -n dave -t PKEY -V $DAVE_PKEY -e never -c test_gns_lookup.conf | 33 | gnunet-namestore -p -z bob -a -n dave -t PKEY -V $DAVE_PKEY -e never -c test_gns_lookup.conf |
31 | gnunet-namestore -p -z bobego -a -n + -t REVERSE -V "bob $ALICE_PKEY 0" -e never -c test_gns_lookup.conf | 34 | gnunet-namestore -p -z bob -a -n alice -t PKEY -V $ALICE_PKEY -e never -c test_gns_lookup.conf |
35 | #gnunet-namestore -p -z bob -a -n + -t REVERSE -V "bob $ALICE_PKEY 0" -e never -c test_gns_lookup.conf | ||
32 | gnunet-namestore -p -z daveego -a -n + -t REVERSE -V "dave $BOB_PKEY 0" -e never -c test_gns_lookup.conf | 36 | gnunet-namestore -p -z daveego -a -n + -t REVERSE -V "dave $BOB_PKEY 0" -e never -c test_gns_lookup.conf |
37 | gnunet-namestore -p -z daveego -a -n bob -t PKEY -V $BOB_PKEY -e never -c test_gns_lookup.conf | ||
33 | gnunet-arm -i gns -c test_gns_lookup.conf | 38 | gnunet-arm -i gns -c test_gns_lookup.conf |
34 | sleep 0.5 | 39 | $DO_TIMEOUT gnunet-gns --raw -z aliceego -u bob.gnu -t PKEY -c test_gns_lookup.conf |
40 | sleep 10 | ||
41 | gnunet-namestore -z bob -D -c test_gns_lookup.conf | ||
42 | gnunet-namestore -z daveego -D -c test_gns_lookup.conf | ||
35 | RES_NAME=`$DO_TIMEOUT gnunet-gns --raw -z testego -R $DAVE_PKEY -c test_gns_lookup.conf` | 43 | RES_NAME=`$DO_TIMEOUT gnunet-gns --raw -z testego -R $DAVE_PKEY -c test_gns_lookup.conf` |
36 | gnunet-arm -e -c test_gns_lookup.conf | 44 | gnunet-arm -e -c test_gns_lookup.conf |
37 | rm -rf /tmp/test-gnunet-gns-peer-1/ | 45 | rm -rf /tmp/test-gnunet-gns-peer-1/ |