2008-06-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Renamed BtRuntime::lessThanMinPeers() and 
BtRuntime::lessThanEqMinPeers.
	Made MAX_PEERS and MIN_PEERS static const members of BtRuntime.
	* src/ActivePeerConnectionCommand.cc
	* src/BtConstants.h
	* src/BtRuntime.h
	* src/DHTGetPeersCommand.cc
	* src/DefaultBtAnnounce.cc
	* src/DefaultPeerStorage.cc: Calculate maxPeerListSize based on
	BtRuntime::MAX_PEERS.
	* src/DefaultPeerStorage.h
	* src/InitiatorMSEHandshakeCommand.cc
	* src/PeerInitiateConnectionCommand.cc
	* src/PeerInteractionCommand.cc
	* src/PeerReceiveHandshakeCommand.cc
	* src/TrackerWatcherCommand.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-06-05 13:17:46 +00:00
parent 4a454e94b7
commit d773613e93
13 changed files with 40 additions and 25 deletions

View File

@ -1,3 +1,21 @@
2008-06-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Renamed BtRuntime::lessThanMinPeers() and BtRuntime::lessThanEqMinPeers.
Made MAX_PEERS and MIN_PEERS static const members of BtRuntime.
* src/ActivePeerConnectionCommand.cc
* src/BtConstants.h
* src/BtRuntime.h
* src/DHTGetPeersCommand.cc
* src/DefaultBtAnnounce.cc
* src/DefaultPeerStorage.cc: Calculate maxPeerListSize based on
BtRuntime::MAX_PEERS.
* src/DefaultPeerStorage.h
* src/InitiatorMSEHandshakeCommand.cc
* src/PeerInitiateConnectionCommand.cc
* src/PeerInteractionCommand.cc
* src/PeerReceiveHandshakeCommand.cc
* src/TrackerWatcherCommand.cc
2008-06-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2008-06-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Always Connect to _numNewConnection Always Connect to _numNewConnection

View File

