2010-11-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added .cc file for classes/structs that only provided by header
	file. Defined non-POD classes' ctor, dtor in .cc file.  Moved
	implementation code in header file to .cc file for major
	classes/strucsts.
pull/1/head
Tatsuhiro Tsujikawa 2010-11-14 07:17:55 +00:00
parent 93e5dbed32
commit 1372ac51ad
272 changed files with 5418 additions and 2483 deletions

View File

@ -1,3 +1,10 @@
2010-11-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added .cc file for classes/structs that only provided by header
file. Defined non-POD classes' ctor, dtor in .cc file. Moved
implementation code in header file to .cc file for major
classes/strucsts.
2010-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed SharedHandle::isNull(). Instead we added operator* and Removed SharedHandle::isNull(). Instead we added operator* and

View File

@ -49,9 +49,6 @@
#include "CreateRequestCommand.h" #include "CreateRequestCommand.h"
#include "InitiateConnectionCommandFactory.h" #include "InitiateConnectionCommandFactory.h"
#include "SleepCommand.h" #include "SleepCommand.h"
#ifdef ENABLE_ASYNC_DNS
#include "AsyncNameResolver.h"
#endif // ENABLE_ASYNC_DNS
#include "StreamCheckIntegrityEntry.h" #include "StreamCheckIntegrityEntry.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "Socket.h" #include "Socket.h"
@ -66,9 +63,11 @@
#include "DownloadContext.h" #include "DownloadContext.h"
#include "wallclock.h" #include "wallclock.h"
#include "NameResolver.h" #include "NameResolver.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "uri.h" #include "uri.h"
#include "FileEntry.h"
#ifdef ENABLE_ASYNC_DNS
#include "AsyncNameResolver.h"
#endif // ENABLE_ASYNC_DNS
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
# include "ChecksumCheckIntegrityEntry.h" # include "ChecksumCheckIntegrityEntry.h"
#endif // ENABLE_MESSAGE_DIGEST #endif // ENABLE_MESSAGE_DIGEST
@ -861,4 +860,34 @@ size_t AbstractCommand::calculateMinSplitSize() const
} }
} }
void AbstractCommand::setRequest(const SharedHandle<Request>& request)
{
req_ = request;
}
void AbstractCommand::setFileEntry(const SharedHandle<FileEntry>& fileEntry)
{
fileEntry_ = fileEntry;
}
void AbstractCommand::setSocket(const SharedHandle<SocketCore>& s)
{
socket_ = s;
}
const SharedHandle<DownloadContext>& AbstractCommand::getDownloadContext() const
{
return requestGroup_->getDownloadContext();
}
const SharedHandle<SegmentMan>& AbstractCommand::getSegmentMan() const
{
return requestGroup_->getSegmentMan();
}
const SharedHandle<PieceStorage>& AbstractCommand::getPieceStorage() const
{
return requestGroup_->getPieceStorage();
}
} // namespace aria2 } // namespace aria2

View File

@ -36,17 +36,24 @@
#define D_ABSTRACT_COMMAND_H #define D_ABSTRACT_COMMAND_H
#include "Command.h" #include "Command.h"
#include <vector>
#include <string>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "TimerA2.h" #include "TimerA2.h"
#include "FileEntry.h"
#include "RequestGroup.h"
namespace aria2 { namespace aria2 {
class FileEntry;
class RequestGroup;
class CheckIntegrityEntry;
class DownloadContext;
class SegmentMan;
class PieceStorage;
class Request; class Request;
class DownloadEngine; class DownloadEngine;
class Segment; class Segment;
class Exception;
class SocketCore; class SocketCore;
class Option; class Option;
#ifdef ENABLE_ASYNC_DNS #ifdef ENABLE_ASYNC_DNS
@ -98,20 +105,14 @@ protected:
return req_; return req_;
} }
void setRequest(const SharedHandle<Request>& request) void setRequest(const SharedHandle<Request>& request);
{
req_ = request;
}
const SharedHandle<FileEntry>& getFileEntry() const const SharedHandle<FileEntry>& getFileEntry() const
{ {
return fileEntry_; return fileEntry_;
} }
void setFileEntry(const SharedHandle<FileEntry>& fileEntry) void setFileEntry(const SharedHandle<FileEntry>& fileEntry);
{
fileEntry_ = fileEntry;
}
DownloadEngine* getDownloadEngine() const DownloadEngine* getDownloadEngine() const
{ {
@ -123,10 +124,7 @@ protected:
return socket_; return socket_;
} }
void setSocket(const SharedHandle<SocketCore>& s) void setSocket(const SharedHandle<SocketCore>& s);
{
socket_ = s;
}
void createSocket(); void createSocket();
@ -213,20 +211,9 @@ protected:
const SharedHandle<Option>& getOption() const; const SharedHandle<Option>& getOption() const;
const SharedHandle<DownloadContext>& getDownloadContext() const const SharedHandle<DownloadContext>& getDownloadContext() const;
{ const SharedHandle<SegmentMan>& getSegmentMan() const;
return requestGroup_->getDownloadContext(); const SharedHandle<PieceStorage>& getPieceStorage() const;
}
const SharedHandle<SegmentMan>& getSegmentMan() const
{
return requestGroup_->getSegmentMan();
}
const SharedHandle<PieceStorage>& getPieceStorage() const
{
return requestGroup_->getPieceStorage();
}
Timer& getCheckPoint() Timer& getCheckPoint()
{ {

View File

@ -42,14 +42,7 @@
#include "Option.h" #include "Option.h"
#include "prefs.h" #include "prefs.h"
#include "Socket.h" #include "Socket.h"
#include "CookieStorage.h"
#include "AuthConfigFactory.h"
#include "AuthConfig.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "RequestGroupMan.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -46,10 +46,6 @@
#include "message.h" #include "message.h"
#include "HttpHeader.h" #include "HttpHeader.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "RequestGroupMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

View File

@ -35,11 +35,11 @@
#include "AbstractSingleDiskAdaptor.h" #include "AbstractSingleDiskAdaptor.h"
#include "File.h" #include "File.h"
#include "AdaptiveFileAllocationIterator.h" #include "AdaptiveFileAllocationIterator.h"
#include "DiskWriter.h"
#include "FileEntry.h"
#ifdef HAVE_SOME_FALLOCATE #ifdef HAVE_SOME_FALLOCATE
# include "FallocFileAllocationIterator.h" # include "FallocFileAllocationIterator.h"
#endif // HAVE_SOME_FALLOCATE #endif // HAVE_SOME_FALLOCATE
#include "DiskWriter.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -51,10 +51,6 @@
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "wallclock.h" #include "wallclock.h"
#include "util.h" #include "util.h"
#include "RequestGroupMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

View File

@ -34,13 +34,13 @@
/* copyright --> */ /* copyright --> */
#include "AdaptiveFileAllocationIterator.h" #include "AdaptiveFileAllocationIterator.h"
#include "BinaryStream.h" #include "BinaryStream.h"
#ifdef HAVE_FALLOCATE
# include "FallocFileAllocationIterator.h"
#endif // HAVE_FALLOCATE
#include "SingleFileAllocationIterator.h" #include "SingleFileAllocationIterator.h"
#include "RecoverableException.h" #include "RecoverableException.h"
#include "LogFactory.h" #include "LogFactory.h"
#include "Logger.h" #include "Logger.h"
#ifdef HAVE_FALLOCATE
# include "FallocFileAllocationIterator.h"
#endif // HAVE_FALLOCATE
namespace aria2 { namespace aria2 {
@ -99,4 +99,18 @@ bool AdaptiveFileAllocationIterator::finished()
} }
} }
off_t AdaptiveFileAllocationIterator::getCurrentLength()
{
if(!allocator_) {
return offset_;
} else {
return allocator_->getCurrentLength();
}
}
uint64_t AdaptiveFileAllocationIterator::getTotalLength()
{
return totalLength_;
}
} // namespace aria2 } // namespace aria2

View File

@ -64,19 +64,9 @@ public:
virtual bool finished(); virtual bool finished();
virtual off_t getCurrentLength() virtual off_t getCurrentLength();
{
if(!allocator_) {
return offset_;
} else {
return allocator_->getCurrentLength();
}
}
virtual uint64_t getTotalLength() virtual uint64_t getTotalLength();
{
return totalLength_;
}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -0,0 +1,82 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "AlphaNumberDecorator.h"
#include <algorithm>
namespace aria2 {
namespace {
std::string widen(const std::string& s, size_t width, char zeroChar)
{
std::string t = s;
std::string zero(1, zeroChar);
while(t.size() < width) {
t.insert(0, zero);
}
return t;
}
} // namespace
AlphaNumberDecorator::AlphaNumberDecorator(size_t width, bool uppercase)
: width_(width),
zero_(uppercase?'A':'a')
{}
AlphaNumberDecorator::~AlphaNumberDecorator() {}
std::string AlphaNumberDecorator::decorate(unsigned int number)
{
if(number == 0) {
return widen(std::string(1, zero_), width_, zero_);
}
int base = 26;
char u[14]; // because if unsigned int is 64bit, which is the
// biggest integer for the time being and number is
// UINT64_MAX, you get "HLHXCZMXSYUMQP"
size_t index = 0;
do {
unsigned int quot = number/base;
unsigned int rem = number%base;
u[index++] = zero_+rem;
number = quot;
} while(number);
std::reverse(&u[0], &u[index]);
return widen(std::string(&u[0], &u[index]), width_, zero_);
}
} // namespace aria2

View File

