From: Alex Sharov Date: Wed, 13 Sep 2023 11:15:36 +0000 (+0700) Subject: Configurable hashers amount per torrent (#867) X-Git-Url: http://www.git.stargrave.org/?p=btrtrc.git;a=commitdiff_plain;h=bd2839cb9ca1a337a1e302267c290aacd76ef993 Configurable hashers amount per torrent (#867) --- diff --git a/.gitignore b/.gitignore index d92c6d5b..0c15585d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .idea *-run.gob .envrc* +.DS_Store +go.work* \ No newline at end of file diff --git a/config.go b/config.go index 0c029a7e..e2d0ea1e 100644 --- a/config.go +++ b/config.go @@ -188,6 +188,8 @@ type ClientConfig struct { ICEServers []string DialRateLimiter *rate.Limiter + + PieceHashersPerTorrent int // default: 2 } func (cfg *ClientConfig) SetListenAddr(addr string) *ClientConfig { @@ -225,13 +227,14 @@ func NewDefaultClientConfig() *ClientConfig { Preferred: true, RequirePreferred: false, }, - CryptoSelector: mse.DefaultCryptoSelector, - CryptoProvides: mse.AllSupportedCrypto, - ListenPort: 42069, - Extensions: defaultPeerExtensionBytes(), - AcceptPeerConnections: true, - MaxUnverifiedBytes: 64 << 20, - DialRateLimiter: rate.NewLimiter(10, 10), + CryptoSelector: mse.DefaultCryptoSelector, + CryptoProvides: mse.AllSupportedCrypto, + ListenPort: 42069, + Extensions: defaultPeerExtensionBytes(), + AcceptPeerConnections: true, + MaxUnverifiedBytes: 64 << 20, + DialRateLimiter: rate.NewLimiter(10, 10), + PieceHashersPerTorrent: 2, } cc.DhtStartingNodes = func(network string) dht.StartingNodesGetter { return func() ([]dht.Addr, error) { return dht.GlobalBootstrapAddrs(network) } diff --git a/torrent.go b/torrent.go index 5f6ddf39..8b474521 100644 --- a/torrent.go +++ b/torrent.go @@ -2251,7 +2251,7 @@ func (t *Torrent) onIncompletePiece(piece pieceIndex) { } func (t *Torrent) tryCreateMorePieceHashers() { - for !t.closed.IsSet() && t.activePieceHashes < 2 && t.tryCreatePieceHasher() { + for !t.closed.IsSet() && t.activePieceHashes < t.cl.config.PieceHashersPerTorrent && t.tryCreatePieceHasher() { } }