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

Method ProcessBlockPacket

src/DownloadClient.cpp:853–1067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

851*/
852
853void CUpDownClient::ProcessBlockPacket(const uint8_t* packet, uint32 size, bool packed, bool largeblocks)
854{
855 // Ignore if no data required
856 if (!(GetDownloadState() == DS_DOWNLOADING || GetDownloadState() == DS_NONEEDEDPARTS)) {
857 return;
858 }
859
860 // This vars are defined here to be able to use them on the catch
861 int header_size = 16;
862 uint64 nStartPos = 0;
863 uint64 nEndPos = 0;
864 uint32 nBlockSize = 0;
865 uint32 lenUnzipped = 0;
866
867 // Update stats
868 m_dwLastBlockReceived = ::GetTickCount64();
869
870 try {
871
872 // Read data from packet
873 const CMemFile data(packet, size);
874
875 // Check that this data is for the correct file
876 if ((!m_reqfile) || data.ReadHash() != m_reqfile->GetFileHash()) {
877 throw wxString("Wrong fileid sent (ProcessBlockPacket)");
878 }
879
880 // Find the start & end positions, and size of this chunk of data
881
882 if (largeblocks) {
883 nStartPos = data.ReadUInt64();
884 header_size += 8;
885 } else {
886 nStartPos = data.ReadUInt32();
887 header_size += 4;
888 }
889
890 if (packed) {
891 nBlockSize = data.ReadUInt32();
892 header_size += 4;
893 nEndPos = nStartPos + (size - header_size);
894 } else {
895 if (largeblocks) {
896 nEndPos = data.ReadUInt64();
897 header_size += 8;
898 } else {
899 nEndPos = data.ReadUInt32();
900 header_size += 4;
901 }
902 }
903
904 // Check that packet size matches the declared data size + header size
905 if ( nEndPos == nStartPos || size != ((nEndPos - nStartPos) + header_size)) {
906 throw wxString("Corrupted or invalid DataBlock received (ProcessBlockPacket)");
907 }
908 theStats::AddDownloadFromSoft(GetClientSoft(),size - header_size);
909 bytesReceivedCycle += size - header_size;
910

Callers 2

ProcessPacketMethod · 0.80
ProcessExtPacketMethod · 0.80

Calls 15

GetTickCount64Function · 0.85
CFormatClass · 0.85
Uint32toStringIPFunction · 0.85
ReadUInt64Method · 0.80
ReadUInt32Method · 0.80
AddDownloadedMethod · 0.80
RemoveBlockFromListMethod · 0.80
WriteToBufferMethod · 0.80
eraseMethod · 0.80
whatMethod · 0.80
wxStringClass · 0.70
ReadHashMethod · 0.45

Tested by

no test coverage detected