chore: clear config field name (be compatible with old field name)

This commit is contained in:
wwqgtxx 2022-11-26 21:35:47 +08:00
parent ae76daf393
commit 495fd191f2
5 changed files with 67 additions and 70 deletions

View file

@ -236,14 +236,15 @@ proxies:
type: tuic
token: TOKEN
# ip: 127.0.0.1 # for overwriting the DNS lookup result of the server address set in option 'server'
# heartbeat_interval: 10000
# heartbeat-interval: 10000
# alpn: [h3]
# disable_sni: true
reduce_rtt: true
# request_timeout: 8000
udp_relay_mode: native # Available: "native", "quic". Default: "native"
# congestion_controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
# max_udp_relay_packet_size: 1500
# disable-sni: true
reduce-rtt: true
# request-timeout: 8000
udp-relay-mode: native # Available: "native", "quic". Default: "native"
# congestion-controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
# max-udp-relay-packet-size: 1500
# fast-open: true
# skip-cert-verify: true
```

View file

@ -10,7 +10,6 @@ import (
"fmt"
"net"
"os"
"reflect"
"regexp"
"strconv"
"time"
@ -106,13 +105,9 @@ type HysteriaOption struct {
Fingerprint string `proxy:"fingerprint,omitempty"`
ALPN []string `proxy:"alpn,omitempty"`
CustomCA string `proxy:"ca,omitempty"`
OldCustomCAString string `proxy:"ca_str,omitempty"`
CustomCAString string `proxy:"ca-str,omitempty"`
OldReceiveWindowConn int `proxy:"recv_window_conn,omitempty"`
ReceiveWindowConn int `proxy:"recv-window-conn,omitempty"`
OldReceiveWindow int `proxy:"recv_window,omitempty"`
ReceiveWindow int `proxy:"recv-window,omitempty"`
OldDisableMTUDiscovery bool `proxy:"disable_mtu_discovery,omitempty"`
DisableMTUDiscovery bool `proxy:"disable-mtu-discovery,omitempty"`
FastOpen bool `proxy:"fast-open,omitempty"`
}
@ -158,8 +153,8 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
if err != nil {
return nil, fmt.Errorf("hysteria %s load ca error: %w", addr, err)
}
} else if compatibilityValue(option.CustomCAString, option.OldCustomCAString) != "" {
bs = []byte(compatibilityValue(option.CustomCAString, option.OldCustomCAString))
} else if option.CustomCAString != "" {
bs = []byte(option.CustomCAString)
}
if len(bs) > 0 {
@ -190,12 +185,12 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
tlsConfig.NextProtos = []string{DefaultALPN}
}
quicConfig := &quic.Config{
InitialStreamReceiveWindow: uint64(compatibilityValue(option.ReceiveWindowConn, option.OldReceiveWindow)),
MaxStreamReceiveWindow: uint64(compatibilityValue(option.ReceiveWindowConn, option.OldReceiveWindow)),
InitialConnectionReceiveWindow: uint64(compatibilityValue(option.ReceiveWindow, option.OldReceiveWindow)),
MaxConnectionReceiveWindow: uint64(compatibilityValue(option.ReceiveWindow, option.OldReceiveWindow)),
InitialStreamReceiveWindow: uint64(option.ReceiveWindowConn),
MaxStreamReceiveWindow: uint64(option.ReceiveWindowConn),
InitialConnectionReceiveWindow: uint64(option.ReceiveWindow),
MaxConnectionReceiveWindow: uint64(option.ReceiveWindow),
KeepAlivePeriod: 10 * time.Second,
DisablePathMTUDiscovery: compatibilityValue(option.DisableMTUDiscovery, option.OldDisableMTUDiscovery),
DisablePathMTUDiscovery: option.DisableMTUDiscovery,
EnableDatagrams: true,
}
if option.ObfsProtocol != "" {
@ -204,11 +199,11 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
if option.Protocol == "" {
option.Protocol = DefaultProtocol
}
if compatibilityValue( option.ReceiveWindowConn, option.OldReceiveWindowConn)== 0 {
if option.ReceiveWindow == 0 {
quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow / 10
quicConfig.MaxStreamReceiveWindow = DefaultStreamReceiveWindow
}
if compatibilityValue( option.ReceiveWindow,option.OldReceiveWindow) == 0 {
if option.ReceiveWindow == 0 {
quicConfig.InitialConnectionReceiveWindow = DefaultConnectionReceiveWindow / 10
quicConfig.MaxConnectionReceiveWindow = DefaultConnectionReceiveWindow
}
@ -216,7 +211,7 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
log.Infoln("hysteria: Path MTU Discovery is not yet supported on this platform")
}
var auth = []byte(compatibilityValue(option.AuthString, option.OldAuthString))
var auth = []byte(option.AuthString)
if option.Auth != "" {
auth, err = base64.StdEncoding.DecodeString(option.Auth)
if err != nil {
@ -260,13 +255,6 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
}, nil
}
func compatibilityValue[T any](prefer T, fallback T) T {
if reflect.ValueOf(prefer).IsZero() {
return fallback
} else {
return prefer
}
}
func stringToBps(s string) uint64 {
if s == "" {
return 0

View file

@ -38,23 +38,23 @@ type TuicOption struct {
Port int `proxy:"port"`
Token string `proxy:"token"`
Ip string `proxy:"ip,omitempty"`
HeartbeatInterval int `proxy:"heartbeat_interval,omitempty"`
HeartbeatInterval int `proxy:"heartbeat-interval,omitempty"`
ALPN []string `proxy:"alpn,omitempty"`
ReduceRtt bool `proxy:"reduce_rtt,omitempty"`
RequestTimeout int `proxy:"request_timeout,omitempty"`
UdpRelayMode string `proxy:"udp_relay_mode,omitempty"`
CongestionController string `proxy:"congestion_controller,omitempty"`
DisableSni bool `proxy:"disable_sni,omitempty"`
MaxUdpRelayPacketSize int `proxy:"max_udp_relay_packet_size,omitempty"`
ReduceRtt bool `proxy:"reduce-rtt,omitempty"`
RequestTimeout int `proxy:"request-timeout,omitempty"`
UdpRelayMode string `proxy:"udp-relay-mode,omitempty"`
CongestionController string `proxy:"congestion-controller,omitempty"`
DisableSni bool `proxy:"disable-sni,omitempty"`
MaxUdpRelayPacketSize int `proxy:"max-udp-relay-packet-size,omitempty"`
FastOpen bool `proxy:"fast-open,omitempty"`
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
Fingerprint string `proxy:"fingerprint,omitempty"`
CustomCA string `proxy:"ca,omitempty"`
CustomCAString string `proxy:"ca_str,omitempty"`
ReceiveWindowConn int `proxy:"recv_window_conn,omitempty"`
ReceiveWindow int `proxy:"recv_window,omitempty"`
DisableMTUDiscovery bool `proxy:"disable_mtu_discovery,omitempty"`
CustomCAString string `proxy:"ca-str,omitempty"`
ReceiveWindowConn int `proxy:"recv-window-conn,omitempty"`
ReceiveWindow int `proxy:"recv-window,omitempty"`
DisableMTUDiscovery bool `proxy:"disable-mtu-discovery,omitempty"`
}
// DialContext implements C.ProxyAdapter

View file

@ -2,6 +2,7 @@ package adapter
import (
"fmt"
"strings"
"github.com/Dreamacro/clash/adapter/outbound"
"github.com/Dreamacro/clash/common/structure"
@ -9,6 +10,12 @@ import (
)
func ParseProxy(mapping map[string]any) (C.Proxy, error) {
newMapping := make(map[string]any)
for key := range mapping {
newMapping[strings.ReplaceAll(key, "_", "-")] = mapping[key]
}
mapping = newMapping
decoder := structure.NewDecoder(structure.Option{TagName: "proxy", WeaklyTypedInput: true})
proxyType, existType := mapping["type"].(string)
if !existType {

View file

@ -469,14 +469,15 @@ proxies:
type: tuic
token: TOKEN
# ip: 127.0.0.1 # for overwriting the DNS lookup result of the server address set in option 'server'
# heartbeat_interval: 10000
# heartbeat-interval: 10000
# alpn: [h3]
# disable_sni: true
reduce_rtt: true
# request_timeout: 8000
udp_relay_mode: native # Available: "native", "quic". Default: "native"
# congestion_controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
# max_udp_relay_packet_size: 1500
# disable-sni: true
reduce-rtt: true
# request-timeout: 8000
udp-relay-mode: native # Available: "native", "quic". Default: "native"
# congestion-controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
# max-udp-relay-packet-size: 1500
# fast-open: true
# skip-cert-verify: true
# ShadowsocksR