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

Method WriteToBuffer

src/PartFile.cpp:3107–3202  ·  view source on GitHub ↗

Kry - transize is 32bits, no packet can be more than that (this is compressed size). Even 32bits is too much imho.As for the return size, look at the lenData below.

Source from the content-addressed store, hash-verified

3105// compressed size). Even 32bits is too much imho.As for the return size,
3106// look at the lenData below.
3107uint32 CPartFile::WriteToBuffer(uint32 transize, uint8_t* data, uint64 start, uint64 end, Requested_Block_Struct *block, const CUpDownClient* client)
3108{
3109 // Increment transferred bytes counter for this file
3110 transferred += transize;
3111
3112 // This is needed a few times
3113 // Kry - should not need a uint64 here - no block is larger than
3114 // 2GB even after uncompressed.
3115 uint32 lenData = (uint32) (end - start + 1);
3116
3117 if(lenData > transize) {
3118 m_iGainDueToCompression += lenData-transize;
3119 }
3120
3121 // Occasionally packets are duplicated, no point writing it twice
3122 if (IsComplete(start, end)) {
3123 AddDebugLogLineN(logPartFile,
3124 CFormat("File '%s' has already been written from %u to %u")
3125 % GetFileName() % start % end);
3126 return 0;
3127 }
3128
3129 // security sanitize check to make sure we do not write anything into an already hashed complete chunk
3130 const uint64 nStartChunk = start / PARTSIZE;
3131 const uint64 nEndChunk = end / PARTSIZE;
3132 if (IsComplete(nStartChunk)) {
3133 AddDebugLogLineN(logPartFile, CFormat("Received data touches already hashed chunk - ignored (start): %u-%u; File=%s") % start % end % GetFileName());
3134 return 0;
3135 } else if (nStartChunk != nEndChunk) {
3136 if (IsComplete(nEndChunk)) {
3137 AddDebugLogLineN(logPartFile, CFormat("Received data touches already hashed chunk - ignored (end): %u-%u; File=%s") % start % end % GetFileName());
3138 return 0;
3139 } else {
3140 AddDebugLogLineN(logPartFile, CFormat("Received data crosses chunk boundaries: %u-%u; File=%s") % start % end % GetFileName());
3141 }
3142 }
3143
3144 // log transferinformation in our "blackbox"
3145 m_CorruptionBlackBox->TransferredData(start, end, client->GetIP());
3146
3147 // Stamp for FlushBuffer's Phase 3 quiescent guard, and for the
3148 // download-list "Last Reception" column. The latter must stamp on
3149 // real data arrival, not on every periodic FlushBuffer call, or
3150 // idle/paused/stalled files will all read "now" and the column
3151 // stops being useful for spotting hopeless downloads.
3152 m_nLastBlockReceivedTick = GetTickCount64();
3153 m_lastDateChanged = wxDateTime::GetTimeNow();
3154
3155 // Create a new buffered queue entry
3156 PartFileBufferedData *item = new PartFileBufferedData(m_hpartfile, data, start, end, block);
3157
3158 // Add to the queue in the correct position (most likely the end)
3159 bool added = false;
3160
3161 std::list<PartFileBufferedData*>::iterator it = m_BufferedData_list.begin();
3162 for (; it != m_BufferedData_list.end(); ++it) {
3163 PartFileBufferedData* queueItem = *it;
3164

Callers 1

ProcessBlockPacketMethod · 0.80

Calls 8

CFormatClass · 0.85
GetTickCount64Function · 0.85
TransferredDataMethod · 0.80
insertMethod · 0.80
GetIPMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
IsCompleteMethod · 0.45

Tested by

no test coverage detected