@ -36,54 +36,23 @@
#define D_ALPHA_NUMBER_DECORATOR_H #define D_ALPHA_NUMBER_DECORATOR_H
#include "NumberDecorator.h" #include "NumberDecorator.h"
#include "DlAbortEx.h"
#include <algorithm>
namespace aria2 { namespace aria2 {
class AlphaNumberDecorator : public NumberDecorator class AlphaNumberDecorator : public NumberDecorator
{ {
private: private:
size_t width_; size_t width_;
char zero_; char zero_;
std::string widen(const std::string& s, size_t width)
{
std::string t = s;
std::string zero(1, zero_);
while(t.size() < width) {
t.insert(0, zero);
}
return t;
}
public: public:
AlphaNumberDecorator(size_t width, bool uppercase = false): AlphaNumberDecorator(size_t width, bool uppercase = false);
width_(width), zero_(uppercase?'A':'a') {} virtual ~AlphaNumberDecorator();
virtual ~AlphaNumberDecorator() {} // Don't allow copying
AlphaNumberDecorator(const AlphaNumberDecorator& c);
AlphaNumberDecorator& operator=(const AlphaNumberDecorator& c);
virtual std::string decorate(unsigned int number) virtual std::string decorate(unsigned int number);
{
if(number == 0) {
return widen(std::string(1, zero_), width_);
}
int base = 26;
char u[14]; // because if unsigned int is 64bit, which is the biggest integer for the time being and number is UINT64_MAX, you get "HLHXCZMXSYUMQP"
size_t index = 0;
do {
unsigned int quot = number/base;
unsigned int rem = number%base;
u[index++] = zero_+rem;
number = quot;
} while(number);
std::reverse(&u[0], &u[index]);
return widen(std::string(&u[0], &u[index]), width_);
}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -38,7 +38,6 @@
#include "A2STR.h" #include "A2STR.h"
#include "SimpleRandomizer.h" #include "SimpleRandomizer.h"
#include "util.h"
#include "a2algo.h" #include "a2algo.h"
namespace aria2 { namespace aria2 {
@ -49,6 +48,8 @@ const std::string AnnounceList::STOPPED("stopped");
const std::string AnnounceList::COMPLETED("completed"); const std::string AnnounceList::COMPLETED("completed");
AnnounceList::AnnounceList():currentTrackerInitialized_(false) {}
AnnounceList::AnnounceList AnnounceList::AnnounceList
(const std::vector<std::vector<std::string> >& announceList): (const std::vector<std::vector<std::string> >& announceList):
currentTrackerInitialized_(false) { currentTrackerInitialized_(false) {
@ -61,6 +62,8 @@ AnnounceList::AnnounceList
resetIterator(); resetIterator();
} }
AnnounceList::~AnnounceList() {}
void AnnounceList::reconfigure void AnnounceList::reconfigure
(const std::vector<std::vector<std::string> >& announceList) (const std::vector<std::vector<std::string> >& announceList)
{ {
@ -262,4 +265,9 @@ bool AnnounceList::currentTierAcceptsCompletedEvent() const
} }
} }
size_t AnnounceList::countTier() const
{
return tiers_.size();
}
} // namespace aria2 } // namespace aria2

View File

@ -54,16 +54,19 @@ private:
void setCurrentTier void setCurrentTier
(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr); (const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
public: public:
AnnounceList():currentTrackerInitialized_(false) {} AnnounceList();
AnnounceList(const std::vector<std::vector<std::string> >& announceList); AnnounceList(const std::vector<std::vector<std::string> >& announceList);
AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers); AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
~AnnounceList();
// Don't allow copying
AnnounceList(const AnnounceList&);
AnnounceList& operator=(const AnnounceList&);
void reconfigure(const std::vector<std::vector<std::string> >& announceList); void reconfigure(const std::vector<std::vector<std::string> >& announceList);
void reconfigure(const std::string& url); void reconfigure(const std::string& url);
size_t countTier() const { size_t countTier() const;
return tiers_.size();
}
/** /**
* Shuffles all the URLs in each group. * Shuffles all the URLs in each group.

79
src/AnnounceTier.cc Normal file
View File

@ -0,0 +1,79 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "AnnounceTier.h"
namespace aria2 {
AnnounceTier::AnnounceTier(const std::deque<std::string>& urls)
: event(STARTED), urls(urls)
{}
AnnounceTier::~AnnounceTier() {}
void AnnounceTier::nextEvent()
{
switch(event) {
case STARTED:
event = DOWNLOADING;
break;
case STARTED_AFTER_COMPLETION:
event = SEEDING;
break;
case STOPPED:
event = HALTED;
break;
case COMPLETED:
event = SEEDING;
break;
default:
break;
}
}
void AnnounceTier::nextEventIfAfterStarted()
{
switch(event) {
case STOPPED:
event = HALTED;
break;
case COMPLETED:
event = SEEDING;
break;
default:
break;
}
}
} // namespace aria2

View File

@ -36,10 +36,12 @@
#define D_ANNOUNCE_TIER_H #define D_ANNOUNCE_TIER_H
#include "common.h" #include "common.h"
#include "SharedHandle.h"
#include <string> #include <string>
#include <deque> #include <deque>
#include "SharedHandle.h"
namespace aria2 { namespace aria2 {
class AnnounceTier { class AnnounceTier {
@ -57,40 +59,17 @@ public:
AnnounceEvent event; AnnounceEvent event;
std::deque<std::string> urls; std::deque<std::string> urls;
AnnounceTier(const std::deque<std::string>& urls):event(STARTED), urls(urls) {} AnnounceTier(const std::deque<std::string>& urls);
void nextEvent() { ~AnnounceTier();
switch(event) {
case STARTED:
event = DOWNLOADING;
break;
case STARTED_AFTER_COMPLETION:
event = SEEDING;
break;
case STOPPED:
event = HALTED;
break;
case COMPLETED:
event = SEEDING;
break;
default:
break;
}
}
void nextEventIfAfterStarted() // Don't allow copying
{ AnnounceTier(const AnnounceTier&);
switch(event) { AnnounceTier& operator=(const AnnounceTier&);
case STOPPED:
event = HALTED; void nextEvent();
break;
case COMPLETED: void nextEventIfAfterStarted();
event = SEEDING;
break;
default:
break;
}
}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -33,10 +33,27 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "AuthConfig.h" #include "AuthConfig.h"
#include <ostream> #include <ostream>
#include "a2functional.h"
namespace aria2 { namespace aria2 {
AuthConfig::AuthConfig() {}
AuthConfig::AuthConfig(const std::string& user, const std::string& password)
: user_(user),
password_(password)
{}
AuthConfig::~AuthConfig() {}
std::string AuthConfig::getAuthText() const
{
return strconcat(user_, ":", password_);
}
std::ostream& operator<<(std::ostream& o, const AuthConfigHandle& authConfig) std::ostream& operator<<(std::ostream& o, const AuthConfigHandle& authConfig)
{ {
o << authConfig->getAuthText(); o << authConfig->getAuthText();

View File

@ -41,7 +41,6 @@
#include <iosfwd> #include <iosfwd>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "a2functional.h"
namespace aria2 { namespace aria2 {
@ -51,15 +50,15 @@ private:
std::string user_; std::string user_;
std::string password_; std::string password_;
public: public:
AuthConfig();
AuthConfig(const std::string& user, const std::string& password);
~AuthConfig();
AuthConfig() {} // Don't allow copying
AuthConfig(const std::string& user, const std::string& password): AuthConfig(const AuthConfig&);
user_(user), password_(password) {} AuthConfig& operator=(const AuthConfig&);
std::string getAuthText() const std::string getAuthText() const;
{
return strconcat(user_, ":", password_);
}
const std::string& getUser() const const std::string& getUser() const
{ {

View File

@ -35,15 +35,13 @@
#include "AutoSaveCommand.h" #include "AutoSaveCommand.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "FileEntry.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {
AutoSaveCommand::AutoSaveCommand(cuid_t cuid, DownloadEngine* e, time_t interval): AutoSaveCommand::AutoSaveCommand
TimeBasedCommand(cuid, e, interval, true) {} (cuid_t cuid, DownloadEngine* e, time_t interval)
: TimeBasedCommand(cuid, e, interval, true)
{}
AutoSaveCommand::~AutoSaveCommand() {} AutoSaveCommand::~AutoSaveCommand() {}

View File

@ -37,7 +37,6 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include "util.h"
#include "array_fun.h" #include "array_fun.h"
#include "bitfield.h" #include "bitfield.h"
@ -131,6 +130,11 @@ BitfieldMan::~BitfieldMan() {
delete [] filterBitfield_; delete [] filterBitfield_;
} }
size_t BitfieldMan::getLastBlockLength() const
{
return totalLength_-blockLength_*(blocks_-1);
}
size_t BitfieldMan::getBlockLength(size_t index) const size_t BitfieldMan::getBlockLength(size_t index) const
{ {
if(index == blocks_-1) { if(index == blocks_-1) {
@ -716,4 +720,30 @@ uint64_t BitfieldMan::getMissingUnusedLength(size_t startingIndex) const
return length; return length;
} }
BitfieldMan::Range::Range(size_t startIndex, size_t endIndex)
:
startIndex(startIndex),
endIndex(endIndex)
{}
size_t BitfieldMan::Range::getSize() const
{
return endIndex-startIndex;
}
size_t BitfieldMan::Range::getMidIndex() const
{
return (endIndex-startIndex)/2+startIndex;
}
bool BitfieldMan::Range::operator<(const Range& range) const
{
return getSize() < range.getSize();
}
bool BitfieldMan::Range::operator==(const Range& range) const
{
return getSize() == range.getSize();
}
} // namespace aria2 } // namespace aria2

View File

@ -74,29 +74,14 @@ private:
void ensureFilterBitfield(); void ensureFilterBitfield();
public: public:
// [startIndex, endIndex) // [startIndex, endIndex)
class Range { struct Range {
public:
size_t startIndex; size_t startIndex;
size_t endIndex; size_t endIndex;
Range(size_t startIndex = 0, size_t endIndex = 0):startIndex(startIndex), Range(size_t startIndex = 0, size_t endIndex = 0);
endIndex(endIndex) {} size_t getSize() const;
size_t getMidIndex() const;
size_t getSize() const { bool operator<(const Range& range) const;
return endIndex-startIndex; bool operator==(const Range& range) const;
}
size_t getMidIndex() const {
return (endIndex-startIndex)/2+startIndex;
}
bool operator<(const Range& range) const {
return getSize() < range.getSize();
}
bool operator==(const Range& range) const
{
return getSize() == range.getSize();
}
}; };
public: public:
BitfieldMan(size_t blockLength, uint64_t totalLength); BitfieldMan(size_t blockLength, uint64_t totalLength);
@ -110,10 +95,7 @@ public:
return blockLength_; return blockLength_;
} }
size_t getLastBlockLength() const size_t getLastBlockLength() const;
{
return totalLength_-blockLength_*(blocks_-1);
}
size_t getBlockLength(size_t index) const; size_t getBlockLength(size_t index) const;

View File

@ -0,0 +1,47 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "BtAbortOutstandingRequestEvent.h"
#include "Piece.h"
namespace aria2 {
BtAbortOutstandingRequestEvent::BtAbortOutstandingRequestEvent
(const SharedHandle<Piece>& piece)
: piece_(piece)
{}
BtAbortOutstandingRequestEvent::~BtAbortOutstandingRequestEvent() {}
} // namespace aria2

View File

@ -37,16 +37,17 @@
#include "common.h" #include "common.h"
#include "SharedHandle.h" #include "SharedHandle.h"
#include "Piece.h"
namespace aria2 { namespace aria2 {
class Piece;
class BtAbortOutstandingRequestEvent { class BtAbortOutstandingRequestEvent {
private: private:
SharedHandle<Piece> piece_; SharedHandle<Piece> piece_;
public: public:
BtAbortOutstandingRequestEvent(const SharedHandle<Piece>& piece): BtAbortOutstandingRequestEvent(const SharedHandle<Piece>& piece);
piece_(piece) {} ~BtAbortOutstandingRequestEvent();
const SharedHandle<Piece>& getPiece() const { return piece_; } const SharedHandle<Piece>& getPiece() const { return piece_; }
}; };

View File

@ -36,9 +36,11 @@
#define D_BT_ANNOUNCE_H #define D_BT_ANNOUNCE_H
#include "common.h" #include "common.h"
#include <string>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "a2time.h" #include "a2time.h"
#include <string>
namespace aria2 { namespace aria2 {

View File

@ -0,0 +1,56 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "BtBitfieldMessageValidator.h"
#include "BtBitfieldMessage.h"
#include "bittorrent_helper.h"
namespace aria2 {
BtBitfieldMessageValidator::BtBitfieldMessageValidator
(const BtBitfieldMessage* message, size_t numPiece)
: message_(message),
numPiece_(numPiece)
{}
BtBitfieldMessageValidator::~BtBitfieldMessageValidator() {}
void BtBitfieldMessageValidator::validate()
{
bittorrent::checkBitfield(message_->getBitfield(),
message_->getBitfieldLength(),
numPiece_);
}
} // namespace aria2

View File

@ -36,27 +36,21 @@
#define D_BT_BITFIELD_MESSAGE_VALIDATOR_H #define D_BT_BITFIELD_MESSAGE_VALIDATOR_H
#include "BtMessageValidator.h" #include "BtMessageValidator.h"
#include "BtBitfieldMessage.h"
#include "bittorrent_helper.h"
namespace aria2 { namespace aria2 {
class BtBitfieldMessage;
class BtBitfieldMessageValidator : public BtMessageValidator { class BtBitfieldMessageValidator : public BtMessageValidator {
private: private:
const BtBitfieldMessage* message_; const BtBitfieldMessage* message_;
size_t numPiece_; size_t numPiece_;
public: public:
BtBitfieldMessageValidator(const BtBitfieldMessage* message, BtBitfieldMessageValidator(const BtBitfieldMessage* message,
size_t numPiece): size_t numPiece);
message_(message), ~BtBitfieldMessageValidator();
numPiece_(numPiece) {}
virtual void validate() virtual void validate();
{
bittorrent::checkBitfield(message_->getBitfield(),
message_->getBitfieldLength(),
numPiece_);
}
}; };
typedef SharedHandle<BtBitfieldMessageValidator> BtBitfieldMessageValidatorHandle; typedef SharedHandle<BtBitfieldMessageValidator> BtBitfieldMessageValidatorHandle;

View File

@ -40,9 +40,6 @@
#include "DiskAdaptor.h" #include "DiskAdaptor.h"
#include "prefs.h" #include "prefs.h"
#include "Option.h" #include "Option.h"
#include "DownloadContext.h"
#include "RequestGroupMan.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

View File

@ -48,6 +48,7 @@
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "FileEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -58,6 +58,8 @@ BtExtendedMessage::BtExtendedMessage
msgLength_(0) msgLength_(0)
{} {}
BtExtendedMessage::~BtExtendedMessage() {}
unsigned char* BtExtendedMessage::createMessage() unsigned char* BtExtendedMessage::createMessage()
{ {
/** /**

View File

@ -53,6 +53,7 @@ private:
public: public:
BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage = BtExtendedMessage(const SharedHandle<ExtensionMessage>& extensionMessage =
SharedHandle<ExtensionMessage>()); SharedHandle<ExtensionMessage>());
virtual ~BtExtendedMessage();
static const uint8_t ID = 20; static const uint8_t ID = 20;

View File

@ -41,9 +41,7 @@
#include "Command.h" #include "Command.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "RequestGroupMan.h" #include "FileEntry.h"
#include "CheckIntegrityEntry.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

View File

@ -0,0 +1,76 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "BtHandshakeMessageValidator.h"
#include <cstring>
#include "BtHandshakeMessage.h"
#include "util.h"
#include "StringFormat.h"
#include "DlAbortEx.h"
namespace aria2 {
BtHandshakeMessageValidator::BtHandshakeMessageValidator
(const BtHandshakeMessage* message, const unsigned char* infoHash)
: message_(message)
{
memcpy(infoHash_, infoHash, sizeof(infoHash_));
}
BtHandshakeMessageValidator::~BtHandshakeMessageValidator() {}
void BtHandshakeMessageValidator::validate()
{
if(message_->getPstrlen() != 19) {
throw DL_ABORT_EX(StringFormat("invalid handshake pstrlen=%u",
message_->getPstrlen()).str());
}
if(memcmp(BtHandshakeMessage::BT_PSTR, message_->getPstr(), 19) != 0) {
throw DL_ABORT_EX
(StringFormat("invalid handshake pstr=%s",
util::percentEncode
(message_->getPstr(), 19).c_str()).str());
}
if(memcmp(infoHash_, message_->getInfoHash(), sizeof(infoHash_)) != 0) {
throw DL_ABORT_EX
(StringFormat("invalid handshake info hash: expected:%s, actual:%s",
util::toHex(infoHash_, sizeof(infoHash_)).c_str(),
util::toHex(message_->getInfoHash(),
INFO_HASH_LENGTH).c_str()).str());
}
}
} // namespace aria2

View File

@ -39,45 +39,23 @@
#include <cstring> #include <cstring>
#include "BtHandshakeMessage.h"
#include "util.h"
#include "StringFormat.h"
#include "BtConstants.h" #include "BtConstants.h"
namespace aria2 { namespace aria2 {
class BtHandshakeMessage;
class BtHandshakeMessageValidator : public BtMessageValidator { class BtHandshakeMessageValidator : public BtMessageValidator {
private: private:
const BtHandshakeMessage* message_; const BtHandshakeMessage* message_;
unsigned char infoHash_[INFO_HASH_LENGTH]; unsigned char infoHash_[INFO_HASH_LENGTH];
public: public:
BtHandshakeMessageValidator(const BtHandshakeMessage* message, BtHandshakeMessageValidator(const BtHandshakeMessage* message,
const unsigned char* infoHash): const unsigned char* infoHash);
message_(message)
{
memcpy(infoHash_, infoHash, sizeof(infoHash_));
}
virtual void validate() ~BtHandshakeMessageValidator();
{
if(message_->getPstrlen() != 19) { virtual void validate();
throw DL_ABORT_EX(StringFormat("invalid handshake pstrlen=%u",
message_->getPstrlen()).str());
}
if(memcmp(BtHandshakeMessage::BT_PSTR, message_->getPstr(), 19) != 0) {
throw DL_ABORT_EX
(StringFormat("invalid handshake pstr=%s",
util::percentEncode
(message_->getPstr(), 19).c_str()).str());
}
if(memcmp(infoHash_, message_->getInfoHash(), sizeof(infoHash_)) != 0) {
throw DL_ABORT_EX
(StringFormat("invalid handshake info hash: expected:%s, actual:%s",
util::toHex(infoHash_, sizeof(infoHash_)).c_str(),
util::toHex(message_->getInfoHash(),
INFO_HASH_LENGTH).c_str()).str());
}
}
}; };
typedef SharedHandle<BtHandshakeMessageValidator> BtHandshakeMessageValidatorHandle; typedef SharedHandle<BtHandshakeMessageValidator> BtHandshakeMessageValidatorHandle;

View File

@ -42,6 +42,8 @@ const std::string BtInterestedMessage::NAME("interested");
BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {} BtInterestedMessage::BtInterestedMessage():ZeroBtMessage(ID, NAME) {}
BtInterestedMessage::~BtInterestedMessage() {}
SharedHandle<BtInterestedMessage> BtInterestedMessage::create SharedHandle<BtInterestedMessage> BtInterestedMessage::create
(const unsigned char* data, size_t dataLength) (const unsigned char* data, size_t dataLength)
{ {

View File

@ -49,6 +49,7 @@ private:
SharedHandle<PeerStorage> peerStorage_; SharedHandle<PeerStorage> peerStorage_;
public: public:
BtInterestedMessage(); BtInterestedMessage();
virtual ~BtInterestedMessage();
static const uint8_t ID = 2; static const uint8_t ID = 2;

View File

@ -58,6 +58,25 @@ BtLeecherStateChoke::PeerEntry::PeerEntry(const SharedHandle<Peer>& peer):
(peer->peerInterested() && (peer->peerInterested() &&
peer->getLastDownloadUpdate().difference(global::wallclock) < 30) {} peer->getLastDownloadUpdate().difference(global::wallclock) < 30) {}
BtLeecherStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
: peer_(c.peer_),
downloadSpeed_(c.downloadSpeed_),
regularUnchoker_(c.regularUnchoker_)
{}
BtLeecherStateChoke::PeerEntry& BtLeecherStateChoke::PeerEntry::operator=
(const PeerEntry& c)
{
if(this != &c) {
peer_ = c.peer_;
downloadSpeed_ = c.downloadSpeed_;
regularUnchoker_ = c.regularUnchoker_;
}
return *this;
}
BtLeecherStateChoke::PeerEntry::~PeerEntry() {}
const SharedHandle<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const const SharedHandle<Peer>& BtLeecherStateChoke::PeerEntry::getPeer() const
{ {
return peer_; return peer_;

View File

@ -62,6 +62,10 @@ private:
bool regularUnchoker_; bool regularUnchoker_;
public: public:
PeerEntry(const SharedHandle<Peer>& peer); PeerEntry(const SharedHandle<Peer>& peer);
PeerEntry(const PeerEntry& c);
~PeerEntry();
PeerEntry& operator=(const PeerEntry& c);
bool operator<(const PeerEntry& rhs) const; bool operator<(const PeerEntry& rhs) const;

View File

@ -42,6 +42,8 @@ const std::string BtNotInterestedMessage::NAME("not interested");
BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {} BtNotInterestedMessage::BtNotInterestedMessage():ZeroBtMessage(ID, NAME) {}
BtNotInterestedMessage::~BtNotInterestedMessage() {}
SharedHandle<BtNotInterestedMessage> BtNotInterestedMessage::create SharedHandle<BtNotInterestedMessage> BtNotInterestedMessage::create
(const unsigned char* data, size_t dataLength) (const unsigned char* data, size_t dataLength)
{ {

View File

@ -49,6 +49,7 @@ private:
SharedHandle<PeerStorage> peerStorage_; SharedHandle<PeerStorage> peerStorage_;
public: public:
BtNotInterestedMessage(); BtNotInterestedMessage();
virtual ~BtNotInterestedMessage();
static const uint8_t ID = 3; static const uint8_t ID = 3;

View File

@ -0,0 +1,56 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "BtPieceMessageValidator.h"
#include "BtPieceMessage.h"
#include "bittorrent_helper.h"
namespace aria2 {
BtPieceMessageValidator::BtPieceMessageValidator
(const BtPieceMessage* message, size_t numPiece, size_t pieceLength)
: message_(message),
numPiece_(numPiece),
pieceLength_(pieceLength)
{}
BtPieceMessageValidator::~BtPieceMessageValidator() {}
void BtPieceMessageValidator::validate()
{
bittorrent::checkIndex(message_->getIndex(), numPiece_);
bittorrent::checkBegin(message_->getBegin(), pieceLength_);
}
} // namespace aria2

View File

@ -36,11 +36,11 @@
#define D_BT_PIECE_MESSAGE_VALIDATOR_H #define D_BT_PIECE_MESSAGE_VALIDATOR_H
#include "BtMessageValidator.h" #include "BtMessageValidator.h"
#include "BtPieceMessage.h"
#include "bittorrent_helper.h"
namespace aria2 { namespace aria2 {
class BtPieceMessage;
class BtPieceMessageValidator : public BtMessageValidator { class BtPieceMessageValidator : public BtMessageValidator {
private: private:
const BtPieceMessage* message_; const BtPieceMessage* message_;
@ -49,16 +49,11 @@ private:
public: public:
BtPieceMessageValidator(const BtPieceMessage* message, BtPieceMessageValidator(const BtPieceMessage* message,
size_t numPiece, size_t numPiece,
size_t pieceLength): size_t pieceLength);
message_(message),
numPiece_(numPiece),
pieceLength_(pieceLength) {}
virtual void validate() ~BtPieceMessageValidator();
{
bittorrent::checkIndex(message_->getIndex(), numPiece_); virtual void validate();
bittorrent::checkBegin(message_->getBegin(), pieceLength_);
}
}; };
typedef SharedHandle<BtPieceMessageValidator> BtPieceMessageValidatorHandle; typedef SharedHandle<BtPieceMessageValidator> BtPieceMessageValidatorHandle;

View File

@ -89,4 +89,55 @@ void BtRegistry::removeAll() {
pool_.clear(); pool_.clear();
} }
BtObject::BtObject
(const SharedHandle<DownloadContext>& downloadContext,
const SharedHandle<PieceStorage>& pieceStorage,
const SharedHandle<PeerStorage>& peerStorage,
const SharedHandle<BtAnnounce>& btAnnounce,
const SharedHandle<BtRuntime>& btRuntime,
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile)
: downloadContext_(downloadContext),
pieceStorage_(pieceStorage),
peerStorage_(peerStorage),
btAnnounce_(btAnnounce),
btRuntime_(btRuntime),
btProgressInfoFile_(btProgressInfoFile)
{}
BtObject::BtObject() {}
BtObject::BtObject(const BtObject& c)
: downloadContext_(c.downloadContext_),
pieceStorage_(c.pieceStorage_),
peerStorage_(c.peerStorage_),
btAnnounce_(c.btAnnounce_),
btRuntime_(c.btRuntime_),
btProgressInfoFile_(c.btProgressInfoFile_)
{}
BtObject::~BtObject() {}
BtObject& BtObject::operator=(const BtObject& c)
{
if(this != &c) {
downloadContext_ = c.downloadContext_;
pieceStorage_ = c.pieceStorage_;
peerStorage_ = c.peerStorage_;
btAnnounce_ = c.btAnnounce_;
btRuntime_ = c.btRuntime_;
btProgressInfoFile_ = c.btProgressInfoFile_;
}
return *this;
}
bool BtObject::isNull() const
{
return !downloadContext_ &&
!pieceStorage_ &&
!peerStorage_ &&
!btAnnounce_ &&
!btRuntime_ &&
!btProgressInfoFile_;
}
} // namespace aria2 } // namespace aria2

View File

@ -64,25 +64,17 @@ struct BtObject {
const SharedHandle<PeerStorage>& peerStorage, const SharedHandle<PeerStorage>& peerStorage,
const SharedHandle<BtAnnounce>& btAnnounce, const SharedHandle<BtAnnounce>& btAnnounce,
const SharedHandle<BtRuntime>& btRuntime, const SharedHandle<BtRuntime>& btRuntime,
const SharedHandle<BtProgressInfoFile>& btProgressInfoFile): const SharedHandle<BtProgressInfoFile>& btProgressInfoFile);
downloadContext_(downloadContext),
pieceStorage_(pieceStorage),
peerStorage_(peerStorage),
btAnnounce_(btAnnounce),
btRuntime_(btRuntime),
btProgressInfoFile_(btProgressInfoFile) {}
BtObject() {} BtObject();
bool isNull() const BtObject(const BtObject& c);
{
return !downloadContext_ && ~BtObject();
!pieceStorage_ &&
!peerStorage_ && BtObject& operator=(const BtObject& c);
!btAnnounce_ &&
!btRuntime_ && bool isNull() const;
!btProgressInfoFile_;
}
}; };
class BtRegistry { class BtRegistry {

61
src/BtRuntime.cc Normal file
View File

@ -0,0 +1,61 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "BtRuntime.h"
#include "BtConstants.h"
namespace aria2 {
BtRuntime::BtRuntime()
: uploadLengthAtStartup_(0),
port_(0),
halt_(false),
connections_(0),
ready_(false),
maxPeers_(DEFAULT_MAX_PEERS),
minPeers_(DEFAULT_MIN_PEERS)
{}
BtRuntime::~BtRuntime() {}
void BtRuntime::setMaxPeers(unsigned int maxPeers)
{
maxPeers_ = maxPeers;
minPeers_ = static_cast<unsigned int>(maxPeers*0.8);
if(minPeers_ == 0 && maxPeers != 0) {
minPeers_ = maxPeers;
}
}
} // namespace aria2

View File

@ -36,7 +36,7 @@
#define D_BT_RUNTIME_H #define D_BT_RUNTIME_H
#include "common.h" #include "common.h"
#include "BtConstants.h" #include "SharedHandle.h"
namespace aria2 { namespace aria2 {
@ -57,17 +57,9 @@ private:
static const unsigned int DEFAULT_MIN_PEERS = 40; static const unsigned int DEFAULT_MIN_PEERS = 40;
public: public:
BtRuntime(): BtRuntime();
uploadLengthAtStartup_(0),
port_(0),
halt_(false),
connections_(0),
ready_(false),
maxPeers_(DEFAULT_MAX_PEERS),
minPeers_(DEFAULT_MIN_PEERS)
{}
~BtRuntime() {} ~BtRuntime();
uint64_t getUploadLengthAtStartup() const { uint64_t getUploadLengthAtStartup() const {
return uploadLengthAtStartup_; return uploadLengthAtStartup_;
@ -114,14 +106,7 @@ public:
void setReady(bool go) { ready_ = go; } void setReady(bool go) { ready_ = go; }
void setMaxPeers(unsigned int maxPeers) void setMaxPeers(unsigned int maxPeers);
{
maxPeers_ = maxPeers;
minPeers_ = static_cast<unsigned int>(maxPeers*0.8);
if(minPeers_ == 0 && maxPeers != 0) {
minPeers_ = maxPeers;
}
}
unsigned int getMaxPeers() const unsigned int getMaxPeers() const
{ {

View File

@ -60,6 +60,29 @@ BtSeederStateChoke::PeerEntry::PeerEntry
uploadSpeed_(peer->calculateUploadSpeed()) uploadSpeed_(peer->calculateUploadSpeed())
{} {}
BtSeederStateChoke::PeerEntry::PeerEntry(const PeerEntry& c)
: peer_(c.peer_),
outstandingUpload_(c.outstandingUpload_),
lastAmUnchoking_(c.lastAmUnchoking_),
recentUnchoking_(c.recentUnchoking_),
uploadSpeed_(c.uploadSpeed_)
{}
BtSeederStateChoke::PeerEntry::~PeerEntry() {}
BtSeederStateChoke::PeerEntry& BtSeederStateChoke::PeerEntry::operator=
(const PeerEntry& c)
{
if(this != &c) {
peer_ = c.peer_;
outstandingUpload_ = c.outstandingUpload_;
lastAmUnchoking_ = c.lastAmUnchoking_;
recentUnchoking_ = c.recentUnchoking_;
uploadSpeed_ = c.uploadSpeed_;
}
return *this;
}
bool bool
BtSeederStateChoke::PeerEntry::operator<(const PeerEntry& rhs) const BtSeederStateChoke::PeerEntry::operator<(const PeerEntry& rhs) const
{ {

View File

@ -66,6 +66,10 @@ private:
const static time_t TIME_FRAME = 20; const static time_t TIME_FRAME = 20;
public: public:
PeerEntry(const SharedHandle<Peer>& peer); PeerEntry(const SharedHandle<Peer>& peer);
PeerEntry(const PeerEntry& c);
~PeerEntry();
PeerEntry& operator=(const PeerEntry& c);
bool operator<(const PeerEntry& rhs) const; bool operator<(const PeerEntry& rhs) const;

View File

@ -78,12 +78,11 @@
#include "LpdMessageDispatcher.h" #include "LpdMessageDispatcher.h"
#include "message.h" #include "message.h"
#include "SocketCore.h" #include "SocketCore.h"
#include "RequestGroupMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
#include "ServerStatMan.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "array_fun.h" #include "array_fun.h"
#include "DownloadContext.h"
#include "PieceStorage.h"
#include "PeerStorage.h"
namespace aria2 { namespace aria2 {

View File

@ -36,8 +36,6 @@
#include "PieceStorage.h" #include "PieceStorage.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "BtRuntime.h" #include "BtRuntime.h"
#include "Peer.h"
#include "DownloadContext.h"
#include "Logger.h" #include "Logger.h"
#include "wallclock.h" #include "wallclock.h"
#include "util.h" #include "util.h"

View File

@ -33,7 +33,6 @@
*/ */
/* copyright --> */ /* copyright --> */
#include "ByteArrayDiskWriter.h" #include "ByteArrayDiskWriter.h"
#include "util.h"
#include "A2STR.h" #include "A2STR.h"
namespace aria2 { namespace aria2 {
@ -90,4 +89,14 @@ uint64_t ByteArrayDiskWriter::size()
return buf_.tellg(); return buf_.tellg();
} }
void ByteArrayDiskWriter::setString(const std::string& s)
{
buf_.str(s);
}
std::string ByteArrayDiskWriter::getString() const
{
return buf_.str();
}
} // namespace aria2 } // namespace aria2

View File

@ -66,15 +66,9 @@ public:
virtual void disableDirectIO() {} virtual void disableDirectIO() {}
void setString(const std::string& s) void setString(const std::string& s);
{
buf_.str(s);
}
std::string getString() const std::string getString() const;
{
return buf_.str();
}
}; };
typedef SharedHandle<ByteArrayDiskWriter> ByteArrayDiskWriterHandle; typedef SharedHandle<ByteArrayDiskWriter> ByteArrayDiskWriterHandle;

