From ef76b3f3b6beee87f57d74addd0ca2ef2c517b6d Mon Sep 17 00:00:00 2001 From: Paul Sharypov Date: Wed, 1 Jun 2022 18:23:38 +0300 Subject: [PATCH 1/2] feat(events): Support of `paused` client event (#411) * feat: Added `paused` client event * fix(events): fixed 'invalid event' response on 'paused' request from client * fix(styles): fixed extra semicolon --- lib/common-node.js | 8 +++++--- lib/server/swarm.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/common-node.js b/lib/common-node.js index b570f2b1..dab4b675 100644 --- a/lib/common-node.js +++ b/lib/common-node.js @@ -11,18 +11,20 @@ exports.REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/ exports.CONNECTION_ID = Buffer.concat([toUInt32(0x417), toUInt32(0x27101980)]) exports.ACTIONS = { CONNECT: 0, ANNOUNCE: 1, SCRAPE: 2, ERROR: 3 } -exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3 } +exports.EVENTS = { update: 0, completed: 1, started: 2, stopped: 3, paused: 4 } exports.EVENT_IDS = { 0: 'update', 1: 'completed', 2: 'started', - 3: 'stopped' + 3: 'stopped', + 4: 'paused' } exports.EVENT_NAMES = { update: 'update', completed: 'complete', started: 'start', - stopped: 'stop' + stopped: 'stop', + paused: 'pause' } /** diff --git a/lib/server/swarm.js b/lib/server/swarm.js index 8194270f..c3602133 100644 --- a/lib/server/swarm.js +++ b/lib/server/swarm.js @@ -47,6 +47,8 @@ class Swarm { self._onAnnounceCompleted(params, peer, id) } else if (params.event === 'update') { self._onAnnounceUpdate(params, peer, id) + } else if (params.event === 'paused') { + self._onAnnouncePaused(params, peer, id) } else { cb(new Error('invalid event')) return @@ -132,6 +134,15 @@ class Swarm { this.peers.set(id, peer) } + _onAnnouncePaused (params, peer, id) { + if (!peer) { + debug('unexpected `paused` event from peer that is not in swarm') + return this._onAnnounceStarted(params, peer, id) // treat as a start + } + + this._onAnnounceUpdate(params, peer, id) + } + _getPeers (numwant, ownPeerId, isWebRTC) { const peers = [] const ite = randomIterate(this.peers.keys) From 4b5299b691e93b98038c6de3423fb22db55b0816 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 1 Jun 2022 15:26:39 +0000 Subject: [PATCH 2/2] chore(release): 9.19.0 # [9.19.0](https://github.com/webtorrent/bittorrent-tracker/compare/v9.18.6...v9.19.0) (2022-06-01) ### Features * **events:** Support of `paused` client event ([#411](https://github.com/webtorrent/bittorrent-tracker/issues/411)) ([ef76b3f](https://github.com/webtorrent/bittorrent-tracker/commit/ef76b3f3b6beee87f57d74addd0ca2ef2c517b6d)) --- AUTHORS.md | 1 + CHANGELOG.md | 7 +++++++ package.json | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index ccffe922..3d80837a 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -60,5 +60,6 @@ - Bruce Hopkins (behopkinsjr@gmail.com) - Ryan Finnie (ryan@finnie.org) - Lookis (lookisliu@gmail.com) +- Paul Sharypov (pavloniym@gmail.com) #### Generated by tools/update-authors.sh. diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f8df94..2e511e3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [9.19.0](https://github.com/webtorrent/bittorrent-tracker/compare/v9.18.6...v9.19.0) (2022-06-01) + + +### Features + +* **events:** Support of `paused` client event ([#411](https://github.com/webtorrent/bittorrent-tracker/issues/411)) ([ef76b3f](https://github.com/webtorrent/bittorrent-tracker/commit/ef76b3f3b6beee87f57d74addd0ca2ef2c517b6d)) + ## [9.18.6](https://github.com/webtorrent/bittorrent-tracker/compare/v9.18.5...v9.18.6) (2022-05-11) diff --git a/package.json b/package.json index 7271f05b..74f64391 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bittorrent-tracker", "description": "Simple, robust, BitTorrent tracker (client & server) implementation", - "version": "9.18.6", + "version": "9.19.0", "author": { "name": "WebTorrent LLC", "email": "feross@webtorrent.io",