From f38586dcb06135eec53770a686eed15474589d0d Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 14 Apr 2021 23:42:24 -0400 Subject: [PATCH] Add bolt provider, rewrite hosts, start of api, start of update via nsupdate --- Dockerfile | 5 +- api/api.go | 17 ++++ api/hosts.go | 7 ++ go.mod | 23 ++--- go.sum | 219 +++++++++++++++++++++++++++++++++-------- handler.go | 193 ++++++++++++++++++++++++++++-------- hosts/hosts.go | 38 +++---- hosts/hosts_bolt.go | 124 +++++++++++++++++++++++ hosts/hosts_file.go | 42 ++++---- hosts/hosts_redis.go | 97 +++++++++--------- log/log.go | 177 --------------------------------- log/log_test.go | 60 ----------- log/logger.go | 33 ------- main.go | 80 ++++++++++----- resolver/nameserver.go | 1 + resolver/resolver.go | 84 +++++++++------- server.go | 6 +- settings/settings.go | 17 ---- 18 files changed, 684 insertions(+), 539 deletions(-) create mode 100644 api/api.go create mode 100644 api/hosts.go create mode 100644 hosts/hosts_bolt.go delete mode 100644 log/log.go delete mode 100644 log/log_test.go delete mode 100644 log/logger.go diff --git a/Dockerfile b/Dockerfile index 7dbf4ce..18e9913 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,9 +5,10 @@ MAINTAINER Tyler Stuyfzand EXPOSE 53 RUN apk --no-cache add tini -ENTRYPOINT ["/sbin/tini", "-g", "--"] -CMD ["godns"] COPY etc/godns.example.conf /etc/godns.conf COPY /build/godns /usr/local/bin/godns RUN chmod +x /usr/local/bin/godns + +ENTRYPOINT ["/sbin/tini", "-g", "--"] +CMD ["godns"] \ No newline at end of file diff --git a/api/api.go b/api/api.go new file mode 100644 index 0000000..fc2cdef --- /dev/null +++ b/api/api.go @@ -0,0 +1,17 @@ +package api + +import ( + "github.com/go-chi/chi" + "github.com/go-chi/render" + "net/http" +) + +func Start() error { + r := chi.NewRouter() + + r.Use(render.SetContentType(render.ContentTypeJSON)) + + r.Get("/hosts", hostsGet) + + return http.ListenAndServe(":8080", r) +} \ No newline at end of file diff --git a/api/hosts.go b/api/hosts.go new file mode 100644 index 0000000..2737da5 --- /dev/null +++ b/api/hosts.go @@ -0,0 +1,7 @@ +package api + +import "net/http" + +func hostsGet(w http.ResponseWriter, r *http.Request) { + +} diff --git a/go.mod b/go.mod index 748461d..ba562d6 100644 --- a/go.mod +++ b/go.mod @@ -1,25 +1,18 @@ module meow.tf/joker/godns -go 1.12 +go 1.16 require ( - github.com/BurntSushi/toml v0.3.1 github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b - github.com/caarlos0/env v3.5.0+incompatible github.com/fsnotify/fsnotify v1.4.7 + github.com/go-chi/chi v1.5.4 + github.com/go-chi/render v1.0.1 github.com/go-redis/redis/v7 v7.0.0-beta.5 - github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f // indirect - github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0 - github.com/kr/pretty v0.2.0 // indirect - github.com/miekg/dns v1.1.27 - github.com/mitchellh/go-homedir v1.1.0 + github.com/miekg/dns v1.1.41 github.com/ryanuber/go-glob v1.0.0 - github.com/smartystreets/assertions v1.0.1 // indirect + github.com/sirupsen/logrus v1.2.0 github.com/smartystreets/goconvey v1.6.4 - github.com/spf13/viper v1.6.2 - github.com/stretchr/testify v1.4.0 // indirect - golang.org/x/crypto v0.0.0-20200117160349-530e935923ad // indirect - golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect - golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect - golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect + github.com/spf13/viper v1.7.1 + go.etcd.io/bbolt v1.3.5 + golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect ) diff --git a/go.sum b/go.sum index f788050..47b7a19 100644 --- a/go.sum +++ b/go.sum @@ -1,21 +1,36 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= -github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs= -github.com/caarlos0/env v3.5.0+incompatible/go.mod h1:tdCsowwCzMLdkqRYDlHpZCp2UooDD3MspDBjZ2AD02Y= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= -github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -23,9 +38,15 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs= +github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg= +github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8= +github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= @@ -37,48 +58,84 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f h1:TyqzGm2z1h3AGhjOoRYyeLcW4WlW81MDQkWa+rx/000= -github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0 h1:mjZV3MTu2A5gwfT5G9IIiLGdwZNciyVq5qqnmJJZ2JI= -github.com/hoisie/redis v0.0.0-20160730154456-b5c6e81454e0/go.mod h1:pMYMxVaKJqCDC1JUg/XbPJ4/fSazB25zORpFzqsIGIc= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= -github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM= -github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= +github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -86,11 +143,14 @@ github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo= github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= @@ -101,12 +161,15 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w= -github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= @@ -119,82 +182,150 @@ github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9 github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/spf13/viper v1.6.2 h1:7aKfF+e8/k68gda3LOjo5RxiUqddoFxVq4BKBPrxk5E= -github.com/spf13/viper v1.6.2/go.mod h1:t3iDnF5Jlj76alVNuyFBk5oUMCvsrkbvZK0WQdfDi5k= +github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= +github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= +go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg= -golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M= -golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 h1:1/DFK4b7JH8DmkqhUk48onnSfrPzImPoVxuomtbT2nk= -golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno= @@ -204,8 +335,10 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/handler.go b/handler.go index 39ab535..524c9a3 100644 --- a/handler.go +++ b/handler.go @@ -4,9 +4,9 @@ import ( "crypto/md5" "fmt" "github.com/miekg/dns" + log "github.com/sirupsen/logrus" "meow.tf/joker/godns/cache" "meow.tf/joker/godns/hosts" - "meow.tf/joker/godns/log" "meow.tf/joker/godns/resolver" "meow.tf/joker/godns/utils" "net" @@ -15,15 +15,74 @@ import ( type Handler struct { resolver *resolver.Resolver + middleware []MiddlewareFunc cache, negCache cache.Cache hosts hosts.Hosts } -func NewHandler(r *resolver.Resolver, resolverCache, negCache cache.Cache, h hosts.Hosts) *Handler { - return &Handler{r, resolverCache, negCache, h} +type MiddlewareFunc func(w dns.ResponseWriter, r *dns.Msg, m *dns.Msg) *dns.Msg + +func TsigMiddleware(secretKey string) MiddlewareFunc { + return func(w dns.ResponseWriter, r *dns.Msg, m *dns.Msg) *dns.Msg { + if r.IsTsig() != nil { + if w.TsigStatus() == nil { + m.SetTsig(r.Extra[len(r.Extra)-1].(*dns.TSIG).Hdr.Name, dns.HmacSHA256, 300, time.Now().Unix()) + } + } + + return m + } } +func NewHandler(r *resolver.Resolver, resolverCache, negCache cache.Cache, h hosts.Hosts) *Handler { + return &Handler{r, make([]MiddlewareFunc, 0), resolverCache, negCache, h} +} + +// do handles a dns request. +// network will decide which network type it is (udp, tcp, https, etc) func (h *Handler) do(network string, w dns.ResponseWriter, req *dns.Msg) { + switch req.Opcode { + case dns.OpcodeQuery: + h.query(network, w, req) + case dns.OpcodeUpdate: + if req.IsTsig() == nil { + m := new(dns.Msg) + m.SetRcode(req, dns.RcodeBadSig) + w.WriteMsg(m) + return + } + + packed, err := req.Pack() + + if err != nil { + m := new(dns.Msg) + m.SetRcode(req, dns.RcodeBadSig) + w.WriteMsg(m) + return + } + + if err := dns.TsigVerify(packed, "", "", false); err != nil { + m := new(dns.Msg) + m.SetRcode(req, dns.RcodeBadSig) + w.WriteMsg(m) + return + } + + h.update(network, w, req) + } +} + +// writeMsg writes a *dns.Msg after passing it through middleware. +func (h *Handler) writeMsg(w dns.ResponseWriter, r *dns.Msg, m *dns.Msg) { + for _, f := range h.middleware { + m = f(w, r, m) + } + + w.WriteMsg(m) +} + +// query handles dns queries. +func (h *Handler) query(network string, w dns.ResponseWriter, req *dns.Msg) { q := req.Question[0] question := resolver.Question{Name: utils.UnFqdn(q.Name), Type: q.Qtype, Class: dns.ClassToString[q.Qclass]} @@ -38,11 +97,40 @@ func (h *Handler) do(network string, w dns.ResponseWriter, req *dns.Msg) { return } - log.Info("%s lookup %s", remote, question.String()) + log.WithFields(log.Fields{ + "remote": remote, + "question": question.String(), + }).Debug("Lookup question") + + key := KeyGen(question) + + // Check cache first + mesg, err := h.cache.Get(key) + + if err != nil { + if mesg, err = h.negCache.Get(key); err != nil { + log.WithField("question", question.String()).Debug("no negative cache hit") + } else { + log.WithField("question", question.String()).Debug("negative cache hit") + m := new(dns.Msg) + m.SetRcode(req, dns.RcodeServerFailure) + w.WriteMsg(m) + return + } + } else { + log.WithField("question", question.String()).Debug("hit cache") + + // we need this copy against concurrent modification of Id + msg := *mesg + msg.Id = req.Id + h.writeMsg(w, req, &msg) + + return + } // Query hosts if h.hosts != nil { - if vals, ttl, ok := h.hosts.Get(question.Type, question.Name); ok { + if host, err := h.hosts.Get(question.Type, question.Name); err == nil { m := new(dns.Msg) m.SetReply(req) @@ -50,74 +138,97 @@ func (h *Handler) do(network string, w dns.ResponseWriter, req *dns.Msg) { Name: q.Name, Rrtype: question.Type, Class: dns.ClassINET, - Ttl: uint32(ttl / time.Second), + Ttl: uint32(host.TTL / time.Second), } switch question.Type { case dns.TypeA: - for _, val := range vals { + for _, val := range host.Values { m.Answer = append(m.Answer, &dns.A{Hdr: hdr, A: net.ParseIP(val).To4()}) } case dns.TypeAAAA: - for _, val := range vals { + for _, val := range host.Values { m.Answer = append(m.Answer, &dns.AAAA{Hdr: hdr, AAAA: net.ParseIP(val).To16()}) } case dns.TypeCNAME: - for _, val := range vals { + for _, val := range host.Values { m.Answer = append(m.Answer, &dns.CNAME{Hdr: hdr, Target: val}) } + case dns.TypeTXT: + m.Answer = append(m.Answer, &dns.TXT{Hdr: hdr, Txt: host.Values}) } - w.WriteMsg(m) - log.Debug("%s found in hosts file", question.Name) + // Insert into cache before using any middleware + err = h.cache.Set(key, m) + + if err != nil { + log.WithError(err).Error("Unable to insert hosts entry into cache") + } + + // Write the message + h.writeMsg(w, req, m) + + log.WithField("question", question.Name).Debug("Found entry in hosts file") return } else { - log.Debug("%s didn't found in hosts file", question.Name) + log.WithField("question", question.Name).Debug("No entry found in hosts file") } } - key := KeyGen(question) - - mesg, err := h.cache.Get(key) - - if err != nil { - if mesg, err = h.negCache.Get(key); err != nil { - log.Debug("%s didn't hit cache", question.String()) - } else { - log.Debug("%s hit negative cache", question.String()) - dns.HandleFailed(w, req) - return - } - } else { - log.Debug("%s hit cache", question.String()) - // we need this copy against concurrent modification of Id - msg := *mesg - msg.Id = req.Id - w.WriteMsg(&msg) - return - } - mesg, err = h.resolver.Lookup(network, req) if err != nil { - log.Warn("Resolve query error %s", err) - dns.HandleFailed(w, req) + log.WithError(err).Warn("Query resolution error") + + m := new(dns.Msg) + m.SetRcode(req, dns.RcodeServerFailure) + w.WriteMsg(m) // cache the failure, too! if err = h.negCache.Set(key, nil); err != nil { - log.Warn("Set %s negative cache failed: %v", question.String(), err) + log.WithError(err).Warn("Negative cache save failed") } return } - w.WriteMsg(mesg) - + // Cache if mesg.Answer length > 0 + // This is done BEFORE sending it so we don't modify the request first if len(mesg.Answer) > 0 { err = h.cache.Set(key, mesg) - if err != nil { - log.Warn("Set %s cache failed: %s", question.String(), err.Error()) + + fields := log.Fields{ + "question": question.String(), + } + + log.WithFields(fields).Debug("Insert record into cache") + + if err != nil { + fields["error"] = err + + log.WithFields(fields).Warn("Unable to add to cache") + } + } + + // Write message + h.writeMsg(w, req, mesg) +} + +func (h *Handler) update(network string, w dns.ResponseWriter, req *dns.Msg) { + for _, question := range req.Question { + if _, ok := dns.IsDomainName(question.Name); !ok { + continue + } + + for _, rr := range req.Ns { + hdr := rr.Header() + + if hdr.Class == dns.ClassANY && hdr.Rdlength == 0 { + // Delete record + continue + } + + } - log.Debug("Insert %s into cache", question.String()) } } diff --git a/hosts/hosts.go b/hosts/hosts.go index d7ecf66..636f48b 100644 --- a/hosts/hosts.go +++ b/hosts/hosts.go @@ -1,6 +1,7 @@ package hosts import ( + "github.com/miekg/dns" "time" ) @@ -8,8 +9,18 @@ var ( zeroDuration = time.Duration(0) ) +type Host struct { + Type uint16 `json:"type"` + TTL time.Duration `json:"ttl"` + Values []string `json:"values"` +} + +func (h *Host) TypeString() string { + return dns.TypeToString[h.Type] +} + type Hosts interface { - Get(queryType uint16, domain string) ([]string, time.Duration, bool) + Get(queryType uint16, domain string) (*Host, error) } type ProviderList struct { @@ -17,33 +28,26 @@ type ProviderList struct { } type Provider interface { - Get(queryType uint16, domain string) ([]string, time.Duration, bool) - Set(t, domain, value string) (bool, error) + Get(queryType uint16, domain string) (*Host, error) + Set(domain string, host *Host) error } func NewHosts(providers []Provider) Hosts { return &ProviderList{providers} } -/* -Match local /etc/hosts file first, remote redis records second -*/ -func (h *ProviderList) Get(queryType uint16, domain string) ([]string, time.Duration, bool) { - var vals []string - var ok bool - var ttl time.Duration +// Get Matches values to providers, loping each in order +func (h *ProviderList) Get(queryType uint16, domain string) (*Host, error) { + var host *Host + var err error for _, provider := range h.providers { - vals, ttl, ok = provider.Get(queryType, domain) + host, err = provider.Get(queryType, domain) - if ok { + if host != nil { break } } - if vals == nil { - return nil, zeroDuration, false - } - - return vals, ttl, true + return host, err } \ No newline at end of file diff --git a/hosts/hosts_bolt.go b/hosts/hosts_bolt.go new file mode 100644 index 0000000..09ce2eb --- /dev/null +++ b/hosts/hosts_bolt.go @@ -0,0 +1,124 @@ +package hosts + +import ( + "encoding/json" + "errors" + "github.com/miekg/dns" + log "github.com/sirupsen/logrus" + bolt "go.etcd.io/bbolt" + "strings" +) + +const ( + recordBucket = "records" +) + +type BoltHosts struct { + Provider + + db *bolt.DB +} + +func NewBoltProvider(file string) Provider { + db, err := bolt.Open(file, 0600, &bolt.Options{}) + + if err != nil { + log.WithError(err).Fatalln("Unable to open database") + } + + err = db.Update(func(tx *bolt.Tx) error { + _, err := tx.CreateBucketIfNotExists([]byte(recordBucket)) + if err != nil { + return err + } + + return nil + }) + + return &BoltHosts{ + db: db, + } +} + +func (b *BoltHosts) Get(queryType uint16, domain string) (*Host, error) { + log.Debug("Checking bolt provider for %s : %s", queryType, domain) + + domain = strings.ToLower(domain) + + var err error + + key := domain + "_" + dns.TypeToString[queryType] + var v []byte + + err = b.db.View(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte("records")) + + v = b.Get([]byte(key)) + + if string(v) == "" { + return errors.New( "Record not found, key: " + key) + } + + v = b.Get([]byte("*." + key)) + + if string(v) == "" { + return errors.New( "Record not found, key: " + key) + } + + return nil + }) + + if err != nil { + return nil, err + } + + var h []Host + + if err = json.Unmarshal(v, &h); err != nil { + return nil, err + } + + for _, host := range h { + if host.Type == queryType { + return &host, nil + } + } + + return nil, errRecordNotFound +} + +func (b *BoltHosts) Set(domain string, host *Host) error { + err := b.db.Update(func(tx *bolt.Tx) error { + b := tx.Bucket([]byte(recordBucket)) + + hosts := []*Host{host} + + existing := b.Get([]byte(domain)) + + if existing != nil { + err := json.Unmarshal(existing, &hosts) + + if err != nil { + return err + } + + hosts = append(hosts, host) + } + + hostBytes, err := json.Marshal(hosts) + + if err != nil { + return err + } + + err = b.Put([]byte(domain), hostBytes) + + if err != nil { + return err + } + + return nil + }) + + return err +} diff --git a/hosts/hosts_file.go b/hosts/hosts_file.go index c451de5..297a24d 100644 --- a/hosts/hosts_file.go +++ b/hosts/hosts_file.go @@ -6,7 +6,7 @@ import ( "github.com/fsnotify/fsnotify" "github.com/miekg/dns" "github.com/ryanuber/go-glob" - "meow.tf/joker/godns/log" + log "github.com/sirupsen/logrus" "meow.tf/joker/godns/utils" "os" "regexp" @@ -15,11 +15,17 @@ import ( "time" ) +var ( + errUnsupportedType = errors.New("unsupported type") + errRecordNotFound = errors.New("record not found") + errUnsupportedOperation = errors.New("unsupported operation") +) + type FileHosts struct { Provider file string - hosts map[string]string + hosts map[string]Host mu sync.RWMutex ttl time.Duration } @@ -27,7 +33,7 @@ type FileHosts struct { func NewFileProvider(file string, ttl time.Duration) Provider { fp := &FileHosts{ file: file, - hosts: make(map[string]string), + hosts: make(map[string]Host), ttl: ttl, } @@ -51,41 +57,41 @@ func NewFileProvider(file string, ttl time.Duration) Provider { return fp } -func (f *FileHosts) Get(queryType uint16, domain string) ([]string, time.Duration, bool) { +func (f *FileHosts) Get(queryType uint16, domain string) (*Host, error) { log.Debug("Checking file provider for %s : %s", queryType, domain) // Does not support CNAME/TXT/etc if queryType != dns.TypeA && queryType != dns.TypeAAAA { - return nil, zeroDuration, false + return nil, errUnsupportedType } f.mu.RLock() defer f.mu.RUnlock() domain = strings.ToLower(domain) - if ip, ok := f.hosts[domain]; ok { - return strings.Split(ip, ","), f.ttl, true + if host, ok := f.hosts[domain]; ok { + return &host, nil } if idx := strings.Index(domain, "."); idx != -1 { wildcard := "*." + domain[strings.Index(domain, ".") + 1:] - if ip, ok := f.hosts[wildcard]; ok { - return strings.Split(ip, ","), f.ttl, true + if host, ok := f.hosts[wildcard]; ok { + return &host, nil } } - for host, ip := range f.hosts { - if glob.Glob(host, domain) { - return strings.Split(ip, ","), f.ttl, true + for hostname, host := range f.hosts { + if glob.Glob(hostname, domain) { + return &host, nil } } - return nil, time.Duration(0), false + return nil, errRecordNotFound } -func (f *FileHosts) Set(t, domain, value string) (bool, error) { - return false, errors.New("file provider does not support setting values") +func (f *FileHosts) Set(domain string, host *Host) error { + return errUnsupportedOperation } var ( @@ -112,7 +118,7 @@ func (f *FileHosts) Refresh() { for scanner.Scan() { line := strings.TrimSpace(scanner.Text()) - if strings.HasPrefix(line, "#") || line == "" { + if line == "" || line[0] == '#' { continue } @@ -140,12 +146,12 @@ func (f *FileHosts) Refresh() { continue } - f.hosts[strings.ToLower(domain)] = ip + f.hosts[strings.ToLower(domain)] = Host{Values: []string{ip}} } } log.Debug("update hosts records from %s, total %d records.", f.file, len(f.hosts)) } func (f *FileHosts) clear() { - f.hosts = make(map[string]string) + f.hosts = make(map[string]Host) } diff --git a/hosts/hosts_redis.go b/hosts/hosts_redis.go index a78df72..b61abd7 100644 --- a/hosts/hosts_redis.go +++ b/hosts/hosts_redis.go @@ -1,13 +1,10 @@ package hosts import ( + "encoding/json" "github.com/go-redis/redis/v7" - "github.com/miekg/dns" - "github.com/ryanuber/go-glob" - "meow.tf/joker/godns/log" + log "github.com/sirupsen/logrus" "strings" - "sync" - "time" ) type RedisHosts struct { @@ -15,79 +12,75 @@ type RedisHosts struct { redis *redis.Client key string - hosts map[string]string - mu sync.RWMutex - ttl time.Duration } -func NewRedisProvider(rc *redis.Client, key string, ttl time.Duration) Provider { +func NewRedisProvider(rc *redis.Client, key string) Provider { rh := &RedisHosts{ redis: rc, key: key, - hosts: make(map[string]string), - ttl: ttl, } - // Force an initial refresh - rh.Refresh() - return rh } -func (r *RedisHosts) Get(queryType uint16, domain string) ([]string, time.Duration, bool) { +func (r *RedisHosts) Get(queryType uint16, domain string) (*Host, error) { log.Debug("Checking redis provider for %s", domain) - // Don't support queries other than A/AAAA for now - if queryType != dns.TypeA || queryType != dns.TypeAAAA { - return nil, zeroDuration, false - } - - r.mu.RLock() - defer r.mu.RUnlock() - domain = strings.ToLower(domain) - if ip, ok := r.hosts[domain]; ok { - return strings.Split(ip, ","), r.ttl, true + if res, err := r.redis.HGet(r.key, domain).Result(); res != "" && err == nil { + var h []Host + + if err = json.Unmarshal([]byte(res), &h); err != nil { + return nil, err + } + + for _, host := range h { + if host.Type == queryType { + return &host, nil + } + } } if idx := strings.Index(domain, "."); idx != -1 { wildcard := "*." + domain[strings.Index(domain, ".")+1:] - if ip, ok := r.hosts[wildcard]; ok { - return strings.Split(ip, ","), r.ttl, true + if res, err := r.redis.HGet(r.key, wildcard).Result(); res != "" && err == nil { + var h []Host + + if err = json.Unmarshal([]byte(res), &h); err != nil { + return nil, err + } + + for _, host := range h { + if host.Type == queryType { + return &host, nil + } + } } } - for host, ip := range r.hosts { - if glob.Glob(host, domain) { - return strings.Split(ip, ","), r.ttl, true + return nil, errRecordNotFound +} + +func (r *RedisHosts) Set(domain string, host *Host) error { + hosts := []*Host{host} + + if res, err := r.redis.HGet(r.key, domain).Result(); res != "" && err == nil { + if err = json.Unmarshal([]byte(res), &hosts); err != nil { + return err } + + hosts = append(hosts, host) } - return nil, time.Duration(0), false -} + b, err := json.Marshal(hosts) -func (r *RedisHosts) Set(t, domain, ip string) (bool, error) { - r.mu.Lock() - defer r.mu.Unlock() - return r.redis.HSet(r.key, strings.ToLower(domain), []byte(ip)).Result() -} - -func (r *RedisHosts) Refresh() { - r.mu.Lock() - defer r.mu.Unlock() - r.clear() - - var err error - r.hosts, err = r.redis.HGetAll(r.key).Result() if err != nil { - log.Warn("Update hosts records from redis failed %s", err) - } else { - log.Debug("Update hosts records from redis") + return err } -} -func (r *RedisHosts) clear() { - r.hosts = make(map[string]string) -} + _, err = r.redis.HSet(r.key, strings.ToLower(domain), b).Result() + + return err +} \ No newline at end of file diff --git a/log/log.go b/log/log.go deleted file mode 100644 index 4a8cd0d..0000000 --- a/log/log.go +++ /dev/null @@ -1,177 +0,0 @@ -package log - -import ( - "fmt" - "log" - "os" -) - -const LOG_OUTPUT_BUFFER = 1024 - -const ( - LevelDebug = iota - LevelInfo - LevelNotice - LevelWarn - LevelError -) - -var ( - logger *GoDNSLogger -) - -type logMesg struct { - Level int - Mesg string -} - -type LoggerHandler interface { - Setup(config map[string]interface{}) error - Write(mesg *logMesg) -} - -type GoDNSLogger struct { - level int - mesgs chan *logMesg - outputs map[string]LoggerHandler -} - -func NewLogger() *GoDNSLogger { - logger := &GoDNSLogger{ - mesgs: make(chan *logMesg, LOG_OUTPUT_BUFFER), - outputs: make(map[string]LoggerHandler), - } - go logger.Run() - return logger -} - -func (l *GoDNSLogger) SetLogger(handlerType string, config map[string]interface{}) { - var handler LoggerHandler - switch handlerType { - case "console": - handler = NewConsoleHandler() - case "file": - handler = NewFileHandler() - default: - panic("Unknown log handler.") - } - - handler.Setup(config) - l.outputs[handlerType] = handler -} - -func (l *GoDNSLogger) SetLevel(level int) { - l.level = level -} - -func (l *GoDNSLogger) Run() { - for { - select { - case mesg := <-l.mesgs: - for _, handler := range l.outputs { - handler.Write(mesg) - } - } - } -} - -func (l *GoDNSLogger) writeMesg(mesg string, level int) { - if l.level > level { - return - } - - lm := &logMesg{ - Level: level, - Mesg: mesg, - } - - l.mesgs <- lm -} - -func (l *GoDNSLogger) Debug(format string, v ...interface{}) { - mesg := fmt.Sprintf("[DEBUG] "+format, v...) - l.writeMesg(mesg, LevelDebug) -} - -func (l *GoDNSLogger) Info(format string, v ...interface{}) { - mesg := fmt.Sprintf("[INFO] "+format, v...) - l.writeMesg(mesg, LevelInfo) -} - -func (l *GoDNSLogger) Notice(format string, v ...interface{}) { - mesg := fmt.Sprintf("[NOTICE] "+format, v...) - l.writeMesg(mesg, LevelNotice) -} - -func (l *GoDNSLogger) Warn(format string, v ...interface{}) { - mesg := fmt.Sprintf("[WARN] "+format, v...) - l.writeMesg(mesg, LevelWarn) -} - -func (l *GoDNSLogger) Error(format string, v ...interface{}) { - mesg := fmt.Sprintf("[ERROR] "+format, v...) - l.writeMesg(mesg, LevelError) -} - -type ConsoleHandler struct { - level int - logger *log.Logger -} - -func NewConsoleHandler() LoggerHandler { - return new(ConsoleHandler) -} - -func (h *ConsoleHandler) Setup(config map[string]interface{}) error { - if _level, ok := config["level"]; ok { - level := _level.(int) - h.level = level - } - h.logger = log.New(os.Stdout, "", log.Ldate|log.Ltime) - return nil - -} - -func (h *ConsoleHandler) Write(lm *logMesg) { - if h.level <= lm.Level { - h.logger.Println(lm.Mesg) - } -} - -type FileHandler struct { - level int - file string - logger *log.Logger -} - -func NewFileHandler() LoggerHandler { - return new(FileHandler) -} - -func (h *FileHandler) Setup(config map[string]interface{}) error { - if level, ok := config["level"]; ok { - h.level = level.(int) - } - - if file, ok := config["file"]; ok { - h.file = file.(string) - output, err := os.Create(h.file) - if err != nil { - return err - } - - h.logger = log.New(output, "", log.Ldate|log.Ltime) - } - - return nil -} - -func (h *FileHandler) Write(lm *logMesg) { - if h.logger == nil { - return - } - - if h.level <= lm.Level { - h.logger.Println(lm.Mesg) - } -} diff --git a/log/log_test.go b/log/log_test.go deleted file mode 100644 index 79662c1..0000000 --- a/log/log_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package log - -import ( - "bufio" - "os" - "testing" - "time" - - . "github.com/smartystreets/goconvey/convey" -) - -func TestConsole(t *testing.T) { - logger := NewLogger() - logger.SetLogger("console", nil) - logger.SetLevel(LevelInfo) - - logger.Debug("debug") - logger.Info("info") - logger.Notice("notiece") - logger.Warn("warn") - logger.Error("error") -} - -func TestFile(t *testing.T) { - logger := NewLogger() - logger.SetLogger("file", map[string]interface{}{"file": "test.log"}) - logger.SetLevel(LevelInfo) - - logger.Debug("debug") - logger.Info("info") - logger.Notice("notiece") - logger.Warn("warn") - logger.Error("error") - - time.Sleep(time.Second) - - f, err := os.Open("test.log") - if err != nil { - t.Fatal(err) - } - b := bufio.NewReader(f) - linenum := 0 - for { - line, _, err := b.ReadLine() - if err != nil { - break - } - if len(line) > 0 { - linenum++ - } - } - - Convey("Test Log File Handler", t, func() { - Convey("file line nums should be 4", func() { - So(linenum, ShouldEqual, 4) - }) - }) - - os.Remove("test.log") -} diff --git a/log/logger.go b/log/logger.go deleted file mode 100644 index 21eae12..0000000 --- a/log/logger.go +++ /dev/null @@ -1,33 +0,0 @@ -package log - -func init() { - logger = NewLogger() -} - -func Debug(format string, v ...interface{}) { - logger.Debug(format, v...) -} - -func Info(format string, v ...interface{}) { - logger.Info(format, v...) -} - -func Notice(format string, v ...interface{}) { - logger.Notice(format, v...) -} - -func Warn(format string, v ...interface{}) { - logger.Warn(format, v...) -} - -func Error(format string, v ...interface{}) { - logger.Error(format, v...) -} - -func SetLogger(handlerType string, config map[string]interface{}) { - logger.SetLogger(handlerType, config) -} - -func SetLevel(level int) { - logger.SetLevel(level) -} \ No newline at end of file diff --git a/main.go b/main.go index 8c79f80..6e83b02 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,13 @@ package main import ( "flag" - "fmt" "github.com/go-redis/redis/v7" + log "github.com/sirupsen/logrus" "github.com/spf13/viper" + "io" + "meow.tf/joker/godns/api" "meow.tf/joker/godns/cache" "meow.tf/joker/godns/hosts" - "meow.tf/joker/godns/log" "meow.tf/joker/godns/resolver" "meow.tf/joker/godns/settings" "os" @@ -37,7 +38,7 @@ func main() { viper.AutomaticEnv() if err := viper.ReadInConfig(); err == nil { - fmt.Println("Using config file:", viper.ConfigFileUsed()) + log.WithField("file", viper.ConfigFileUsed()).Info("Using configuration from file") } server := &Server{ @@ -47,26 +48,31 @@ func main() { wTimeout: 5 * time.Second, } + var resolverSettings resolver.Settings + + /* + resolver.Settings{ + Timeout: viper.GetInt("resolv.timeout"), + Interval: viper.GetInt("resolv.interval"), + SetEDNS0: viper.GetBool("resolv.edns0"), + ServerListFile: viper.GetStringSlice("resolv.server-list"), + ResolvFile: viper.GetString("resolv.file"), + } + */ + + viper.UnmarshalKey("resolv", &resolverSettings) + var resolverCache, negCache cache.Cache - r := resolver.NewResolver(resolver.Settings{ - Timeout: viper.GetInt("resolv.timeout"), - Interval: viper.GetInt("resolv.interval"), - SetEDNS0: viper.GetBool("resolv.edns0"), - ServerListFile: viper.GetStringSlice("resolv.server-list"), - ResolvFile: viper.GetString("resolv.file"), - }) + r := resolver.NewResolver(resolverSettings) cacheDuration := viper.GetDuration("cache.expire") - redisConfig := settings.RedisSettings{ - Host: viper.GetString("cache.redis.host"), - Port: viper.GetInt("cache.redis.port"), - DB: viper.GetInt("cache.redis.db"), - Password: viper.GetString("cache.redis.password"), - } - backend := viper.GetString("cache.backend") + var redisConfig settings.RedisSettings + + viper.UnmarshalKey("cache.redis", &redisConfig) + switch backend { case "memory": cacheMaxCount := viper.GetInt("cache.memory.maxCount") @@ -79,11 +85,11 @@ func main() { resolverCache = cache.NewMemcachedCache(servers, int32(cacheDuration.Seconds())) negCache = cache.NewMemcachedCache(servers, int32(cacheDuration.Seconds()/2)) case "redis": + resolverCache = cache.NewRedisCache(redisConfig, cacheDuration) negCache = cache.NewRedisCache(redisConfig, cacheDuration/2) default: - log.Error("Invalid cache backend %s", backend) - panic("Invalid cache backend") + log.WithField("backend", backend).Fatalln("Invalid cache backend") } providers := make([]hosts.Provider, 0) @@ -92,17 +98,31 @@ func main() { providers = append(providers, hosts.NewFileProvider(viper.GetString("hosts.file.file"), viper.GetDuration("hosts.file.ttl"))) } + if viper.GetBool("hosts.bolt.enable") { + providers = append(providers, hosts.NewBoltProvider(viper.GetString("hosts.bolt.file"))) + } + if viper.GetBool("hosts.redis.enable") { rc := redis.NewClient(&redis.Options{Addr: redisConfig.Addr(), DB: redisConfig.DB, Password: redisConfig.Password}) providers = append(providers, hosts.NewRedisProvider(rc, viper.GetString("hosts.redis.key"), viper.GetDuration("hosts.redis.ttl"))) } + if viper.GetBool("api.enabled") { + go func() { + err := api.Start() + + if err != nil { + log.WithError(err).Fatalln("Unable to bind API") + } + }() + } + h := hosts.NewHosts(providers) server.Run(NewHandler(r, resolverCache, negCache, h)) - log.Info("godns %s (%s)", Version, runtime.Version()) + log.Infof("joker dns %s (%s)", Version, runtime.Version()) if viper.GetBool("debug") { go profileCPU() @@ -124,10 +144,10 @@ func profileCPU() { } pprof.StartCPUProfile(f) + time.AfterFunc(6*time.Minute, func() { pprof.StopCPUProfile() f.Close() - }) } @@ -148,12 +168,24 @@ func profileMEM() { func initLogger() { if viper.GetBool("log.stdout") { - log.SetLogger("console", nil) + // log.SetLogger("console", nil) } if file := viper.GetString("log.file"); file != "" { - log.SetLogger("file", map[string]interface{}{"file": file}) + f, err := os.Create(file) + + if err != nil { + return + } + + log.SetOutput(io.MultiWriter(f, log.StandardLogger().Out)) } - log.SetLevel(settings.LogLevelFor(viper.GetString("log.level"))) + level, err := log.ParseLevel(viper.GetString("log.level")) + + if err != nil { + return + } + + log.SetLevel(level) } diff --git a/resolver/nameserver.go b/resolver/nameserver.go index 3b5d73a..7e63037 100644 --- a/resolver/nameserver.go +++ b/resolver/nameserver.go @@ -1,5 +1,6 @@ package resolver type Nameserver struct { + net string address string } diff --git a/resolver/resolver.go b/resolver/resolver.go index 87a2213..9714eaa 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -4,7 +4,7 @@ import ( "bufio" "errors" "fmt" - "meow.tf/joker/godns/log" + log "github.com/sirupsen/logrus" "meow.tf/joker/godns/utils" "net" "os" @@ -19,24 +19,29 @@ import ( type ResolvError struct { qname, net string - nameservers []string + nameservers []*Nameserver } func (e ResolvError) Error() string { - errmsg := fmt.Sprintf("%s resolv failed on %s (%s)", e.qname, strings.Join(e.nameservers, "; "), e.net) - return errmsg + nameservers := make([]string, len(e.nameservers)) + + for i, nameserver := range e.nameservers { + nameservers[i] = nameserver.address + } + + return fmt.Sprintf("%s resolv failed on %s (%s)", e.qname, strings.Join(nameservers, "; "), e.net) } type RResp struct { msg *dns.Msg - nameserver string + nameserver *Nameserver rtt time.Duration } type Resolver struct { - servers []string - domain_server *suffixTreeNode - config *Settings + servers []*Nameserver + domainServer *suffixTreeNode + config *Settings clients map[string]*dns.Client clientLock sync.RWMutex @@ -44,9 +49,9 @@ type Resolver struct { func NewResolver(c Settings) *Resolver { r := &Resolver{ - servers: []string{}, - domain_server: newSuffixTreeRoot(), - config: &c, + servers: make([]*Nameserver, 0), + domainServer: newSuffixTreeRoot(), + config: &c, } if len(c.ServerListFile) > 0 { @@ -63,7 +68,7 @@ func NewResolver(c Settings) *Resolver { } for _, server := range clientConfig.Servers { - r.servers = append(r.servers, net.JoinHostPort(server, clientConfig.Port)) + r.servers = append(r.servers, &Nameserver{net: "udp", address: net.JoinHostPort(server, clientConfig.Port)}) } } @@ -92,7 +97,7 @@ func (r *Resolver) parseServerListFile(buf *os.File) { line = strings.TrimSpace(line[idx+1:]) if strings.HasPrefix(line, "https://") { - r.servers = append(r.servers, line) + r.servers = append(r.servers, &Nameserver{net: "https", address: line}) continue } @@ -106,7 +111,7 @@ func (r *Resolver) parseServerListFile(buf *os.File) { continue } - r.domain_server.sinsert(strings.Split(domain, "."), ip) + r.domainServer.sinsert(strings.Split(domain, "."), ip) case 1: srvPort := strings.Split(line, "#") @@ -130,7 +135,7 @@ func (r *Resolver) parseServerListFile(buf *os.File) { port = srvPort[1] } - r.servers = append(r.servers, net.JoinHostPort(ip, port)) + r.servers = append(r.servers, &Nameserver{address: net.JoinHostPort(ip, port)}) } } @@ -159,7 +164,7 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error res := make(chan *RResp, 1) var wg sync.WaitGroup - L := func(resolver *Resolver, nameserver string) { + L := func(resolver *Resolver, nameserver *Nameserver) { defer wg.Done() c, err := resolver.resolverFor(net, nameserver) @@ -169,7 +174,7 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error return } - r, rtt, err := c.Exchange(req, nameserver) + r, rtt, err := c.Exchange(req, nameserver.address) if err != nil { log.Warn("%s socket error on %s", qname, nameserver) @@ -213,18 +218,21 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error wg.Wait() select { case re := <-res: - log.Debug("%s resolv on %s rtt: %v", utils.UnFqdn(qname), re.nameserver, re.rtt) + log.Debug("%s resolv on %s rtt: %v", utils.UnFqdn(qname), re.nameserver.address, re.rtt) return re.msg, nil default: return nil, ResolvError{qname, net, nameservers} } } -func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) { - key := net +func (r *Resolver) resolverFor(network string, n *Nameserver) (*dns.Client, error) { + key := network - if net == "tcp-tls" { - key = net + ":" + nameserver + // Use HTTPS if network is https, or TLS to force secure connections + if n.net == "https" { + key = n.net + } else if n.net == "tcp-tls" { + key = n.net + ":" + n.address } r.clientLock.RLock() @@ -235,21 +243,27 @@ func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) { return client, nil } - if net != "tcp" && net != "tcp-tls" && net != "https" && net != "udp" { + if n.net != "tcp" && n.net != "tcp-tls" && n.net != "https" && n.net != "udp" { return nil, errors.New("unknown network type") } timeout := r.Timeout() client = &dns.Client{ - Net: net, + Net: n.net, ReadTimeout: timeout, WriteTimeout: timeout, } - if strings.HasSuffix(nameserver, ":853") { - client.TLSConfig = &tls.Config{ + if n.net == "tcp-tls" { + host, _, err := net.SplitHostPort(n.address) + if err != nil { + host = n.address + } + + client.TLSConfig = &tls.Config{ + ServerName: host, } } @@ -260,27 +274,23 @@ func (r *Resolver) resolverFor(net, nameserver string) (*dns.Client, error) { return client, nil } -// Namservers return the array of nameservers, with port number appended. +// Nameservers return the array of nameservers, with port number appended. // '#' in the name is treated as port separator, as with dnsmasq. -func (r *Resolver) Nameservers(qname string) []string { +func (r *Resolver) Nameservers(qname string) []*Nameserver { queryKeys := strings.Split(qname, ".") queryKeys = queryKeys[:len(queryKeys)-1] // ignore last '.' - ns := []string{} - if v, found := r.domain_server.search(queryKeys); found { + if v, found := r.domainServer.search(queryKeys); found { log.Debug("%s found in domain server list, upstream: %v", qname, v) - ns = append(ns, net.JoinHostPort(v, "53")) //Ensure query the specific upstream nameserver in async Lookup() function. - return ns + return []*Nameserver{ + {net: "udp", address: net.JoinHostPort(v, "53")}, + } } - for _, nameserver := range r.servers { - ns = append(ns, nameserver) - } - - return ns + return r.servers } func (r *Resolver) Timeout() time.Duration { diff --git a/server.go b/server.go index d4db3b0..412de11 100644 --- a/server.go +++ b/server.go @@ -1,7 +1,7 @@ package main import ( - "meow.tf/joker/godns/log" + log "github.com/sirupsen/logrus" "strings" "time" @@ -49,11 +49,11 @@ func (s *Server) Run(handler *Handler) { } func (s *Server) start(ds *dns.Server) { - log.Info("Start %s listener on %s", ds.Net, ds.Addr) + log.Infof("Start %s listener on %s", ds.Net, ds.Addr) err := ds.ListenAndServe() if err != nil { - log.Error("Start %s listener on %s failed:%s", ds.Net, ds.Addr, err.Error()) + log.Errorf("Start %s listener on %s failed:%s", ds.Net, ds.Addr, err.Error()) } } diff --git a/settings/settings.go b/settings/settings.go index 9b265da..79d349e 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -1,18 +1,9 @@ package settings import ( - "meow.tf/joker/godns/log" "strconv" ) -var LogLevelMap = map[string]int{ - "DEBUG": log.LevelDebug, - "INFO": log.LevelInfo, - "NOTICE": log.LevelNotice, - "WARN": log.LevelWarn, - "ERROR": log.LevelError, -} - type HostsSettings struct { HostsFile string `toml:"host-file" env:"HOSTS_FILE"` RedisEnable bool `toml:"redis-enable" env:"REDIS_HOSTS_ENABLE"` @@ -67,14 +58,6 @@ type LogSettings struct { Level string `toml:"level" env:"LOG_LEVEL"` } -func LogLevelFor(level string) int { - l, ok := LogLevelMap[level] - if !ok { - panic("Config error: invalid log level: " + level) - } - return l -} - type CacheSettings struct { Backend string `toml:"backend" env:"CACHE_BACKEND"` Expire int `toml:"expire" env:"CACHE_EXPIRE"`