51
src/CUIDCounter.cc Normal file
View File

@ -0,0 +1,51 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "CUIDCounter.h"
namespace aria2 {
CUIDCounter::CUIDCounter():count_(0) {}
CUIDCounter::~CUIDCounter() {}
cuid_t CUIDCounter::newID()
{
if(count_ == INT64_MAX) {
count_ = 0;
}
return ++count_;
}
} // namespace aria2

View File

@ -44,19 +44,11 @@ class CUIDCounter {
private: private:
cuid_t count_; cuid_t count_;
public: public:
CUIDCounter():count_(0) {} CUIDCounter();
~CUIDCounter();
~CUIDCounter() {} cuid_t newID();
cuid_t newID()
{
if(count_ == INT64_MAX) {
count_ = 0;
}
return ++count_;
}
}; };
} } // namespace aria2
#endif // D_CUID_COUNTER_H #endif // D_CUID_COUNTER_H

View File

@ -43,9 +43,6 @@
#include "a2functional.h" #include "a2functional.h"
#include "RecoverableException.h" #include "RecoverableException.h"
#include "util.h" #include "util.h"
#include "RequestGroupMan.h"
#include "FileAllocationEntry.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

View File

@ -37,10 +37,7 @@
#include "CheckIntegrityCommand.h" #include "CheckIntegrityCommand.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "FileEntry.h"
#include "util.h" #include "util.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -41,9 +41,6 @@
#include "FileAllocationEntry.h" #include "FileAllocationEntry.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "Option.h" #include "Option.h"
#include "DownloadContext.h"
#include "RequestGroupMan.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

