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:
parent
7e595898e5
commit
37157f1d45
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -26,17 +26,17 @@ var dfgetConfig = ClientOption{
|
|||
Output: "",
|
||||
Timeout: 0,
|
||||
BenchmarkRate: 128 * unit.KB,
|
||||
RateLimit: 0,
|
||||
Md5: "",
|
||||
DigestMethod: "",
|
||||
DigestValue: "",
|
||||
Identifier: "",
|
||||
CallSystem: "",
|
||||
Pattern: "",
|
||||
Cacerts: nil,
|
||||
Filter: nil,
|
||||
Header: nil,
|
||||
NotBackSource: false,
|
||||
Insecure: false,
|
||||
ShowBar: false,
|
||||
RateLimit: 0,
|
||||
Md5: "",
|
||||
DigestMethod: "",
|
||||
DigestValue: "",
|
||||
Identifier: "",
|
||||
CallSystem: "",
|
||||
Pattern: "",
|
||||
Cacerts: nil,
|
||||
Filter: nil,
|
||||
Header: nil,
|
||||
DisableBackSource: false,
|
||||
Insecure: false,
|
||||
ShowBar: false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,17 +22,17 @@ var dfgetConfig = ClientOption{
|
|||
URL: "",
|
||||
LockFile: "/var/run/dfget.lock",
|
||||
Output: "",
|
||||
Timeout: 0,
|
||||
Md5: "",
|
||||
DigestMethod: "",
|
||||
DigestValue: "",
|
||||
Identifier: "",
|
||||
CallSystem: "",
|
||||
Pattern: "",
|
||||
Cacerts: nil,
|
||||
Filter: nil,
|
||||
Header: nil,
|
||||
NotBackSource: false,
|
||||
Insecure: false,
|
||||
ShowBar: false,
|
||||
Timeout: 0,
|
||||
Md5: "",
|
||||
DigestMethod: "",
|
||||
DigestValue: "",
|
||||
Identifier: "",
|
||||
CallSystem: "",
|
||||
Pattern: "",
|
||||
Cacerts: nil,
|
||||
Filter: nil,
|
||||
Header: nil,
|
||||
DisableBackSource: false,
|
||||
Insecure: false,
|
||||
ShowBar: false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue