Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ratelimit #1391

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/config/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"time"

"github.com/pkg/errors"
"golang.org/x/time/rate"

"d7y.io/dragonfly/v2/client/clientutil"
"d7y.io/dragonfly/v2/cmd/dependency/base"
"d7y.io/dragonfly/v2/internal/dferrors"
logger "d7y.io/dragonfly/v2/internal/dflog"
Expand Down Expand Up @@ -103,7 +103,7 @@ type ClientOption struct {
// WorkHome is working directory of dfget.
WorkHome string `yaml:"workHome,omitempty" mapstructure:"workHome,omitempty"`

RateLimit rate.Limit `yaml:"rateLimit,omitempty" mapstructure:"rateLimit,omitempty"`
RateLimit clientutil.RateLimit `yaml:"rateLimit,omitempty" mapstructure:"rateLimit,omitempty"`

// Config file paths,
// default:["/etc/dragonfly/dfget.yaml","/etc/dragonfly.conf"].
Expand Down
18 changes: 12 additions & 6 deletions client/config/dfget_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,20 @@

package config

import "d7y.io/dragonfly/v2/pkg/unit"
import (
"d7y.io/dragonfly/v2/client/clientutil"
"d7y.io/dragonfly/v2/pkg/unit"
"golang.org/x/time/rate"
)

var dfgetConfig = ClientOption{
URL: "",
Output: "",
Timeout: 0,
BenchmarkRate: 128 * unit.KB,
RateLimit: 0,
URL: "",
Output: "",
Timeout: 0,
BenchmarkRate: 128 * unit.KB,
RateLimit: clientutil.RateLimit{
Limit: rate.Limit(DefaultTotalDownloadLimit),
},
Md5: "",
DigestMethod: "",
DigestValue: "",
Expand Down
11 changes: 8 additions & 3 deletions client/config/dfget_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@

package config

import "d7y.io/dragonfly/v2/client/clientutil"

var dfgetConfig = ClientOption{
URL: "",
Output: "",
Timeout: 0,
URL: "",
Output: "",
Timeout: 0,
RateLimit: clientutil.RateLimit{
Limit: rate.Limit(DefaultTotalDownloadLimit),
},
Md5: "",
DigestMethod: "",
DigestValue: "",
Expand Down
2 changes: 1 addition & 1 deletion client/dfget/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func newDownRequest(cfg *config.DfgetConfig, hdr map[string]string) *dfdaemon.Do
Url: cfg.URL,
Output: cfg.Output,
Timeout: uint64(cfg.Timeout),
Limit: float64(cfg.RateLimit),
Limit: float64(cfg.RateLimit.Limit),
DisableBackSource: cfg.DisableBackSource,
UrlMeta: &base.UrlMeta{
Digest: cfg.Digest,
Expand Down
2 changes: 1 addition & 1 deletion cmd/dfget/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func init() {

flagSet.Duration("timeout", dfgetConfig.Timeout, "Timeout for the downloading task, 0 is infinite")

flagSet.String("limit", unit.Bytes(dfgetConfig.RateLimit).String(),
flagSet.String("ratelimit", unit.Bytes(dfgetConfig.RateLimit.Limit).String(),
"The downloading network bandwidth limit per second in format of G(B)/g/M(B)/m/K(B)/k/B, pure number will be parsed as Byte, 0 is infinite")

flagSet.String("digest", dfgetConfig.Digest,
Expand Down