mafintosh / peer-wire-swarm

swarm implementation for bittorrent
MIT License
80 stars 18 forks source link

Fixes Reconnecting to Wires #15

Open jaruba opened 9 years ago

jaruba commented 9 years ago

As mentioned on https://github.com/mafintosh/peerflix/issues/203

Fixes reconnecting to wires in swarm.resume() and adds the swarm.reconnectAll() method.

jaruba commented 9 years ago

I can confirm that there is a need for swarm.reconnectAll() to be exposed outside this particular issue, in one of my tests on poor health torrents, one torrent in particular went from 4 to 2 peers when the file was 50% downloaded.

One of the disconnected peers was the one I was primarily downloading from with the highest speed. Manually executing swarm.reconnectAll() in this scenario reconnected to the 2 missing peers successfully and the torrent continued to download with it's normal speed.

I have experienced this issue before, although I am still uncertain what causes the peers to disconnect in mid-download. And I know that at least @watdafox mentioned this happens in Popcorn Time too as stated in this comment: https://github.com/mafintosh/peerflix/issues/189#issuecomment-77709737

This would not fix the secondary issue of disconnecting peers but would give the possibility of a clean workaround when it happens.

asapach commented 9 years ago

@jaruba, some() effectively evaluates your function in loop and stops when you return truthy. Otherwise it keeps going.