Open kevenwyld opened 2 years ago
Hi @kevenwyld, sorting the lines added to hosts file would be a good idea!
I'm looking at the code, it should be a matter of changing HostsBuilder
's HashMap
to BTreeMap
:
https://github.com/tonarino/innernet/blob/e98c0659efa5cc42564a7273e3baa11ebaed5396/hostsfile/src/lib.rs#L84
However, even when the hostname list is sorted, it seems that there is currently no detection of `hostname file is already the same as we want to write", so we'd need to add that too (I think we should).
Do you want to try contributing such improvement?
Thanks @strohel . I am up for trying to trying to contribute however this would be my first experience with rust. I will see what I can come up with but it may take me a few days.
Hey, just wanted to say that I'm still working on this, sorry for the silence. @mcginty helped me out a bit getting up to speed.
Hey @kevenwyld ! Since this seems inactive and the change is pretty simple, I decided to open a PR. #259
Hey thanks @evaporei! Life happened and I didn't have time to get it done.
Currently /etc/hosts is written very frequently, nearly every minute, because innernet writes the contents of each section as it is received. Apparently those checkins, or whatever is triggering HostsBuilder to run, is receiving the list of hosts in the order they respond which is not always the same. This order is carried through to the order mappings appear in the hosts file.
Would it be possible to sort the list of hosts in each section before checking to see if /etc/hosts requires updating? This would, I think, change the behavior so that updating /etc/hosts only happens when there is actually an ip/hostname update required and make it much less frequent.
Thanks!