* use urlfilter v0.4.0

Now we pass filtering rules to urlfilter as filer file names,
 rather than the list of rule strings.
(Note: user rules are still passed as the list of rule strings).

As a result, we don't store the contents of filter files in memory.
This commit is contained in:
Simon Zolin
2019-07-04 14:00:20 +03:00
parent ceac4cbdd5
commit 134d9275bb
6 changed files with 51 additions and 22 deletions

View File

@@ -180,8 +180,8 @@ func generateServerConfig() dnsforward.ServerConfig {
})
for _, filter := range config.Filters {
filters = append(filters, dnsfilter.Filter{
ID: filter.ID,
Data: filter.Data,
ID: filter.ID,
FilePath: filter.Path(),
})
}

View File

@@ -241,7 +241,7 @@ func refreshFiltersIfNecessary(force bool) int {
log.Info("Updated filter #%d. Rules: %d -> %d",
f.ID, f.RulesCount, uf.RulesCount)
f.Name = uf.Name
f.Data = uf.Data
f.Data = nil
f.RulesCount = uf.RulesCount
f.checksum = uf.checksum
updateCount++
@@ -339,6 +339,9 @@ func (filter *filter) update() (bool, error) {
}
// saves filter contents to the file in dataDir
// This method is safe to call during filters update,
// because it creates a new file and then renames it,
// so the currently opened file descriptors to the old filter file remain valid.
func (filter *filter) save() error {
filterFilePath := filter.Path()
log.Printf("Saving filter %d contents to: %s", filter.ID, filterFilePath)
@@ -369,7 +372,7 @@ func (filter *filter) load() error {
rulesCount, _ := parseFilterContents(filterFileContents)
filter.RulesCount = rulesCount
filter.Data = filterFileContents
filter.Data = nil
filter.checksum = crc32.ChecksumIEEE(filterFileContents)
filter.LastUpdated = filter.LastTimeUpdated()