Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'noPeers' event to torrents #775

Merged
merged 3 commits into from May 5, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Torrent emits 'noPeers' even when swarm is empty after announce

  • Loading branch information
Jonathan Harper
Jonathan Harper committed Apr 27, 2016
commit cd7fcb2d797cccf9507557493146e6a498f16861
@@ -333,10 +333,12 @@ Torrent.prototype._onListening = function () {

function onTrackerAnnounce () {
self.emit('trackerAnnounce')
if (self.swarm.numPeers === 0) self.emit('noPeers', 'tracker')
}

function onDHTAnnounce () {
self.emit('dhtAnnounce')
if (self.swarm.numPeers === 0) self.emit('noPeers', 'dht')
}

function onWarning (err) {
@@ -53,10 +53,17 @@ test('Download using DHT (via .torrent file)', function (t) {
maybeDone(null)
})

torrent.on('noPeers', function (announceType) {
t.equal(announceType, 'dht', 'noPeers event seen with correct announceType')
noPeersFound = true
maybeDone(null)
})

var announced = false
var loaded = false
var noPeersFound = false
function maybeDone (err) {
if ((announced && loaded) || err) cb(err, client1)
if ((announced && loaded && noPeersFound) || err) cb(err, client1)
}
},

@@ -15,7 +15,7 @@ test('Download using HTTP tracker (via magnet uri)', function (t) {
})

function magnetDownloadTest (t, serverType) {
t.plan(9)
t.plan(10)

var tracker = new TrackerServer(
serverType === 'udp' ? { http: false, ws: false } : { udp: false, ws: false }
@@ -59,6 +59,10 @@ function magnetDownloadTest (t, serverType) {
'Leaves of Grass by Walt Whitman.epub'
]

torrent.on('noPeers', function (announceType) {
t.equal(announceType, 'tracker', 'noPeers event seen with correct announceType')
})

t.deepEqual(torrent.files.map(function (file) { return file.name }), names)

torrent.load(fs.createReadStream(fixtures.leaves.contentPath), function (err) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.