2006-12-24 06:25:21 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-12-24 06:25:21 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "DefaultBtMessageDispatcher.h"
|
2008-11-03 06:49:02 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
#include "prefs.h"
|
|
|
|
#include "BtAbortOutstandingRequestEvent.h"
|
|
|
|
#include "BtCancelSendingPieceEvent.h"
|
|
|
|
#include "BtChokingEvent.h"
|
|
|
|
#include "BtMessageFactory.h"
|
2007-07-20 17:06:21 +00:00
|
|
|
#include "message.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "PeerStorage.h"
|
|
|
|
#include "PieceStorage.h"
|
|
|
|
#include "BtMessage.h"
|
|
|
|
#include "Peer.h"
|
|
|
|
#include "Piece.h"
|
|
|
|
#include "LogFactory.h"
|
|
|
|
#include "Logger.h"
|
2008-04-13 01:25:36 +00:00
|
|
|
#include "a2functional.h"
|
2009-04-25 17:01:29 +00:00
|
|
|
#include "a2algo.h"
|
2008-12-10 14:14:11 +00:00
|
|
|
#include "RequestGroupMan.h"
|
2009-02-28 11:48:26 +00:00
|
|
|
#include "RequestGroup.h"
|
2010-03-21 07:05:49 +00:00
|
|
|
#include "util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
|
|
|
|
|
|
|
DefaultBtMessageDispatcher::DefaultBtMessageDispatcher():
|
|
|
|
cuid(0),
|
|
|
|
requestTimeout(0),
|
|
|
|
logger(LogFactory::getInstance()) {}
|
|
|
|
|
|
|
|
DefaultBtMessageDispatcher::~DefaultBtMessageDispatcher()
|
|
|
|
{
|
2010-02-09 12:20:20 +00:00
|
|
|
if(logger->debug()) {
|
|
|
|
logger->debug("DefaultBtMessageDispatcher::deleted");
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
void DefaultBtMessageDispatcher::addMessageToQueue(const BtMessageHandle& btMessage)
|
|
|
|
{
|
|
|
|
btMessage->onQueued();
|
|
|
|
messageQueue.push_back(btMessage);
|
|
|
|
}
|
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
void DefaultBtMessageDispatcher::addMessageToQueue
|
|
|
|
(const std::vector<SharedHandle<BtMessage> >& btMessages)
|
2006-12-24 06:25:21 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
for(std::vector<SharedHandle<BtMessage> >::const_iterator itr =
|
2010-02-28 16:04:52 +00:00
|
|
|
btMessages.begin(), eoi = btMessages.end(); itr != eoi; ++itr) {
|
2006-12-24 06:25:21 +00:00
|
|
|
addMessageToQueue(*itr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcher::sendMessages() {
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> > tempQueue;
|
2008-05-17 07:31:32 +00:00
|
|
|
while(!messageQueue.empty()) {
|
2006-12-24 06:25:21 +00:00
|
|
|
BtMessageHandle msg = messageQueue.front();
|
|
|
|
messageQueue.pop_front();
|
2008-12-10 14:14:11 +00:00
|
|
|
if(msg->isUploading() && !msg->isSendingInProgress()) {
|
2009-02-28 11:48:26 +00:00
|
|
|
if(_requestGroupMan->doesOverallUploadSpeedExceed() ||
|
2010-01-05 16:01:46 +00:00
|
|
|
_downloadContext->getOwnerRequestGroup()->doesUploadSpeedExceed()) {
|
|
|
|
tempQueue.push_back(msg);
|
|
|
|
continue;
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
msg->send();
|
2009-03-19 13:42:10 +00:00
|
|
|
if(msg->isUploading()) {
|
|
|
|
_peerStorage->updateTransferStatFor(peer);
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
if(msg->isSendingInProgress()) {
|
|
|
|
messageQueue.push_front(msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-04 15:53:47 +00:00
|
|
|
if(!tempQueue.empty()) {
|
|
|
|
// Insert pending message to the front, so that message is likely sent in
|
|
|
|
// the same order as it is queued.
|
|
|
|
if(!messageQueue.empty() && messageQueue.front()->isSendingInProgress()) {
|
|
|
|
messageQueue.insert(messageQueue.begin()+1,
|
2010-01-05 16:01:46 +00:00
|
|
|
tempQueue.begin(), tempQueue.end());
|
2008-06-04 15:53:47 +00:00
|
|
|
} else {
|
|
|
|
messageQueue.insert(messageQueue.begin(),
|
2010-01-05 16:01:46 +00:00
|
|
|
tempQueue.begin(), tempQueue.end());
|
2008-06-04 15:53:47 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel sending piece message to peer.
|
2008-03-09 12:24:01 +00:00
|
|
|
void DefaultBtMessageDispatcher::doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length)
|
2006-12-24 06:25:21 +00:00
|
|
|
{
|
2009-04-21 14:52:04 +00:00
|
|
|
BtCancelSendingPieceEvent event(index, begin, length);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> > tempQueue
|
|
|
|
(messageQueue.begin(), messageQueue.end());
|
2009-04-25 17:01:29 +00:00
|
|
|
|
2010-01-05 16:01:46 +00:00
|
|
|
forEachMemFunSH(tempQueue.begin(), tempQueue.end(),
|
|
|
|
&BtMessage::onCancelSendingPieceEvent, event);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel sending piece message to peer.
|
|
|
|
// TODO Is this method really necessary?
|
2010-02-28 12:30:11 +00:00
|
|
|
void DefaultBtMessageDispatcher::doCancelSendingPieceAction
|
|
|
|
(const SharedHandle<Piece>& piece)
|
2006-12-24 06:25:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-05-17 07:31:32 +00:00
|
|
|
class AbortOutstandingRequest {
|
|
|
|
private:
|
|
|
|
SharedHandle<Piece> _piece;
|
2010-03-20 14:30:36 +00:00
|
|
|
cuid_t _cuid;
|
2008-05-17 07:31:32 +00:00
|
|
|
Logger* _logger;
|
|
|
|
public:
|
2010-03-20 14:30:36 +00:00
|
|
|
AbortOutstandingRequest(const SharedHandle<Piece>& piece, cuid_t cuid):
|
2008-05-17 07:31:32 +00:00
|
|
|
_piece(piece),
|
|
|
|
_cuid(cuid),
|
|
|
|
_logger(LogFactory::getInstance()) {}
|
|
|
|
|
|
|
|
void operator()(const RequestSlot& slot) const
|
|
|
|
{
|
2010-02-09 12:20:20 +00:00
|
|
|
if(_logger->debug()) {
|
|
|
|
_logger->debug(MSG_DELETING_REQUEST_SLOT,
|
2010-03-21 07:05:49 +00:00
|
|
|
util::itos(_cuid).c_str(),
|
2010-02-09 12:20:20 +00:00
|
|
|
slot.getIndex(),
|
|
|
|
slot.getBlockIndex());
|
|
|
|
_logger->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
|
|
|
|
}
|
2008-05-17 07:31:32 +00:00
|
|
|
_piece->cancelBlock(slot.getBlockIndex());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
// localhost cancels outstanding download requests to the peer.
|
2010-02-28 12:30:11 +00:00
|
|
|
void DefaultBtMessageDispatcher::doAbortOutstandingRequestAction
|
|
|
|
(const SharedHandle<Piece>& piece) {
|
2008-05-17 07:31:32 +00:00
|
|
|
RequestSlot rs(piece->getIndex(), 0, 0, 0);
|
|
|
|
std::deque<RequestSlot>::iterator first =
|
|
|
|
std::lower_bound(requestSlots.begin(), requestSlots.end(), rs);
|
|
|
|
|
|
|
|
rs.setIndex(piece->getIndex()+1);
|
|
|
|
std::deque<RequestSlot>::iterator last =
|
|
|
|
std::lower_bound(requestSlots.begin(), requestSlots.end(), rs);
|
|
|
|
|
|
|
|
std::for_each(first, last, AbortOutstandingRequest(piece, cuid));
|
|
|
|
requestSlots.erase(first, last);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2009-04-21 14:52:04 +00:00
|
|
|
BtAbortOutstandingRequestEvent event(piece);
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> > tempQueue
|
|
|
|
(messageQueue.begin(), messageQueue.end());
|
2009-04-25 17:01:29 +00:00
|
|
|
forEachMemFunSH(tempQueue.begin(), tempQueue.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
&BtMessage::onAbortOutstandingRequestEvent, event);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 07:31:32 +00:00
|
|
|
class ProcessChokedRequestSlot {
|
|
|
|
private:
|
2010-03-20 14:30:36 +00:00
|
|
|
cuid_t _cuid;
|
2008-05-17 07:31:32 +00:00
|
|
|
SharedHandle<Peer> _peer;
|
|
|
|
SharedHandle<PieceStorage> _pieceStorage;
|
|
|
|
Logger* _logger;
|
|
|
|
public:
|
2010-03-20 14:30:36 +00:00
|
|
|
ProcessChokedRequestSlot(cuid_t cuid,
|
2010-01-05 16:01:46 +00:00
|
|
|
const SharedHandle<Peer>& peer,
|
|
|
|
const SharedHandle<PieceStorage>& pieceStorage):
|
2008-05-17 07:31:32 +00:00
|
|
|
_cuid(cuid),
|
|
|
|
_peer(peer),
|
|
|
|
_pieceStorage(pieceStorage),
|
|
|
|
_logger(LogFactory::getInstance()) {}
|
|
|
|
|
|
|
|
void operator()(const RequestSlot& slot) const
|
|
|
|
{
|
|
|
|
if(!_peer->isInPeerAllowedIndexSet(slot.getIndex())) {
|
2010-02-09 12:20:20 +00:00
|
|
|
if(_logger->debug()) {
|
|
|
|
_logger->debug(MSG_DELETING_REQUEST_SLOT_CHOKED,
|
2010-03-21 07:05:49 +00:00
|
|
|
util::itos(_cuid).c_str(),
|
2010-02-09 12:20:20 +00:00
|
|
|
slot.getIndex(),
|
|
|
|
slot.getBlockIndex());
|
|
|
|
_logger->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
|
|
|
|
}
|
2008-05-17 07:31:32 +00:00
|
|
|
SharedHandle<Piece> piece = _pieceStorage->getPiece(slot.getIndex());
|
2007-01-11 16:32:31 +00:00
|
|
|
piece->cancelBlock(slot.getBlockIndex());
|
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 07:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FindChokedRequestSlot {
|
|
|
|
private:
|
|
|
|
SharedHandle<Peer> _peer;
|
|
|
|
public:
|
|
|
|
FindChokedRequestSlot(const SharedHandle<Peer>& peer):
|
|
|
|
_peer(peer) {}
|
|
|
|
|
|
|
|
bool operator()(const RequestSlot& slot) const
|
|
|
|
{
|
|
|
|
return !_peer->isInPeerAllowedIndexSet(slot.getIndex());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// localhost received choke message from the peer.
|
|
|
|
void DefaultBtMessageDispatcher::doChokedAction()
|
|
|
|
{
|
|
|
|
std::for_each(requestSlots.begin(), requestSlots.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
ProcessChokedRequestSlot(cuid, peer, _pieceStorage));
|
2008-05-17 07:31:32 +00:00
|
|
|
|
|
|
|
requestSlots.erase(std::remove_if(requestSlots.begin(), requestSlots.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
FindChokedRequestSlot(peer)),
|
|
|
|
requestSlots.end());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// localhost dispatched choke message to the peer.
|
|
|
|
void DefaultBtMessageDispatcher::doChokingAction()
|
|
|
|
{
|
2009-04-21 14:52:04 +00:00
|
|
|
BtChokingEvent event;
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<BtMessage> > tempQueue
|
|
|
|
(messageQueue.begin(), messageQueue.end());
|
2009-04-25 17:01:29 +00:00
|
|
|
forEachMemFunSH(tempQueue.begin(), tempQueue.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
&BtMessage::onChokingEvent, event);
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 07:31:32 +00:00
|
|
|
class ProcessStaleRequestSlot {
|
|
|
|
private:
|
2010-03-20 14:30:36 +00:00
|
|
|
cuid_t _cuid;
|
2008-05-17 07:31:32 +00:00
|
|
|
SharedHandle<Peer> _peer;
|
|
|
|
SharedHandle<PieceStorage> _pieceStorage;
|
|
|
|
BtMessageDispatcher* _messageDispatcher;
|
|
|
|
WeakHandle<BtMessageFactory> _messageFactory;
|
|
|
|
time_t _requestTimeout;
|
|
|
|
Logger* _logger;
|
|
|
|
public:
|
2010-03-20 14:30:36 +00:00
|
|
|
ProcessStaleRequestSlot(cuid_t cuid, const SharedHandle<Peer>& peer,
|
2010-01-05 16:01:46 +00:00
|
|
|
const SharedHandle<PieceStorage>& pieceStorage,
|
|
|
|
BtMessageDispatcher* dispatcher,
|
|
|
|
const WeakHandle<BtMessageFactory>& factory,
|
|
|
|
time_t requestTimeout):
|
2008-05-17 07:31:32 +00:00
|
|
|
_cuid(cuid),
|
|
|
|
_peer(peer),
|
|
|
|
_pieceStorage(pieceStorage),
|
|
|
|
_messageDispatcher(dispatcher),
|
|
|
|
_messageFactory(factory),
|
|
|
|
_requestTimeout(requestTimeout),
|
|
|
|
_logger(LogFactory::getInstance()) {}
|
|
|
|
|
|
|
|
void operator()(const RequestSlot& slot)
|
|
|
|
{
|
2010-03-06 08:29:53 +00:00
|
|
|
if(slot.isTimeout(_requestTimeout)) {
|
2010-02-09 12:20:20 +00:00
|
|
|
if(_logger->debug()) {
|
|
|
|
_logger->debug(MSG_DELETING_REQUEST_SLOT_TIMEOUT,
|
2010-03-21 07:05:49 +00:00
|
|
|
util::itos(_cuid).c_str(),
|
2010-02-09 12:20:20 +00:00
|
|
|
slot.getBlockIndex());
|
|
|
|
_logger->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
|
|
|
|
}
|
2008-05-31 05:46:16 +00:00
|
|
|
slot.getPiece()->cancelBlock(slot.getBlockIndex());
|
2008-05-17 07:31:32 +00:00
|
|
|
_peer->snubbing(true);
|
2008-05-31 05:46:16 +00:00
|
|
|
} else if(slot.getPiece()->hasBlock(slot.getBlockIndex())) {
|
2010-02-09 12:20:20 +00:00
|
|
|
if(_logger->debug()) {
|
|
|
|
_logger->debug(MSG_DELETING_REQUEST_SLOT_ACQUIRED,
|
2010-03-21 07:05:49 +00:00
|
|
|
util::itos(_cuid).c_str(),
|
2010-02-09 12:20:20 +00:00
|
|
|
slot.getBlockIndex());
|
|
|
|
_logger->debug("index=%d, begin=%d", slot.getIndex(), slot.getBegin());
|
|
|
|
}
|
2008-05-17 07:31:32 +00:00
|
|
|
_messageDispatcher->addMessageToQueue
|
2010-01-05 16:01:46 +00:00
|
|
|
(_messageFactory->createCancelMessage(slot.getIndex(),
|
|
|
|
slot.getBegin(),
|
|
|
|
slot.getLength()));
|
2008-05-17 07:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FindStaleRequestSlot {
|
|
|
|
private:
|
|
|
|
SharedHandle<PieceStorage> _pieceStorage;
|
|
|
|
time_t _requestTimeout;
|
|
|
|
public:
|
|
|
|
FindStaleRequestSlot(const SharedHandle<PieceStorage>& pieceStorage,
|
2010-01-05 16:01:46 +00:00
|
|
|
time_t requestTimeout):
|
2008-05-17 07:31:32 +00:00
|
|
|
_pieceStorage(pieceStorage),
|
|
|
|
_requestTimeout(requestTimeout) {}
|
|
|
|
|
|
|
|
bool operator()(const RequestSlot& slot)
|
|
|
|
{
|
2010-03-06 08:29:53 +00:00
|
|
|
if(slot.isTimeout(_requestTimeout)) {
|
2008-05-17 07:31:32 +00:00
|
|
|
return true;
|
2006-12-24 06:25:21 +00:00
|
|
|
} else {
|
2008-05-31 05:46:16 +00:00
|
|
|
if(slot.getPiece()->hasBlock(slot.getBlockIndex())) {
|
2010-01-05 16:01:46 +00:00
|
|
|
return true;
|
2008-05-17 07:31:32 +00:00
|
|
|
} else {
|
2010-01-05 16:01:46 +00:00
|
|
|
return false;
|
2008-05-17 07:31:32 +00:00
|
|
|
}
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-17 07:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcher::checkRequestSlotAndDoNecessaryThing()
|
|
|
|
{
|
|
|
|
std::for_each(requestSlots.begin(), requestSlots.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
ProcessStaleRequestSlot(cuid,
|
|
|
|
peer,
|
|
|
|
_pieceStorage,
|
|
|
|
this,
|
|
|
|
messageFactory,
|
|
|
|
requestTimeout));
|
2008-05-17 07:31:32 +00:00
|
|
|
requestSlots.erase(std::remove_if(requestSlots.begin(), requestSlots.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
FindStaleRequestSlot(_pieceStorage,
|
|
|
|
requestTimeout)),
|
|
|
|
requestSlots.end());
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DefaultBtMessageDispatcher::isSendingInProgress()
|
|
|
|
{
|
|
|
|
if(messageQueue.size() > 0) {
|
|
|
|
return messageQueue.front()->isSendingInProgress();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-17 07:31:32 +00:00
|
|
|
class BlockIndexLess {
|
|
|
|
public:
|
|
|
|
bool operator()(const RequestSlot& lhs, const RequestSlot& rhs) const
|
|
|
|
{
|
|
|
|
if(lhs.getIndex() == rhs.getIndex()) {
|
|
|
|
return lhs.getBlockIndex() < rhs.getBlockIndex();
|
|
|
|
} else {
|
|
|
|
return lhs.getIndex() < rhs.getIndex();
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-17 07:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool DefaultBtMessageDispatcher::isOutstandingRequest(size_t index, size_t blockIndex) {
|
|
|
|
RequestSlot rs(index, 0, 0, blockIndex);
|
|
|
|
|
|
|
|
std::deque<RequestSlot>::iterator i =
|
|
|
|
std::lower_bound(requestSlots.begin(), requestSlots.end(), rs, BlockIndexLess());
|
|
|
|
return i != requestSlots.end() &&
|
|
|
|
(*i).getIndex() == index && (*i).getBlockIndex() == blockIndex;
|
2006-12-24 06:25:21 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
RequestSlot
|
2008-03-09 12:24:01 +00:00
|
|
|
DefaultBtMessageDispatcher::getOutstandingRequest(size_t index, uint32_t begin, size_t length)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-05-31 05:46:16 +00:00
|
|
|
RequestSlot ret;
|
2008-05-17 07:31:32 +00:00
|
|
|
RequestSlot rs(index, begin, length, 0);
|
|
|
|
std::deque<RequestSlot>::iterator i =
|
|
|
|
std::lower_bound(requestSlots.begin(), requestSlots.end(), rs);
|
|
|
|
if(i != requestSlots.end() && (*i) == rs) {
|
|
|
|
ret = *i;
|
|
|
|
} else {
|
|
|
|
ret = RequestSlot::nullSlot;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
2008-05-17 07:31:32 +00:00
|
|
|
return ret;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcher::removeOutstandingRequest(const RequestSlot& slot)
|
|
|
|
{
|
2008-05-17 07:31:32 +00:00
|
|
|
std::deque<RequestSlot>::iterator i =
|
|
|
|
std::lower_bound(requestSlots.begin(), requestSlots.end(), slot);
|
|
|
|
if(i != requestSlots.end() && (*i) == slot) {
|
2008-12-29 13:58:21 +00:00
|
|
|
AbortOutstandingRequest(slot.getPiece(), cuid)(*i);
|
2008-05-17 07:31:32 +00:00
|
|
|
requestSlots.erase(i);
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-05-17 07:31:32 +00:00
|
|
|
void DefaultBtMessageDispatcher::addOutstandingRequest(const RequestSlot& slot)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-05-17 07:31:32 +00:00
|
|
|
std::deque<RequestSlot>::iterator i =
|
|
|
|
std::lower_bound(requestSlots.begin(), requestSlots.end(), slot);
|
|
|
|
if(i == requestSlots.end() || (*i) != slot) {
|
|
|
|
requestSlots.insert(i, slot);
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-13 01:25:36 +00:00
|
|
|
size_t DefaultBtMessageDispatcher::countOutstandingUpload()
|
|
|
|
{
|
|
|
|
return std::count_if(messageQueue.begin(), messageQueue.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
mem_fun_sh(&BtMessage::isUploading));
|
2008-04-13 01:25:36 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void DefaultBtMessageDispatcher::setPeer(const SharedHandle<Peer>& peer)
|
|
|
|
{
|
|
|
|
this->peer = peer;
|
|
|
|
}
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
void DefaultBtMessageDispatcher::setDownloadContext
|
|
|
|
(const SharedHandle<DownloadContext>& downloadContext)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2009-06-28 10:37:15 +00:00
|
|
|
_downloadContext = downloadContext;
|
2008-11-03 06:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcher::setPieceStorage
|
|
|
|
(const SharedHandle<PieceStorage>& pieceStorage)
|
|
|
|
{
|
|
|
|
_pieceStorage = pieceStorage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcher::setPeerStorage
|
|
|
|
(const SharedHandle<PeerStorage>& peerStorage)
|
|
|
|
{
|
|
|
|
_peerStorage = peerStorage;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DefaultBtMessageDispatcher::setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory)
|
|
|
|
{
|
|
|
|
this->messageFactory = factory;
|
|
|
|
}
|
|
|
|
|
2008-12-10 14:14:11 +00:00
|
|
|
void DefaultBtMessageDispatcher::setRequestGroupMan
|
|
|
|
(const WeakHandle<RequestGroupMan>& rgman)
|
|
|
|
{
|
|
|
|
_requestGroupMan = rgman;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|