/* */ #include "BtSetup.h" #include "RequestGroup.h" #include "DownloadEngine.h" #include "Option.h" #include "BtRegistry.h" #include "PeerListenCommand.h" #include "TrackerWatcherCommand.h" #include "SeedCheckCommand.h" #include "PeerChokeCommand.h" #include "ActivePeerConnectionCommand.h" #include "PeerListenCommand.h" #include "UnionSeedCriteria.h" #include "TimeSeedCriteria.h" #include "ShareRatioSeedCriteria.h" #include "DefaultPieceStorage.h" #include "DefaultBtProgressInfoFile.h" #include "CUIDCounter.h" #include "prefs.h" #include "LogFactory.h" #include "Logger.h" #include "Util.h" BtSetup::BtSetup():_logger(LogFactory::getInstance()) {} Commands BtSetup::setup(RequestGroup* requestGroup, DownloadEngine* e, const Option* option) { Commands commands; BtContextHandle btContext = requestGroup->getDownloadContext(); if(btContext.isNull()) { return commands; } // TODO following process is moved to BtSetup // commands commands.push_back(new TrackerWatcherCommand(CUIDCounterSingletonHolder::instance()->newID(), requestGroup, e, btContext)); commands.push_back(new PeerChokeCommand(CUIDCounterSingletonHolder::instance()->newID(), requestGroup, e, btContext, 10)); commands.push_back(new ActivePeerConnectionCommand(CUIDCounterSingletonHolder::instance()->newID(), requestGroup, e, btContext, 30)); SharedHandle unionCri = new UnionSeedCriteria(); if(option->defined(PREF_SEED_TIME)) { unionCri->addSeedCriteria(new TimeSeedCriteria(option->getAsInt(PREF_SEED_TIME)*60)); } if(option->defined(PREF_SEED_RATIO)) { unionCri->addSeedCriteria(new ShareRatioSeedCriteria(option->getAsDouble(PREF_SEED_RATIO), btContext)); } if(unionCri->getSeedCriterion().size() > 0) { commands.push_back(new SeedCheckCommand(CUIDCounterSingletonHolder::instance()->newID(), requestGroup, e, btContext, unionCri)); } if(PeerListenCommand::getNumInstance() == 0) { PeerListenCommand* listenCommand = PeerListenCommand::getInstance(e); int32_t port; int32_t listenPort = option->getAsInt(PREF_LISTEN_PORT); if(listenPort == -1) { port = listenCommand->bindPort(6881, 6999); } else { port = listenCommand->bindPort(listenPort, listenPort); } if(port == -1) { _logger->error(_("Errors occurred while binding port.\n")); delete listenCommand; } else { BT_RUNTIME(btContext)->setListenPort(port); commands.push_back(listenCommand); } } BT_RUNTIME(btContext)->setReady(true); return commands; }