-
-
Notifications
You must be signed in to change notification settings - Fork 243
feat: allow hosts file resolver to use a HTTP(S) link or inline block #884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow hosts file resolver to use a HTTP(S) link or inline block #884
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## development #884 +/- ##
===============================================
- Coverage 93.15% 93.00% -0.15%
===============================================
Files 42 48 +6
Lines 4950 5332 +382
===============================================
+ Hits 4611 4959 +348
- Misses 268 291 +23
- Partials 71 82 +11
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
9785d4b
to
cb47ea8
Compare
@@ -147,6 +147,8 @@ func logger() *logrus.Entry { | |||
} | |||
|
|||
// downloads and reads files with domain names and creates cache for them | |||
// | |||
//nolint:funlen // will refactor in a later commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll refactor this in the follow-up.
I already have something locally, but think it'll be better in the PR that allows the HostsFileResolver
to use multiple sources since that is going to look a lot like this function.
return factory.Create(), err | ||
cache := factory.Create() | ||
if cache.ElementCount() == 0 && err != nil { | ||
cache = nil // don't replace existing cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a change from the previous behavior (I also changed a test). I think makes more sense to keep the current cache if the parsing completely failed.
I can easily revert it if you prefer the current behavior as it's isolated to 8caf7c5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should replace cache content if file was parsed without errors, but contains no entries. Example: user has a local blacklist with 2 entries and he/she comments both entries out. In this case I would expect that both entries aren't in the cache anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that's covered by err != nil
: this only ignores a new empty parse result if there was also an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skimmed over your code. I leaved some comments, some minor points. The parsers package is difficult to understand, unit tests would be really helpful here.
return factory.Create(), err | ||
cache := factory.Create() | ||
if cache.ElementCount() == 0 && err != nil { | ||
cache = nil // don't replace existing cache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should replace cache content if file was parsed without errors, but contains no entries. Example: user has a local blacklist with 2 entries and he/she comments both entries out. In this case I would expect that both entries aren't in the cache anymore
} | ||
|
||
return err | ||
} | ||
|
||
func (b *ListCache) groupElementCount(group string, isInit bool) int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In "Configuration()" we do already count elements per group. Maybe we can reuse it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked this, but I think it's better kept as is: in Configuration
we're iterating on the groups, so no need to check which ones exist like this func does. Also we can acquire the lock only once for the whole loop with the way it is.
@@ -131,7 +131,7 @@ var _ = Describe("ListCache", func() { | |||
}) | |||
}) | |||
When("non transient err occurs on download", func() { | |||
It("should delete existing elements from group cache", func() { | |||
It("should keep existing elements from group cache", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied on the other comment too.
This test has an error occur on second parse, so it's not the case you mentioned (no entries and no error).
I'll add a test for that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a test with 08b17e2
Wrote tests to get 100% coverage on parsers and |
Got test coverage to a point I'm happy with. I'll squash the commits and see if that unblocks it. |
Unify the hosts file parsing between the hosts resolver and lists so the resolver supports more data sources than local files.
Instead of iterating through all hosts+aliases for each A/AAAA query, we can do a single lookup. For PTR we search through only the hosts with an IP version that matches the question. And compare IPs instead of building the reverse DNS name for each IP in the hosts database.
The new `MockCallSequence` generalizes creating a function that can return `(T, error)` multiple times.
a984eb2
to
9bca5d0
Compare
Seems like CodeCov isn't working properly with rebase+force push. I think everything is ready on my side :) |
CodeCov results are something "strange". I wanted to check it out, but as usual, no time. :) I skimmed over your commit, it looks good. Is it now a stand what can be checked in? Or do you want to continue to develop? I think, threre was a TODO in your code (something with golint). If you want to merge it, please squash your commits to one together. |
Yeah the Thanks! |
This is a first step towards #867.
In example config from the issue, @adb76 also uses multiple hosts files, which this does not implement. I'll do that as a follow up so this PR doesn't get too huge.
I ended up doing a bit more than "just re-using our existing code" as I said in the issue:
There aren't tests for those new types/functions yet, I first wanted some feedback.
All commits pass all existing tests though.
HostsFileResolver
so it uses a map internally so lookups are faster (actually multiple to also speedup reserve lookups)EDIT: force-pushed to remove a
FDescribe
I accidentally committed.