Don't try legacy BitTorrent handshake when connection did not established.

pull/1/head
Tatsuhiro Tsujikawa 2011-01-08 17:49:43 +09:00
parent ce2d401dce
commit 3020087a75
2 changed files with 25 additions and 13 deletions

View File

@ -197,22 +197,32 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
return false;
}
void InitiatorMSEHandshakeCommand::tryNewPeer()
{
if(peerStorage_->isPeerAvailable() && btRuntime_->lessThanEqMinPeers()) {
SharedHandle<Peer> peer = peerStorage_->getUnusedPeer();
peer->usedBy(getDownloadEngine()->newCUID());
PeerInitiateConnectionCommand* command =
new PeerInitiateConnectionCommand(peer->usedBy(), requestGroup_, peer,
getDownloadEngine(), btRuntime_);
command->setPeerStorage(peerStorage_);
command->setPieceStorage(pieceStorage_);
getDownloadEngine()->addCommand(command);
}
}
bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
{
if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
A2_LOG_INFO(fmt("CUID#%lld - Establishing connection using legacy BitTorrent"
" handshake is disabled by preference.",
if(sequence_ == INITIATOR_SEND_KEY) {
// We don't try legacy handshake when connection did not
// established.
tryNewPeer();
return true;
} else if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
A2_LOG_INFO(fmt("CUID#%lld - Establishing connection using legacy"
" BitTorrent handshake is disabled by preference.",
getCuid()));
if(peerStorage_->isPeerAvailable() && btRuntime_->lessThanEqMinPeers()) {
SharedHandle<Peer> peer = peerStorage_->getUnusedPeer();
peer->usedBy(getDownloadEngine()->newCUID());
PeerInitiateConnectionCommand* command =
new PeerInitiateConnectionCommand(peer->usedBy(), requestGroup_, peer,
getDownloadEngine(), btRuntime_);
command->setPeerStorage(peerStorage_);
command->setPieceStorage(pieceStorage_);
getDownloadEngine()->addCommand(command);
}
tryNewPeer();
return true;
} else {
// try legacy BitTorrent handshake

View File

@ -70,6 +70,8 @@ private:
MSEHandshake* mseHandshake_;
const SharedHandle<Option>& getOption() const;
void tryNewPeer();
protected:
virtual bool executeInternal();
virtual bool prepareForNextPeer(time_t wait);