/* */ #include "PeerInitiateConnectionCommand.h" #include "PeerInteractionCommand.h" #include "Util.h" #include "DlAbortEx.h" #include "message.h" #include "prefs.h" #include "CUIDCounter.h" PeerInitiateConnectionCommand::PeerInitiateConnectionCommand(int cuid, const PeerHandle& peer, TorrentDownloadEngine* e, const BtContextHandle& btContext) :PeerAbstractCommand(cuid, peer, e, btContext) {} PeerInitiateConnectionCommand::~PeerInitiateConnectionCommand() {} bool PeerInitiateConnectionCommand::executeInternal() { Command* command; logger->info(MSG_CONNECTING_TO_SERVER, cuid, peer->ipaddr.c_str(), peer->port); socket->establishConnection(peer->ipaddr, peer->port); command = new PeerInteractionCommand(cuid, peer, e, btContext, socket, PeerInteractionCommand::INITIATOR_SEND_HANDSHAKE); e->commands.push_back(command); return true; } // TODO this method removed when PeerBalancerCommand is implemented bool PeerInitiateConnectionCommand::prepareForNextPeer(int wait) { if(peerStorage->isPeerAvailable() && btRuntime->lessThanEqMinPeer()) { PeerHandle peer = peerStorage->getUnusedPeer(); peer->cuid = CUIDCounterSingletonHolder::instance()->newID(); PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(peer->cuid, peer, e, btContext); e->commands.push_back(command); } return true; } bool PeerInitiateConnectionCommand::prepareForRetry(int wait) { PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(cuid, peer, e, btContext); e->commands.push_back(command); return true; }