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