forked from I2P_Developers/i2p.i2p
* i2psnark:
- Defer piece loading until required
- Stub out Extension message support
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user