@ -79,7 +79,7 @@ bool ActivePeerConnectionCommand::execute() {
checkPoint.reset(); checkPoint.reset();
TransferStat tstat = peerStorage->calculateStat(); TransferStat tstat = peerStorage->calculateStat();
if(tstat.getDownloadSpeed() < _thresholdSpeed || if(tstat.getDownloadSpeed() < _thresholdSpeed ||
btRuntime->lessThanMinPeer()) { btRuntime->lessThanMinPeers()) {
for(size_t numAdd = _numNewConnection; for(size_t numAdd = _numNewConnection;
numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) { numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) {
PeerHandle peer = peerStorage->getUnusedPeer(); PeerHandle peer = peerStorage->getUnusedPeer();

View File

@ -45,10 +45,6 @@ typedef std::map<std::string, uint8_t> Extensions;
#define INFO_HASH_LENGTH 20 #define INFO_HASH_LENGTH 20
#define MAX_PEER_ERROR 5
#define MAX_PEERS 55
#define DEFAULT_LATENCY 1500 #define DEFAULT_LATENCY 1500
#endif // _D_BT_CONSTANTS_ #endif // _D_BT_CONSTANTS_

View File

@ -40,8 +40,6 @@
namespace aria2 { namespace aria2 {
#define MIN_PEERS 40
class BtRuntime { class BtRuntime {
private: private:
uint64_t uploadLengthAtStartup; uint64_t uploadLengthAtStartup;
@ -49,6 +47,9 @@ private:
bool halt; bool halt;
unsigned int connections; unsigned int connections;
bool _ready; bool _ready;
static const unsigned int MIN_PEERS = 40;
public: public:
BtRuntime(): BtRuntime():
uploadLengthAtStartup(0), uploadLengthAtStartup(0),
@ -86,13 +87,17 @@ public:
void decreaseConnections() { connections--; } void decreaseConnections() { connections--; }
bool lessThanMinPeer() const { return connections < MIN_PEERS; } bool lessThanMaxPeers() const { return connections < MAX_PEERS; }
bool lessThanEqMinPeer() const { return connections <= MIN_PEERS; } bool lessThanMinPeers() const { return connections < MIN_PEERS; }
bool lessThanEqMinPeers() const { return connections <= MIN_PEERS; }
bool ready() { return _ready; } bool ready() { return _ready; }
void setReady(bool go) { _ready = go; } void setReady(bool go) { _ready = go; }
static const unsigned int MAX_PEERS = 55;
}; };
typedef SharedHandle<BtRuntime> BtRuntimeHandle; typedef SharedHandle<BtRuntime> BtRuntimeHandle;

View File

@ -77,7 +77,7 @@ bool DHTGetPeersCommand::execute()
_taskQueue->addPeriodicTask2(_task); _taskQueue->addPeriodicTask2(_task);
} else if(!_task.isNull() && _task->finished()) { } else if(!_task.isNull() && _task->finished()) {
_lastGetPeerTime.reset(); _lastGetPeerTime.reset();
if(_numRetry < MAX_RETRIES && btRuntime->lessThanEqMinPeer()) { if(_numRetry < MAX_RETRIES && btRuntime->lessThanMinPeers()) {
++_numRetry; ++_numRetry;
} else { } else {
_numRetry = 0; _numRetry = 0;

View File

@ -132,7 +132,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
return A2STR::NIL; return A2STR::NIL;
} }
unsigned int numWant = 50; unsigned int numWant = 50;
if(!btRuntime->lessThanEqMinPeer() || btRuntime->isHalt()) { if(!btRuntime->lessThanMinPeers() || btRuntime->isHalt()) {
numWant = 0; numWant = 0;
} }
TransferStat stat = peerStorage->calculateStat(); TransferStat stat = peerStorage->calculateStat();
@ -257,7 +257,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
const MetaEntry* peersEntry = response->get(BtAnnounce::PEERS); const MetaEntry* peersEntry = response->get(BtAnnounce::PEERS);
if(peersEntry && if(peersEntry &&
!btRuntime->isHalt() && !btRuntime->isHalt() &&
btRuntime->lessThanMinPeer()) { btRuntime->lessThanMinPeers()) {
DelegatingPeerListProcessor proc; DelegatingPeerListProcessor proc;
std::deque<SharedHandle<Peer> > peers; std::deque<SharedHandle<Peer> > peers;
proc.extractPeer(peers, peersEntry); proc.extractPeer(peers, peersEntry);

View File

@ -52,15 +52,14 @@ DefaultPeerStorage::DefaultPeerStorage(const BtContextHandle& btContext,
const Option* option): const Option* option):
btContext(btContext), btContext(btContext),
option(option), option(option),
maxPeerListSize(MAX_PEER_LIST_SIZE), logger(LogFactory::getInstance()),
btRuntime(BT_RUNTIME(btContext)), btRuntime(BT_RUNTIME(btContext)),
maxPeerListSize(btRuntime->MAX_PEERS+(btRuntime->MAX_PEERS >> 2)),
removedPeerSessionDownloadLength(0), removedPeerSessionDownloadLength(0),
removedPeerSessionUploadLength(0), removedPeerSessionUploadLength(0),
_seederStateChoke(new BtSeederStateChoke(btContext)), _seederStateChoke(new BtSeederStateChoke(btContext)),
_leecherStateChoke(new BtLeecherStateChoke()) _leecherStateChoke(new BtLeecherStateChoke())
{ {}
logger = LogFactory::getInstance();
}
DefaultPeerStorage::~DefaultPeerStorage() DefaultPeerStorage::~DefaultPeerStorage()
{ {

View File

@ -39,9 +39,6 @@
namespace aria2 { namespace aria2 {
#define MAX_PEER_LIST_SIZE 60
#define MAX_PEER_ERROR 5
class BtContext; class BtContext;
class Option; class Option;
class Logger; class Logger;
@ -54,9 +51,9 @@ private:
SharedHandle<BtContext> btContext; SharedHandle<BtContext> btContext;
const Option* option; const Option* option;
std::deque<SharedHandle<Peer> > peers; std::deque<SharedHandle<Peer> > peers;
size_t maxPeerListSize;
Logger* logger; Logger* logger;
SharedHandle<BtRuntime> btRuntime; SharedHandle<BtRuntime> btRuntime;
size_t maxPeerListSize;
uint64_t removedPeerSessionDownloadLength; uint64_t removedPeerSessionDownloadLength;
uint64_t removedPeerSessionUploadLength; uint64_t removedPeerSessionUploadLength;

View File

@ -147,7 +147,7 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
{ {
if(e->option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) { if(e->option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
logger->info("CUID#%d - Establishing connection using legacy BitTorrent handshake is disabled by preference.", cuid); logger->info("CUID#%d - Establishing connection using legacy BitTorrent handshake is disabled by preference.", cuid);
if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) { if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeers()) {
SharedHandle<Peer> peer = peerStorage->getUnusedPeer(); SharedHandle<Peer> peer = peerStorage->getUnusedPeer();
peer->usedBy(CUIDCounterSingletonHolder::instance()->newID()); peer->usedBy(CUIDCounterSingletonHolder::instance()->newID());
Command* command = Command* command =

View File

@ -93,7 +93,7 @@ bool PeerInitiateConnectionCommand::executeInternal() {
// TODO this method removed when PeerBalancerCommand is implemented // TODO this method removed when PeerBalancerCommand is implemented
bool PeerInitiateConnectionCommand::prepareForNextPeer(time_t wait) { bool PeerInitiateConnectionCommand::prepareForNextPeer(time_t wait) {
if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) { if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeers()) {
PeerHandle peer = peerStorage->getUnusedPeer(); PeerHandle peer = peerStorage->getUnusedPeer();
peer->usedBy(CUIDCounterSingletonHolder::instance()->newID()); peer->usedBy(CUIDCounterSingletonHolder::instance()->newID());
Command* command = Command* command =

View File

@ -253,7 +253,7 @@ bool PeerInteractionCommand::executeInternal() {
// TODO this method removed when PeerBalancerCommand is implemented // TODO this method removed when PeerBalancerCommand is implemented
bool PeerInteractionCommand::prepareForNextPeer(time_t wait) { bool PeerInteractionCommand::prepareForNextPeer(time_t wait) {
if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) { if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeers()) {
PeerHandle peer = peerStorage->getUnusedPeer(); PeerHandle peer = peerStorage->getUnusedPeer();
peer->usedBy(CUIDCounterSingletonHolder::instance()->newID()); peer->usedBy(CUIDCounterSingletonHolder::instance()->newID());
PeerInitiateConnectionCommand* command = PeerInitiateConnectionCommand* command =

View File

@ -100,7 +100,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
TransferStat tstat = PEER_STORAGE(btContext)->calculateStat(); TransferStat tstat = PEER_STORAGE(btContext)->calculateStat();
if((!PIECE_STORAGE(btContext)->downloadFinished() && if((!PIECE_STORAGE(btContext)->downloadFinished() &&
tstat.getDownloadSpeed() < _thresholdSpeed) || tstat.getDownloadSpeed() < _thresholdSpeed) ||
BT_RUNTIME(btContext)->getConnections() < MAX_PEERS) { BT_RUNTIME(btContext)->lessThanMaxPeers()) {
if(PEER_STORAGE(btContext)->addPeer(peer)) { if(PEER_STORAGE(btContext)->addPeer(peer)) {
peer->usedBy(cuid); peer->usedBy(cuid);

View File

@ -142,7 +142,7 @@ void TrackerWatcherCommand::processTrackerResponse(const std::string& trackerRes
{ {
btAnnounce->processAnnounceResponse(reinterpret_cast<const unsigned char*>(trackerResponse.c_str()), btAnnounce->processAnnounceResponse(reinterpret_cast<const unsigned char*>(trackerResponse.c_str()),
trackerResponse.size()); trackerResponse.size());
while(!btRuntime->isHalt() && btRuntime->lessThanMinPeer()) { while(!btRuntime->isHalt() && btRuntime->lessThanMinPeers()) {
PeerHandle peer = peerStorage->getUnusedPeer(); PeerHandle peer = peerStorage->getUnusedPeer();
if(peer.isNull()) { if(peer.isNull()) {
break; break;