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'.
|
// 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"`
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ var dfgetConfig = ClientOption{
|
||||||
Cacerts: nil,
|
Cacerts: nil,
|
||||||
Filter: nil,
|
Filter: nil,
|
||||||
Header: nil,
|
Header: nil,
|
||||||
NotBackSource: false,
|
DisableBackSource: false,
|
||||||
Insecure: false,
|
Insecure: false,
|
||||||
ShowBar: false,
|
ShowBar: false,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ var dfgetConfig = ClientOption{
|
||||||
Cacerts: nil,
|
Cacerts: nil,
|
||||||
Filter: nil,
|
Filter: nil,
|
||||||
Header: nil,
|
Header: nil,
|
||||||
NotBackSource: false,
|
DisableBackSource: false,
|
||||||
Insecure: false,
|
Insecure: false,
|
||||||
ShowBar: 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) {
|
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
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue