diff --git a/adapter/outbound/tuic.go b/adapter/outbound/tuic.go index 97938014c..264c991be 100644 --- a/adapter/outbound/tuic.go +++ b/adapter/outbound/tuic.go @@ -169,12 +169,12 @@ func NewTuic(option TuicOption) (*Tuic, error) { EnableDatagrams: true, } if option.ReceiveWindowConn == 0 { - quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow / 10 - quicConfig.MaxStreamReceiveWindow = DefaultStreamReceiveWindow + quicConfig.InitialStreamReceiveWindow = tuic.DefaultStreamReceiveWindow / 10 + quicConfig.MaxStreamReceiveWindow = tuic.DefaultStreamReceiveWindow } if option.ReceiveWindow == 0 { - quicConfig.InitialConnectionReceiveWindow = DefaultConnectionReceiveWindow / 10 - quicConfig.MaxConnectionReceiveWindow = DefaultConnectionReceiveWindow + quicConfig.InitialConnectionReceiveWindow = tuic.DefaultConnectionReceiveWindow / 10 + quicConfig.MaxConnectionReceiveWindow = tuic.DefaultConnectionReceiveWindow } if len(option.Ip) > 0 { diff --git a/common/structure/structure.go b/common/structure/structure.go index 2b5e024f4..958ad54b5 100644 --- a/common/structure/structure.go +++ b/common/structure/structure.go @@ -49,12 +49,12 @@ func (d *Decoder) Decode(src map[string]any, dst any) error { key, omitKey, found := strings.Cut(tag, ",") omitempty := found && omitKey == "omitempty" - if d.option.KeyReplacer != nil { - key = d.option.KeyReplacer.Replace(key) - } - value, ok := src[key] if !ok { + if d.option.KeyReplacer != nil { + key = d.option.KeyReplacer.Replace(key) + } + for _strKey := range src { strKey := _strKey if d.option.KeyReplacer != nil { @@ -364,9 +364,6 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e tagValue = strings.SplitN(tagValue, ",", 2)[0] if tagValue != "" { fieldName = tagValue - if d.option.KeyReplacer != nil { - fieldName = d.option.KeyReplacer.Replace(fieldName) - } } rawMapKey := reflect.ValueOf(fieldName) @@ -374,6 +371,9 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e if !rawMapVal.IsValid() { // Do a slower search by iterating over each key and // doing case-insensitive search. + if d.option.KeyReplacer != nil { + fieldName = d.option.KeyReplacer.Replace(fieldName) + } for dataValKey := range dataValKeys { mK, ok := dataValKey.Interface().(string) if !ok { diff --git a/listener/tuic/server.go b/listener/tuic/server.go index 870c9f806..64ec84896 100644 --- a/listener/tuic/server.go +++ b/listener/tuic/server.go @@ -17,11 +17,6 @@ import ( "github.com/Dreamacro/clash/transport/tuic" ) -const ( - DefaultStreamReceiveWindow = 15728640 // 15 MB/s - DefaultConnectionReceiveWindow = 67108864 // 64 MB/s -) - type Listener struct { closed bool config config.TuicServer @@ -49,10 +44,10 @@ func New(config config.TuicServer, tcpIn chan<- C.ConnContext, udpIn chan<- *inb MaxIncomingUniStreams: 1 >> 32, EnableDatagrams: true, } - quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow / 10 - quicConfig.MaxStreamReceiveWindow = DefaultStreamReceiveWindow - quicConfig.InitialConnectionReceiveWindow = DefaultConnectionReceiveWindow / 10 - quicConfig.MaxConnectionReceiveWindow = DefaultConnectionReceiveWindow + quicConfig.InitialStreamReceiveWindow = tuic.DefaultStreamReceiveWindow / 10 + quicConfig.MaxStreamReceiveWindow = tuic.DefaultStreamReceiveWindow + quicConfig.InitialConnectionReceiveWindow = tuic.DefaultConnectionReceiveWindow / 10 + quicConfig.MaxConnectionReceiveWindow = tuic.DefaultConnectionReceiveWindow tokens := make([][32]byte, len(config.Token)) for i, token := range config.Token { diff --git a/transport/tuic/conn.go b/transport/tuic/conn.go index b030c3d83..3e759f25d 100644 --- a/transport/tuic/conn.go +++ b/transport/tuic/conn.go @@ -15,6 +15,11 @@ import ( "github.com/Dreamacro/clash/transport/tuic/congestion" ) +const ( + DefaultStreamReceiveWindow = 15728640 // 15 MB/s + DefaultConnectionReceiveWindow = 67108864 // 64 MB/s +) + func SetCongestionController(quicConn quic.Connection, cc string) { switch cc { case "cubic":