diff options
Diffstat (limited to 'src/gns/gns_api.c')
-rw-r--r-- | src/gns/gns_api.c | 194 |
1 files changed, 3 insertions, 191 deletions
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c index 5d6158bd4..15a59a4bc 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 |
@@ -382,14 +272,9 @@ reconnect (struct GNUNET_GNS_Handle *handle) | |||
382 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, | 272 | GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, |
383 | struct LookupResultMessage, | 273 | struct LookupResultMessage, |
384 | handle), | 274 | handle), |
385 | GNUNET_MQ_hd_var_size (rev_result, | ||
386 | GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP_RESULT, | ||
387 | struct ReverseLookupResultMessage, | ||
388 | handle), | ||
389 | GNUNET_MQ_handler_end () | 275 | GNUNET_MQ_handler_end () |
390 | }; | 276 | }; |
391 | struct GNUNET_GNS_LookupRequest *lh; | 277 | struct GNUNET_GNS_LookupRequest *lh; |
392 | struct GNUNET_GNS_ReverseLookupRequest *rlh; | ||
393 | 278 | ||
394 | GNUNET_assert (NULL == handle->mq); | 279 | GNUNET_assert (NULL == handle->mq); |
395 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 280 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -404,9 +289,6 @@ reconnect (struct GNUNET_GNS_Handle *handle) | |||
404 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) | 289 | for (lh = handle->lookup_head; NULL != lh; lh = lh->next) |
405 | GNUNET_MQ_send_copy (handle->mq, | 290 | GNUNET_MQ_send_copy (handle->mq, |
406 | lh->env); | 291 | lh->env); |
407 | for (rlh = handle->rev_lookup_head; NULL != rlh; rlh = rlh->next) | ||
408 | GNUNET_MQ_send_copy (handle->mq, | ||
409 | rlh->env); | ||
410 | } | 292 | } |
411 | 293 | ||
412 | 294 | ||
@@ -452,7 +334,6 @@ GNUNET_GNS_disconnect (struct GNUNET_GNS_Handle *handle) | |||
452 | handle->reconnect_task = NULL; | 334 | handle->reconnect_task = NULL; |
453 | } | 335 | } |
454 | GNUNET_assert (NULL == handle->lookup_head); | 336 | GNUNET_assert (NULL == handle->lookup_head); |
455 | GNUNET_assert (NULL == handle->rev_lookup_head); | ||
456 | GNUNET_free (handle); | 337 | GNUNET_free (handle); |
457 | } | 338 | } |
458 | 339 | ||
@@ -474,22 +355,6 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr) | |||
474 | GNUNET_free (lr); | 355 | GNUNET_free (lr); |
475 | } | 356 | } |
476 | 357 | ||
477 | /** | ||
478 | * Cancel pending reverse lookup request | ||
479 | * | ||
480 | * @param lr the lookup request to cancel | ||
481 | */ | ||
482 | void | ||
483 | GNUNET_GNS_reverse_lookup_cancel (struct GNUNET_GNS_ReverseLookupRequest *lr) | ||
484 | { | ||
485 | struct GNUNET_GNS_Handle *handle = lr->gns_handle; | ||
486 | |||
487 | GNUNET_CONTAINER_DLL_remove (handle->rev_lookup_head, | ||
488 | handle->rev_lookup_tail, | ||
489 | lr); | ||
490 | GNUNET_MQ_discard (lr->env); | ||
491 | GNUNET_free (lr); | ||
492 | } | ||
493 | 358 | ||
494 | /** | 359 | /** |
495 | * Perform an asynchronous lookup operation on the GNS. | 360 | * Perform an asynchronous lookup operation on the GNS. |
@@ -499,7 +364,6 @@ GNUNET_GNS_reverse_lookup_cancel (struct GNUNET_GNS_ReverseLookupRequest *lr) | |||
499 | * @param zone the zone to start the resolution in | 364 | * @param zone the zone to start the resolution in |
500 | * @param type the record type to look up | 365 | * @param type the record type to look up |
501 | * @param options local options for the lookup | 366 | * @param options local options for the lookup |
502 | * @param shorten_zone_key the private key of the shorten zone (can be NULL) | ||
503 | * @param proc processor to call on result | 367 | * @param proc processor to call on result |
504 | * @param proc_cls closure for @a proc | 368 | * @param proc_cls closure for @a proc |
505 | * @return handle to the get request | 369 | * @return handle to the get request |
@@ -510,7 +374,6 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
510 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, | 374 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, |
511 | uint32_t type, | 375 | uint32_t type, |
512 | enum GNUNET_GNS_LocalOptions options, | 376 | enum GNUNET_GNS_LocalOptions options, |
513 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key, | ||
514 | GNUNET_GNS_LookupResultProcessor proc, | 377 | GNUNET_GNS_LookupResultProcessor proc, |
515 | void *proc_cls) | 378 | void *proc_cls) |
516 | { | 379 | { |
@@ -545,11 +408,6 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
545 | lookup_msg->options = htons ((uint16_t) options); | 408 | lookup_msg->options = htons ((uint16_t) options); |
546 | lookup_msg->zone = *zone; | 409 | lookup_msg->zone = *zone; |
547 | lookup_msg->type = htonl (type); | 410 | lookup_msg->type = htonl (type); |
548 | if (NULL != shorten_zone_key) | ||
549 | { | ||
550 | lookup_msg->have_key = htons (GNUNET_YES); | ||
551 | lookup_msg->shorten_key = *shorten_zone_key; | ||
552 | } | ||
553 | GNUNET_memcpy (&lookup_msg[1], | 411 | GNUNET_memcpy (&lookup_msg[1], |
554 | name, | 412 | name, |
555 | nlen); | 413 | nlen); |
@@ -562,50 +420,4 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle, | |||
562 | return lr; | 420 | return lr; |
563 | } | 421 | } |
564 | 422 | ||
565 | /** | ||
566 | * Perform an asynchronous reverse lookup operation on the GNS. | ||
567 | * | ||
568 | * @param handle handle to the GNS service | ||
569 | * @param zone_key zone to find a name for | ||
570 | * @param root_key our zone | ||
571 | * @param proc processor to call on result | ||
572 | * @param proc_cls closure for @a proc | ||
573 | * @return handle to the request | ||
574 | */ | ||
575 | struct GNUNET_GNS_ReverseLookupRequest* | ||
576 | GNUNET_GNS_reverse_lookup (struct GNUNET_GNS_Handle *handle, | ||
577 | const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, | ||
578 | const struct GNUNET_CRYPTO_EcdsaPublicKey *root_key, | ||
579 | GNUNET_GNS_ReverseLookupResultProcessor proc, | ||
580 | void *proc_cls) | ||
581 | { | ||
582 | /* IPC to shorten gns names, return shorten_handle */ | ||
583 | struct ReverseLookupMessage *rev_lookup_msg; | ||
584 | struct GNUNET_GNS_ReverseLookupRequest *lr; | ||
585 | |||
586 | if ((NULL == zone_key) || (NULL == root_key)) | ||
587 | { | ||
588 | GNUNET_break (0); | ||
589 | return NULL; | ||
590 | } | ||
591 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
592 | "Trying to reverse lookup in GNS\n"); | ||
593 | lr = GNUNET_new (struct GNUNET_GNS_ReverseLookupRequest); | ||
594 | lr->gns_handle = handle; | ||
595 | lr->lookup_proc = proc; | ||
596 | lr->proc_cls = proc_cls; | ||
597 | lr->r_id = handle->r_id_gen++; | ||
598 | lr->env = GNUNET_MQ_msg (rev_lookup_msg, | ||
599 | GNUNET_MESSAGE_TYPE_GNS_REVERSE_LOOKUP); | ||
600 | rev_lookup_msg->id = htonl (lr->r_id); | ||
601 | rev_lookup_msg->zone_pkey = *zone_key; | ||
602 | rev_lookup_msg->root_pkey = *root_key; | ||
603 | GNUNET_CONTAINER_DLL_insert (handle->rev_lookup_head, | ||
604 | handle->rev_lookup_tail, | ||
605 | lr); | ||
606 | if (NULL != handle->mq) | ||
607 | GNUNET_MQ_send_copy (handle->mq, | ||
608 | lr->env); | ||
609 | return lr; | ||
610 | } | ||
611 | /* end of gns_api.c */ | 423 | /* end of gns_api.c */ |