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

get connected peer list and their progress #1095

Closed
souravndp opened this issue Apr 6, 2017 · 5 comments
Closed

get connected peer list and their progress #1095

souravndp opened this issue Apr 6, 2017 · 5 comments

Comments

@souravndp
Copy link

@souravndp souravndp commented Apr 6, 2017

I want to use webtorrent in the browser. I need to get the list of connected peers and their progress. eg: 13.234.5.156, 95% ; 134.67.54.3, 100% etc.

I have looked into API section and found out torrent.numPeers and torrent.on('wire', function (wire) {}). but didn't find any specific tutorial/help for my requirement. torrent.numPeers returns the total number of peers but I need connected peers. Also, it is mentioned torrent.on('wire', function (wire) {}) is emitted whenever a new peer is connected for this torrent. but how to get the IP of the peer?

Is this feature available? If yes, can you please point me towards the right direction?

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Apr 6, 2017

You'd be best scraping a tracker or creating a backend where you send that information. The wire API can be found here: https://github.com/feross/bittorrent-protocol, but you can only query the stats between you as a peer and that peer.

If the peers are TCP/UDP (Won't work on browser), you can get the IP using wire.addr

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Apr 7, 2017

Btw, torrent.numPeers does return the number of currently connected peers.

You might be able to get the info you need by listening to the 'wire' event, actually:

torrent.on('wire', function (wire) {
  var downloaded = 0
  for (var index = 0, len = torrent.pieces.length; index < len; ++index) {
    if (wire.peerPieces.get(index)) {
      downloaded += (index === len - 1) ? torrent.lastPieceLength : torrent.pieceLength
    }
  }
  var percentComplete = (downloaded / torrent.length) * 100
  console.log('Peer ' + wire.addr + ' connected with ' + percentComplete + '% complete')
})

(Untested, but something like that should work)

@souravndp

This comment has been minimized.

Copy link
Author

@souravndp souravndp commented Apr 7, 2017

@feross Thank you for your help. I will test the code later. just for information, is this okay to post such questions asking for help here? After all, the section is named as 'issues'. Or, should I post this to some place else, like StackOverflow? I would prefer to post here if this is not much a problem.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Apr 7, 2017

Posting questions is fine, but ideally you would chat with others on https://gitter.im/feross/webtorrent first 👍 Or if you use IRC, that chat room is linked to #webtorrent on freenode.

@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 3, 2018

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators May 3, 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
3 participants
You can’t perform that action at this time.