65
src/Checksum.cc Normal file
View File

@ -0,0 +1,65 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "Checksum.h"
namespace aria2 {
Checksum::Checksum(const std::string& algo, const std::string& messageDigest)
: algo_(algo),
messageDigest_(messageDigest)
{}
Checksum::Checksum()
: algo_("sha-1")
{}
Checksum::~Checksum() {}
bool Checksum::isEmpty() const
{
return messageDigest_.empty();
}
void Checksum::setMessageDigest(const std::string& md)
{
messageDigest_ = md;
}
void Checksum::setAlgo(const std::string& algo)
{
algo_ = algo;
}
} // namespace aria2

View File

@ -47,29 +47,21 @@ private:
std::string messageDigest_; std::string messageDigest_;
public: public:
// messageDigest_ is ascii hexadecimal notation. // messageDigest_ is ascii hexadecimal notation.
Checksum(const std::string& algo, const std::string& messageDigest): Checksum(const std::string& algo, const std::string& messageDigest);
algo_(algo), messageDigest_(messageDigest) {} Checksum();
Checksum(): ~Checksum();
algo_("sha-1") {}
~Checksum() {} bool isEmpty() const;
bool isEmpty() const { void setMessageDigest(const std::string& md);
return messageDigest_.empty(); const std::string& getMessageDigest() const
} {
void setMessageDigest(const std::string& md) {
this->messageDigest_ = md;
}
const std::string& getMessageDigest() const {
return messageDigest_; return messageDigest_;
} }
void setAlgo(const std::string& algo) { void setAlgo(const std::string& algo);
this->algo_ = algo; const std::string& getAlgo() const
} {
const std::string& getAlgo() const {
return algo_; return algo_;
} }
}; };

