diff --git a/lib/common-node.js b/lib/common-node.js index b570f2b..dab4b67 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 8194270..c360213 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)