2008-04-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Rewritten SharedHandle. Now copy constructor taking raw pointer 
has
	keyword explicit and SharedHandle's default constructor 
initializes
	its internal obj to null, old implementation initializes it 
using
	obj's default constructor.
	To assign null, write SharedHandle<T> x(...); x.reset();
	TODO: test/SharedHandleTest.cc needs more tests.
	* src/SharedHandle.h
This commit is contained in:
Tatsuhiro Tsujikawa 2008-04-20 00:50:22 +00:00
parent 99733a84e2
commit 3505201f33
262 changed files with 2106 additions and 1843 deletions

View File

@ -1,3 +1,13 @@
2008-04-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten SharedHandle. Now copy constructor taking raw pointer has
keyword explicit and SharedHandle's default constructor initializes
its internal obj to null, old implementation initializes it using
obj's default constructor.
To assign null, write SharedHandle<T> x(...); x.reset();
TODO: test/SharedHandleTest.cc needs more tests.
* src/SharedHandle.h
2008-04-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed type in man page.

View File

@ -38,7 +38,6 @@
namespace aria2 {
AbstractAuthResolver::AbstractAuthResolver():
_userDefinedAuthConfig(0),
_defaultAuthConfig(new AuthConfig()) {}
AbstractAuthResolver::~AbstractAuthResolver() {}

View File

@ -48,10 +48,6 @@ AbstractBtMessage::AbstractBtMessage():sendingInProgress(false),
invalidate(false),
uploading(false),
cuid(0),
btContext(0),
pieceStorage(0),
peer(0),
validator(0),
logger(LogFactory::getInstance())
{}

View File

@ -97,7 +97,7 @@ bool AbstractCommand::execute() {
//logger->debug("CUID#%d - finished.", cuid);
return true;
}
PeerStatHandle peerStat = 0;
PeerStatHandle peerStat;
if(!_requestGroup->getSegmentMan().isNull()) {
peerStat = _requestGroup->getSegmentMan()->getPeerStat(cuid);
}
@ -316,8 +316,7 @@ bool AbstractCommand::nameResolveFinished() const {
void AbstractCommand::prepareForNextAction(Command* nextCommand)
{
CheckIntegrityEntryHandle entry =
new StreamCheckIntegrityEntry(req, _requestGroup, nextCommand);
CheckIntegrityEntryHandle entry(new StreamCheckIntegrityEntry(req, _requestGroup, nextCommand));
e->addCommand(_requestGroup->processCheckIntegrityEntry(entry, e));
}

View File

@ -50,7 +50,7 @@ AbstractProxyRequestCommand::AbstractProxyRequestCommand(int cuid,
RequestGroup* requestGroup,
DownloadEngine* e,
const SocketHandle& s)
:AbstractCommand(cuid, req, requestGroup, e, s), httpConnection(0) {
:AbstractCommand(cuid, req, requestGroup, e, s) {
disableReadCheckSocket();
setWriteCheckSocket(socket);
}
@ -60,12 +60,12 @@ AbstractProxyRequestCommand::~AbstractProxyRequestCommand() {}
bool AbstractProxyRequestCommand::executeInternal() {
socket->setBlockingMode();
HttpRequestHandle httpRequest = new HttpRequest();
HttpRequestHandle httpRequest(new HttpRequest());
httpRequest->setUserAgent(e->option->get(PREF_USER_AGENT));
httpRequest->setRequest(req);
httpRequest->configure(e->option);
httpConnection= new HttpConnection(cuid, socket, e->option);
httpConnection.reset(new HttpConnection(cuid, socket, e->option));
httpConnection->sendProxyRequest(httpRequest);

View File

@ -39,9 +39,7 @@
namespace aria2 {
AbstractSingleDiskAdaptor::AbstractSingleDiskAdaptor():
diskWriter(0),
totalLength(0) {}
AbstractSingleDiskAdaptor::AbstractSingleDiskAdaptor():totalLength(0) {}
AbstractSingleDiskAdaptor::~AbstractSingleDiskAdaptor() {}
@ -92,8 +90,8 @@ void AbstractSingleDiskAdaptor::truncate(uint64_t length)
FileAllocationIteratorHandle AbstractSingleDiskAdaptor::fileAllocationIterator()
{
SingleFileAllocationIteratorHandle h =
new SingleFileAllocationIterator(this, size(), totalLength);
SingleFileAllocationIteratorHandle h
(new SingleFileAllocationIterator(this, size(), totalLength));
h->init();
return h;
}

View File

@ -44,11 +44,12 @@
namespace aria2 {
AuthConfigFactory::AuthConfigFactory(const Option* option):
_option(option), _netrc(0) {}
_option(option) {}
AuthConfigFactory::~AuthConfigFactory() {}
AuthConfigHandle AuthConfigFactory::createAuthConfig(const RequestHandle& request) const
AuthConfigHandle
AuthConfigFactory::createAuthConfig(const RequestHandle& request) const
{
if(request->getProtocol() == "http" || request->getProtocol() == "https") {
return createHttpAuthResolver()->resolveAuthConfig(request->getHost());
@ -59,31 +60,33 @@ AuthConfigHandle AuthConfigFactory::createAuthConfig(const RequestHandle& reques
return createFtpAuthResolver()->resolveAuthConfig(request->getHost());
}
} else {
return new AuthConfig();
return SharedHandle<AuthConfig>(new AuthConfig());
}
}
AuthConfigHandle AuthConfigFactory::createAuthConfigForHttpProxy(const RequestHandle& request) const
AuthConfigHandle
AuthConfigFactory::createAuthConfigForHttpProxy(const RequestHandle& request) const
{
return createHttpProxyAuthResolver()->resolveAuthConfig(request->getHost());
}
AuthConfigHandle AuthConfigFactory::createAuthConfig(const std::string& user, const std::string& password) const
AuthConfigHandle
AuthConfigFactory::createAuthConfig(const std::string& user, const std::string& password) const
{
SharedHandle<AuthConfig> ac;
if(user.length() > 0) {
return new AuthConfig(user, password);
} else {
return 0;
ac.reset(new AuthConfig(user, password));
}
return ac;
}
AuthResolverHandle AuthConfigFactory::createHttpAuthResolver() const
{
AbstractAuthResolverHandle resolver = 0;
AbstractAuthResolverHandle resolver;
if(true || _option->getAsBool(PREF_NO_NETRC)) {
resolver = new DefaultAuthResolver();
resolver.reset(new DefaultAuthResolver());
} else {
NetrcAuthResolverHandle authResolver = new NetrcAuthResolver();
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
authResolver->setNetrc(_netrc);
resolver = authResolver;
}
@ -93,26 +96,27 @@ AuthResolverHandle AuthConfigFactory::createHttpAuthResolver() const
AuthResolverHandle AuthConfigFactory::createFtpAuthResolver() const
{
AbstractAuthResolverHandle resolver = 0;
AbstractAuthResolverHandle resolver;
if(_option->getAsBool(PREF_NO_NETRC)) {
resolver = new DefaultAuthResolver();
resolver.reset(new DefaultAuthResolver());
} else {
NetrcAuthResolverHandle authResolver = new NetrcAuthResolver();
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
authResolver->setNetrc(_netrc);
resolver = authResolver;
}
resolver->setUserDefinedAuthConfig(createAuthConfig(_option->get(PREF_FTP_USER), _option->get(PREF_FTP_PASSWD)));
resolver->setDefaultAuthConfig(new AuthConfig("anonymous", "ARIA2USER@"));
SharedHandle<AuthConfig> defaultAuthConfig(new AuthConfig("anonymous", "ARIA2USER@"));
resolver->setDefaultAuthConfig(defaultAuthConfig);
return resolver;
}
AuthResolverHandle AuthConfigFactory::createHttpProxyAuthResolver() const
{
AbstractAuthResolverHandle resolver = 0;
AbstractAuthResolverHandle resolver;
if(true || _option->getAsBool(PREF_NO_NETRC)) {
resolver = new DefaultAuthResolver();
resolver.reset(new DefaultAuthResolver());
} else {
NetrcAuthResolverHandle authResolver = new NetrcAuthResolver();
NetrcAuthResolverHandle authResolver(new NetrcAuthResolver());
authResolver->setNetrc(_netrc);
resolver = authResolver;
}

View File

@ -129,7 +129,7 @@ SharedHandle<DHTBucket> BNode::findBucketFor(BNode* b, const unsigned char* key)
if(bnode) {
return bnode->getBucket();
} else {
return 0;
return SharedHandle<DHTBucket>();
}
}

View File

@ -55,7 +55,7 @@ private:
BNode* _right;
public:
BNode(const SharedHandle<DHTBucket>& bucket = 0);
BNode(const SharedHandle<DHTBucket>& bucket = SharedHandle<DHTBucket>());
~BNode();

View File

@ -49,7 +49,6 @@ BitfieldMan::BitfieldMan(size_t blockLength, uint64_t totalLength)
bitfieldLength(0),
blocks(0),
filterEnabled(false),
randomizer(0),
cachedNumMissingBlock(0),
cachedNumFilteredBlock(0),
cachedCompletedLength(0),
@ -76,7 +75,6 @@ BitfieldMan::BitfieldMan(const BitfieldMan& bitfieldMan)
bitfieldLength(0),
blocks(0),
filterEnabled(false),
randomizer(0),
cachedNumMissingBlock(0),
cachedNumFilteredBlock(0),
cachedCompletedLength(0),

View File

@ -38,17 +38,17 @@
namespace aria2 {
BitfieldManFactoryHandle BitfieldManFactory::factory = 0;
BitfieldManFactoryHandle BitfieldManFactory::factory;
BitfieldManFactoryHandle BitfieldManFactory::getFactoryInstance()
{
if(factory.isNull()) {
factory = new BitfieldManFactory();
factory.reset(new BitfieldManFactory());
}
return factory;
}
BitfieldManFactory::BitfieldManFactory():randomizer(0) {}
BitfieldManFactory::BitfieldManFactory() {}
BitfieldManFactory::~BitfieldManFactory() {}

View File

@ -49,7 +49,7 @@ BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* dat
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "allowed fast", ID);
}
BtAllowedFastMessageHandle message = new BtAllowedFastMessage();
BtAllowedFastMessageHandle message(new BtAllowedFastMessage());
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
return message;
}

View File

@ -63,7 +63,7 @@ BtBitfieldMessage::create(const unsigned char* data, size_t dataLength)
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "bitfield", ID);
}
BtBitfieldMessageHandle message = new BtBitfieldMessage();
BtBitfieldMessageHandle message(new BtBitfieldMessage());
message->setBitfield((unsigned char*)data+1, dataLength-1);
return message;
}

View File

@ -49,7 +49,7 @@ BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, size_t
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "cancel", ID);
}
BtCancelMessageHandle message = new BtCancelMessage();
BtCancelMessageHandle message(new BtCancelMessage());
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
message->setBegin(PeerMessageUtil::getIntParam(data, 5));
message->setLength(PeerMessageUtil::getIntParam(data, 9));

View File

@ -50,7 +50,7 @@ BtCheckIntegrityEntry::~BtCheckIntegrityEntry() {}
Commands BtCheckIntegrityEntry::onDownloadIncomplete(DownloadEngine* e)
{
Commands commands;
FileAllocationEntryHandle entry = new BtFileAllocationEntry(_requestGroup);
FileAllocationEntryHandle entry(new BtFileAllocationEntry(_requestGroup));
if(_requestGroup->needsFileAllocation()) {
e->_fileAllocationMan->pushFileAllocationEntry(entry);
} else {

View File

@ -50,7 +50,7 @@ BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, size_t da
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "choke", ID);
}
BtChokeMessageHandle chokeMessage = new BtChokeMessage();
BtChokeMessageHandle chokeMessage(new BtChokeMessage());
return chokeMessage;
}

View File

@ -63,8 +63,8 @@ bool BtDependency::resolve()
if(_dependee->getNumCommand() == 0 && _dependee->downloadFinished()) {
RequestGroupHandle dependee = _dependee;
// cut reference here
_dependee = 0;
DefaultBtContextHandle btContext = new DefaultBtContext();
_dependee.reset();
DefaultBtContextHandle btContext(new DefaultBtContext());
try {
DiskAdaptorHandle diskAdaptor = dependee->getPieceStorage()->getDiskAdaptor();
diskAdaptor->openExistingFile();
@ -89,7 +89,7 @@ bool BtDependency::resolve()
} else if(_dependee->getNumCommand() == 0) {
// _dependee's download failed.
// cut reference here
_dependee = 0;
_dependee.reset();
_logger->debug("BtDependency for GID#%d failed. Go without Bt.",
_dependant->getGID());
return true;

View File

@ -111,7 +111,7 @@ BtExtendedMessage::create(const BtContextHandle& btContext,
assert(!factory.isNull());
ExtensionMessageHandle extmsg = factory->createMessage(data+1,
dataLength-1);
BtExtendedMessageHandle message = new BtExtendedMessage(extmsg);
BtExtendedMessageHandle message(new BtExtendedMessage(extmsg));
return message;
}

View File

@ -52,7 +52,8 @@ private:
size_t _msgLength;
public:
BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage = 0);
BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage =
SharedHandle<ExtensionMessage>());
virtual ~BtExtendedMessage();

View File

