MCPcopy Create free account
hub / github.com/amule-project/amule / ProcessExtPacket

Method ProcessExtPacket

src/ClientTCPSocket.cpp:973–1774  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

971
972
973bool CClientTCPSocket::ProcessExtPacket(const uint8_t* buffer, uint32 size, uint8 opcode)
974{
975 #ifdef __PACKET_RECV_DUMP__
976 //printf("Rec: OPCODE %x \n",opcode);
977 DumpMem(buffer,size);
978 #endif
979
980 // 0.42e - except the catches on mem exception and file exception
981 if (!m_client) {
982 throw wxString("Unknown clients sends extended protocol packet");
983 }
984 /*
985 if (!client->CheckHandshakeFinished()) {
986 // Here comes an extended packet without finishing the handshake.
987 // IMHO, we should disconnect the client.
988 throw wxString("Client send extended packet before finishing handshake");
989 }
990 */
991 switch(opcode) {
992 case OP_MULTIPACKET_EXT:
993 AddDebugLogLineN( logRemoteClient, "Remote Client: OP_MULTIPACKET_EXT from " + m_client->GetFullIP());
994 /* fall through */
995 case OP_MULTIPACKET: {
996 if (opcode == OP_MULTIPACKET) AddDebugLogLineN( logRemoteClient, "Remote Client: OP_MULTIPACKET from " + m_client->GetFullIP() );
997
998 theStats::AddDownOverheadFileRequest(size);
999
1000 if (m_client->IsBanned()) {
1001 break;
1002 }
1003
1004 if (!m_client->CheckHandshakeFinished()) {
1005 // Here comes an extended packet without finishing the handshake.
1006 // IMHO, we should disconnect the client.
1007 throw wxString("Client send OP_MULTIPACKET before finishing handshake");
1008 }
1009
1010 CMemFile data_in(buffer, size);
1011 CMD4Hash reqfilehash = data_in.ReadHash();
1012 uint64 nSize = (opcode == OP_MULTIPACKET_EXT) ? data_in.ReadUInt64() : 0;
1013
1014 bool file_not_found = false;
1015 CKnownFile* reqfile = theApp->sharedfiles->GetFileByID(reqfilehash);
1016 if ( reqfile == NULL ){
1017 reqfile = theApp->downloadqueue->GetFileByID(reqfilehash);
1018 if ( !( reqfile != NULL && reqfile->GetFileSize() > PARTSIZE ) ) {
1019 AddDebugLogLineN(logRemoteClient, "Remote client asked for a non-shared file");
1020 file_not_found = true;
1021 }
1022 }
1023
1024 if (!file_not_found && reqfile->IsLargeFile() && !m_client->SupportsLargeFiles()) {
1025 AddDebugLogLineN(logRemoteClient, "Remote client asked for a large file but doesn't support them");
1026 file_not_found = true;
1027 }
1028
1029 if (!file_not_found && nSize && (reqfile->GetFileSize() != nSize)) {
1030 AddDebugLogLineN(logRemoteClient, "Remote client asked for a file but specified wrong size");

Callers

nothing calls this directly

Calls 15

DumpMemFunction · 0.85
GetTickCount64Function · 0.85
PeekUInt16Function · 0.85
CFormatClass · 0.85
Uint32toStringIPFunction · 0.85
IsBannedMethod · 0.80
ReadUInt64Method · 0.80
IsLargeFileMethod · 0.80
SupportsLargeFilesMethod · 0.80
Copy16ToDataBufferMethod · 0.80
GetPacketSizeMethod · 0.80

Tested by

no test coverage detected