Store a piece of received data (don't know if it's good or bad yet). Data is stored in a list for the chunk in belongs to.
| 76 | // Store a piece of received data (don't know if it's good or bad yet). |
| 77 | // Data is stored in a list for the chunk in belongs to. |
| 78 | void CCorruptionBlackBox::TransferredData(uint64 nStartPos, uint64 nEndPos, uint32 senderIP) |
| 79 | { |
| 80 | if (nStartPos > nEndPos) { |
| 81 | wxFAIL; |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | // convert pos to relative block pos |
| 86 | uint16 nPart = (uint16)(nStartPos / PARTSIZE); |
| 87 | uint32 nRelStartPos = nStartPos - nPart*PARTSIZE; |
| 88 | uint32 nRelEndPos = nEndPos - nPart*PARTSIZE; |
| 89 | if (nRelEndPos >= PARTSIZE) { |
| 90 | // data crosses the partborder, split it |
| 91 | // (for the fun of it, this should never happen) |
| 92 | nRelEndPos = PARTSIZE-1; |
| 93 | TransferredData((nPart+1)*PARTSIZE, nEndPos, senderIP); |
| 94 | } |
| 95 | // |
| 96 | // Let's keep things simple. |
| 97 | // We don't request data we already have. |
| 98 | // We check if received data exceeds block boundaries. |
| 99 | // -> There should not be much overlap here. |
| 100 | // So just stuff everything received into the list and only join adjacent blocks. |
| 101 | // |
| 102 | CRecordList & list = m_Records[nPart]; // this creates the entry if it doesn't exist yet |
| 103 | bool merged = false; |
| 104 | for (CRecordList::iterator it = list.begin(); it != list.end() && !merged; ++it) { |
| 105 | merged = it->Merge(nRelStartPos, nRelEndPos, senderIP); |
| 106 | } |
| 107 | if (!merged) { |
| 108 | list.push_back(CCBBRecord(nRelStartPos, nRelEndPos, senderIP)); |
| 109 | AddDebugLogLineN(logPartFile, CFormat("CorruptionBlackBox(%s): transferred: new record for part %d (%d - %d, %s)") |
| 110 | % m_partNumber % nPart % nRelStartPos % nRelEndPos % Uint32toStringIP(senderIP)); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Mark a piece of data as good or bad. |
| 115 | // Piece is removed from the chunk list and added to the client's record. |
no test coverage detected