Skip to content

Commit

Permalink
Merge pull request #1 from capnspacehook/feat/generics
Browse files Browse the repository at this point in the history
Feat/generics
  • Loading branch information
capnspacehook authored Apr 3, 2022
2 parents 52d4f02 + 7403f88 commit a18b9fe
Show file tree
Hide file tree
Showing 12 changed files with 611 additions and 376 deletions.
20 changes: 16 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ import (
"os"
"time"

"github.com/pelletier/go-toml"
"github.com/BurntSushi/toml"
)

const selfFilterName = "self-filter"

type duration time.Duration

func (d *duration) UnmarshalText(text []byte) error {
dur, err := time.ParseDuration(string(text))
if err != nil {
return err
}
*d = duration(dur)

return nil
}

type Config struct {
InboundDNSQueue uint16
SelfDNSQueue uint16
Expand All @@ -20,13 +32,13 @@ type Config struct {

type FilterOptions struct {
Name string
DNSQueue uint16 `toml:"dnsQueue"`
DNSQueue uint16
TrafficQueue uint16
IPv6 bool
AllowAllHostnames bool
LookupUnknownIPs bool
AllowAnswersFor time.Duration
ReCacheEvery time.Duration
AllowAnswersFor duration
ReCacheEvery duration
AllowedHostnames []string
CachedHostnames []string
}
Expand Down
17 changes: 8 additions & 9 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ allowedHostnames = ["foo"]`,
expectedConfig: nil,
expectedErr: `"inboundDNSQueue" and "selfDNSQueue" must be different`,
},
// TODO: test all filters have different queues
{
testName: "trafficQueue and AllowAllHostnames set",
configStr: `
Expand Down Expand Up @@ -343,7 +342,7 @@ allowedHostnames = [
Name: "foo",
DNSQueue: 1000,
TrafficQueue: 1001,
AllowAnswersFor: 5 * time.Second,
AllowAnswersFor: duration(5 * time.Second),
AllowedHostnames: []string{
"foo",
"bar",
Expand Down Expand Up @@ -381,7 +380,7 @@ allowAllHostnames = true`,
Name: "foo",
DNSQueue: 1000,
TrafficQueue: 1001,
AllowAnswersFor: 5 * time.Second,
AllowAnswersFor: duration(5 * time.Second),
AllowedHostnames: []string{
"foo",
"bar",
Expand Down Expand Up @@ -426,7 +425,7 @@ cachedHostnames = [
{
Name: "foo",
TrafficQueue: 1001,
ReCacheEvery: time.Second,
ReCacheEvery: duration(time.Second),
CachedHostnames: []string{
"oof",
"rab",
Expand Down Expand Up @@ -504,8 +503,8 @@ allowedHostnames = [
Name: "foo",
DNSQueue: 1000,
TrafficQueue: 1001,
ReCacheEvery: time.Second,
AllowAnswersFor: 5 * time.Second,
ReCacheEvery: duration(time.Second),
AllowAnswersFor: duration(5 * time.Second),
AllowedHostnames: []string{
"foo",
"bar",
Expand Down Expand Up @@ -554,7 +553,7 @@ allowedHostnames = [
DNSQueue: 1000,
TrafficQueue: 1001,
LookupUnknownIPs: true,
AllowAnswersFor: 5 * time.Second,
AllowAnswersFor: duration(5 * time.Second),
AllowedHostnames: []string{
"foo",
"bar",
Expand Down Expand Up @@ -606,8 +605,8 @@ allowedHostnames = [
DNSQueue: 1000,
TrafficQueue: 1001,
LookupUnknownIPs: true,
ReCacheEvery: time.Second,
AllowAnswersFor: 5 * time.Second,
ReCacheEvery: duration(time.Second),
AllowAnswersFor: duration(5 * time.Second),
AllowedHostnames: []string{
"foo",
"bar",
Expand Down
Loading

0 comments on commit a18b9fe

Please sign in to comment.