Skip to content

Commit b9f3ea5

Browse files
authored
Merge pull request #43 from Code-Hex/add/warning-msg
Added warning msg
2 parents b84878d + a1f1547 commit b9f3ea5

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ This is an example to download [linux kernel](https://www.kernel.org/). It will
2323

2424
This program comes with no warranty. You must use this program at your own risk.
2525

26+
### Note
27+
28+
- Using a large number of connections to a single URL can lead to DOS attacks.
29+
- The case is increasing that if you use multiple connections to 1 URL does not increase the download speed with the spread of CDNs.
30+
- I recommend to use multiple mirrors simultaneously for faster downloads (And the number of connections is 1 for each).
31+
2632
## Installation
2733

2834
### Homebrew
@@ -51,12 +57,6 @@ You can do this
5157

5258
cat list.txt | pget -p 2
5359

54-
### Note
55-
56-
The case is increasing that if you use multiple connections for a single URL does not increase the download speed with the spread of CDNs.
57-
58-
I recommend to use multiple mirrors simultaneously for faster downloads (And the number of connections is 1 for each).
59-
6060
## Options
6161

6262
```

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.15
44

55
require (
66
github.com/Code-Hex/updater v0.0.0-20160712085121-c3f278672520
7+
github.com/Songmu/prompter v0.5.0
78
github.com/antonholmquist/jason v1.0.1-0.20160829104012-962e09b85496 // indirect
89
github.com/asaskevich/govalidator v0.0.0-20161001163130-7b3beb6df3c4
910
github.com/cheggaaa/pb/v3 v3.0.8

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/Code-Hex/updater v0.0.0-20160712085121-c3f278672520 h1:AhI5ytq4dAam2scBpgeQY/9kz/covK9/NMyzO3e8350=
22
github.com/Code-Hex/updater v0.0.0-20160712085121-c3f278672520/go.mod h1:RZRMRhdqo/22EdcyGiDJdIdCrptsRDEbqQ8/bswHV1E=
3+
github.com/Songmu/prompter v0.5.0 h1:uf60xlFItY5nW+rlLJ2XIUfaUReo4gUEeftuUeHpio8=
4+
github.com/Songmu/prompter v0.5.0/go.mod h1:S4Eg25l60kPlnfB2ttFVpvBKYw7RKJexzB3gzpAansY=
35
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
46
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
57
github.com/antonholmquist/jason v1.0.1-0.20160829104012-962e09b85496 h1:dESITdufxuiwgQh1YPiPupEXORHTYvY8tr40nvrWelo=
@@ -65,8 +67,12 @@ golang.org/x/sync v0.0.0-20161004233620-1ae7c7b29e06 h1:pRVhPB331E/b1+A7Y9d/3Zkg
6567
golang.org/x/sync v0.0.0-20161004233620-1ae7c7b29e06/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6668
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6769
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
70+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
71+
golang.org/x/sys v0.0.0-20210319071255-635bc2c9138d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
6872
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A=
6973
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
74+
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6 h1:EC6+IGYTjPpRfv9a2b/6Puw0W+hLtAhkV1tPsXhutqs=
75+
golang.org/x/term v0.0.0-20210317153231-de623e64d2a6/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
7076
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
7177
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
7278
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

pget.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111
"time"
1212

13+
"github.com/Songmu/prompter"
1314
"github.com/asaskevich/govalidator"
1415
"github.com/pkg/errors"
1516
)
@@ -86,6 +87,15 @@ func (pget *Pget) Run(ctx context.Context, version string, args []string) error
8687
}, opts...)
8788
}
8889

90+
const (
91+
warningNumConnection = 4
92+
warningMessage = "[WARNING] Using a large number of connections to 1 URL can lead to DOS attacks.\n" +
93+
"In most cases, `4` or less is enough. In addition, the case is increasing that if you use multiple connections to 1 URL does not increase the download speed with the spread of CDNs.\n" +
94+
"See: https://github.com/Code-Hex/pget#disclaimer\n" +
95+
"\n" +
96+
"Would you execute knowing these?\n"
97+
)
98+
8999
// Ready method define the variables required to Download.
90100
func (pget *Pget) Ready(version string, args []string) error {
91101
opts, err := pget.parseOptions(args, version)
@@ -105,6 +115,10 @@ func (pget *Pget) Ready(version string, args []string) error {
105115
return errors.Wrap(err, "failed to parse of url")
106116
}
107117

118+
if opts.NumConnection > warningNumConnection && !prompter.YN(warningMessage, false) {
119+
return makeIgnoreErr()
120+
}
121+
108122
pget.Procs = opts.NumConnection * len(pget.URLs)
109123

110124
if opts.Output != "" {

0 commit comments

Comments
 (0)