Welcome to mirror list, hosted at ThFree Co, Russian Federation.

client-add-duplicate-trackers.js « test - github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 161e920972bdfe47ae291fbcb13017fecf15539e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var fixtures = require('webtorrent-fixtures')
var test = require('tape')
var WebTorrent = require('../')

test('client.add: duplicate trackers', function (t) {
  t.plan(3)

  var client = new WebTorrent({ dht: false, tracker: false })

  client.on('error', function (err) { t.fail(err) })
  client.on('warning', function (err) { t.fail(err) })

  var torrent = client.add(fixtures.leaves.torrent, {
    announce: [ 'wss://example.com', 'wss://example.com', 'wss://example.com' ]
  })

  torrent.on('ready', function () {
    t.equal(torrent.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))
    client.remove(fixtures.leaves.magnetURI, function (err) { t.error(err, 'torrent destroyed') })
    client.destroy(function (err) { t.error(err, 'client destroyed') })
  })
})

test('client.add: duplicate trackers, with multiple torrents', function (t) {
  t.plan(5)

  // Re-use this object, in case webtorrent is changing it
  var opts = {
    announce: [ 'wss://example.com', 'wss://example.com', 'wss://example.com' ]
  }

  var client = new WebTorrent({ dht: false, tracker: false })

  client.on('error', function (err) { t.fail(err) })
  client.on('warning', function (err) { t.fail(err) })

  var torrent1 = client.add(fixtures.leaves.torrent, opts)

  torrent1.on('ready', function () {
    t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

    var torrent2 = client.add(fixtures.alice.torrent, opts)

    torrent2.on('ready', function () {
      t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

      torrent1.destroy(function (err) { t.error(err, 'torrent1 destroyed') })
      torrent2.destroy(function (err) { t.error(err, 'torrent2 destroyed') })
      client.destroy(function (err) { t.error(err, 'client destroyed') })
    })
  })
})

test('client.add: duplicate trackers (including in .torrent file), multiple torrents', function (t) {
  t.plan(5)

  // Re-use this object, in case webtorrent is changing it
  var opts = {
    announce: [ 'wss://example.com', 'wss://example.com', 'wss://example.com' ]
  }

  // Include the duplicate trackers in the .torrent files
  var parsedTorrentLeaves = Object.assign({}, fixtures.leaves.parsedTorrent)
  parsedTorrentLeaves.announce = [ 'wss://example.com', 'wss://example.com', 'wss://example.com' ]

  var parsedTorrentAlice = Object.assign({}, fixtures.alice.parsedTorrent)
  parsedTorrentAlice.announce = [ 'wss://example.com', 'wss://example.com', 'wss://example.com' ]

  var client = new WebTorrent({ dht: false, tracker: false })

  client.on('error', function (err) { t.fail(err) })
  client.on('warning', function (err) { t.fail(err) })

  var torrent1 = client.add(parsedTorrentLeaves, opts)

  torrent1.on('ready', function () {
    t.equal(torrent1.magnetURI, fixtures.leaves.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

    var torrent2 = client.add(parsedTorrentAlice, opts)

    torrent2.on('ready', function () {
      t.equal(torrent2.magnetURI, fixtures.alice.magnetURI + '&tr=' + encodeURIComponent('wss://example.com'))

      torrent1.destroy(function (err) { t.error(err, 'torrent1 destroyed') })
      torrent2.destroy(function (err) { t.error(err, 'torrent2 destroyed') })
      client.destroy(function (err) { t.error(err, 'client destroyed') })
    })
  })
})