diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-01-26 17:50:06 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2013-01-26 17:50:06 +0900 |
| commit | ba69f5c0c318132bb95c561f89488c754341ee96 (patch) | |
| tree | 26f016e6e2f2fd104c01fb6e2ac48374f5f2586c /src/PeerInteractionCommand.cc | |
| parent | 8524ac38067ba2ca2e692de39166edd6612e1d5b (diff) | |
Refactor peer list management in DefaultPeerStorage
Peer list is now divided into 2: unusedPeers_ and usedPeers_.
Duplicate check is done using std::set by comparing pair of IP address
and port. For this, only IP address and port given to the Peer
constructor are used. In other words, TCP port received from extended
message is not used for this purpose.
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; } |
