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

How to list peers #223

Closed
mmathys opened this issue Dec 29, 2014 · 1 comment
Closed

How to list peers #223

mmathys opened this issue Dec 29, 2014 · 1 comment

Comments

@mmathys
Copy link

@mmathys mmathys commented Dec 29, 2014

I am trying to list 10 random peers from a torrent, but my code doesn't work. Can anyone help?

var WebTorrent = require('webtorrent')
var Swarm = require('webtorrent-swarm')
var client = new WebTorrent({maxPeers:10})

var magnet_uri = "magnet:?xt=urn:btih:b415c913643e5ff49fe37d304bbb5e6e11ad5101&dn=ubuntu-14.10-desktop-amd64.iso";

client.download(magnet_uri, function (torrent) {

  var swarm = new Swarm(torrent.infoHash, "-AZ2200-6wfG2wk6wWLc")

  swarm.on('wire', function(wire) {

      console.log("wire")
      wire.on('unchoke', function() {
          // we are now unchoked
      })
      swarm.wires // <- list of all connected wires
      console.log("wires: "+swarm.wires)
  });
})
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Dec 29, 2014

You don't need to use the webtorrent-swarm module. Swarms are automatically created internally.

Try this instead:

var WebTorrent = require('webtorrent')

var client = new WebTorrent({ maxPeers:10 })

var magnet_uri = "magnet:?xt=urn:btih:b415c913643e5ff49fe37d304bbb5e6e11ad5101&dn=ubuntu-14.10-desktop-amd64.iso"

client.download(magnet_uri, function (torrent) {
  // print out ips of currently connected wires
  torrent.swarm.wires.forEach(function (wire) {
    console.log(wire.remoteAddress)
  })

  // print out ips of new wires the client connects to
  torrent.swarm.on('wire', function (wire) {
    console.log(wire.remoteAddress)
  })
})
@feross feross closed this Dec 29, 2014
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 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
2 participants
You can’t perform that action at this time.