1
0
mirror of https://github.com/fumiama/terasu.git synced 2026-06-09 12:40:29 +08:00

fix: error on different frag lens

This commit is contained in:
源文雨
2025-10-23 23:33:06 +08:00
parent 3f56d5341b
commit bda0c8de97
9 changed files with 206 additions and 33 deletions

View File

@@ -6,6 +6,7 @@ import (
"crypto/tls"
"errors"
"net"
"slices"
"strings"
"sync"
"syscall"
@@ -27,6 +28,7 @@ var dnsDialer = net.Dialer{
Timeout: time.Second * 4,
}
// SetTimeout ...
func SetTimeout(t time.Duration) {
dnsDialer.Timeout = t
}
@@ -37,6 +39,7 @@ type dnsstat struct {
keep bool
}
// String ...
func (ds *dnsstat) String() string {
sb := strings.Builder{}
sb.WriteString("[addr: ")
@@ -78,6 +81,7 @@ func (ds *dnsstat) disable(reEnable time.Duration) {
})
}
// DNSList is a bundle of DNSs
type DNSList struct {
sync.RWMutex
hostseq []string
@@ -85,6 +89,7 @@ type DNSList struct {
b map[string][]string
}
// DNSConfig is the user config
type DNSConfig struct {
Servers map[string][]string `yaml:"Servers"` // Servers map[dot.com]ip:ports
Fallbacks map[string][]string `yaml:"Fallbacks"` // Fallbacks map[domain]ips
@@ -102,14 +107,10 @@ func hasrecord(lst []*dnsstat, a string) bool {
// hasrecord no lock, use under lock
func hasfallback(lst []string, a string) bool {
for _, addr := range lst {
if addr == a {
return true
}
}
return false
return slices.Contains(lst, a)
}
// Add ...
func (ds *DNSList) Add(c *DNSConfig) {
ds.Lock()
defer ds.Unlock()
@@ -193,6 +194,7 @@ func (ds *DNSList) lookupHostDoH(ctx context.Context, host string) (hosts []stri
return nil, ErrNoDNSAvailable
}
// DialContext ...
func (ds *DNSList) DialContext(ctx context.Context, dialer *net.Dialer) (tlsConn *tls.Conn, err error) {
err = ErrNoDNSAvailable
@@ -267,6 +269,7 @@ func (ds *DNSList) DialContext(ctx context.Context, dialer *net.Dialer) (tlsConn
return
}
// IPv6Servers should only be used when IPv6 is available
var IPv6Servers = DNSList{
hostseq: []string{
"dot.sb", "dns.google", "cloudflare-dns.com", "dns.opendns.com", "dns10.quad9.net",
@@ -303,6 +306,7 @@ var IPv6Servers = DNSList{
b: map[string][]string{},
}
// IPv4Servers is the default server set
var IPv4Servers = DNSList{
hostseq: []string{
"dot.sb", "dns.google", "cloudflare-dns.com", "dns.opendns.com", "dns10.quad9.net",
@@ -339,6 +343,7 @@ var IPv4Servers = DNSList{
b: map[string][]string{},
}
// DefaultResolver ...
var DefaultResolver = &net.Resolver{
PreferGo: true,
Dial: func(ctx context.Context, nw, _ string) (net.Conn, error) {

View File

@@ -18,6 +18,7 @@ import (
)
var (
// ErrEmptyHostAddress ...
ErrEmptyHostAddress = errors.New("empty host addr")
)
@@ -29,25 +30,43 @@ const (
recordTypeAAAA recordType = 28
)
// dohjsonresponse represents the JSON response structure for DNS over HTTPS (DoH) queries.
// It contains DNS query results and metadata about the response.
type dohjsonresponse struct {
Status uint32
TC bool
RD bool
RA bool
AD bool
CD bool
// Status indicates the DNS query status code (0 = NOERROR, etc.)
Status uint32
// TC indicates whether the response was truncated (true if truncated)
TC bool
// RD indicates whether recursion was requested in the query
RD bool
// RA indicates whether the server supports recursion
RA bool
// AD indicates whether the response was authenticated (DNSSEC)
AD bool
// CD indicates whether the client requested that DNSSEC validation be disabled
CD bool
// Question contains the DNS query question section with name and type
Question []struct {
Name string `json:"name"`
// Name is the domain name being queried
Name string `json:"name"`
// Type is the DNS record type being requested (A, AAAA, etc.)
Type recordType `json:"type"`
}
// Answer contains the DNS response answer section with resource records
Answer []struct {
Name string `json:"name"`
// Name is the domain name for this resource record
Name string `json:"name"`
// Type is the DNS record type (A, AAAA, etc.)
Type recordType `json:"type"`
TTL uint16
// TTL is the time-to-live value for this resource record in seconds
TTL uint16
// Data is the textual representation of the resource record data
Data string `json:"data"`
}
// EdnsClientSubnet is the EDNS client subnet information for geolocation
EdnsClientSubnet string `json:"edns_client_subnet"`
Comment string
// Comment is an optional comment field for additional information
Comment string
}
func (jr *dohjsonresponse) hosts() []string {