summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2014-02-09 16:16:58 +0000
committerXavier Roche <xroche@users.noreply.github.com>2014-02-09 16:16:58 +0000
commit70185ab3108d9b5d834bfbdc0ab98a90b646bed9 (patch)
tree64934d6047f38913c186d759416be443709023ee /src
parent008601e493d8bb103272c96f53aef638765bf830 (diff)
Removed background DNS resolution, prone to bugs (racy when interrupting a mirror), and not providing any additional performance boost. Keeping cached DNS resolution, though.
Diffstat (limited to 'src')
-rw-r--r--src/htsback.c93
-rw-r--r--src/htsback.h6
-rw-r--r--src/htslib.c60
-rw-r--r--src/htslib.h2
4 files changed, 16 insertions, 145 deletions
diff --git a/src/htsback.c b/src/htsback.c
index 857e6be..ab5b2c1 100644
--- a/src/htsback.c
+++ b/src/htsback.c
@@ -2112,66 +2112,6 @@ int back_add(struct_back * sback, httrackp * opt, cache_back * cache, char *adr,
}
#if HTS_XGETHOST
-#if USE_BEGINTHREAD
-// lancement multithread du robot
-typedef struct {
- httrackp *opt;
- char iadr_p[HTS_URLMAXSIZE];
-} HostlookupStruct;
-void Hostlookup(void *pP) {
- HostlookupStruct *const str = (HostlookupStruct *) pP;
- httrackp *const opt = str->opt;
- char iadr[256];
- t_hostent *hp;
- t_dnscache *cache;
- t_fullhostent fullhostent_buffer;
-
- // recopier (après id:pass)
- strcpybuff(iadr, jump_identification(str->iadr_p));
- // couper éventuel :
- {
- char *a;
-
- if ((a = jump_toport(iadr)))
- *a = '\0'; // get rid of it
- }
-
- // resolve
- hp = vxgethostbyname(iadr, &fullhostent_buffer);
-
- hts_mutexlock(&opt->state.lock);
-
- hts_log_print(opt, LOG_DEBUG, "finished resolved: %s", iadr);
-
- for(cache = _hts_cache(opt); cache != NULL; cache = cache->n) {
- if (strcmp(cache->iadr, iadr) == 0) {
- break;
- }
- }
-
- if (cache != NULL && cache->host_length == 0) {
- if (hp != NULL) {
- memset(cache->host_addr, 0, sizeof(cache->host_addr));
- memcpy(cache->host_addr, hp->h_addr, hp->h_length);
- cache->host_length = hp->h_length;
- hts_log_print(opt, LOG_DEBUG, "saved resolved host: %s", iadr);
- } else {
- cache->host_length = -1;
- hts_log_print(opt, LOG_DEBUG, "saved negative resolved host: %s", iadr);
- }
- } else {
- hts_log_print(opt, LOG_DEBUG, "could not save resolved host: %s", iadr);
- }
-
- assertf(opt->state.dns_cache_nthreads > 0);
- opt->state.dns_cache_nthreads--;
-
- hts_mutexrelease(&opt->state.lock);
-
- freet(pP);
-}
-#endif
-
// attendre que le host (ou celui du proxy) ait été résolu
// si c'est un fichier, la résolution est immédiate
// idem pour ftp://
@@ -2181,7 +2121,6 @@ void back_solve(httrackp * opt, lien_back * back) {
if ((!strfield(back->url_adr, "file://"))
&& !strfield(back->url_adr, "ftp://")
) {
- //## if (back->url_adr[0]!=lOCAL_CHAR) { // qq chose à préparer
const char *a;
if (!(back->r.req.proxy.active))
@@ -2190,34 +2129,22 @@ void back_solve(httrackp * opt, lien_back * back) {
a = back->r.req.proxy.name;
assertf(a != NULL);
a = jump_protocol(a);
- if (hts_dnstest(opt, a, 1) == 2) { // non encore testé!..
- hts_log_print(opt, LOG_DEBUG, "resolving in background: %s", a);
- {
- HostlookupStruct *str =
- (HostlookupStruct *) malloct(sizeof(HostlookupStruct));
- if (str != NULL) {
- strcpybuff(str->iadr_p, a);
- str->opt = opt;
- hts_newthread(Hostlookup, str);
- }
- }
+ if (check_hostname_dns(a)) {
+ hts_log_print(opt, LOG_DEBUG, "resolved: %s", a);
+ } else {
+ hts_log_print(opt, LOG_DEBUG, "failed to resolve: %s", a);
}
+ //if (hts_dnstest(opt, a, 1) == 2) { // non encore testé!..
+ // hts_log_print(opt, LOG_DEBUG, "resolving in background: %s", a);
+ //}
}
}
// détermine si le host a pu être résolu
int host_wait(httrackp * opt, lien_back * back) {
- if ((!strfield(back->url_adr, "file://"))
- && (!strfield(back->url_adr, "ftp://"))
- ) {
- //## if (back->url_adr[0]!=lOCAL_CHAR) {
- if (!(back->r.req.proxy.active)) {
- return (hts_dnstest(opt, back->url_adr, 0));
- } else {
- return (hts_dnstest(opt, back->r.req.proxy.name, 0));
- }
- } else
- return 1; // prêt, fichier local
+ // Always synchronous. No more background DNS resolution
+ // (does not really improve performances)
+ return 1;
}
#endif
diff --git a/src/htsback.h b/src/htsback.h
index 85b6ea2..2dc992c 100644
--- a/src/htsback.h
+++ b/src/htsback.h
@@ -138,12 +138,6 @@ int host_wait(httrackp * opt, lien_back * sback);
int back_checksize(httrackp * opt, lien_back * eback, int check_only_totalsize);
int back_checkmirror(httrackp * opt);
-#if HTS_XGETHOST
-#if USE_BEGINTHREAD
-void Hostlookup(void *iadr_p);
-#endif
-#endif
-
#endif
#endif
diff --git a/src/htslib.c b/src/htslib.c
index 450a4b8..05286bb 100644
--- a/src/htslib.c
+++ b/src/htslib.c
@@ -4605,61 +4605,6 @@ static t_hostent *hts_ghbn(t_dnscache * cache, const char *iadr, t_hostent * ret
return NULL;
}
-// tester si iadr a déja été testé (ou en cours de test)
-// 0 non encore (en cours)
-// 1 ok
-// 2 non présent
-int hts_dnstest(httrackp * opt, const char *_iadr, int add) {
- int ret = 2;
- t_dnscache *cache, *tail;
- char iadr[HTS_URLMAXSIZE * 2];
-
- // sauter user:pass@ éventuel
- strcpybuff(iadr, jump_identification(_iadr));
- // couper éventuel :
- {
- char *a;
-
- if ((a = jump_toport(iadr)))
- *a = '\0';
- }
-
-#ifdef _WIN32
- if (inet_addr(iadr) != INADDR_NONE) // numérique
-#else
- if (inet_addr(iadr) != (in_addr_t) - 1) // numérique
-#endif
- return 1;
-
- hts_mutexlock(&opt->state.lock);
- for(cache = tail = _hts_cache(opt); cache != NULL; cache = cache->n) {
- tail = cache;
- if (strcmp(cache->iadr, iadr) == 0) { // ok trouvé
- ret = cache->host_length != 0 ? 1 : 0;
- break;
- }
- }
- // Add empty entry ?
- if (ret == 2 && add) {
- assertf(tail != NULL);
- assertf(tail->n == NULL);
- if (opt->state.dns_cache_nthreads < 16) {
- opt->state.dns_cache_nthreads++;
- tail->n = (t_dnscache *) calloct(1, sizeof(t_dnscache));
- if (tail->n != NULL) {
- strcpybuff(tail->n->iadr, iadr);
- tail->n->host_length = 0; /* pour le moment rien */
- tail->n->n = NULL;
- }
- } else {
- hts_log_print(opt, LOG_DEBUG, "too many threads, not adding another dns resolution in background");
- ret = 0;
- }
- }
- hts_mutexrelease(&opt->state.lock);
- return ret;
-}
-
HTSEXT_API t_hostent *vxgethostbyname2(char *hostname, void *v_buffer, const char **error) {
t_fullhostent *buffer = (t_fullhostent *) v_buffer;
@@ -4747,6 +4692,11 @@ HTSEXT_API t_hostent *vxgethostbyname(char *hostname, void *v_buffer) {
return vxgethostbyname2(hostname, v_buffer, NULL);
}
+HTSEXT_API int check_hostname_dns(char *hostname) {
+ t_fullhostent buffer;
+ return vxgethostbyname(hostname, &buffer) != NULL;
+}
+
// Needs locking
// cache dns interne à HTS // ** FREE A FAIRE sur la chaine
static t_hostent *hts_gethostbyname_(httrackp * opt, const char *_iadr, void *v_buffer, const char **error) {
diff --git a/src/htslib.h b/src/htslib.h
index 52d63e1..03ac7b1 100644
--- a/src/htslib.h
+++ b/src/htslib.h
@@ -295,12 +295,12 @@ HTS_INLINE t_hostent *hts_gethostbyname(httrackp * opt, const char *iadr,
#ifndef HTTRACK_DEFLIB
HTSEXT_API t_hostent *vxgethostbyname2(char *hostname, void *v_buffer, const char **error);
HTSEXT_API t_hostent *vxgethostbyname(char *hostname, void *v_buffer);
+HTSEXT_API int check_hostname_dns(char *hostname);
#endif
int ftp_available(void);
#if HTS_DNSCACHE
void hts_cache_free(t_dnscache * cache);
-int hts_dnstest(httrackp * opt, const char *_iadr, int add);
t_dnscache *_hts_cache(httrackp * opt);
#endif