diff --git a/client/config/constants.go b/client/config/constants.go index 50eed165712..516f1f6a8ca 100644 --- a/client/config/constants.go +++ b/client/config/constants.go @@ -49,7 +49,7 @@ const ( DefaultPerPeerDownloadLimit = 20 * unit.MB DefaultTotalDownloadLimit = 100 * unit.MB DefaultUploadLimit = 100 * unit.MB - DefaultMinRate = 64 * unit.KB + DefaultMinRate = 20 * unit.MB ) /* others */ diff --git a/client/config/dfget.go b/client/config/dfget.go index bb2d819ba79..22fd1088626 100644 --- a/client/config/dfget.go +++ b/client/config/dfget.go @@ -163,6 +163,10 @@ func (cfg *ClientOption) Validate() error { return errors.Wrapf(dferrors.ErrInvalidHeader, "output: %v", err) } + if int64(cfg.RateLimit.Limit) < DefaultMinRate.ToNumber() { + return errors.Wrapf(dferrors.ErrInvalidArgument, "rate limit must be greater than %s", DefaultMinRate.String()) + } + return nil } diff --git a/client/config/dfget_linux.go b/client/config/dfget_linux.go index 61ece8f5f24..e0fa70a868b 100644 --- a/client/config/dfget_linux.go +++ b/client/config/dfget_linux.go @@ -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: "", diff --git a/client/config/peerhost.go b/client/config/peerhost.go index 77a754caea2..e17bbeee188 100644 --- a/client/config/peerhost.go +++ b/client/config/peerhost.go @@ -129,6 +129,15 @@ func (p *DaemonOption) Validate() error { if len(p.Scheduler.NetAddrs) == 0 { return errors.New("empty schedulers and config server is not specified") } + + if int64(p.Download.TotalRateLimit.Limit) < DefaultMinRate.ToNumber() { + return errors.Errorf("rate limit must be greater than %s", DefaultMinRate.String()) + } + + if int64(p.Upload.RateLimit.Limit) < DefaultMinRate.ToNumber() { + return errors.Errorf("rate limit must be greater than %s", DefaultMinRate.String()) + } + switch p.Download.DefaultPattern { case PatternP2P, PatternSeedPeer, PatternSource: default: