summaryrefslogtreecommitdiff
path: root/src/PeerInteractionCommand.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-03-31 13:58:22 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-03-31 13:58:22 +0000
commite6e017756096d53417622c0a4048d1dfb4340f49 (patch)
treebb9f940a72be4886c14a2959ff0461e1261d5af4 /src/PeerInteractionCommand.cc
parente1f24adc4046dfc24d01fc5eb9797d05420c136f (diff)
* src/PeerInteractionCommand.cc (checkInactiveConnection): New
function (detectMessageFlooding): Updated. (checkLongTimePeerChoking): Updated. (getNewPieceAndSendInterest): Added debug log. * src/PeerInteractionCommand.h: New function checkInactiveConnection() * src/TorrentMan.cc (deleteOldErrorPeers): Updated. (getPeer): Updated. * src/TorrentMan.h: Added MAX_PEER_ERROR. * src/PeerAbstractCommand.cc (onAbort): Increment error counter. * src/PeerListenCommand.cc (execute): Close connection if incoming peer is localhost. * src/main.cc (main): Updated PREF_PEER_CONNECTION_TIMEOUT to 60. * src/PendingMessage.cc (processMessage): Not to send piece message if peer is not interested in the pieces localhost has. * src/Peer.cc (shouldChoke): Updated. * src/SendMessageQueue.cc (cancelAllRequest): Fixed.
Diffstat (limited to 'src/PeerInteractionCommand.cc')
-rw-r--r--src/PeerInteractionCommand.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc
index b1021df6..a5569dbb 100644
--- a/src/PeerInteractionCommand.cc
+++ b/src/PeerInteractionCommand.cc
@@ -107,6 +107,7 @@ bool PeerInteractionCommand::executeInternal() {
case WIRED:
detectMessageFlooding();
checkLongTimePeerChoking();
+ checkInactiveConnection();
syncPiece();
decideChoking();
for(int i = 0; i < 10; i++) {
@@ -128,6 +129,16 @@ bool PeerInteractionCommand::executeInternal() {
return false;
}
+void PeerInteractionCommand::checkInactiveConnection() {
+ if((!peer->amInterested && !peer->peerInterested &&
+ e->torrentMan->connections >= MAX_PEER_LIST_SIZE) ||
+ (!peer->amInterested && e->torrentMan->connections >= MAX_PEER_LIST_SIZE &&
+ e->torrentMan->isEndGame())) {
+ throw new DlAbortEx("marked as inactive connection.");
+ }
+
+}
+
void PeerInteractionCommand::detectMessageFlooding() {
struct timeval now;
gettimeofday(&now, NULL);
@@ -135,7 +146,7 @@ void PeerInteractionCommand::detectMessageFlooding() {
freqCheckPoint = now;
} else {
if(Util::difftv(now, freqCheckPoint) >= 5*1000000) {
- if(chokeUnchokeCount*1.0/(Util::difftv(now, freqCheckPoint)/1000000) >= 0.3
+ if(chokeUnchokeCount*1.0/(Util::difftv(now, freqCheckPoint)/1000000) >= 0.4
|| haveCount*1.0/(Util::difftv(now, freqCheckPoint)/1000000) >= 20.0) {
throw new DlAbortEx("flooding detected.");
} else {
@@ -159,7 +170,7 @@ void PeerInteractionCommand::checkLongTimePeerChoking() {
}
} else {
if(peer->amInterested && peer->peerChoking) {
- if(Util::difftv(now, chokeCheckPoint) >= 5*60*1000000) {
+ if(Util::difftv(now, chokeCheckPoint) >= 3*60*1000000) {
throw new DlAbortEx("too long choking");
}
} else {
@@ -325,6 +336,7 @@ Piece PeerInteractionCommand::getNewPieceAndSendInterest() {
PendingMessage pendingMessage(PeerMessage::NOT_INTERESTED, peerConnection);
sendMessageQueue->addPendingMessage(pendingMessage);
} else {
+ e->logger->debug("CUID#%d - starting download for piece #%d", cuid, piece.getIndex());
e->logger->debug("CUID#%d - try to send interested", cuid);
PendingMessage pendingMessage(PeerMessage::INTERESTED, peerConnection);
sendMessageQueue->addPendingMessage(pendingMessage);
@@ -404,6 +416,7 @@ void PeerInteractionCommand::beforeSocketCheck() {
e->torrentMan->unadvertisePiece(cuid);
detectMessageFlooding();
checkLongTimePeerChoking();
+ checkInactiveConnection();
PieceIndexes indexes = e->torrentMan->getAdvertisedPieceIndexes(cuid);
if(indexes.size() >= 20) {