Skip to content

Commit ba22d4b

Browse files
committed
cmd/torrent: Add verify and flag for large chunk uploads
1 parent 847bb72 commit ba22d4b

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

cmd/torrent/download.go

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ func addTorrents(
218218
log.Printf("error writing %q: %v", path, err)
219219
}
220220
}
221+
if flags.Verify {
222+
err := t.VerifyDataContext(ctx)
223+
if err != nil && ctx.Err() == nil {
224+
log.Levelf(log.Error, "error verifying data: %v", err)
225+
}
226+
}
221227
if len(flags.File) == 0 {
222228
t.DownloadAll()
223229
wg.Add(1)
@@ -311,21 +317,23 @@ type downloadFlags struct {
311317
}
312318

313319
type DownloadCmd struct {
314-
SaveMetainfos bool
315-
Mmap bool `help:"memory-map torrent data"`
316-
Seed bool `help:"seed after download is complete"`
317-
Addr string `help:"network listen addr"`
318-
MaxUnverifiedBytes *tagflag.Bytes `help:"maximum number bytes to have pending verification"`
319-
UploadRate *tagflag.Bytes `help:"max piece bytes to send per second"`
320-
DownloadRate *tagflag.Bytes `help:"max bytes per second down from peers"`
321-
PackedBlocklist string
322-
PublicIP net.IP
323-
Progress bool `default:"true"`
324-
PieceStates bool `help:"Output piece state runs at progress intervals."`
325-
Quiet bool `help:"discard client logging"`
326-
Stats bool `help:"print stats at termination"`
327-
Dht bool `default:"true"`
328-
PortForward bool `default:"true"`
320+
SaveMetainfos bool `help:"save metainfo files when info is obtained"`
321+
Mmap bool `help:"memory-map torrent data"`
322+
Seed bool `help:"seed after download is complete"`
323+
Addr string `help:"network listen addr"`
324+
MaxUnverifiedBytes *tagflag.Bytes `help:"maximum number bytes to have pending verification"`
325+
UploadRate *tagflag.Bytes `help:"max piece bytes to send per second"`
326+
MaxAllocPeerRequestDataPerConn *tagflag.Bytes `help:"max bytes to allocate for peer request data per connection"`
327+
DownloadRate *tagflag.Bytes `help:"max bytes per second down from peers"`
328+
PackedBlocklist string
329+
PublicIP net.IP
330+
Progress bool `default:"true"`
331+
PieceStates bool `help:"Output piece state runs at progress intervals."`
332+
Quiet bool `help:"discard client logging"`
333+
Stats bool `help:"print stats at termination"`
334+
Dht bool `default:"true"`
335+
PortForward bool `default:"true"`
336+
Verify bool `help:"verify data after adding torrent"`
329337

330338
TcpPeers bool `default:"true"`
331339
UtpPeers bool `default:"true"`
@@ -366,6 +374,7 @@ func downloadErr(ctx context.Context, flags downloadFlags) error {
366374
clientConfig.DisablePEX = !flags.Pex
367375
clientConfig.DisableWebtorrent = !flags.Webtorrent
368376
clientConfig.NoDefaultPortForwarding = !flags.PortForward
377+
clientConfig.MaxAllocPeerRequestDataPerConn = flags.MaxAllocPeerRequestDataPerConn.Int64()
369378
if flags.PackedBlocklist != "" {
370379
blocklist, err := iplist.MMapPackedFile(flags.PackedBlocklist)
371380
if err != nil {
@@ -381,8 +390,14 @@ func downloadErr(ctx context.Context, flags downloadFlags) error {
381390
clientConfig.SetListenAddr(flags.Addr)
382391
}
383392
if flags.UploadRate != nil {
384-
// TODO: I think the upload rate limit could be much lower.
385-
clientConfig.UploadRateLimiter = rate.NewLimiter(rate.Limit(*flags.UploadRate), 256<<10)
393+
clientConfig.UploadRateLimiter = rate.NewLimiter(
394+
rate.Limit(*flags.UploadRate),
395+
// Need to ensure the expected peer request length <= the upload
396+
// burst. We can't really encode this logic into the ClientConfig as
397+
// helper because it's quite specific. We're assuming the
398+
// MaxAllocPeerRequestDataPerConn flag is being used to support
399+
// this.
400+
max(int(*flags.MaxAllocPeerRequestDataPerConn), 256<<10))
386401
}
387402
if flags.DownloadRate != nil {
388403
clientConfig.DownloadRateLimiter = rate.NewLimiter(rate.Limit(*flags.DownloadRate), 1<<16)

0 commit comments

Comments
 (0)