Merge pull request #219 from HyNetwork/wip-client-retry

feat: client retry
This commit is contained in:
Toby 2022-02-03 21:42:32 -08:00 committed by GitHub
commit 9b78d1cad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 12 deletions

View File

@ -110,13 +110,30 @@ func client(config *clientConfig) {
} }
} }
// Client // Client
client, err := core.NewClient(config.Server, config.Protocol, auth, tlsConfig, quicConfig, var client *core.Client
transport.DefaultClientTransport, uint64(config.UpMbps)*mbpsToBps, uint64(config.DownMbps)*mbpsToBps, try := 0
func(refBPS uint64) congestion.CongestionControl { for {
return hyCongestion.NewBrutalSender(congestion.ByteCount(refBPS)) try += 1
}, obfuscator) c, err := core.NewClient(config.Server, config.Protocol, auth, tlsConfig, quicConfig,
if err != nil { transport.DefaultClientTransport, uint64(config.UpMbps)*mbpsToBps, uint64(config.DownMbps)*mbpsToBps,
logrus.WithField("error", err).Fatal("Failed to initialize client") 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() defer client.Close()
logrus.WithField("addr", config.Server).Info("Connected") 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") logrus.WithField("error", err).Fatal("Client shutdown")
} }

View File

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

View File

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