mafintosh / torrent-stream

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

block peers that consistently send bad pieces #59

Closed asapach closed 10 years ago

BastienClement commented 10 years ago

There is already a list of peers per pieces being maintained - this is used for hotswapping.

Unless I'm missing something, the reservation list is not really usable for sources peer. When everything is done and we check the hash value, the reservation[piece] array is [null, null, null, ...]. Also during download, this array can contains duplicates of the same wire.

f4c16350e7644129e70c4243fc7541e9c6040f67 implements a uniquified and permanent source list. I tried to match the rest of the object construction, this means that the source list is cleared on .flush() just before checking hash.

This would lead to something like

var sources = p.sources; // save sources in case of hash-fail
var buffer = p.flush();

if (sha1(buffer) !== torrent.pieces[index]) {
    ...
    sources.forEach(...)
}

in index.js, acceptable for me.

BastienClement commented 10 years ago

Don't merge this right now.

https://github.com/mafintosh/torrent-stream/blob/efaea6d58dce687a8df87b22aba71d888dd7684b/index.js#L618

That's not how the blocklist array is constructed. This code is just plain wrong.

asapach commented 10 years ago

@galedric, fixed.