View File

@ -39,9 +39,7 @@
#include "IteratableChecksumValidator.h" #include "IteratableChecksumValidator.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "PieceStorage.h" #include "PieceStorage.h"
#include "RequestGroupMan.h"
#include "FileAllocationEntry.h" #include "FileAllocationEntry.h"
#include "ServerStatMan.h"
#include "StreamFileAllocationEntry.h" #include "StreamFileAllocationEntry.h"
namespace aria2 { namespace aria2 {

91
src/ChunkChecksum.cc Normal file
View File

@ -0,0 +1,91 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "ChunkChecksum.h"
#include "A2STR.h"
namespace aria2 {
ChunkChecksum::ChunkChecksum():checksumLength_(0) {}
ChunkChecksum::ChunkChecksum
(const std::string& algo,
const std::vector<std::string>& checksums,
size_t checksumLength)
: algo_(algo),
checksums_(checksums),
checksumLength_(checksumLength)
{}
bool ChunkChecksum::validateChunk
(const std::string& actualChecksum,
size_t checksumIndex) const
{
if(checksumIndex < checksums_.size()) {
return actualChecksum == getChecksum(checksumIndex);
} else {
return false;
}
}
uint64_t ChunkChecksum::getEstimatedDataLength() const
{
return static_cast<uint64_t>(checksumLength_)*checksums_.size();
}
size_t ChunkChecksum::countChecksum() const
{
return checksums_.size();
}
const std::string& ChunkChecksum::getChecksum(size_t index) const
{
if(index < checksums_.size()) {
return checksums_[index];
} else {
return A2STR::NIL;
}
}
void ChunkChecksum::setAlgo(const std::string& algo)
{
algo_ = algo;
}
void ChunkChecksum::setChecksums(const std::vector<std::string>& mds)
{
checksums_ = mds;
}
} // namespace aria2

View File

@ -41,7 +41,6 @@
#include <vector> #include <vector>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "A2STR.h"
namespace aria2 { namespace aria2 {
@ -51,44 +50,22 @@ private:
std::vector<std::string> checksums_; std::vector<std::string> checksums_;
size_t checksumLength_; size_t checksumLength_;
public: public:
ChunkChecksum():checksumLength_(0) {} ChunkChecksum();
ChunkChecksum(const std::string& algo, ChunkChecksum(const std::string& algo,
const std::vector<std::string>& checksums, const std::vector<std::string>& checksums,
size_t checksumLength): size_t checksumLength);
algo_(algo),
checksums_(checksums),
checksumLength_(checksumLength) {}
bool validateChunk(const std::string& actualChecksum, bool validateChunk(const std::string& actualChecksum,
size_t checksumIndex) const size_t checksumIndex) const;
{
if(checksumIndex < checksums_.size()) {
return actualChecksum == getChecksum(checksumIndex);
} else {
return false;
}
}
uint64_t getEstimatedDataLength() const uint64_t getEstimatedDataLength() const;
{
return ((uint64_t)checksumLength_)*checksums_.size();
}
size_t countChecksum() const size_t countChecksum() const;
{
return checksums_.size();
}
const std::string& getChecksum(size_t index) const const std::string& getChecksum(size_t index) const;
{
if(index < checksums_.size()) {
return checksums_[index];
} else {
return A2STR::NIL;
}
}
void setChecksums(const std::vector<std::string>& mds);
const std::vector<std::string>& getChecksums() const const std::vector<std::string>& getChecksums() const
{ {
return checksums_; return checksums_;
@ -99,25 +76,16 @@ public:
return checksumLength_; return checksumLength_;
} }
void setAlgo(const std::string& algo);
const std::string& getAlgo() const const std::string& getAlgo() const
{ {
return algo_; return algo_;
} }
void setAlgo(const std::string& algo)
{
algo_ = algo;
}
void setChecksumLength(size_t length) void setChecksumLength(size_t length)
{ {
checksumLength_ = length; checksumLength_ = length;
} }
void setChecksums(const std::vector<std::string>& mds)
{
checksums_ = mds;
}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -36,7 +36,6 @@
#define D_COMMAND_H #define D_COMMAND_H
#include "common.h" #include "common.h"
#include <stdint.h>
namespace aria2 { namespace aria2 {

View File

@ -60,20 +60,40 @@
#include "util.h" #include "util.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "wallclock.h" #include "wallclock.h"
#include "ServerStatMan.h" #include "FileEntry.h"
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
# include "bittorrent_helper.h" # include "bittorrent_helper.h"
# include "Peer.h"
# include "PeerStorage.h" # include "PeerStorage.h"
# include "BtRegistry.h" # include "BtRegistry.h"
# include "BtProgressInfoFile.h"
# include "BtRuntime.h"
# include "BtAnnounce.h"
# include "PieceStorage.h"
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
namespace aria2 { namespace aria2 {
std::string SizeFormatter::operator()(int64_t size) const
{
return format(size);
}
namespace {
class AbbrevSizeFormatter:public SizeFormatter {
protected:
virtual std::string format(int64_t size) const
{
return util::abbrevSize(size);
}
};
} // namespace
namespace {
class PlainSizeFormatter:public SizeFormatter {
protected:
virtual std::string format(int64_t size) const
{
return util::itos(size);
}
};
} // namespace
namespace { namespace {
void printProgress void printProgress
(std::ostream& o, const SharedHandle<RequestGroup>& rg, const DownloadEngine* e, (std::ostream& o, const SharedHandle<RequestGroup>& rg, const DownloadEngine* e,

View File

@ -36,8 +36,10 @@
#define D_CONSOLE_STAT_CALC_H #define D_CONSOLE_STAT_CALC_H
#include "StatCalc.h" #include "StatCalc.h"
#include <string>
#include "TimerA2.h" #include "TimerA2.h"
#include "util.h"
namespace aria2 { namespace aria2 {
@ -47,26 +49,7 @@ protected:
public: public:
virtual ~SizeFormatter() {} virtual ~SizeFormatter() {}
std::string operator()(int64_t size) const std::string operator()(int64_t size) const;
{
return format(size);
}
};
class AbbrevSizeFormatter:public SizeFormatter {
protected:
virtual std::string format(int64_t size) const
{
return util::abbrevSize(size);
}
};
class PlainSizeFormatter:public SizeFormatter {
protected:
virtual std::string format(int64_t size) const
{
return util::itos(size);
}
}; };
class ConsoleStatCalc:public StatCalc class ConsoleStatCalc:public StatCalc

View File

@ -37,8 +37,12 @@
#include "common.h" #include "common.h"
namespace aria2 {
struct ContextAttribute { struct ContextAttribute {
virtual ~ContextAttribute() {} virtual ~ContextAttribute() {}
}; };
} // namespace aria2
#endif // D_CONTEXT_ATTRIBUTE_H #endif // D_CONTEXT_ATTRIBUTE_H

View File

@ -74,8 +74,40 @@ Cookie::Cookie():
creationTime_(0), creationTime_(0),
lastAccessTime_(0) {} lastAccessTime_(0) {}
Cookie::Cookie(const Cookie& c)
: name_(c.name_),
value_(c.value_),
expiryTime_(c.expiryTime_),
persistent_(c.persistent_),
domain_(c.domain_),
hostOnly_(c.hostOnly_),
path_(c.path_),
secure_(c.secure_),
httpOnly_(c.httpOnly_),
creationTime_(c.creationTime_),
lastAccessTime_(c.lastAccessTime_)
{}
Cookie::~Cookie() {} Cookie::~Cookie() {}
Cookie& Cookie::operator=(const Cookie& c)
{
if(this != &c) {
name_ = c.name_;
value_ = c.value_;
expiryTime_ = c.expiryTime_;
persistent_ = c.persistent_;
domain_ = c.domain_;
hostOnly_ = c.hostOnly_;
path_ = c.path_;
secure_ = c.secure_;
httpOnly_ = c.httpOnly_;
creationTime_ = c.creationTime_;
lastAccessTime_ = c.lastAccessTime_;
}
return *this;
}
std::string Cookie::toString() const std::string Cookie::toString() const
{ {
return strconcat(name_, '=', value_); return strconcat(name_, '=', value_);
@ -139,4 +171,24 @@ std::string Cookie::toNsCookieFormat() const
return ss.str(); return ss.str();
} }
void Cookie::setName(const std::string& name)
{
name_ = name;
}
void Cookie::setValue(const std::string& value)
{
value_ = value;
}
void Cookie::setDomain(const std::string& domain)
{
domain_ = domain;
}
void Cookie::setPath(const std::string& path)
{
path_ = path;
}
} // namespace aria2 } // namespace aria2

View File

@ -74,8 +74,12 @@ public:
bool httpOnly, bool httpOnly,
time_t creationTime); time_t creationTime);
Cookie(const Cookie& c);
~Cookie(); ~Cookie();
Cookie& operator=(const Cookie& c);
std::string toString() const; std::string toString() const;
bool match bool match
@ -91,20 +95,14 @@ public:
return name_; return name_;
} }
void setName(const std::string& name) void setName(const std::string& name);
{
name_ = name;
}
const std::string& getValue() const const std::string& getValue() const
{ {
return value_; return value_;
} }
void setValue(const std::string& value) void setValue(const std::string& value);
{
value_ = value;
}
time_t getExpiryTime() const time_t getExpiryTime() const
{ {
@ -131,10 +129,7 @@ public:
return domain_; return domain_;
} }
void setDomain(const std::string& domain) void setDomain(const std::string& domain);
{
domain_ = domain;
}
bool getHostOnly() const bool getHostOnly() const
{ {
@ -151,10 +146,7 @@ public:
return path_; return path_;
} }
void setPath(const std::string& path) void setPath(const std::string& path);
{
path_ = path;
}
bool getSecure() const bool getSecure() const
{ {

View File

@ -55,11 +55,30 @@
namespace aria2 { namespace aria2 {
CookieStorage::DomainEntry::DomainEntry CookieStorage::DomainEntry::DomainEntry(const std::string& domain)
(const std::string& domain): : key_(util::isNumericHost(domain)?domain:cookie::reverseDomainLevel(domain))
key_(util::isNumericHost(domain)?domain:cookie::reverseDomainLevel(domain))
{} {}
CookieStorage::DomainEntry::DomainEntry
(const DomainEntry& c)
: key_(c.key_),
lastAccessTime_(c.lastAccessTime_),
cookies_(c.cookies_)
{}
CookieStorage::DomainEntry::~DomainEntry() {}
CookieStorage::DomainEntry& CookieStorage::DomainEntry::operator=
(const DomainEntry& c)
{
if(this != &c) {
key_ = c.key_;
lastAccessTime_ = c.lastAccessTime_;
cookies_ = c.cookies_;
}
return *this;
}
bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now) bool CookieStorage::DomainEntry::addCookie(const Cookie& cookie, time_t now)
{ {
setLastAccessTime(now); setLastAccessTime(now);
@ -109,6 +128,17 @@ void CookieStorage::DomainEntry::writeCookie(std::ostream& o) const
} }
} }
size_t CookieStorage::DomainEntry::countCookie() const
{
return cookies_.size();
}
bool CookieStorage::DomainEntry::operator<(const DomainEntry& de) const
{
return key_ < de.key_;
}
CookieStorage::CookieStorage():logger_(LogFactory::getInstance()) {} CookieStorage::CookieStorage():logger_(LogFactory::getInstance()) {}
CookieStorage::~CookieStorage() {} CookieStorage::~CookieStorage() {}

View File

@ -66,6 +66,10 @@ public:
std::deque<Cookie> cookies_; std::deque<Cookie> cookies_;
public: public:
DomainEntry(const std::string& domain); DomainEntry(const std::string& domain);
DomainEntry(const DomainEntry& c);
~DomainEntry();
DomainEntry& operator=(const DomainEntry& c);
const std::string& getKey() const const std::string& getKey() const
{ {
@ -89,10 +93,7 @@ public:
return out; return out;
} }
size_t countCookie() const size_t countCookie() const;
{
return cookies_.size();
}
bool addCookie(const Cookie& cookie, time_t now); bool addCookie(const Cookie& cookie, time_t now);
@ -116,10 +117,7 @@ public:
return std::copy(cookies_.begin(), cookies_.end(), out); return std::copy(cookies_.begin(), cookies_.end(), out);
} }
bool operator<(const DomainEntry& de) const bool operator<(const DomainEntry& de) const;
{
return key_ < de.key_;
}
}; };
private: private:
std::deque<DomainEntry> domains_; std::deque<DomainEntry> domains_;

View File

@ -44,9 +44,7 @@
#include "prefs.h" #include "prefs.h"
#include "Option.h" #include "Option.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "FileAllocationEntry.h" #include "FileEntry.h"
#include "CheckIntegrityEntry.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

View File

@ -43,7 +43,6 @@
#include "DHTRoutingTableSerializer.h" #include "DHTRoutingTableSerializer.h"
#include "RecoverableException.h" #include "RecoverableException.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "util.h"
#include "DHTBucket.h" #include "DHTBucket.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "prefs.h" #include "prefs.h"
@ -54,9 +53,6 @@
#include "FileEntry.h" #include "FileEntry.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -39,10 +39,6 @@
#include "DHTTask.h" #include "DHTTask.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "FileEntry.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -34,9 +34,6 @@
/* copyright --> */ /* copyright --> */
#include "DHTEntryPointNameResolveCommand.h" #include "DHTEntryPointNameResolveCommand.h"
#include "DownloadEngine.h" #include "DownloadEngine.h"
#ifdef ENABLE_ASYNC_DNS
#include "AsyncNameResolver.h"
#endif // ENABLE_ASYNC_DNS
#include "NameResolver.h" #include "NameResolver.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "prefs.h" #include "prefs.h"
@ -51,10 +48,9 @@
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "Logger.h" #include "Logger.h"
#include "StringFormat.h" #include "StringFormat.h"
#include "FileEntry.h" #ifdef ENABLE_ASYNC_DNS
#include "ServerStatMan.h" #include "AsyncNameResolver.h"
#include "FileAllocationEntry.h" #endif // ENABLE_ASYNC_DNS
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -47,10 +47,6 @@
#include "bittorrent_helper.h" #include "bittorrent_helper.h"
#include "DownloadContext.h" #include "DownloadContext.h"
#include "wallclock.h" #include "wallclock.h"
#include "RequestGroupMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
#include "ServerStatMan.h"
namespace aria2 { namespace aria2 {

View File

@ -45,10 +45,6 @@
#include "Logger.h" #include "Logger.h"
#include "DHTMessageCallback.h" #include "DHTMessageCallback.h"
#include "DHTNode.h" #include "DHTNode.h"
#include "FileEntry.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -53,6 +53,8 @@ DHTMessageTrackerEntry::DHTMessageTrackerEntry(const SharedHandle<DHTMessage>& s
timeout_(timeout) timeout_(timeout)
{} {}
DHTMessageTrackerEntry::~DHTMessageTrackerEntry() {}
bool DHTMessageTrackerEntry::isTimeout() const bool DHTMessageTrackerEntry::isTimeout() const
{ {
return dispatchedTime_.difference(global::wallclock) >= timeout_; return dispatchedTime_.difference(global::wallclock) >= timeout_;
@ -77,4 +79,9 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std::
return false; return false;
} }
int64_t DHTMessageTrackerEntry::getElapsedMillis() const
{
return dispatchedTime_.differenceInMillis(global::wallclock);
}
} // namespace aria2 } // namespace aria2

View File

@ -69,6 +69,8 @@ public:
const SharedHandle<DHTMessageCallback>& callback = const SharedHandle<DHTMessageCallback>& callback =
SharedHandle<DHTMessageCallback>()); SharedHandle<DHTMessageCallback>());
~DHTMessageTrackerEntry();
bool isTimeout() const; bool isTimeout() const;
void extendTimeout(); void extendTimeout();
@ -90,10 +92,7 @@ public:
return callback_; return callback_;
} }
int64_t getElapsedMillis() const int64_t getElapsedMillis() const;
{
return dispatchedTime_.differenceInMillis(global::wallclock);
}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -53,6 +53,8 @@ DHTNode::DHTNode(const unsigned char* id):port_(0), rtt_(0), condition_(1), last
memcpy(id_, id, DHT_ID_LENGTH); memcpy(id_, id, DHT_ID_LENGTH);
} }
DHTNode::~DHTNode() {}
void DHTNode::generateID() void DHTNode::generateID()
{ {
util::generateRandomKey(id_); util::generateRandomKey(id_);
@ -126,4 +128,9 @@ void DHTNode::setID(const unsigned char* id)
memcpy(id_, id, DHT_ID_LENGTH); memcpy(id_, id, DHT_ID_LENGTH);
} }
void DHTNode::setIPAddress(const std::string& ipaddr)
{
ipaddr_ = ipaddr;
}
} // namespace aria2 } // namespace aria2

