[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    extragear/network/ktorrent/libbtcore
From:       Joris Guisson <joris.guisson () gmail ! com>
Date:       2008-08-13 17:43:01
Message-ID: 1218649381.184152.27041.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 846581 by guisson:

Added path from Adam Forsyth, which kills stalled peers

BUG: 168397


 M  +12 -0     peer/peer.cpp  
 M  +4 -0      peer/peer.h  
 M  +10 -2     peer/peermanager.cpp  
 M  +6 -3      torrent/torrentcontrol.cpp  


--- trunk/extragear/network/ktorrent/libbtcore/peer/peer.cpp #846580:846581
@@ -63,6 +63,7 @@
 		uploader = new PeerUploader(this);
 		
 		
+		stalled_timer.update();
 		pwriter = new PacketWriter(this);
 		time_choked = GetCurrentTime();
 		time_unchoked = 0;
@@ -479,8 +480,19 @@
 		
 		if (ut_pex && ut_pex->needsUpdate())
 			ut_pex->update(pman);
+
+		// if no data is being sent or recieved, and there are pending requests
+		// increment the connection stalled timer
+		if (getUploadRate() > 100 || getDownloadRate() > 100 || 
+		   (uploader->getNumRequests() == 0 && downloader->getNumRequests() == 0) )
+			stalled_timer.update();
 	}
 	
+	bool Peer::isStalled() const
+	{
+		return stalled_timer.getElapsedSinceUpdate() >= 2*60*1000;
+	}
+	
 	bool Peer::isSnubbed() const
 	{
 		// 4 minutes
--- trunk/extragear/network/ktorrent/libbtcore/peer/peer.h #846580:846581
@@ -97,6 +97,9 @@
 		/// Get the address of the peer
 		net::Address getAddress() const;
 		
+		/// See if the peer is stalled.
+		bool isStalled() const;
+		
 		/// See if the peer has been killed.
 		bool isKilled() const {return killed;}
 
@@ -292,6 +295,7 @@
 	private:
 		mse::StreamSocket* sock;
 		bool killed;
+		Timer stalled_timer;
 		TimeStamp time_choked;
 		TimeStamp time_unchoked;
 		Uint32 id;
--- trunk/extragear/network/ktorrent/libbtcore/peer/peermanager.cpp #846580:846581
@@ -90,6 +90,16 @@
 		while (i != peer_list.end())
 		{
 			Peer* p = *i;
+			if (!p->isKilled() && p->isStalled())
+			{
+				PotentialPeer pp;
+				pp.port = p->getPort();
+				pp.local = p->getStats().local;
+				pp.ip = p->getIPAddresss();
+				p->kill();
+				addPotentialPeer(pp);
+				Out(SYS_CON|LOG_NOTICE) << QString("Killed stalled peer %1").arg(pp.ip) << endl;
+			}
 			if (p->isKilled())
 			{
 				cnt->decBitSet(p->getBitSet());
@@ -134,8 +144,6 @@
 			}
 			wanted_changed = false;
 		}
-		// connect to some new peers
-		connectToPeers();
 	}
 
 	void PeerManager::killChokedPeers(Uint32 older_then)
--- trunk/extragear/network/ktorrent/libbtcore/torrent/torrentcontrol.cpp #846580:846581
@@ -195,6 +195,12 @@
 			pman->update();
 			bool comp = stats.completed;
 
+			// get rid of dead Peers
+			Uint32 num_cleared = pman->clearDeadPeers();
+			
+			// connect to new peers
+			pman->connectToPeers();
+
 			// then the downloader and uploader
 			uploader->update(choke->getOptimisticlyUnchokedPeerID());			
 			downloader->update();
@@ -254,9 +260,6 @@
 				wanted_update_timer.update();
 			}
 			
-			// get rid of dead Peers
-			Uint32 num_cleared = pman->clearDeadPeers();
-			
 			// we may need to update the choker
 			if (choker_update_timer.getElapsedSinceUpdate() >= 10000 || num_cleared > 0)
 			{
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic