mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-04 01:07:49 +02:00
all: support h3:// protocol prefix
This commit is contained in:
committed by
Cuong Manh Le
parent
082d14a9ba
commit
08fe04f1ee
+5
-1
@@ -1473,7 +1473,11 @@ func processNoConfigFlags(noConfigStart bool) {
|
|||||||
|
|
||||||
endpointAndTyp := func(endpoint string) (string, string) {
|
endpointAndTyp := func(endpoint string) (string, string) {
|
||||||
typ := ctrld.ResolverTypeFromEndpoint(endpoint)
|
typ := ctrld.ResolverTypeFromEndpoint(endpoint)
|
||||||
return strings.TrimPrefix(endpoint, "quic://"), typ
|
endpoint = strings.TrimPrefix(endpoint, "quic://")
|
||||||
|
if after, found := strings.CutPrefix(endpoint, "h3://"); found {
|
||||||
|
endpoint = "https://" + after
|
||||||
|
}
|
||||||
|
return endpoint, typ
|
||||||
}
|
}
|
||||||
pEndpoint, pType := endpointAndTyp(primaryUpstream)
|
pEndpoint, pType := endpointAndTyp(primaryUpstream)
|
||||||
upstream := map[string]*ctrld.UpstreamConfig{
|
upstream := map[string]*ctrld.UpstreamConfig{
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ const (
|
|||||||
controlDComDomain = "controld.com"
|
controlDComDomain = "controld.com"
|
||||||
controlDNetDomain = "controld.net"
|
controlDNetDomain = "controld.net"
|
||||||
controlDDevDomain = "controld.dev"
|
controlDDevDomain = "controld.dev"
|
||||||
|
|
||||||
|
endpointPrefixHTTPS = "https://"
|
||||||
|
endpointPrefixQUIC = "quic://"
|
||||||
|
endpointPrefixH3 = "h3://"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -677,12 +681,16 @@ func (uc *UpstreamConfig) netForDNSType(dnsType uint16) (string, string) {
|
|||||||
// initDoHScheme initializes the endpoint scheme for DoH/DoH3 upstream if not present.
|
// initDoHScheme initializes the endpoint scheme for DoH/DoH3 upstream if not present.
|
||||||
func (uc *UpstreamConfig) initDoHScheme() {
|
func (uc *UpstreamConfig) initDoHScheme() {
|
||||||
switch uc.Type {
|
switch uc.Type {
|
||||||
case ResolverTypeDOH, ResolverTypeDOH3:
|
case ResolverTypeDOH:
|
||||||
|
case ResolverTypeDOH3:
|
||||||
|
if after, found := strings.CutPrefix(uc.Endpoint, endpointPrefixH3); found {
|
||||||
|
uc.Endpoint = endpointPrefixHTTPS + after
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !strings.HasPrefix(uc.Endpoint, "https://") {
|
if !strings.HasPrefix(uc.Endpoint, endpointPrefixHTTPS) {
|
||||||
uc.Endpoint = "https://" + uc.Endpoint
|
uc.Endpoint = endpointPrefixHTTPS + uc.Endpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -767,13 +775,16 @@ func defaultPortFor(typ string) string {
|
|||||||
// - If endpoint is an IP address -> ResolverTypeLegacy
|
// - If endpoint is an IP address -> ResolverTypeLegacy
|
||||||
// - If endpoint starts with "https://" -> ResolverTypeDOH
|
// - If endpoint starts with "https://" -> ResolverTypeDOH
|
||||||
// - If endpoint starts with "quic://" -> ResolverTypeDOQ
|
// - If endpoint starts with "quic://" -> ResolverTypeDOQ
|
||||||
|
// - If endpoint starts with "h3://" -> ResolverTypeDOH3
|
||||||
// - For anything else -> ResolverTypeDOT
|
// - For anything else -> ResolverTypeDOT
|
||||||
func ResolverTypeFromEndpoint(endpoint string) string {
|
func ResolverTypeFromEndpoint(endpoint string) string {
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(endpoint, "https://"):
|
case strings.HasPrefix(endpoint, endpointPrefixHTTPS):
|
||||||
return ResolverTypeDOH
|
return ResolverTypeDOH
|
||||||
case strings.HasPrefix(endpoint, "quic://"):
|
case strings.HasPrefix(endpoint, endpointPrefixQUIC):
|
||||||
return ResolverTypeDOQ
|
return ResolverTypeDOQ
|
||||||
|
case strings.HasPrefix(endpoint, endpointPrefixH3):
|
||||||
|
return ResolverTypeDOH3
|
||||||
}
|
}
|
||||||
host := endpoint
|
host := endpoint
|
||||||
if strings.Contains(endpoint, ":") {
|
if strings.Contains(endpoint, ":") {
|
||||||
|
|||||||
@@ -178,6 +178,27 @@ func TestUpstreamConfig_Init(t *testing.T) {
|
|||||||
u: u2,
|
u: u2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"h3",
|
||||||
|
&UpstreamConfig{
|
||||||
|
Name: "doh3",
|
||||||
|
Type: "doh3",
|
||||||
|
Endpoint: "h3://example.com",
|
||||||
|
BootstrapIP: "",
|
||||||
|
Domain: "",
|
||||||
|
Timeout: 0,
|
||||||
|
},
|
||||||
|
&UpstreamConfig{
|
||||||
|
Name: "doh3",
|
||||||
|
Type: "doh3",
|
||||||
|
Endpoint: "https://example.com",
|
||||||
|
BootstrapIP: "",
|
||||||
|
Domain: "example.com",
|
||||||
|
Timeout: 0,
|
||||||
|
IPStack: IpStackBoth,
|
||||||
|
u: u1,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user