View File

@ -36,10 +36,12 @@
#define D_DHT_NODE_H #define D_DHT_NODE_H
#include "common.h" #include "common.h"
#include <string>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "DHTConstants.h" #include "DHTConstants.h"
#include "TimerA2.h" #include "TimerA2.h"
#include <string>
namespace aria2 { namespace aria2 {
@ -65,6 +67,8 @@ public:
*/ */
DHTNode(const unsigned char* id); DHTNode(const unsigned char* id);
~DHTNode();
void generateID(); void generateID();
const unsigned char* getID() const const unsigned char* getID() const
@ -82,10 +86,7 @@ public:
return ipaddr_; return ipaddr_;
} }
void setIPAddress(const std::string& ipaddr) void setIPAddress(const std::string& ipaddr);
{
ipaddr_ = ipaddr;
}
void setID(const unsigned char* id); void setID(const unsigned char* id);

View File

@ -39,10 +39,6 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "FileEntry.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {

View File

@ -39,10 +39,6 @@
#include "RecoverableException.h" #include "RecoverableException.h"
#include "message.h" #include "message.h"
#include "Logger.h" #include "Logger.h"
#include "FileEntry.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "CheckIntegrityEntry.h"
namespace aria2 { namespace aria2 {

209
src/DNSCache.cc Normal file
View File

@ -0,0 +1,209 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "DNSCache.h"
#include "A2STR.h"
namespace aria2 {
DNSCache::AddrEntry::AddrEntry(const std::string& addr)
: addr_(addr), good_(true)
{}
DNSCache::AddrEntry::AddrEntry(const AddrEntry& c)
: addr_(c.addr_), good_(c.good_)
{}
DNSCache::AddrEntry::~AddrEntry() {}
DNSCache::AddrEntry& DNSCache::AddrEntry::operator=(const AddrEntry& c)
{
if(this != &c) {
addr_ = c.addr_;
good_ = c.good_;
}
return *this;
}
DNSCache::CacheEntry::CacheEntry(const std::string& hostname, uint16_t port)
: hostname_(hostname), port_(port)
{}
DNSCache::CacheEntry::CacheEntry(const CacheEntry& c)
: hostname_(c.hostname_), port_(c.port_), addrEntries_(c.addrEntries_)
{}
DNSCache::CacheEntry::~CacheEntry() {}
DNSCache::CacheEntry& DNSCache::CacheEntry::operator=(const CacheEntry& c)
{
if(this != &c) {
hostname_ = c.hostname_;
port_ = c.port_;
addrEntries_ = c.addrEntries_;
}
return *this;
}
void DNSCache::CacheEntry::add(const std::string& addr)
{
addrEntries_.push_back(AddrEntry(addr));
}
std::vector<DNSCache::AddrEntry>::iterator DNSCache::CacheEntry::find
(const std::string& addr)
{
for(std::vector<AddrEntry>::iterator i = addrEntries_.begin(),
eoi = addrEntries_.end(); i != eoi; ++i) {
if((*i).addr_ == addr) {
return i;
}
}
return addrEntries_.end();
}
std::vector<DNSCache::AddrEntry>::const_iterator DNSCache::CacheEntry::find
(const std::string& addr) const
{
for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(),
eoi = addrEntries_.end(); i != eoi; ++i) {
if((*i).addr_ == addr) {
return i;
}
}
return addrEntries_.end();
}
bool DNSCache::CacheEntry::contains(const std::string& addr) const
{
return find(addr) != addrEntries_.end();
}
const std::string& DNSCache::CacheEntry::getGoodAddr() const
{
for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(),
eoi = addrEntries_.end(); i != eoi; ++i) {
if((*i).good_) {
return (*i).addr_;
}
}
return A2STR::NIL;
}
void DNSCache::CacheEntry::markBad(const std::string& addr)
{
std::vector<AddrEntry>::iterator i = find(addr);
if(i != addrEntries_.end()) {
(*i).good_ = false;
}
}
bool DNSCache::CacheEntry::operator<(const CacheEntry& e) const
{
int r = hostname_.compare(e.hostname_);
if(r != 0) {
return r < 0;
}
return port_ < e.port_;
}
bool DNSCache::CacheEntry::operator==(const CacheEntry& e) const
{
return hostname_ == e.hostname_ && port_ == e.port_;
}
DNSCache::DNSCache() {}
DNSCache::DNSCache(const DNSCache& c):entries_(c.entries_) {}
DNSCache::~DNSCache() {}
DNSCache& DNSCache::operator=(const DNSCache& c)
{
if(this != &c) {
entries_ = c.entries_;
}
return *this;
}
const std::string& DNSCache::find
(const std::string& hostname, uint16_t port) const
{
CacheEntry target(hostname, port);
std::deque<CacheEntry>::const_iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target);
if(i != entries_.end() && (*i) == target) {
return (*i).getGoodAddr();
}
return A2STR::NIL;
}
void DNSCache::put
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
{
CacheEntry target(hostname, port);
std::deque<CacheEntry>::iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target);
if(i == entries_.end() || !((*i) == target)) {
target.add(ipaddr);
entries_.insert(i, target);
} else {
if(!(*i).contains(ipaddr)) {
(*i).add(ipaddr);
}
}
}
void DNSCache::markBad
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
{
CacheEntry target(hostname, port);
std::deque<CacheEntry>::iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target);
if(i != entries_.end() && (*i) == target) {
(*i).markBad(ipaddr);
}
}
void DNSCache::remove(const std::string& hostname, uint16_t port)
{
CacheEntry target(hostname, port);
std::deque<CacheEntry>::iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target);
if(i != entries_.end() && (*i) == target) {
entries_.erase(i);
}
}
} // namespace aria2

