Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions updater.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/sha256"
"bufio"
"fmt"
"io"
Expand All @@ -11,9 +12,9 @@ import (
"regexp"
"strings"
"sync"
"time"
)

var timesSeen = make(map[string]int)
var whitelist = make(map[string]bool)

// Update downloads all the blocklists and imports them into the database
Expand Down Expand Up @@ -66,6 +67,13 @@ func downloadFile(uri string, name string) error {
}
}(response.Body)

downloadTime := time.Now()
header := fmt.Sprintf(
"# Downloaded at %s from %s\n\n",
downloadTime.Format(time.RFC3339), uri,
)
output.WriteString(header)

if _, err := io.Copy(output, response.Body); err != nil {
return fmt.Errorf("error copying output: %s", err)
}
Expand All @@ -79,10 +87,14 @@ func fetchSources(sources []string) error {
for _, uri := range sources {
wg.Add(1)

// get the first 12 bytes of the sha256 hash of the uri
hash := sha256.New()
hash.Write([]byte(uri))
urihash := fmt.Sprintf("%s", hash.Sum(nil)[:12])

u, _ := url.Parse(uri)
host := u.Host
timesSeen[host] = timesSeen[host] + 1
fileName := fmt.Sprintf("%s.%d.list", host, timesSeen[host])
fileName := fmt.Sprintf("%s.%x.list", host, urihash)

go func(uri string, name string) {
logger.Debugf("fetching source %s\n", uri)
Expand Down