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

torrent.addPeer() disconnects soon after handshake #1333

Closed
gurupras opened this issue Mar 11, 2018 · 1 comment
Closed

torrent.addPeer() disconnects soon after handshake #1333

gurupras opened this issue Mar 11, 2018 · 1 comment
Labels

Comments

@gurupras
Copy link

@gurupras gurupras commented Mar 11, 2018

I have already set up simple-peer instances using Socket.IO. My plan was to add these via torrent.addPeer() to remove the incredibly long delay (possibly due to bad tracker configuration) that my tracker server is taking to establish a connection between two peers.

This approach sometimes works for the first few seconds of the torrent's video, but then the leecher receives a close event and does not receive or play the video anymore.

A test page can be found at: https://twoseven.xyz:8405/
I have also attached the relevant code of the client below.

What version of WebTorrent?
v0.98.24
What operating system and Node.js version?
Ubuntu 16.04
NodeJS v8.6.0
What browser and version? (if using WebTorrent in the browser)
Chrome v64.0.3282.186

What did you expect to happen?
The entire torrent is shared successfully via the manually added peer

What actually happened?
The torrent is not being transferred using the manually added peer. Occasionally, a part of the torrent is transferred before a close event is emitted by the manually added simple-peer.

Using localStorage.debug="webtorrent,webtorrent:torrent,webtorrent:peer,simple-peer", I got the following:

webtorrent [2d57573] new webtorrent (peerId 2d5757303039382d5352453878426f7253424769, nodeId c2cc1d052915666f41170246bbb340c7a6598a16, port 0) +0ms
webtorrent.debug.js:3703 webtorrent [2d57573] listening +31ms
simple-peer-socketio.min.js:1 Received peer info: {"initiator":true,"trickle":true}
simple-peer-socketio.min.js:1 simple-peer [cf4b845] new peer {initiator: true, trickle: true} +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] signal +11ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] signalingStateChange have-local-offer +1ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] iceStateChange (connection: new) (gathering: gathering) +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] signal() +28ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] signal() +1ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] signalingStateChange stable +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] iceStateChange (connection: checking) (gathering: gathering) +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] iceStateChange (connection: checking) (gathering: complete) +2ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] iceStateChange (connection: connected) (gathering: complete) +1ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] maybeReady pc true channel false +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] iceStateChange (connection: completed) (gathering: complete) +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] maybeReady pc true channel false +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] on channel open +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] maybeReady pc true channel true +0ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] connect local: 192.168.2.179:58873 remote: 192.168.2.179:58875 +2ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] connect +1ms
2index.js:36 self.dragging=true
webtorrent.debug.js:3703 webtorrent [2d57573] seed +12s
webtorrent.debug.js:3703 webtorrent [2d57573] add +0ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [unknown infohash] new torrent +0ms
index.js:40 self.dragging=false
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] got metadata +615ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 0-962 (priority 0) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] verifying existing torrent data +4ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] done verifying +17ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] on store +5ms
index.js:228 torrent ready
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] file done: SampleVideo_720x480_30mb.mp4 +654ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] torrent done: 7fe98bcb7bc395d1441fe102935cd356dd7753d3 +4ms
webtorrent.debug.js:3703 webtorrent [2d57573] on seed +1s
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] add peer eo3EvWiqVQb69DojAAAu +10ms
webtorrent.debug.js:3703 webtorrent:peer new Peer eo3EvWiqVQb69DojAAAu +0ms
webtorrent.debug.js:3703 webtorrent:peer Peer eo3EvWiqVQb69DojAAAu connected +6ms
index.js:156 Successfully added peer-eo3EvWiqVQb69DojAAAu
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 0-962 (priority 1) +27ms
index.js:170 Torrent file ready for seeding
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 0-962 (priority 1) +21ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 0-962 (priority 1) +6ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 0-962 (priority 1) +6ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 0-962 (priority 1) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 0-962 (priority 1) +4ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 0-962 (priority 1) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 0-962 (priority 1) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 0-962 (priority 1) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 959-962 (priority 1) +4ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 959-962 (priority 1) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 959-962 (priority 1) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 959-962 (priority 1) +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 959-962 (priority 1) +16ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] deselect 959-962 (priority 1) +6ms
index.js:81 Received torrent info..Starting leecher
index.js:85 magnet:?xt=urn:btih:7fe98bcb7bc395d1441fe102935cd356dd7753d3&dn=SampleVideo_720x480_30mb.mp4
index.js:86 https://twoseven.xyz:8405/torrents/7fe98bcb7bc395d1441fe102935cd356dd7753d3.torrent
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 0-962 (priority 1) +37ms
webtorrent.debug.js:3703 webtorrent:peer Peer eo3EvWiqVQb69DojAAAu got handshake 7fe98bcb7bc395d1441fe102935cd356dd7753d3 +230ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] got wire fd9b17e4 (192.168.2.179:58875) +81ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] on channel close +14s
simple-peer-socketio.min.js:1 simple-peer [cf4b845] destroy (error: undefined) +1ms
webtorrent.debug.js:3703 webtorrent:peer destroy eo3EvWiqVQb69DojAAAu (error: undefined) +16ms
simple-peer-socketio.min.js:1 simple-peer [cf4b845] destroy (error: null) +1ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] removePeer eo3EvWiqVQb69DojAAAu +31ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] _drain numConns 0 maxConns 55 +0ms

