mafintosh / torrent-stream

The low level streaming torrent engine that peerflix uses
MIT License
1.94k stars 228 forks source link

max connections not respected ? #99

Open smolleyes opened 9 years ago

smolleyes commented 9 years ago

hello

i have connections: 100 in my call to torrent-stream but when i read the swarm stats i have more than 300 peers connected when running :/ an idear why ?

thanks :)

mafintosh commented 9 years ago

can you share a gist of how you set it up?

smolleyes commented 9 years ago

hello mafintosh

https://gist.github.com/smolleyes/2672d76cc779d8ba5b96

(it s in the handleTorrent function...) i add some extra opts because i create a list of files when i have multiples video in a torrent so i can choose the file i want to stream

i have many problems since few days fitst, sometimes the engine won t be destroyed so the download continue when i destroy it, i found yesterday that if i call it like this (maybe wrong)

videoStreamer.deselect()
videoStreamer.files.pop()
videoStreamer.selection.forEach(function(sel){
    videoStreamer.selection.pop();
})
videoStreamer.swarm.destroy()
videoStreamer.destroy();
videoStreamer = null;

it always works... if i just call videoStreamer.destroy(), sometimes it s still downloading after that ...

2/ on many torrents peers can t be found or download is very slow, i looked at the code of app.js in peerflix then i found

readTorrent(filename, function (err, torrent, raw) {
    if (err) {
      console.error(err.message)
      process.exit(1)
    }
    ontorrent(raw) // use raw so we don't get infohash/metadata issues in torrent-stream.
  })

so i use the "raw" of read-torrent now as you can see in my gist and yes it s very very faster and peers are always found ! but it create some side effects with parse-torrent sometimes and my stream "crash" sometimes too

more exactly i had to modify line 64 of index.js in parse-torrent from torrent-stream deps with

if(torrent && torrent['url-list'] && torrent['url-list'].length !== 0) {

an idear why ?

thanks !

smolleyes commented 9 years ago

So no idears mafintosh ?:)

mafintosh commented 9 years ago

2) looks like this might be solved if we upgrade to latest parse-torrent (https://github.com/feross/parse-torrent-file/blob/master/index.js#L66-L75)

smolleyes commented 9 years ago

so i just replace parse-torrent by this one ?

smolleyes commented 9 years ago

done, seems working :)

mafintosh commented 9 years ago

bumped parse-torrent in torrent-stream 0.17.0