From 637045c19a5b5fc37c3f7d55f885cee3dab3b5a9 Mon Sep 17 00:00:00 2001 From: Simon Kirsten <1972314+skirsten@users.noreply.github.com> Date: Mon, 11 Oct 2021 02:33:40 +0200 Subject: [PATCH] Add DisableInitialPieceCheck option (#677) --- client.go | 1 + spec.go | 5 +++-- torrent.go | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 3cf07cf3..dcf93628 100644 --- a/client.go +++ b/client.go @@ -1195,6 +1195,7 @@ func (t *Torrent) MergeSpec(spec *TorrentSpec) error { if spec.DisplayName != "" { t.SetDisplayName(spec.DisplayName) } + t.initialPieceCheckDisabled = spec.DisableInitialPieceCheck if spec.InfoBytes != nil { err := t.SetInfoBytes(spec.InfoBytes) if err != nil { diff --git a/spec.go b/spec.go index 6708db90..21058477 100644 --- a/spec.go +++ b/spec.go @@ -23,8 +23,9 @@ type TorrentSpec struct { Sources []string // The chunk size to use for outbound requests. Defaults to 16KiB if not set. - ChunkSize int - Storage storage.ClientImpl + ChunkSize int + DisableInitialPieceCheck bool + Storage storage.ClientImpl // Whether to allow data download or upload DisallowDataUpload bool diff --git a/torrent.go b/torrent.go index 3c6a65d9..49d69fe7 100644 --- a/torrent.go +++ b/torrent.go @@ -135,8 +135,9 @@ type Torrent struct { // A cache of completed piece indices. _completedPieces roaring.Bitmap // Pieces that need to be hashed. - piecesQueuedForHash bitmap.Bitmap - activePieceHashes int + piecesQueuedForHash bitmap.Bitmap + activePieceHashes int + initialPieceCheckDisabled bool // A pool of piece priorities []int for assignment to new connections. // These "inclinations" are used to give connections preference for @@ -439,7 +440,7 @@ func (t *Torrent) onSetInfo() { } p.availability = int64(t.pieceAvailabilityFromPeers(i)) t.updatePieceCompletion(pieceIndex(i)) - if !p.storageCompletionOk { + if !t.initialPieceCheckDisabled && !p.storageCompletionOk { // t.logger.Printf("piece %s completion unknown, queueing check", p) t.queuePieceCheck(pieceIndex(i)) } -- 2.48.1