long chunk_end = Convert.intToLong(packet_data.getInt());
ByteBuffer chunk_content = Misc.getByteBuffer(chunk_end
- chunk_start);
packet_data.get(chunk_content.array());
_network_manager.receivedRequestedFileChunkFromPeer(peerIP,
peerPort, new FileHash(file_hash), new FileChunk(
chunk_start, chunk_end, chunk_content));
break;
}
case OP_REQUESTPARTS: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
long[] startPos = new long[3];
long[] endPos = new long[3];
List<FileChunkRequest> chunks = new LinkedList<FileChunkRequest>();
for (int i = 0; i < 3; i++)
startPos[i] = Convert.intToLong(packet_data.getInt());
for (int i = 0; i < 3; i++)
endPos[i] = Convert.intToLong(packet_data.getInt());
for (int i = 0; i < 3; i++) {
if ((startPos[i] == endPos[i]) && (startPos[i] == 0))
break;
chunks
.add(new FileChunkRequest(startPos[i],
endPos[i]));
}
_network_manager.receivedFileChunkRequestFromPeer(peerIP,
peerPort, new FileHash(file_hash), chunks);
break;
}
case OP_END_OF_DOWNLOAD: {
_network_manager.receivedEndOfDownloadFromPeer(peerIP,
peerPort);
break;
}
case OP_HASHSETREQUEST: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
_network_manager.receivedHashSetRequestFromPeer(peerIP,
peerPort, new FileHash(file_hash));
break;
}
case OP_HASHSETANSWER: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
int partCount = Convert.shortToInt(packet_data.getShort());
PartHashSet partSet = new PartHashSet(new FileHash(
file_hash));
byte[] partHash = new byte[16];
for (short i = 1; i <= partCount; i++) {
packet_data.get(partHash);
partSet.add(partHash);
}
_network_manager.receivedHashSetResponseFromPeer(peerIP,
peerPort, partSet);
break;
}
case OP_SLOTREQUEST: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
_network_manager.receivedSlotRequestFromPeer(peerIP,
peerPort, new FileHash(file_hash));
break;
}
case OP_SLOTGIVEN: {
_network_manager
.receivedSlotGivenFromPeer(peerIP, peerPort);
break;
}
case OP_SLOTRELEASE: {
_network_manager.receivedSlotReleaseFromPeer(peerIP,
peerPort);
break;
}
case OP_SLOTTAKEN: {
_network_manager
.receivedSlotTakenFromPeer(peerIP, peerPort);
break;
}
case OP_FILEREQUEST: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
_network_manager.receivedFileRequestFromPeer(peerIP,
peerPort, new FileHash(file_hash));
break;
}
case OP_FILEREQANSWER: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
int name_length = Convert
.shortToInt(packet_data.getShort());
ByteBuffer str_bytes = Misc.getByteBuffer(name_length);
packet_data.get(str_bytes.array());
_network_manager.receivedFileRequestAnswerFromPeer(peerIP,
peerPort, new FileHash(file_hash), new String(
str_bytes.array()));
break;
}
case OP_FILEREQANSNOFILE: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
_network_manager.receivedFileNotFoundFromPeer(peerIP,
peerPort, new FileHash(file_hash));
break;
}
case OP_FILESTATREQ: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
_network_manager.receivedFileStatusRequestFromPeer(peerIP,
peerPort, new FileHash(file_hash));
break;
}
case OP_FILESTATUS: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
short partCount = packet_data.getShort();
int count = (partCount + 7) / 8;
// if (((partCount + 7) / 8) != 0)
// if (count == 0)
// count++;
byte[] data = new byte[count];
for (int i = 0; i < count; i++)
data[i] = packet_data.get();
JMuleBitSet bitSet;
bitSet = Convert.byteToBitset(data);
bitSet.setPartCount(partCount);
_network_manager.receivedFileStatusResponseFromPeer(peerIP,
peerPort, new FileHash(file_hash), bitSet);
break;
}
case OP_MESSAGE: {
int message_length = Convert.shortToInt(packet_data
.getShort());
ByteBuffer message_bytes = Misc
.getByteBuffer(message_length);
packet_data.get(message_bytes.array());
String message = new String(message_bytes.array());
message_bytes.clear();
message_bytes = null;
_peer_manager.receivedMessage(peerIP, peerPort, message);
break;
}
default: {
throw new UnknownPacketException(packet_header,
packet_opcode, packet_data.array());
}
}
else if (packet_header == PROTO_EMULE_EXTENDED_TCP)
switch (packet_opcode) {
case OP_EMULE_HELLO: {
byte client_version = packet_data.get();
byte protocol_version = packet_data.get();
TagList tag_list = readTagList(packet_data);
_network_manager.receivedEMuleHelloFromPeer(peerIP,
peerPort, client_version, protocol_version,
tag_list);
break;
}
case OP_EMULEHELLOANSWER: {
byte client_version = packet_data.get();
byte protocol_version = packet_data.get();
TagList tag_list = readTagList(packet_data);
_network_manager.receivedEMuleHelloAnswerFromPeer(peerIP,
peerPort, client_version, protocol_version,
tag_list);
break;
}
case OP_COMPRESSEDPART: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
long chunkStart = Convert.intToLong(packet_data.getInt());
long chunkEnd = Convert.intToLong(packet_data.getInt());
long compressedSize = packet_data.capacity()
- packet_data.position();
ByteBuffer data = Misc.getByteBuffer(compressedSize);
packet_data.get(data.array());
_network_manager.receivedCompressedFileChunkFromPeer(
peerIP, peerPort, new FileHash(file_hash),
new FileChunk(chunkStart, chunkEnd, data));
break;
}
case OP_EMULE_QUEUERANKING: {
short queue_rank = packet_data.getShort();
_network_manager.receivedQueueRankFromPeer(peerIP,
peerPort, Convert.shortToInt(queue_rank));
break;
}
case OP_REQUESTSOURCES: {
byte[] hash = new byte[16];
packet_data.get(hash);
_network_manager.receivedSourcesRequestFromPeer(peerIP,
peerPort, new FileHash(hash));
break;
}
case OP_ANSWERSOURCES: {
byte[] hash = new byte[16];
packet_data.get(hash);
int source_count = Convert.shortToInt(packet_data
.getShort());
List<String> ip_list = new ArrayList<String>();
List<Integer> port_list = new ArrayList<Integer>();
byte[] ip = new byte[4];
short port;
for (int k = 0; k < source_count; k++) {
packet_data.get(ip);
port = packet_data.getShort();
ip = Convert.reverseArray(ip);
ip_list.add(Convert.IPtoString(ip));
port_list.add(Convert.shortToInt(port));
}
_network_manager.receivedSourcesAnswerFromPeer(peerIP,
peerPort, new FileHash(hash), ip_list, port_list);
break;
}
case OP_CHATCAPTCHAREQ: {
packet_data.get();