curl-library
round robin DNS without Ares only takes first IP
Date: Mon, 25 Apr 2005 12:28:37 +0200
Daniel Stenberg wrote:
>> How frequently does libCurl ask the DNS server? In other words: How
>> frequently is there a chance to get a different order?
>
> Ah, very good point. I didn't think of the DNS cache.
>
> It caches the entries in there for 60 seconds by default (and as long
> as the entry is "in use") and during that period it will use the same
> address order... Of course, as long as it re-uses the same connection
> it will also remain using that same address (as then it won't even
> check its IP address again).
>
> I guess this calls for a shuffle function to use when using cached
> results.
>
> Anyone up for making a patch?
The following is an excerpt of hostip.c
Would you find it appropriate to check an option set in the session data
and randomize the entryies before assigning them in
dns->addr = addr; /* this is the address(es) */
struct Curl_dns_entry *
Curl_cache_addr(struct SessionHandle *data,
Curl_addrinfo *addr,
char *hostname,
int port)
{
char *entry_id;
size_t entry_len;
struct Curl_dns_entry *dns;
struct Curl_dns_entry *dns2;
time_t now;
/* Create an entry id, based upon the hostname and port */
entry_id = create_hostcache_id(hostname, port);
/* If we can't create the entry id, fail */
if (!entry_id)
return NULL;
entry_len = strlen(entry_id);
/* Create a new cache entry */
dns = (struct Curl_dns_entry *) malloc(sizeof(struct Curl_dns_entry));
if (!dns) {
free(entry_id);
return NULL;
}
dns->inuse = 0; /* init to not used */
dns->addr = addr; /* this is the address(es) */
/* Store the resolved data in our DNS cache. This function may return a
pointer to an existing struct already present in the hash, and it may
return the same argument we pass in. Make no assumptions. */
dns2 = Curl_hash_add(data->hostcache, entry_id, entry_len+1, (void *)dns);
if(!dns2) {
/* Major badness, run away. */
free(dns);
free(entry_id);
return NULL;
}
time(&now);
dns = dns2;
dns->timestamp = now; /* used now */
dns->inuse++; /* mark entry as in-use */
/* free the allocated entry_id again */
free(entry_id);
return dns;
}
Received on 2005-04-25