@ -72,7 +72,7 @@ void BtHandshakeMessage::init() {
SharedHandle<BtHandshakeMessage>
BtHandshakeMessage::create(const unsigned char* data, size_t dataLength)
{
SharedHandle<BtHandshakeMessage> message = new BtHandshakeMessage();
SharedHandle<BtHandshakeMessage> message(new BtHandshakeMessage());
message->pstrlen = data[0];
memcpy(message->pstr, &data[1], PSTR_LENGTH);
memcpy(message->reserved, &data[20], RESERVED_LENGTH);

View File

@ -48,7 +48,7 @@ BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, size_
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have all", ID);
}
BtHaveAllMessageHandle message = new BtHaveAllMessage();
BtHaveAllMessageHandle message(new BtHaveAllMessage());
return message;
}

View File

@ -49,7 +49,7 @@ BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, size_t data
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have", ID);
}
BtHaveMessageHandle message = new BtHaveMessage();
BtHaveMessageHandle message(new BtHaveMessage());
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
return message;
}

View File

@ -48,7 +48,7 @@ BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, siz
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "have none", ID);
}
BtHaveNoneMessageHandle message = new BtHaveNoneMessage();
BtHaveNoneMessageHandle message(new BtHaveNoneMessage());
return message;
}

View File

@ -51,7 +51,7 @@ BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data,
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "interested", ID);
}
BtInterestedMessageHandle message = new BtInterestedMessage();
BtInterestedMessageHandle message(new BtInterestedMessage());
return message;
}

View File

@ -41,6 +41,7 @@
namespace aria2 {
class BtMessage;
class BtHandshakeMessage;
class Piece;
class ExtensionMessage;
@ -51,10 +52,10 @@ public:
virtual SharedHandle<BtMessage>
createBtMessage(const unsigned char* msg, size_t msgLength) = 0;
virtual SharedHandle<BtMessage>
virtual SharedHandle<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* msg, size_t msgLength) = 0;
virtual SharedHandle<BtMessage>
virtual SharedHandle<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId) = 0;

View File

@ -41,14 +41,15 @@
namespace aria2 {
class BtMessage;
class BtHandshakeMessage;
class BtMessageReceiver {
public:
virtual ~BtMessageReceiver() {}
virtual SharedHandle<BtMessage> receiveHandshake(bool quickReply = false) = 0;
virtual SharedHandle<BtHandshakeMessage> receiveHandshake(bool quickReply = false) = 0;
virtual SharedHandle<BtMessage> receiveAndSendHandshake() = 0;
virtual SharedHandle<BtHandshakeMessage> receiveAndSendHandshake() = 0;
virtual SharedHandle<BtMessage> receiveMessage() = 0;
};

View File

@ -51,7 +51,7 @@ BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char*
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "not interested", ID);
}
BtNotInterestedMessageHandle message = new BtNotInterestedMessage();
BtNotInterestedMessageHandle message(new BtNotInterestedMessage());
return message;
}

View File

@ -69,7 +69,7 @@ BtPieceMessageHandle BtPieceMessage::create(const unsigned char* data, size_t da
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID);
}
BtPieceMessageHandle message = new BtPieceMessage();
BtPieceMessageHandle message(new BtPieceMessage());
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
message->setBegin(PeerMessageUtil::getIntParam(data, 5));
message->setBlock(data+9, dataLength-9);

View File

@ -104,8 +104,14 @@ public:
msgHeader(0)
{
uploading = true;
addEventListener(new BtChokingEventListener(this));
addEventListener(new BtCancelSendingPieceEventListener(this));
{
SharedHandle<BtEventListener> listener(new BtChokingEventListener(this));
addEventListener(listener);
}
{
SharedHandle<BtEventListener> listener(new BtCancelSendingPieceEventListener(this));
addEventListener(listener);
}
}
virtual ~BtPieceMessage() {

View File

@ -64,7 +64,7 @@ SharedHandle<BtPortMessage> BtPortMessage::create(const unsigned char* data, siz
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "piece", ID);
}
uint16_t port = PeerMessageUtil::getShortIntParam(data, 1);
SharedHandle<BtPortMessage> message = new BtPortMessage(port);
SharedHandle<BtPortMessage> message(new BtPortMessage(port));
return message;
}
@ -73,7 +73,7 @@ void BtPortMessage::doReceivedAction()
if(!_taskFactory.isNull() && !_taskQueue.isNull()) {
// node id is random at this point. When ping reply received, new DHTNode
// instance created with proper node ID and is added to a routing table.
SharedHandle<DHTNode> node = new DHTNode();
SharedHandle<DHTNode> node(new DHTNode());
node->setIPAddress(peer->ipaddr);
node->setPort(_port);
{

View File

@ -50,8 +50,10 @@ namespace aria2 {
BtPostDownloadHandler::BtPostDownloadHandler()
{
setCriteria(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getBtContentTypes(),
DownloadHandlerConstants::getBtExtensions()));
SharedHandle<RequestGroupCriteria> cri
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getBtContentTypes(),
DownloadHandlerConstants::getBtExtensions()));
setCriteria(cri);
}
BtPostDownloadHandler::~BtPostDownloadHandler() {}
@ -61,7 +63,7 @@ RequestGroups BtPostDownloadHandler::getNextRequestGroups(RequestGroup* requestG
const Option* op = requestGroup->getOption();
_logger->debug("Generating RequestGroups for Torrent file %s",
requestGroup->getFilePath().c_str());
RequestGroupHandle rg = new RequestGroup(op, std::deque<std::string>());
RequestGroupHandle rg(new RequestGroup(op, std::deque<std::string>()));
std::string content;
try {
@ -72,7 +74,7 @@ RequestGroups BtPostDownloadHandler::getNextRequestGroups(RequestGroup* requestG
requestGroup->getPieceStorage()->getDiskAdaptor()->closeFile();
throw;
}
DefaultBtContextHandle btContext = new DefaultBtContext();
DefaultBtContextHandle btContext(new DefaultBtContext());
btContext->loadFromMemory(content, File(requestGroup->getFilePath()).getBasename());
if(op->defined(PREF_PEER_ID_PREFIX)) {
btContext->setPeerIdPrefix(op->get(PREF_PEER_ID_PREFIX));

View File

@ -51,7 +51,7 @@ BtRejectMessageHandle BtRejectMessage::create(const unsigned char* data, size_t
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "reject", ID);
}
BtRejectMessageHandle message = new BtRejectMessage();
BtRejectMessageHandle message(new BtRejectMessage());
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
message->setBegin(PeerMessageUtil::getIntParam(data, 5));
message->setLength(PeerMessageUtil::getIntParam(data, 9));

View File

@ -55,7 +55,7 @@ BtRequestMessageHandle BtRequestMessage::create(const unsigned char* data, size_
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "request", ID);
}
BtRequestMessageHandle message = new BtRequestMessage();
BtRequestMessageHandle message(new BtRequestMessage());
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
message->setBegin(PeerMessageUtil::getIntParam(data, 5));
message->setLength(PeerMessageUtil::getIntParam(data, 9));

View File

@ -77,7 +77,8 @@ public:
blockIndex(blockIndex),
msg(0)
{
addEventListener(new BtAbortOutstandingRequestEventListener(this));
SharedHandle<BtEventListener> listener(new BtAbortOutstandingRequestEventListener(this));
addEventListener(listener);
}
virtual ~BtRequestMessage() {

View File

@ -66,7 +66,7 @@ Commands BtSetup::setup(RequestGroup* requestGroup,
const Option* option)
{
Commands commands;
BtContextHandle btContext = requestGroup->getDownloadContext();
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(requestGroup->getDownloadContext()));
if(btContext.isNull()) {
return commands;
}
@ -92,14 +92,16 @@ Commands BtSetup::setup(RequestGroup* requestGroup,
command->setTaskFactory(DHTRegistry::_taskFactory);
commands.push_back(command);
}
SharedHandle<UnionSeedCriteria> unionCri = new UnionSeedCriteria();
SharedHandle<UnionSeedCriteria> unionCri(new UnionSeedCriteria());
if(option->defined(PREF_SEED_TIME)) {
unionCri->addSeedCriteria(new TimeSeedCriteria(option->getAsInt(PREF_SEED_TIME)*60));
SharedHandle<SeedCriteria> cri(new TimeSeedCriteria(option->getAsInt(PREF_SEED_TIME)*60));
unionCri->addSeedCriteria(cri);
}
{
double ratio = option->getAsDouble(PREF_SEED_RATIO);
if(ratio > 0.0) {
unionCri->addSeedCriteria(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO), btContext));
SharedHandle<SeedCriteria> cri(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO), btContext));
unionCri->addSeedCriteria(cri);
}
}
if(unionCri->getSeedCriterion().size() > 0) {

View File

@ -48,7 +48,7 @@ BtSuggestPieceMessageHandle BtSuggestPieceMessage::create(const unsigned char* d
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "suggest piece", ID);
}
BtSuggestPieceMessageHandle message = new BtSuggestPieceMessage();
BtSuggestPieceMessageHandle message(new BtSuggestPieceMessage());
message->setIndex(PeerMessageUtil::getIntParam(data, 1));
return message;
}

View File

@ -48,7 +48,7 @@ BtUnchokeMessageHandle BtUnchokeMessage::create(const unsigned char* data, size_
if(id != ID) {
throw new DlAbortEx(EX_INVALID_BT_MESSAGE_ID, id, "unchoke", ID);
}
BtUnchokeMessageHandle message = new BtUnchokeMessage();
BtUnchokeMessageHandle message(new BtUnchokeMessage());
return message;
}

View File

@ -39,7 +39,7 @@ namespace aria2 {
DiskWriterHandle ByteArrayDiskWriterFactory::newDiskWriter()
{
return new ByteArrayDiskWriter();
return SharedHandle<DiskWriter>(new ByteArrayDiskWriter());
}
} // namespace aria2

View File

@ -39,8 +39,7 @@ namespace aria2 {
CheckIntegrityEntry::CheckIntegrityEntry(RequestGroup* requestGroup,
Command* nextCommand):
RequestGroupEntry(requestGroup, nextCommand),
_validator(0)
RequestGroupEntry(requestGroup, nextCommand)
{}
CheckIntegrityEntry::~CheckIntegrityEntry() {}

View File

@ -62,7 +62,7 @@ bool CheckIntegrityMan::removeCheckIntegrityEntry(const CheckIntegrityEntryHandl
CheckIntegrityEntryHandle CheckIntegrityMan::getFirstCheckIntegrityEntry() const
{
if(_checkIntegrityEntries.empty()) {
return 0;
return SharedHandle<CheckIntegrityEntry>();
} else {
return _checkIntegrityEntries.front();
}

View File

@ -49,15 +49,18 @@ ChecksumCheckIntegrityEntry::~ChecksumCheckIntegrityEntry() {}
bool ChecksumCheckIntegrityEntry::isValidationReady()
{
SingleFileDownloadContextHandle dctx = _requestGroup->getDownloadContext();
SingleFileDownloadContextHandle dctx
(dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext()));
return !dctx.isNull() && dctx->getChecksum().size() > 0 &&
dctx->getChecksumHashAlgo().size() > 0;
}
void ChecksumCheckIntegrityEntry::initValidator()
{
_validator = new IteratableChecksumValidator(_requestGroup->getDownloadContext(),
_requestGroup->getPieceStorage());
SingleFileDownloadContextHandle dctx
(dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext()));
_validator.reset(new IteratableChecksumValidator(dctx,
_requestGroup->getPieceStorage()));
_validator->init();
}

View File

@ -58,7 +58,7 @@ Peers CompactPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
in.s_addr = *(uint32_t*)(peersData->getData()+i);
std::string ipaddr = inet_ntoa(in);
uint16_t port = ntohs(*(uint16_t*)(peersData->getData()+i+4));
PeerHandle peer = new Peer(ipaddr, port);
PeerHandle peer(new Peer(ipaddr, port));
peers.push_back(peer);
}
}

View File

