* i2psnark: Don't timeout queued piece messages

This commit is contained in:
zzz
2010-11-29 13:08:03 +00:00
parent 2138599567
commit a86fef2a21
3 changed files with 18 additions and 5 deletions

View File

@ -229,12 +229,9 @@ class PeerConnectionOut implements Runnable
/**
* Adds a message to the sendQueue and notifies the method waiting
* on the sendQueue to change.
* If a PIECE message only, add a timeout.
*/
private void addMessage(Message m)
{
if (m.type == Message.PIECE)
SimpleScheduler.getInstance().addEvent(new RemoveTooSlow(m), SEND_TIMEOUT);
synchronized(sendQueue)
{
sendQueue.add(m);
@ -430,7 +427,11 @@ class PeerConnectionOut implements Runnable
return total;
}
/** @since 0.8.2 */
/**
* Queue a piece message with a callback to load the data
* from disk when required.
* @since 0.8.2
*/
void sendPiece(int piece, int begin, int length, DataLoader loader)
{
boolean sendNow = false;
@ -457,6 +458,11 @@ class PeerConnectionOut implements Runnable
addMessage(m);
}
/**
* Queue a piece message with the data already loaded from disk
* Also add a timeout.
* We don't use this anymore.
*/
void sendPiece(int piece, int begin, int length, byte[] bytes)
{
Message m = new Message();
@ -467,6 +473,8 @@ class PeerConnectionOut implements Runnable
m.data = bytes;
m.off = 0;
m.len = length;
// since we have the data already loaded, queue a timeout to remove it
SimpleScheduler.getInstance().addEvent(new RemoveTooSlow(m), SEND_TIMEOUT);
addMessage(m);
}

View File

@ -75,7 +75,9 @@ public class PeerCoordinator implements PeerListener
private final byte[] id;
// Some random wanted pieces
/** The wanted pieces. We could use a TreeSet but we'd have to clear and re-add everything
* when priorities change.
*/
private final List<Piece> wantedPieces;
/** partial pieces - lock by synching on wantedPieces */

View File

@ -110,6 +110,9 @@ class PeerState implements DataLoader
if (choked) {
out.cancelRequestMessages();
// old Roberts thrash us here, choke+unchoke right together
// The only problem with returning the partials to the coordinator
// is that chunks above a missing request are lost.
// Future enhancements to PartialPiece could keep track of the holes.
List<PartialPiece> pcs = returnPartialPieces();
if (!pcs.isEmpty()) {
if (_log.shouldLog(Log.DEBUG))