From 0ffbb0bb171f20f2d6ab152ddd172bdf2ed905bc Mon Sep 17 00:00:00 2001 From: upstream svn Date: Mon, 8 Feb 2010 22:21:49 +0000 Subject: [PATCH] Upstream tarball 10013 --- .svn-revision | 2 +- src/ExternalConn.cpp | 13 ++++++++----- src/RLE.cpp | 12 ++++++++++++ src/RLE.h | 28 ++++++++++++++++++++-------- src/amule-remote-gui.cpp | 26 +++++++++++--------------- src/webserver/src/WebServer.cpp | 9 +++++---- 6 files changed, 57 insertions(+), 33 deletions(-) diff --git a/.svn-revision b/.svn-revision index afd13f22..4a9341ba 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10012 +10013 diff --git a/src/ExternalConn.cpp b/src/ExternalConn.cpp index 498664d0..1206a141 100644 --- a/src/ExternalConn.cpp +++ b/src/ExternalConn.cpp @@ -961,12 +961,15 @@ void CPartFile_Encoder::Encode(CECTag *parent) for ( ; curr_pos2 != requestedblocks.end(); ++curr_pos2 ) { Requested_Block_Struct* block = *curr_pos2; - req_buffer.push_back(ENDIAN_HTONLL(block->StartOffset)); - req_buffer.push_back(ENDIAN_HTONLL(block->EndOffset)); + req_buffer.push_back(block->StartOffset); + req_buffer.push_back(block->EndOffset); } - if (!req_buffer.empty()) - parent->AddTag(CECTag(EC_TAG_PARTFILE_REQ_STATUS, - requestedblocks.size() * 2 * sizeof(uint64), (void *)&req_buffer[0])); + int req_enc_size = 0; + const uint8 *req_enc_data = m_enc_data.m_req_status.Encode(req_buffer, req_enc_size, changed); + if (changed) { + parent->AddTag(CECTag(EC_TAG_PARTFILE_REQ_STATUS, req_enc_size, (void *)req_enc_data)); + } + delete[] req_enc_data; } void CKnownFile_Encoder::Encode(CECTag *parent) diff --git a/src/RLE.cpp b/src/RLE.cpp index 5478fb62..8b8ba959 100644 --- a/src/RLE.cpp +++ b/src/RLE.cpp @@ -263,10 +263,22 @@ void RLE_Data::Decode(const uint8 *data, int len, ArrayOfUInts64 &outdata) } } +void PartFileEncoderData::ResetEncoder() +{ + m_part_status.ResetEncoder(); + m_gap_status.ResetEncoder(); + m_req_status.ResetEncoder(); +} + void PartFileEncoderData::DecodeGaps(const CECTag * tag, ArrayOfUInts64 &outdata) { m_gap_status.Decode((uint8 *)tag->GetTagData(), tag->GetTagDataLen(), outdata); } +void PartFileEncoderData::DecodeReqs(const CECTag * tag, ArrayOfUInts64 &outdata) +{ + m_req_status.Decode((uint8 *)tag->GetTagData(), tag->GetTagDataLen(), outdata); +} + // File_checked_for_headers diff --git a/src/RLE.h b/src/RLE.h index 27278318..76feedce 100644 --- a/src/RLE.h +++ b/src/RLE.h @@ -43,8 +43,6 @@ public: ~RLE_Data(); - const uint8 *Encode(const uint8 *data, int inlen, int &outlen, bool &changed); - const uint8 *Encode(const ArrayOfUInts16 &data, int &outlen, bool &changed); const uint8 *Encode(const ArrayOfUInts64 &data, int &outlen, bool &changed); @@ -68,7 +66,20 @@ private: // change size of internal buffers // returns true if size was changed bool Realloc(int size); - + + // + // Encode some raw data + // + // data: block to encode + // inlen: number of bytes to encode. May be zero, then data can also be 0. + // outlen: here the number of encoded bytes gets stored (0 if inlen is 0) + // changed: becomes true if the size has changed or a change in the data occured, + // so the differential data (before encoding) is not all zero + // + // return: new buffer with encoded data, must be deleted after use! + // + const uint8 *Encode(const uint8 *data, int inlen, int &outlen, bool &changed); + // Encode: source data (original or diff in diff mode) // Decode: store decoded data uint8 *m_buff; @@ -84,21 +95,22 @@ private: */ class PartFileEncoderData { public: + // number of sources for each part for progress bar colouring RLE_Data m_part_status; + // gap list RLE_Data m_gap_status; + // blocks requested for download + RLE_Data m_req_status; // // Encoder may reset history if full info requested - void ResetEncoder() - { - m_part_status.ResetEncoder(); - m_gap_status.ResetEncoder(); - } + void ResetEncoder(); // // decoder side - can be used everywhere void DecodeParts(uint8 *partdata, int partlen) { m_part_status.Decode(partdata, partlen); } void DecodeGaps(const class CECTag * tag, ArrayOfUInts64 &outdata); + void DecodeReqs(const class CECTag * tag, ArrayOfUInts64 &outdata); }; #endif diff --git a/src/amule-remote-gui.cpp b/src/amule-remote-gui.cpp index dc40282e..4fb201f4 100644 --- a/src/amule-remote-gui.cpp +++ b/src/amule-remote-gui.cpp @@ -1412,22 +1412,18 @@ void CDownQueueRem::ProcessItemUpdate(CEC_PartFile_Tag *tag, CPartFile *file) } } if (reqtag) { - const uint64 *reqparts = (const uint64 *)reqtag->GetTagData(); - unsigned reqcount = reqtag->GetTagDataLen() / (2 * sizeof(uint64)); - // adjust size of requested block list - while ( file->m_requestedblocks_list.size() > reqcount ) { - delete file->m_requestedblocks_list.front(); - file->m_requestedblocks_list.pop_front(); - } - while ( file->m_requestedblocks_list.size() != reqcount ) { - file->m_requestedblocks_list.push_front(new Requested_Block_Struct); - } + ArrayOfUInts64 reqs; + encoder.DecodeReqs(reqtag, reqs); + int req_size = reqs.size() / 2; + // clear reqlist + DeleteContents(file->m_requestedblocks_list); - std::list::iterator it2 = file->m_requestedblocks_list.begin(); - for (unsigned i = 0; i < reqcount; ++i) { - Requested_Block_Struct* block = *it2++; - block->StartOffset = ENDIAN_NTOHLL(reqparts[2*i]); - block->EndOffset = ENDIAN_NTOHLL(reqparts[2*i+1]); + // and refill it + for (int j = 0; j < req_size; j++) { + Requested_Block_Struct* block = new Requested_Block_Struct; + block->StartOffset = reqs[2*j]; + block->EndOffset = reqs[2*j+1]; + file->m_requestedblocks_list.push_back(block); } } } diff --git a/src/webserver/src/WebServer.cpp b/src/webserver/src/WebServer.cpp index 52813c9c..a3d50e07 100644 --- a/src/webserver/src/WebServer.cpp +++ b/src/webserver/src/WebServer.cpp @@ -733,12 +733,13 @@ void DownloadFile::ProcessUpdate(CEC_PartFile_Tag *tag) m_Encoder.DecodeParts((uint8 *)parttag->GetTagData(), parttag->GetTagDataLen()); } if (reqtag) { - const Gap_Struct *reqparts = (const Gap_Struct *)reqtag->GetTagData(); - int reqcount = reqtag->GetTagDataLen() / sizeof(Gap_Struct); + ArrayOfUInts64 reqs; + m_Encoder.DecodeReqs(reqtag, reqs); + int reqcount = reqs.size() / 2; m_ReqParts.resize(reqcount); for (int i = 0; i < reqcount;i++) { - m_ReqParts[i].start = ENDIAN_NTOHLL(reqparts[i].start); - m_ReqParts[i].end = ENDIAN_NTOHLL(reqparts[i].end); + m_ReqParts[i].start = reqs[2*i]; + m_ReqParts[i].end = reqs[2*i+1]; } } } -- 2.11.4.GIT