mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-28 15:30:02 +00:00
chore: minor code tweaks
This commit is contained in:
parent
4cd18e6685
commit
4b2fd55060
@ -75,14 +75,14 @@ func client(config *clientConfig) {
|
|||||||
MaxStreamReceiveWindow: config.ReceiveWindowConn,
|
MaxStreamReceiveWindow: config.ReceiveWindowConn,
|
||||||
InitialConnectionReceiveWindow: config.ReceiveWindow,
|
InitialConnectionReceiveWindow: config.ReceiveWindow,
|
||||||
MaxConnectionReceiveWindow: config.ReceiveWindow,
|
MaxConnectionReceiveWindow: config.ReceiveWindow,
|
||||||
HandshakeIdleTimeout: time.Duration(config.QUICSettings.HandshakeIdleTimeout) * time.Second,
|
HandshakeIdleTimeout: time.Duration(config.Connectivity.HandshakeIdleTimeout) * time.Second,
|
||||||
MaxIdleTimeout: time.Duration(config.QUICSettings.MaxIdleTimeout) * time.Second,
|
MaxIdleTimeout: time.Duration(config.Connectivity.MaxIdleTimeout) * time.Second,
|
||||||
DisablePathMTUDiscovery: config.DisableMTUDiscovery,
|
DisablePathMTUDiscovery: config.DisableMTUDiscovery,
|
||||||
EnableDatagrams: true,
|
EnableDatagrams: true,
|
||||||
}
|
}
|
||||||
quicConfig.KeepAlivePeriod = quicConfig.MaxIdleTimeout / 2
|
quicConfig.KeepAlivePeriod = quicConfig.MaxIdleTimeout / 2
|
||||||
if quicConfig.KeepAlivePeriod == 0 || quicConfig.KeepAlivePeriod > KeepAlivePeriod {
|
if quicConfig.KeepAlivePeriod == 0 {
|
||||||
quicConfig.KeepAlivePeriod = KeepAlivePeriod
|
quicConfig.KeepAlivePeriod = DefaultKeepAlivePeriod
|
||||||
}
|
}
|
||||||
if config.ReceiveWindowConn == 0 {
|
if config.ReceiveWindowConn == 0 {
|
||||||
quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow
|
quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow
|
||||||
@ -147,14 +147,16 @@ func client(config *clientConfig) {
|
|||||||
func(refBPS uint64) congestion.CongestionControl {
|
func(refBPS uint64) congestion.CongestionControl {
|
||||||
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
|
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
|
||||||
}, obfuscator, func(err error) {
|
}, obfuscator, func(err error) {
|
||||||
if config.QUICSettings.DisableAutoReconnect {
|
if config.Connectivity.DisableAutoReconnect {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"addr": config.Server,
|
||||||
"error": err,
|
"error": err,
|
||||||
}).Fatal("QUIC connection lost, exiting...")
|
}).Fatal("Connection to server lost, exiting...")
|
||||||
} else {
|
} else {
|
||||||
logrus.WithFields(logrus.Fields{
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"addr": config.Server,
|
||||||
"error": err,
|
"error": err,
|
||||||
}).Info("QUIC connection lost, reconnecting...")
|
}).Info("Connection to server lost, reconnecting...")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,7 +23,7 @@ const (
|
|||||||
|
|
||||||
DefaultMMDBFilename = "GeoLite2-Country.mmdb"
|
DefaultMMDBFilename = "GeoLite2-Country.mmdb"
|
||||||
|
|
||||||
KeepAlivePeriod = 10 * time.Second
|
DefaultKeepAlivePeriod = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
var rateStringRegexp = regexp.MustCompile(`^(\d+)\s*([KMGT]?)([Bb])ps$`)
|
var rateStringRegexp = regexp.MustCompile(`^(\d+)\s*([KMGT]?)([Bb])ps$`)
|
||||||
@ -147,11 +147,11 @@ type clientConfig struct {
|
|||||||
Retry int `json:"retry"`
|
Retry int `json:"retry"`
|
||||||
RetryInterval int `json:"retry_interval"`
|
RetryInterval int `json:"retry_interval"`
|
||||||
// Optional below
|
// Optional below
|
||||||
QUICSettings struct {
|
Connectivity struct {
|
||||||
DisableAutoReconnect bool `json:"disable_auto_reconnect"`
|
DisableAutoReconnect bool `json:"disable_auto_reconnect"`
|
||||||
HandshakeIdleTimeout int `json:"handshake_idle_timeout"`
|
HandshakeIdleTimeout int `json:"handshake_idle_timeout"`
|
||||||
MaxIdleTimeout int `json:"max_idle_timeout"`
|
MaxIdleTimeout int `json:"max_idle_timeout"`
|
||||||
} `json:"quic_settings"`
|
} `json:"connectivity"`
|
||||||
SOCKS5 struct {
|
SOCKS5 struct {
|
||||||
Listen string `json:"listen"`
|
Listen string `json:"listen"`
|
||||||
Timeout int `json:"timeout"`
|
Timeout int `json:"timeout"`
|
||||||
@ -236,6 +236,12 @@ func (c *clientConfig) Check() error {
|
|||||||
len(c.TCPRedirect.Listen) == 0 {
|
len(c.TCPRedirect.Listen) == 0 {
|
||||||
return errors.New("please enable at least one mode")
|
return errors.New("please enable at least one mode")
|
||||||
}
|
}
|
||||||
|
if c.Connectivity.HandshakeIdleTimeout != 0 && c.Connectivity.HandshakeIdleTimeout <= 2 {
|
||||||
|
return errors.New("invalid handshake idle timeout")
|
||||||
|
}
|
||||||
|
if c.Connectivity.MaxIdleTimeout != 0 && c.Connectivity.MaxIdleTimeout <= 4 {
|
||||||
|
return errors.New("invalid max idle timeout")
|
||||||
|
}
|
||||||
if c.SOCKS5.Timeout != 0 && c.SOCKS5.Timeout <= 4 {
|
if c.SOCKS5.Timeout != 0 && c.SOCKS5.Timeout <= 4 {
|
||||||
return errors.New("invalid SOCKS5 timeout")
|
return errors.New("invalid SOCKS5 timeout")
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func server(config *serverConfig) {
|
|||||||
InitialConnectionReceiveWindow: config.ReceiveWindowClient,
|
InitialConnectionReceiveWindow: config.ReceiveWindowClient,
|
||||||
MaxConnectionReceiveWindow: config.ReceiveWindowClient,
|
MaxConnectionReceiveWindow: config.ReceiveWindowClient,
|
||||||
MaxIncomingStreams: int64(config.MaxConnClient),
|
MaxIncomingStreams: int64(config.MaxConnClient),
|
||||||
KeepAlivePeriod: KeepAlivePeriod,
|
KeepAlivePeriod: DefaultKeepAlivePeriod,
|
||||||
DisablePathMTUDiscovery: config.DisableMTUDiscovery,
|
DisablePathMTUDiscovery: config.DisableMTUDiscovery,
|
||||||
EnableDatagrams: true,
|
EnableDatagrams: true,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user