/* */ #include "PeerInitiateConnectionCommand.h" #include "PeerInteractionCommand.h" #include "Util.h" #include "DlAbortEx.h" #include "message.h" #include "prefs.h" PeerInitiateConnectionCommand::PeerInitiateConnectionCommand(int cuid, const PeerHandle& peer, TorrentDownloadEngine* e) :PeerAbstractCommand(cuid, peer, e) {} 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, 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(e->torrentMan->isPeerAvailable()) { PeerHandle peer = e->torrentMan->getPeer(); int newCuid = e->torrentMan->getNewCuid(); peer->cuid = newCuid; PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(newCuid, peer, e); e->commands.push_back(command); } return true; } bool PeerInitiateConnectionCommand::prepareForRetry(int wait) { PeerInitiateConnectionCommand* command = new PeerInitiateConnectionCommand(cuid, peer, e); e->commands.push_back(command); return true; }