* i2psnark: Implement retransmission of requests. This
      eliminates one cause of complete stalls with a peer.
      This problem is common on torrents with a small number of
      active peers where there are no choke/unchokes to kickstart things.
This commit is contained in:
zzz
2006-09-16 21:07:28 +00:00
committed by zzz
parent 46f2645834
commit 23e8a558c2
7 changed files with 47 additions and 3 deletions

View File

@ -477,4 +477,14 @@ public class Peer implements Comparable
s.keepAlive();
}
/**
* Retransmit outstanding requests if necessary
*/
public void retransmitRequests()
{
PeerState s = state;
if (s != null)
s.retransmitRequests();
}
}

View File

@ -164,6 +164,7 @@ class PeerCheckerTask extends TimerTask
worstDownloader = peer;
}
}
peer.retransmitRequests();
peer.keepAlive();
}

View File

@ -324,6 +324,23 @@ class PeerConnectionOut implements Runnable
addMessage(m);
}
/** reransmit requests not received in 7m */
private static final int REQ_TIMEOUT = (2 * SEND_TIMEOUT) + (60 * 1000);
void retransmitRequests(List requests)
{
long now = System.currentTimeMillis();
Iterator it = requests.iterator();
while (it.hasNext())
{
Request req = (Request)it.next();
if(now > req.sendTime + REQ_TIMEOUT) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Retransmit request " + req + " to peer " + peer);
sendRequest(req);
}
}
}
void sendRequests(List requests)
{
Iterator it = requests.iterator();
@ -336,12 +353,15 @@ class PeerConnectionOut implements Runnable
void sendRequest(Request req)
{
// should we check for duplicate requests to deal with fibrillating i2p-bt??
// or just send some cancels when we get an unwanted chunk??
Message m = new Message();
m.type = Message.REQUEST;
m.piece = req.piece;
m.begin = req.off;
m.length = req.len;
addMessage(m);
req.sendTime = System.currentTimeMillis();
}
void sendPiece(int piece, int begin, int length, byte[] bytes)

View File

@ -596,4 +596,10 @@ class PeerState
{
out.sendAlive();
}
synchronized void retransmitRequests()
{
if (interesting && !choked)
out.retransmitRequests(outstandingRequests);
}
}

View File

@ -29,6 +29,7 @@ class Request
final byte[] bs;
final int off;
final int len;
long sendTime;
/**
* Creates a new Request.

View File

@ -1,4 +1,10 @@
$Id: history.txt,v 1.520 2006-09-13 18:24:14 zzz Exp $
$Id: history.txt,v 1.521 2006-09-13 21:37:33 zzz Exp $
2006-09-16 zzz
* i2psnark: Implement retransmission of requests. This
eliminates one cause of complete stalls with a peer.
This problem is common on torrents with a small number of
active peers where there are no choke/unchokes to kickstart things.
2006-09-13 zzz
* i2psnark: Fix restoral of partial pieces broken by last patch

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.457 $ $Date: 2006-09-13 18:02:07 $";
public final static String ID = "$Revision: 1.458 $ $Date: 2006-09-13 21:37:32 $";
public final static String VERSION = "0.6.1.25";
public final static long BUILD = 4;
public final static long BUILD = 5;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);