View File

@ -42,8 +42,6 @@
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
#include "A2STR.h"
namespace aria2 { namespace aria2 {
class DNSCache { class DNSCache {
@ -52,7 +50,11 @@ private:
std::string addr_; std::string addr_;
bool good_; bool good_;
AddrEntry(const std::string& addr):addr_(addr), good_(true) {} AddrEntry(const std::string& addr);
AddrEntry(const AddrEntry& c);
~AddrEntry();
AddrEntry& operator=(const AddrEntry& c);
}; };
struct CacheEntry { struct CacheEntry {
@ -60,52 +62,21 @@ private:
uint16_t port_; uint16_t port_;
std::vector<AddrEntry> addrEntries_; std::vector<AddrEntry> addrEntries_;
CacheEntry CacheEntry(const std::string& hostname, uint16_t port);
(const std::string& hostname, uint16_t port): CacheEntry(const CacheEntry& c);
hostname_(hostname), port_(port) {} ~CacheEntry();
void add(const std::string& addr) CacheEntry& operator=(const CacheEntry& c);
{
addrEntries_.push_back(AddrEntry(addr));
}
std::vector<AddrEntry>::iterator find(const std::string& addr) void add(const std::string& addr);
{
for(std::vector<AddrEntry>::iterator i = addrEntries_.begin(),
eoi = addrEntries_.end(); i != eoi; ++i) {
if((*i).addr_ == addr) {
return i;
}
}
return addrEntries_.end();
}
std::vector<AddrEntry>::const_iterator find(const std::string& addr) const std::vector<AddrEntry>::iterator find(const std::string& addr);
{
for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(),
eoi = addrEntries_.end(); i != eoi; ++i) {
if((*i).addr_ == addr) {
return i;
}
}
return addrEntries_.end();
}
bool contains(const std::string& addr) const std::vector<AddrEntry>::const_iterator find(const std::string& addr) const;
{
return find(addr) != addrEntries_.end();
}
const std::string& getGoodAddr() const bool contains(const std::string& addr) const;
{
for(std::vector<AddrEntry>::const_iterator i = addrEntries_.begin(), const std::string& getGoodAddr() const;
eoi = addrEntries_.end(); i != eoi; ++i) {
if((*i).good_) {
return (*i).addr_;
}
}
return A2STR::NIL;
}
template<typename OutputIterator> template<typename OutputIterator>
void getAllGoodAddrs(OutputIterator out) const void getAllGoodAddrs(OutputIterator out) const
@ -118,42 +89,23 @@ private:
} }
} }
void markBad(const std::string& addr) void markBad(const std::string& addr);
{
std::vector<AddrEntry>::iterator i = find(addr);
if(i != addrEntries_.end()) {
(*i).good_ = false;
}
}
bool operator<(const CacheEntry& e) const bool operator<(const CacheEntry& e) const;
{
int r = hostname_.compare(e.hostname_);
if(r != 0) {
return r < 0;
}
return port_ < e.port_;
}
bool operator==(const CacheEntry& e) const bool operator==(const CacheEntry& e) const;
{
return hostname_ == e.hostname_ && port_ == e.port_;
}
}; };
std::deque<CacheEntry> entries_; std::deque<CacheEntry> entries_;
public: public:
const std::string& find(const std::string& hostname, uint16_t port) const DNSCache();
{ DNSCache(const DNSCache& c);
CacheEntry target(hostname, port); ~DNSCache();
std::deque<CacheEntry>::const_iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target); DNSCache& operator=(const DNSCache& c);
if(i != entries_.end() && (*i) == target) {
return (*i).getGoodAddr(); const std::string& find(const std::string& hostname, uint16_t port) const;
}
return A2STR::NIL;
}
template<typename OutputIterator> template<typename OutputIterator>
void findAll void findAll
@ -168,41 +120,12 @@ public:
} }
void put void put
(const std::string& hostname, const std::string& ipaddr, uint16_t port) (const std::string& hostname, const std::string& ipaddr, uint16_t port);
{
CacheEntry target(hostname, port);
std::deque<CacheEntry>::iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target);
if(i == entries_.end() || !((*i) == target)) {
target.add(ipaddr);
entries_.insert(i, target);
} else {
if(!(*i).contains(ipaddr)) {
(*i).add(ipaddr);
}
}
}
void markBad void markBad
(const std::string& hostname, const std::string& ipaddr, uint16_t port) (const std::string& hostname, const std::string& ipaddr, uint16_t port);
{
CacheEntry target(hostname, port);
std::deque<CacheEntry>::iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target);
if(i != entries_.end() && (*i) == target) {
(*i).markBad(ipaddr);
}
}
void remove(const std::string& hostname, uint16_t port) void remove(const std::string& hostname, uint16_t port);
{
CacheEntry target(hostname, port);
std::deque<CacheEntry>::iterator i =
std::lower_bound(entries_.begin(), entries_.end(), target);
if(i != entries_.end() && (*i) == target) {
entries_.erase(i);
}
}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -43,4 +43,6 @@ DiskAdaptor::DiskAdaptor():
fallocate_(false), fallocate_(false),
logger_(LogFactory::getInstance()) {} logger_(LogFactory::getInstance()) {}
DiskAdaptor::~DiskAdaptor() {}
} // namespace aria2 } // namespace aria2

View File

@ -62,7 +62,7 @@ protected:
} }
public: public:
DiskAdaptor(); DiskAdaptor();
virtual ~DiskAdaptor() {} virtual ~DiskAdaptor();
virtual void openFile() = 0; virtual void openFile() = 0;

View File

@ -58,9 +58,8 @@
#include "StringFormat.h" #include "StringFormat.h"
#include "RequestGroupMan.h" #include "RequestGroupMan.h"
#include "wallclock.h" #include "wallclock.h"
#include "ServerStatMan.h"
#include "FileAllocationEntry.h"
#include "SinkStreamFilter.h" #include "SinkStreamFilter.h"
#include "FileEntry.h"
#ifdef ENABLE_MESSAGE_DIGEST #ifdef ENABLE_MESSAGE_DIGEST
# include "MessageDigest.h" # include "MessageDigest.h"
# include "MessageDigestHelper.h" # include "MessageDigestHelper.h"

View File

