Revert 9eea959 only the parts which affect src/BtPieceMessage.cc

This is because we are not sure that peer has a piece just sending off
its block. It should be notified by the peer.
pull/103/head
Tatsuhiro Tsujikawa 2013-06-13 21:34:08 +09:00
parent 9eea959455
commit e3506b04fb
1 changed files with 3 additions and 15 deletions

View File

@ -179,10 +179,8 @@ size_t BtPieceMessage::getMessageHeaderLength()
namespace { namespace {
struct PieceSendUpdate : public ProgressUpdate { struct PieceSendUpdate : public ProgressUpdate {
PieceSendUpdate(const SharedHandle<Peer>& peer, size_t headerLength, PieceSendUpdate(const SharedHandle<Peer>& peer, size_t headerLength)
size_t index, const SharedHandle<PieceStorage>& pieceStorage) : peer(peer), headerLength(headerLength) {}
: peer(peer), headerLength(headerLength), index(index),
pieceStorage(pieceStorage) {}
virtual void update(size_t length, bool complete) virtual void update(size_t length, bool complete)
{ {
if(headerLength > 0) { if(headerLength > 0) {
@ -191,17 +189,9 @@ struct PieceSendUpdate : public ProgressUpdate {
length -= m; length -= m;
} }
peer->updateUploadLength(length); peer->updateUploadLength(length);
if(complete && !peer->hasPiece(index)) {
// Update peer's bitfield because peer may not send HAVE message
// to us.
peer->updateBitfield(index, 1);
pieceStorage->addPieceStats(index);
}
} }
SharedHandle<Peer> peer; SharedHandle<Peer> peer;
size_t headerLength; size_t headerLength;
size_t index;
SharedHandle<PieceStorage> pieceStorage;
}; };
} // namespace } // namespace
@ -234,9 +224,7 @@ void BtPieceMessage::pushPieceData(int64_t offset, int32_t length) const
buf.reset(0); buf.reset(0);
getPeerConnection()->pushBytes(dbuf, length+MESSAGE_HEADER_LENGTH, getPeerConnection()->pushBytes(dbuf, length+MESSAGE_HEADER_LENGTH,
new PieceSendUpdate(getPeer(), new PieceSendUpdate(getPeer(),
MESSAGE_HEADER_LENGTH, MESSAGE_HEADER_LENGTH));
index_,
getPieceStorage()));
// To avoid upload rate overflow, we update the length here at // To avoid upload rate overflow, we update the length here at
// once. // once.
downloadContext_->updateUploadLength(length); downloadContext_->updateUploadLength(length);