mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-07-28 16:08:35 +00:00
feat: add quic_settings into client config
fix: #420 allow user to disable auto reconnect when quic disconnected, along with quic handshake & idle timeout. an extra failed request would be required to make the client exit in case of quic disconnected, but i don't think this would be a problem in the common usage.
This commit is contained in:
@@ -75,10 +75,15 @@ func client(config *clientConfig) {
|
||||
MaxStreamReceiveWindow: config.ReceiveWindowConn,
|
||||
InitialConnectionReceiveWindow: config.ReceiveWindow,
|
||||
MaxConnectionReceiveWindow: config.ReceiveWindow,
|
||||
KeepAlivePeriod: KeepAlivePeriod,
|
||||
HandshakeIdleTimeout: time.Duration(config.QUICSettings.HandshakeIdleTimeout) * time.Second,
|
||||
MaxIdleTimeout: time.Duration(config.QUICSettings.MaxIdleTimeout) * time.Second,
|
||||
DisablePathMTUDiscovery: config.DisableMTUDiscovery,
|
||||
EnableDatagrams: true,
|
||||
}
|
||||
quicConfig.KeepAlivePeriod = quicConfig.MaxIdleTimeout / 2
|
||||
if quicConfig.KeepAlivePeriod == 0 || quicConfig.KeepAlivePeriod > KeepAlivePeriod {
|
||||
quicConfig.KeepAlivePeriod = KeepAlivePeriod
|
||||
}
|
||||
if config.ReceiveWindowConn == 0 {
|
||||
quicConfig.InitialStreamReceiveWindow = DefaultStreamReceiveWindow
|
||||
quicConfig.MaxStreamReceiveWindow = DefaultStreamReceiveWindow
|
||||
@@ -141,7 +146,17 @@ func client(config *clientConfig) {
|
||||
transport.DefaultClientTransport, up, down,
|
||||
func(refBPS uint64) congestion.CongestionControl {
|
||||
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
|
||||
}, obfuscator)
|
||||
}, obfuscator, func(err error) {
|
||||
if config.QUICSettings.DisableAutoReconnect {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
}).Fatal("QUIC connection lost, exiting...")
|
||||
} else {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
}).Info("QUIC connection lost, reconnecting...")
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
logrus.WithField("error", err).Error("Failed to initialize client")
|
||||
if try <= config.Retry || config.Retry < 0 {
|
||||
|
@@ -147,6 +147,11 @@ type clientConfig struct {
|
||||
Retry int `json:"retry"`
|
||||
RetryInterval int `json:"retry_interval"`
|
||||
// Optional below
|
||||
QUICSettings struct {
|
||||
DisableAutoReconnect bool `json:"disable_auto_reconnect"`
|
||||
HandshakeIdleTimeout int `json:"handshake_idle_timeout"`
|
||||
MaxIdleTimeout int `json:"max_idle_timeout"`
|
||||
} `json:"quic_settings"`
|
||||
SOCKS5 struct {
|
||||
Listen string `json:"listen"`
|
||||
Timeout int `json:"timeout"`
|
||||
|
@@ -44,11 +44,13 @@ type Client struct {
|
||||
udpSessionMutex sync.RWMutex
|
||||
udpSessionMap map[uint32]chan *udpMessage
|
||||
udpDefragger defragger
|
||||
|
||||
quicReconnectFunc func(err error)
|
||||
}
|
||||
|
||||
func NewClient(serverAddr string, protocol string, auth []byte, tlsConfig *tls.Config, quicConfig *quic.Config,
|
||||
transport *transport.ClientTransport, sendBPS uint64, recvBPS uint64, congestionFactory CongestionFactory,
|
||||
obfuscator obfs.Obfuscator,
|
||||
obfuscator obfs.Obfuscator, quicReconnectFunc func(err error),
|
||||
) (*Client, error) {
|
||||
quicConfig.DisablePathMTUDiscovery = quicConfig.DisablePathMTUDiscovery || pmtud_fix.DisablePathMTUDiscovery
|
||||
c := &Client{
|
||||
@@ -62,6 +64,7 @@ func NewClient(serverAddr string, protocol string, auth []byte, tlsConfig *tls.C
|
||||
obfuscator: obfuscator,
|
||||
tlsConfig: tlsConfig,
|
||||
quicConfig: quicConfig,
|
||||
quicReconnectFunc: quicReconnectFunc,
|
||||
}
|
||||
if err := c.connectToServer(); err != nil {
|
||||
return nil, err
|
||||
@@ -173,6 +176,7 @@ func (c *Client) openStreamWithReconnect() (quic.Connection, quic.Stream, error)
|
||||
// Temporary error, just return
|
||||
return nil, nil, err
|
||||
}
|
||||
c.quicReconnectFunc(err)
|
||||
// Permanent error, need to reconnect
|
||||
if err := c.connectToServer(); err != nil {
|
||||
// Still error, oops
|
||||
|
Reference in New Issue
Block a user