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

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJulen Garcia Leunda <hicom150@gmail.com>2020-09-30 22:39:09 +0300
committerJulen Garcia Leunda <hicom150@gmail.com>2020-10-02 16:37:33 +0300
commit692b3d113c0a08a17ee53bca7e16180a94b4fbfe (patch)
tree07ba6df67701f9397d46a0ddaf26f7f5b2c880a1 /test
parent7aee819796c540df0b247fec1853098f9a591d4c (diff)
Add uTP support (BEP29)
Diffstat (limited to 'test')
-rw-r--r--test/node/conn-pool.js205
1 files changed, 205 insertions, 0 deletions
diff --git a/test/node/conn-pool.js b/test/node/conn-pool.js
new file mode 100644
index 0000000..435d951
--- /dev/null
+++ b/test/node/conn-pool.js
@@ -0,0 +1,205 @@
+var test = require('tape')
+var fixtures = require('webtorrent-fixtures')
+var WebTorrent = require('../../')
+const MemoryChunkStore = require('memory-chunk-store')
+const dgram = require('dgram')
+
+test('client.conn-pool: use TCP when uTP disabled', function (t) {
+ t.plan(6)
+
+ var client1 = new WebTorrent({ dht: false, tracker: false, utp: false })
+ var client2 = new WebTorrent({ dht: false, tracker: false, utp: false })
+
+ client1.on('error', function (err) { t.fail(err) })
+ client1.on('warning', function (err) { t.fail(err) })
+
+ client2.on('error', function (err) { t.fail(err) })
+ client2.on('warning', function (err) { t.fail(err) })
+
+ // Start seeding
+ client2.seed(fixtures.leaves.content, {
+ name: 'Leaves of Grass by Walt Whitman.epub',
+ announce: []
+ })
+
+ client2.on('listening', function () {
+ // Start downloading
+ var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
+
+ // Manually connect peers
+ torrent.addPeer('127.0.0.1:' + client2.address().port)
+
+ var order = 0
+
+ torrent.on('infoHash', function () {
+ t.equal(++order, 1)
+ })
+
+ torrent.on('metadata', function () {
+ t.equal(++order, 2)
+ })
+
+ torrent.on('ready', function () {
+ t.equal(++order, 3)
+ })
+
+ torrent.on('done', function () {
+ t.equal(++order, 4)
+
+ client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
+ client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ })
+ })
+})
+
+test('client.conn-pool: use uTP when uTP enabled', function (t) {
+ t.plan(6)
+
+ var client1 = new WebTorrent({ dht: false, tracker: false, utp: true })
+ var client2 = new WebTorrent({ dht: false, tracker: false, utp: true })
+
+ client1.on('error', function (err) { t.fail(err) })
+ client1.on('warning', function (err) { t.fail(err) })
+
+ client2.on('error', function (err) { t.fail(err) })
+ client2.on('warning', function (err) { t.fail(err) })
+
+ // Start seeding
+ client2.seed(fixtures.leaves.content, {
+ name: 'Leaves of Grass by Walt Whitman.epub',
+ announce: []
+ })
+
+ client2.on('listening', function () {
+ // Start downloading
+ var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
+
+ // Manually connect peers
+ torrent.addPeer('127.0.0.1:' + client2.address().port)
+
+ var order = 0
+
+ torrent.on('infoHash', function () {
+ t.equal(++order, 1)
+ })
+
+ torrent.on('metadata', function () {
+ t.equal(++order, 2)
+ })
+
+ torrent.on('ready', function () {
+ t.equal(++order, 3)
+ })
+
+ torrent.on('done', function () {
+ t.equal(++order, 4)
+
+ client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
+ client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ })
+ })
+})
+
+// Warning: slow test as we need to rely on connection timeouts
+test('client.conn-pool: fallback to TCP when uTP server failed', function (t) {
+ t.plan(6)
+
+ // force uTP server failure
+ const server = dgram.createSocket('udp4')
+ server.bind(63000)
+
+ var client1 = new WebTorrent({ dht: false, tracker: false, utp: true, torrentPort: 63000 })
+ var client2 = new WebTorrent({ dht: false, tracker: false, utp: false })
+
+ client1.on('error', function (err) { t.fail(err) })
+ client1.on('warning', function (err) { t.fail(err) })
+
+ client2.on('error', function (err) { t.fail(err) })
+ client2.on('warning', function (err) { t.fail(err) })
+
+ // Start seeding
+ client2.seed(fixtures.leaves.content, {
+ name: 'Leaves of Grass by Walt Whitman.epub',
+ announce: []
+ })
+
+ client2.on('listening', function () {
+ // Start downloading
+ var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
+
+ // Manually connect peers
+ torrent.addPeer('127.0.0.1:' + client2.address().port)
+
+ var order = 0
+
+ torrent.on('infoHash', function () {
+ t.equal(++order, 1)
+ })
+
+ torrent.on('metadata', function () {
+ t.equal(++order, 2)
+ })
+
+ torrent.on('ready', function () {
+ t.equal(++order, 3)
+ })
+
+ torrent.on('done', function () {
+ t.equal(++order, 4)
+
+ client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
+ client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+
+ server.close()
+ })
+ })
+})
+
+// Warning: slow test as we need to rely on connection timeouts
+test('client.conn-pool: fallback to TCP when remote client has uTP disabled', function (t) {
+ t.plan(6)
+
+ var client1 = new WebTorrent({ dht: false, tracker: false, utp: true })
+ var client2 = new WebTorrent({ dht: false, tracker: false, utp: false })
+
+ client1.on('error', function (err) { t.fail(err) })
+ client1.on('warning', function (err) { t.fail(err) })
+
+ client2.on('error', function (err) { t.fail(err) })
+ client2.on('warning', function (err) { t.fail(err) })
+
+ // Start seeding
+ client2.seed(fixtures.leaves.content, {
+ name: 'Leaves of Grass by Walt Whitman.epub',
+ announce: []
+ })
+
+ client2.on('listening', function () {
+ // Start downloading
+ var torrent = client1.add(fixtures.leaves.parsedTorrent.infoHash, { store: MemoryChunkStore })
+
+ // Manually connect peers
+ torrent.addPeer('127.0.0.1:' + client2.address().port)
+
+ var order = 0
+
+ torrent.on('infoHash', function () {
+ t.equal(++order, 1)
+ })
+
+ torrent.on('metadata', function () {
+ t.equal(++order, 2)
+ })
+
+ torrent.on('ready', function () {
+ t.equal(++order, 3)
+ })
+
+ torrent.on('done', function () {
+ t.equal(++order, 4)
+
+ client1.destroy(function (err) { t.error(err, 'client 1 destroyed') })
+ client2.destroy(function (err) { t.error(err, 'client 2 destroyed') })
+ })
+ })
+})