@ -37,6 +37,8 @@
#include "AbstractCommand.h" #include "AbstractCommand.h"
#include <unistd.h>
namespace aria2 { namespace aria2 {
class PeerStat; class PeerStat;

View File

@ -42,6 +42,8 @@
#include "wallclock.h" #include "wallclock.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "a2functional.h" #include "a2functional.h"
#include "Signature.h"
#include "ContextAttribute.h"
namespace aria2 { namespace aria2 {
@ -69,6 +71,8 @@ DownloadContext::DownloadContext(size_t pieceLength,
fileEntries_.push_back(fileEntry); fileEntries_.push_back(fileEntry);
} }
DownloadContext::~DownloadContext() {}
void DownloadContext::resetDownloadStartTime() void DownloadContext::resetDownloadStartTime()
{ {
downloadStartTime_ = global::wallclock; downloadStartTime_ = global::wallclock;
@ -226,4 +230,43 @@ bool DownloadContext::isPieceHashVerificationAvailable() const
pieceHashes_.size() > 0 && pieceHashes_.size() == getNumPieces(); pieceHashes_.size() > 0 && pieceHashes_.size() == getNumPieces();
} }
const std::string& DownloadContext::getPieceHash(size_t index) const
{
if(index < pieceHashes_.size()) {
return pieceHashes_[index];
} else {
return A2STR::NIL;
}
}
void DownloadContext::setPieceHashAlgo(const std::string& algo)
{
pieceHashAlgo_ = algo;
}
void DownloadContext::setChecksum(const std::string& checksum)
{
checksum_ = checksum;
}
void DownloadContext::setChecksumHashAlgo(const std::string& algo)
{
checksumHashAlgo_ = algo;
}
void DownloadContext::setBasePath(const std::string& basePath)
{
basePath_ = basePath;
}
void DownloadContext::setDir(const std::string& dir)
{
dir_ = dir;
}
void DownloadContext::setSignature(const SharedHandle<Signature>& signature)
{
signature_ = signature;
}
} // namespace aria2 } // namespace aria2

View File

@ -42,17 +42,17 @@
#include <vector> #include <vector>
#include "SharedHandle.h" #include "SharedHandle.h"
#include "Signature.h"
#include "TimerA2.h" #include "TimerA2.h"
#include "A2STR.h" #include "A2STR.h"
#include "ValueBase.h" #include "ValueBase.h"
#include "IntSequence.h" #include "IntSequence.h"
#include "FileEntry.h"
#include "TorrentAttribute.h"
namespace aria2 { namespace aria2 {
class RequestGroup; class RequestGroup;
class Signature;
class FileEntry;
class ContextAttribute;
class DownloadContext class DownloadContext
{ {
@ -95,14 +95,9 @@ public:
uint64_t totalLength, uint64_t totalLength,
const std::string& path = A2STR::NIL); const std::string& path = A2STR::NIL);
const std::string& getPieceHash(size_t index) const ~DownloadContext();
{
if(index < pieceHashes_.size()) { const std::string& getPieceHash(size_t index) const;
return pieceHashes_[index];
} else {
return A2STR::NIL;
}
}
const std::vector<std::string>& getPieceHashes() const const std::vector<std::string>& getPieceHashes() const
{ {
@ -148,24 +143,15 @@ public:
const std::string& getPieceHashAlgo() const { return pieceHashAlgo_; } const std::string& getPieceHashAlgo() const { return pieceHashAlgo_; }
void setPieceHashAlgo(const std::string& algo) void setPieceHashAlgo(const std::string& algo);
{
pieceHashAlgo_ = algo;
}
const std::string& getChecksum() const { return checksum_; } const std::string& getChecksum() const { return checksum_; }
void setChecksum(const std::string& checksum) void setChecksum(const std::string& checksum);
{
checksum_ = checksum;
}
const std::string& getChecksumHashAlgo() const { return checksumHashAlgo_; } const std::string& getChecksumHashAlgo() const { return checksumHashAlgo_; }
void setChecksumHashAlgo(const std::string& algo) void setChecksumHashAlgo(const std::string& algo);
{
checksumHashAlgo_ = algo;
}
// The representative path name for this context. It is used as a // The representative path name for this context. It is used as a
// part of .aria2 control file. If basePath_ is set, returns // part of .aria2 control file. If basePath_ is set, returns
@ -173,18 +159,15 @@ public:
// returned. // returned.
const std::string& getBasePath() const; const std::string& getBasePath() const;
void setBasePath(const std::string& basePath) { basePath_ = basePath; } void setBasePath(const std::string& basePath);
const std::string& getDir() const { return dir_; } const std::string& getDir() const { return dir_; }
void setDir(const std::string& dir) { dir_ = dir; } void setDir(const std::string& dir);
const SharedHandle<Signature>& getSignature() const { return signature_; } const SharedHandle<Signature>& getSignature() const { return signature_; }
void setSignature(const SharedHandle<Signature>& signature) void setSignature(const SharedHandle<Signature>& signature);
{
signature_ = signature;
}
RequestGroup* getOwnerRequestGroup() { return ownerRequestGroup_; } RequestGroup* getOwnerRequestGroup() { return ownerRequestGroup_; }

View File

@ -66,10 +66,6 @@
#include "DownloadContext.h" #include "DownloadContext.h"
#ifdef ENABLE_BITTORRENT #ifdef ENABLE_BITTORRENT
# include "BtRegistry.h" # include "BtRegistry.h"
# include "PeerStorage.h"
# include "PieceStorage.h"
# include "BtAnnounce.h"
# include "BtRuntime.h"
#endif // ENABLE_BITTORRENT #endif // ENABLE_BITTORRENT
namespace aria2 { namespace aria2 {
@ -540,4 +536,32 @@ void DownloadEngine::setRefreshInterval(int64_t interval)
refreshInterval_ = interval; refreshInterval_ = interval;
} }
void DownloadEngine::addCommand(const std::vector<Command*>& commands)
{
commands_.insert(commands_.end(), commands.begin(), commands.end());
}
void DownloadEngine::addCommand(Command* command)
{
commands_.push_back(command);
}
void DownloadEngine::setRequestGroupMan
(const SharedHandle<RequestGroupMan>& rgman)
{
requestGroupMan_ = rgman;
}
void DownloadEngine::setFileAllocationMan
(const SharedHandle<FileAllocationMan>& faman)
{
fileAllocationMan_ = faman;
}
void DownloadEngine::setCheckIntegrityMan
(const SharedHandle<CheckIntegrityMan>& ciman)
{
checkIntegrityMan_ = ciman;
}
} // namespace aria2 } // namespace aria2

View File

@ -46,13 +46,13 @@
#include "a2netcompat.h" #include "a2netcompat.h"
#include "TimerA2.h" #include "TimerA2.h"
#include "a2io.h" #include "a2io.h"
#ifdef ENABLE_ASYNC_DNS
# include "AsyncNameResolver.h"
#endif // ENABLE_ASYNC_DNS
#include "CUIDCounter.h" #include "CUIDCounter.h"
#include "FileAllocationMan.h" #include "FileAllocationMan.h"
#include "CheckIntegrityMan.h" #include "CheckIntegrityMan.h"
#include "DNSCache.h" #include "DNSCache.h"
#ifdef ENABLE_ASYNC_DNS
# include "AsyncNameResolver.h"
#endif // ENABLE_ASYNC_DNS
namespace aria2 { namespace aria2 {
@ -187,45 +187,30 @@ public:
Command* command); Command* command);
#endif // ENABLE_ASYNC_DNS #endif // ENABLE_ASYNC_DNS
void addCommand(const std::vector<Command*>& commands) void addCommand(const std::vector<Command*>& commands);
{
commands_.insert(commands_.end(), commands.begin(), commands.end());
}
void addCommand(Command* command) void addCommand(Command* command);
{
commands_.push_back(command);
}
const SharedHandle<RequestGroupMan>& getRequestGroupMan() const const SharedHandle<RequestGroupMan>& getRequestGroupMan() const
{ {
return requestGroupMan_; return requestGroupMan_;
} }
void setRequestGroupMan(const SharedHandle<RequestGroupMan>& rgman) void setRequestGroupMan(const SharedHandle<RequestGroupMan>& rgman);
{
requestGroupMan_ = rgman;
}
const SharedHandle<FileAllocationMan>& getFileAllocationMan() const const SharedHandle<FileAllocationMan>& getFileAllocationMan() const
{ {
return fileAllocationMan_; return fileAllocationMan_;
} }
void setFileAllocationMan(const SharedHandle<FileAllocationMan>& faman) void setFileAllocationMan(const SharedHandle<FileAllocationMan>& faman);
{
fileAllocationMan_ = faman;
}
const SharedHandle<CheckIntegrityMan>& getCheckIntegrityMan() const const SharedHandle<CheckIntegrityMan>& getCheckIntegrityMan() const
{ {
return checkIntegrityMan_; return checkIntegrityMan_;
} }
void setCheckIntegrityMan(const SharedHandle<CheckIntegrityMan>& ciman) void setCheckIntegrityMan(const SharedHandle<CheckIntegrityMan>& ciman);
{
checkIntegrityMan_ = ciman;
}
Option* getOption() const Option* getOption() const
{ {

46
src/DownloadResult.cc Normal file
View File

@ -0,0 +1,46 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "DownloadResult.h"
#include "FileEntry.h"
#include "Option.h"
#include "MetadataInfo.h"
namespace aria2 {
DownloadResult::DownloadResult() {}
DownloadResult::~DownloadResult() {}
} // namespace aria2

View File

@ -45,12 +45,12 @@
#include "SharedHandle.h" #include "SharedHandle.h"
#include "DownloadResultCode.h" #include "DownloadResultCode.h"
#include "RequestGroup.h" #include "RequestGroup.h"
#include "Option.h"
#include "MetadataInfo.h"
namespace aria2 { namespace aria2 {
class Option;
class FileEntry; class FileEntry;
class MetadataInfo;
struct DownloadResult struct DownloadResult
{ {
@ -94,6 +94,13 @@ struct DownloadResult
size_t numPieces; size_t numPieces;
std::string dir; std::string dir;
DownloadResult();
~DownloadResult();
// Don't allow copying
DownloadResult(const DownloadResult& c);
DownloadResult& operator=(const DownloadResult& c);
}; };
typedef SharedHandle<DownloadResult> DownloadResultHandle; typedef SharedHandle<DownloadResult> DownloadResultHandle;

View File

@ -72,4 +72,9 @@ std::string Exception::stackTrace() const
return s.str(); return s.str();
} }
const char* Exception::what() const throw()
{
return msg_.c_str();
}
} // namespace aria2 } // namespace aria2

View File

@ -71,10 +71,7 @@ public:
virtual ~Exception() throw(); virtual ~Exception() throw();
virtual const char* what() const throw() virtual const char* what() const throw();
{
return msg_.c_str();
}
std::string stackTrace() const; std::string stackTrace() const;

View File

@ -0,0 +1,78 @@
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2010 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 "ExtensionMessageRegistry.h"
#include "BtConstants.h"
#include "A2STR.h"
namespace aria2 {
ExtensionMessageRegistry::ExtensionMessageRegistry()
{
extensions_["ut_pex"] = 8;
// http://www.bittorrent.org/beps/bep_0009.html
extensions_["ut_metadata"] = 9;
}
ExtensionMessageRegistry::~ExtensionMessageRegistry() {}
uint8_t ExtensionMessageRegistry::getExtensionMessageID
(const std::string& name) const
{
Extensions::const_iterator itr = extensions_.find(name);
if(itr == extensions_.end()) {
return 0;
} else {
return (*itr).second;
}
}
const std::string& ExtensionMessageRegistry::getExtensionName(uint8_t id) const
{
for(Extensions::const_iterator itr = extensions_.begin(),
eoi = extensions_.end(); itr != eoi; ++itr) {
const Extensions::value_type& p = *itr;
if(p.second == id) {
return p.first;
}
}
return A2STR::NIL;
}
void ExtensionMessageRegistry::removeExtension(const std::string& name)
{
extensions_.erase(name);
}
} // namespace aria2

View File

@ -40,7 +40,6 @@
#include <string> #include <string>
#include "BtConstants.h" #include "BtConstants.h"
#include "A2STR.h"
namespace aria2 { namespace aria2 {
@ -48,44 +47,20 @@ class ExtensionMessageRegistry {
private: private:
Extensions extensions_; Extensions extensions_;
public: public:
ExtensionMessageRegistry() ExtensionMessageRegistry();
{
extensions_["ut_pex"] = 8; ~ExtensionMessageRegistry();
// http://www.bittorrent.org/beps/bep_0009.html
extensions_["ut_metadata"] = 9;
}
const Extensions& getExtensions() const const Extensions& getExtensions() const
{ {
return extensions_; return extensions_;
} }
uint8_t getExtensionMessageID(const std::string& name) const uint8_t getExtensionMessageID(const std::string& name) const;
{
Extensions::const_iterator itr = extensions_.find(name);
if(itr == extensions_.end()) {
return 0;
} else {
return (*itr).second;
}
}
const std::string& getExtensionName(uint8_t id) const const std::string& getExtensionName(uint8_t id) const;
{
for(Extensions::const_iterator itr = extensions_.begin(),
eoi = extensions_.end(); itr != eoi; ++itr) {
const Extensions::value_type& p = *itr;
if(p.second == id) {
return p.first;
}
}
return A2STR::NIL;
}
void removeExtension(const std::string& name) void removeExtension(const std::string& name);
{
extensions_.erase(name);
}
}; };
} // namespace aria2 } // namespace aria2

View File

@ -120,6 +120,8 @@ FeatureConfig::FeatureConfig() {
features_.insert(vbegin(featureArray), vend(featureArray)); features_.insert(vbegin(featureArray), vend(featureArray));
} }
FeatureConfig::~FeatureConfig() {}
const SharedHandle<FeatureConfig>& FeatureConfig::getInstance() const SharedHandle<FeatureConfig>& FeatureConfig::getInstance()
{ {
if(!featureConfig_) { if(!featureConfig_) {

View File

@ -56,6 +56,8 @@ private:
FeatureConfig(); FeatureConfig();
public: public:
~FeatureConfig();
static const SharedHandle<FeatureConfig>& getInstance(); static const SharedHandle<FeatureConfig>& getInstance();
uint16_t getDefaultPort(const std::string& protocol) const; uint16_t getDefaultPort(const std::string& protocol) const;

View File

@ -56,8 +56,18 @@ namespace aria2 {
File::File(const std::string& name) : name_(name) {} File::File(const std::string& name) : name_(name) {}
File::File(const File& c) : name_(c.name_) {}
File::~File() {} File::~File() {}
File& File::operator=(const File& c)
{
if(this != &c) {
name_ = c.name_;
}
return *this;
}
int File::fillStat(a2_struct_stat& fstat) { int File::fillStat(a2_struct_stat& fstat) {
return a2stat(name_.c_str(), &fstat); return a2stat(name_.c_str(), &fstat);
} }

View File

@ -57,8 +57,13 @@ private:
int fillStat(a2_struct_stat& fstat); int fillStat(a2_struct_stat& fstat);
public: public:
File(const std::string& name); File(const std::string& name);
File(const File& c);
~File(); ~File();
File& operator=(const File& c);
/** /**
* Tests whether the file or directory denoted by name exists. * Tests whether the file or directory denoted by name exists.
*/ */

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