From 10c9ccba538c8670793e04ee593fddd30f3bc50b Mon Sep 17 00:00:00 2001 From: Lev Lybin Date: Fri, 19 Jul 2019 20:51:37 +0700 Subject: [PATCH] answer only with requested type --- burst/blockchain.go | 2 +- dns/dns.go | 8 ++++++-- dns/resourse.go | 13 ++++++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/burst/blockchain.go b/burst/blockchain.go index 2c9bc0c..a1488de 100644 --- a/burst/blockchain.go +++ b/burst/blockchain.go @@ -23,7 +23,7 @@ type response struct { Alias string } -var httpClient = &http.Client{Timeout: 5 * time.Second} +var httpClient = &http.Client{Timeout: 10 * time.Second} func getJson(url string, target interface{}) error { r, err := httpClient.Get(url) diff --git a/dns/dns.go b/dns/dns.go index c0f1d86..e231f39 100644 --- a/dns/dns.go +++ b/dns/dns.go @@ -50,6 +50,10 @@ func (s *BurstDNS) answer(addr net.UDPAddr, m dnsmessage.Message) { if records, err := burst.GetRecords(aliasName); err == nil { for _, record := range records { + // return only requested type + if record.Type != dnsTypeToStr(m.Questions[0].Type) { + continue + } req := request{ Host: domain, Type: record.Type, @@ -57,7 +61,7 @@ func (s *BurstDNS) answer(addr net.UDPAddr, m dnsmessage.Message) { TTL: record.TTL, } - res, err := ToResource(req) + res, err := toResource(req) if err != nil { log.Println(err) continue @@ -108,7 +112,7 @@ func (s *BurstDNS) Listen() { continue } - log.Printf("Got request %v, %v from: %s\n", m, m.Header, addr) + //log.Printf("Got request %v, %v from: %s\n", m, m.Header, addr) go s.answer(*addr, m) } diff --git a/dns/resourse.go b/dns/resourse.go index f415e72..7fc7257 100644 --- a/dns/resourse.go +++ b/dns/resourse.go @@ -11,7 +11,7 @@ var ( errUnknownType = errors.New("type unknown") ) -func ToResource(req request) (dnsmessage.Resource, error) { +func toResource(req request) (dnsmessage.Resource, error) { rName, err := dnsmessage.NewName(req.Host) none := dnsmessage.Resource{} if err != nil { @@ -52,3 +52,14 @@ func ToResource(req request) (dnsmessage.Resource, error) { Body: rBody, }, nil } + +func dnsTypeToStr(dnsType dnsmessage.Type) string { + switch dnsType { + case dnsmessage.TypeA: + return "a" + case dnsmessage.TypeAAAA: + return "aaaa" + default: + return "" + } +}