Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions sources/src/TorrentPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,22 +735,27 @@ protocol_session::RemovedConnectionCallbackHandler<libtorrent::peer_id> TorrentP
protocol_session::FullPieceArrived<libtorrent::peer_id> TorrentPlugin::fullPieceArrived() {

return [this](const libtorrent::peer_id & peerId, const protocol_wire::PieceData & pieceData, int index) -> void {

// Make sure no outstanding calls exist for this index
assert(!_outstandingFullPieceArrivedCalls.count(index));

_outstandingFullPieceArrivedCalls[index] = peerId;

// Tell libtorrent to validate piece
// last argument is a flag which presently seems to only test
// flags & torrent::overwrite_existing, which seems to be whether
// the piece should be overwritten if it is already present
//
// libtorrent::torrent_plugin::on_piece_pass()
// libtorrent::torrent_plugin::on_piece_failed()
// processes result of checking

torrent()->add_piece(index, pieceData.piece().get(), 0);
if (!torrent()->have_piece(index)) {
// Make sure no outstanding calls exist for this index
assert(!_outstandingFullPieceArrivedCalls.count(index));

_outstandingFullPieceArrivedCalls[index] = peerId;

// Tell libtorrent to validate piece
// last argument is a flag which presently seems to only test
// flags & torrent::overwrite_existing, which seems to be whether
// the piece should be overwritten if it is already present
//
// libtorrent::torrent_plugin::on_piece_pass()
// libtorrent::torrent_plugin::on_piece_failed()
// processes result of checking
torrent()->add_piece(index, pieceData.piece().get(), 0);
} else {
// We already received the piece from another peer (most likely a non joystream peer)
// For now we ignore the validity of the piece data
// tell session about endpoint and piece
_session.validPieceReceivedOnConnection(peerId, index);
}
};
}

Expand Down