diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-10-24 21:45:44 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-10-24 21:45:44 +0000 |
commit | 47d7779091557516cda70ab9038dc2d460b0b3bb (patch) | |
tree | 2c8a334a40268d8b3717332a9d7278909830fab7 /src/util/resolver_api.c | |
parent | 267b8b5e0e264627f334a18ae1bf3f3a88ff2e32 (diff) | |
download | gnunet-47d7779091557516cda70ab9038dc2d460b0b3bb.tar.gz gnunet-47d7779091557516cda70ab9038dc2d460b0b3bb.zip |
giving client API option for auto-retry, making more often use of transmit_and_get_response API and removing auto-retry code where enhanced client API can be used for it
Diffstat (limited to 'src/util/resolver_api.c')
-rw-r--r-- | src/util/resolver_api.c | 114 |
1 files changed, 16 insertions, 98 deletions
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c index cbd8392bf..5dede1c09 100644 --- a/src/util/resolver_api.c +++ b/src/util/resolver_api.c | |||
@@ -51,11 +51,6 @@ struct GetAddressContext | |||
51 | /** | 51 | /** |
52 | * FIXME. | 52 | * FIXME. |
53 | */ | 53 | */ |
54 | struct GNUNET_RESOLVER_GetMessage *msg; | ||
55 | |||
56 | /** | ||
57 | * FIXME. | ||
58 | */ | ||
59 | struct GNUNET_CLIENT_Connection *client; | 54 | struct GNUNET_CLIENT_Connection *client; |
60 | 55 | ||
61 | /** | 56 | /** |
@@ -238,43 +233,6 @@ handle_address_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
238 | 233 | ||
239 | 234 | ||
240 | /** | 235 | /** |
241 | * FIXME | ||
242 | * | ||
243 | * @param cls FIXME | ||
244 | * @param size number of bytes available in buf | ||
245 | * @param buf target buffer, NULL on error | ||
246 | * @return number of bytes written to buf | ||
247 | */ | ||
248 | static size_t | ||
249 | transmit_get_ip (void *cls, size_t size, void *buf) | ||
250 | { | ||
251 | struct GetAddressContext *actx = cls; | ||
252 | uint16_t ms; | ||
253 | |||
254 | if (buf == NULL) | ||
255 | { | ||
256 | /* timeout / error */ | ||
257 | GNUNET_free (actx->msg); | ||
258 | actx->callback (actx->cls, NULL, 0); | ||
259 | GNUNET_CLIENT_disconnect (actx->client); | ||
260 | GNUNET_free (actx); | ||
261 | return 0; | ||
262 | } | ||
263 | ms = ntohs (actx->msg->header.size); | ||
264 | GNUNET_assert (size >= ms); | ||
265 | memcpy (buf, actx->msg, ms); | ||
266 | GNUNET_free (actx->msg); | ||
267 | actx->msg = NULL; | ||
268 | GNUNET_CLIENT_receive (actx->client, | ||
269 | &handle_address_response, | ||
270 | actx, | ||
271 | GNUNET_TIME_absolute_get_remaining (actx->timeout)); | ||
272 | return ms; | ||
273 | } | ||
274 | |||
275 | |||
276 | |||
277 | /** | ||
278 | * Convert a string to one or more IP addresses. | 236 | * Convert a string to one or more IP addresses. |
279 | * | 237 | * |
280 | * @param sched scheduler to use | 238 | * @param sched scheduler to use |
@@ -404,19 +362,19 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
404 | actx->cls = callback_cls; | 362 | actx->cls = callback_cls; |
405 | actx->client = client; | 363 | actx->client = client; |
406 | actx->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 364 | actx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
407 | actx->msg = msg; | ||
408 | 365 | ||
409 | #if DEBUG_RESOLVER | 366 | #if DEBUG_RESOLVER |
410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 367 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
411 | _("Resolver requests DNS resolution of hostname `%s'.\n"), | 368 | _("Resolver requests DNS resolution of hostname `%s'.\n"), |
412 | hostname); | 369 | hostname); |
413 | #endif | 370 | #endif |
414 | if (NULL == | 371 | if (GNUNET_OK != |
415 | GNUNET_CLIENT_notify_transmit_ready (client, | 372 | GNUNET_CLIENT_transmit_and_get_response (client, |
416 | slen + | 373 | &msg->header, |
417 | sizeof (struct | 374 | timeout, |
418 | GNUNET_RESOLVER_GetMessage), | 375 | GNUNET_YES, |
419 | timeout, &transmit_get_ip, actx)) | 376 | &handle_address_response, |
377 | actx)) | ||
420 | { | 378 | { |
421 | GNUNET_free (msg); | 379 | GNUNET_free (msg); |
422 | GNUNET_free (actx); | 380 | GNUNET_free (actx); |
@@ -424,6 +382,7 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
424 | GNUNET_CLIENT_disconnect (client); | 382 | GNUNET_CLIENT_disconnect (client); |
425 | return; | 383 | return; |
426 | } | 384 | } |
385 | GNUNET_free (msg); | ||
427 | } | 386 | } |
428 | 387 | ||
429 | 388 | ||
@@ -445,11 +404,6 @@ struct GetHostnameContext | |||
445 | 404 | ||
446 | /** | 405 | /** |
447 | * FIXME. | 406 | * FIXME. |
448 | */ | ||
449 | struct GNUNET_RESOLVER_GetMessage *msg; | ||
450 | |||
451 | /** | ||
452 | * FIXME. | ||
453 | */ | 407 | */ |
454 | struct GNUNET_CLIENT_Connection *client; | 408 | struct GNUNET_CLIENT_Connection *client; |
455 | 409 | ||
@@ -516,43 +470,6 @@ handle_hostname_response (void *cls, const struct GNUNET_MessageHeader *msg) | |||
516 | 470 | ||
517 | 471 | ||
518 | /** | 472 | /** |
519 | * FIXME | ||
520 | * | ||
521 | * @param cls FIXME | ||
522 | * @param size number of bytes available in buf | ||
523 | * @param buf target buffer, NULL on error | ||
524 | * @return number of bytes written to buf | ||
525 | */ | ||
526 | static size_t | ||
527 | transmit_get_hostname (void *cls, size_t size, void *buf) | ||
528 | { | ||
529 | struct GetHostnameContext *hctx = cls; | ||
530 | uint16_t msize; | ||
531 | |||
532 | if (buf == NULL) | ||
533 | { | ||
534 | GNUNET_free (hctx->msg); | ||
535 | hctx->callback (hctx->cls, NULL); | ||
536 | GNUNET_CLIENT_disconnect (hctx->client); | ||
537 | GNUNET_free (hctx); | ||
538 | return 0; | ||
539 | } | ||
540 | msize = ntohs (hctx->msg->header.size); | ||
541 | GNUNET_assert (size >= msize); | ||
542 | memcpy (buf, hctx->msg, msize); | ||
543 | GNUNET_free (hctx->msg); | ||
544 | hctx->msg = NULL; | ||
545 | GNUNET_CLIENT_receive (hctx->client, | ||
546 | &handle_hostname_response, | ||
547 | hctx, | ||
548 | GNUNET_TIME_absolute_get_remaining (hctx->timeout)); | ||
549 | return msize; | ||
550 | } | ||
551 | |||
552 | |||
553 | |||
554 | |||
555 | /** | ||
556 | * Get an IP address as a string. | 473 | * Get an IP address as a string. |
557 | * | 474 | * |
558 | * @param sched scheduler to use | 475 | * @param sched scheduler to use |
@@ -624,19 +541,20 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched, | |||
624 | hctx->cls = cls; | 541 | hctx->cls = cls; |
625 | hctx->client = client; | 542 | hctx->client = client; |
626 | hctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 543 | hctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
627 | hctx->msg = msg; | 544 | if (GNUNET_OK != |
628 | if (NULL == | 545 | GNUNET_CLIENT_transmit_and_get_response (client, |
629 | GNUNET_CLIENT_notify_transmit_ready (client, | 546 | &msg->header, |
630 | sizeof (struct | 547 | timeout, |
631 | GNUNET_RESOLVER_GetMessage) | 548 | GNUNET_YES, |
632 | + salen, timeout, | 549 | &handle_hostname_response, |
633 | &transmit_get_hostname, hctx)) | 550 | hctx)) |
634 | { | 551 | { |
635 | GNUNET_free (msg); | 552 | GNUNET_free (msg); |
636 | callback (cls, NULL); | 553 | callback (cls, NULL); |
637 | GNUNET_CLIENT_disconnect (client); | 554 | GNUNET_CLIENT_disconnect (client); |
638 | GNUNET_free (hctx); | 555 | GNUNET_free (hctx); |
639 | } | 556 | } |
557 | GNUNET_free (msg); | ||
640 | } | 558 | } |
641 | 559 | ||
642 | /** | 560 | /** |