mirror of https://github.com/aria2/aria2
				
				
				
			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.ccpull/1/head
							parent
							
								
									4a454e94b7
								
							
						
					
					
						commit
						d773613e93
					
				
							
								
								
									
										18
									
								
								ChangeLog
								
								
								
								
							
							
						
						
									
										18
									
								
								ChangeLog
								
								
								
								
							| 
						 | 
				
			
			@ -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>
 | 
			
		||||
 | 
			
		||||
	Always Connect to _numNewConnection 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,7 +79,7 @@ bool ActivePeerConnectionCommand::execute() {
 | 
			
		|||
    checkPoint.reset();
 | 
			
		||||
    TransferStat tstat = peerStorage->calculateStat();
 | 
			
		||||
    if(tstat.getDownloadSpeed() < _thresholdSpeed ||
 | 
			
		||||
       btRuntime->lessThanMinPeer()) {
 | 
			
		||||
       btRuntime->lessThanMinPeers()) {
 | 
			
		||||
      for(size_t numAdd = _numNewConnection;
 | 
			
		||||
	  numAdd > 0 && peerStorage->isPeerAvailable(); --numAdd) {
 | 
			
		||||
	PeerHandle peer = peerStorage->getUnusedPeer();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,10 +45,6 @@ typedef std::map<std::string, uint8_t> Extensions;
 | 
			
		|||
 | 
			
		||||
#define INFO_HASH_LENGTH 20
 | 
			
		||||
 | 
			
		||||
#define MAX_PEER_ERROR 5
 | 
			
		||||
 | 
			
		||||
#define MAX_PEERS 55
 | 
			
		||||
 | 
			
		||||
#define DEFAULT_LATENCY 1500
 | 
			
		||||
 | 
			
		||||
#endif // _D_BT_CONSTANTS_
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,8 +40,6 @@
 | 
			
		|||
 | 
			
		||||
namespace aria2 {
 | 
			
		||||
 | 
			
		||||
#define MIN_PEERS 40
 | 
			
		||||
 | 
			
		||||
class BtRuntime {
 | 
			
		||||
private:
 | 
			
		||||
  uint64_t uploadLengthAtStartup;
 | 
			
		||||
| 
						 | 
				
			
			@ -49,6 +47,9 @@ private:
 | 
			
		|||
  bool halt;
 | 
			
		||||
  unsigned int connections;
 | 
			
		||||
  bool _ready;
 | 
			
		||||
 | 
			
		||||
  static const unsigned int MIN_PEERS = 40;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  BtRuntime():
 | 
			
		||||
    uploadLengthAtStartup(0),
 | 
			
		||||
| 
						 | 
				
			
			@ -86,13 +87,17 @@ public:
 | 
			
		|||
 | 
			
		||||
  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; }
 | 
			
		||||
 | 
			
		||||
  void setReady(bool go) { _ready = go; }
 | 
			
		||||
 | 
			
		||||
  static const unsigned int MAX_PEERS = 55;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef SharedHandle<BtRuntime> BtRuntimeHandle;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,7 +77,7 @@ bool DHTGetPeersCommand::execute()
 | 
			
		|||
    _taskQueue->addPeriodicTask2(_task);
 | 
			
		||||
  } else if(!_task.isNull() && _task->finished()) {
 | 
			
		||||
    _lastGetPeerTime.reset();
 | 
			
		||||
    if(_numRetry < MAX_RETRIES && btRuntime->lessThanEqMinPeer()) {
 | 
			
		||||
    if(_numRetry < MAX_RETRIES && btRuntime->lessThanMinPeers()) {
 | 
			
		||||
      ++_numRetry;
 | 
			
		||||
    } else {
 | 
			
		||||
      _numRetry = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -132,7 +132,7 @@ std::string DefaultBtAnnounce::getAnnounceUrl() {
 | 
			
		|||
    return A2STR::NIL;
 | 
			
		||||
  }
 | 
			
		||||
  unsigned int numWant = 50;
 | 
			
		||||
  if(!btRuntime->lessThanEqMinPeer() || btRuntime->isHalt()) {
 | 
			
		||||
  if(!btRuntime->lessThanMinPeers() || btRuntime->isHalt()) {
 | 
			
		||||
    numWant = 0;
 | 
			
		||||
  }
 | 
			
		||||
  TransferStat stat = peerStorage->calculateStat();
 | 
			
		||||
| 
						 | 
				
			
			@ -257,7 +257,7 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
 | 
			
		|||
  const MetaEntry* peersEntry = response->get(BtAnnounce::PEERS);
 | 
			
		||||
  if(peersEntry &&
 | 
			
		||||
     !btRuntime->isHalt() &&
 | 
			
		||||
     btRuntime->lessThanMinPeer()) {
 | 
			
		||||
     btRuntime->lessThanMinPeers()) {
 | 
			
		||||
    DelegatingPeerListProcessor proc;
 | 
			
		||||
    std::deque<SharedHandle<Peer> > peers;
 | 
			
		||||
    proc.extractPeer(peers, peersEntry);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,15 +52,14 @@ DefaultPeerStorage::DefaultPeerStorage(const BtContextHandle& btContext,
 | 
			
		|||
				       const Option* option):
 | 
			
		||||
  btContext(btContext),
 | 
			
		||||
  option(option),
 | 
			
		||||
  maxPeerListSize(MAX_PEER_LIST_SIZE),
 | 
			
		||||
  logger(LogFactory::getInstance()),
 | 
			
		||||
  btRuntime(BT_RUNTIME(btContext)),
 | 
			
		||||
  maxPeerListSize(btRuntime->MAX_PEERS+(btRuntime->MAX_PEERS >> 2)),
 | 
			
		||||
  removedPeerSessionDownloadLength(0),
 | 
			
		||||
  removedPeerSessionUploadLength(0),
 | 
			
		||||
  _seederStateChoke(new BtSeederStateChoke(btContext)),
 | 
			
		||||
  _leecherStateChoke(new BtLeecherStateChoke())
 | 
			
		||||
{
 | 
			
		||||
  logger = LogFactory::getInstance();
 | 
			
		||||
}
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
DefaultPeerStorage::~DefaultPeerStorage()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,9 +39,6 @@
 | 
			
		|||
 | 
			
		||||
namespace aria2 {
 | 
			
		||||
 | 
			
		||||
#define MAX_PEER_LIST_SIZE 60
 | 
			
		||||
#define MAX_PEER_ERROR 5
 | 
			
		||||
 | 
			
		||||
class BtContext;
 | 
			
		||||
class Option;
 | 
			
		||||
class Logger;
 | 
			
		||||
| 
						 | 
				
			
			@ -54,9 +51,9 @@ private:
 | 
			
		|||
  SharedHandle<BtContext> btContext;
 | 
			
		||||
  const Option* option;
 | 
			
		||||
  std::deque<SharedHandle<Peer> > peers;
 | 
			
		||||
  size_t maxPeerListSize;
 | 
			
		||||
  Logger* logger;
 | 
			
		||||
  SharedHandle<BtRuntime> btRuntime;
 | 
			
		||||
  size_t maxPeerListSize;
 | 
			
		||||
  uint64_t removedPeerSessionDownloadLength;
 | 
			
		||||
  uint64_t removedPeerSessionUploadLength;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -147,7 +147,7 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
 | 
			
		|||
{
 | 
			
		||||
  if(e->option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
 | 
			
		||||
    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();
 | 
			
		||||
      peer->usedBy(CUIDCounterSingletonHolder::instance()->newID());
 | 
			
		||||
      Command* command =
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -93,7 +93,7 @@ bool PeerInitiateConnectionCommand::executeInternal() {
 | 
			
		|||
 | 
			
		||||
// TODO this method removed when PeerBalancerCommand is implemented
 | 
			
		||||
bool PeerInitiateConnectionCommand::prepareForNextPeer(time_t wait) {
 | 
			
		||||
  if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) {
 | 
			
		||||
  if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeers()) {
 | 
			
		||||
    PeerHandle peer = peerStorage->getUnusedPeer();
 | 
			
		||||
    peer->usedBy(CUIDCounterSingletonHolder::instance()->newID());
 | 
			
		||||
    Command* command =
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -253,7 +253,7 @@ bool PeerInteractionCommand::executeInternal() {
 | 
			
		|||
 | 
			
		||||
// TODO this method removed when PeerBalancerCommand is implemented
 | 
			
		||||
bool PeerInteractionCommand::prepareForNextPeer(time_t wait) {
 | 
			
		||||
  if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) {
 | 
			
		||||
  if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeers()) {
 | 
			
		||||
    PeerHandle peer = peerStorage->getUnusedPeer();
 | 
			
		||||
    peer->usedBy(CUIDCounterSingletonHolder::instance()->newID());
 | 
			
		||||
    PeerInitiateConnectionCommand* command =
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -100,7 +100,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
 | 
			
		|||
    TransferStat tstat = PEER_STORAGE(btContext)->calculateStat();
 | 
			
		||||
    if((!PIECE_STORAGE(btContext)->downloadFinished() &&
 | 
			
		||||
       tstat.getDownloadSpeed() < _thresholdSpeed) ||
 | 
			
		||||
       BT_RUNTIME(btContext)->getConnections() < MAX_PEERS) {
 | 
			
		||||
       BT_RUNTIME(btContext)->lessThanMaxPeers()) {
 | 
			
		||||
      if(PEER_STORAGE(btContext)->addPeer(peer)) {
 | 
			
		||||
 | 
			
		||||
	peer->usedBy(cuid);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -142,7 +142,7 @@ void TrackerWatcherCommand::processTrackerResponse(const std::string& trackerRes
 | 
			
		|||
{
 | 
			
		||||
  btAnnounce->processAnnounceResponse(reinterpret_cast<const unsigned char*>(trackerResponse.c_str()),
 | 
			
		||||
				      trackerResponse.size());
 | 
			
		||||
  while(!btRuntime->isHalt() && btRuntime->lessThanMinPeer()) {
 | 
			
		||||
  while(!btRuntime->isHalt() && btRuntime->lessThanMinPeers()) {
 | 
			
		||||
    PeerHandle peer = peerStorage->getUnusedPeer();
 | 
			
		||||
    if(peer.isNull()) {
 | 
			
		||||
      break;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue