diff options
Diffstat (limited to 'src/PeerInteractionCommand.cc')
| -rw-r--r-- | src/PeerInteractionCommand.cc | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc index 5fcc8faf..f07e42b5 100644 --- a/src/PeerInteractionCommand.cc +++ b/src/PeerInteractionCommand.cc @@ -391,14 +391,18 @@ bool PeerInteractionCommand::executeInternal() { // TODO this method removed when PeerBalancerCommand is implemented bool PeerInteractionCommand::prepareForNextPeer(time_t wait) { 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); + cuid_t ncuid = getDownloadEngine()->newCUID(); + SharedHandle<Peer> peer = peerStorage_->checkoutPeer(ncuid); + // sanity check + if(peer) { + PeerInitiateConnectionCommand* command; + command = new PeerInitiateConnectionCommand(ncuid, requestGroup_, peer, + getDownloadEngine(), + btRuntime_); + command->setPeerStorage(peerStorage_); + command->setPieceStorage(pieceStorage_); + getDownloadEngine()->addCommand(command); + } } return true; } |
