Feature: support DoH

This commit is contained in:
Dreamacro
2019-06-28 12:29:08 +08:00
parent 662038e40e
commit bc3fc0c840
8 changed files with 412 additions and 260 deletions

View File

@ -1,6 +1,7 @@
package dns
import (
"crypto/tls"
"encoding/json"
"errors"
"time"
@ -107,3 +108,34 @@ func setMsgTTL(msg *D.Msg, ttl uint32) {
extra.Header().Ttl = ttl
}
}
func isIPRequest(q D.Question) bool {
if q.Qclass == D.ClassINET && (q.Qtype == D.TypeA || q.Qtype == D.TypeAAAA) {
return true
}
return false
}
func transform(servers []NameServer) []resolver {
ret := []resolver{}
for _, s := range servers {
if s.Net == "https" {
ret = append(ret, &dohClient{url: s.Addr})
continue
}
ret = append(ret, &client{
Client: &D.Client{
Net: s.Net,
TLSConfig: &tls.Config{
ClientSessionCache: globalSessionCache,
// alpn identifier, see https://tools.ietf.org/html/draft-hoffman-dprive-dns-tls-alpn-00#page-6
NextProtos: []string{"dns"},
},
UDPSize: 4096,
},
Address: s.Addr,
})
}
return ret
}