diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-03-29 14:26:33 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-03-29 14:26:33 +0200 |
commit | ab281595eeb270120f89ec954a572f4fcf78fc53 (patch) | |
tree | 335a2caf503596adc400c5ebb9fb742f097bc5a3 /src/gns/gns_api.c | |
parent | 59d393a1124cfd1aaffdf994bf6f8a9baaac8361 (diff) | |
parent | 2b87f173e360aaf4a3bac3fbc6e5b4dc44cf58cd (diff) | |
download | gnunet-ab281595eeb270120f89ec954a572f4fcf78fc53.tar.gz gnunet-ab281595eeb270120f89ec954a572f4fcf78fc53.zip |
- merge with master
Diffstat (limited to 'src/gns/gns_api.c')
-rw-r--r-- | src/gns/gns_api.c | 196 |
1 files changed, 4 insertions, 192 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index f6f9889ac..84c4ae189 100644 --- a/src/gns/gns_api.c +++ b/src/gns/gns_api.c | |||
@@ -79,49 +79,6 @@ struct GNUNET_GNS_LookupRequest | |||
79 | 79 | ||
80 | }; | 80 | }; |
81 | 81 | ||
82 | /** | ||
83 | * Handle to a lookup request | ||
84 | */ | ||
85 | struct GNUNET_GNS_ReverseLookupRequest | ||
86 | { | ||
87 | |||
88 | /** | ||
89 | * DLL | ||
90 | */ | ||
91 | struct GNUNET_GNS_ReverseLookupRequest *next; | ||
92 | |||
93 | /** | ||
94 | * DLL | ||
95 | */ | ||
96 | struct GNUNET_GNS_ReverseLookupRequest *prev; | ||
97 | |||
98 | /** | ||
99 | * handle to gns | ||
100 | */ | ||
101 | struct GNUNET_GNS_Handle *gns_handle; | ||
102 | |||
103 | /** | ||
104 | * processor to call on lookup result | ||
105 | */ | ||
106 | GNUNET_GNS_ReverseLookupResultProcessor lookup_proc; | ||
107 | |||
108 | /** | ||
109 | * @e lookup_proc closure | ||
110 | */ | ||
111 | void *proc_cls; | ||
112 | |||
113 | /** | ||
114 | * Envelope with the message for this queue entry. | ||
115 | */ | ||
116 | struct GNUNET_MQ_Envelope *env; | ||
117 | |||
118 | /** | ||
119 | * request id | ||
120 | */ | ||
121 | uint32_t r_id; | ||
122 | |||
123 | }; | ||
124 | |||
125 | 82 | ||
126 | /** | 83 | /** |
127 | * Connection to the GNS service. | 84 | * Connection to the GNS service. |
@@ -150,15 +107,6 @@ struct GNUNET_GNS_Handle | |||
150 | struct GNUNET_GNS_LookupRequest *lookup_tail; | 107 | struct GNUNET_GNS_LookupRequest *lookup_tail; |
151 | 108 | ||
152 | /** | 109 | /** |
153 | * Head of linked list of active reverse lookup requests. | ||
154 | */ | ||
155 | struct GNUNET_GNS_ReverseLookupRequest *rev_lookup_head; | ||
156 | |||
157 | /** | ||
158 | * Tail of linked list of active reverse lookup requests. | ||
159 | */ | ||
160 | struct GNUNET_GNS_ReverseLookupRequest *rev_lookup_tail; | ||
161 | /** | ||
162 | * Reconnect task | 110 | * Reconnect task |
163 | */ | 111 | */ |
164 | struct GNUNET_SCHEDULER_Task *reconnect_task; | 112 | struct GNUNET_SCHEDULER_Task *reconnect_task; |
@@ -232,71 +180,13 @@ mq_error_handler (void *cls, | |||
232 | enum GNUNET_MQ_Error error) | 180 | enum GNUNET_MQ_Error error) |
233 | { | 181 | { |
234 | struct GNUNET_GNS_Handle *handle = cls; | 182 | struct GNUNET_GNS_Handle *handle = cls; |
235 | LOG (GNUNET_ERROR_TYPE_WARNING, "Problem with message queue. error: %i\n", | 183 | |
184 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
185 | "Problem with message queue. error: %i\n", | ||
236 | error); | 186 | error); |
237 | force_reconnect (handle); | 187 | force_reconnect (handle); |
238 | } | 188 | } |
239 | 189 | ||
240 | /** | ||
241 | * Check validity of message received from the GNS service | ||
242 | * | ||
243 | * @param cls the `struct GNUNET_GNS_Handle *` | ||
244 | * @param loookup_msg the incoming message | ||
245 | */ | ||
246 | static int | ||
247 | check_rev_result (void *cls, | ||
248 | const struct ReverseLookupResultMessage *lookup_msg) | ||
249 | { | ||
250 | size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg); | ||
251 | char *name; | ||
252 | |||
253 | name = (char*) &lookup_msg[1]; | ||
254 | if ('\0' != name[mlen-1]) | ||
255 | { | ||
256 | GNUNET_break (0); | ||
257 | return GNUNET_SYSERR; | ||
258 | } | ||
259 | return GNUNET_OK; | ||
260 | } | ||
261 | |||
262 | |||
263 | /** | ||
264 | * Handler for messages received from the GNS service | ||
265 | * | ||
266 | * @param cls the `struct GNUNET_GNS_Handle *` | ||
267 | * @param loookup_msg the incoming message | ||
268 | */ | ||
269 | static void | ||
270 | handle_rev_result (void *cls, | ||
271 | const struct ReverseLookupResultMessage *lookup_msg) | ||
272 | { | ||
273 | struct GNUNET_GNS_Handle *handle = cls; | ||
274 | char *name; | ||
275 | uint32_t r_id = ntohl (lookup_msg->id); | ||
276 | struct GNUNET_GNS_ReverseLookupRequest *rlr; | ||
277 | GNUNET_GNS_ReverseLookupResultProcessor proc; | ||
278 | void *proc_cls; | ||
279 | |||
280 | name = (char*)&lookup_msg[1]; | ||
281 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
282 | "Received reverse lookup reply from GNS service (%s)\n", | ||
283 | name); | ||
284 | for (rlr = handle->rev_lookup_head; NULL != rlr; rlr = rlr->next) | ||
285 | if (rlr->r_id == r_id) | ||
286 | break; | ||
287 | if (NULL == rlr) | ||
288 | return; | ||
289 | proc = rlr->lookup_proc; | ||
290 | proc_cls = rlr->proc_cls; | ||
291 | GNUNET_CONTAINER_DLL_remove (handle->rev_lookup_head, | ||
292 | handle->rev_lookup_tail, | ||
293 | rlr); | ||
294 | GNUNET_free (rlr); | ||
295 | proc (proc_cls, | ||
296 | name); | ||
297 | } | ||
298 | |||
299 | |||
300 | 190 | ||
301 | /** | 191 | /** |
302 | * Check validity of message received from the GNS service | 192 | * Check validity of message received from the GNS service |
@@ -385,14 +275,9 @@ reconnect (struct GNUNET_GNS_Handle *handle) | |||
385 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, | 275 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, |
386 | struct LookupResultMessage, | 276 | struct LookupResultMessage, |
387 | handle), | 277 | handle), |
388 | GNUNET_MQ_hd_var_size (rev_result, | ||
389 | GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP_RESULT, | ||
390 | struct ReverseLookupResultMessage, | ||
391 | handle), | ||
392 | GNUNET_MQ_handler_end () | 278 | GNUNET_MQ_handler_end () |
393 | }; | 279 | }; |
394 | struct GNUNET_GNS_LookupRequest *lh; | 280 | struct GNUNET_GNS_LookupRequest *lh; |
395 | struct GNUNET_GNS_ReverseLookupRequest *rlh; | ||
396 | 281 | ||
397 | GNUNET_assert (NULL == handle->mq); | 282 | GNUNET_assert (NULL == handle->mq); |
398 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 283 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -407,9 +292,6 @@ reconnect (struct GNUNET_GNS_Handle *handle) | |||
407 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) | 292 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) |
408 | GNUNET_MQ_send_copy (handle->mq, | 293 | GNUNET_MQ_send_copy (handle->mq, |
409 | lh->env); | 294 | lh->env); |
410 | for (rlh = handle->rev_lookup_head; NULL != rlh; rlh = rlh->next) | ||
411 | GNUNET_MQ_send_copy (handle->mq, | ||
412 | rlh->env); | ||
413 | } | 295 | } |
414 | 296 | ||
415 | 297 | ||
@@ -455,7 +337,6 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | |||
455 | handle->reconnect_task = NULL; | 337 | handle->reconnect_task = NULL; |
456 | } | 338 | } |
457 | GNUNET_assert (NULL == handle->lookup_head); | 339 | GNUNET_assert (NULL == handle->lookup_head); |
458 | GNUNET_assert (NULL == handle->rev_lookup_head); | ||
459 | GNUNET_free (handle); | 340 | GNUNET_free (handle); |
460 | } | 341 | } |
461 | 342 | ||
@@ -477,22 +358,6 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) | |||
477 | GNUNET_free (lr); | 358 | GNUNET_free (lr); |
478 | } | 359 | } |
479 | 360 | ||
480 | /** | ||
481 | * Cancel pending reverse lookup request | ||
482 | * | ||
483 | * @param lr the lookup request to cancel | ||
484 | */ | ||
485 | void | ||
486 | GNUNET_GNS_reverse_lookup_cancel (struct GNUNET_GNS_ReverseLookupRequest *lr) | ||
487 | { | ||
488 | struct GNUNET_GNS_Handle *handle = lr->gns_handle; | ||
489 | |||
490 | GNUNET_CONTAINER_DLL_remove (handle->rev_lookup_head, | ||
491 | handle->rev_lookup_tail, | ||
492 | lr); | ||
493 | GNUNET_MQ_discard (lr->env); | ||
494 | GNUNET_free (lr); | ||
495 | } | ||
496 | 361 | ||
497 | /** | 362 | /** |
498 | * Perform an asynchronous lookup operation on the GNS. | 363 | * Perform an asynchronous lookup operation on the GNS. |
@@ -502,7 +367,6 @@ GNUNET_GNS_reverse_lookup_cancel (struct GNUNET_GNS_ReverseLookupRequest *lr) | |||
502 | * @param zone the zone to start the resolution in | 367 | * @param zone the zone to start the resolution in |
503 | * @param type the record type to look up | 368 | * @param type the record type to look up |
504 | * @param options local options for the lookup | 369 | * @param options local options for the lookup |
505 | * @param shorten_zone_key the private key of the shorten zone (can be NULL) | ||
506 | * @param proc processor to call on result | 370 | * @param proc processor to call on result |
507 | * @param proc_cls closure for @a proc | 371 | * @param proc_cls closure for @a proc |
508 | * @return handle to the get request | 372 | * @return handle to the get request |
@@ -513,7 +377,6 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
513 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 377 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, |
514 | uint32_t type, | 378 | uint32_t type, |
515 | enum GNUNET_GNS_LocalOptions options, | 379 | enum GNUNET_GNS_LocalOptions options, |
516 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key, | ||
517 | GNUNET_GNS_LookupResultProcessor proc, | 380 | GNUNET_GNS_LookupResultProcessor proc, |
518 | void *proc_cls) | 381 | void *proc_cls) |
519 | { | 382 | { |
@@ -531,7 +394,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
531 | "Trying to lookup `%s' in GNS\n", | 394 | "Trying to lookup `%s' in GNS\n", |
532 | name); | 395 | name); |
533 | nlen = strlen (name) + 1; | 396 | nlen = strlen (name) + 1; |
534 | if (nlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*lr)) | 397 | if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*lr)) |
535 | { | 398 | { |
536 | GNUNET_break (0); | 399 | GNUNET_break (0); |
537 | return NULL; | 400 | return NULL; |
@@ -548,11 +411,6 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
548 | lookup_msg->options = htons ((uint16_t) options); | 411 | lookup_msg->options = htons ((uint16_t) options); |
549 | lookup_msg->zone = *zone; | 412 | lookup_msg->zone = *zone; |
550 | lookup_msg->type = htonl (type); | 413 | lookup_msg->type = htonl (type); |
551 | if (NULL != shorten_zone_key) | ||
552 | { | ||
553 | lookup_msg->have_key = htons (GNUNET_YES); | ||
554 | lookup_msg->shorten_key = *shorten_zone_key; | ||
555 | } | ||
556 | GNUNET_memcpy (&lookup_msg[1], | 414 | GNUNET_memcpy (&lookup_msg[1], |
557 | name, | 415 | name, |
558 | nlen); | 416 | nlen); |
@@ -565,50 +423,4 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
565 | return lr; | 423 | return lr; |
566 | } | 424 | } |
567 | 425 | ||
568 | /** | ||
569 | * Perform an asynchronous reverse lookup operation on the GNS. | ||
570 | * | ||
571 | * @param handle handle to the GNS service | ||
572 | * @param zone_key zone to find a name for | ||
573 | * @param root_key our zone | ||
574 | * @param proc processor to call on result | ||
575 | * @param proc_cls closure for @a proc | ||
576 | * @return handle to the request | ||
577 | */ | ||
578 | struct GNUNET_GNS_ReverseLookupRequest* | ||
579 | GNUNET_GNS_reverse_lookup (struct GNUNET_GNS_Handle *handle, | ||
580 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, | ||
581 | const struct GNUNET_CRYPTO_EcdsaPublicKey *root_key, | ||
582 | GNUNET_GNS_ReverseLookupResultProcessor proc, | ||
583 | void *proc_cls) | ||
584 | { | ||
585 | /* IPC to shorten gns names, return shorten_handle */ | ||
586 | struct ReverseLookupMessage *rev_lookup_msg; | ||
587 | struct GNUNET_GNS_ReverseLookupRequest *lr; | ||
588 | |||
589 | if ((NULL == zone_key) || (NULL == root_key)) | ||
590 | { | ||
591 | GNUNET_break (0); | ||
592 | return NULL; | ||
593 | } | ||
594 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
595 | "Trying to reverse lookup in GNS\n"); | ||
596 | lr = GNUNET_new (struct GNUNET_GNS_ReverseLookupRequest); | ||
597 | lr->gns_handle = handle; | ||
598 | lr->lookup_proc = proc; | ||
599 | lr->proc_cls = proc_cls; | ||
600 | lr->r_id = handle->r_id_gen++; | ||
601 | lr->env = GNUNET_MQ_msg (rev_lookup_msg, | ||
602 | GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP); | ||
603 | rev_lookup_msg->id = htonl (lr->r_id); | ||
604 | rev_lookup_msg->zone_pkey = *zone_key; | ||
605 | rev_lookup_msg->root_pkey = *root_key; | ||
606 | GNUNET_CONTAINER_DLL_insert (handle->rev_lookup_head, | ||
607 | handle->rev_lookup_tail, | ||
608 | lr); | ||
609 | if (NULL != handle->mq) | ||
610 | GNUNET_MQ_send_copy (handle->mq, | ||
611 | lr->env); | ||
612 | return lr; | ||
613 | } | ||
614 | /* end of gns_api.c */ | 426 | /* end of gns_api.c */ |