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'. // eg: --header='Accept: *' --header='Host: abc'.
Header []string `yaml:"header,omitempty" mapstructure:"header,omitempty"` Header []string `yaml:"header,omitempty" mapstructure:"header,omitempty"`
// NotBackSource indicates whether to not back source to download when p2p fails. // DisableBackSource indicates whether to not back source to download when p2p fails.
NotBackSource bool `yaml:"not_back_source,omitempty" mapstructure:"not_back_source,omitempty"` 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 indicates whether skip secure verify when supernode interact with the source.
Insecure bool `yaml:"insecure,omitempty" mapstructure:"insecure,omitempty"` Insecure bool `yaml:"insecure,omitempty" mapstructure:"insecure,omitempty"`

View File

@ -26,17 +26,17 @@ var dfgetConfig = ClientOption{
Output: "", Output: "",
Timeout: 0, Timeout: 0,
BenchmarkRate: 128 * unit.KB, BenchmarkRate: 128 * unit.KB,
RateLimit: 0, RateLimit: 0,
Md5: "", Md5: "",
DigestMethod: "", DigestMethod: "",
DigestValue: "", DigestValue: "",
Identifier: "", Identifier: "",
CallSystem: "", CallSystem: "",
Pattern: "", Pattern: "",
Cacerts: nil, Cacerts: nil,
Filter: nil, Filter: nil,
Header: nil, Header: nil,
NotBackSource: false, DisableBackSource: false,
Insecure: false, Insecure: false,
ShowBar: false, ShowBar: false,
} }

View File

@ -22,17 +22,17 @@ var dfgetConfig = ClientOption{
URL: "", URL: "",
LockFile: "/var/run/dfget.lock", LockFile: "/var/run/dfget.lock",
Output: "", Output: "",
Timeout: 0, Timeout: 0,
Md5: "", Md5: "",
DigestMethod: "", DigestMethod: "",
DigestValue: "", DigestValue: "",
Identifier: "", Identifier: "",
CallSystem: "", CallSystem: "",
Pattern: "", Pattern: "",
Cacerts: nil, Cacerts: nil,
Filter: nil, Filter: nil,
Header: nil, Header: nil,
NotBackSource: false, DisableBackSource: false,
Insecure: false, Insecure: false,
ShowBar: 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) { 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") err = fmt.Errorf("dfget download error, and back source disabled")
logger.Warnf("%s", err) logger.Warnf("%s", err)
return err return err

View File

@ -18,6 +18,7 @@ package cmd
import ( import (
"context" "context"
"fmt"
"os" "os"
"os/exec" "os/exec"
"strconv" "strconv"
@ -85,6 +86,7 @@ var rootCmd = &cobra.Command{
func Execute() { func Execute() {
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
logger.Error(err) logger.Error(err)
fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
} }
@ -106,11 +108,7 @@ func init() {
flagSet.DurationP("timeout", "e", dfgetConfig.Timeout, flagSet.DurationP("timeout", "e", dfgetConfig.Timeout,
"timeout for file downloading task. If dfget has not finished downloading all pieces of file "+ "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") "before --timeout, the dfget will throw an error and exit, 0 is infinite")
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")
flagSet.String("limit", unit.Bytes(dfgetConfig.RateLimit).String(), 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") "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' "+ "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") "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, flagSet.Bool("disable-back-source", dfgetConfig.DisableBackSource,
"disable dfget downloading file directly from url source when peer fails to download file") "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") 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, DisableAutoGenTag: true,
SilenceUsage: true, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
// Initialize logger // Initialize logger
if err := logcore.InitScheduler(cfg.Console); err != nil { if err := logcore.InitScheduler(cfg.Console); err != nil {
return errors.Wrap(err, "init scheduler logger") return errors.Wrap(err, "init scheduler logger")
} }
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
return runScheduler() return runScheduler()
}, },
} }