Re: wget 1.10.x: New option --random to randomize the dns result
Jerry Lundström <[email protected]> Tue, 18 Apr 2006 15:19:42 +0200
| Newsgroups | gmane.comp.web.wget.patches |
|---|---|
| Message-ID | <[email protected]> |
Hrvoje Niksic wrote: > Jerry Lundström <[email protected]> writes: > >>Here is a patch that adds '--random' (rename at will). What it does is >>to run address_list_randomize() after getting the dns result. >>Reason I made this was because of IPv6 and RFC 3484 the dns result for >>multi record hosts are sorted leaving round robins mirrors useless. > > What value does this option bring to the end user? Wget is hardly the > most popular user agent, so even if it were the default, it wouldn't > lessen the load on the web server. If you just need to test a site > that uses round-robin DNS, you can always specify the needed IP > address directly (and optionally correct the `Host' header using > --header). As getaddrinfo() sorts the dns result no matter if its ipv4 or ipv6 you will be resolved to the same server 99.9% of the time. I wished there was a flag to getaddrinfo() so that you simply could turn off the RFC 3484 behaviour but there isnt. Mirroring scripts, dists and other things that use wget might not always like getting the same ip address over and over again. I am a Lunar Linux developer (www.lunar-linux.org) and we use wget for fetching sources and RFC 3484 breaks our mirrors before they are synced. I am not suggesting putting this as a default option. >>+ int random; > > That should be bool. Np, will fix. >>+ if (opt.random && al->count > 1) { >>+ int *tbl = xnew0_array(int, al->count); >>+ ip_address *ip = xnew0_array(ip_address, al->count); > > I don't understand the allocations. It should certainly be possible > to shuffle an array in place! For example, see > http://www.stanford.edu/~blp/writings/clc/shuffle.html > > Anyway, it's a better idea to add a generic shuffle() code to, say, > utils.c, and just call it from host.c. Didn't want to mess the struct up before it was done and I wanted to move all elements. Doing shuffle might just move the same element around but ofcourse it can be moved to a more generic function and use shuffle. >>+ /* fast init */ >>+ srandom(al->count*time(0)); > > Seeding the RNG should be done only once, not every time. Also note > that [s]random is less portable than [s]rand. You'r right about that. >>- return al; >>+ return address_list_randomize(al); >> } > > [...] > >>+ al = address_list_randomize(al); > > You don't seem to be checking the value of opt.random at all. It's done in the address_list_randomize() function. -- Jerry Lundström, System Developer The Division of IT and media, Stockholm University, Sweden +46 (0)8 16 19 99 / http://www.it.su.se