packet_data.get(client_id);
ClientID clientID = new ClientID(client_id);
int tcpPort = Convert.shortToInt(packet_data.getShort());
TagList tag_list = readTagList(packet_data);
byte[] server_ip_array = new byte[4];
packet_data.get(server_ip_array);
String server_ip = Convert.IPtoString(server_ip_array);
int server_port;
server_port = Convert.shortToInt(packet_data.getShort());
_network_manager.receivedHelloFromPeerAndRespondTo(peerIP,
peerPort, userHash, clientID, tcpPort, tag_list,
server_ip, server_port);
break;
}
case OP_PEERHELLOANSWER: {
byte[] data = new byte[16];
packet_data.get(data);
UserHash userHash = new UserHash(data);
byte client_id[] = new byte[4];
packet_data.get(client_id);
ClientID clientID = new ClientID(client_id);
int tcpPort = Convert.shortToInt(packet_data.getShort());
TagList tag_list = readTagList(packet_data);
byte[] server_ip_array = new byte[4];
packet_data.get(server_ip_array);
String server_ip = Convert.IPtoString(server_ip_array);
int server_port;
server_port = Convert.shortToInt(packet_data.getShort());
_network_manager.receivedHelloAnswerFromPeer(peerIP,
peerPort, userHash, clientID, tcpPort, tag_list,
server_ip, server_port);
break;
}
case OP_SENDINGPART: {
byte[] file_hash = new byte[16];
packet_data.get(file_hash);
long chunk_start = Convert.intToLong(packet_data.getInt());
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;
}