Fasten seed/download on fast connection

pull/675/head
Tatsuhiro Tsujikawa 2016-06-02 22:13:47 +09:00
parent a0706f5a44
commit 482cf6aca4
6 changed files with 36 additions and 24 deletions

View File

@ -189,6 +189,7 @@ void DefaultBtInteractive::doPostHandshakeProcessing()
if (!metadataGetMode_) {
addAllowedFastMessageToQueue();
}
peerStorage_->scheduleForcedChokeRound();
sendPendingMessage();
}

View File

@ -62,7 +62,8 @@ DefaultPeerStorage::DefaultPeerStorage()
: maxPeerListSize_(MAX_PEER_LIST_SIZE),
seederStateChoke_(make_unique<BtSeederStateChoke>()),
leecherStateChoke_(make_unique<BtLeecherStateChoke>()),
lastTransferStatMapUpdated_(Timer::zero())
lastTransferStatMapUpdated_(Timer::zero()),
forceChokeRound_(false)
{
}
@ -284,16 +285,21 @@ void DefaultPeerStorage::returnPeer(const std::shared_ptr<Peer>& peer)
bool DefaultPeerStorage::chokeRoundIntervalElapsed()
{
constexpr auto CHOKE_ROUND_INTERVAL = 10_s;
auto forceChokeRound = forceChokeRound_;
forceChokeRound_ = false;
if (pieceStorage_->downloadFinished()) {
auto interval = forceChokeRound ? 1_s : CHOKE_ROUND_INTERVAL;
return seederStateChoke_->getLastRound().difference(global::wallclock()) >=
CHOKE_ROUND_INTERVAL;
interval;
}
else {
return leecherStateChoke_->getLastRound().difference(global::wallclock()) >=
CHOKE_ROUND_INTERVAL;
}
}
void DefaultPeerStorage::scheduleForcedChokeRound() { forceChokeRound_ = true; }
void DefaultPeerStorage::executeChoke()
{
if (pieceStorage_->downloadFinished()) {

View File

@ -74,6 +74,8 @@ private:
std::map<std::string, Timer> badPeers_;
Timer lastBadPeerCleaned_;
bool forceChokeRound_;
bool isPeerAlreadyAdded(const std::shared_ptr<Peer>& peer);
void addUniqPeer(const std::shared_ptr<Peer>& peer);
@ -113,6 +115,8 @@ public:
virtual bool chokeRoundIntervalElapsed() CXX11_OVERRIDE;
virtual void scheduleForcedChokeRound() CXX11_OVERRIDE;
virtual void executeChoke() CXX11_OVERRIDE;
void deleteUnusedPeer(size_t delSize);

View File

@ -347,9 +347,6 @@ bool PeerInteractionCommand::executeInternal()
if (btInteractive_->countReceivedMessageInIteration() > 0) {
updateKeepAlive();
}
if ((getPeer()->amInterested() && !getPeer()->peerChoking()) ||
btInteractive_->countOutstandingRequest() ||
(getPeer()->peerInterested() && !getPeer()->amChoking())) {
// Writable check to avoid slow seeding
if (btInteractive_->isSendingMessageInProgress()) {
@ -366,10 +363,7 @@ bool PeerInteractionCommand::executeInternal()
else {
setReadCheckSocket(getSocket());
}
}
else {
disableReadCheckSocket();
}
done = true;
break;
}

View File

@ -113,6 +113,11 @@ public:
virtual bool chokeRoundIntervalElapsed() = 0;
/**
* Schedules choke round forcibly.
*/
virtual void scheduleForcedChokeRound() = 0;
virtual void executeChoke() = 0;
};

View File

@ -84,6 +84,8 @@ public:
virtual bool chokeRoundIntervalElapsed() CXX11_OVERRIDE { return false; }
virtual void scheduleForcedChokeRound() CXX11_OVERRIDE {}
virtual void executeChoke() CXX11_OVERRIDE { ++numChokeExecuted_; }
int getNumChokeExecuted() const { return numChokeExecuted_; }