mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
Use internet.DialSystem
Due to https://github.com/v2fly/v2ray-core/pull/3162#issuecomment-2355879556
This commit is contained in:
parent
9357bed8cf
commit
72892dac2f
@ -5,6 +5,7 @@ package tls
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"io"
|
"io"
|
||||||
@ -15,6 +16,8 @@ import (
|
|||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/xtls/xray-core/common/errors"
|
"github.com/xtls/xray-core/common/errors"
|
||||||
|
"github.com/xtls/xray-core/common/net"
|
||||||
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ApplyECH(c *Config, config *tls.Config) error {
|
func ApplyECH(c *Config, config *tls.Config) error {
|
||||||
@ -58,6 +61,7 @@ func QueryRecord(domain string, server string) (string, error) {
|
|||||||
}
|
}
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
errors.LogDebug(context.Background(), "Tring to query ECH config for domain: ", domain, " with ECH server: ", server)
|
||||||
record, ttl, err := dohQuery(server, domain)
|
record, ttl, err := dohQuery(server, domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -79,8 +83,24 @@ func dohQuery(server string, domain string) (string, uint32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
}
|
}
|
||||||
|
tr := &http.Transport{
|
||||||
|
IdleConnTimeout: 90 * time.Second,
|
||||||
|
ForceAttemptHTTP2: true,
|
||||||
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
|
dest, err := net.ParseDestination(network + ":" + addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
conn, err := internet.DialSystem(ctx, dest, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return conn, nil
|
||||||
|
},
|
||||||
|
}
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
|
Transport: tr,
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest("POST", server, bytes.NewReader(msg))
|
req, err := http.NewRequest("POST", server, bytes.NewReader(msg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,6 +128,7 @@ func dohQuery(server string, domain string) (string, uint32, error) {
|
|||||||
re := regexp.MustCompile(`ech="([^"]+)"`)
|
re := regexp.MustCompile(`ech="([^"]+)"`)
|
||||||
match := re.FindStringSubmatch(respMsg.Answer[0].String())
|
match := re.FindStringSubmatch(respMsg.Answer[0].String())
|
||||||
if match[1] != "" {
|
if match[1] != "" {
|
||||||
|
errors.LogDebug(context.Background(), "Get ECH config:", match[1], " TTL:", respMsg.Answer[0].Header().Ttl)
|
||||||
return match[1], respMsg.Answer[0].Header().Ttl, nil
|
return match[1], respMsg.Answer[0].Header().Ttl, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user