DNS: Fix some bugs; Refactors; Optimizations (#4659)

This commit is contained in:
patterniha 2025-04-29 12:09:57 +03:30 committed by GitHub
parent 1c4e246788
commit aa4134f4a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 658 additions and 978 deletions

View file

@ -16,24 +16,23 @@ import (
func TestQUICNameServer(t *testing.T) {
url, err := url.Parse("quic://dns.adguard-dns.com")
common.Must(err)
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP)
s, err := NewQUICNameServer(url, false, net.IP(nil))
common.Must(err)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
ips, _, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns.IPOption{
ips, _, err := s.QueryIP(ctx, "google.com", dns.IPOption{
IPv4Enable: true,
IPv6Enable: true,
}, false)
})
cancel()
common.Must(err)
if len(ips) == 0 {
t.Error("expect some ips, but got 0")
}
ctx2, cancel := context.WithTimeout(context.Background(), time.Second*5)
ips2, _, err := s.QueryIP(ctx2, "google.com", net.IP(nil), dns.IPOption{
ips2, _, err := s.QueryIP(ctx2, "google.com", dns.IPOption{
IPv4Enable: true,
IPv6Enable: true,
}, true)
})
cancel()
common.Must(err)
if r := cmp.Diff(ips2, ips); r != "" {
@ -44,13 +43,13 @@ func TestQUICNameServer(t *testing.T) {
func TestQUICNameServerWithIPv4Override(t *testing.T) {
url, err := url.Parse("quic://dns.adguard-dns.com")
common.Must(err)
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP4)
s, err := NewQUICNameServer(url, false, net.IP(nil))
common.Must(err)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
ips, _, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns.IPOption{
ips, _, err := s.QueryIP(ctx, "google.com", dns.IPOption{
IPv4Enable: true,
IPv6Enable: true,
}, false)
IPv6Enable: false,
})
cancel()
common.Must(err)
if len(ips) == 0 {
@ -67,13 +66,13 @@ func TestQUICNameServerWithIPv4Override(t *testing.T) {
func TestQUICNameServerWithIPv6Override(t *testing.T) {
url, err := url.Parse("quic://dns.adguard-dns.com")
common.Must(err)
s, err := NewQUICNameServer(url, QueryStrategy_USE_IP6)
s, err := NewQUICNameServer(url, false, net.IP(nil))
common.Must(err)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
ips, _, err := s.QueryIP(ctx, "google.com", net.IP(nil), dns.IPOption{
IPv4Enable: true,
ips, _, err := s.QueryIP(ctx, "google.com", dns.IPOption{
IPv4Enable: false,
IPv6Enable: true,
}, false)
})
cancel()
common.Must(err)
if len(ips) == 0 {