Skip to content

Commit

Permalink
Make "always choke seeders" optional (#2774)
Browse files Browse the repository at this point in the history
* Update torrent.js
* Update lib/torrent.js
* Update api.md
* linter wanted single-line if statements
  • Loading branch information
QuixThe2nd committed Apr 22, 2024
1 parent c8ffdda commit 41cb62b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ If `opts` is specified, then the default options (shown below) will be overridde
strategy: String, // Piece selection strategy, `rarest` or `sequential`(defaut=`sequential`)
noPeersIntervalTime: Number, // The amount of time (in seconds) to wait between each check of the `noPeers` event (default=30)
paused: Boolean, // If true, create the torrent in a paused state (default=false)
deselect: Boolean // If true, create the torrent with no pieces selected (default=false)
deselect: Boolean, // If true, create the torrent with no pieces selected (default=false)
alwaysChokeSeeders: Boolean // If true, client will automatically choke seeders if it's seeding. (default=true)
}
```

Expand Down
5 changes: 3 additions & 2 deletions lib/torrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export default class Torrent extends EventEmitter {
this._destroyStoreOnDestroy = opts.destroyStoreOnDestroy || false
this.store = null
this.storeOpts = opts.storeOpts
this.alwaysChokeSeeders = opts.alwaysChokeSeeders ?? true

this._getAnnounceOpts = opts.getAnnounceOpts

Expand Down Expand Up @@ -1198,7 +1199,7 @@ export default class Torrent extends EventEmitter {
if (!wire.peerPieces.get(i)) return
}
wire.isSeeder = true
wire.choke() // always choke seeders
if (this.alwaysChokeSeeders) wire.choke() // always choke seeders
}

wire.on('bitfield', () => {
Expand All @@ -1222,7 +1223,7 @@ export default class Torrent extends EventEmitter {
// fast extension (BEP6)
wire.on('have-all', () => {
wire.isSeeder = true
wire.choke() // always choke seeders
if (this.alwaysChokeSeeders) wire.choke() // always choke seeders
this._update()
this._updateWireInterest(wire)
})
Expand Down

0 comments on commit 41cb62b

Please sign in to comment.