mirror of https://github.com/aria2/aria2
2008-02-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Removed "using namespace std;" from all sources. Appended std:: prefix to c++ standard classes. Included string.h where mem* function are used.pull/1/head
parent
d82e183d34
commit
1b7c198289
|
@ -1,3 +1,9 @@
|
||||||
|
2008-02-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
|
Removed "using namespace std;" from all sources. Appended std:: prefix to c++
|
||||||
|
standard classes.
|
||||||
|
Included string.h where mem* function are used.
|
||||||
|
|
||||||
2008-02-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
2008-02-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Create directory before saving DHT routing table.
|
Create directory before saving DHT routing table.
|
||||||
|
|
|
@ -32,29 +32,35 @@
|
||||||
* files in the program, then also delete it here.
|
* files in the program, then also delete it here.
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#ifndef _D_DIRECTORY_H_
|
#include "AbstractAuthResolver.h"
|
||||||
#define _D_DIRECTORY_H_
|
#include "AuthConfig.h"
|
||||||
|
|
||||||
#include "common.h"
|
namespace aria2 {
|
||||||
#include <string>
|
|
||||||
#include <deque>
|
|
||||||
|
|
||||||
class Directory {
|
AbstractAuthResolver::AbstractAuthResolver():
|
||||||
|
_userDefinedAuthConfig(0),
|
||||||
|
_defaultAuthConfig(new AuthConfig()) {}
|
||||||
|
|
||||||
typedef deque<Directory*> Files;
|
AbstractAuthResolver::~AbstractAuthResolver() {}
|
||||||
|
|
||||||
private:
|
void AbstractAuthResolver::setUserDefinedAuthConfig(const AuthConfigHandle& authConfig)
|
||||||
string name;
|
{
|
||||||
Files files;
|
_userDefinedAuthConfig = authConfig;
|
||||||
public:
|
}
|
||||||
Directory(const string& name);
|
|
||||||
Directory();
|
|
||||||
~Directory();
|
|
||||||
|
|
||||||
void createDir(const string& parentDir, bool recursive) const;
|
AuthConfigHandle AbstractAuthResolver::getUserDefinedAuthConfig() const
|
||||||
void addFile(Directory* directory);
|
{
|
||||||
};
|
return _userDefinedAuthConfig;
|
||||||
|
}
|
||||||
|
|
||||||
typedef SharedHandle<Directory> DirectoryHandle;
|
void AbstractAuthResolver::setDefaultAuthConfig(const AuthConfigHandle& authConfig)
|
||||||
|
{
|
||||||
|
_defaultAuthConfig = authConfig;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _D_DIRECTORY_H_
|
AuthConfigHandle AbstractAuthResolver::getDefaultAuthConfig() const
|
||||||
|
{
|
||||||
|
return _defaultAuthConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
|
@ -37,42 +37,31 @@
|
||||||
|
|
||||||
#include "AuthResolver.h"
|
#include "AuthResolver.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class AbstractAuthResolver : public AuthResolver {
|
class AbstractAuthResolver : public AuthResolver {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AuthConfigHandle _userDefinedAuthConfig;
|
SharedHandle<AuthConfig> _userDefinedAuthConfig;
|
||||||
|
|
||||||
AuthConfigHandle _defaultAuthConfig;
|
SharedHandle<AuthConfig> _defaultAuthConfig;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AbstractAuthResolver():_userDefinedAuthConfig(0),
|
AbstractAuthResolver();
|
||||||
_defaultAuthConfig(new AuthConfig())
|
|
||||||
{}
|
|
||||||
|
|
||||||
virtual ~AbstractAuthResolver() {}
|
virtual ~AbstractAuthResolver();
|
||||||
|
|
||||||
void setUserDefinedAuthConfig(const AuthConfigHandle& authConfig)
|
void setUserDefinedAuthConfig(const SharedHandle<AuthConfig>& authConfig);
|
||||||
{
|
|
||||||
_userDefinedAuthConfig = authConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthConfigHandle getUserDefinedAuthConfig() const
|
SharedHandle<AuthConfig> getUserDefinedAuthConfig() const;
|
||||||
{
|
|
||||||
return _userDefinedAuthConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDefaultAuthConfig(const AuthConfigHandle& authConfig)
|
void setDefaultAuthConfig(const SharedHandle<AuthConfig>& authConfig);
|
||||||
{
|
|
||||||
_defaultAuthConfig = authConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthConfigHandle getDefaultAuthConfig() const
|
|
||||||
{
|
|
||||||
return _defaultAuthConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
SharedHandle<AuthConfig> getDefaultAuthConfig() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<AbstractAuthResolver> AbstractAuthResolverHandle;
|
typedef SharedHandle<AbstractAuthResolver> AbstractAuthResolverHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_AUTH_RESOLVER_H_
|
#endif // _D_ABSTRACT_AUTH_RESOLVER_H_
|
||||||
|
|
|
@ -37,19 +37,23 @@
|
||||||
|
|
||||||
#include "BtEventListener.h"
|
#include "BtEventListener.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class AbstractBtEventListener : public BtEventListener {
|
class AbstractBtEventListener : public BtEventListener {
|
||||||
public:
|
public:
|
||||||
virtual ~AbstractBtEventListener() {}
|
virtual ~AbstractBtEventListener() {}
|
||||||
|
|
||||||
virtual bool canHandle(const BtEventHandle& event) = 0;
|
virtual bool canHandle(const SharedHandle<BtEvent>& event) = 0;
|
||||||
|
|
||||||
virtual void handleEventInternal(const BtEventHandle& event) = 0;
|
virtual void handleEventInternal(const SharedHandle<BtEvent>& event) = 0;
|
||||||
|
|
||||||
virtual void handleEvent(const BtEventHandle& event) {
|
virtual void handleEvent(const SharedHandle<BtEvent>& event) {
|
||||||
if(canHandle(event)) {
|
if(canHandle(event)) {
|
||||||
handleEventInternal(event);
|
handleEventInternal(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_BT_EVENT_LISTENER_H_
|
#endif // _D_ABSTRACT_BT_EVENT_LISTENER_H_
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
/* <!-- 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
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* 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 "AbstractBtMessage.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
#include "BtContext.h"
|
||||||
|
#include "PieceStorage.h"
|
||||||
|
#include "BtRegistry.h"
|
||||||
|
#include "BtEventListener.h"
|
||||||
|
#include "BtMessageValidator.h"
|
||||||
|
#include "LogFactory.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
AbstractBtMessage::AbstractBtMessage():sendingInProgress(false),
|
||||||
|
invalidate(false),
|
||||||
|
uploading(false),
|
||||||
|
cuid(0),
|
||||||
|
btContext(0),
|
||||||
|
pieceStorage(0),
|
||||||
|
peer(0),
|
||||||
|
validator(0),
|
||||||
|
logger(LogFactory::getInstance())
|
||||||
|
{}
|
||||||
|
|
||||||
|
AbstractBtMessage::~AbstractBtMessage() {}
|
||||||
|
|
||||||
|
SharedHandle<Peer> AbstractBtMessage::getPeer() const
|
||||||
|
{
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractBtMessage::setPeer(const SharedHandle<Peer>& peer)
|
||||||
|
{
|
||||||
|
this->peer = peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AbstractBtMessage::validate(std::deque<std::string>& errors)
|
||||||
|
{
|
||||||
|
if(validator.get()) {
|
||||||
|
return validator->validate(errors);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractBtMessage::handleEvent(const SharedHandle<BtEvent>& event)
|
||||||
|
{
|
||||||
|
for(std::deque<SharedHandle<BtEventListener> >::iterator itr = listeners.begin();
|
||||||
|
itr != listeners.end(); ++itr) {
|
||||||
|
(*itr)->handleEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AbstractBtMessage::addEventListener(const SharedHandle<BtEventListener>& listener)
|
||||||
|
{
|
||||||
|
listeners.push_back(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
AbstractBtMessage::setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator) {
|
||||||
|
this->validator = validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedHandle<BtMessageValidator> AbstractBtMessage::getBtMessageValidator() const
|
||||||
|
{
|
||||||
|
return validator;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractBtMessage::setBtContext(const SharedHandle<BtContext>& btContext)
|
||||||
|
{
|
||||||
|
this->btContext = btContext;
|
||||||
|
this->pieceStorage = PIECE_STORAGE(btContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedHandle<BtContext> AbstractBtMessage::getBtContext() const
|
||||||
|
{
|
||||||
|
return btContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractBtMessage::setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher)
|
||||||
|
{
|
||||||
|
this->dispatcher = dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractBtMessage::setPeerConnection(const WeakHandle<PeerConnection>& peerConnection)
|
||||||
|
{
|
||||||
|
this->peerConnection = peerConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractBtMessage::setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory)
|
||||||
|
{
|
||||||
|
this->messageFactory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractBtMessage::setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory)
|
||||||
|
{
|
||||||
|
this->requestFactory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
|
@ -36,18 +36,20 @@
|
||||||
#define _D_ABSTRACT_BT_MESSAGE_H_
|
#define _D_ABSTRACT_BT_MESSAGE_H_
|
||||||
|
|
||||||
#include "BtMessage.h"
|
#include "BtMessage.h"
|
||||||
#include "Peer.h"
|
#include <deque>
|
||||||
#include "Piece.h"
|
|
||||||
#include "LogFactory.h"
|
namespace aria2 {
|
||||||
#include "Logger.h"
|
|
||||||
#include "BtEvent.h"
|
class BtContext;
|
||||||
#include "BtEventListener.h"
|
class PieceStorage;
|
||||||
#include "BtContext.h"
|
class Peer;
|
||||||
#include "BtRegistry.h"
|
class BtMessageDispatcher;
|
||||||
#include "BtMessageDispatcher.h"
|
class BtMessageFactory;
|
||||||
#include "PeerConnection.h"
|
class BtRequestFactory;
|
||||||
#include "BtRequestFactory.h"
|
class PeerConnection;
|
||||||
#include "BtMessageFactory.h"
|
class BtMessageValidator;
|
||||||
|
class BtEventListener;
|
||||||
|
class Logger;
|
||||||
|
|
||||||
class AbstractBtMessage : public BtMessage {
|
class AbstractBtMessage : public BtMessage {
|
||||||
protected:
|
protected:
|
||||||
|
@ -56,35 +58,29 @@ protected:
|
||||||
bool uploading;
|
bool uploading;
|
||||||
int32_t cuid;
|
int32_t cuid;
|
||||||
|
|
||||||
BtContextHandle btContext;
|
SharedHandle<BtContext> btContext;
|
||||||
|
|
||||||
PieceStorageHandle pieceStorage;
|
SharedHandle<PieceStorage> pieceStorage;
|
||||||
|
|
||||||
PeerHandle peer;
|
SharedHandle<Peer> peer;
|
||||||
|
|
||||||
BtMessageDispatcherWeakHandle dispatcher;
|
WeakHandle<BtMessageDispatcher> dispatcher;
|
||||||
|
|
||||||
BtMessageFactoryWeakHandle messageFactory;
|
WeakHandle<BtMessageFactory> messageFactory;
|
||||||
|
|
||||||
BtRequestFactoryWeakHandle requestFactory;
|
WeakHandle<BtRequestFactory> requestFactory;
|
||||||
|
|
||||||
PeerConnectionWeakHandle peerConnection;
|
WeakHandle<PeerConnection> peerConnection;
|
||||||
|
|
||||||
|
SharedHandle<BtMessageValidator> validator;
|
||||||
|
|
||||||
|
std::deque<SharedHandle<BtEventListener> > listeners;
|
||||||
|
|
||||||
BtMessageValidatorHandle validator;
|
|
||||||
BtEventListeners listeners;
|
|
||||||
const Logger* logger;
|
const Logger* logger;
|
||||||
public:
|
public:
|
||||||
AbstractBtMessage():sendingInProgress(false),
|
AbstractBtMessage();
|
||||||
invalidate(false),
|
|
||||||
uploading(false),
|
|
||||||
cuid(0),
|
|
||||||
btContext(0),
|
|
||||||
pieceStorage(0),
|
|
||||||
peer(0),
|
|
||||||
validator(0),
|
|
||||||
logger(LogFactory::getInstance())
|
|
||||||
|
|
||||||
{}
|
virtual ~AbstractBtMessage();
|
||||||
|
|
||||||
virtual bool isSendingInProgress() {
|
virtual bool isSendingInProgress() {
|
||||||
return sendingInProgress;
|
return sendingInProgress;
|
||||||
|
@ -118,72 +114,39 @@ public:
|
||||||
this->cuid = cuid;
|
this->cuid = cuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerHandle getPeer() const {
|
SharedHandle<Peer> getPeer() const;
|
||||||
return peer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPeer(const PeerHandle& peer) {
|
void setPeer(const SharedHandle<Peer>& peer);
|
||||||
this->peer = peer;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void doReceivedAction() {}
|
virtual void doReceivedAction() {}
|
||||||
|
|
||||||
virtual bool validate(Errors& errors) {
|
virtual bool validate(std::deque<std::string>& errors);
|
||||||
if(validator.get()) {
|
|
||||||
return validator->validate(errors);
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void onQueued() {}
|
virtual void onQueued() {}
|
||||||
|
|
||||||
virtual void handleEvent(const BtEventHandle& event) {
|
virtual void handleEvent(const SharedHandle<BtEvent>& event);
|
||||||
for(BtEventListeners::iterator itr = listeners.begin();
|
|
||||||
itr != listeners.end(); ++itr) {
|
|
||||||
(*itr)->handleEvent(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addEventListener(const BtEventListenerHandle& listener) {
|
void addEventListener(const SharedHandle<BtEventListener>& listener);
|
||||||
listeners.push_back(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBtMessageValidator(const BtMessageValidatorHandle& validator) {
|
void setBtMessageValidator(const SharedHandle<BtMessageValidator>& validator);
|
||||||
this->validator = validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
BtMessageValidatorHandle getBtMessageValidator() const {
|
SharedHandle<BtMessageValidator> getBtMessageValidator() const;
|
||||||
return validator;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBtContext(const BtContextHandle& btContext) {
|
void setBtContext(const SharedHandle<BtContext>& btContext);
|
||||||
this->btContext = btContext;
|
|
||||||
this->pieceStorage = PIECE_STORAGE(btContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
BtContextHandle getBtContext() const {
|
SharedHandle<BtContext> getBtContext() const;
|
||||||
return btContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBtMessageDispatcher(const BtMessageDispatcherWeakHandle& dispatcher)
|
void setBtMessageDispatcher(const WeakHandle<BtMessageDispatcher>& dispatcher);
|
||||||
{
|
|
||||||
this->dispatcher = dispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPeerConnection(const PeerConnectionWeakHandle& peerConnection) {
|
void setPeerConnection(const WeakHandle<PeerConnection>& peerConnection);
|
||||||
this->peerConnection = peerConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBtMessageFactory(const BtMessageFactoryWeakHandle& factory) {
|
void setBtMessageFactory(const WeakHandle<BtMessageFactory>& factory);
|
||||||
this->messageFactory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBtRequestFactory(const BtRequestFactoryWeakHandle& factory) {
|
void setBtRequestFactory(const WeakHandle<BtRequestFactory>& factory);
|
||||||
this->requestFactory = factory;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<AbstractBtMessage> AbstractBtMessageHandle;
|
typedef SharedHandle<AbstractBtMessage> AbstractBtMessageHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_BT_MESSAGE_H_
|
#endif // _D_ABSTRACT_BT_MESSAGE_H_
|
||||||
|
|
|
@ -33,26 +33,31 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "AbstractCommand.h"
|
#include "AbstractCommand.h"
|
||||||
|
#include "RequestGroup.h"
|
||||||
|
#include "Request.h"
|
||||||
|
#include "DownloadEngine.h"
|
||||||
|
#include "Option.h"
|
||||||
|
#include "PeerStat.h"
|
||||||
#include "SegmentMan.h"
|
#include "SegmentMan.h"
|
||||||
#include "NameResolver.h"
|
#include "Logger.h"
|
||||||
#include "CUIDCounter.h"
|
#include "Segment.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "DlRetryEx.h"
|
#include "DlRetryEx.h"
|
||||||
#include "DownloadFailureException.h"
|
#include "DownloadFailureException.h"
|
||||||
#include "InitiateConnectionCommandFactory.h"
|
#include "InitiateConnectionCommandFactory.h"
|
||||||
#include "Util.h"
|
|
||||||
#include "message.h"
|
|
||||||
#include "SleepCommand.h"
|
#include "SleepCommand.h"
|
||||||
#include "prefs.h"
|
#include "NameResolver.h"
|
||||||
#include "DNSCache.h"
|
#include "DNSCache.h"
|
||||||
#include "StreamCheckIntegrityEntry.h"
|
#include "StreamCheckIntegrityEntry.h"
|
||||||
#include "PeerStat.h"
|
|
||||||
#include "Segment.h"
|
|
||||||
#include "Option.h"
|
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
|
#include "Socket.h"
|
||||||
|
#include "message.h"
|
||||||
|
#include "prefs.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
AbstractCommand::AbstractCommand(int32_t cuid,
|
AbstractCommand::AbstractCommand(int32_t cuid,
|
||||||
const RequestHandle& req,
|
const SharedHandle<Request>& req,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const SocketHandle& s):
|
const SocketHandle& s):
|
||||||
|
@ -66,6 +71,20 @@ AbstractCommand::AbstractCommand(int32_t cuid,
|
||||||
_requestGroup->increaseStreamConnection();
|
_requestGroup->increaseStreamConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AbstractCommand::AbstractCommand(int32_t cuid,
|
||||||
|
const SharedHandle<Request>& req,
|
||||||
|
RequestGroup* requestGroup,
|
||||||
|
DownloadEngine* e):
|
||||||
|
Command(cuid), RequestGroupAware(requestGroup),
|
||||||
|
req(req), e(e), socket(new SocketCore()),
|
||||||
|
checkSocketIsReadable(false), checkSocketIsWritable(false),
|
||||||
|
nameResolverCheck(false)
|
||||||
|
{
|
||||||
|
setReadCheckSocket(socket);
|
||||||
|
timeout = this->e->option->getAsInt(PREF_TIMEOUT);
|
||||||
|
_requestGroup->increaseStreamConnection();
|
||||||
|
}
|
||||||
|
|
||||||
AbstractCommand::~AbstractCommand() {
|
AbstractCommand::~AbstractCommand() {
|
||||||
disableReadCheckSocket();
|
disableReadCheckSocket();
|
||||||
disableWriteCheckSocket();
|
disableWriteCheckSocket();
|
||||||
|
@ -239,9 +258,9 @@ void AbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AbstractCommand::resolveHostname(const string& hostname,
|
bool AbstractCommand::resolveHostname(const std::string& hostname,
|
||||||
const NameResolverHandle& resolver) {
|
const NameResolverHandle& resolver) {
|
||||||
string ipaddr = DNSCacheSingletonHolder::instance()->find(hostname);
|
std::string ipaddr = DNSCacheSingletonHolder::instance()->find(hostname);
|
||||||
if(ipaddr.empty()) {
|
if(ipaddr.empty()) {
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
switch(resolver->getStatus()) {
|
switch(resolver->getStatus()) {
|
||||||
|
@ -301,3 +320,5 @@ void AbstractCommand::prepareForNextAction(Command* nextCommand)
|
||||||
new StreamCheckIntegrityEntry(req, _requestGroup, nextCommand);
|
new StreamCheckIntegrityEntry(req, _requestGroup, nextCommand);
|
||||||
e->addCommand(_requestGroup->processCheckIntegrityEntry(entry, e));
|
e->addCommand(_requestGroup->processCheckIntegrityEntry(entry, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,44 +36,44 @@
|
||||||
#define _D_ABSTRACT_COMMAND_H_
|
#define _D_ABSTRACT_COMMAND_H_
|
||||||
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
#include "SharedHandle.h"
|
||||||
#include "TimeA2.h"
|
#include "TimeA2.h"
|
||||||
#include "RequestGroupAware.h"
|
#include "RequestGroupAware.h"
|
||||||
#include "Socket.h"
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class Request;
|
class Request;
|
||||||
typedef SharedHandle<Request> RequestHandle;
|
|
||||||
class DownloadEngine;
|
class DownloadEngine;
|
||||||
|
class RequestGroup;
|
||||||
class Segment;
|
class Segment;
|
||||||
typedef SharedHandle<Segment> SegmentHandle;
|
|
||||||
typedef deque<SegmentHandle> Segments;
|
|
||||||
class NameResolver;
|
class NameResolver;
|
||||||
typedef SharedHandle<NameResolver> NameResolverHandle;
|
class Exception;
|
||||||
class BtProgressInfoFile;
|
class SocketCore;
|
||||||
typedef SharedHandle<BtProgressInfoFile> BtProgressInfoFileHandle;
|
|
||||||
|
|
||||||
class AbstractCommand : public Command, public RequestGroupAware {
|
class AbstractCommand : public Command, public RequestGroupAware {
|
||||||
private:
|
private:
|
||||||
Time checkPoint;
|
Time checkPoint;
|
||||||
int32_t timeout;
|
int32_t timeout;
|
||||||
protected:
|
protected:
|
||||||
RequestHandle req;
|
SharedHandle<Request> req;
|
||||||
DownloadEngine* e;
|
DownloadEngine* e;
|
||||||
SocketHandle socket;
|
SharedHandle<SocketCore> socket;
|
||||||
Segments _segments;
|
std::deque<SharedHandle<Segment> > _segments;
|
||||||
|
|
||||||
void tryReserved();
|
void tryReserved();
|
||||||
virtual bool prepareForRetry(int32_t wait);
|
virtual bool prepareForRetry(int32_t wait);
|
||||||
virtual void onAbort(Exception* ex);
|
virtual void onAbort(Exception* ex);
|
||||||
virtual bool executeInternal() = 0;
|
virtual bool executeInternal() = 0;
|
||||||
|
|
||||||
void setReadCheckSocket(const SocketHandle& socket);
|
void setReadCheckSocket(const SharedHandle<SocketCore>& socket);
|
||||||
void setWriteCheckSocket(const SocketHandle& socket);
|
void setWriteCheckSocket(const SharedHandle<SocketCore>& socket);
|
||||||
void disableReadCheckSocket();
|
void disableReadCheckSocket();
|
||||||
void disableWriteCheckSocket();
|
void disableWriteCheckSocket();
|
||||||
bool resolveHostname(const string& hostname, const NameResolverHandle& nameResolver);
|
bool resolveHostname(const std::string& hostname,
|
||||||
|
const SharedHandle<NameResolver>& nameResolver);
|
||||||
#ifdef ENABLE_ASYNC_DNS
|
#ifdef ENABLE_ASYNC_DNS
|
||||||
void setNameResolverCheck(const NameResolverHandle& resolver);
|
void setNameResolverCheck(const SharedHandle<NameResolver>& resolver);
|
||||||
void disableNameResolverCheck(const NameResolverHandle& resolver);
|
void disableNameResolverCheck(const SharedHandle<NameResolver>& resolver);
|
||||||
virtual bool nameResolveFinished() const;
|
virtual bool nameResolveFinished() const;
|
||||||
#endif // ENABLE_ASYNC_DNS
|
#endif // ENABLE_ASYNC_DNS
|
||||||
void setTimeout(int32_t timeout) { this->timeout = timeout; }
|
void setTimeout(int32_t timeout) { this->timeout = timeout; }
|
||||||
|
@ -83,14 +83,22 @@ protected:
|
||||||
private:
|
private:
|
||||||
bool checkSocketIsReadable;
|
bool checkSocketIsReadable;
|
||||||
bool checkSocketIsWritable;
|
bool checkSocketIsWritable;
|
||||||
SocketHandle readCheckTarget;
|
SharedHandle<SocketCore> readCheckTarget;
|
||||||
SocketHandle writeCheckTarget;
|
SharedHandle<SocketCore> writeCheckTarget;
|
||||||
bool nameResolverCheck;
|
bool nameResolverCheck;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AbstractCommand(int32_t cuid, const RequestHandle& req, RequestGroup* requestGroup, DownloadEngine* e, const SocketHandle& s = SocketHandle());
|
AbstractCommand(int32_t cuid, const SharedHandle<Request>& req,
|
||||||
|
RequestGroup* requestGroup, DownloadEngine* e,
|
||||||
|
const SharedHandle<SocketCore>& s);
|
||||||
|
|
||||||
|
AbstractCommand(int32_t cuid, const SharedHandle<Request>& req,
|
||||||
|
RequestGroup* requestGroup, DownloadEngine* e);
|
||||||
|
|
||||||
virtual ~AbstractCommand();
|
virtual ~AbstractCommand();
|
||||||
bool execute();
|
bool execute();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_COMMAND_H_
|
#endif // _D_ABSTRACT_COMMAND_H_
|
||||||
|
|
|
@ -37,13 +37,13 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "a2io.h"
|
#include "Logger.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include <unistd.h>
|
#include "a2io.h"
|
||||||
#include <sys/types.h>
|
#include <cerrno>
|
||||||
#include <sys/stat.h>
|
#include <cassert>
|
||||||
#include <errno.h>
|
|
||||||
#include <fcntl.h>
|
namespace aria2 {
|
||||||
|
|
||||||
AbstractDiskWriter::AbstractDiskWriter():
|
AbstractDiskWriter::AbstractDiskWriter():
|
||||||
fd(-1),
|
fd(-1),
|
||||||
|
@ -54,7 +54,7 @@ AbstractDiskWriter::~AbstractDiskWriter()
|
||||||
closeFile();
|
closeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::openFile(const string& filename, int64_t totalLength)
|
void AbstractDiskWriter::openFile(const std::string& filename, int64_t totalLength)
|
||||||
{
|
{
|
||||||
File f(filename);
|
File f(filename);
|
||||||
if(f.exists()) {
|
if(f.exists()) {
|
||||||
|
@ -72,7 +72,7 @@ void AbstractDiskWriter::closeFile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::openExistingFile(const string& filename,
|
void AbstractDiskWriter::openExistingFile(const std::string& filename,
|
||||||
int64_t totalLength)
|
int64_t totalLength)
|
||||||
{
|
{
|
||||||
this->filename = filename;
|
this->filename = filename;
|
||||||
|
@ -86,7 +86,7 @@ void AbstractDiskWriter::openExistingFile(const string& filename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractDiskWriter::createFile(const string& filename, int32_t addFlags)
|
void AbstractDiskWriter::createFile(const std::string& filename, int32_t addFlags)
|
||||||
{
|
{
|
||||||
this->filename = filename;
|
this->filename = filename;
|
||||||
assert(filename.size());
|
assert(filename.size());
|
||||||
|
@ -182,3 +182,5 @@ void AbstractDiskWriter::disableDirectIO()
|
||||||
while(fcntl(fd, F_SETFL, flg&(~O_DIRECT)) == -1 && errno == EINTR);
|
while(fcntl(fd, F_SETFL, flg&(~O_DIRECT)) == -1 && errno == EINTR);
|
||||||
#endif // ENABLE_DIRECT_IO
|
#endif // ENABLE_DIRECT_IO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,15 +36,19 @@
|
||||||
#define _D_ABSTRACT_DISK_WRITER_H_
|
#define _D_ABSTRACT_DISK_WRITER_H_
|
||||||
|
|
||||||
#include "DiskWriter.h"
|
#include "DiskWriter.h"
|
||||||
#include "Logger.h"
|
#include <string>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class Logger;
|
||||||
|
|
||||||
class AbstractDiskWriter : public DiskWriter {
|
class AbstractDiskWriter : public DiskWriter {
|
||||||
protected:
|
protected:
|
||||||
string filename;
|
std::string filename;
|
||||||
int32_t fd;
|
int32_t fd;
|
||||||
const Logger* logger;
|
const Logger* logger;
|
||||||
|
|
||||||
void createFile(const string& filename, int32_t addFlags = 0);
|
void createFile(const std::string& filename, int32_t addFlags = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32_t writeDataInternal(const unsigned char* data, int32_t len);
|
int32_t writeDataInternal(const unsigned char* data, int32_t len);
|
||||||
|
@ -56,11 +60,11 @@ public:
|
||||||
AbstractDiskWriter();
|
AbstractDiskWriter();
|
||||||
virtual ~AbstractDiskWriter();
|
virtual ~AbstractDiskWriter();
|
||||||
|
|
||||||
virtual void openFile(const string& filename, int64_t totalLength = 0);
|
virtual void openFile(const std::string& filename, int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void closeFile();
|
virtual void closeFile();
|
||||||
|
|
||||||
virtual void openExistingFile(const string& filename, int64_t totalLength = 0);
|
virtual void openExistingFile(const std::string& filename, int64_t totalLength = 0);
|
||||||
|
|
||||||
virtual void writeData(const unsigned char* data, int32_t len, int64_t offset);
|
virtual void writeData(const unsigned char* data, int32_t len, int64_t offset);
|
||||||
|
|
||||||
|
@ -75,4 +79,6 @@ public:
|
||||||
virtual void disableDirectIO();
|
virtual void disableDirectIO();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_DISK_WRITER_H_
|
#endif // _D_ABSTRACT_DISK_WRITER_H_
|
||||||
|
|
|
@ -37,7 +37,13 @@
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
#include "HttpConnection.h"
|
#include "HttpConnection.h"
|
||||||
|
#include "HttpRequest.h"
|
||||||
|
#include "Segment.h"
|
||||||
|
#include "Option.h"
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
|
#include "Socket.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
AbstractProxyRequestCommand::AbstractProxyRequestCommand(int cuid,
|
AbstractProxyRequestCommand::AbstractProxyRequestCommand(int cuid,
|
||||||
const RequestHandle& req,
|
const RequestHandle& req,
|
||||||
|
@ -66,3 +72,5 @@ bool AbstractProxyRequestCommand::executeInternal() {
|
||||||
e->commands.push_back(getNextCommand());
|
e->commands.push_back(getNextCommand());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,23 +37,27 @@
|
||||||
|
|
||||||
#include "AbstractCommand.h"
|
#include "AbstractCommand.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class HttpConnection;
|
class HttpConnection;
|
||||||
typedef SharedHandle<HttpConnection> HttpConnectionHandle;
|
class SocketCore;
|
||||||
|
|
||||||
class AbstractProxyRequestCommand : public AbstractCommand {
|
class AbstractProxyRequestCommand : public AbstractCommand {
|
||||||
protected:
|
protected:
|
||||||
HttpConnectionHandle httpConnection;
|
SharedHandle<HttpConnection> httpConnection;
|
||||||
|
|
||||||
virtual bool executeInternal();
|
virtual bool executeInternal();
|
||||||
public:
|
public:
|
||||||
AbstractProxyRequestCommand(int cuid,
|
AbstractProxyRequestCommand(int cuid,
|
||||||
const RequestHandle& req,
|
const SharedHandle<Request>& req,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const SocketHandle& s);
|
const SharedHandle<SocketCore>& s);
|
||||||
virtual ~AbstractProxyRequestCommand();
|
virtual ~AbstractProxyRequestCommand();
|
||||||
|
|
||||||
virtual Command* getNextCommand() = 0;
|
virtual Command* getNextCommand() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_PROXY_REQUEST_COMMAND_H_
|
#endif // _D_ABSTRACT_PROXY_REQUEST_COMMAND_H_
|
||||||
|
|
|
@ -35,13 +35,18 @@
|
||||||
#include "AbstractProxyResponseCommand.h"
|
#include "AbstractProxyResponseCommand.h"
|
||||||
#include "HttpConnection.h"
|
#include "HttpConnection.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
|
#include "Segment.h"
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
|
#include "HttpRequest.h"
|
||||||
#include "HttpResponse.h"
|
#include "HttpResponse.h"
|
||||||
#include "HttpRequestCommand.h"
|
#include "HttpRequestCommand.h"
|
||||||
|
#include "Socket.h"
|
||||||
#include "DlRetryEx.h"
|
#include "DlRetryEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
AbstractProxyResponseCommand::AbstractProxyResponseCommand(int cuid,
|
AbstractProxyResponseCommand::AbstractProxyResponseCommand(int cuid,
|
||||||
const RequestHandle& req,
|
const RequestHandle& req,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
|
@ -66,3 +71,5 @@ bool AbstractProxyResponseCommand::executeInternal() {
|
||||||
e->commands.push_back(getNextCommand());
|
e->commands.push_back(getNextCommand());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,24 +37,28 @@
|
||||||
|
|
||||||
#include "AbstractCommand.h"
|
#include "AbstractCommand.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class HttpConnection;
|
class HttpConnection;
|
||||||
typedef SharedHandle<HttpConnection> HttpConnectionHandle;
|
class SocketCore;
|
||||||
|
|
||||||
class AbstractProxyResponseCommand : public AbstractCommand {
|
class AbstractProxyResponseCommand : public AbstractCommand {
|
||||||
protected:
|
protected:
|
||||||
HttpConnectionHandle httpConnection;
|
SharedHandle<HttpConnection> httpConnection;
|
||||||
|
|
||||||
virtual bool executeInternal();
|
virtual bool executeInternal();
|
||||||
public:
|
public:
|
||||||
AbstractProxyResponseCommand(int cuid,
|
AbstractProxyResponseCommand(int cuid,
|
||||||
const RequestHandle& req,
|
const SharedHandle<Request>& req,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
const HttpConnectionHandle& httpConnection,
|
const SharedHandle<HttpConnection>& httpConnection,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const SocketHandle& s);
|
const SharedHandle<SocketCore>& s);
|
||||||
virtual ~AbstractProxyResponseCommand();
|
virtual ~AbstractProxyResponseCommand();
|
||||||
|
|
||||||
virtual Command* getNextCommand() = 0;
|
virtual Command* getNextCommand() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_PROXY_RESPONSE_COMMAND_H_
|
#endif // _D_ABSTRACT_PROXY_RESPONSE_COMMAND_H_
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
|
|
||||||
#include "SegmentManFactory.h"
|
#include "SegmentManFactory.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class Option;
|
||||||
|
|
||||||
class AbstractSegmentManFactory : public SegmentManFactory {
|
class AbstractSegmentManFactory : public SegmentManFactory {
|
||||||
protected:
|
protected:
|
||||||
const Option* _option;
|
const Option* _option;
|
||||||
|
@ -48,4 +52,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<AbstractSegmentManFactory> AbstractSegmentManFactoryHandle;
|
typedef SharedHandle<AbstractSegmentManFactory> AbstractSegmentManFactoryHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_SEGMENT_MAN_FACTORY_H_
|
#endif // _D_ABSTRACT_SEGMENT_MAN_FACTORY_H_
|
||||||
|
|
|
@ -35,6 +35,15 @@
|
||||||
#include "AbstractSingleDiskAdaptor.h"
|
#include "AbstractSingleDiskAdaptor.h"
|
||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "SingleFileAllocationIterator.h"
|
#include "SingleFileAllocationIterator.h"
|
||||||
|
#include "DiskWriter.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
AbstractSingleDiskAdaptor::AbstractSingleDiskAdaptor():
|
||||||
|
diskWriter(0),
|
||||||
|
totalLength(0) {}
|
||||||
|
|
||||||
|
AbstractSingleDiskAdaptor::~AbstractSingleDiskAdaptor() {}
|
||||||
|
|
||||||
void AbstractSingleDiskAdaptor::initAndOpenFile()
|
void AbstractSingleDiskAdaptor::initAndOpenFile()
|
||||||
{
|
{
|
||||||
|
@ -71,12 +80,20 @@ bool AbstractSingleDiskAdaptor::fileExists()
|
||||||
return File(getFilePath()).exists();
|
return File(getFilePath()).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t AbstractSingleDiskAdaptor::size() const
|
||||||
|
{
|
||||||
|
return diskWriter->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractSingleDiskAdaptor::truncate(int64_t length)
|
||||||
|
{
|
||||||
|
diskWriter->truncate(length);
|
||||||
|
}
|
||||||
|
|
||||||
FileAllocationIteratorHandle AbstractSingleDiskAdaptor::fileAllocationIterator()
|
FileAllocationIteratorHandle AbstractSingleDiskAdaptor::fileAllocationIterator()
|
||||||
{
|
{
|
||||||
SingleFileAllocationIteratorHandle h =
|
SingleFileAllocationIteratorHandle h =
|
||||||
new SingleFileAllocationIterator(this,
|
new SingleFileAllocationIterator(this, size(), totalLength);
|
||||||
size(),
|
|
||||||
totalLength);
|
|
||||||
h->init();
|
h->init();
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
@ -90,3 +107,30 @@ void AbstractSingleDiskAdaptor::disableDirectIO()
|
||||||
{
|
{
|
||||||
diskWriter->disableDirectIO();
|
diskWriter->disableDirectIO();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AbstractSingleDiskAdaptor::directIOAllowed() const
|
||||||
|
{
|
||||||
|
return diskWriter->directIOAllowed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractSingleDiskAdaptor::setDiskWriter(const DiskWriterHandle& diskWriter)
|
||||||
|
{
|
||||||
|
this->diskWriter = diskWriter;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiskWriterHandle AbstractSingleDiskAdaptor::getDiskWriter() const
|
||||||
|
{
|
||||||
|
return diskWriter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractSingleDiskAdaptor::setTotalLength(const int64_t& totalLength)
|
||||||
|
{
|
||||||
|
this->totalLength = totalLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t AbstractSingleDiskAdaptor::getTotalLength() const
|
||||||
|
{
|
||||||
|
return totalLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,16 +36,20 @@
|
||||||
#define _D_ABSTRACT_SINGLE_DISK_ADAPTOR_H_
|
#define _D_ABSTRACT_SINGLE_DISK_ADAPTOR_H_
|
||||||
|
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
#include "DiskWriter.h"
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class DiskWriter;
|
||||||
|
class FileAllocationIterator;
|
||||||
|
|
||||||
class AbstractSingleDiskAdaptor : public DiskAdaptor {
|
class AbstractSingleDiskAdaptor : public DiskAdaptor {
|
||||||
protected:
|
protected:
|
||||||
DiskWriterHandle diskWriter;
|
SharedHandle<DiskWriter> diskWriter;
|
||||||
int64_t totalLength;
|
int64_t totalLength;
|
||||||
public:
|
public:
|
||||||
AbstractSingleDiskAdaptor():diskWriter(0), totalLength(0) {}
|
AbstractSingleDiskAdaptor();
|
||||||
|
|
||||||
virtual ~AbstractSingleDiskAdaptor() {}
|
virtual ~AbstractSingleDiskAdaptor();
|
||||||
|
|
||||||
virtual void initAndOpenFile();
|
virtual void initAndOpenFile();
|
||||||
|
|
||||||
|
@ -62,38 +66,27 @@ public:
|
||||||
|
|
||||||
virtual bool fileExists();
|
virtual bool fileExists();
|
||||||
|
|
||||||
virtual int64_t size() const
|
virtual int64_t size() const;
|
||||||
{
|
|
||||||
return diskWriter->size();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void truncate(int64_t length)
|
virtual void truncate(int64_t length);
|
||||||
{
|
|
||||||
diskWriter->truncate(length);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual FileAllocationIteratorHandle fileAllocationIterator();
|
virtual SharedHandle<FileAllocationIterator> fileAllocationIterator();
|
||||||
|
|
||||||
virtual void enableDirectIO();
|
virtual void enableDirectIO();
|
||||||
|
|
||||||
virtual void disableDirectIO();
|
virtual void disableDirectIO();
|
||||||
|
|
||||||
virtual bool directIOAllowed() const
|
virtual bool directIOAllowed() const;
|
||||||
{
|
|
||||||
return diskWriter->directIOAllowed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDiskWriter(const DiskWriterHandle diskWriter) {
|
void setDiskWriter(const SharedHandle<DiskWriter>& diskWriter);
|
||||||
this->diskWriter = diskWriter;
|
|
||||||
}
|
|
||||||
|
|
||||||
DiskWriterHandle getDiskWriter() const { return diskWriter; }
|
SharedHandle<DiskWriter> getDiskWriter() const;
|
||||||
|
|
||||||
void setTotalLength(const int64_t& totalLength) {
|
void setTotalLength(const int64_t& totalLength);
|
||||||
this->totalLength = totalLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t getTotalLength() const { return totalLength; }
|
int64_t getTotalLength() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ABSTRACT_SINGLE_DISK_ADAPTOR_H_
|
#endif // _D_ABSTRACT_SINGLE_DISK_ADAPTOR_H_
|
||||||
|
|
|
@ -36,6 +36,15 @@
|
||||||
#include "PeerInitiateConnectionCommand.h"
|
#include "PeerInitiateConnectionCommand.h"
|
||||||
#include "CUIDCounter.h"
|
#include "CUIDCounter.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "DownloadEngine.h"
|
||||||
|
#include "BtContext.h"
|
||||||
|
#include "PeerStorage.h"
|
||||||
|
#include "PieceStorage.h"
|
||||||
|
#include "BtRuntime.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
|
ActivePeerConnectionCommand::ActivePeerConnectionCommand(int cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
|
@ -84,3 +93,5 @@ void ActivePeerConnectionCommand::connectToPeer(const PeerHandle& peer)
|
||||||
logger->info(MSG_CONNECTING_TO_PEER,
|
logger->info(MSG_CONNECTING_TO_PEER,
|
||||||
cuid, peer->ipaddr.c_str());
|
cuid, peer->ipaddr.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,9 +37,13 @@
|
||||||
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "BtContextAwareCommand.h"
|
#include "BtContextAwareCommand.h"
|
||||||
#include "DownloadEngine.h"
|
|
||||||
#include "TimeA2.h"
|
|
||||||
#include "RequestGroupAware.h"
|
#include "RequestGroupAware.h"
|
||||||
|
#include "TimeA2.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class DownloadEngine;
|
||||||
|
class Peer;
|
||||||
|
|
||||||
class ActivePeerConnectionCommand : public Command,
|
class ActivePeerConnectionCommand : public Command,
|
||||||
public BtContextAwareCommand,
|
public BtContextAwareCommand,
|
||||||
|
@ -55,14 +59,14 @@ public:
|
||||||
ActivePeerConnectionCommand(int cuid,
|
ActivePeerConnectionCommand(int cuid,
|
||||||
RequestGroup* requestGroup,
|
RequestGroup* requestGroup,
|
||||||
DownloadEngine* e,
|
DownloadEngine* e,
|
||||||
const BtContextHandle& btContext,
|
const SharedHandle<BtContext>& btContext,
|
||||||
int32_t interval);
|
int32_t interval);
|
||||||
|
|
||||||
virtual ~ActivePeerConnectionCommand();
|
virtual ~ActivePeerConnectionCommand();
|
||||||
|
|
||||||
virtual bool execute();
|
virtual bool execute();
|
||||||
|
|
||||||
void connectToPeer(const PeerHandle& peer);
|
void connectToPeer(const SharedHandle<Peer>& peer);
|
||||||
|
|
||||||
void setLowestSpeedLimit(int32_t speed)
|
void setLowestSpeedLimit(int32_t speed)
|
||||||
{
|
{
|
||||||
|
@ -75,4 +79,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ACTIVE_PEER_CONNECTION_COMMAND_H_
|
#endif // _D_ACTIVE_PEER_CONNECTION_COMMAND_H_
|
||||||
|
|
|
@ -38,17 +38,19 @@
|
||||||
#include "NumberDecorator.h"
|
#include "NumberDecorator.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class AlphaNumberDecorator : public NumberDecorator
|
class AlphaNumberDecorator : public NumberDecorator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int32_t _width;
|
int32_t _width;
|
||||||
|
|
||||||
string _zero;
|
std::string _zero;
|
||||||
|
|
||||||
string widen(const string& s, int32_t width)
|
std::string widen(const std::string& s, int32_t width)
|
||||||
{
|
{
|
||||||
string t = s;
|
std::string t = s;
|
||||||
while(t.size() < (size_t)width) {
|
while(t.size() < (size_t)width) {
|
||||||
t.insert(0, _zero);
|
t.insert(0, _zero);
|
||||||
}
|
}
|
||||||
|
@ -61,7 +63,7 @@ public:
|
||||||
|
|
||||||
virtual ~AlphaNumberDecorator() {}
|
virtual ~AlphaNumberDecorator() {}
|
||||||
|
|
||||||
virtual string decorate(int32_t number)
|
virtual std::string decorate(int32_t number)
|
||||||
{
|
{
|
||||||
if(number < 0) {
|
if(number < 0) {
|
||||||
throw new DlAbortEx("The number must be greater than 0.");
|
throw new DlAbortEx("The number must be greater than 0.");
|
||||||
|
@ -70,15 +72,17 @@ public:
|
||||||
return widen(_zero, _width);
|
return widen(_zero, _width);
|
||||||
}
|
}
|
||||||
int32_t base = 26;
|
int32_t base = 26;
|
||||||
string x;
|
std::string x;
|
||||||
while(number > 0) {
|
while(number > 0) {
|
||||||
int32_t r = number%base;
|
int32_t r = number%base;
|
||||||
char alpha = _zero[0]+r;
|
char alpha = _zero[0]+r;
|
||||||
x.insert(0, string(1, alpha));
|
x.insert(0, std::string(1, alpha));
|
||||||
number /= base;
|
number /= base;
|
||||||
}
|
}
|
||||||
return widen(x, _width);
|
return widen(x, _width);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ALPHA_NUMBER_DECORATOR_H_
|
#endif // _D_ALPHA_NUMBER_DECORATOR_H_
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
#include "AnnounceList.h"
|
#include "AnnounceList.h"
|
||||||
#include "List.h"
|
#include "List.h"
|
||||||
#include "Data.h"
|
#include "Data.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
AnnounceList::AnnounceList(const MetaEntry* announceListEntry):
|
AnnounceList::AnnounceList(const MetaEntry* announceListEntry):
|
||||||
currentTrackerInitialized(false) {
|
currentTrackerInitialized(false) {
|
||||||
|
@ -49,14 +52,14 @@ AnnounceList::AnnounceList(const AnnounceTiers& announceTiers):
|
||||||
void AnnounceList::reconfigure(const MetaEntry* announceListEntry) {
|
void AnnounceList::reconfigure(const MetaEntry* announceListEntry) {
|
||||||
const List* l = dynamic_cast<const List*>(announceListEntry);
|
const List* l = dynamic_cast<const List*>(announceListEntry);
|
||||||
if(l) {
|
if(l) {
|
||||||
for(MetaList::const_iterator itr = l->getList().begin();
|
for(std::deque<MetaEntry*>::const_iterator itr = l->getList().begin();
|
||||||
itr != l->getList().end(); itr++) {
|
itr != l->getList().end(); itr++) {
|
||||||
const List* elem = dynamic_cast<const List*>(*itr);
|
const List* elem = dynamic_cast<const List*>(*itr);
|
||||||
if(!elem) {
|
if(!elem) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Strings urls;
|
std::deque<std::string> urls;
|
||||||
for(MetaList::const_iterator elemItr = elem->getList().begin();
|
for(std::deque<MetaEntry*>::const_iterator elemItr = elem->getList().begin();
|
||||||
elemItr != elem->getList().end(); elemItr++) {
|
elemItr != elem->getList().end(); elemItr++) {
|
||||||
const Data* data = dynamic_cast<const Data*>(*elemItr);
|
const Data* data = dynamic_cast<const Data*>(*elemItr);
|
||||||
if(data) {
|
if(data) {
|
||||||
|
@ -72,8 +75,8 @@ void AnnounceList::reconfigure(const MetaEntry* announceListEntry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnnounceList::reconfigure(const string& url) {
|
void AnnounceList::reconfigure(const std::string& url) {
|
||||||
Strings urls;
|
std::deque<std::string> urls;
|
||||||
urls.push_back(url);
|
urls.push_back(url);
|
||||||
tiers.push_back(AnnounceTierHandle(new AnnounceTier(urls)));
|
tiers.push_back(AnnounceTierHandle(new AnnounceTier(urls)));
|
||||||
resetIterator();
|
resetIterator();
|
||||||
|
@ -89,7 +92,7 @@ void AnnounceList::resetIterator() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string AnnounceList::getAnnounce() const {
|
std::string AnnounceList::getAnnounce() const {
|
||||||
if(currentTrackerInitialized) {
|
if(currentTrackerInitialized) {
|
||||||
return *currentTracker;
|
return *currentTracker;
|
||||||
} else {
|
} else {
|
||||||
|
@ -100,7 +103,7 @@ string AnnounceList::getAnnounce() const {
|
||||||
void AnnounceList::announceSuccess() {
|
void AnnounceList::announceSuccess() {
|
||||||
if(currentTrackerInitialized) {
|
if(currentTrackerInitialized) {
|
||||||
(*currentTier)->nextEvent();
|
(*currentTier)->nextEvent();
|
||||||
string url = *currentTracker;
|
std::string url = *currentTracker;
|
||||||
(*currentTier)->urls.erase(currentTracker);
|
(*currentTier)->urls.erase(currentTracker);
|
||||||
(*currentTier)->urls.push_front(url);
|
(*currentTier)->urls.push_front(url);
|
||||||
currentTier = tiers.begin();
|
currentTier = tiers.begin();
|
||||||
|
@ -138,7 +141,7 @@ void AnnounceList::setEvent(AnnounceTier::AnnounceEvent event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string AnnounceList::getEventString() const {
|
std::string AnnounceList::getEventString() const {
|
||||||
if(currentTrackerInitialized) {
|
if(currentTrackerInitialized) {
|
||||||
switch((*currentTier)->event) {
|
switch((*currentTier)->event) {
|
||||||
case AnnounceTier::STARTED:
|
case AnnounceTier::STARTED:
|
||||||
|
@ -203,10 +206,9 @@ template<class InputIterator, class Predicate>
|
||||||
InputIterator
|
InputIterator
|
||||||
find_wrap_if(InputIterator first, InputIterator last,
|
find_wrap_if(InputIterator first, InputIterator last,
|
||||||
InputIterator current, Predicate pred) {
|
InputIterator current, Predicate pred) {
|
||||||
InputIterator itr = find_if(current, last,
|
InputIterator itr = std::find_if(current, last, pred);
|
||||||
pred);
|
|
||||||
if(itr == last) {
|
if(itr == last) {
|
||||||
itr = find_if(first, current, pred);
|
itr = std::find_if(first, current, pred);
|
||||||
}
|
}
|
||||||
return itr;
|
return itr;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +230,7 @@ void AnnounceList::moveToCompletedAllowedTier() {
|
||||||
void AnnounceList::shuffle() {
|
void AnnounceList::shuffle() {
|
||||||
for(AnnounceTiers::iterator itr = tiers.begin();
|
for(AnnounceTiers::iterator itr = tiers.begin();
|
||||||
itr != tiers.end(); itr++) {
|
itr != tiers.end(); itr++) {
|
||||||
Strings& urls = (*itr)->urls;
|
std::deque<std::string>& urls = (*itr)->urls;
|
||||||
random_shuffle(urls.begin(), urls.end());
|
random_shuffle(urls.begin(), urls.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,3 +262,5 @@ bool AnnounceList::currentTierAcceptsCompletedEvent() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,26 +36,30 @@
|
||||||
#define _D_ANNOUNCE_LIST_H_
|
#define _D_ANNOUNCE_LIST_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "MetaEntry.h"
|
#include "SharedHandle.h"
|
||||||
#include "AnnounceTier.h"
|
#include "AnnounceTier.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class MetaEntry;
|
||||||
|
|
||||||
class AnnounceList {
|
class AnnounceList {
|
||||||
public:
|
public:
|
||||||
private:
|
private:
|
||||||
AnnounceTiers tiers;
|
std::deque<SharedHandle<AnnounceTier> > tiers;
|
||||||
AnnounceTiers::iterator currentTier;
|
std::deque<SharedHandle<AnnounceTier> >::iterator currentTier;
|
||||||
Strings::iterator currentTracker;
|
std::deque<std::string>::iterator currentTracker;
|
||||||
bool currentTrackerInitialized;
|
bool currentTrackerInitialized;
|
||||||
|
|
||||||
void resetIterator();
|
void resetIterator();
|
||||||
void setCurrentTier(const AnnounceTiers::iterator& itr);
|
void setCurrentTier(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
|
||||||
public:
|
public:
|
||||||
AnnounceList():currentTrackerInitialized(false) {}
|
AnnounceList():currentTrackerInitialized(false) {}
|
||||||
AnnounceList(const MetaEntry* announceListEntry);
|
AnnounceList(const MetaEntry* announceListEntry);
|
||||||
AnnounceList(const AnnounceTiers& tiers);
|
AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
|
||||||
|
|
||||||
void reconfigure(const MetaEntry* announceListEntry);
|
void reconfigure(const MetaEntry* announceListEntry);
|
||||||
void reconfigure(const string& url);
|
void reconfigure(const std::string& url);
|
||||||
|
|
||||||
int32_t countTier() const {
|
int32_t countTier() const {
|
||||||
return tiers.size();
|
return tiers.size();
|
||||||
|
@ -69,12 +73,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns announce URL.
|
* Returns announce URL.
|
||||||
*/
|
*/
|
||||||
string getAnnounce() const;
|
std::string getAnnounce() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns announce event, such as started, stopped, completed, etc.
|
* Returns announce event, such as started, stopped, completed, etc.
|
||||||
*/
|
*/
|
||||||
string getEventString() const;
|
std::string getEventString() const;
|
||||||
|
|
||||||
AnnounceTier::AnnounceEvent getEvent() const;
|
AnnounceTier::AnnounceEvent getEvent() const;
|
||||||
|
|
||||||
|
@ -125,4 +129,6 @@ public:
|
||||||
bool currentTierAcceptsCompletedEvent() const;
|
bool currentTierAcceptsCompletedEvent() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ANNOUNCE_LIST_H_
|
#endif // _D_ANNOUNCE_LIST_H_
|
||||||
|
|
|
@ -36,6 +36,11 @@
|
||||||
#define _D_ANNOUNCE_TIER_H_
|
#define _D_ANNOUNCE_TIER_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
#include <string>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class AnnounceTier {
|
class AnnounceTier {
|
||||||
public:
|
public:
|
||||||
|
@ -50,9 +55,9 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
AnnounceEvent event;
|
AnnounceEvent event;
|
||||||
Strings urls;
|
std::deque<std::string> urls;
|
||||||
|
|
||||||
AnnounceTier(const Strings& urls):event(STARTED), urls(urls) {}
|
AnnounceTier(const std::deque<std::string>& urls):event(STARTED), urls(urls) {}
|
||||||
|
|
||||||
void nextEvent() {
|
void nextEvent() {
|
||||||
switch(event) {
|
switch(event) {
|
||||||
|
@ -89,6 +94,8 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<AnnounceTier> AnnounceTierHandle;
|
typedef SharedHandle<AnnounceTier> AnnounceTierHandle;
|
||||||
typedef deque<AnnounceTierHandle> AnnounceTiers;
|
typedef std::deque<AnnounceTierHandle> AnnounceTiers;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_ANNOUNCE_TIER_H_
|
#endif // _D_ANNOUNCE_TIER_H_
|
||||||
|
|
|
@ -34,9 +34,12 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "AuthConfig.h"
|
#include "AuthConfig.h"
|
||||||
|
|
||||||
ostream& operator<<(ostream& o, const AuthConfigHandle& authConfig)
|
namespace aria2 {
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& o, const AuthConfigHandle& authConfig)
|
||||||
{
|
{
|
||||||
o << authConfig->getAuthText();
|
o << authConfig->getAuthText();
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,29 +36,34 @@
|
||||||
#define _D_AUTH_CONFIG_H_
|
#define _D_AUTH_CONFIG_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
#include <string>
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class AuthConfig {
|
class AuthConfig {
|
||||||
private:
|
private:
|
||||||
string _authScheme;
|
std::string _authScheme;
|
||||||
string _user;
|
std::string _user;
|
||||||
string _password;
|
std::string _password;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AuthConfig() {}
|
AuthConfig() {}
|
||||||
AuthConfig(const string& user, const string& password):
|
AuthConfig(const std::string& user, const std::string& password):
|
||||||
_user(user), _password(password) {}
|
_user(user), _password(password) {}
|
||||||
|
|
||||||
string getAuthText() const
|
std::string getAuthText() const
|
||||||
{
|
{
|
||||||
return _user+":"+_password;
|
return _user+":"+_password;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& getUser() const
|
const std::string& getUser() const
|
||||||
{
|
{
|
||||||
return _user;
|
return _user;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& getPassword() const
|
const std::string& getPassword() const
|
||||||
{
|
{
|
||||||
return _password;
|
return _password;
|
||||||
}
|
}
|
||||||
|
@ -66,6 +71,8 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<AuthConfig> AuthConfigHandle;
|
typedef SharedHandle<AuthConfig> AuthConfigHandle;
|
||||||
|
|
||||||
ostream& operator<<(ostream& o, const AuthConfigHandle& authConfig);
|
std::ostream& operator<<(std::ostream& o, const AuthConfigHandle& authConfig);
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_AUTH_CONFIG_H_
|
#endif // _D_AUTH_CONFIG_H_
|
||||||
|
|
|
@ -41,6 +41,8 @@
|
||||||
#include "prefs.h"
|
#include "prefs.h"
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
AuthConfigFactory::AuthConfigFactory(const Option* option):
|
AuthConfigFactory::AuthConfigFactory(const Option* option):
|
||||||
_option(option), _netrc(0) {}
|
_option(option), _netrc(0) {}
|
||||||
|
|
||||||
|
@ -66,7 +68,7 @@ AuthConfigHandle AuthConfigFactory::createAuthConfigForHttpProxy(const RequestHa
|
||||||
return createHttpProxyAuthResolver()->resolveAuthConfig(request->getHost());
|
return createHttpProxyAuthResolver()->resolveAuthConfig(request->getHost());
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthConfigHandle AuthConfigFactory::createAuthConfig(const string& user, const string& password) const
|
AuthConfigHandle AuthConfigFactory::createAuthConfig(const std::string& user, const std::string& password) const
|
||||||
{
|
{
|
||||||
if(user.length() > 0) {
|
if(user.length() > 0) {
|
||||||
return new AuthConfig(user, password);
|
return new AuthConfig(user, password);
|
||||||
|
@ -122,3 +124,5 @@ void AuthConfigFactory::setNetrc(const NetrcHandle& netrc)
|
||||||
{
|
{
|
||||||
_netrc = netrc;
|
_netrc = netrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,30 +36,31 @@
|
||||||
#define _D_AUTH_CONFIG_FACTORY_H_
|
#define _D_AUTH_CONFIG_FACTORY_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
#include "SingletonHolder.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class Option;
|
class Option;
|
||||||
class Netrc;
|
class Netrc;
|
||||||
typedef SharedHandle<Netrc> NetrcHandle;
|
|
||||||
class AuthConfig;
|
class AuthConfig;
|
||||||
typedef SharedHandle<AuthConfig> AuthConfigHandle;
|
|
||||||
class Request;
|
class Request;
|
||||||
typedef SharedHandle<Request> RequestHandle;
|
|
||||||
class AuthResolver;
|
class AuthResolver;
|
||||||
typedef SharedHandle<AuthResolver> AuthResolverHandle;
|
|
||||||
|
|
||||||
class AuthConfigFactory {
|
class AuthConfigFactory {
|
||||||
private:
|
private:
|
||||||
const Option* _option;
|
const Option* _option;
|
||||||
|
|
||||||
NetrcHandle _netrc;
|
SharedHandle<Netrc> _netrc;
|
||||||
|
|
||||||
AuthConfigHandle createAuthConfig(const string& user, const string& password) const;
|
SharedHandle<AuthConfig> createAuthConfig(const std::string& user, const std::string& password) const;
|
||||||
|
|
||||||
AuthResolverHandle createHttpAuthResolver() const;
|
SharedHandle<AuthResolver> createHttpAuthResolver() const;
|
||||||
|
|
||||||
AuthResolverHandle createHttpProxyAuthResolver() const;
|
SharedHandle<AuthResolver> createHttpProxyAuthResolver() const;
|
||||||
|
|
||||||
AuthResolverHandle createFtpAuthResolver() const;
|
SharedHandle<AuthResolver> createFtpAuthResolver() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -67,14 +68,16 @@ public:
|
||||||
|
|
||||||
~AuthConfigFactory();
|
~AuthConfigFactory();
|
||||||
|
|
||||||
AuthConfigHandle createAuthConfig(const RequestHandle& request) const;
|
SharedHandle<AuthConfig> createAuthConfig(const SharedHandle<Request>& request) const;
|
||||||
|
|
||||||
AuthConfigHandle createAuthConfigForHttpProxy(const RequestHandle& request) const;
|
SharedHandle<AuthConfig> createAuthConfigForHttpProxy(const SharedHandle<Request>& request) const;
|
||||||
|
|
||||||
void setNetrc(const NetrcHandle& netrc);
|
void setNetrc(const SharedHandle<Netrc>& netrc);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<AuthConfigFactory> AuthConfigFactoryHandle;
|
typedef SharedHandle<AuthConfigFactory> AuthConfigFactoryHandle;
|
||||||
typedef SingletonHolder<AuthConfigFactoryHandle> AuthConfigFactorySingleton;
|
typedef SingletonHolder<AuthConfigFactoryHandle> AuthConfigFactorySingleton;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_AUTH_CONFIG_FACTORY_H_
|
#endif // _D_AUTH_CONFIG_FACTORY_H_
|
||||||
|
|
|
@ -36,15 +36,22 @@
|
||||||
#define _D_AUTH_RESOLVER_H_
|
#define _D_AUTH_RESOLVER_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "AuthConfig.h"
|
#include "SharedHandle.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class AuthConfig;
|
||||||
|
|
||||||
class AuthResolver {
|
class AuthResolver {
|
||||||
public:
|
public:
|
||||||
virtual ~AuthResolver() {}
|
virtual ~AuthResolver() {}
|
||||||
|
|
||||||
virtual AuthConfigHandle resolveAuthConfig(const string& hostname) = 0;
|
virtual SharedHandle<AuthConfig> resolveAuthConfig(const std::string& hostname) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<AuthResolver> AuthResolverHandle;
|
typedef SharedHandle<AuthResolver> AuthResolverHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_AUTH_RESOLVER_H_
|
#endif // _D_AUTH_RESOLVER_H_
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "RequestGroupMan.h"
|
#include "RequestGroupMan.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
AutoSaveCommand::AutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval):
|
AutoSaveCommand::AutoSaveCommand(int32_t cuid, DownloadEngine* e, int32_t interval):
|
||||||
TimeBasedCommand(cuid, e, interval) {}
|
TimeBasedCommand(cuid, e, interval) {}
|
||||||
|
|
||||||
|
@ -52,3 +54,5 @@ void AutoSaveCommand::process()
|
||||||
{
|
{
|
||||||
_e->_requestGroupMan->save();
|
_e->_requestGroupMan->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "TimeBasedCommand.h"
|
#include "TimeBasedCommand.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class AutoSaveCommand : public TimeBasedCommand
|
class AutoSaveCommand : public TimeBasedCommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -49,4 +51,6 @@ public:
|
||||||
virtual void process();
|
virtual void process();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_AUTO_SAVE_COMMAND_H_
|
#endif // _D_AUTO_SAVE_COMMAND_H_
|
||||||
|
|
50
src/BNode.cc
50
src/BNode.cc
|
@ -35,10 +35,16 @@
|
||||||
#include "BNode.h"
|
#include "BNode.h"
|
||||||
#include "DHTBucket.h"
|
#include "DHTBucket.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
|
#include <functional>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
BNode::BNode(const DHTBucketHandle& bucket):_bucket(bucket),
|
namespace aria2 {
|
||||||
|
|
||||||
|
BNode::BNode(const SharedHandle<DHTBucket>& bucket):
|
||||||
|
_bucket(bucket),
|
||||||
_up(0),
|
_up(0),
|
||||||
_left(0), _right(0) {}
|
_left(0),
|
||||||
|
_right(0) {}
|
||||||
|
|
||||||
BNode::~BNode()
|
BNode::~BNode()
|
||||||
{
|
{
|
||||||
|
@ -46,7 +52,7 @@ BNode::~BNode()
|
||||||
delete _right;
|
delete _right;
|
||||||
}
|
}
|
||||||
|
|
||||||
DHTBucketHandle BNode::getBucket() const
|
SharedHandle<DHTBucket> BNode::getBucket() const
|
||||||
{
|
{
|
||||||
return _bucket;
|
return _bucket;
|
||||||
}
|
}
|
||||||
|
@ -83,7 +89,7 @@ void BNode::setUp(BNode* up)
|
||||||
_up = up;
|
_up = up;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BNode::setBucket(const DHTBucketHandle& bucket)
|
void BNode::setBucket(const SharedHandle<DHTBucket>& bucket)
|
||||||
{
|
{
|
||||||
_bucket = bucket;
|
_bucket = bucket;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +123,7 @@ BNode* BNode::findBNodeFor(BNode* b, const unsigned char* key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
DHTBucketHandle BNode::findBucketFor(BNode* b, const unsigned char* key)
|
SharedHandle<DHTBucket> BNode::findBucketFor(BNode* b, const unsigned char* key)
|
||||||
{
|
{
|
||||||
BNode* bnode = findBNodeFor(b, key);
|
BNode* bnode = findBNodeFor(b, key);
|
||||||
if(bnode) {
|
if(bnode) {
|
||||||
|
@ -128,22 +134,22 @@ DHTBucketHandle BNode::findBucketFor(BNode* b, const unsigned char* key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DHTNodes BNode::findClosestKNodes(BNode* b, const unsigned char* key)
|
std::deque<SharedHandle<DHTNode> > BNode::findClosestKNodes(BNode* b, const unsigned char* key)
|
||||||
{
|
{
|
||||||
BNode* bnode = findBNodeFor(b, key);
|
BNode* bnode = findBNodeFor(b, key);
|
||||||
DHTNodes nodes;
|
std::deque<SharedHandle<DHTNode> > nodes;
|
||||||
if(!bnode) {
|
if(!bnode) {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
DHTBucketHandle bucket = bnode->getBucket();
|
SharedHandle<DHTBucket> bucket = bnode->getBucket();
|
||||||
DHTNodes goodNodes = bucket->getGoodNodes();
|
std::deque<SharedHandle<DHTNode> > goodNodes = bucket->getGoodNodes();
|
||||||
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end());
|
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end());
|
||||||
}
|
}
|
||||||
if(nodes.size() >= DHTBucket::K) {
|
if(nodes.size() >= DHTBucket::K) {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
BNodes visited;
|
std::deque<const BNode*> visited;
|
||||||
visited.push_back(bnode);
|
visited.push_back(bnode);
|
||||||
|
|
||||||
BNode* up = bnode->getUp();
|
BNode* up = bnode->getUp();
|
||||||
|
@ -156,16 +162,16 @@ DHTNodes BNode::findClosestKNodes(BNode* b, const unsigned char* key)
|
||||||
}
|
}
|
||||||
bnode = up;
|
bnode = up;
|
||||||
|
|
||||||
const_mem_fun_t<BNode*, BNode> firstfunc = leftFirst?mem_fun(&BNode::getLeft):mem_fun(&BNode::getRight);
|
std::const_mem_fun_t<BNode*, BNode> firstfunc = leftFirst?std::mem_fun(&BNode::getLeft):std::mem_fun(&BNode::getRight);
|
||||||
const_mem_fun_t<BNode*, BNode> secondfunc = leftFirst?mem_fun(&BNode::getRight):mem_fun(&BNode::getLeft);
|
std::const_mem_fun_t<BNode*, BNode> secondfunc = leftFirst?std::mem_fun(&BNode::getRight):std::mem_fun(&BNode::getLeft);
|
||||||
while(nodes.size() < DHTBucket::K) {
|
while(nodes.size() < DHTBucket::K) {
|
||||||
|
|
||||||
if(!bnode->getLeft() && !bnode->getRight()) {
|
if(!bnode->getLeft() && !bnode->getRight()) {
|
||||||
bnode = bnode->getUp();
|
bnode = bnode->getUp();
|
||||||
} else {
|
} else {
|
||||||
if(find(visited.begin(), visited.end(), firstfunc(bnode)) == visited.end()) {
|
if(std::find(visited.begin(), visited.end(), firstfunc(bnode)) == visited.end()) {
|
||||||
bnode = firstfunc(bnode);
|
bnode = firstfunc(bnode);
|
||||||
} else if(find(visited.begin(), visited.end(), secondfunc(bnode)) == visited.end()) {
|
} else if(std::find(visited.begin(), visited.end(), secondfunc(bnode)) == visited.end()) {
|
||||||
bnode = secondfunc(bnode);
|
bnode = secondfunc(bnode);
|
||||||
} else {
|
} else {
|
||||||
bnode = bnode->getUp();
|
bnode = bnode->getUp();
|
||||||
|
@ -176,9 +182,9 @@ DHTNodes BNode::findClosestKNodes(BNode* b, const unsigned char* key)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
DHTBucketHandle bucket = bnode->getBucket();
|
SharedHandle<DHTBucket> bucket = bnode->getBucket();
|
||||||
if(!bucket.isNull()) {
|
if(!bucket.isNull()) {
|
||||||
DHTNodes goodNodes = bucket->getGoodNodes();
|
std::deque<SharedHandle<DHTNode> > goodNodes = bucket->getGoodNodes();
|
||||||
size_t r = DHTBucket::K-nodes.size();
|
size_t r = DHTBucket::K-nodes.size();
|
||||||
if(goodNodes.size() <= r) {
|
if(goodNodes.size() <= r) {
|
||||||
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end());
|
nodes.insert(nodes.end(), goodNodes.begin(), goodNodes.end());
|
||||||
|
@ -191,10 +197,10 @@ DHTNodes BNode::findClosestKNodes(BNode* b, const unsigned char* key)
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
DHTBuckets BNode::enumerateBucket(const BNode* b)
|
std::deque<SharedHandle<DHTBucket> > BNode::enumerateBucket(const BNode* b)
|
||||||
{
|
{
|
||||||
DHTBuckets buckets;
|
std::deque<SharedHandle<DHTBucket> > buckets;
|
||||||
deque<const BNode*> visited;
|
std::deque<const BNode*> visited;
|
||||||
visited.push_back(b);
|
visited.push_back(b);
|
||||||
while(1) {
|
while(1) {
|
||||||
if(!b) {
|
if(!b) {
|
||||||
|
@ -203,10 +209,10 @@ DHTBuckets BNode::enumerateBucket(const BNode* b)
|
||||||
if(!b->getBucket().isNull()) {
|
if(!b->getBucket().isNull()) {
|
||||||
buckets.push_back(b->getBucket());
|
buckets.push_back(b->getBucket());
|
||||||
b = b->getUp();
|
b = b->getUp();
|
||||||
} else if(find(visited.begin(), visited.end(), b->getLeft()) == visited.end()) {
|
} else if(std::find(visited.begin(), visited.end(), b->getLeft()) == visited.end()) {
|
||||||
b = b->getLeft();
|
b = b->getLeft();
|
||||||
visited.push_back(b);
|
visited.push_back(b);
|
||||||
} else if(find(visited.begin(), visited.end(), b->getRight()) == visited.end()) {
|
} else if(std::find(visited.begin(), visited.end(), b->getRight()) == visited.end()) {
|
||||||
b = b->getRight();
|
b = b->getRight();
|
||||||
visited.push_back(b);
|
visited.push_back(b);
|
||||||
} else {
|
} else {
|
||||||
|
@ -215,3 +221,5 @@ DHTBuckets BNode::enumerateBucket(const BNode* b)
|
||||||
}
|
}
|
||||||
return buckets;
|
return buckets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
26
src/BNode.h
26
src/BNode.h
|
@ -36,13 +36,17 @@
|
||||||
#define _D_BNODE_H_
|
#define _D_BNODE_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "DHTBucketDecl.h"
|
#include "SharedHandle.h"
|
||||||
#include "BNodeDecl.h"
|
#include <deque>
|
||||||
#include "DHTNodeDecl.h"
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class DHTBucket;
|
||||||
|
class DHTNode;
|
||||||
|
|
||||||
class BNode {
|
class BNode {
|
||||||
private:
|
private:
|
||||||
DHTBucketHandle _bucket;
|
SharedHandle<DHTBucket> _bucket;
|
||||||
|
|
||||||
BNode* _up;
|
BNode* _up;
|
||||||
|
|
||||||
|
@ -51,13 +55,13 @@ private:
|
||||||
BNode* _right;
|
BNode* _right;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BNode(const DHTBucketHandle& bucket = 0);
|
BNode(const SharedHandle<DHTBucket>& bucket = 0);
|
||||||
|
|
||||||
~BNode();
|
~BNode();
|
||||||
|
|
||||||
DHTBucketHandle getBucket() const;
|
SharedHandle<DHTBucket> getBucket() const;
|
||||||
|
|
||||||
void setBucket(const DHTBucketHandle& bucket);
|
void setBucket(const SharedHandle<DHTBucket>& bucket);
|
||||||
|
|
||||||
BNode* getLeft() const;
|
BNode* getLeft() const;
|
||||||
|
|
||||||
|
@ -75,11 +79,13 @@ public:
|
||||||
|
|
||||||
static BNode* findBNodeFor(BNode* b, const unsigned char* key);
|
static BNode* findBNodeFor(BNode* b, const unsigned char* key);
|
||||||
|
|
||||||
static DHTBucketHandle findBucketFor(BNode* b, const unsigned char* key);
|
static SharedHandle<DHTBucket> findBucketFor(BNode* b, const unsigned char* key);
|
||||||
|
|
||||||
static DHTNodes findClosestKNodes(BNode* b, const unsigned char* key);
|
static std::deque<SharedHandle<DHTNode> > findClosestKNodes(BNode* b, const unsigned char* key);
|
||||||
|
|
||||||
static DHTBuckets enumerateBucket(const BNode* b);
|
static std::deque<SharedHandle<DHTBucket> > enumerateBucket(const BNode* b);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BNODE_H_
|
#endif // _D_BNODE_H_
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "Base64.h"
|
#include "Base64.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
static const char CHAR_TABLE[] = {
|
static const char CHAR_TABLE[] = {
|
||||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||||
|
@ -179,22 +181,24 @@ void Base64::decode(unsigned char*& result, size_t& rlength,
|
||||||
delete [] nsrc;
|
delete [] nsrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Base64::encode(const string& s)
|
std::string Base64::encode(const std::string& s)
|
||||||
{
|
{
|
||||||
unsigned char* buf = 0;
|
unsigned char* buf = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
encode(buf, len, s.c_str(), s.size());
|
encode(buf, len, s.c_str(), s.size());
|
||||||
string r(&buf[0], &buf[len]);
|
std::string r(&buf[0], &buf[len]);
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Base64::decode(const string& s)
|
std::string Base64::decode(const std::string& s)
|
||||||
{
|
{
|
||||||
unsigned char* buf = 0;
|
unsigned char* buf = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
decode(buf, len, s.c_str(), s.size());
|
decode(buf, len, s.c_str(), s.size());
|
||||||
string r(&buf[0], &buf[len]);
|
std::string r(&buf[0], &buf[len]);
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#define _D_BASE64_H_
|
#define _D_BASE64_H_
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace std;
|
namespace aria2 {
|
||||||
|
|
||||||
class Base64
|
class Base64
|
||||||
{
|
{
|
||||||
|
@ -67,7 +67,7 @@ public:
|
||||||
encode(result, rlength, (const unsigned char*)src, slength);
|
encode(result, rlength, (const unsigned char*)src, slength);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string encode(const string& s);
|
static std::string encode(const std::string& s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dencods base64 encoded src whose length is slength and stores them to
|
* Dencods base64 encoded src whose length is slength and stores them to
|
||||||
|
@ -87,7 +87,9 @@ public:
|
||||||
decode(result, rlength, (const unsigned char*)src, slength);
|
decode(result, rlength, (const unsigned char*)src, slength);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string decode(const string& s);
|
static std::string decode(const std::string& s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _BASE64_H_
|
#endif // _BASE64_H_
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
#include "List.h"
|
#include "List.h"
|
||||||
#include "Dictionary.h"
|
#include "Dictionary.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include <functional>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BencodeVisitor::BencodeVisitor() {}
|
BencodeVisitor::BencodeVisitor() {}
|
||||||
|
|
||||||
|
@ -54,8 +58,8 @@ void BencodeVisitor::visit(const Data* d)
|
||||||
void BencodeVisitor::visit(const List* l)
|
void BencodeVisitor::visit(const List* l)
|
||||||
{
|
{
|
||||||
_bencodedData += "l";
|
_bencodedData += "l";
|
||||||
for_each(l->getList().begin(), l->getList().end(),
|
std::for_each(l->getList().begin(), l->getList().end(),
|
||||||
bind2nd(mem_fun(&MetaEntry::accept), this));
|
std::bind2nd(std::mem_fun(&MetaEntry::accept), this));
|
||||||
_bencodedData += "e";
|
_bencodedData += "e";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +67,7 @@ void BencodeVisitor::visit(const Dictionary* d)
|
||||||
{
|
{
|
||||||
_bencodedData += "d";
|
_bencodedData += "d";
|
||||||
|
|
||||||
for(Order::const_iterator itr = d->getOrder().begin(); itr != d->getOrder().end(); ++itr) {
|
for(std::deque<std::string>::const_iterator itr = d->getOrder().begin(); itr != d->getOrder().end(); ++itr) {
|
||||||
_bencodedData += Util::itos((int32_t)(*itr).size());
|
_bencodedData += Util::itos((int32_t)(*itr).size());
|
||||||
_bencodedData += ":";
|
_bencodedData += ":";
|
||||||
_bencodedData += *itr;
|
_bencodedData += *itr;
|
||||||
|
@ -82,3 +86,5 @@ void BencodeVisitor::visit(const MetaEntry* e)
|
||||||
visit(reinterpret_cast<const Dictionary*>(e));
|
visit(reinterpret_cast<const Dictionary*>(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#define _D_BENCODE_VISITOR_H_
|
#define _D_BENCODE_VISITOR_H_
|
||||||
|
|
||||||
#include "MetaEntryVisitor.h"
|
#include "MetaEntryVisitor.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class Data;
|
class Data;
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
|
@ -44,7 +47,7 @@ class MetaEntry;
|
||||||
|
|
||||||
class BencodeVisitor : public MetaEntryVisitor {
|
class BencodeVisitor : public MetaEntryVisitor {
|
||||||
private:
|
private:
|
||||||
string _bencodedData;
|
std::string _bencodedData;
|
||||||
public:
|
public:
|
||||||
BencodeVisitor();
|
BencodeVisitor();
|
||||||
~BencodeVisitor();
|
~BencodeVisitor();
|
||||||
|
@ -55,10 +58,12 @@ public:
|
||||||
|
|
||||||
virtual void visit(const MetaEntry* e);
|
virtual void visit(const MetaEntry* e);
|
||||||
|
|
||||||
const string& getBencodedData() const
|
const std::string& getBencodedData() const
|
||||||
{
|
{
|
||||||
return _bencodedData;
|
return _bencodedData;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BENCODE_VISITOR_H_
|
#endif // _D_BENCODE_VISITOR_H_
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
#define _D_BINARY_STREAM_H_
|
#define _D_BINARY_STREAM_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "DlAbortEx.h"
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BinaryStream {
|
class BinaryStream {
|
||||||
public:
|
public:
|
||||||
|
@ -57,4 +59,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BinaryStream> BinaryStreamHandle;
|
typedef SharedHandle<BinaryStream> BinaryStreamHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BINARY_STREAM_H_
|
#endif // _D_BINARY_STREAM_H_
|
||||||
|
|
|
@ -33,9 +33,12 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BitfieldMan.h"
|
#include "BitfieldMan.h"
|
||||||
|
#include "Randomizer.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "array_fun.h"
|
#include "array_fun.h"
|
||||||
#include <string.h>
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BitfieldMan::BitfieldMan(int32_t blockLength, int64_t totalLength)
|
BitfieldMan::BitfieldMan(int32_t blockLength, int64_t totalLength)
|
||||||
:blockLength(blockLength),
|
:blockLength(blockLength),
|
||||||
|
@ -99,12 +102,63 @@ BitfieldMan::BitfieldMan(const BitfieldMan& bitfieldMan)
|
||||||
updateCache();
|
updateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BitfieldMan& BitfieldMan::operator=(const BitfieldMan& bitfieldMan)
|
||||||
|
{
|
||||||
|
if(this != &bitfieldMan) {
|
||||||
|
blockLength = bitfieldMan.blockLength;
|
||||||
|
totalLength = bitfieldMan.totalLength;
|
||||||
|
blocks = bitfieldMan.blocks;
|
||||||
|
bitfieldLength = bitfieldMan.bitfieldLength;
|
||||||
|
filterEnabled = bitfieldMan.filterEnabled;
|
||||||
|
|
||||||
|
delete [] bitfield;
|
||||||
|
bitfield = new unsigned char[bitfieldLength];
|
||||||
|
memcpy(bitfield, bitfieldMan.bitfield, bitfieldLength);
|
||||||
|
|
||||||
|
delete [] useBitfield;
|
||||||
|
useBitfield = new unsigned char[bitfieldLength];
|
||||||
|
memcpy(useBitfield, bitfieldMan.useBitfield, bitfieldLength);
|
||||||
|
|
||||||
|
delete [] filterBitfield;
|
||||||
|
if(filterEnabled) {
|
||||||
|
filterBitfield = new unsigned char[bitfieldLength];
|
||||||
|
memcpy(filterBitfield, bitfieldMan.filterBitfield, bitfieldLength);
|
||||||
|
} else {
|
||||||
|
filterBitfield = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCache();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
BitfieldMan::~BitfieldMan() {
|
BitfieldMan::~BitfieldMan() {
|
||||||
delete [] bitfield;
|
delete [] bitfield;
|
||||||
delete [] useBitfield;
|
delete [] useBitfield;
|
||||||
delete [] filterBitfield;
|
delete [] filterBitfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t BitfieldMan::getBlockLength() const
|
||||||
|
{
|
||||||
|
return blockLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t BitfieldMan::getLastBlockLength() const
|
||||||
|
{
|
||||||
|
return totalLength-blockLength*(blocks-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t BitfieldMan::getBlockLength(int32_t index) const
|
||||||
|
{
|
||||||
|
if(index == blocks-1) {
|
||||||
|
return getLastBlockLength();
|
||||||
|
} else if(0 <= index && index < blocks-1) {
|
||||||
|
return getBlockLength();
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int32_t BitfieldMan::countSetBit(const unsigned char* bitfield, int32_t len) const {
|
int32_t BitfieldMan::countSetBit(const unsigned char* bitfield, int32_t len) const {
|
||||||
int32_t count = 0;
|
int32_t count = 0;
|
||||||
int32_t size = sizeof(int32_t);
|
int32_t size = sizeof(int32_t);
|
||||||
|
@ -332,9 +386,9 @@ int32_t BitfieldMan::getSparseMissingUnusedIndex() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Array>
|
template<typename Array>
|
||||||
BlockIndexes BitfieldMan::getAllMissingIndexes(const Array& bitfield, int32_t bitfieldLength) const
|
std::deque<int32_t> BitfieldMan::getAllMissingIndexes(const Array& bitfield, int32_t bitfieldLength) const
|
||||||
{
|
{
|
||||||
BlockIndexes missingIndexes;
|
std::deque<int32_t> missingIndexes;
|
||||||
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
for(int32_t i = 0; i < bitfieldLength; ++i) {
|
||||||
int32_t base = i*8;
|
int32_t base = i*8;
|
||||||
for(int32_t bi = 0; bi < 8 && base+bi < blocks; ++bi) {
|
for(int32_t bi = 0; bi < 8 && base+bi < blocks; ++bi) {
|
||||||
|
@ -347,7 +401,7 @@ BlockIndexes BitfieldMan::getAllMissingIndexes(const Array& bitfield, int32_t bi
|
||||||
return missingIndexes;
|
return missingIndexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockIndexes BitfieldMan::getAllMissingIndexes() const {
|
std::deque<int32_t> BitfieldMan::getAllMissingIndexes() const {
|
||||||
array_fun<unsigned char> bf = array_negate(bitfield);
|
array_fun<unsigned char> bf = array_negate(bitfield);
|
||||||
if(filterEnabled) {
|
if(filterEnabled) {
|
||||||
bf = array_and(bf, filterBitfield);
|
bf = array_and(bf, filterBitfield);
|
||||||
|
@ -355,9 +409,9 @@ BlockIndexes BitfieldMan::getAllMissingIndexes() const {
|
||||||
return getAllMissingIndexes(bf, bitfieldLength);
|
return getAllMissingIndexes(bf, bitfieldLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockIndexes BitfieldMan::getAllMissingIndexes(const unsigned char* peerBitfield, int32_t peerBitfieldLength) const {
|
std::deque<int32_t> BitfieldMan::getAllMissingIndexes(const unsigned char* peerBitfield, int32_t peerBitfieldLength) const {
|
||||||
if(bitfieldLength != peerBitfieldLength) {
|
if(bitfieldLength != peerBitfieldLength) {
|
||||||
return BlockIndexes();
|
return std::deque<int32_t>();
|
||||||
}
|
}
|
||||||
array_fun<unsigned char> bf = array_and(array_negate(bitfield),
|
array_fun<unsigned char> bf = array_and(array_negate(bitfield),
|
||||||
peerBitfield);
|
peerBitfield);
|
||||||
|
@ -402,6 +456,11 @@ int32_t BitfieldMan::countFilteredBlockNow() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t BitfieldMan::getMaxIndex() const
|
||||||
|
{
|
||||||
|
return blocks-1;
|
||||||
|
}
|
||||||
|
|
||||||
bool BitfieldMan::setBitInternal(unsigned char* bitfield, int32_t index, bool on) {
|
bool BitfieldMan::setBitInternal(unsigned char* bitfield, int32_t index, bool on) {
|
||||||
if(blocks <= index) { return false; }
|
if(blocks <= index) { return false; }
|
||||||
unsigned char mask = 128 >> index%8;
|
unsigned char mask = 128 >> index%8;
|
||||||
|
@ -485,6 +544,16 @@ void BitfieldMan::setBitfield(const unsigned char* bitfield, int32_t bitfieldLen
|
||||||
updateCache();
|
updateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const unsigned char* BitfieldMan::getBitfield() const
|
||||||
|
{
|
||||||
|
return bitfield;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t BitfieldMan::getBitfieldLength() const
|
||||||
|
{
|
||||||
|
return bitfieldLength;
|
||||||
|
}
|
||||||
|
|
||||||
void BitfieldMan::clearAllBit() {
|
void BitfieldMan::clearAllBit() {
|
||||||
memset(this->bitfield, 0, this->bitfieldLength);
|
memset(this->bitfield, 0, this->bitfieldLength);
|
||||||
updateCache();
|
updateCache();
|
||||||
|
@ -680,3 +749,15 @@ int64_t BitfieldMan::getMissingUnusedLength(int32_t startingIndex) const
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BitfieldMan::setRandomizer(const SharedHandle<Randomizer>& randomizer)
|
||||||
|
{
|
||||||
|
this->randomizer = randomizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedHandle<Randomizer> BitfieldMan::getRandomizer() const
|
||||||
|
{
|
||||||
|
return randomizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,10 +36,12 @@
|
||||||
#define _D_BITFIELD_MAN_H_
|
#define _D_BITFIELD_MAN_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "Randomizer.h"
|
#include "SharedHandle.h"
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
typedef deque<int> BlockIndexes;
|
namespace aria2 {
|
||||||
|
|
||||||
|
class Randomizer;
|
||||||
|
|
||||||
class BitfieldMan {
|
class BitfieldMan {
|
||||||
private:
|
private:
|
||||||
|
@ -51,7 +53,7 @@ private:
|
||||||
int32_t bitfieldLength;
|
int32_t bitfieldLength;
|
||||||
int32_t blocks;
|
int32_t blocks;
|
||||||
bool filterEnabled;
|
bool filterEnabled;
|
||||||
RandomizerHandle randomizer;
|
SharedHandle<Randomizer> randomizer;
|
||||||
|
|
||||||
// for caching
|
// for caching
|
||||||
int32_t cachedNumMissingBlock;
|
int32_t cachedNumMissingBlock;
|
||||||
|
@ -72,7 +74,7 @@ private:
|
||||||
int32_t getFirstMissingIndex(const Array& bitfield, int32_t bitfieldLength) const;
|
int32_t getFirstMissingIndex(const Array& bitfield, int32_t bitfieldLength) const;
|
||||||
|
|
||||||
template<typename Array>
|
template<typename Array>
|
||||||
BlockIndexes getAllMissingIndexes(const Array& bitfield, int32_t bitfieldLength) const;
|
std::deque<int32_t> getAllMissingIndexes(const Array& bitfield, int32_t bitfieldLength) const;
|
||||||
|
|
||||||
bool isBitSetInternal(const unsigned char* bitfield, int32_t index) const;
|
bool isBitSetInternal(const unsigned char* bitfield, int32_t index) const;
|
||||||
bool setBitInternal(unsigned char* bitfield, int32_t index, bool on);
|
bool setBitInternal(unsigned char* bitfield, int32_t index, bool on);
|
||||||
|
@ -87,50 +89,13 @@ public:
|
||||||
BitfieldMan(const BitfieldMan& bitfieldMan);
|
BitfieldMan(const BitfieldMan& bitfieldMan);
|
||||||
~BitfieldMan();
|
~BitfieldMan();
|
||||||
|
|
||||||
BitfieldMan& operator=(const BitfieldMan& bitfieldMan) {
|
BitfieldMan& operator=(const BitfieldMan& bitfieldMan);
|
||||||
if(this != &bitfieldMan) {
|
|
||||||
blockLength = bitfieldMan.blockLength;
|
|
||||||
totalLength = bitfieldMan.totalLength;
|
|
||||||
blocks = bitfieldMan.blocks;
|
|
||||||
bitfieldLength = bitfieldMan.bitfieldLength;
|
|
||||||
filterEnabled = bitfieldMan.filterEnabled;
|
|
||||||
|
|
||||||
delete [] bitfield;
|
int32_t getBlockLength() const;
|
||||||
bitfield = new unsigned char[bitfieldLength];
|
|
||||||
memcpy(bitfield, bitfieldMan.bitfield, bitfieldLength);
|
|
||||||
|
|
||||||
delete [] useBitfield;
|
int32_t getLastBlockLength() const;
|
||||||
useBitfield = new unsigned char[bitfieldLength];
|
|
||||||
memcpy(useBitfield, bitfieldMan.useBitfield, bitfieldLength);
|
|
||||||
|
|
||||||
delete [] filterBitfield;
|
int32_t getBlockLength(int32_t index) const;
|
||||||
if(filterEnabled) {
|
|
||||||
filterBitfield = new unsigned char[bitfieldLength];
|
|
||||||
memcpy(filterBitfield, bitfieldMan.filterBitfield, bitfieldLength);
|
|
||||||
} else {
|
|
||||||
filterBitfield = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateCache();
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t getBlockLength() const { return blockLength; }
|
|
||||||
|
|
||||||
int32_t getLastBlockLength() const {
|
|
||||||
return totalLength-blockLength*(blocks-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t getBlockLength(int32_t index) const {
|
|
||||||
if(index == blocks-1) {
|
|
||||||
return getLastBlockLength();
|
|
||||||
} else if(0 <= index && index < blocks-1) {
|
|
||||||
return getBlockLength();
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t getTotalLength() const { return totalLength; }
|
int64_t getTotalLength() const { return totalLength; }
|
||||||
|
|
||||||
|
@ -173,11 +138,11 @@ public:
|
||||||
/**
|
/**
|
||||||
* affected by filter
|
* affected by filter
|
||||||
*/
|
*/
|
||||||
BlockIndexes getAllMissingIndexes() const;
|
std::deque<int32_t> getAllMissingIndexes() const;
|
||||||
/**
|
/**
|
||||||
* affected by filter
|
* affected by filter
|
||||||
*/
|
*/
|
||||||
BlockIndexes getAllMissingIndexes(const unsigned char* bitfield, int32_t len) const;
|
std::deque<int32_t> getAllMissingIndexes(const unsigned char* bitfield, int32_t len) const;
|
||||||
/**
|
/**
|
||||||
* affected by filter
|
* affected by filter
|
||||||
*/
|
*/
|
||||||
|
@ -203,8 +168,9 @@ public:
|
||||||
|
|
||||||
bool isAllBitSet() const;
|
bool isAllBitSet() const;
|
||||||
|
|
||||||
const unsigned char* getBitfield() const { return bitfield; }
|
const unsigned char* getBitfield() const;
|
||||||
int32_t getBitfieldLength() const { return bitfieldLength; }
|
|
||||||
|
int32_t getBitfieldLength() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* affected by filter
|
* affected by filter
|
||||||
|
@ -217,7 +183,7 @@ public:
|
||||||
*/
|
*/
|
||||||
int32_t countFilteredBlockNow() const;
|
int32_t countFilteredBlockNow() const;
|
||||||
|
|
||||||
int32_t getMaxIndex() const { return blocks-1; }
|
int32_t getMaxIndex() const;
|
||||||
|
|
||||||
void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength);
|
void setBitfield(const unsigned char* bitfield, int32_t bitfieldLength);
|
||||||
|
|
||||||
|
@ -258,13 +224,9 @@ public:
|
||||||
*/
|
*/
|
||||||
int64_t getFilteredCompletedLengthNow() const;
|
int64_t getFilteredCompletedLengthNow() const;
|
||||||
|
|
||||||
void setRandomizer(const RandomizerHandle& randomizer) {
|
void setRandomizer(const SharedHandle<Randomizer>& randomizer);
|
||||||
this->randomizer = randomizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
RandomizerHandle getRandomizer() const {
|
SharedHandle<Randomizer> getRandomizer() const;
|
||||||
return randomizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateCache();
|
void updateCache();
|
||||||
|
|
||||||
|
@ -280,4 +242,6 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BITFIELD_MAN_H_
|
#endif // _D_BITFIELD_MAN_H_
|
||||||
|
|
|
@ -33,8 +33,51 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BitfieldManFactory.h"
|
#include "BitfieldManFactory.h"
|
||||||
#include "SimpleRandomizer.h"
|
#include "BitfieldMan.h"
|
||||||
|
#include "Randomizer.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BitfieldManFactoryHandle BitfieldManFactory::factory = 0;
|
BitfieldManFactoryHandle BitfieldManFactory::factory = 0;
|
||||||
|
|
||||||
|
BitfieldManFactoryHandle BitfieldManFactory::getFactoryInstance()
|
||||||
|
{
|
||||||
|
if(factory.isNull()) {
|
||||||
|
factory = new BitfieldManFactory();
|
||||||
|
}
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
BitfieldManFactory::BitfieldManFactory():randomizer(0) {}
|
BitfieldManFactory::BitfieldManFactory():randomizer(0) {}
|
||||||
|
|
||||||
|
BitfieldManFactory::~BitfieldManFactory() {}
|
||||||
|
|
||||||
|
BitfieldMan*
|
||||||
|
BitfieldManFactory::createBitfieldMan(int32_t blockLength, int64_t totalLength)
|
||||||
|
{
|
||||||
|
BitfieldMan* bitfieldMan = new BitfieldMan(blockLength, totalLength);
|
||||||
|
bitfieldMan->setRandomizer(randomizer);
|
||||||
|
return bitfieldMan;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BitfieldManFactory::setDefaultRandomizer(const RandomizerHandle& randomizer) {
|
||||||
|
BitfieldManFactoryHandle factory = getFactoryInstance();
|
||||||
|
factory->setRandomizer(randomizer);
|
||||||
|
}
|
||||||
|
|
||||||
|
RandomizerHandle BitfieldManFactory::getDefaultRandomizer()
|
||||||
|
{
|
||||||
|
return getFactoryInstance()->getRandomizer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BitfieldManFactory::setRandomizer(const RandomizerHandle& randomizer)
|
||||||
|
{
|
||||||
|
this->randomizer = randomizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
RandomizerHandle BitfieldManFactory::getRandomizer() const
|
||||||
|
{
|
||||||
|
return randomizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,52 +36,38 @@
|
||||||
#define _D_BITFIELD_MAN_FACTORY_H_
|
#define _D_BITFIELD_MAN_FACTORY_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "Randomizer.h"
|
#include "SharedHandle.h"
|
||||||
#include "BitfieldMan.h"
|
|
||||||
|
|
||||||
class BitfieldManFactory;
|
namespace aria2 {
|
||||||
|
|
||||||
typedef SharedHandle<BitfieldManFactory> BitfieldManFactoryHandle;
|
class Randomizer;
|
||||||
|
class BitfieldMan;
|
||||||
|
|
||||||
class BitfieldManFactory {
|
class BitfieldManFactory {
|
||||||
private:
|
private:
|
||||||
static BitfieldManFactoryHandle factory;
|
static SharedHandle<BitfieldManFactory> factory;
|
||||||
|
|
||||||
RandomizerHandle randomizer;
|
SharedHandle<Randomizer> randomizer;
|
||||||
|
|
||||||
BitfieldManFactory();
|
BitfieldManFactory();
|
||||||
public:
|
public:
|
||||||
~BitfieldManFactory() {}
|
~BitfieldManFactory();
|
||||||
|
|
||||||
static BitfieldManFactoryHandle getFactoryInstance() {
|
static SharedHandle<BitfieldManFactory> getFactoryInstance();
|
||||||
if(factory.isNull()) {
|
|
||||||
factory = new BitfieldManFactory();
|
|
||||||
}
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
BitfieldMan* createBitfieldMan(int32_t blockLength, int64_t totalLength) {
|
BitfieldMan* createBitfieldMan(int32_t blockLength, int64_t totalLength);
|
||||||
BitfieldMan* bitfieldMan = new BitfieldMan(blockLength, totalLength);
|
|
||||||
bitfieldMan->setRandomizer(randomizer);
|
|
||||||
return bitfieldMan;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setDefaultRandomizer(const RandomizerHandle& randomizer) {
|
static void setDefaultRandomizer(const SharedHandle<Randomizer>& randomizer);
|
||||||
BitfieldManFactoryHandle factory = getFactoryInstance();
|
|
||||||
factory->setRandomizer(randomizer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static RandomizerHandle getDefaultRandomizer() {
|
static SharedHandle<Randomizer> getDefaultRandomizer();
|
||||||
return getFactoryInstance()->getRandomizer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRandomizer(const RandomizerHandle& randomizer) {
|
void setRandomizer(const SharedHandle<Randomizer>& randomizer);
|
||||||
this->randomizer = randomizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
RandomizerHandle getRandomizer() const {
|
SharedHandle<Randomizer> getRandomizer() const;
|
||||||
return randomizer;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef SharedHandle<BitfieldManFactory> BitfieldManFactoryHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BITFIELD_MAN_FACTORY_H_
|
#endif // _D_BITFIELD_MAN_FACTORY_H_
|
||||||
|
|
|
@ -37,21 +37,27 @@
|
||||||
|
|
||||||
#include "BtEvent.h"
|
#include "BtEvent.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class Piece;
|
||||||
|
|
||||||
class BtAbortOutstandingRequestEvent : public BtEvent {
|
class BtAbortOutstandingRequestEvent : public BtEvent {
|
||||||
private:
|
private:
|
||||||
PieceHandle piece;
|
SharedHandle<Piece> piece;
|
||||||
public:
|
public:
|
||||||
BtAbortOutstandingRequestEvent(const PieceHandle& piece):piece(piece) {}
|
BtAbortOutstandingRequestEvent(const SharedHandle<Piece>& piece):piece(piece) {}
|
||||||
|
|
||||||
PieceHandle getPiece() const {
|
SharedHandle<Piece> getPiece() const {
|
||||||
return piece;
|
return piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPiece(const PieceHandle& piece) {
|
void setPiece(const SharedHandle<Piece>& piece) {
|
||||||
this->piece = piece;
|
this->piece = piece;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtAbortOutstandingRequestEvent> BtAbortOutstandingRequestEventHandle;
|
typedef SharedHandle<BtAbortOutstandingRequestEvent> BtAbortOutstandingRequestEventHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_ABORT_OUTSTANDING_REQUEST_EVENT_H_
|
#endif // _D_BT_ABORT_OUTSTANDING_REQUEST_EVENT_H_
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtAllowedFastMessageHandle BtAllowedFastMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 5) {
|
if(dataLength != 5) {
|
||||||
|
@ -84,6 +87,8 @@ void BtAllowedFastMessage::onSendComplete() {
|
||||||
peer->addAmAllowedIndex(index);
|
peer->addAmAllowedIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtAllowedFastMessage::toString() const {
|
std::string BtAllowedFastMessage::toString() const {
|
||||||
return "allowed fast index="+Util::itos(index);
|
return "allowed fast index="+Util::itos(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtAllowedFastMessage;
|
class BtAllowedFastMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtAllowedFastMessage> BtAllowedFastMessageHandle;
|
typedef SharedHandle<BtAllowedFastMessage> BtAllowedFastMessageHandle;
|
||||||
|
@ -74,10 +76,12 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
virtual void onSendComplete();
|
virtual void onSendComplete();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_ALLOWED_FAST_MESSAGE_H_
|
#endif // _D_BT_ALLOWED_FAST_MESSAGE_H_
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
|
|
||||||
#include "BtMessageValidator.h"
|
#include "BtMessageValidator.h"
|
||||||
#include "BtAllowedFastMessage.h"
|
#include "BtAllowedFastMessage.h"
|
||||||
|
#include "PeerMessageUtil.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtAllowedFastMessageValidator : public BtMessageValidator {
|
class BtAllowedFastMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
|
@ -57,4 +60,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtAllowedFastMessageValidator> BtAllowedFastMessageValidatorHandle;
|
typedef SharedHandle<BtAllowedFastMessageValidator> BtAllowedFastMessageValidatorHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_ALLOWED_FAST_MESSAGE_VALIDATOR_H_
|
#endif // _D_BT_ALLOWED_FAST_MESSAGE_VALIDATOR_H_
|
||||||
|
|
|
@ -36,6 +36,10 @@
|
||||||
#define _D_BT_ANNOUNCE_H_
|
#define _D_BT_ANNOUNCE_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtAnnounce {
|
class BtAnnounce {
|
||||||
public:
|
public:
|
||||||
|
@ -57,7 +61,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns announe URL with all necessary parameters included.
|
* Returns announe URL with all necessary parameters included.
|
||||||
*/
|
*/
|
||||||
virtual string getAnnounceUrl() = 0;
|
virtual std::string getAnnounceUrl() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells that the announce process has just started.
|
* Tells that the announce process has just started.
|
||||||
|
@ -103,4 +107,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtAnnounce> BtAnnounceHandle;
|
typedef SharedHandle<BtAnnounce> BtAnnounceHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_ANNOUNCE_H_
|
#endif // _D_BT_ANNOUNCE_H_
|
||||||
|
|
|
@ -37,6 +37,10 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) {
|
void BtBitfieldMessage::setBitfield(const unsigned char* bitfield, int32_t bitfieldLength) {
|
||||||
if(this->bitfield == bitfield) {
|
if(this->bitfield == bitfield) {
|
||||||
|
@ -90,6 +94,8 @@ int32_t BtBitfieldMessage::getMessageLength() {
|
||||||
return msgLength;
|
return msgLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtBitfieldMessage::toString() const {
|
std::string BtBitfieldMessage::toString() const {
|
||||||
return "bitfield "+Util::toHex(bitfield, bitfieldLength);
|
return "bitfield "+Util::toHex(bitfield, bitfieldLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtBitfieldMessage;
|
class BtBitfieldMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtBitfieldMessage> BtBitfieldMessageHandle;
|
typedef SharedHandle<BtBitfieldMessage> BtBitfieldMessageHandle;
|
||||||
|
@ -90,7 +92,9 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_BITFIELD_MESSAGE_H_
|
#endif // _D_BT_BITFIELD_MESSAGE_H_
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
#include "BtMessageValidator.h"
|
#include "BtMessageValidator.h"
|
||||||
#include "BtBitfieldMessage.h"
|
#include "BtBitfieldMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtBitfieldMessageValidator : public BtMessageValidator {
|
class BtBitfieldMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
const BtBitfieldMessage* message;
|
const BtBitfieldMessage* message;
|
||||||
|
@ -58,4 +60,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtBitfieldMessageValidator> BtBitfieldMessageValidatorHandle;
|
typedef SharedHandle<BtBitfieldMessageValidator> BtBitfieldMessageValidatorHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_BITFIELD_MESSAGE_VALIDATOR_H_
|
#endif // _D_BT_BITFIELD_MESSAGE_VALIDATOR_H_
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "BtMessageDispatcher.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtCancelMessageHandle BtCancelMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 13) {
|
if(dataLength != 13) {
|
||||||
|
@ -82,7 +85,9 @@ int32_t BtCancelMessage::getMessageLength() {
|
||||||
return MESSAGE_LENGTH;
|
return MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtCancelMessage::toString() const {
|
std::string BtCancelMessage::toString() const {
|
||||||
return "cancel index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
return "cancel index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||||
", length="+Util::itos(length);
|
", length="+Util::itos(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,7 +36,8 @@
|
||||||
#define _D_BT_CANCEL_MESSAGE_H_
|
#define _D_BT_CANCEL_MESSAGE_H_
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
#include "message.h"
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtCancelMessage;
|
class BtCancelMessage;
|
||||||
|
|
||||||
|
@ -86,7 +87,9 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CANCEL_MESSAGE_H_
|
#endif // _D_BT_CANCEL_MESSAGE_H_
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
|
|
||||||
#include "BtMessageValidator.h"
|
#include "BtMessageValidator.h"
|
||||||
#include "BtCancelMessage.h"
|
#include "BtCancelMessage.h"
|
||||||
|
#include "PeerMessageUtil.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtCancelMessageValidator : public BtMessageValidator {
|
class BtCancelMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
|
@ -64,4 +67,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtCancelMessageValidator> BtCancelMessageValidatorHandle;
|
typedef SharedHandle<BtCancelMessageValidator> BtCancelMessageValidatorHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CANCEL_MESSAGE_VALIDATOR_H_
|
#endif // _D_BT_CANCEL_MESSAGE_VALIDATOR_H_
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "BtEvent.h"
|
#include "BtEvent.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtCancelSendingPieceEvent : public BtEvent {
|
class BtCancelSendingPieceEvent : public BtEvent {
|
||||||
private:
|
private:
|
||||||
int32_t index;
|
int32_t index;
|
||||||
|
@ -75,4 +77,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtCancelSendingPieceEvent> BtCancelSendingPieceEventHandle;
|
typedef SharedHandle<BtCancelSendingPieceEvent> BtCancelSendingPieceEventHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CANCEL_SENDING_PIECE_EVENT_H_
|
#endif // _D_BT_CANCEL_SENDING_PIECE_EVENT_H_
|
||||||
|
|
|
@ -33,15 +33,15 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BtCheckIntegrityEntry.h"
|
#include "BtCheckIntegrityEntry.h"
|
||||||
#include "BtSetup.h"
|
|
||||||
#include "BtFileAllocationEntry.h"
|
#include "BtFileAllocationEntry.h"
|
||||||
#include "CUIDCounter.h"
|
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "FileAllocationMan.h"
|
#include "FileAllocationMan.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtCheckIntegrityEntry::BtCheckIntegrityEntry(RequestGroup* requestGroup):
|
BtCheckIntegrityEntry::BtCheckIntegrityEntry(RequestGroup* requestGroup):
|
||||||
PieceHashCheckIntegrityEntry(requestGroup, 0) {}
|
PieceHashCheckIntegrityEntry(requestGroup, 0) {}
|
||||||
|
|
||||||
|
@ -68,3 +68,5 @@ Commands BtCheckIntegrityEntry::onDownloadFinished(DownloadEngine* e)
|
||||||
// behavior.
|
// behavior.
|
||||||
return onDownloadIncomplete(e);
|
return onDownloadIncomplete(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,17 +37,21 @@
|
||||||
|
|
||||||
#include "PieceHashCheckIntegrityEntry.h"
|
#include "PieceHashCheckIntegrityEntry.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtCheckIntegrityEntry : public PieceHashCheckIntegrityEntry {
|
class BtCheckIntegrityEntry : public PieceHashCheckIntegrityEntry {
|
||||||
public:
|
public:
|
||||||
BtCheckIntegrityEntry(RequestGroup* requestGroup);
|
BtCheckIntegrityEntry(RequestGroup* requestGroup);
|
||||||
|
|
||||||
virtual ~BtCheckIntegrityEntry();
|
virtual ~BtCheckIntegrityEntry();
|
||||||
|
|
||||||
virtual Commands onDownloadFinished(DownloadEngine* e);
|
virtual std::deque<Command*> onDownloadFinished(DownloadEngine* e);
|
||||||
|
|
||||||
virtual Commands onDownloadIncomplete(DownloadEngine* e);
|
virtual std::deque<Command*> onDownloadIncomplete(DownloadEngine* e);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtCheckIntegrityEntry> BtCheckIntegrityEntryHandle;
|
typedef SharedHandle<BtCheckIntegrityEntry> BtCheckIntegrityEntryHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_FILE_ALLOCATION_ENTRY_H_
|
#endif // _D_BT_FILE_ALLOCATION_ENTRY_H_
|
||||||
|
|
|
@ -36,6 +36,11 @@
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
#include "BtMessageDispatcher.h"
|
||||||
|
#include "BtRequestFactory.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtChokeMessageHandle BtChokeMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 1) {
|
if(dataLength != 1) {
|
||||||
|
@ -83,6 +88,8 @@ void BtChokeMessage::onSendComplete() {
|
||||||
dispatcher->doChokingAction();
|
dispatcher->doChokingAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtChokeMessage::toString() const {
|
std::string BtChokeMessage::toString() const {
|
||||||
return "choke";
|
return "choke";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtChokeMessage;
|
class BtChokeMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtChokeMessage> BtChokeMessageHandle;
|
typedef SharedHandle<BtChokeMessage> BtChokeMessageHandle;
|
||||||
|
@ -63,7 +65,7 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
static BtChokeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
static BtChokeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
||||||
|
|
||||||
|
@ -72,4 +74,6 @@ public:
|
||||||
virtual void onSendComplete();
|
virtual void onSendComplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_CHOKE_MESSAGE_H_
|
#endif // _D_CHOKE_MESSAGE_H_
|
||||||
|
|
|
@ -36,10 +36,15 @@
|
||||||
#define _D_BT_CHOKED_EVENT_H_
|
#define _D_BT_CHOKED_EVENT_H_
|
||||||
|
|
||||||
#include "BtEvent.h"
|
#include "BtEvent.h"
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtChokedEvent : public BtEvent {
|
class BtChokedEvent : public BtEvent {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtChokedEvent> BtChokedEventHandle;
|
typedef SharedHandle<BtChokedEvent> BtChokedEventHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CHOKED_EVENT_H_
|
#endif // _D_BT_CHOKED_EVENT_H_
|
||||||
|
|
|
@ -37,9 +37,13 @@
|
||||||
|
|
||||||
#include "BtEvent.h"
|
#include "BtEvent.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtChokingEvent : public BtEvent {
|
class BtChokingEvent : public BtEvent {
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtChokingEvent> BtChokingEventHandle;
|
typedef SharedHandle<BtChokingEvent> BtChokingEventHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CHOKING_EVENT_H_
|
#endif // _D_BT_CHOKING_EVENT_H_
|
||||||
|
|
|
@ -38,6 +38,16 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
typedef map<string, uint8_t> Extensions;
|
typedef std::map<std::string, uint8_t> Extensions;
|
||||||
|
|
||||||
|
#define PEER_ID_LENGTH 20
|
||||||
|
|
||||||
|
#define INFO_HASH_LENGTH 20
|
||||||
|
|
||||||
|
#define MAX_PEER_ERROR 5
|
||||||
|
|
||||||
|
#define MAX_PEERS 55
|
||||||
|
|
||||||
|
#define DEFAULT_LATENCY 1500
|
||||||
|
|
||||||
#endif // _D_BT_CONSTANTS_
|
#endif // _D_BT_CONSTANTS_
|
||||||
|
|
|
@ -38,14 +38,9 @@
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "BtContextDecl.h"
|
#include "BtContextDecl.h"
|
||||||
|
|
||||||
#define INFO_HASH_LENGTH 20
|
namespace aria2 {
|
||||||
#define MAX_PEER_ERROR 5
|
|
||||||
#define MAX_PEERS 55
|
|
||||||
|
|
||||||
class AnnounceTier;
|
class AnnounceTier;
|
||||||
typedef SharedHandle<AnnounceTier> AnnounceTierHandle;
|
|
||||||
typedef deque<AnnounceTierHandle> AnnounceTiers;
|
|
||||||
|
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
|
|
||||||
class BtContext:public DownloadContext {
|
class BtContext:public DownloadContext {
|
||||||
|
@ -60,11 +55,12 @@ public:
|
||||||
|
|
||||||
virtual int32_t getInfoHashLength() const = 0;
|
virtual int32_t getInfoHashLength() const = 0;
|
||||||
|
|
||||||
virtual string getInfoHashAsString() const = 0;
|
virtual std::string getInfoHashAsString() const = 0;
|
||||||
|
|
||||||
virtual AnnounceTiers getAnnounceTiers() const = 0;
|
virtual std::deque<SharedHandle<AnnounceTier> >
|
||||||
|
getAnnounceTiers() const = 0;
|
||||||
|
|
||||||
virtual void load(const string& torrentFile) = 0;
|
virtual void load(const std::string& torrentFile) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the peer id of localhost, 20 byte length
|
* Returns the peer id of localhost, 20 byte length
|
||||||
|
@ -76,10 +72,13 @@ public:
|
||||||
return _private;
|
return _private;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Integers computeFastSet(const string& ipaddr, int32_t fastSetSize) = 0;
|
virtual std::deque<int32_t>
|
||||||
|
computeFastSet(const std::string& ipaddr, int32_t fastSetSize) = 0;
|
||||||
|
|
||||||
virtual RequestGroup* getOwnerRequestGroup() = 0;
|
virtual RequestGroup* getOwnerRequestGroup() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CONTEXT_H_
|
#endif // _D_BT_CONTEXT_H_
|
||||||
|
|
|
@ -34,6 +34,14 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BtContextAwareCommand.h"
|
#include "BtContextAwareCommand.h"
|
||||||
#include "BtRegistry.h"
|
#include "BtRegistry.h"
|
||||||
|
#include "BtContext.h"
|
||||||
|
#include "BtRuntime.h"
|
||||||
|
#include "PieceStorage.h"
|
||||||
|
#include "PeerStorage.h"
|
||||||
|
#include "BtAnnounce.h"
|
||||||
|
#include "BtProgressInfoFile.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtContextAwareCommand::BtContextAwareCommand(const BtContextHandle& btContext):
|
BtContextAwareCommand::BtContextAwareCommand(const BtContextHandle& btContext):
|
||||||
btContext(btContext),
|
btContext(btContext),
|
||||||
|
@ -44,3 +52,5 @@ BtContextAwareCommand::BtContextAwareCommand(const BtContextHandle& btContext):
|
||||||
btProgressInfoFile(BT_PROGRESS_INFO_FILE(btContext)) {}
|
btProgressInfoFile(BT_PROGRESS_INFO_FILE(btContext)) {}
|
||||||
|
|
||||||
BtContextAwareCommand::~BtContextAwareCommand() {}
|
BtContextAwareCommand::~BtContextAwareCommand() {}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,26 +36,32 @@
|
||||||
#define _D_BT_CONTEXT_AWARE_COMMAND_H_
|
#define _D_BT_CONTEXT_AWARE_COMMAND_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "BtContext.h"
|
#include "SharedHandle.h"
|
||||||
#include "BtRuntime.h"
|
|
||||||
#include "PieceStorage.h"
|
namespace aria2 {
|
||||||
#include "PeerStorage.h"
|
|
||||||
#include "BtAnnounce.h"
|
class BtContext;
|
||||||
#include "BtProgressInfoFile.h"
|
class BtRuntime;
|
||||||
|
class PieceStorage;
|
||||||
|
class PeerStorage;
|
||||||
|
class BtAnnounce;
|
||||||
|
class BtProgressInfoFile;
|
||||||
|
|
||||||
class BtContextAwareCommand
|
class BtContextAwareCommand
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
BtContextHandle btContext;
|
SharedHandle<BtContext> btContext;
|
||||||
BtRuntimeHandle btRuntime;
|
SharedHandle<BtRuntime> btRuntime;
|
||||||
PieceStorageHandle pieceStorage;
|
SharedHandle<PieceStorage> pieceStorage;
|
||||||
PeerStorageHandle peerStorage;
|
SharedHandle<PeerStorage> peerStorage;
|
||||||
BtAnnounceHandle btAnnounce;
|
SharedHandle<BtAnnounce> btAnnounce;
|
||||||
BtProgressInfoFileHandle btProgressInfoFile;
|
SharedHandle<BtProgressInfoFile> btProgressInfoFile;
|
||||||
public:
|
public:
|
||||||
BtContextAwareCommand(const BtContextHandle& btContext);
|
BtContextAwareCommand(const SharedHandle<BtContext>& btContext);
|
||||||
|
|
||||||
virtual ~BtContextAwareCommand();
|
virtual ~BtContextAwareCommand();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CONTEXT_AWARE_COMMAND_H_
|
#endif // _D_BT_CONTEXT_AWARE_COMMAND_H_
|
||||||
|
|
|
@ -37,7 +37,11 @@
|
||||||
|
|
||||||
#include "SharedHandle.h"
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtContext;
|
class BtContext;
|
||||||
typedef SharedHandle<BtContext> BtContextHandle;
|
typedef SharedHandle<BtContext> BtContextHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_CONTEXT_DECL_H_
|
#endif // _D_BT_CONTEXT_DECL_H_
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include "DefaultBtContext.h"
|
#include "DefaultBtContext.h"
|
||||||
#include "RecoverableException.h"
|
#include "RecoverableException.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
@ -43,6 +44,9 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
|
#include "File.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtDependency::BtDependency(const RequestGroupWeakHandle& dependant,
|
BtDependency::BtDependency(const RequestGroupWeakHandle& dependant,
|
||||||
const RequestGroupHandle& dependee,
|
const RequestGroupHandle& dependee,
|
||||||
|
@ -64,7 +68,7 @@ bool BtDependency::resolve()
|
||||||
try {
|
try {
|
||||||
DiskAdaptorHandle diskAdaptor = dependee->getPieceStorage()->getDiskAdaptor();
|
DiskAdaptorHandle diskAdaptor = dependee->getPieceStorage()->getDiskAdaptor();
|
||||||
diskAdaptor->openExistingFile();
|
diskAdaptor->openExistingFile();
|
||||||
string content = Util::toString(diskAdaptor);
|
std::string content = Util::toString(diskAdaptor);
|
||||||
btContext->loadFromMemory(content.c_str(), content.size(),
|
btContext->loadFromMemory(content.c_str(), content.size(),
|
||||||
File(dependee->getFilePath()).getBasename());
|
File(dependee->getFilePath()).getBasename());
|
||||||
if(_option->defined(PREF_PEER_ID_PREFIX)) {
|
if(_option->defined(PREF_PEER_ID_PREFIX)) {
|
||||||
|
@ -93,3 +97,5 @@ bool BtDependency::resolve()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,22 +37,22 @@
|
||||||
|
|
||||||
#include "Dependency.h"
|
#include "Dependency.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class RequestGroup;
|
class RequestGroup;
|
||||||
typedef WeakHandle<RequestGroup> RequestGroupWeakHandle;
|
|
||||||
typedef SharedHandle<RequestGroup> RequestGroupHandle;
|
|
||||||
class Option;
|
class Option;
|
||||||
class Logger;
|
class Logger;
|
||||||
|
|
||||||
class BtDependency : public Dependency
|
class BtDependency : public Dependency
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
RequestGroupWeakHandle _dependant;
|
WeakHandle<RequestGroup> _dependant;
|
||||||
RequestGroupHandle _dependee;
|
SharedHandle<RequestGroup> _dependee;
|
||||||
const Option* _option;
|
const Option* _option;
|
||||||
const Logger* _logger;
|
const Logger* _logger;
|
||||||
public:
|
public:
|
||||||
BtDependency(const RequestGroupWeakHandle& dependant,
|
BtDependency(const WeakHandle<RequestGroup>& dependant,
|
||||||
const RequestGroupHandle& dependee,
|
const SharedHandle<RequestGroup>& dependee,
|
||||||
const Option* option);
|
const Option* option);
|
||||||
|
|
||||||
virtual ~BtDependency();
|
virtual ~BtDependency();
|
||||||
|
@ -62,4 +62,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtDependency> BtDependencyHandle;
|
typedef SharedHandle<BtDependency> BtDependencyHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_DEPENDENCY_H_
|
#endif // _D_BT_DEPENDENCY_H_
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
#define _D_BT_EVENT_H_
|
#define _D_BT_EVENT_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
class BtEvent {
|
class BtEvent {
|
||||||
public:
|
public:
|
||||||
virtual ~BtEvent() {}
|
virtual ~BtEvent() {}
|
||||||
|
@ -44,4 +46,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtEvent> BtEventHandle;
|
typedef SharedHandle<BtEvent> BtEventHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_EVENT_H_
|
#endif // _D_BT_EVENT_H_
|
||||||
|
|
|
@ -36,16 +36,23 @@
|
||||||
#define _D_BT_EVENT_LISTENER_H_
|
#define _D_BT_EVENT_LISTENER_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "BtEvent.h"
|
#include "SharedHandle.h"
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class BtEvent;
|
||||||
|
|
||||||
class BtEventListener {
|
class BtEventListener {
|
||||||
public:
|
public:
|
||||||
virtual ~BtEventListener() {}
|
virtual ~BtEventListener() {}
|
||||||
|
|
||||||
virtual void handleEvent(const BtEventHandle& event) = 0;
|
virtual void handleEvent(const SharedHandle<BtEvent>& event) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtEventListener> BtEventListenerHandle;
|
typedef SharedHandle<BtEventListener> BtEventListenerHandle;
|
||||||
typedef deque<BtEventListenerHandle> BtEventListeners;
|
typedef std::deque<BtEventListenerHandle> BtEventListeners;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_EVENT_LISTENER_H_
|
#endif // _D_BT_EVENT_LISTENER_H_
|
||||||
|
|
|
@ -34,11 +34,24 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BtExtendedMessage.h"
|
#include "BtExtendedMessage.h"
|
||||||
#include "BtRegistry.h"
|
#include "BtRegistry.h"
|
||||||
|
#include "PeerObject.h"
|
||||||
|
#include "BtMessageFactory.h"
|
||||||
|
#include "BtMessageReceiver.h"
|
||||||
|
#include "BtMessageDispatcher.h"
|
||||||
|
#include "BtRequestFactory.h"
|
||||||
|
#include "PeerConnection.h"
|
||||||
#include "ExtensionMessage.h"
|
#include "ExtensionMessage.h"
|
||||||
|
#include "ExtensionMessageFactory.h"
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
#include "BtContext.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtExtendedMessage::BtExtendedMessage(const ExtensionMessageHandle& extensionMessage):_extensionMessage(extensionMessage), _msg(0), _msgLength(0)
|
BtExtendedMessage::BtExtendedMessage(const ExtensionMessageHandle& extensionMessage):_extensionMessage(extensionMessage), _msg(0), _msgLength(0)
|
||||||
{}
|
{}
|
||||||
|
@ -57,7 +70,7 @@ const unsigned char* BtExtendedMessage::getMessage() {
|
||||||
* extpayload --- extpayload, nbytes
|
* extpayload --- extpayload, nbytes
|
||||||
* total: 6+extpayload.length bytes
|
* total: 6+extpayload.length bytes
|
||||||
*/
|
*/
|
||||||
string payload = _extensionMessage->getBencodedData();
|
std::string payload = _extensionMessage->getBencodedData();
|
||||||
_msgLength = 6+payload.size();
|
_msgLength = 6+payload.size();
|
||||||
_msg = new unsigned char[_msgLength];
|
_msg = new unsigned char[_msgLength];
|
||||||
PeerMessageUtil::createPeerMessageString(_msg, _msgLength, 2+payload.size(), ID);
|
PeerMessageUtil::createPeerMessageString(_msg, _msgLength, 2+payload.size(), ID);
|
||||||
|
@ -77,7 +90,7 @@ bool BtExtendedMessage::sendPredicate() const
|
||||||
return peer->isExtendedMessagingEnabled();
|
return peer->isExtendedMessagingEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtExtendedMessage::toString() const {
|
std::string BtExtendedMessage::toString() const {
|
||||||
return "extended "+_extensionMessage->toString();
|
return "extended "+_extensionMessage->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,3 +126,5 @@ ExtensionMessageHandle BtExtendedMessage::getExtensionMessage() const
|
||||||
{
|
{
|
||||||
return _extensionMessage;
|
return _extensionMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,28 +36,30 @@
|
||||||
#define _D_BT_EXTENDED_MESSAGE_H_
|
#define _D_BT_EXTENDED_MESSAGE_H_
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class ExtensionMessage;
|
||||||
|
|
||||||
class BtExtendedMessage;
|
class BtExtendedMessage;
|
||||||
typedef SharedHandle<BtExtendedMessage> BtExtendedMessageHandle;
|
typedef SharedHandle<BtExtendedMessage> BtExtendedMessageHandle;
|
||||||
class ExtensionMessage;
|
|
||||||
typedef SharedHandle<ExtensionMessage> ExtensionMessageHandle;
|
|
||||||
|
|
||||||
class BtExtendedMessage:public SimpleBtMessage
|
class BtExtendedMessage:public SimpleBtMessage
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ExtensionMessageHandle _extensionMessage;
|
SharedHandle<ExtensionMessage> _extensionMessage;
|
||||||
|
|
||||||
unsigned char* _msg;
|
unsigned char* _msg;
|
||||||
|
|
||||||
size_t _msgLength;
|
size_t _msgLength;
|
||||||
public:
|
public:
|
||||||
BtExtendedMessage(const ExtensionMessageHandle& extensionMessage = 0);
|
BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage = 0);
|
||||||
|
|
||||||
virtual ~BtExtendedMessage();
|
virtual ~BtExtendedMessage();
|
||||||
|
|
||||||
static const uint8_t ID = 20;
|
static const uint8_t ID = 20;
|
||||||
|
|
||||||
static BtExtendedMessageHandle create(const BtContextHandle& btContext,
|
static BtExtendedMessageHandle create(const SharedHandle<BtContext>& btContext,
|
||||||
const PeerHandle& peer,
|
const SharedHandle<Peer>& peer,
|
||||||
const char* data,
|
const char* data,
|
||||||
size_t dataLength);
|
size_t dataLength);
|
||||||
|
|
||||||
|
@ -71,9 +73,11 @@ public:
|
||||||
|
|
||||||
virtual bool sendPredicate() const;
|
virtual bool sendPredicate() const;
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
ExtensionMessageHandle getExtensionMessage() const;
|
SharedHandle<ExtensionMessage> getExtensionMessage() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_EXTENDED_MESSAGE_H_
|
#endif // _D_BT_EXTENDED_MESSAGE_H_
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtFileAllocationEntry::BtFileAllocationEntry(RequestGroup* requestGroup):
|
BtFileAllocationEntry::BtFileAllocationEntry(RequestGroup* requestGroup):
|
||||||
FileAllocationEntry(requestGroup, 0) {}
|
FileAllocationEntry(requestGroup, 0) {}
|
||||||
|
|
||||||
|
@ -52,3 +54,5 @@ Commands BtFileAllocationEntry::prepareForNextAction(DownloadEngine* e)
|
||||||
}
|
}
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,10 +37,7 @@
|
||||||
|
|
||||||
#include "FileAllocationEntry.h"
|
#include "FileAllocationEntry.h"
|
||||||
|
|
||||||
class RequestGroup;
|
namespace aria2 {
|
||||||
class DownloadEngine;
|
|
||||||
class Command;
|
|
||||||
typedef deque<Command*> Commands;
|
|
||||||
|
|
||||||
class BtFileAllocationEntry : public FileAllocationEntry {
|
class BtFileAllocationEntry : public FileAllocationEntry {
|
||||||
public:
|
public:
|
||||||
|
@ -48,9 +45,11 @@ public:
|
||||||
|
|
||||||
virtual ~BtFileAllocationEntry();
|
virtual ~BtFileAllocationEntry();
|
||||||
|
|
||||||
virtual Commands prepareForNextAction(DownloadEngine* e);
|
virtual std::deque<Command*> prepareForNextAction(DownloadEngine* e);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtFileAllocationEntry> BtFileAllocationEntryHandle;
|
typedef SharedHandle<BtFileAllocationEntry> BtFileAllocationEntryHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_FILE_ALLOCATION_ENTRY_H_
|
#endif // _D_BT_FILE_ALLOCATION_ENTRY_H_
|
||||||
|
|
|
@ -35,6 +35,10 @@
|
||||||
#include "BtHandshakeMessage.h"
|
#include "BtHandshakeMessage.h"
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "BtConstants.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
const unsigned char* BtHandshakeMessage::BT_PSTR = (const unsigned char*)"BitTorrent protocol";
|
const unsigned char* BtHandshakeMessage::BT_PSTR = (const unsigned char*)"BitTorrent protocol";
|
||||||
|
|
||||||
|
@ -65,8 +69,10 @@ void BtHandshakeMessage::init() {
|
||||||
this->reserved[5] |= 0x10;
|
this->reserved[5] |= 0x10;
|
||||||
}
|
}
|
||||||
|
|
||||||
BtHandshakeMessageHandle BtHandshakeMessage::create(const unsigned char* data, int32_t dataLength) {
|
SharedHandle<BtHandshakeMessage>
|
||||||
BtHandshakeMessageHandle message = new BtHandshakeMessage();
|
BtHandshakeMessage::create(const unsigned char* data, int32_t dataLength)
|
||||||
|
{
|
||||||
|
SharedHandle<BtHandshakeMessage> message = new BtHandshakeMessage();
|
||||||
message->pstrlen = data[0];
|
message->pstrlen = data[0];
|
||||||
memcpy(message->pstr, &data[1], PSTR_LENGTH);
|
memcpy(message->pstr, &data[1], PSTR_LENGTH);
|
||||||
memcpy(message->reserved, &data[20], RESERVED_LENGTH);
|
memcpy(message->reserved, &data[20], RESERVED_LENGTH);
|
||||||
|
@ -91,7 +97,7 @@ int32_t BtHandshakeMessage::getMessageLength() {
|
||||||
return MESSAGE_LENGTH;
|
return MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtHandshakeMessage::toString() const {
|
std::string BtHandshakeMessage::toString() const {
|
||||||
return "handshake peerId="+
|
return "handshake peerId="+
|
||||||
Util::urlencode(peerId, PEER_ID_LENGTH)+
|
Util::urlencode(peerId, PEER_ID_LENGTH)+
|
||||||
", reserved="+Util::toHex(reserved, RESERVED_LENGTH);
|
", reserved="+Util::toHex(reserved, RESERVED_LENGTH);
|
||||||
|
@ -111,3 +117,14 @@ bool BtHandshakeMessage::isDHTEnabled() const
|
||||||
return reserved[7]&0x01;
|
return reserved[7]&0x01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BtHandshakeMessage::setInfoHash(const unsigned char* infoHash)
|
||||||
|
{
|
||||||
|
memcpy(this->infoHash, infoHash, INFO_HASH_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BtHandshakeMessage::setPeerId(const unsigned char* peerId)
|
||||||
|
{
|
||||||
|
memcpy(this->peerId, peerId, PEER_ID_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,9 +37,7 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
class BtHandshakeMessage;
|
namespace aria2 {
|
||||||
|
|
||||||
typedef SharedHandle<BtHandshakeMessage> BtHandshakeMessageHandle;
|
|
||||||
|
|
||||||
class BtHandshakeMessage : public SimpleBtMessage {
|
class BtHandshakeMessage : public SimpleBtMessage {
|
||||||
public:
|
public:
|
||||||
|
@ -63,7 +61,8 @@ public:
|
||||||
*/
|
*/
|
||||||
BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId);
|
BtHandshakeMessage(const unsigned char* infoHash, const unsigned char* peerId);
|
||||||
|
|
||||||
static BtHandshakeMessageHandle create(const unsigned char* data, int32_t dataLength);
|
static SharedHandle<BtHandshakeMessage>
|
||||||
|
create(const unsigned char* data, int32_t dataLength);
|
||||||
|
|
||||||
virtual ~BtHandshakeMessage() {
|
virtual ~BtHandshakeMessage() {
|
||||||
delete [] msg;
|
delete [] msg;
|
||||||
|
@ -83,7 +82,7 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
bool isFastExtensionSupported() const;
|
bool isFastExtensionSupported() const;
|
||||||
|
|
||||||
|
@ -116,17 +115,15 @@ public:
|
||||||
return infoHash;
|
return infoHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInfoHash(const unsigned char* infoHash) {
|
void setInfoHash(const unsigned char* infoHash);
|
||||||
memcpy(this->infoHash, infoHash, INFO_HASH_LENGTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
const unsigned char* getPeerId() const {
|
const unsigned char* getPeerId() const {
|
||||||
return peerId;
|
return peerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPeerId(const unsigned char* peerId) {
|
void setPeerId(const unsigned char* peerId);
|
||||||
memcpy(this->peerId, peerId, PEER_ID_LENGTH);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_HANDSHAKE_MESSAGE_H_
|
#endif // _D_HANDSHAKE_MESSAGE_H_
|
||||||
|
|
|
@ -38,6 +38,10 @@
|
||||||
#include "BtMessageValidator.h"
|
#include "BtMessageValidator.h"
|
||||||
#include "BtHandshakeMessage.h"
|
#include "BtHandshakeMessage.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "PeerMessageUtil.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtHandshakeMessageValidator : public BtMessageValidator {
|
class BtHandshakeMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
|
@ -72,4 +76,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtHandshakeMessageValidator> BtHandshakeMessageValidatorHandle;
|
typedef SharedHandle<BtHandshakeMessageValidator> BtHandshakeMessageValidatorHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_HANDSHAKE_MESSAGE_VALIDATOR_H_
|
#endif // _D_BT_HANDSHAKE_MESSAGE_VALIDATOR_H_
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtHaveAllMessageHandle BtHaveAllMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 1) {
|
if(dataLength != 1) {
|
||||||
|
@ -76,6 +79,8 @@ int32_t BtHaveAllMessage::getMessageLength() {
|
||||||
return MESSAGE_LENGTH;
|
return MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtHaveAllMessage::toString() const {
|
std::string BtHaveAllMessage::toString() const {
|
||||||
return "have all";
|
return "have all";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtHaveAllMessage;
|
class BtHaveAllMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtHaveAllMessage> BtHaveAllMessageHandle;
|
typedef SharedHandle<BtHaveAllMessage> BtHaveAllMessageHandle;
|
||||||
|
@ -65,7 +67,9 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_HAVE_ALL_MESSAGE_H_
|
#endif // _D_BT_HAVE_ALL_MESSAGE_H_
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtHaveMessageHandle BtHaveMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 5) {
|
if(dataLength != 5) {
|
||||||
|
@ -76,6 +79,8 @@ int32_t BtHaveMessage::getMessageLength() {
|
||||||
return MESSAGE_LENGTH;
|
return MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtHaveMessage::toString() const {
|
std::string BtHaveMessage::toString() const {
|
||||||
return "have index="+Util::itos(index);
|
return "have index="+Util::itos(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtHaveMessage;
|
class BtHaveMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtHaveMessage> BtHaveMessageHandle;
|
typedef SharedHandle<BtHaveMessage> BtHaveMessageHandle;
|
||||||
|
@ -71,7 +73,9 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_HAVE_MESSAGE_H_
|
#endif // _D_BT_HAVE_MESSAGE_H_
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
#include "BtHaveMessage.h"
|
#include "BtHaveMessage.h"
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtHaveMessageValidator : public BtMessageValidator {
|
class BtHaveMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
const BtHaveMessage* message;
|
const BtHaveMessage* message;
|
||||||
|
@ -57,4 +59,6 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_HAVE_MESSAGE_VALIDATOR_H_
|
#endif // _D_BT_HAVE_MESSAGE_VALIDATOR_H_
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtHaveNoneMessageHandle BtHaveNoneMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 1) {
|
if(dataLength != 1) {
|
||||||
|
@ -75,6 +78,8 @@ int32_t BtHaveNoneMessage::getMessageLength() {
|
||||||
return MESSAGE_LENGTH;
|
return MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtHaveNoneMessage::toString() const {
|
std::string BtHaveNoneMessage::toString() const {
|
||||||
return "have none";
|
return "have none";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtHaveNoneMessage;
|
class BtHaveNoneMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtHaveNoneMessage> BtHaveNoneMessageHandle;
|
typedef SharedHandle<BtHaveNoneMessage> BtHaveNoneMessageHandle;
|
||||||
|
@ -65,7 +67,9 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_HAVE_NONE_MESSAGE_H_
|
#endif // _D_BT_HAVE_NONE_MESSAGE_H_
|
||||||
|
|
|
@ -36,7 +36,11 @@
|
||||||
#define _D_BT_INTERACTIVE_H_
|
#define _D_BT_INTERACTIVE_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "BtMessage.h"
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class BtMessage;
|
||||||
|
|
||||||
class BtInteractive {
|
class BtInteractive {
|
||||||
public:
|
public:
|
||||||
|
@ -44,9 +48,9 @@ public:
|
||||||
|
|
||||||
virtual void initiateHandshake() = 0;
|
virtual void initiateHandshake() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle receiveHandshake(bool quickReply = false) = 0;
|
virtual SharedHandle<BtMessage> receiveHandshake(bool quickReply = false) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle receiveAndSendHandshake() = 0;
|
virtual SharedHandle<BtMessage> receiveAndSendHandshake() = 0;
|
||||||
|
|
||||||
virtual void doPostHandshakeProcessing() = 0;
|
virtual void doPostHandshakeProcessing() = 0;
|
||||||
|
|
||||||
|
@ -63,4 +67,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtInteractive> BtInteractiveHandle;
|
typedef SharedHandle<BtInteractive> BtInteractiveHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_INTERACTIVE_H_
|
#endif // _D_BT_INTERACTIVE_H_
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtInterestedMessageHandle BtInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 1) {
|
if(dataLength != 1) {
|
||||||
|
@ -80,6 +83,8 @@ void BtInterestedMessage::onSendComplete() {
|
||||||
peer->amInterested = true;
|
peer->amInterested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtInterestedMessage::toString() const {
|
std::string BtInterestedMessage::toString() const {
|
||||||
return "interested";
|
return "interested";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtInterestedMessage;
|
class BtInterestedMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtInterestedMessage> BtInterestedMessageHandle;
|
typedef SharedHandle<BtInterestedMessage> BtInterestedMessageHandle;
|
||||||
|
@ -65,11 +67,13 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
virtual bool sendPredicate() const;
|
virtual bool sendPredicate() const;
|
||||||
|
|
||||||
virtual void onSendComplete();
|
virtual void onSendComplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_INTERESTED_MESSAGE_H_
|
#endif // _D_BT_INTERESTED_MESSAGE_H_
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "BtKeepAliveMessage.h"
|
#include "BtKeepAliveMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
int32_t BtKeepAliveMessage::MESSAGE_LENGTH = 4;
|
int32_t BtKeepAliveMessage::MESSAGE_LENGTH = 4;
|
||||||
|
|
||||||
const unsigned char* BtKeepAliveMessage::getMessage() {
|
const unsigned char* BtKeepAliveMessage::getMessage() {
|
||||||
|
@ -51,3 +53,5 @@ const unsigned char* BtKeepAliveMessage::getMessage() {
|
||||||
int32_t BtKeepAliveMessage::getMessageLength() {
|
int32_t BtKeepAliveMessage::getMessageLength() {
|
||||||
return MESSAGE_LENGTH;
|
return MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtKeepAliveMessage;
|
class BtKeepAliveMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtKeepAliveMessage> BtKeepAliveMessageHandle;
|
typedef SharedHandle<BtKeepAliveMessage> BtKeepAliveMessageHandle;
|
||||||
|
@ -63,9 +65,11 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const {
|
virtual std::string toString() const {
|
||||||
return "keep alive";
|
return "keep alive";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_KEEP_ALIVE_MESSAGE_H_
|
#endif // _D_BT_KEEP_ALIVE_MESSAGE_H_
|
||||||
|
|
|
@ -36,9 +36,13 @@
|
||||||
#define _D_BT_MESSAGE_H_
|
#define _D_BT_MESSAGE_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "Piece.h"
|
#include "SharedHandle.h"
|
||||||
#include "BtMessageValidator.h"
|
#include <string>
|
||||||
#include "BtEvent.h"
|
#include <deque>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class BtEvent;
|
||||||
|
|
||||||
class BtMessage {
|
class BtMessage {
|
||||||
public:
|
public:
|
||||||
|
@ -56,17 +60,19 @@ public:
|
||||||
|
|
||||||
virtual void send() = 0;
|
virtual void send() = 0;
|
||||||
|
|
||||||
virtual bool validate(Errors& errors) = 0;
|
virtual bool validate(std::deque<std::string>& errors) = 0;
|
||||||
|
|
||||||
virtual void handleEvent(const BtEventHandle& event) = 0;
|
virtual void handleEvent(const SharedHandle<BtEvent>& event) = 0;
|
||||||
|
|
||||||
virtual void onQueued() = 0;
|
virtual void onQueued() = 0;
|
||||||
|
|
||||||
virtual string toString() const = 0;
|
virtual std::string toString() const = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtMessage> BtMessageHandle;
|
typedef SharedHandle<BtMessage> BtMessageHandle;
|
||||||
typedef deque<BtMessageHandle> BtMessages;
|
typedef std::deque<BtMessageHandle> BtMessages;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_MESSAGE_H_
|
#endif // _D_BT_MESSAGE_H_
|
||||||
|
|
|
@ -36,25 +36,31 @@
|
||||||
#define _D_BT_MESSAGE_DISPATCHER_H_
|
#define _D_BT_MESSAGE_DISPATCHER_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "Piece.h"
|
#include "SharedHandle.h"
|
||||||
#include "BtMessage.h"
|
|
||||||
#include "RequestSlot.h"
|
#include "RequestSlot.h"
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class Piece;
|
||||||
|
class BtMessage;
|
||||||
|
|
||||||
class BtMessageDispatcher {
|
class BtMessageDispatcher {
|
||||||
public:
|
public:
|
||||||
virtual ~BtMessageDispatcher() {}
|
virtual ~BtMessageDispatcher() {}
|
||||||
|
|
||||||
virtual void addMessageToQueue(const BtMessageHandle& btMessage) = 0;
|
virtual void addMessageToQueue(const SharedHandle<BtMessage>& btMessage) = 0;
|
||||||
|
|
||||||
virtual void addMessageToQueue(const BtMessages& btMessages) = 0;
|
virtual void
|
||||||
|
addMessageToQueue(const std::deque<SharedHandle<BtMessage> >& btMessages) = 0;
|
||||||
|
|
||||||
virtual void sendMessages() = 0;
|
virtual void sendMessages() = 0;
|
||||||
|
|
||||||
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) = 0;
|
virtual void doCancelSendingPieceAction(int32_t index, int32_t begin, int32_t length) = 0;
|
||||||
|
|
||||||
virtual void doCancelSendingPieceAction(const PieceHandle& piece) = 0;
|
virtual void doCancelSendingPieceAction(const SharedHandle<Piece>& piece) = 0;
|
||||||
|
|
||||||
virtual void doAbortOutstandingRequestAction(const PieceHandle& piece) = 0;
|
virtual void doAbortOutstandingRequestAction(const SharedHandle<Piece>& piece) = 0;
|
||||||
|
|
||||||
virtual void doChokedAction() = 0;
|
virtual void doChokedAction() = 0;
|
||||||
|
|
||||||
|
@ -79,4 +85,7 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtMessageDispatcher> BtMessageDispatcherHandle;
|
typedef SharedHandle<BtMessageDispatcher> BtMessageDispatcherHandle;
|
||||||
typedef WeakHandle<BtMessageDispatcher> BtMessageDispatcherWeakHandle;
|
typedef WeakHandle<BtMessageDispatcher> BtMessageDispatcherWeakHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_MESSAGE_DISPATCHER_H_
|
#endif // _D_BT_MESSAGE_DISPATCHER_H_
|
||||||
|
|
|
@ -36,63 +36,69 @@
|
||||||
#define _D_BT_MESSAGE_FACTORY_H_
|
#define _D_BT_MESSAGE_FACTORY_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "BtMessage.h"
|
#include "SharedHandle.h"
|
||||||
#include "Piece.h"
|
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class BtMessage;
|
||||||
|
class Piece;
|
||||||
class ExtensionMessage;
|
class ExtensionMessage;
|
||||||
typedef SharedHandle<ExtensionMessage> ExensionMessageHandle;
|
|
||||||
|
|
||||||
class BtMessageFactory {
|
class BtMessageFactory {
|
||||||
public:
|
public:
|
||||||
virtual ~BtMessageFactory() {}
|
virtual ~BtMessageFactory() {}
|
||||||
|
|
||||||
virtual BtMessageHandle
|
virtual SharedHandle<BtMessage>
|
||||||
createBtMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
createBtMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle
|
virtual SharedHandle<BtMessage>
|
||||||
createHandshakeMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
createHandshakeMessage(const unsigned char* msg, int32_t msgLength) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle
|
virtual SharedHandle<BtMessage>
|
||||||
createHandshakeMessage(const unsigned char* infoHash,
|
createHandshakeMessage(const unsigned char* infoHash,
|
||||||
const unsigned char* peerId) = 0;
|
const unsigned char* peerId) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle
|
virtual SharedHandle<BtMessage>
|
||||||
createRequestMessage(const PieceHandle& piece, int32_t blockIndex) = 0;
|
createRequestMessage(const SharedHandle<Piece>& piece, int32_t blockIndex) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle
|
virtual SharedHandle<BtMessage>
|
||||||
createCancelMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
createCancelMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle
|
virtual SharedHandle<BtMessage>
|
||||||
createPieceMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
createPieceMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createHaveMessage(int32_t index) = 0;
|
virtual SharedHandle<BtMessage> createHaveMessage(int32_t index) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createChokeMessage() = 0;
|
virtual SharedHandle<BtMessage> createChokeMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createUnchokeMessage() = 0;
|
virtual SharedHandle<BtMessage> createUnchokeMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createInterestedMessage() = 0;
|
virtual SharedHandle<BtMessage> createInterestedMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createNotInterestedMessage() = 0;
|
virtual SharedHandle<BtMessage> createNotInterestedMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createBitfieldMessage() = 0;
|
virtual SharedHandle<BtMessage> createBitfieldMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createKeepAliveMessage() = 0;
|
virtual SharedHandle<BtMessage> createKeepAliveMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createHaveAllMessage() = 0;
|
virtual SharedHandle<BtMessage> createHaveAllMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createHaveNoneMessage() = 0;
|
virtual SharedHandle<BtMessage> createHaveNoneMessage() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle
|
virtual SharedHandle<BtMessage>
|
||||||
createRejectMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
createRejectMessage(int32_t index, int32_t begin, int32_t length) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createAllowedFastMessage(int32_t index) = 0;
|
virtual SharedHandle<BtMessage> createAllowedFastMessage(int32_t index) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createPortMessage(uint16_t port) = 0;
|
virtual SharedHandle<BtMessage> createPortMessage(uint16_t port) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle createBtExtendedMessage(const ExensionMessageHandle& msg) = 0;
|
virtual SharedHandle<BtMessage>
|
||||||
|
createBtExtendedMessage(const SharedHandle<ExtensionMessage>& msg) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtMessageFactory> BtMessageFactoryHandle;
|
typedef SharedHandle<BtMessageFactory> BtMessageFactoryHandle;
|
||||||
typedef WeakHandle<BtMessageFactory> BtMessageFactoryWeakHandle;
|
typedef WeakHandle<BtMessageFactory> BtMessageFactoryWeakHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_MESSAGE_FACTORY_H_
|
#endif // _D_BT_MESSAGE_FACTORY_H_
|
||||||
|
|
|
@ -36,20 +36,26 @@
|
||||||
#define _D_BT_MESSAGE_RECEIVER_H_
|
#define _D_BT_MESSAGE_RECEIVER_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "BtMessage.h"
|
#include "SharedHandle.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class BtMessage;
|
||||||
|
|
||||||
class BtMessageReceiver {
|
class BtMessageReceiver {
|
||||||
public:
|
public:
|
||||||
virtual ~BtMessageReceiver() {}
|
virtual ~BtMessageReceiver() {}
|
||||||
|
|
||||||
virtual BtMessageHandle receiveHandshake(bool quickReply = false) = 0;
|
virtual SharedHandle<BtMessage> receiveHandshake(bool quickReply = false) = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle receiveAndSendHandshake() = 0;
|
virtual SharedHandle<BtMessage> receiveAndSendHandshake() = 0;
|
||||||
|
|
||||||
virtual BtMessageHandle receiveMessage() = 0;
|
virtual SharedHandle<BtMessage> receiveMessage() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtMessageReceiver> BtMessageReceiverHandle;
|
typedef SharedHandle<BtMessageReceiver> BtMessageReceiverHandle;
|
||||||
typedef WeakHandle<BtMessageReceiver> BtMessageReceiverWeakHandle;
|
typedef WeakHandle<BtMessageReceiver> BtMessageReceiverWeakHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_MESSAGE_RECEIVER_H_
|
#endif // _D_BT_MESSAGE_RECEIVER_H_
|
||||||
|
|
|
@ -36,9 +36,13 @@
|
||||||
#define _D_BT_MESSAGE_VALIDATOR_H_
|
#define _D_BT_MESSAGE_VALIDATOR_H_
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "BtMessage.h"
|
#include "SharedHandle.h"
|
||||||
|
#include <string>
|
||||||
|
#include <deque>
|
||||||
|
|
||||||
typedef Strings Errors;
|
namespace aria2 {
|
||||||
|
|
||||||
|
typedef std::deque<std::string> Errors;
|
||||||
|
|
||||||
class BtMessageValidator {
|
class BtMessageValidator {
|
||||||
public:
|
public:
|
||||||
|
@ -49,4 +53,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtMessageValidator> BtMessageValidatorHandle;
|
typedef SharedHandle<BtMessageValidator> BtMessageValidatorHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_MESSAGE_VALIDATOR_H_
|
#endif // _D_BT_MESSAGE_VALIDATOR_H_
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
#include "PeerMessageUtil.h"
|
#include "PeerMessageUtil.h"
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
BtNotInterestedMessageHandle BtNotInterestedMessage::create(const unsigned char* data, int32_t dataLength) {
|
||||||
if(dataLength != 1) {
|
if(dataLength != 1) {
|
||||||
|
@ -80,6 +83,8 @@ void BtNotInterestedMessage::onSendComplete() {
|
||||||
peer->amInterested = false;
|
peer->amInterested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtNotInterestedMessage::toString() const {
|
std::string BtNotInterestedMessage::toString() const {
|
||||||
return "not interested";
|
return "not interested";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtNotInterestedMessage;
|
class BtNotInterestedMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtNotInterestedMessage> BtNotInterestedMessageHandle;
|
typedef SharedHandle<BtNotInterestedMessage> BtNotInterestedMessageHandle;
|
||||||
|
@ -65,11 +67,13 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
virtual bool sendPredicate() const;
|
virtual bool sendPredicate() const;
|
||||||
|
|
||||||
virtual void onSendComplete();
|
virtual void onSendComplete();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_NOT_INTERESTED_MESSAGE_H_
|
#endif // _D_BT_NOT_INTERESTED_MESSAGE_H_
|
||||||
|
|
|
@ -41,6 +41,18 @@
|
||||||
#include "BtCancelSendingPieceEvent.h"
|
#include "BtCancelSendingPieceEvent.h"
|
||||||
#include "MessageDigestHelper.h"
|
#include "MessageDigestHelper.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
#include "Peer.h"
|
||||||
|
#include "Piece.h"
|
||||||
|
#include "BtContext.h"
|
||||||
|
#include "PieceStorage.h"
|
||||||
|
#include "BtMessageDispatcher.h"
|
||||||
|
#include "BtMessageFactory.h"
|
||||||
|
#include "BtRequestFactory.h"
|
||||||
|
#include "PeerConnection.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
void BtPieceMessage::setBlock(const unsigned char* block, int32_t blockLength) {
|
void BtPieceMessage::setBlock(const unsigned char* block, int32_t blockLength) {
|
||||||
delete [] this->block;
|
delete [] this->block;
|
||||||
|
@ -184,7 +196,7 @@ int32_t BtPieceMessage::sendPieceData(int64_t offset, int32_t length) const {
|
||||||
return writtenLength;
|
return writtenLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtPieceMessage::toString() const {
|
std::string BtPieceMessage::toString() const {
|
||||||
return "piece index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
return "piece index="+Util::itos(index)+", begin="+Util::itos(begin)+
|
||||||
", length="+Util::itos(blockLength);
|
", length="+Util::itos(blockLength);
|
||||||
}
|
}
|
||||||
|
@ -282,3 +294,5 @@ void BtPieceMessage::handleCancelSendingPieceEvent(const BtEventHandle& event) {
|
||||||
invalidate = true;
|
invalidate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,11 +36,12 @@
|
||||||
#define _D_BT_PIECE_MESSAGE_H_
|
#define _D_BT_PIECE_MESSAGE_H_
|
||||||
|
|
||||||
#include "AbstractBtMessage.h"
|
#include "AbstractBtMessage.h"
|
||||||
#include "BtContext.h"
|
|
||||||
#include "PieceStorage.h"
|
|
||||||
#include "BtEvent.h"
|
|
||||||
#include "AbstractBtEventListener.h"
|
#include "AbstractBtEventListener.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
class BtEvent;
|
||||||
|
class Piece;
|
||||||
class BtPieceMessage;
|
class BtPieceMessage;
|
||||||
|
|
||||||
typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
|
typedef SharedHandle<BtPieceMessage> BtPieceMessageHandle;
|
||||||
|
@ -57,13 +58,13 @@ private:
|
||||||
|
|
||||||
static int32_t MESSAGE_HEADER_LENGTH;
|
static int32_t MESSAGE_HEADER_LENGTH;
|
||||||
|
|
||||||
bool checkPieceHash(const PieceHandle& piece);
|
bool checkPieceHash(const SharedHandle<Piece>& piece);
|
||||||
|
|
||||||
void onNewPiece(const PieceHandle& piece);
|
void onNewPiece(const SharedHandle<Piece>& piece);
|
||||||
|
|
||||||
void onWrongPiece(const PieceHandle& piece);
|
void onWrongPiece(const SharedHandle<Piece>& piece);
|
||||||
|
|
||||||
void erasePieceOnDisk(const PieceHandle& piece);
|
void erasePieceOnDisk(const SharedHandle<Piece>& piece);
|
||||||
|
|
||||||
int32_t sendPieceData(int64_t offset, int32_t length) const;
|
int32_t sendPieceData(int64_t offset, int32_t length) const;
|
||||||
|
|
||||||
|
@ -73,9 +74,9 @@ private:
|
||||||
public:
|
public:
|
||||||
BtChokingEventListener(BtPieceMessage* message):message(message) {}
|
BtChokingEventListener(BtPieceMessage* message):message(message) {}
|
||||||
|
|
||||||
virtual bool canHandle(const BtEventHandle& btEvent);
|
virtual bool canHandle(const SharedHandle<BtEvent>& btEvent);
|
||||||
|
|
||||||
virtual void handleEventInternal(const BtEventHandle& btEvent);
|
virtual void handleEventInternal(const SharedHandle<BtEvent>& btEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtChokingEventListener> BtChokingEventListenerHandle;
|
typedef SharedHandle<BtChokingEventListener> BtChokingEventListenerHandle;
|
||||||
|
@ -86,9 +87,9 @@ private:
|
||||||
public:
|
public:
|
||||||
BtCancelSendingPieceEventListener(BtPieceMessage* message):message(message) {}
|
BtCancelSendingPieceEventListener(BtPieceMessage* message):message(message) {}
|
||||||
|
|
||||||
virtual bool canHandle(const BtEventHandle& btEvent);
|
virtual bool canHandle(const SharedHandle<BtEvent>& btEvent);
|
||||||
|
|
||||||
virtual void handleEventInternal(const BtEventHandle& btEvent);
|
virtual void handleEventInternal(const SharedHandle<BtEvent>& btEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<BtCancelSendingPieceEventListener> BtCancelSendingPieceEventListenerHandle;
|
typedef SharedHandle<BtCancelSendingPieceEventListener> BtCancelSendingPieceEventListenerHandle;
|
||||||
|
@ -142,11 +143,13 @@ public:
|
||||||
|
|
||||||
virtual void send();
|
virtual void send();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
void handleChokingEvent(const BtEventHandle& event);
|
void handleChokingEvent(const SharedHandle<BtEvent>& event);
|
||||||
|
|
||||||
void handleCancelSendingPieceEvent(const BtEventHandle& event);
|
void handleCancelSendingPieceEvent(const SharedHandle<BtEvent>& event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_PIECE_MESSAGE_H_
|
#endif // _D_BT_PIECE_MESSAGE_H_
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
|
|
||||||
#include "BtMessageValidator.h"
|
#include "BtMessageValidator.h"
|
||||||
#include "BtPieceMessage.h"
|
#include "BtPieceMessage.h"
|
||||||
|
#include "PeerMessageUtil.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
class BtPieceMessageValidator : public BtMessageValidator {
|
class BtPieceMessageValidator : public BtMessageValidator {
|
||||||
private:
|
private:
|
||||||
|
@ -61,4 +64,6 @@ public:
|
||||||
|
|
||||||
typedef SharedHandle<BtPieceMessageValidator> BtPieceMessageValidatorHandle;
|
typedef SharedHandle<BtPieceMessageValidator> BtPieceMessageValidatorHandle;
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_PIECE_MESSAGE_VALIDATOR_H_
|
#endif // _D_BT_PIECE_MESSAGE_VALIDATOR_H_
|
||||||
|
|
|
@ -37,11 +37,15 @@
|
||||||
#include "DlAbortEx.h"
|
#include "DlAbortEx.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
#include "Peer.h"
|
||||||
#include "DHTNode.h"
|
#include "DHTNode.h"
|
||||||
#include "DHTTaskQueue.h"
|
#include "DHTTaskQueue.h"
|
||||||
#include "DHTTaskFactory.h"
|
#include "DHTTaskFactory.h"
|
||||||
#include "DHTTask.h"
|
#include "DHTTask.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtPortMessage::BtPortMessage(uint16_t port): _port(port), _msg(0) {}
|
BtPortMessage::BtPortMessage(uint16_t port): _port(port), _msg(0) {}
|
||||||
|
|
||||||
BtPortMessage::~BtPortMessage()
|
BtPortMessage::~BtPortMessage()
|
||||||
|
@ -68,10 +72,10 @@ void BtPortMessage::doReceivedAction()
|
||||||
if(!_taskFactory.isNull() && !_taskQueue.isNull()) {
|
if(!_taskFactory.isNull() && !_taskQueue.isNull()) {
|
||||||
// node id is random at this point. When ping reply received, new DHTNode
|
// 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.
|
// instance created with proper node ID and is added to a routing table.
|
||||||
DHTNodeHandle node = new DHTNode();
|
SharedHandle<DHTNode> node = new DHTNode();
|
||||||
node->setIPAddress(peer->ipaddr);
|
node->setIPAddress(peer->ipaddr);
|
||||||
node->setPort(_port);
|
node->setPort(_port);
|
||||||
DHTTaskHandle task = _taskFactory->createPingTask(node);
|
SharedHandle<DHTTask> task = _taskFactory->createPingTask(node);
|
||||||
_taskQueue->addImmediateTask(task);
|
_taskQueue->addImmediateTask(task);
|
||||||
} else {
|
} else {
|
||||||
logger->info("DHT port message received while localhost didn't declare support it.");
|
logger->info("DHT port message received while localhost didn't declare support it.");
|
||||||
|
@ -97,7 +101,7 @@ int32_t BtPortMessage::getMessageLength() {
|
||||||
return MESSAGE_LENGTH;
|
return MESSAGE_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
string BtPortMessage::toString() const {
|
std::string BtPortMessage::toString() const {
|
||||||
return "port port="+Util::uitos(_port);
|
return "port port="+Util::uitos(_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,3 +114,5 @@ void BtPortMessage::setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory
|
||||||
{
|
{
|
||||||
_taskFactory = taskFactory;
|
_taskFactory = taskFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
|
@ -36,8 +36,11 @@
|
||||||
#define _D_BT_PORT_MESSAGE_H_
|
#define _D_BT_PORT_MESSAGE_H_
|
||||||
|
|
||||||
#include "SimpleBtMessage.h"
|
#include "SimpleBtMessage.h"
|
||||||
#include "DHTTaskQueueDecl.h"
|
|
||||||
#include "DHTTaskFactoryDecl.h"
|
namespace aria2 {
|
||||||
|
|
||||||
|
class DHTTaskQueue;
|
||||||
|
class DHTTaskFactory;
|
||||||
|
|
||||||
class BtPortMessage : public SimpleBtMessage {
|
class BtPortMessage : public SimpleBtMessage {
|
||||||
private:
|
private:
|
||||||
|
@ -67,11 +70,13 @@ public:
|
||||||
|
|
||||||
virtual int32_t getMessageLength();
|
virtual int32_t getMessageLength();
|
||||||
|
|
||||||
virtual string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
||||||
void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue);
|
void setTaskQueue(const WeakHandle<DHTTaskQueue>& taskQueue);
|
||||||
|
|
||||||
void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory);
|
void setTaskFactory(const WeakHandle<DHTTaskFactory>& taskFactory);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // _D_BT_PORT_MESSAGE_H_
|
#endif // _D_BT_PORT_MESSAGE_H_
|
||||||
|
|
|
@ -44,6 +44,9 @@
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "ContentTypeRequestGroupCriteria.h"
|
#include "ContentTypeRequestGroupCriteria.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
BtPostDownloadHandler::BtPostDownloadHandler()
|
BtPostDownloadHandler::BtPostDownloadHandler()
|
||||||
{
|
{
|
||||||
|
@ -58,9 +61,9 @@ RequestGroups BtPostDownloadHandler::getNextRequestGroups(RequestGroup* requestG
|
||||||
const Option* op = requestGroup->getOption();
|
const Option* op = requestGroup->getOption();
|
||||||
_logger->debug("Generating RequestGroups for Torrent file %s",
|
_logger->debug("Generating RequestGroups for Torrent file %s",
|
||||||
requestGroup->getFilePath().c_str());
|
requestGroup->getFilePath().c_str());
|
||||||
RequestGroupHandle rg = new RequestGroup(op, Strings());
|
RequestGroupHandle rg = new RequestGroup(op, std::deque<std::string>());
|
||||||
|
|
||||||
string content;
|
std::string content;
|
||||||
try {
|
try {
|
||||||
requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile();
|
requestGroup->getPieceStorage()->getDiskAdaptor()->openExistingFile();
|
||||||
content = Util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
content = Util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
||||||
|
@ -83,3 +86,5 @@ RequestGroups BtPostDownloadHandler::getNextRequestGroups(RequestGroup* requestG
|
||||||
groups.push_back(rg);
|
groups.push_back(rg);
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace aria2
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue