* i2psnark:

- Defer piece loading until required
      - Stub out Extension message support
This commit is contained in:
zzz
2010-11-21 21:19:12 +00:00
parent b5ae626425
commit 6c19e7e399
6 changed files with 145 additions and 12 deletions

View File

@@ -430,6 +430,33 @@ class PeerConnectionOut implements Runnable
return total;
}
/** @since 0.8.2 */
void sendPiece(int piece, int begin, int length, DataLoader loader)
{
boolean sendNow = false;
// are there any cases where we should?
if (sendNow) {
// queue the real thing
byte[] bytes = loader.loadData(piece, begin, length);
if (bytes != null)
sendPiece(piece, begin, length, bytes);
return;
}
// queue a fake message... set everything up,
// except save the PeerState instead of the bytes.
Message m = new Message();
m.type = Message.PIECE;
m.piece = piece;
m.begin = begin;
m.length = length;
m.dataLoader = loader;
m.off = 0;
m.len = length;
addMessage(m);
}
void sendPiece(int piece, int begin, int length, byte[] bytes)
{
Message m = new Message();
@@ -488,4 +515,16 @@ class PeerConnectionOut implements Runnable
}
}
}
/** @since 0.8.2 */
void sendExtension(int id, byte[] bytes) {
Message m = new Message();
m.type = Message.EXTENSION;
m.piece = id;
m.data = bytes;
m.begin = 0;
m.length = bytes.length;
addMessage(m);
}
}