From a8505ec0bd339ceccbb27e2a7cf7687cd50503aa Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 2 Jul 2012 12:39:04 +0000 Subject: [PATCH] -be lazy about connecting to VPN --- src/gns/gnunet-service-gns_resolver.c | 58 +++++++++++++++------------ src/gns/gnunet-service-gns_resolver.h | 4 +- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c index 1ce3eea52..653f9190d 100644 --- a/src/gns/gnunet-service-gns_resolver.c +++ b/src/gns/gnunet-service-gns_resolver.c @@ -131,6 +131,11 @@ static struct ResolverHandle *nah_head; */ static struct ResolverHandle *nah_tail; +/** + * Global configuration. + */ +static const struct GNUNET_CONFIGURATION_Handle *cfg; + /** * a resolution identifier pool variable * FIXME overflow? @@ -719,20 +724,21 @@ start_shorten (struct AuthorityChain *atail, * @param nh the namestore handle * @param dh the dht handle * @param lz the local zone's hash - * @param cfg configuration handle + * @param c configuration handle * @param max_bg_queries maximum number of parallel background queries in dht * @param ignore_pending ignore records that still require user confirmation * on lookup * @return GNUNET_OK on success */ int -gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, - struct GNUNET_DHT_Handle *dh, - struct GNUNET_CRYPTO_ShortHashCode lz, - const struct GNUNET_CONFIGURATION_Handle *cfg, - unsigned long long max_bg_queries, - int ignore_pending) +gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh, + struct GNUNET_DHT_Handle *dh, + struct GNUNET_CRYPTO_ShortHashCode lz, + const struct GNUNET_CONFIGURATION_Handle *c, + unsigned long long max_bg_queries, + int ignore_pending) { + cfg = c; namestore_handle = nh; dht_handle = dh; local_zone = lz; @@ -756,17 +762,6 @@ gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, GNUNET_RESOLVER_connect (cfg); - if (NULL == vpn_handle) - { - vpn_handle = GNUNET_VPN_connect (cfg); - if (NULL == vpn_handle) - { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "GNS_PHASE_INIT: Error connecting to VPN!\n"); - - return GNUNET_SYSERR; - } - } if ((namestore_handle != NULL) && (dht_handle != NULL)) { @@ -2045,14 +2040,27 @@ resolve_record_vpn (struct ResolverHandle *rh, af = AF_INET6; //FIXME timeout?? + if (NULL == vpn_handle) + { + vpn_handle = GNUNET_VPN_connect (cfg); + if (NULL == vpn_handle) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "GNS_PHASE_INIT: Error connecting to VPN!\n"); + finish_lookup (rh, rh->proc_cls, 0, NULL); + return; + } + } + + rh->vpn_handle = GNUNET_VPN_redirect_to_peer (vpn_handle, - af, ntohs (vpn->proto), - (struct GNUNET_PeerIdentity *)&vpn->peer, - &serv_desc, - GNUNET_NO, //nac - GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME - &process_record_result_vpn, - rh); + af, ntohs (vpn->proto), + (struct GNUNET_PeerIdentity *)&vpn->peer, + &serv_desc, + GNUNET_NO, //nac + GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME + &process_record_result_vpn, + rh); } diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h index 7f3d3799c..e9cbf0d53 100644 --- a/src/gns/gnunet-service-gns_resolver.h +++ b/src/gns/gnunet-service-gns_resolver.h @@ -350,7 +350,7 @@ struct NamestoreBGTask * @param nh handle to the namestore * @param dh handle to the dht * @param lz the local zone - * @param cfg configuration handle + * @param c configuration handle * @param max_bg_queries maximum amount of background queries * @param ignore_pending ignore records that still require user confirmation * on lookup @@ -360,7 +360,7 @@ int gns_resolver_init(struct GNUNET_NAMESTORE_Handle *nh, struct GNUNET_DHT_Handle *dh, struct GNUNET_CRYPTO_ShortHashCode lz, - const struct GNUNET_CONFIGURATION_Handle *cfg, + const struct GNUNET_CONFIGURATION_Handle *c, unsigned long long max_bg_queries, int ignore_pending); -- 2.25.1