refactor: remove benchmark-rate and rename not-back-source (#245)

Signed-off-by: zuozheng.hzz <zuozheng.hzz@alibaba-inc.com>
This commit is contained in:
加菲 2021-05-23 21:38:56 +08:00 committed by Gaius
parent 7e595898e5
commit 37157f1d45
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
6 changed files with 40 additions and 41 deletions

View File

@ -90,8 +90,8 @@ type ClientOption struct {
// eg: --header='Accept: *' --header='Host: abc'.
Header []string `yaml:"header,omitempty" mapstructure:"header,omitempty"`
// NotBackSource indicates whether to not back source to download when p2p fails.
NotBackSource bool `yaml:"not_back_source,omitempty" mapstructure:"not_back_source,omitempty"`
// DisableBackSource indicates whether to not back source to download when p2p fails.
DisableBackSource bool `yaml:"disable_back_source,omitempty" mapstructure:"disable_back_source,omitempty"`
// Insecure indicates whether skip secure verify when supernode interact with the source.
Insecure bool `yaml:"insecure,omitempty" mapstructure:"insecure,omitempty"`

View File

@ -36,7 +36,7 @@ var dfgetConfig = ClientOption{
Cacerts: nil,
Filter: nil,
Header: nil,
NotBackSource: false,
DisableBackSource: false,
Insecure: false,
ShowBar: false,
}

View File

@ -32,7 +32,7 @@ var dfgetConfig = ClientOption{
Cacerts: nil,
Filter: nil,
Header: nil,
NotBackSource: false,
DisableBackSource: false,
Insecure: false,
ShowBar: false,
}

View File

@ -120,7 +120,7 @@ func Download(cfg *config.DfgetConfig, client dfclient.DaemonClient) error {
}
func downloadFromSource(cfg *config.DfgetConfig, hdr map[string]string) (err error) {
if cfg.NotBackSource {
if cfg.DisableBackSource {
err = fmt.Errorf("dfget download error, and back source disabled")
logger.Warnf("%s", err)
return err

View File

@ -18,6 +18,7 @@ package cmd
import (
"context"
"fmt"
"os"
"os/exec"
"strconv"
@ -85,6 +86,7 @@ var rootCmd = &cobra.Command{
func Execute() {
if err := rootCmd.Execute(); err != nil {
logger.Error(err)
fmt.Println(err)
os.Exit(1)
}
}
@ -106,11 +108,7 @@ func init() {
flagSet.DurationP("timeout", "e", dfgetConfig.Timeout,
"timeout for file downloading task. If dfget has not finished downloading all pieces of file "+
"before --timeout, the dfget will throw an error and exit, default see --benchmark-rate")
flagSet.String("benchmark-rate", dfgetConfig.BenchmarkRate.String(),
"benchmark rate in format of G(B)/g/M(B)/m/K(B)/k/B which is used to calculate the default --timeout, "+
"calculation formula: fileLength/benchmark-rate")
"before --timeout, the dfget will throw an error and exit, 0 is infinite")
flagSet.String("limit", unit.Bytes(dfgetConfig.RateLimit).String(),
"network bandwidth rate limit in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will be parsed as Byte, 0 is infinite")
@ -125,8 +123,9 @@ func init() {
"filter some query params of url, use char '&' to separate different params, eg: -f 'key&sign' "+
"will filter 'key' and 'sign' query param. in this way, different urls can correspond to the same P2P task")
flagSet.Bool("not-back-source", dfgetConfig.NotBackSource,
"disable dfget downloading file directly from url source when peer fails to download file")
flagSet.Bool("disable-back-source", dfgetConfig.DisableBackSource,
"disable dfget downloading file directly from url source when peer fails to download file, "+
"--limit is invalid when peer downloads the file from source")
flagSet.StringP("pattern", "p", dfgetConfig.Pattern, "downloading pattern, must be p2p/cdn/source")

View File

@ -43,16 +43,16 @@ for deciding which peers transmit blocks to each other.`,
DisableAutoGenTag: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
// Initialize logger
if err := logcore.InitScheduler(cfg.Console); err != nil {
return errors.Wrap(err, "init scheduler logger")
}
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
return runScheduler()
},
}