chore: clear config field name (be compatible with old field name)
This commit is contained in:
parent
ae76daf393
commit
495fd191f2
5 changed files with 67 additions and 70 deletions
15
README.md
15
README.md
|
@ -236,14 +236,15 @@ proxies:
|
||||||
type: tuic
|
type: tuic
|
||||||
token: TOKEN
|
token: TOKEN
|
||||||
# ip: 127.0.0.1 # for overwriting the DNS lookup result of the server address set in option 'server'
|
# 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]
|
# alpn: [h3]
|
||||||
# disable_sni: true
|
# disable-sni: true
|
||||||
reduce_rtt: true
|
reduce-rtt: true
|
||||||
# request_timeout: 8000
|
# request-timeout: 8000
|
||||||
udp_relay_mode: native # Available: "native", "quic". Default: "native"
|
udp-relay-mode: native # Available: "native", "quic". Default: "native"
|
||||||
# congestion_controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
|
# congestion-controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
|
||||||
# max_udp_relay_packet_size: 1500
|
# max-udp-relay-packet-size: 1500
|
||||||
|
# fast-open: true
|
||||||
# skip-cert-verify: true
|
# skip-cert-verify: true
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -88,33 +87,29 @@ func (h *Hysteria) ListenPacketContext(ctx context.Context, metadata *C.Metadata
|
||||||
|
|
||||||
type HysteriaOption struct {
|
type HysteriaOption struct {
|
||||||
BasicOption
|
BasicOption
|
||||||
Name string `proxy:"name"`
|
Name string `proxy:"name"`
|
||||||
Server string `proxy:"server"`
|
Server string `proxy:"server"`
|
||||||
Port int `proxy:"port"`
|
Port int `proxy:"port"`
|
||||||
Protocol string `proxy:"protocol,omitempty"`
|
Protocol string `proxy:"protocol,omitempty"`
|
||||||
ObfsProtocol string `proxy:"obfs-protocol,omitempty"` // compatible with Stash
|
ObfsProtocol string `proxy:"obfs-protocol,omitempty"` // compatible with Stash
|
||||||
Up string `proxy:"up"`
|
Up string `proxy:"up"`
|
||||||
UpSpeed int `proxy:"up-speed,omitempty"` // compatible with Stash
|
UpSpeed int `proxy:"up-speed,omitempty"` // compatible with Stash
|
||||||
Down string `proxy:"down"`
|
Down string `proxy:"down"`
|
||||||
DownSpeed int `proxy:"down-speed,omitempty"` // compatible with Stash
|
DownSpeed int `proxy:"down-speed,omitempty"` // compatible with Stash
|
||||||
Auth string `proxy:"auth,omitempty"`
|
Auth string `proxy:"auth,omitempty"`
|
||||||
OldAuthString string `proxy:"auth_str,omitempty"`
|
OldAuthString string `proxy:"auth_str,omitempty"`
|
||||||
AuthString string `proxy:"auth-str,omitempty"`
|
AuthString string `proxy:"auth-str,omitempty"`
|
||||||
Obfs string `proxy:"obfs,omitempty"`
|
Obfs string `proxy:"obfs,omitempty"`
|
||||||
SNI string `proxy:"sni,omitempty"`
|
SNI string `proxy:"sni,omitempty"`
|
||||||
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
|
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
|
||||||
Fingerprint string `proxy:"fingerprint,omitempty"`
|
Fingerprint string `proxy:"fingerprint,omitempty"`
|
||||||
ALPN []string `proxy:"alpn,omitempty"`
|
ALPN []string `proxy:"alpn,omitempty"`
|
||||||
CustomCA string `proxy:"ca,omitempty"`
|
CustomCA string `proxy:"ca,omitempty"`
|
||||||
OldCustomCAString string `proxy:"ca_str,omitempty"`
|
CustomCAString string `proxy:"ca-str,omitempty"`
|
||||||
CustomCAString string `proxy:"ca-str,omitempty"`
|
ReceiveWindowConn int `proxy:"recv-window-conn,omitempty"`
|
||||||
OldReceiveWindowConn int `proxy:"recv_window_conn,omitempty"`
|
ReceiveWindow int `proxy:"recv-window,omitempty"`
|
||||||
ReceiveWindowConn int `proxy:"recv-window-conn,omitempty"`
|
DisableMTUDiscovery bool `proxy:"disable-mtu-discovery,omitempty"`
|
||||||
OldReceiveWindow int `proxy:"recv_window,omitempty"`
|
FastOpen bool `proxy:"fast-open,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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HysteriaOption) Speed() (uint64, uint64, error) {
|
func (c *HysteriaOption) Speed() (uint64, uint64, error) {
|
||||||
|
@ -158,8 +153,8 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("hysteria %s load ca error: %w", addr, err)
|
return nil, fmt.Errorf("hysteria %s load ca error: %w", addr, err)
|
||||||
}
|
}
|
||||||
} else if compatibilityValue(option.CustomCAString, option.OldCustomCAString) != "" {
|
} else if option.CustomCAString != "" {
|
||||||
bs = []byte(compatibilityValue(option.CustomCAString, option.OldCustomCAString))
|
bs = []byte(option.CustomCAString)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(bs) > 0 {
|
if len(bs) > 0 {
|
||||||
|
@ -190,12 +185,12 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
|
||||||
tlsConfig.NextProtos = []string{DefaultALPN}
|
tlsConfig.NextProtos = []string{DefaultALPN}
|
||||||
}
|
}
|
||||||
quicConfig := &quic.Config{
|
quicConfig := &quic.Config{
|
||||||
InitialStreamReceiveWindow: uint64(compatibilityValue(option.ReceiveWindowConn, option.OldReceiveWindow)),
|
InitialStreamReceiveWindow: uint64(option.ReceiveWindowConn),
|
||||||
MaxStreamReceiveWindow: uint64(compatibilityValue(option.ReceiveWindowConn, option.OldReceiveWindow)),
|
MaxStreamReceiveWindow: uint64(option.ReceiveWindowConn),
|
||||||
InitialConnectionReceiveWindow: uint64(compatibilityValue(option.ReceiveWindow, option.OldReceiveWindow)),
|
InitialConnectionReceiveWindow: uint64(option.ReceiveWindow),
|
||||||
MaxConnectionReceiveWindow: uint64(compatibilityValue(option.ReceiveWindow, option.OldReceiveWindow)),
|
MaxConnectionReceiveWindow: uint64(option.ReceiveWindow),
|
||||||
KeepAlivePeriod: 10 * time.Second,
|
KeepAlivePeriod: 10 * time.Second,
|
||||||
DisablePathMTUDiscovery: compatibilityValue(option.DisableMTUDiscovery, option.OldDisableMTUDiscovery),
|
DisablePathMTUDiscovery: option.DisableMTUDiscovery,
|
||||||
EnableDatagrams: true,
|
EnableDatagrams: true,
|
||||||
}
|
}
|
||||||
if option.ObfsProtocol != "" {
|
if option.ObfsProtocol != "" {
|
||||||
|
@ -204,11 +199,11 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
|
||||||
if option.Protocol == "" {
|
if option.Protocol == "" {
|
||||||
option.Protocol = DefaultProtocol
|
option.Protocol = DefaultProtocol
|
||||||
}
|
}
|
||||||
if compatibilityValue( option.ReceiveWindowConn, option.OldReceiveWindowConn)== 0 {
|
if option.ReceiveWindow == 0 {
|
||||||
quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow / 10
|
quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow / 10
|
||||||
quicConfig.MaxStreamReceiveWindow = DefaultStreamReceiveWindow
|
quicConfig.MaxStreamReceiveWindow = DefaultStreamReceiveWindow
|
||||||
}
|
}
|
||||||
if compatibilityValue( option.ReceiveWindow,option.OldReceiveWindow) == 0 {
|
if option.ReceiveWindow == 0 {
|
||||||
quicConfig.InitialConnectionReceiveWindow = DefaultConnectionReceiveWindow / 10
|
quicConfig.InitialConnectionReceiveWindow = DefaultConnectionReceiveWindow / 10
|
||||||
quicConfig.MaxConnectionReceiveWindow = DefaultConnectionReceiveWindow
|
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")
|
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 != "" {
|
if option.Auth != "" {
|
||||||
auth, err = base64.StdEncoding.DecodeString(option.Auth)
|
auth, err = base64.StdEncoding.DecodeString(option.Auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -260,13 +255,6 @@ func NewHysteria(option HysteriaOption) (*Hysteria, error) {
|
||||||
}, nil
|
}, 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 {
|
func stringToBps(s string) uint64 {
|
||||||
if s == "" {
|
if s == "" {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -38,23 +38,23 @@ type TuicOption struct {
|
||||||
Port int `proxy:"port"`
|
Port int `proxy:"port"`
|
||||||
Token string `proxy:"token"`
|
Token string `proxy:"token"`
|
||||||
Ip string `proxy:"ip,omitempty"`
|
Ip string `proxy:"ip,omitempty"`
|
||||||
HeartbeatInterval int `proxy:"heartbeat_interval,omitempty"`
|
HeartbeatInterval int `proxy:"heartbeat-interval,omitempty"`
|
||||||
ALPN []string `proxy:"alpn,omitempty"`
|
ALPN []string `proxy:"alpn,omitempty"`
|
||||||
ReduceRtt bool `proxy:"reduce_rtt,omitempty"`
|
ReduceRtt bool `proxy:"reduce-rtt,omitempty"`
|
||||||
RequestTimeout int `proxy:"request_timeout,omitempty"`
|
RequestTimeout int `proxy:"request-timeout,omitempty"`
|
||||||
UdpRelayMode string `proxy:"udp_relay_mode,omitempty"`
|
UdpRelayMode string `proxy:"udp-relay-mode,omitempty"`
|
||||||
CongestionController string `proxy:"congestion_controller,omitempty"`
|
CongestionController string `proxy:"congestion-controller,omitempty"`
|
||||||
DisableSni bool `proxy:"disable_sni,omitempty"`
|
DisableSni bool `proxy:"disable-sni,omitempty"`
|
||||||
MaxUdpRelayPacketSize int `proxy:"max_udp_relay_packet_size,omitempty"`
|
MaxUdpRelayPacketSize int `proxy:"max-udp-relay-packet-size,omitempty"`
|
||||||
|
|
||||||
FastOpen bool `proxy:"fast-open,omitempty"`
|
FastOpen bool `proxy:"fast-open,omitempty"`
|
||||||
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
|
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
|
||||||
Fingerprint string `proxy:"fingerprint,omitempty"`
|
Fingerprint string `proxy:"fingerprint,omitempty"`
|
||||||
CustomCA string `proxy:"ca,omitempty"`
|
CustomCA string `proxy:"ca,omitempty"`
|
||||||
CustomCAString string `proxy:"ca_str,omitempty"`
|
CustomCAString string `proxy:"ca-str,omitempty"`
|
||||||
ReceiveWindowConn int `proxy:"recv_window_conn,omitempty"`
|
ReceiveWindowConn int `proxy:"recv-window-conn,omitempty"`
|
||||||
ReceiveWindow int `proxy:"recv_window,omitempty"`
|
ReceiveWindow int `proxy:"recv-window,omitempty"`
|
||||||
DisableMTUDiscovery bool `proxy:"disable_mtu_discovery,omitempty"`
|
DisableMTUDiscovery bool `proxy:"disable-mtu-discovery,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DialContext implements C.ProxyAdapter
|
// DialContext implements C.ProxyAdapter
|
||||||
|
|
|
@ -2,6 +2,7 @@ package adapter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Dreamacro/clash/adapter/outbound"
|
"github.com/Dreamacro/clash/adapter/outbound"
|
||||||
"github.com/Dreamacro/clash/common/structure"
|
"github.com/Dreamacro/clash/common/structure"
|
||||||
|
@ -9,6 +10,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseProxy(mapping map[string]any) (C.Proxy, error) {
|
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})
|
decoder := structure.NewDecoder(structure.Option{TagName: "proxy", WeaklyTypedInput: true})
|
||||||
proxyType, existType := mapping["type"].(string)
|
proxyType, existType := mapping["type"].(string)
|
||||||
if !existType {
|
if !existType {
|
||||||
|
|
|
@ -469,14 +469,15 @@ proxies:
|
||||||
type: tuic
|
type: tuic
|
||||||
token: TOKEN
|
token: TOKEN
|
||||||
# ip: 127.0.0.1 # for overwriting the DNS lookup result of the server address set in option 'server'
|
# 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]
|
# alpn: [h3]
|
||||||
# disable_sni: true
|
# disable-sni: true
|
||||||
reduce_rtt: true
|
reduce-rtt: true
|
||||||
# request_timeout: 8000
|
# request-timeout: 8000
|
||||||
udp_relay_mode: native # Available: "native", "quic". Default: "native"
|
udp-relay-mode: native # Available: "native", "quic". Default: "native"
|
||||||
# congestion_controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
|
# congestion-controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
|
||||||
# max_udp_relay_packet_size: 1500
|
# max-udp-relay-packet-size: 1500
|
||||||
|
# fast-open: true
|
||||||
# skip-cert-verify: true
|
# skip-cert-verify: true
|
||||||
|
|
||||||
# ShadowsocksR
|
# ShadowsocksR
|
||||||
|
|
Loading…
Reference in a new issue