Skip to content

Commit

Permalink
feat: validate rate limit
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 16, 2022
1 parent a7b4b92 commit 91e951f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/config/dfget.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (cfg *ClientOption) Validate() error {
}

if int64(cfg.RateLimit.Limit) < DefaultMinRate.ToNumber() {
return fmt.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
return errors.Wrapf(dferrors.ErrInvalidArgument, "rate limit must be greater than %s", DefaultMinRate.String())
}

return nil
Expand Down
6 changes: 5 additions & 1 deletion client/config/dfget_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

package config

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

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

var dfgetConfig = ClientOption{
URL: "",
Expand Down
9 changes: 2 additions & 7 deletions client/config/peerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ import (
"d7y.io/dragonfly/v2/pkg/util/net/iputils"
)

const (
// minRateLimit is the minimum of rate limit.
minRateLimit = 20 * 1024 * 1024
)

type DaemonConfig = DaemonOption
type DaemonOption struct {
base.Options `yaml:",inline" mapstructure:",squash"`
Expand Down Expand Up @@ -136,11 +131,11 @@ func (p *DaemonOption) Validate() error {
}

if int64(p.Download.TotalRateLimit.Limit) < DefaultMinRate.ToNumber() {
return fmt.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
return errors.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
}

if int64(p.Upload.RateLimit.Limit) < DefaultMinRate.ToNumber() {
return fmt.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
return errors.Errorf("rate limit must be greater than %s", DefaultMinRate.String())
}

switch p.Download.DefaultPattern {
Expand Down

0 comments on commit 91e951f

Please sign in to comment.