On the other client, I get:

webtorrent [2d57573] add +14s
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [unknown infohash] new torrent +0ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] got metadata +75ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 0-962 (priority 0) +7ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] verifying existing torrent data +5ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] done verifying +18ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] on store +1ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] add peer mAU8qkzd4MeMsLiUAAAt +1ms
webtorrent.debug.js:3703 webtorrent:peer new Peer mAU8qkzd4MeMsLiUAAAt +0ms
webtorrent.debug.js:3703 webtorrent:peer Peer mAU8qkzd4MeMsLiUAAAt connected +1ms
index.js:156 Successfully added peer-mAU8qkzd4MeMsLiUAAAt
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] select 0-962 (priority 1) +15ms
index.js:105 Added torrent
index.js:228 torrent ready
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] critical 0-2 +5ms
webtorrent.debug.js:3703 webtorrent:peer destroy mAU8qkzd4MeMsLiUAAAt (error: write after end) +32ms
simple-peer-socketio.min.js:1 simple-peer [ad5fd1d] destroy (error: null) +14s
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] removePeer mAU8qkzd4MeMsLiUAAAt +27ms
webtorrent.debug.js:3703 webtorrent:torrent [2d57573] [7fe98bc] _drain numConns 0 maxConns 55 +1ms

Client

var ANNOUNCE_URLS = []

// This function is called when a file is drag-and-dropped onto the page
function handleLocalFiles (files, dz) {
  var wtClient = window.wtClient
  wtClient.seed(files[0], {
    urlList: ANNOUNCE_URLS,
    announceList: [ANNOUNCE_URLS],
    private: true
  }, function (torrent) {
    addPeersToTorrent(torrent)
    loadTorrentOntoElement(torrent, '#video')

    socket.emit('torrent', {
      seeder: socket.id,
      infoHash: torrent.infoHash,
      magnetURI: torrent.magnetURI,
      torrentFile: torrent.torrentFile
    })
  })
}

// Handle the socket 'torrent' event
function setupSocketIo() {
  socket.on('torrent', function (info) {
    console.log(`Received torrent info..Starting leecher`)
    var wtClient = window.wtClient
    var torrentUrl = window.location.origin + info.torrentUrl
    wtClient.add(torrentUrl, {
      announce: ANNOUNCE_URLS
    }, function (torrent) {
      addPeersToTorrent(torrent)
      if (info.seeder !== socket.id) {
        // If I'm the seeder, I just load it locally
        loadTorrentOntoElement(torrent, '#video')
      }
      console.log('Added torrent')
    })
  })
}

// Manually add peers to a torrent 
function addPeersToTorrent (torrent) {
  var peers = simplePeer.peers
  for (var peerId of Object.keys(peers)) {
    var peer = peers[peerId]
    if (!torrent.addPeer(peer)) {
      console.log(`Failed to add peer-${peer.id}`)
    } else {
      console.log(`Successfully added peer-${peer.id}`)
    }
  }
}
@gurupras gurupras changed the title torrent.addPeer() not working as expected torrent.addPeer() disconnects soon after handshake Mar 16, 2018
@stale

This comment has been minimized.

Copy link

@stale stale bot commented Jun 14, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Jun 14, 2018
@stale stale bot closed this Jun 21, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Sep 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.