@ -80,7 +80,7 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
<< "#" << firstRequestGroup->getGID() << " ";
#ifdef ENABLE_BITTORRENT
if(firstRequestGroup->downloadFinished() &&
!BtContextHandle(firstRequestGroup->getDownloadContext()).isNull()) {
!dynamic_pointer_cast<BtContext>(firstRequestGroup->getDownloadContext()).isNull()) {
std::cout << "SEEDING" << "(" << "ratio:"
<< std::fixed << std::setprecision(1)
<< ((stat.getAllTimeUploadLength()*10)/firstRequestGroup->getCompletedLength())/10.0

View File

@ -52,7 +52,7 @@ bool ContentTypeRequestGroupCriteria::match(const RequestGroup* requestGroup) co
if(forwardMatch(requestGroup->getFilePath(), _extensions)) {
return true;
} else {
SingleFileDownloadContextHandle dctx = requestGroup->getDownloadContext();
SingleFileDownloadContextHandle dctx(dynamic_pointer_cast<SingleFileDownloadContext>(requestGroup->getDownloadContext()));
if(dctx.isNull()) {
return false;
} else {

View File

@ -43,7 +43,7 @@ namespace aria2 {
CookieBoxHandle CookieBoxFactory::createNewInstance()
{
CookieBoxHandle box = new CookieBox();
CookieBoxHandle box(new CookieBox());
box->add(defaultCookies);
return box;
}

View File

@ -41,6 +41,7 @@
#include "DHTMessageDispatcher.h"
#include "DHTMessageFactory.h"
#include "DHTRoutingTable.h"
#include "DHTMessageCallback.h"
namespace aria2 {
@ -53,7 +54,7 @@ DHTAbstractMessage::~DHTAbstractMessage() {}
std::string DHTAbstractMessage::getBencodedMessage()
{
SharedHandle<Dictionary> msg = new Dictionary();
SharedHandle<Dictionary> msg(new Dictionary());
msg->put(std::string("t"), new Data(_transactionID));
msg->put(std::string("y"), new Data(getType()));
fillMessage(msg.get());

View File

@ -118,7 +118,9 @@ void DHTAbstractNodeLookupTask::sendMessage()
++_inFlightMessage;
(*i)->_used = true;
SharedHandle<DHTMessage> m = createMessage((*i)->_node);
_dispatcher->addMessageToQueue(m, new DHTMessageCallbackImpl(this));
WeakHandle<DHTMessageCallbackListener> listener(this);
SharedHandle<DHTMessageCallback> callback(new DHTMessageCallbackImpl(listener));
_dispatcher->addMessageToQueue(m, callback);
}
}
}
@ -149,7 +151,7 @@ DHTAbstractNodeLookupTask::toEntries(const std::deque<SharedHandle<DHTNode> >& n
{
std::deque<SharedHandle<DHTNodeLookupEntry> > entries;
for(std::deque<SharedHandle<DHTNode> >::const_iterator i = nodes.begin(); i != nodes.end(); ++i) {
SharedHandle<DHTNodeLookupEntry> e = new DHTNodeLookupEntry(*i);
SharedHandle<DHTNodeLookupEntry> e(new DHTNodeLookupEntry(*i));
entries.push_back(e);
}
return entries;

View File

@ -48,8 +48,7 @@ namespace aria2 {
DHTAbstractTask::DHTAbstractTask():
_finished(false),
_logger(LogFactory::getInstance()),
_localNode(0)
_logger(LogFactory::getInstance())
{}
bool DHTAbstractTask::finished()

View File

@ -57,9 +57,7 @@ DHTAnnouncePeerMessage::DHTAnnouncePeerMessage(const SharedHandle<DHTNode>& loca
const std::string& transactionID):
DHTQueryMessage(localNode, remoteNode, transactionID),
_token(token),
_tcpPort(tcpPort),
_peerAnnounceStorage(0),
_tokenTracker(0)
_tcpPort(tcpPort)
{
memcpy(_infoHash, infoHash, DHT_ID_LENGTH);
}

View File

@ -53,9 +53,7 @@
namespace aria2 {
DHTAutoSaveCommand::DHTAutoSaveCommand(int32_t cuid, DownloadEngine* e, time_t interval):
TimeBasedCommand(cuid, e, interval),
_localNode(0),
_routingTable(0) {}
TimeBasedCommand(cuid, e, interval) {}
DHTAutoSaveCommand::~DHTAutoSaveCommand() {}

View File

@ -132,7 +132,7 @@ void DHTBucket::cacheNode(const SharedHandle<DHTNode>& node)
// _cachedNodes are sorted by last time seen
_cachedNodes.push_front(node);
if(_cachedNodes.size() > CACHE_SIZE) {
_cachedNodes.resize(CACHE_SIZE, 0);
_cachedNodes.resize(CACHE_SIZE, SharedHandle<DHTNode>());
}
}
@ -182,8 +182,8 @@ SharedHandle<DHTBucket> DHTBucket::split()
memcpy(rMax, _max, DHT_ID_LENGTH);
DHTUtil::flipBit(rMax, DHT_ID_LENGTH, _prefixLength);
SharedHandle<DHTBucket> rBucket = new DHTBucket(newPrefixLength,
rMax, _min, _localNode);
SharedHandle<DHTBucket> rBucket(new DHTBucket(newPrefixLength,
rMax, _min, _localNode));
std::deque<SharedHandle<DHTNode> > tempNodes = _nodes;
for(std::deque<SharedHandle<DHTNode> >::iterator i = tempNodes.begin();
i != tempNodes.end();) {
@ -228,13 +228,13 @@ std::deque<SharedHandle<DHTNode> > DHTBucket::getGoodNodes() const
SharedHandle<DHTNode> DHTBucket::getNode(const unsigned char* nodeID, const std::string& ipaddr, uint16_t port) const
{
SharedHandle<DHTNode> node = new DHTNode(nodeID);
SharedHandle<DHTNode> node(new DHTNode(nodeID));
node->setIPAddress(ipaddr);
node->setPort(port);
std::deque<SharedHandle<DHTNode> >::const_iterator itr =
std::find(_nodes.begin(), _nodes.end(), node);
if(itr == _nodes.end()) {
return 0;
return SharedHandle<DHTNode>();
} else {
return *itr;
}
@ -274,7 +274,7 @@ SharedHandle<DHTNode> DHTBucket::getLRUQuestionableNode() const
std::deque<SharedHandle<DHTNode> >::const_iterator i =
std::find_if(_nodes.begin(), _nodes.end(), FindQuestionableNode());
if(i == _nodes.end()) {
return 0;
return SharedHandle<DHTNode>();
} else {
return *i;
}

View File

@ -43,10 +43,7 @@
namespace aria2 {
DHTBucketRefreshCommand::DHTBucketRefreshCommand(int32_t cuid, DownloadEngine* e, time_t interval):
TimeBasedCommand(cuid, e, interval),
_routingTable(0),
_taskQueue(0),
_taskFactory(0) {}
TimeBasedCommand(cuid, e, interval) {}
DHTBucketRefreshCommand::~DHTBucketRefreshCommand() {}

View File

@ -57,7 +57,7 @@ void DHTBucketRefreshTask::startup()
(*i)->notifyUpdate();
unsigned char targetID[DHT_ID_LENGTH];
(*i)->getRandomNodeID(targetID);
SharedHandle<DHTNodeLookupTask> task = new DHTNodeLookupTask(targetID);
SharedHandle<DHTNodeLookupTask> task(new DHTNodeLookupTask(targetID));
task->setRoutingTable(_routingTable);
task->setMessageDispatcher(_dispatcher);
task->setMessageFactory(_factory);

View File

@ -55,10 +55,6 @@ DHTEntryPointNameResolveCommand::DHTEntryPointNameResolveCommand(int32_t cuid, D
Command(cuid),
_e(e),
_resolver(new NameResolver()),
_taskQueue(0),
_taskFactory(0),
_routingTable(0),
_localNode(0),
_entryPoints(entryPoints),
_bootstrapEnabled(false)
{}
@ -120,7 +116,7 @@ bool DHTEntryPointNameResolveCommand::execute()
void DHTEntryPointNameResolveCommand::addPingTask(const std::pair<std::string, uint16_t>& addr)
{
SharedHandle<DHTNode> entryNode = new DHTNode();
SharedHandle<DHTNode> entryNode(new DHTNode());
entryNode->setIPAddress(addr.first);
entryNode->setPort(addr.second);

View File

@ -57,9 +57,6 @@ DHTGetPeersCommand::DHTGetPeersCommand(int32_t cuid,
BtContextAwareCommand(ctx),
RequestGroupAware(requestGroup),
_e(e),
_taskQueue(0),
_taskFactory(0),
_task(0),
_numRetry(0),
_lastGetPeerTime(0)
{}
@ -76,7 +73,7 @@ bool DHTGetPeersCommand::execute()
_lastGetPeerTime.elapsed(GET_PEER_INTERVAL))) {
logger->debug("Issuing PeerLookup for infoHash=%s",
btContext->getInfoHashAsString().c_str());
_task = _taskFactory->createPeerLookupTask(btContext);
_task = dynamic_pointer_cast<DHTPeerLookupTask>(_taskFactory->createPeerLookupTask(btContext));
_taskQueue->addPeriodicTask2(_task);
} else if(!_task.isNull() && _task->finished()) {
_lastGetPeerTime.reset();
@ -85,7 +82,7 @@ bool DHTGetPeersCommand::execute()
} else {
_numRetry = 0;
}
_task = 0;
_task.reset();
}
_e->commands.push_back(this);

View File

@ -67,7 +67,7 @@ void DHTGetPeersMessage::doReceivedAction()
_remoteNode->getPort());
// Check to see localhost has the contents which has same infohash
Peers peers = _peerAnnounceStorage->getPeers(_infoHash);
SharedHandle<DHTMessage> reply = 0;
SharedHandle<DHTMessage> reply;
if(peers.empty()) {
std::deque<SharedHandle<DHTNode> > nodes = _routingTable->getClosestKNodes(_infoHash);
reply =

View File

@ -43,17 +43,13 @@
#include "message.h"
#include "RequestGroupMan.h"
#include "Logger.h"
#include "DHTMessageCallback.h"
namespace aria2 {
DHTInteractionCommand::DHTInteractionCommand(int32_t cuid, DownloadEngine* e):
Command(cuid),
_e(e),
_dispatcher(0),
_receiver(0),
_taskQueue(0),
_readCheckSocket(0)
{}
_e(e) {}
DHTInteractionCommand::~DHTInteractionCommand()
{

View File

@ -51,11 +51,13 @@ public:
virtual void
addMessageToQueue(const SharedHandle<DHTMessage>& message,
time_t timeout,
const SharedHandle<DHTMessageCallback>& callback = 0) = 0;
const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>()) = 0;
virtual void
addMessageToQueue(const SharedHandle<DHTMessage>& message,
const SharedHandle<DHTMessageCallback>& callback = 0) = 0;
const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>()) = 0;
virtual void sendMessages() = 0;

View File

@ -55,7 +55,8 @@ DHTMessageDispatcherImpl::addMessageToQueue(const SharedHandle<DHTMessage>& mess
time_t timeout,
const SharedHandle<DHTMessageCallback>& callback)
{
_messageQueue.push_back(new DHTMessageEntry(message, timeout, callback));
SharedHandle<DHTMessageEntry> e(new DHTMessageEntry(message, timeout, callback));
_messageQueue.push_back(e);
}
void

View File

@ -61,11 +61,13 @@ public:
virtual void
addMessageToQueue(const SharedHandle<DHTMessage>& message,
time_t timeout,
const SharedHandle<DHTMessageCallback>& callback = 0);
const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>());
virtual void
addMessageToQueue(const SharedHandle<DHTMessage>& message,
const SharedHandle<DHTMessageCallback>& callback = 0);
const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>());
virtual void sendMessages();

View File

@ -53,6 +53,7 @@
#include "DHTMessageDispatcher.h"
#include "DHTPeerAnnounceStorage.h"
#include "DHTTokenTracker.h"
#include "DHTMessageCallback.h"
#include "PeerMessageUtil.h"
#include "BtRuntime.h"
#include "Util.h"
@ -63,8 +64,8 @@
namespace aria2 {
DHTMessageFactoryImpl::DHTMessageFactoryImpl():_localNode(0),
_logger(LogFactory::getInstance()) {}
DHTMessageFactoryImpl::DHTMessageFactoryImpl():
_logger(LogFactory::getInstance()) {}
DHTMessageFactoryImpl::~DHTMessageFactoryImpl() {}
@ -73,7 +74,7 @@ DHTMessageFactoryImpl::getRemoteNode(const unsigned char* id, const std::string&
{
SharedHandle<DHTNode> node = _routingTable->getNode(id, ipaddr, port);
if(node.isNull()) {
node = new DHTNode(id);
node.reset(new DHTNode(id));
node->setIPAddress(ipaddr);
node->setPort(port);
}
@ -245,12 +246,13 @@ void DHTMessageFactoryImpl::setCommonProperty(const SharedHandle<DHTAbstractMess
m->setConnection(_connection);
m->setMessageDispatcher(_dispatcher);
m->setRoutingTable(_routingTable);
m->setMessageFactory(this);
WeakHandle<DHTMessageFactory> factory(this);
m->setMessageFactory(factory);
}
SharedHandle<DHTMessage> DHTMessageFactoryImpl::createPingMessage(const SharedHandle<DHTNode>& remoteNode, const std::string& transactionID)
{
SharedHandle<DHTPingMessage> m = new DHTPingMessage(_localNode, remoteNode, transactionID);
SharedHandle<DHTPingMessage> m(new DHTPingMessage(_localNode, remoteNode, transactionID));
setCommonProperty(m);
return m;
}
@ -260,7 +262,7 @@ DHTMessageFactoryImpl::createPingReplyMessage(const SharedHandle<DHTNode>& remot
const unsigned char* id,
const std::string& transactionID)
{
SharedHandle<DHTPingReplyMessage> m = new DHTPingReplyMessage(_localNode, remoteNode, id, transactionID);
SharedHandle<DHTPingReplyMessage> m(new DHTPingReplyMessage(_localNode, remoteNode, id, transactionID));
setCommonProperty(m);
return m;
}
@ -270,7 +272,7 @@ DHTMessageFactoryImpl::createFindNodeMessage(const SharedHandle<DHTNode>& remote
const unsigned char* targetNodeID,
const std::string& transactionID)
{
SharedHandle<DHTFindNodeMessage> m = new DHTFindNodeMessage(_localNode, remoteNode, targetNodeID, transactionID);
SharedHandle<DHTFindNodeMessage> m(new DHTFindNodeMessage(_localNode, remoteNode, targetNodeID, transactionID));
setCommonProperty(m);
return m;
}
@ -280,7 +282,7 @@ DHTMessageFactoryImpl::createFindNodeReplyMessage(const SharedHandle<DHTNode>& r
const std::deque<SharedHandle<DHTNode> >& closestKNodes,
const std::string& transactionID)
{
SharedHandle<DHTFindNodeReplyMessage> m = new DHTFindNodeReplyMessage(_localNode, remoteNode, transactionID);
SharedHandle<DHTFindNodeReplyMessage> m(new DHTFindNodeReplyMessage(_localNode, remoteNode, transactionID));
m->setClosestKNodes(closestKNodes);
setCommonProperty(m);
return m;
@ -294,7 +296,7 @@ DHTMessageFactoryImpl::extractNodes(const unsigned char* src, size_t length)
}
std::deque<SharedHandle<DHTNode> > nodes;
for(size_t offset = 0; offset < length; offset += 26) {
SharedHandle<DHTNode> node = new DHTNode(src+offset);
SharedHandle<DHTNode> node(new DHTNode(src+offset));
std::pair<std::string, uint16_t> addr =
PeerMessageUtil::unpackcompact(src+offset+DHT_ID_LENGTH);
if(addr.first.empty()) {
@ -322,10 +324,10 @@ DHTMessageFactoryImpl::createGetPeersMessage(const SharedHandle<DHTNode>& remote
const unsigned char* infoHash,
const std::string& transactionID)
{
SharedHandle<DHTGetPeersMessage> m = new DHTGetPeersMessage(_localNode,
remoteNode,
infoHash,
transactionID);
SharedHandle<DHTGetPeersMessage> m(new DHTGetPeersMessage(_localNode,
remoteNode,
infoHash,
transactionID));
m->setPeerAnnounceStorage(_peerAnnounceStorage);
m->setTokenTracker(_tokenTracker);
setCommonProperty(m);
@ -351,8 +353,8 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage(const SharedHandle<DHTNode>& r
const std::string& token,
const std::string& transactionID)
{
SharedHandle<DHTGetPeersReplyMessage> m =
new DHTGetPeersReplyMessage(_localNode, remoteNode, token, transactionID);
SharedHandle<DHTGetPeersReplyMessage> m
(new DHTGetPeersReplyMessage(_localNode, remoteNode, token, transactionID));
m->setClosestKNodes(closestKNodes);
setCommonProperty(m);
return m;
@ -370,7 +372,7 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues(const SharedHandle<D
const Data* data = dynamic_cast<const Data*>(*i);
if(data && data->getLen() == 6) {
std::pair<std::string, uint16_t> addr = PeerMessageUtil::unpackcompact(data->getData());
PeerHandle peer = new Peer(addr.first, addr.second);
PeerHandle peer(new Peer(addr.first, addr.second));
peers.push_back(peer);
}
}
@ -385,7 +387,7 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage(const SharedHandle<DHTNode>& r
const std::string& token,
const std::string& transactionID)
{
SharedHandle<DHTGetPeersReplyMessage> m = new DHTGetPeersReplyMessage(_localNode, remoteNode, token, transactionID);
SharedHandle<DHTGetPeersReplyMessage> m(new DHTGetPeersReplyMessage(_localNode, remoteNode, token, transactionID));
m->setValues(values);
setCommonProperty(m);
return m;
@ -398,8 +400,8 @@ DHTMessageFactoryImpl::createAnnouncePeerMessage(const SharedHandle<DHTNode>& re
const std::string& token,
const std::string& transactionID)
{
SharedHandle<DHTAnnouncePeerMessage> m =
new DHTAnnouncePeerMessage(_localNode, remoteNode, infoHash, tcpPort, token, transactionID);
SharedHandle<DHTAnnouncePeerMessage> m
(new DHTAnnouncePeerMessage(_localNode, remoteNode, infoHash, tcpPort, token, transactionID));
m->setPeerAnnounceStorage(_peerAnnounceStorage);
m->setTokenTracker(_tokenTracker);
setCommonProperty(m);
@ -410,8 +412,8 @@ SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& remoteNode,
const std::string& transactionID)
{
SharedHandle<DHTAnnouncePeerReplyMessage> m =
new DHTAnnouncePeerReplyMessage(_localNode, remoteNode, transactionID);
SharedHandle<DHTAnnouncePeerReplyMessage> m
(new DHTAnnouncePeerReplyMessage(_localNode, remoteNode, transactionID));
setCommonProperty(m);
return m;
}
@ -421,8 +423,8 @@ DHTMessageFactoryImpl::createUnknownMessage(const unsigned char* data, size_t le
const std::string& ipaddr, uint16_t port)
{
SharedHandle<DHTUnknownMessage> m =
new DHTUnknownMessage(_localNode, data, length, ipaddr, port);
SharedHandle<DHTUnknownMessage> m
(new DHTUnknownMessage(_localNode, data, length, ipaddr, port));
return m;
}

View File

@ -53,9 +53,6 @@ namespace aria2 {
DHTMessageReceiver::DHTMessageReceiver(const SharedHandle<DHTMessageTracker>& tracker):
_tracker(tracker),
_connection(0),
_factory(0),
_routingTable(0),
_logger(LogFactory::getInstance())
{}
@ -70,11 +67,11 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
remoteAddr,
remotePort);
if(length <= 0) {
return 0;
return SharedHandle<DHTMessage>();
}
try {
bool isReply = false;
MetaEntryHandle msgroot = MetaFileUtil::bdecoding(data, length);
MetaEntryHandle msgroot(MetaFileUtil::bdecoding(data, length));
const Dictionary* d = dynamic_cast<const Dictionary*>(msgroot.get());
if(d) {
const Data* y = dynamic_cast<const Data*>(d->get("y"));
@ -90,8 +87,8 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
_logger->info("Malformed DHT message. This is not a bencoded directory. From:%s:%u", remoteAddr.c_str(), remotePort);
return handleUnknownMessage(data, sizeof(data), remoteAddr, remotePort);
}
SharedHandle<DHTMessage> message = 0;
SharedHandle<DHTMessageCallback> callback = 0;
SharedHandle<DHTMessage> message;
SharedHandle<DHTMessageCallback> callback;
if(isReply) {
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p = _tracker->messageArrived(d, remoteAddr, remotePort);
message = p.first;

View File

@ -51,15 +51,14 @@
namespace aria2 {
DHTMessageTracker::DHTMessageTracker():
_routingTable(0),
_factory(0),
_logger(LogFactory::getInstance()) {}
DHTMessageTracker::~DHTMessageTracker() {}
void DHTMessageTracker::addMessage(const SharedHandle<DHTMessage>& message, time_t timeout, const SharedHandle<DHTMessageCallback>& callback)
{
_entries.push_back(new DHTMessageTrackerEntry(message, timeout, callback));
SharedHandle<DHTMessageTrackerEntry> e(new DHTMessageTrackerEntry(message, timeout, callback));
_entries.push_back(e);
}
void DHTMessageTracker::addMessage(const SharedHandle<DHTMessage>& message, const SharedHandle<DHTMessageCallback>& callback)
@ -95,7 +94,7 @@ DHTMessageTracker::messageArrived(const Dictionary* d,
}
}
_logger->debug("Tracker entry not found.");
return std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> >(0, 0);
return std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> >();
}
void DHTMessageTracker::handleTimeout()
@ -139,7 +138,7 @@ DHTMessageTracker::getEntryFor(const SharedHandle<DHTMessage>& message) const
return *i;
}
}
return 0;
return SharedHandle<DHTMessageTrackerEntry>();
}
size_t DHTMessageTracker::countEntry() const

View File

@ -67,10 +67,12 @@ public:
void addMessage(const SharedHandle<DHTMessage>& message,
time_t timeout,
const SharedHandle<DHTMessageCallback>& callback = 0);
const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>());
void addMessage(const SharedHandle<DHTMessage>& message,
const SharedHandle<DHTMessageCallback>& callback = 0);
const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>());
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> >
messageArrived(const Dictionary* d, const std::string& ipaddr, uint16_t port);

View File

@ -63,7 +63,8 @@ private:
public:
DHTMessageTrackerEntry(const SharedHandle<DHTMessage>& sentMessage,
time_t timeout,
const SharedHandle<DHTMessageCallback>& callback = 0);
const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>());
bool isTimeout() const;

View File

@ -39,6 +39,7 @@
#include "DHTNodeLookupEntry.h"
#include "LogFactory.h"
#include "Util.h"
#include <cassert>
namespace aria2 {
@ -49,7 +50,8 @@ DHTNodeLookupTask::DHTNodeLookupTask(const unsigned char* targetNodeID):
std::deque<SharedHandle<DHTNode> >
DHTNodeLookupTask::getNodesFromMessage(const SharedHandle<DHTMessage>& message)
{
SharedHandle<DHTFindNodeReplyMessage> m = message;
SharedHandle<DHTFindNodeReplyMessage> m
(dynamic_pointer_cast<DHTFindNodeReplyMessage>(message));
if(m.isNull()) {
return std::deque<SharedHandle<DHTNode> >();
} else {

View File

@ -43,9 +43,7 @@
namespace aria2 {
DHTPeerAnnounceCommand::DHTPeerAnnounceCommand(int32_t cuid, DownloadEngine* e, time_t interval):
TimeBasedCommand(cuid, e, interval),
_peerAnnounceStorage(0)
{}
TimeBasedCommand(cuid, e, interval) {}
DHTPeerAnnounceCommand::~DHTPeerAnnounceCommand() {}

View File

@ -42,8 +42,7 @@
namespace aria2 {
DHTPeerAnnounceEntry::DHTPeerAnnounceEntry(const unsigned char* infoHash):
_btCtx(0)
DHTPeerAnnounceEntry::DHTPeerAnnounceEntry(const unsigned char* infoHash)
{
memcpy(_infoHash, infoHash, DHT_ID_LENGTH);
}
@ -108,7 +107,8 @@ Peers DHTPeerAnnounceEntry::getPeers() const
std::deque<SharedHandle<Peer> > peers;
for(std::deque<PeerAddrEntry>::const_iterator i = _peerAddrEntries.begin();
i != _peerAddrEntries.end(); ++i) {
peers.push_back(new Peer((*i).getIPAddress(), (*i).getPort()));
SharedHandle<Peer> peer(new Peer((*i).getIPAddress(), (*i).getPort()));
peers.push_back(peer);
}
if(!_btCtx.isNull()) {
SharedHandle<PeerStorage> peerStorage = PEER_STORAGE(_btCtx);

View File

@ -48,9 +48,8 @@
namespace aria2 {
DHTPeerAnnounceStorage::DHTPeerAnnounceStorage():_taskQueue(0),
_taskFactory(0),
_logger(LogFactory::getInstance()) {}
DHTPeerAnnounceStorage::DHTPeerAnnounceStorage():
_logger(LogFactory::getInstance()) {}
DHTPeerAnnounceStorage::~DHTPeerAnnounceStorage() {}
@ -74,9 +73,9 @@ DHTPeerAnnounceStorage::getPeerAnnounceEntry(const unsigned char* infoHash)
{
std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i =
std::find_if(_entries.begin(), _entries.end(), FindPeerAnnounceEntry(infoHash));
SharedHandle<DHTPeerAnnounceEntry> entry = 0;
SharedHandle<DHTPeerAnnounceEntry> entry;
if(i == _entries.end()) {
entry = new DHTPeerAnnounceEntry(infoHash);
entry.reset(new DHTPeerAnnounceEntry(infoHash));
_entries.push_back(entry);
} else {
entry = *i;
@ -106,7 +105,7 @@ void DHTPeerAnnounceStorage::removePeerAnnounce(const BtContextHandle& ctx)
std::deque<SharedHandle<DHTPeerAnnounceEntry> >::iterator i =
std::find_if(_entries.begin(), _entries.end(), FindPeerAnnounceEntry(ctx->getInfoHash()));
if(i != _entries.end()) {
(*i)->setBtContext(0);
(*i)->setBtContext(SharedHandle<BtContext>());
if((*i)->empty()) {
_entries.erase(i);
}

View File

@ -58,7 +58,7 @@ DHTPeerLookupTask::DHTPeerLookupTask(const SharedHandle<BtContext>& btContext):
std::deque<SharedHandle<DHTNode> > DHTPeerLookupTask::getNodesFromMessage(const SharedHandle<DHTMessage>& message)
{
SharedHandle<DHTGetPeersReplyMessage> m = message;
SharedHandle<DHTGetPeersReplyMessage> m(dynamic_pointer_cast<DHTGetPeersReplyMessage>(message));
if(m.isNull()) {
return std::deque<SharedHandle<DHTNode> >();
} else {
@ -68,7 +68,7 @@ std::deque<SharedHandle<DHTNode> > DHTPeerLookupTask::getNodesFromMessage(const
void DHTPeerLookupTask::onReceivedInternal(const SharedHandle<DHTMessage>& message)
{
SharedHandle<DHTGetPeersReplyMessage> m = message;
SharedHandle<DHTGetPeersReplyMessage> m(dynamic_pointer_cast<DHTGetPeersReplyMessage>(message));
if(m.isNull()) {
return;
}

View File

@ -55,7 +55,9 @@ DHTPingTask::~DHTPingTask() {}
void DHTPingTask::startup()
{
SharedHandle<DHTMessage> m = _factory->createPingMessage(_remoteNode);
_dispatcher->addMessageToQueue(m, _timeout, new DHTMessageCallbackImpl(this));
WeakHandle<DHTMessageCallbackListener> listener(this);
SharedHandle<DHTMessageCallback> callback(new DHTMessageCallbackImpl(listener));
_dispatcher->addMessageToQueue(m, _timeout, callback);
}
void DHTPingTask::onReceived(const SharedHandle<DHTMessage>& message)
@ -72,7 +74,9 @@ void DHTPingTask::onTimeout(const SharedHandle<DHTNode>& node)
_finished = true;
} else {
SharedHandle<DHTMessage> m = _factory->createPingMessage(_remoteNode);
_dispatcher->addMessageToQueue(m, _timeout, new DHTMessageCallbackImpl(this));
WeakHandle<DHTMessageCallbackListener> listener(this);
SharedHandle<DHTMessageCallback> callback(new DHTMessageCallbackImpl(listener));
_dispatcher->addMessageToQueue(m, _timeout, callback);
}
}

View File

@ -42,38 +42,39 @@
#include "DHTMessageDispatcher.h"
#include "DHTMessageReceiver.h"
#include "DHTMessageFactory.h"
#include "DHTMessageCallback.h"
namespace aria2 {
SharedHandle<DHTNode> DHTRegistry::_localNode = 0;
SharedHandle<DHTNode> DHTRegistry::_localNode;
SharedHandle<DHTRoutingTable> DHTRegistry::_routingTable = 0;
SharedHandle<DHTRoutingTable> DHTRegistry::_routingTable;
SharedHandle<DHTTaskQueue> DHTRegistry::_taskQueue = 0;
SharedHandle<DHTTaskQueue> DHTRegistry::_taskQueue;
SharedHandle<DHTTaskFactory> DHTRegistry::_taskFactory = 0;
SharedHandle<DHTTaskFactory> DHTRegistry::_taskFactory;
SharedHandle<DHTPeerAnnounceStorage> DHTRegistry::_peerAnnounceStorage = 0;
SharedHandle<DHTPeerAnnounceStorage> DHTRegistry::_peerAnnounceStorage;
SharedHandle<DHTTokenTracker> DHTRegistry::_tokenTracker = 0;
SharedHandle<DHTTokenTracker> DHTRegistry::_tokenTracker;
SharedHandle<DHTMessageDispatcher> DHTRegistry::_messageDispatcher = 0;
SharedHandle<DHTMessageDispatcher> DHTRegistry::_messageDispatcher;
SharedHandle<DHTMessageReceiver> DHTRegistry::_messageReceiver = 0;
SharedHandle<DHTMessageReceiver> DHTRegistry::_messageReceiver;
SharedHandle<DHTMessageFactory> DHTRegistry::_messageFactory = 0;
SharedHandle<DHTMessageFactory> DHTRegistry::_messageFactory;
void DHTRegistry::clear()
{
_localNode = 0;
_routingTable = 0;
_taskQueue = 0;
_taskFactory = 0;
_peerAnnounceStorage = 0;
_tokenTracker = 0;
_messageDispatcher = 0;
_messageReceiver = 0;
_messageFactory = 0;
_localNode.reset();
_routingTable.reset();
_taskQueue.reset();
_taskFactory.reset();
_peerAnnounceStorage.reset();
_tokenTracker.reset();
_messageDispatcher.reset();
_messageReceiver.reset();
_messageFactory.reset();
}
} // namespace aria2

View File

@ -65,7 +65,9 @@ void DHTReplaceNodeTask::sendMessage()
_finished = true;
} else {
SharedHandle<DHTMessage> m = _factory->createPingMessage(questionableNode);
_dispatcher->addMessageToQueue(m, _timeout, new DHTMessageCallbackImpl(this));
WeakHandle<DHTMessageCallbackListener> listener(this);
SharedHandle<DHTMessageCallback> callback(new DHTMessageCallbackImpl(listener));
_dispatcher->addMessageToQueue(m, _timeout, callback);
}
}

View File

@ -47,12 +47,12 @@ namespace aria2 {
DHTRoutingTable::DHTRoutingTable(const SharedHandle<DHTNode>& localNode):
_localNode(localNode),
_root(new BNode(new DHTBucket(localNode))),
_numBucket(1),
_taskQueue(0),
_taskFactory(0),
_logger(LogFactory::getInstance())
{}
{
SharedHandle<DHTBucket> bucket(new DHTBucket(_localNode));
_root = new BNode(bucket);
}
DHTRoutingTable::~DHTRoutingTable()
{
@ -84,7 +84,7 @@ bool DHTRoutingTable::addNode(const SharedHandle<DHTNode>& node, bool good)
Util::toHex(bucket->getMaxID(), DHT_ID_LENGTH).c_str());
SharedHandle<DHTBucket> r = bucket->split();
bnode->setBucket(0);
bnode->setBucket(SharedHandle<DHTBucket>());
BNode* lbnode = new BNode(bucket);
BNode* rbnode = new BNode(r);
bnode->setLeft(lbnode);

View File

@ -46,8 +46,7 @@
namespace aria2 {
DHTRoutingTableDeserializer::DHTRoutingTableDeserializer():
_localNode(0) {}
DHTRoutingTableDeserializer::DHTRoutingTableDeserializer() {}
DHTRoutingTableDeserializer::~DHTRoutingTableDeserializer() {}
@ -96,7 +95,7 @@ void DHTRoutingTableDeserializer::deserialize(std::istream& in)
in.read(buf, 8);
// localnode ID
in.read(buf, DHT_ID_LENGTH);
SharedHandle<DHTNode> localNode = new DHTNode(reinterpret_cast<const unsigned char*>(buf));
SharedHandle<DHTNode> localNode(new DHTNode(reinterpret_cast<const unsigned char*>(buf)));
// 4bytes reserved
in.read(buf, 4);
@ -140,7 +139,7 @@ void DHTRoutingTableDeserializer::deserialize(std::istream& in)
// localnode ID
in.read(buf, DHT_ID_LENGTH);
SharedHandle<DHTNode> node = new DHTNode(reinterpret_cast<const unsigned char*>(buf));
SharedHandle<DHTNode> node(new DHTNode(reinterpret_cast<const unsigned char*>(buf)));
node->setIPAddress(peer.first);
node->setPort(peer.second);
// 4bytes reserved

View File

@ -45,7 +45,7 @@
namespace aria2 {
DHTRoutingTableSerializer::DHTRoutingTableSerializer():_localNode(0) {}
DHTRoutingTableSerializer::DHTRoutingTableSerializer() {}
DHTRoutingTableSerializer::~DHTRoutingTableSerializer() {}

View File

@ -58,6 +58,7 @@
#include "DHTRoutingTableDeserializer.h"
#include "DHTRegistry.h"
#include "DHTBucketRefreshTask.h"
#include "DHTMessageCallback.h"
#include "CUIDCounter.h"
#include "prefs.h"
#include "Option.h"
@ -82,7 +83,7 @@ Commands DHTSetup::setup(DownloadEngine* e, const Option* option)
try {
// load routing table and localnode id here
SharedHandle<DHTNode> localNode = 0;
SharedHandle<DHTNode> localNode;
DHTRoutingTableDeserializer deserializer;
std::string dhtFile = option->get(PREF_DHT_FILE_PATH);
@ -99,10 +100,10 @@ Commands DHTSetup::setup(DownloadEngine* e, const Option* option)
}
}
if(localNode.isNull()) {
localNode = new DHTNode();
localNode.reset(new DHTNode());
}
SharedHandle<DHTConnectionImpl> connection = new DHTConnectionImpl();
SharedHandle<DHTConnectionImpl> connection(new DHTConnectionImpl());
{
IntSequence seq = Util::parseIntRange(option->get(PREF_DHT_LISTEN_PORT));
uint16_t port;
@ -114,23 +115,23 @@ Commands DHTSetup::setup(DownloadEngine* e, const Option* option)
_logger->debug("Initialized local node ID=%s",
Util::toHex(localNode->getID(), DHT_ID_LENGTH).c_str());
SharedHandle<DHTRoutingTable> routingTable = new DHTRoutingTable(localNode);
SharedHandle<DHTRoutingTable> routingTable(new DHTRoutingTable(localNode));
SharedHandle<DHTMessageFactoryImpl> factory = new DHTMessageFactoryImpl();
SharedHandle<DHTMessageFactoryImpl> factory(new DHTMessageFactoryImpl());
SharedHandle<DHTMessageTracker> tracker = new DHTMessageTracker();
SharedHandle<DHTMessageTracker> tracker(new DHTMessageTracker());
SharedHandle<DHTMessageDispatcherImpl> dispatcher = new DHTMessageDispatcherImpl(tracker);
SharedHandle<DHTMessageDispatcherImpl> dispatcher(new DHTMessageDispatcherImpl(tracker));
SharedHandle<DHTMessageReceiver> receiver = new DHTMessageReceiver(tracker);
SharedHandle<DHTMessageReceiver> receiver(new DHTMessageReceiver(tracker));
SharedHandle<DHTTaskQueue> taskQueue = new DHTTaskQueueImpl();
SharedHandle<DHTTaskQueue> taskQueue(new DHTTaskQueueImpl());
SharedHandle<DHTTaskFactoryImpl> taskFactory = new DHTTaskFactoryImpl();
SharedHandle<DHTTaskFactoryImpl> taskFactory(new DHTTaskFactoryImpl());
SharedHandle<DHTPeerAnnounceStorage> peerAnnounceStorage = new DHTPeerAnnounceStorage();
SharedHandle<DHTPeerAnnounceStorage> peerAnnounceStorage(new DHTPeerAnnounceStorage());
SharedHandle<DHTTokenTracker> tokenTracker = new DHTTokenTracker();
SharedHandle<DHTTokenTracker> tokenTracker(new DHTTokenTracker());
// wiring up
tracker->setRoutingTable(routingTable);
@ -176,7 +177,8 @@ Commands DHTSetup::setup(DownloadEngine* e, const Option* option)
routingTable->addNode(*i);
}
if(!desnodes.empty() && deserializer.getSerializedTime().elapsed(DHT_BUCKET_REFRESH_INTERVAL)) {
SharedHandle<DHTBucketRefreshTask> task = taskFactory->createBucketRefreshTask();
SharedHandle<DHTBucketRefreshTask> task
(dynamic_pointer_cast<DHTBucketRefreshTask>(taskFactory->createBucketRefreshTask()));
task->setForceRefresh(true);
taskQueue->addPeriodicTask1(task);
}

View File

@ -50,15 +50,11 @@
#include "BtContext.h"
#include "PeerStorage.h"
#include "BtRuntime.h"
#include "DHTMessageCallback.h"
namespace aria2 {
DHTTaskFactoryImpl::DHTTaskFactoryImpl():_localNode(0),
_routingTable(0),
_dispatcher(0),
_factory(0),
_taskQueue(0),
_logger(LogFactory::getInstance()) {}
DHTTaskFactoryImpl::DHTTaskFactoryImpl():_logger(LogFactory::getInstance()) {}
DHTTaskFactoryImpl::~DHTTaskFactoryImpl() {}
@ -66,7 +62,7 @@ SharedHandle<DHTTask>
DHTTaskFactoryImpl::createPingTask(const SharedHandle<DHTNode>& remoteNode,
size_t numRetry)
{
SharedHandle<DHTPingTask> task = new DHTPingTask(remoteNode, numRetry);
SharedHandle<DHTPingTask> task(new DHTPingTask(remoteNode, numRetry));
setCommonProperty(task);
return task;
}
@ -74,7 +70,7 @@ DHTTaskFactoryImpl::createPingTask(const SharedHandle<DHTNode>& remoteNode,
SharedHandle<DHTTask>
DHTTaskFactoryImpl::createNodeLookupTask(const unsigned char* targetID)
{
SharedHandle<DHTNodeLookupTask> task = new DHTNodeLookupTask(targetID);
SharedHandle<DHTNodeLookupTask> task(new DHTNodeLookupTask(targetID));
setCommonProperty(task);
return task;
}
@ -82,7 +78,7 @@ DHTTaskFactoryImpl::createNodeLookupTask(const unsigned char* targetID)
SharedHandle<DHTTask>
DHTTaskFactoryImpl::createBucketRefreshTask()
{
SharedHandle<DHTBucketRefreshTask> task = new DHTBucketRefreshTask();
SharedHandle<DHTBucketRefreshTask> task(new DHTBucketRefreshTask());
setCommonProperty(task);
return task;
}
@ -90,7 +86,7 @@ DHTTaskFactoryImpl::createBucketRefreshTask()
SharedHandle<DHTTask>
DHTTaskFactoryImpl::createPeerLookupTask(const SharedHandle<BtContext>& ctx)
{
SharedHandle<DHTPeerLookupTask> task = new DHTPeerLookupTask(ctx);
SharedHandle<DHTPeerLookupTask> task(new DHTPeerLookupTask(ctx));
setCommonProperty(task);
return task;
}
@ -99,14 +95,14 @@ SharedHandle<DHTTask>
DHTTaskFactoryImpl::createPeerAnnounceTask(const unsigned char* infoHash)
{
// TODO
return 0;
return SharedHandle<DHTTask>();
}
SharedHandle<DHTTask>
DHTTaskFactoryImpl::createReplaceNodeTask(const SharedHandle<DHTBucket>& bucket,
const SharedHandle<DHTNode>& newNode)
{
SharedHandle<DHTReplaceNodeTask> task = new DHTReplaceNodeTask(bucket, newNode);
SharedHandle<DHTReplaceNodeTask> task(new DHTReplaceNodeTask(bucket, newNode));
setCommonProperty(task);
return task;
}

View File

@ -37,9 +37,7 @@
namespace aria2 {
DHTTaskQueueImpl::DHTTaskQueueImpl():_periodicTask1(0),
_periodicTask2(0),
_immediateTask(0) {}
DHTTaskQueueImpl::DHTTaskQueueImpl() {}
DHTTaskQueueImpl::~DHTTaskQueueImpl() {}
@ -48,7 +46,7 @@ void DHTTaskQueueImpl::executeTask(SharedHandle<DHTTask>& task,
{
while(1) {
if(task.isNull() || task->finished()) {
task = 0;
task.reset();
if(taskQueue.empty()) {
break;
}

View File

@ -45,9 +45,7 @@ namespace aria2 {
DHTTokenUpdateCommand::DHTTokenUpdateCommand(int32_t cuid,
DownloadEngine* e,
time_t interval):
TimeBasedCommand(cuid, e, interval),
_tokenTracker(0)
{}
TimeBasedCommand(cuid, e, interval) {}
DHTTokenUpdateCommand::~DHTTokenUpdateCommand() {}

View File

@ -42,7 +42,7 @@ namespace aria2 {
DHTUnknownMessage::DHTUnknownMessage(const SharedHandle<DHTNode>& localNode,
const unsigned char* data, size_t length,
const std::string& ipaddr, uint16_t port):
DHTMessage(localNode, 0),
DHTMessage(localNode, SharedHandle<DHTNode>()),
_length(length),
_ipaddr(ipaddr),
_port(port)

View File

@ -262,7 +262,7 @@ void DefaultBtContext::loadFromMemory(const unsigned char* content,
size_t length,
const std::string& defaultName)
{
SharedHandle<MetaEntry> rootEntry = MetaFileUtil::bdecoding(content, length);
SharedHandle<MetaEntry> rootEntry(MetaFileUtil::bdecoding(content, length));
const Dictionary* rootDic = dynamic_cast<const Dictionary*>(rootEntry.get());
if(!rootDic) {
throw new DlAbortEx("torrent file does not contain a root dictionary .");
@ -271,7 +271,7 @@ void DefaultBtContext::loadFromMemory(const unsigned char* content,
}
void DefaultBtContext::load(const std::string& torrentFile) {
SharedHandle<MetaEntry> rootEntry = MetaFileUtil::parseMetaFile(torrentFile);
SharedHandle<MetaEntry> rootEntry(MetaFileUtil::parseMetaFile(torrentFile));
const Dictionary* rootDic = dynamic_cast<const Dictionary*>(rootEntry.get());
if(!rootDic) {
throw new DlAbortEx("torrent file does not contain a root dictionary .");

View File

@ -83,7 +83,7 @@ DefaultBtInteractive::~DefaultBtInteractive() {}
void DefaultBtInteractive::initiateHandshake() {
SharedHandle<BtHandshakeMessage> message =
SharedHandle<BtMessage> message =
messageFactory->createHandshakeMessage(btContext->getInfoHash(),
btContext->getPeerId());
dispatcher->addMessageToQueue(message);
@ -94,7 +94,7 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
SharedHandle<BtHandshakeMessage> message =
btMessageReceiver->receiveHandshake(quickReply);
if(message.isNull()) {
return 0;
return SharedHandle<BtMessage>();
}
peer->setPeerId(message->getPeerId());
@ -104,8 +104,8 @@ BtMessageHandle DefaultBtInteractive::receiveHandshake(bool quickReply) {
}
if(message->isExtendedMessagingEnabled()) {
peer->setExtendedMessagingEnabled(true);
DefaultExtensionMessageFactoryHandle factory =
new DefaultExtensionMessageFactory(btContext, peer);
DefaultExtensionMessageFactoryHandle factory
(new DefaultExtensionMessageFactory(btContext, peer));
if(!_utPexEnabled) {
factory->removeExtension("ut_pex");
}
@ -150,12 +150,12 @@ void DefaultBtInteractive::addPortMessageToQueue()
void DefaultBtInteractive::addHandshakeExtendedMessageToQueue()
{
HandshakeExtensionMessageHandle m = new HandshakeExtensionMessage();
HandshakeExtensionMessageHandle m(new HandshakeExtensionMessage());
m->setClientVersion("aria2");
m->setTCPPort(btRuntime->getListenPort());
m->setExtensions(EXTENSION_MESSAGE_FACTORY(btContext, peer)->getExtensions());
BtExtendedMessageHandle msg = messageFactory->createBtExtendedMessage(m);
SharedHandle<BtMessage> msg = messageFactory->createBtExtendedMessage(m);
dispatcher->addMessageToQueue(msg);
}
@ -386,8 +386,8 @@ void DefaultBtInteractive::addPeerExchangeMessage()
{
time_t interval = 60;
if(_pexCheckPoint.elapsed(interval)) {
UTPexExtensionMessageHandle m =
new UTPexExtensionMessage(peer->getExtensionMessageID("ut_pex"));
UTPexExtensionMessageHandle m
(new UTPexExtensionMessage(peer->getExtensionMessageID("ut_pex")));
const Peers& peers = peerStorage->getPeers();
{
size_t max = 30;
@ -413,7 +413,7 @@ void DefaultBtInteractive::addPeerExchangeMessage()
}
}
}
BtExtendedMessageHandle msg = messageFactory->createBtExtendedMessage(m);
BtMessageHandle msg = messageFactory->createBtExtendedMessage(m);
dispatcher->addMessageToQueue(msg);
_pexCheckPoint.reset();
}

View File

@ -56,10 +56,6 @@ namespace aria2 {
DefaultBtMessageDispatcher::DefaultBtMessageDispatcher():
cuid(0),
btContext(0),
peerStorage(0),
pieceStorage(0),
peer(0),
maxUploadSpeedLimit(0),
requestTimeout(0),
logger(LogFactory::getInstance()) {}
@ -108,8 +104,8 @@ void DefaultBtMessageDispatcher::sendMessages() {
// Cancel sending piece message to peer.
void DefaultBtMessageDispatcher::doCancelSendingPieceAction(size_t index, uint32_t begin, size_t length)
{
BtCancelSendingPieceEventHandle event =
new BtCancelSendingPieceEvent(index, begin, length);
BtCancelSendingPieceEventHandle event
(new BtCancelSendingPieceEvent(index, begin, length));
BtMessages tempQueue = messageQueue;
for(BtMessages::iterator itr = tempQueue.begin(); itr != tempQueue.end(); itr++) {
@ -140,8 +136,8 @@ void DefaultBtMessageDispatcher::doAbortOutstandingRequestAction(const PieceHand
}
}
BtAbortOutstandingRequestEventHandle event =
new BtAbortOutstandingRequestEvent(piece);
BtAbortOutstandingRequestEventHandle event
(new BtAbortOutstandingRequestEvent(piece));
BtMessages tempQueue = messageQueue;
for(BtMessages::iterator itr = tempQueue.begin(); itr != tempQueue.end(); ++itr) {
@ -168,7 +164,7 @@ void DefaultBtMessageDispatcher::doChokedAction()
}
}
BtChokedEventHandle event = new BtChokedEvent();
BtChokedEventHandle event(new BtChokedEvent());
BtMessages tempQueue = messageQueue;
for(BtMessages::iterator itr = tempQueue.begin(); itr != tempQueue.end(); ++itr) {
@ -179,7 +175,7 @@ void DefaultBtMessageDispatcher::doChokedAction()
// localhost dispatched choke message to the peer.
void DefaultBtMessageDispatcher::doChokingAction()
{
BtChokingEventHandle event = new BtChokingEvent();
BtChokingEventHandle event(new BtChokingEvent());
BtMessages tempQueue = messageQueue;
for(BtMessages::iterator itr = tempQueue.begin(); itr != tempQueue.end(); ++itr) {

View File

@ -72,9 +72,6 @@
namespace aria2 {
DefaultBtMessageFactory::DefaultBtMessageFactory():cuid(0),
btContext(0),
pieceStorage(0),
peer(0),
_dhtEnabled(false)
{}
@ -83,10 +80,10 @@ DefaultBtMessageFactory::~DefaultBtMessageFactory() {}
BtMessageHandle
DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataLength)
{
AbstractBtMessageHandle msg(0);
AbstractBtMessageHandle msg;
if(dataLength == 0) {
// keep-alive
msg = new BtKeepAliveMessage();
msg.reset(new BtKeepAliveMessage());
} else {
uint8_t id = PeerMessageUtil::getId(data);
switch(id) {
@ -104,40 +101,48 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
break;
case BtHaveMessage::ID:
msg = BtHaveMessage::create(data, dataLength);
msg->setBtMessageValidator(new BtHaveMessageValidator((BtHaveMessage*)msg.get(),
btContext->getNumPieces()));
{
SharedHandle<BtMessageValidator> v
(new BtHaveMessageValidator((BtHaveMessage*)msg.get(),
btContext->getNumPieces()));
msg->setBtMessageValidator(v);
}
break;
case BtBitfieldMessage::ID:
msg = BtBitfieldMessage::create(data, dataLength);
msg->setBtMessageValidator(new BtBitfieldMessageValidator((BtBitfieldMessage*)msg.get(),
btContext->getNumPieces()));
{
SharedHandle<BtMessageValidator> v
(new BtBitfieldMessageValidator((BtBitfieldMessage*)msg.get(),
btContext->getNumPieces()));
msg->setBtMessageValidator(v);
}
break;
case BtRequestMessage::ID: {
BtRequestMessageHandle temp = BtRequestMessage::create(data, dataLength);
BtMessageValidatorHandle validator =
new BtRequestMessageValidator(temp.get(),
BtMessageValidatorHandle validator
(new BtRequestMessageValidator(temp.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(temp->getIndex()));
pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
msg = temp;
break;
}
case BtCancelMessage::ID: {
BtCancelMessageHandle temp = BtCancelMessage::create(data, dataLength);
BtMessageValidatorHandle validator =
new BtCancelMessageValidator(temp.get(),
BtMessageValidatorHandle validator
(new BtCancelMessageValidator(temp.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(temp->getIndex()));
pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
msg = temp;
break;
}
case BtPieceMessage::ID: {
BtPieceMessageHandle temp = BtPieceMessage::create(data, dataLength);
BtMessageValidatorHandle validator =
new BtPieceMessageValidator(temp.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(temp->getIndex()));
BtMessageValidatorHandle validator
(new BtPieceMessageValidator(temp.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
msg = temp;
break;
@ -150,28 +155,28 @@ DefaultBtMessageFactory::createBtMessage(const unsigned char* data, size_t dataL
break;
case BtRejectMessage::ID: {
BtRejectMessageHandle temp = BtRejectMessage::create(data, dataLength);
BtMessageValidatorHandle validator =
new BtRejectMessageValidator(temp.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(temp->getIndex()));
BtMessageValidatorHandle validator
(new BtRejectMessageValidator(temp.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(temp->getIndex())));
temp->setBtMessageValidator(validator);
msg = temp;
break;
}
case BtSuggestPieceMessage::ID: {
BtSuggestPieceMessageHandle temp = BtSuggestPieceMessage::create(data, dataLength);
BtMessageValidatorHandle validator =
new BtSuggestPieceMessageValidator(temp.get(),
btContext->getNumPieces());
BtMessageValidatorHandle validator
(new BtSuggestPieceMessageValidator(temp.get(),
btContext->getNumPieces()));
temp->setBtMessageValidator(validator);
msg = temp;
break;
}
case BtAllowedFastMessage::ID: {
BtAllowedFastMessageHandle temp = BtAllowedFastMessage::create(data, dataLength);
BtMessageValidatorHandle validator =
new BtAllowedFastMessageValidator(temp.get(),
btContext->getNumPieces());
BtMessageValidatorHandle validator
(new BtAllowedFastMessageValidator(temp.get(),
btContext->getNumPieces()));
temp->setBtMessageValidator(validator);
msg = temp;
break;
@ -207,30 +212,30 @@ void DefaultBtMessageFactory::setCommonProperty(const AbstractBtMessageHandle& m
msg->setBtContext(btContext);
msg->setBtMessageDispatcher(dispatcher);
msg->setBtRequestFactory(requestFactory);
msg->setBtMessageFactory(this);
msg->setBtMessageFactory(WeakHandle<BtMessageFactory>(this));
msg->setPeerConnection(peerConnection);
}
BtMessageHandle
SharedHandle<BtHandshakeMessage>
DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* data, size_t dataLength)
{
SharedHandle<BtHandshakeMessage> msg = BtHandshakeMessage::create(data, dataLength);
BtMessageValidatorHandle validator =
new BtHandshakeMessageValidator(msg.get(),
btContext->getInfoHash());
BtMessageValidatorHandle validator
(new BtHandshakeMessageValidator(msg.get(),
btContext->getInfoHash()));
msg->setBtMessageValidator(validator);
setCommonProperty(msg);
return msg;
}
BtMessageHandle
SharedHandle<BtHandshakeMessage>
DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId)
{
SharedHandle<BtHandshakeMessage> msg = new BtHandshakeMessage(infoHash, peerId);
BtMessageValidatorHandle validator =
new BtHandshakeMessageValidator(msg.get(),
btContext->getInfoHash());
SharedHandle<BtHandshakeMessage> msg(new BtHandshakeMessage(infoHash, peerId));
BtMessageValidatorHandle validator
(new BtHandshakeMessageValidator(msg.get(),
btContext->getInfoHash()));
msg->setBtMessageValidator(validator);
msg->setDHTEnabled(_dhtEnabled);
setCommonProperty(msg);
@ -240,15 +245,15 @@ DefaultBtMessageFactory::createHandshakeMessage(const unsigned char* infoHash,
BtMessageHandle
DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, size_t blockIndex)
{
BtRequestMessageHandle msg =
new BtRequestMessage(piece->getIndex(),
blockIndex*piece->getBlockLength(),
piece->getBlockLength(blockIndex),
blockIndex);
BtMessageValidatorHandle validator =
new BtRequestMessageValidator(msg.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(msg->getIndex()));
BtRequestMessageHandle msg
(new BtRequestMessage(piece->getIndex(),
blockIndex*piece->getBlockLength(),
piece->getBlockLength(blockIndex),
blockIndex));
BtMessageValidatorHandle validator
(new BtRequestMessageValidator(msg.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(msg->getIndex())));
msg->setBtMessageValidator(validator);
setCommonProperty(msg);
return msg;
@ -257,11 +262,11 @@ DefaultBtMessageFactory::createRequestMessage(const PieceHandle& piece, size_t b
BtMessageHandle
DefaultBtMessageFactory::createCancelMessage(size_t index, uint32_t begin, size_t length)
{
BtCancelMessageHandle msg = new BtCancelMessage(index, begin, length);
BtMessageValidatorHandle validator =
new BtCancelMessageValidator(msg.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(index));
BtCancelMessageHandle msg(new BtCancelMessage(index, begin, length));
BtMessageValidatorHandle validator
(new BtCancelMessageValidator(msg.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(index)));
msg->setBtMessageValidator(validator);
setCommonProperty(msg);
return msg;
@ -270,11 +275,11 @@ DefaultBtMessageFactory::createCancelMessage(size_t index, uint32_t begin, size_
BtMessageHandle
DefaultBtMessageFactory::createPieceMessage(size_t index, uint32_t begin, size_t length)
{
BtPieceMessageHandle msg = new BtPieceMessage(index, begin, length);
BtMessageValidatorHandle validator =
new BtPieceMessageValidator(msg.get(),
BtPieceMessageHandle msg(new BtPieceMessage(index, begin, length));
BtMessageValidatorHandle validator
(new BtPieceMessageValidator(msg.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(index));
pieceStorage->getPieceLength(index)));
msg->setBtMessageValidator(validator);
setCommonProperty(msg);
return msg;
@ -283,9 +288,11 @@ DefaultBtMessageFactory::createPieceMessage(size_t index, uint32_t begin, size_t
BtMessageHandle
DefaultBtMessageFactory::createHaveMessage(size_t index)
{
BtHaveMessageHandle msg = new BtHaveMessage(index);
msg->setBtMessageValidator(new BtHaveMessageValidator(msg.get(),
btContext->getNumPieces()));
BtHaveMessageHandle msg(new BtHaveMessage(index));
SharedHandle<BtMessageValidator> v
(new BtHaveMessageValidator(msg.get(),
btContext->getNumPieces()));
msg->setBtMessageValidator(v);
setCommonProperty(msg);
return msg;
}
@ -293,7 +300,7 @@ DefaultBtMessageFactory::createHaveMessage(size_t index)
BtMessageHandle
DefaultBtMessageFactory::createChokeMessage()
{
BtChokeMessageHandle msg = new BtChokeMessage();
BtChokeMessageHandle msg(new BtChokeMessage());
setCommonProperty(msg);
return msg;
}
@ -301,7 +308,7 @@ DefaultBtMessageFactory::createChokeMessage()
BtMessageHandle
DefaultBtMessageFactory::createUnchokeMessage()
{
BtUnchokeMessageHandle msg = new BtUnchokeMessage();
BtUnchokeMessageHandle msg(new BtUnchokeMessage());
setCommonProperty(msg);
return msg;
}
@ -309,7 +316,7 @@ DefaultBtMessageFactory::createUnchokeMessage()
BtMessageHandle
DefaultBtMessageFactory::createInterestedMessage()
{
BtInterestedMessageHandle msg = new BtInterestedMessage();
BtInterestedMessageHandle msg(new BtInterestedMessage());
setCommonProperty(msg);
return msg;
}
@ -317,7 +324,7 @@ DefaultBtMessageFactory::createInterestedMessage()
BtMessageHandle
DefaultBtMessageFactory::createNotInterestedMessage()
{
BtNotInterestedMessageHandle msg = new BtNotInterestedMessage();
BtNotInterestedMessageHandle msg(new BtNotInterestedMessage());
setCommonProperty(msg);
return msg;
}
@ -325,11 +332,13 @@ DefaultBtMessageFactory::createNotInterestedMessage()
BtMessageHandle
DefaultBtMessageFactory::createBitfieldMessage()
{
BtBitfieldMessageHandle msg =
new BtBitfieldMessage(pieceStorage->getBitfield(),
pieceStorage->getBitfieldLength());
msg->setBtMessageValidator(new BtBitfieldMessageValidator(msg.get(),
btContext->getNumPieces()));
BtBitfieldMessageHandle msg
(new BtBitfieldMessage(pieceStorage->getBitfield(),
pieceStorage->getBitfieldLength()));
SharedHandle<BtMessageValidator> v
(new BtBitfieldMessageValidator(msg.get(),
btContext->getNumPieces()));
msg->setBtMessageValidator(v);
setCommonProperty(msg);
return msg;
}
@ -337,7 +346,7 @@ DefaultBtMessageFactory::createBitfieldMessage()
BtMessageHandle
DefaultBtMessageFactory::createKeepAliveMessage()
{
BtKeepAliveMessageHandle msg = new BtKeepAliveMessage();
BtKeepAliveMessageHandle msg(new BtKeepAliveMessage());
setCommonProperty(msg);
return msg;
}
@ -345,7 +354,7 @@ DefaultBtMessageFactory::createKeepAliveMessage()
BtMessageHandle
DefaultBtMessageFactory::createHaveAllMessage()
{
BtHaveAllMessageHandle msg = new BtHaveAllMessage();
BtHaveAllMessageHandle msg(new BtHaveAllMessage());
setCommonProperty(msg);
return msg;
}
@ -353,7 +362,7 @@ DefaultBtMessageFactory::createHaveAllMessage()
BtMessageHandle
DefaultBtMessageFactory::createHaveNoneMessage()
{
BtHaveNoneMessageHandle msg = new BtHaveNoneMessage();
BtHaveNoneMessageHandle msg(new BtHaveNoneMessage());
setCommonProperty(msg);
return msg;
}
@ -361,11 +370,11 @@ DefaultBtMessageFactory::createHaveNoneMessage()
BtMessageHandle
DefaultBtMessageFactory::createRejectMessage(size_t index, uint32_t begin, size_t length)
{
BtRejectMessageHandle msg = new BtRejectMessage(index, begin, length);
BtMessageValidatorHandle validator =
new BtRejectMessageValidator(msg.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(index));
BtRejectMessageHandle msg(new BtRejectMessage(index, begin, length));
BtMessageValidatorHandle validator
(new BtRejectMessageValidator(msg.get(),
btContext->getNumPieces(),
pieceStorage->getPieceLength(index)));
msg->setBtMessageValidator(validator);
setCommonProperty(msg);
return msg;
@ -374,10 +383,10 @@ DefaultBtMessageFactory::createRejectMessage(size_t index, uint32_t begin, size_
BtMessageHandle
DefaultBtMessageFactory::createAllowedFastMessage(size_t index)
{
BtAllowedFastMessageHandle msg = new BtAllowedFastMessage(index);
BtMessageValidatorHandle validator =
new BtAllowedFastMessageValidator(msg.get(),
btContext->getNumPieces());
BtAllowedFastMessageHandle msg(new BtAllowedFastMessage(index));
BtMessageValidatorHandle validator
(new BtAllowedFastMessageValidator(msg.get(),
btContext->getNumPieces()));
msg->setBtMessageValidator(validator);
setCommonProperty(msg);
return msg;
@ -386,7 +395,7 @@ DefaultBtMessageFactory::createAllowedFastMessage(size_t index)
BtMessageHandle
DefaultBtMessageFactory::createPortMessage(uint16_t port)
{
SharedHandle<BtPortMessage> msg = new BtPortMessage(port);
SharedHandle<BtPortMessage> msg(new BtPortMessage(port));
setCommonProperty(msg);
return msg;
}
@ -394,7 +403,7 @@ DefaultBtMessageFactory::createPortMessage(uint16_t port)
BtMessageHandle
DefaultBtMessageFactory::createBtExtendedMessage(const ExtensionMessageHandle& msg)
{
BtExtendedMessageHandle m = new BtExtendedMessage(msg);
BtExtendedMessageHandle m(new BtExtendedMessage(msg));
setCommonProperty(m);
return m;
}

View File

@ -83,10 +83,10 @@ public:
virtual SharedHandle<BtMessage>
createBtMessage(const unsigned char* msg, size_t msgLength);
virtual SharedHandle<BtMessage>
virtual SharedHandle<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* msg, size_t msgLength);
virtual SharedHandle<BtMessage>
virtual SharedHandle<BtHandshakeMessage>
createHandshakeMessage(const unsigned char* infoHash,
const unsigned char* peerId);

View File

@ -50,10 +50,6 @@ namespace aria2 {
DefaultBtMessageReceiver::DefaultBtMessageReceiver():
cuid(0),
handshakeSent(false),
btContext(0),
peer(0),
peerConnection(0),
dispatcher(0),
logger(LogFactory::getInstance())
{
logger->debug("DefaultBtMessageReceiver::instantiated");
@ -64,7 +60,9 @@ DefaultBtMessageReceiver::~DefaultBtMessageReceiver()
logger->debug("DefaultBtMessageReceiver::deleted");
}
BtMessageHandle DefaultBtMessageReceiver::receiveHandshake(bool quickReply) {
SharedHandle<BtHandshakeMessage>
DefaultBtMessageReceiver::receiveHandshake(bool quickReply)
{
unsigned char data[BtHandshakeMessage::MESSAGE_LENGTH];
size_t dataLength = BtHandshakeMessage::MESSAGE_LENGTH;
bool retval = peerConnection->receiveHandshake(data, dataLength);
@ -77,7 +75,7 @@ BtMessageHandle DefaultBtMessageReceiver::receiveHandshake(bool quickReply) {
}
}
if(!retval) {
return 0;
return SharedHandle<BtHandshakeMessage>();
}
SharedHandle<BtHandshakeMessage> msg = messageFactory->createHandshakeMessage(data, dataLength);
std::deque<std::string> errors;
@ -85,12 +83,14 @@ BtMessageHandle DefaultBtMessageReceiver::receiveHandshake(bool quickReply) {
return msg;
}
BtMessageHandle DefaultBtMessageReceiver::receiveAndSendHandshake() {
SharedHandle<BtHandshakeMessage>
DefaultBtMessageReceiver::receiveAndSendHandshake()
{
return receiveHandshake(true);
}
void DefaultBtMessageReceiver::sendHandshake() {
SharedHandle<BtHandshakeMessage> msg =
SharedHandle<BtMessage> msg =
messageFactory->createHandshakeMessage(btContext->getInfoHash(),
btContext->getPeerId());
dispatcher->addMessageToQueue(msg);
@ -101,7 +101,7 @@ BtMessageHandle DefaultBtMessageReceiver::receiveMessage() {
unsigned char data[MAX_PAYLOAD_LEN];
size_t dataLength = 0;
if(!peerConnection->receiveMessage(data, dataLength)) {
return 0;
return SharedHandle<BtMessage>();
}
BtMessageHandle msg = messageFactory->createBtMessage(data, dataLength);
std::deque<std::string> errors;
@ -109,7 +109,7 @@ BtMessageHandle DefaultBtMessageReceiver::receiveMessage() {
return msg;
} else {
// TODO throw exception here based on errors;
return 0;
return SharedHandle<BtMessage>();
}
}

View File

@ -63,9 +63,9 @@ public:
virtual ~DefaultBtMessageReceiver();
virtual SharedHandle<BtMessage> receiveHandshake(bool quickReply = false);
virtual SharedHandle<BtHandshakeMessage> receiveHandshake(bool quickReply = false);
virtual SharedHandle<BtMessage> receiveAndSendHandshake();
virtual SharedHandle<BtHandshakeMessage> receiveAndSendHandshake();
virtual SharedHandle<BtMessage> receiveMessage();

View File

@ -72,7 +72,7 @@ DefaultBtProgressInfoFile::~DefaultBtProgressInfoFile() {}
bool DefaultBtProgressInfoFile::isTorrentDownload()
{
return !BtContextHandle(_dctx).isNull();
return !dynamic_pointer_cast<BtContext>(_dctx).isNull();
}
void DefaultBtProgressInfoFile::save() {
@ -98,7 +98,7 @@ void DefaultBtProgressInfoFile::save() {
if(torrentDownload) {
// infoHashLength:
// length: 32 bits
BtContextHandle btContext = _dctx;
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
uint32_t infoHashLength = btContext->getInfoHashLength();
o.write(reinterpret_cast<const char*>(&infoHashLength), sizeof(infoHashLength));
// infoHash:
@ -119,7 +119,7 @@ void DefaultBtProgressInfoFile::save() {
// uploadLength: 64 bits
uint64_t uploadLength = 0;
if(torrentDownload) {
BtContextHandle btContext = _dctx;
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
TransferStat stat = PEER_STORAGE(btContext)->calculateStat();
uploadLength = stat.getAllTimeUploadLength();
}
@ -189,7 +189,7 @@ void DefaultBtProgressInfoFile::load()
if(infoHashLength > 0) {
savedInfoHash = new unsigned char[infoHashLength];
in.read(reinterpret_cast<char*>(savedInfoHash), infoHashLength);
BtContextHandle btContext = _dctx;
BtContextHandle btContext(dynamic_pointer_cast<BtContext>(_dctx));
if(infoHashCheckEnabled &&
Util::toHex(savedInfoHash, infoHashLength) != btContext->getInfoHashAsString()) {
throw new DlAbortEx("info hash mismatch. expected: %s, actual: %s",
@ -213,7 +213,7 @@ void DefaultBtProgressInfoFile::load()
uint64_t uploadLength;
in.read(reinterpret_cast<char*>(&uploadLength), sizeof(uploadLength));
if(isTorrentDownload()) {
BT_RUNTIME(BtContextHandle(_dctx))->setUploadLengthAtStartup(uploadLength);
BT_RUNTIME(dynamic_pointer_cast<BtContext>(_dctx))->setUploadLengthAtStartup(uploadLength);
}
// TODO implement the conversion mechanism between different piece length.
@ -249,7 +249,7 @@ void DefaultBtProgressInfoFile::load()
if(!(length <=_dctx->getPieceLength())) {
throw new DlAbortEx("piece length out of range: %u", length);
}
PieceHandle piece = new Piece(index, length);
PieceHandle piece(new Piece(index, length));
uint32_t bitfieldLength;
in.read(reinterpret_cast<char*>(&bitfieldLength), sizeof(bitfieldLength));
if(piece->getBitfieldLength() != bitfieldLength) {

View File

@ -48,11 +48,7 @@
namespace aria2 {
DefaultBtRequestFactory::DefaultBtRequestFactory():
cuid(0),
btContext(0),
pieceStorage(0),
peer(0),
dispatcher(0)
cuid(0)
{
LogFactory::getInstance()->debug("DefaultBtRequestFactory::instantiated");
}

View File

@ -39,7 +39,7 @@ namespace aria2 {
SharedHandle<DiskWriter> DefaultDiskWriterFactory::newDiskWriter()
{
return new DefaultDiskWriter();
return SharedHandle<DiskWriter>(new DefaultDiskWriter());
}
} // namespace aria2

View File

@ -45,8 +45,6 @@
namespace aria2 {
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory():
_btContext(0),
_peer(0),
_logger(LogFactory::getInstance()) {}
DefaultExtensionMessageFactory::DefaultExtensionMessageFactory(const BtContextHandle& btContext,

View File

@ -67,7 +67,7 @@ Peers DefaultPeerListProcessor::extractPeer(const MetaEntry* peersEntry) {
if(!ip || !port || !port->isNumber()) {
continue;
}
PeerHandle peer = new Peer(ip->toString(), port->toInt());
PeerHandle peer(new Peer(ip->toString(), port->toInt()));
peers.push_back(peer);
}
return peers;

View File

@ -123,7 +123,7 @@ PeerHandle DefaultPeerStorage::getUnusedPeer() {
Peers::const_iterator itr = std::find_if(peers.begin(), peers.end(),
FindFinePeer());
if(itr == peers.end()) {
return 0;
return SharedHandle<Peer>();
} else {
return *itr;
}
@ -146,7 +146,7 @@ PeerHandle DefaultPeerStorage::getPeer(const std::string& ipaddr,
Peers::const_iterator itr = std::find_if(peers.begin(), peers.end(),
FindPeer(ipaddr, port));
if(itr == peers.end()) {
return 0;
return SharedHandle<Peer>();
} else {
return *itr;
}

View File

@ -59,7 +59,6 @@ namespace aria2 {
DefaultPieceStorage::DefaultPieceStorage(const DownloadContextHandle& downloadContext, const Option* option):
downloadContext(downloadContext),
diskAdaptor(0),
_diskWriterFactory(new DefaultDiskWriterFactory()),
endGamePieceNum(END_GAME_PIECE_NUM),
option(option)
@ -103,7 +102,7 @@ PieceHandle DefaultPieceStorage::checkOutPiece(size_t index)
PieceHandle piece = findUsedPiece(index);
if(piece.isNull()) {
piece = new Piece(index, bitfieldMan->getBlockLength(index));
piece.reset(new Piece(index, bitfieldMan->getBlockLength(index)));
addUsedPiece(piece);
return piece;
} else {
@ -117,18 +116,17 @@ PieceHandle DefaultPieceStorage::checkOutPiece(size_t index)
*/
PieceHandle DefaultPieceStorage::getPiece(size_t index)
{
PieceHandle piece;
if(0 <= index && index <= bitfieldMan->getMaxIndex()) {
PieceHandle piece = findUsedPiece(index);
piece = findUsedPiece(index);
if(piece.isNull()) {
piece = new Piece(index, bitfieldMan->getBlockLength(index));
piece.reset(new Piece(index, bitfieldMan->getBlockLength(index)));
if(hasPiece(index)) {
piece->setAllBlock();
}
}
return piece;
} else {
return 0;
}
return piece;
}
void DefaultPieceStorage::addUsedPiece(const PieceHandle& piece)
@ -153,7 +151,7 @@ PieceHandle DefaultPieceStorage::findUsedPiece(size_t index) const
usedPieces.end(),
FindPiece(index));
if(itr == usedPieces.end()) {
return 0;
return SharedHandle<Piece>();
} else {
return *itr;
}
@ -165,7 +163,7 @@ PieceHandle DefaultPieceStorage::getMissingPiece(const PeerHandle& peer)
if(getMissingPieceIndex(index, peer)) {
return checkOutPiece(index);
} else {
return 0;
return SharedHandle<Piece>();
}
}
@ -199,7 +197,7 @@ PieceHandle DefaultPieceStorage::getMissingFastPiece(const PeerHandle& peer)
if(getMissingFastPieceIndex(index, peer)) {
return checkOutPiece(index);
} else {
return 0;
return SharedHandle<Piece>();
}
}
@ -209,14 +207,14 @@ PieceHandle DefaultPieceStorage::getMissingPiece()
if(bitfieldMan->getSparseMissingUnusedIndex(index)) {
return checkOutPiece(index);
} else {
return 0;
return SharedHandle<Piece>();
}
}
PieceHandle DefaultPieceStorage::getMissingPiece(size_t index)
{
if(hasPiece(index) || isPieceUsed(index)) {
return 0;
return SharedHandle<Piece>();
} else {
return checkOutPiece(index);
}
@ -421,7 +419,7 @@ void DefaultPieceStorage::initStorage()
logger->debug("Instantiating DirectDiskAdaptor");
DiskWriterHandle writer = _diskWriterFactory->newDiskWriter();
writer->setDirectIOAllowed(option->getAsBool(PREF_ENABLE_DIRECT_IO));
DirectDiskAdaptorHandle directDiskAdaptor = new DirectDiskAdaptor();
DirectDiskAdaptorHandle directDiskAdaptor(new DirectDiskAdaptor());
directDiskAdaptor->setDiskWriter(writer);
directDiskAdaptor->setTotalLength(downloadContext->getTotalLength());
this->diskAdaptor = directDiskAdaptor;
@ -429,7 +427,7 @@ void DefaultPieceStorage::initStorage()
// file mode == DownloadContext::MULTI
if(option->get(PREF_DIRECT_FILE_MAPPING) == V_TRUE) {
logger->debug("Instantiating MultiDiskAdaptor");
MultiDiskAdaptorHandle multiDiskAdaptor = new MultiDiskAdaptor();
MultiDiskAdaptorHandle multiDiskAdaptor(new MultiDiskAdaptor());
multiDiskAdaptor->setDirectIOAllowed(option->getAsBool(PREF_ENABLE_DIRECT_IO));
multiDiskAdaptor->setPieceLength(downloadContext->getPieceLength());
multiDiskAdaptor->setTopDir(downloadContext->getName());
@ -438,7 +436,7 @@ void DefaultPieceStorage::initStorage()
logger->debug("Instantiating CopyDiskAdaptor");
DiskWriterHandle writer = _diskWriterFactory->newDiskWriter();
writer->setDirectIOAllowed(option->getAsBool(PREF_ENABLE_DIRECT_IO));
CopyDiskAdaptorHandle copyDiskAdaptor = new CopyDiskAdaptor();
CopyDiskAdaptorHandle copyDiskAdaptor(new CopyDiskAdaptor());
copyDiskAdaptor->setDiskWriter(writer);
copyDiskAdaptor->setTempFilename(downloadContext->getName()+".a2tmp");
copyDiskAdaptor->setTotalLength(downloadContext->getTotalLength());
@ -543,7 +541,7 @@ void DefaultPieceStorage::markPiecesDone(uint64_t length)
}
size_t r = (length%bitfieldMan->getBlockLength())/Piece::BLOCK_LENGTH;
if(r > 0) {
PieceHandle p = new Piece(numPiece, bitfieldMan->getBlockLength(numPiece));
PieceHandle p(new Piece(numPiece, bitfieldMan->getBlockLength(numPiece)));
for(size_t i = 0; i < r; ++i) {
p->completeBlock(i);
}

View File

@ -45,12 +45,7 @@ SegmentManHandle
DefaultSegmentManFactory::createNewInstance(const DownloadContextHandle& dctx,
const PieceStorageHandle& ps)
{
SegmentManHandle segmentMan = new SegmentMan(_option, dctx, ps);
//segmentMan->diskWriter = new DefaultDiskWriter();
//segmentMan->dir = _option->get(PREF_DIR);
// TODO disable this in multi-simultaneous download mode.
//segmentMan->ufilename = _option->get(PREF_OUT);
//segmentMan->option = _option;
SegmentManHandle segmentMan(new SegmentMan(_option, dctx, ps));
return segmentMan;
}

View File

@ -41,8 +41,14 @@ namespace aria2 {
DelegatingPeerListProcessor::DelegatingPeerListProcessor()
{
processors.push_back(new DefaultPeerListProcessor());
processors.push_back(new CompactPeerListProcessor());
{
SharedHandle<PeerListProcessor> proc(new DefaultPeerListProcessor);
processors.push_back(proc);
}
{
SharedHandle<PeerListProcessor> proc(new CompactPeerListProcessor);
processors.push_back(proc);
}
}
DelegatingPeerListProcessor::~DelegatingPeerListProcessor() {}

View File

@ -67,11 +67,9 @@ DownloadCommand::DownloadCommand(int cuid,
DownloadEngine* e,
const SocketHandle& s):
AbstractCommand(cuid, req, requestGroup, e, s),
peerStat(0),
#ifdef ENABLE_MESSAGE_DIGEST
_messageDigestContext(0),
_messageDigestContext(0)
#endif // ENABLE_MESSAGE_DIGEST
transferDecoder(0)
{
#ifdef ENABLE_MESSAGE_DIGEST
{
@ -85,7 +83,7 @@ DownloadCommand::DownloadCommand(int cuid,
#endif // ENABLE_MESSAGE_DIGEST
peerStat = _requestGroup->getSegmentMan()->getPeerStat(cuid);
if(peerStat.isNull()) {
peerStat = new PeerStat(cuid);
peerStat.reset(new PeerStat(cuid));
_requestGroup->getSegmentMan()->registerPeerStat(peerStat);
}
peerStat->downloadStart();
@ -175,7 +173,7 @@ void DownloadCommand::checkLowestDownloadSpeed() const
bool DownloadCommand::prepareForNextSegment() {
if(_requestGroup->downloadFinished()) {
#ifdef ENABLE_MESSAGE_DIGEST
CheckIntegrityEntryHandle entry = new ChecksumCheckIntegrityEntry(_requestGroup);
CheckIntegrityEntryHandle entry(new ChecksumCheckIntegrityEntry(_requestGroup));
if(entry->isValidationReady()) {
entry->initValidator();
CheckIntegrityCommand* command =

View File

@ -84,12 +84,8 @@ bool NameResolverEntry::operator==(const NameResolverEntry& entry)
#endif // ENABLE_ASYNC_DNS
DownloadEngine::DownloadEngine():logger(LogFactory::getInstance()),
_statCalc(0),
_haltRequested(false),
noWait(false),
_requestGroupMan(0),
_fileAllocationMan(0),
_checkIntegrityMan(0)
noWait(false)
{}
DownloadEngine::~DownloadEngine() {

View File

@ -72,16 +72,16 @@ DownloadEngineFactory::newDownloadEngine(Option* op,
workingSet = requestGroups;
}
DownloadEngineHandle e = new DownloadEngine();
DownloadEngineHandle e(new DownloadEngine());
e->option = op;
RequestGroupManHandle requestGroupMan =
new RequestGroupMan(workingSet,
op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS));
RequestGroupManHandle
requestGroupMan(new RequestGroupMan(workingSet,
op->getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS)));
requestGroupMan->addReservedGroup(reservedSet);
e->_requestGroupMan = requestGroupMan;
e->_fileAllocationMan = new FileAllocationMan();
e->_fileAllocationMan.reset(new FileAllocationMan());
#ifdef ENABLE_MESSAGE_DIGEST
e->_checkIntegrityMan = new CheckIntegrityMan();
e->_checkIntegrityMan.reset(new CheckIntegrityMan());
#endif // ENABLE_MESSAGE_DIGEST
e->commands.push_back(new FillRequestGroupCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get(), 1));
e->commands.push_back(new FileAllocationDispatcherCommand(CUIDCounterSingletonHolder::instance()->newID(), e.get()));

Some files were not shown because too many files have changed in this diff Show More