feat: client retry

This commit is contained in:
Toby 2022-02-03 21:37:25 -08:00
parent 349ac5e41e
commit 0bb74fcd8d
3 changed files with 32 additions and 12 deletions

View File

@ -110,13 +110,30 @@ func client(config *clientConfig) {
}
}
// Client
client, err := core.NewClient(config.Server, config.Protocol, auth, tlsConfig, quicConfig,
transport.DefaultClientTransport, uint64(config.UpMbps)*mbpsToBps, uint64(config.DownMbps)*mbpsToBps,
func(refBPS uint64) congestion.CongestionControl {
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
}, obfuscator)
if err != nil {
logrus.WithField("error", err).Fatal("Failed to initialize client")
var client *core.Client
try := 0
for {
try += 1
c, err := core.NewClient(config.Server, config.Protocol, auth, tlsConfig, quicConfig,
transport.DefaultClientTransport, uint64(config.UpMbps)*mbpsToBps, uint64(config.DownMbps)*mbpsToBps,
func(refBPS uint64) congestion.CongestionControl {
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS))
}, obfuscator)
if err != nil {
logrus.WithField("error", err).Error("Failed to initialize client")
if try <= config.Retry || config.Retry < 0 {
logrus.WithFields(logrus.Fields{
"retry": try,
"interval": config.RetryInterval,
}).Info("Retrying...")
time.Sleep(time.Duration(config.RetryInterval) * time.Second)
} else {
logrus.Fatal("Out of retries, exiting...")
}
} else {
client = c
break
}
}
defer client.Close()
logrus.WithField("addr", config.Server).Info("Connected")
@ -395,6 +412,6 @@ func client(config *clientConfig) {
}()
}
err = <-errChan
err := <-errChan
logrus.WithField("error", err).Fatal("Client shutdown")
}

View File

@ -97,10 +97,12 @@ func (r *Relay) Check() error {
}
type clientConfig struct {
Server string `json:"server"`
Protocol string `json:"protocol"`
UpMbps int `json:"up_mbps"`
DownMbps int `json:"down_mbps"`
Server string `json:"server"`
Protocol string `json:"protocol"`
UpMbps int `json:"up_mbps"`
DownMbps int `json:"down_mbps"`
Retry int `json:"retry"`
RetryInterval int `json:"retry_interval"`
// Optional below
SOCKS5 struct {
Listen string `json:"listen"`

View File

@ -131,6 +131,7 @@ func initApp(c *cli.Context) error {
"version", "url",
"config", "file", "mode",
"addr", "src", "dst", "session", "action",
"retry", "interval",
"code", "msg", "error",
},
TimestampFormat: c.String("log-timestamp"),