From 21e534855aa2168fdabfe63f3004decd286f19f6 Mon Sep 17 00:00:00 2001 From: upstream svn Date: Mon, 15 Feb 2010 16:54:27 +0000 Subject: [PATCH] Upstream tarball 10017 --- .svn-revision | 2 +- src/ECSpecialCoreTags.cpp | 44 +------------------ src/ExternalConn.cpp | 79 ++++++++++++++++++++++++++++------ src/ExternalConn.h | 5 ++- src/FileDetailDialog.cpp | 6 +-- src/PartFile.h | 12 +++--- src/amule-remote-gui.cpp | 41 ++++++------------ src/libs/ec/abstracts/ECCodes.abstract | 1 - src/libs/ec/c#/ECCodes.cs | 3 +- src/libs/ec/cpp/ECCodes.h | 2 - src/libs/ec/cpp/ECSpecialTags.h | 3 +- src/libs/ec/cpp/ECTag.cpp | 2 +- src/libs/ec/cpp/ECTag.h | 18 +++++++- src/libs/ec/java/ECCodes.java | 1 - src/remote-gui.net/ECCodes.cs | 3 +- 15 files changed, 115 insertions(+), 107 deletions(-) diff --git a/.svn-revision b/.svn-revision index 634f0a93..896da6e1 100644 --- a/.svn-revision +++ b/.svn-revision @@ -1 +1 @@ -10016 +10017 diff --git a/src/ECSpecialCoreTags.cpp b/src/ECSpecialCoreTags.cpp index 6117a114..80df68db 100644 --- a/src/ECSpecialCoreTags.cpp +++ b/src/ECSpecialCoreTags.cpp @@ -122,45 +122,7 @@ CEC_ConnState_Tag::CEC_ConnState_Tag(EC_DETAIL_LEVEL detail_level) : CECTag(EC_T AddTag(CECTag(EC_TAG_CLIENT_ID, theApp->GetID())); } -void CEC_PartFile_Tag::Detail_Tag(CPartFile *file, CValueMap *valuemap) -{ - // Tag for source names - CECEmptyTag sn(EC_TAG_PARTFILE_SOURCE_NAMES); - CECEmptyTag snc(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS); - SourcenameItemList sil; - const CPartFile::SourceSet &sources = file->GetSourceList(); - for (CPartFile::SourceSet::const_iterator it = sources.begin(); it != sources.end(); ++it) { - CUpDownClient *cur_src = *it; - if (cur_src->GetRequestFile() != file || cur_src->GetClientFilename().Length() == 0) { - continue; - } - - bool found = false; - for (SourcenameItemList::iterator its = sil.begin() ; its != sil.end(); ++its ) { - if (its->name == cur_src->GetClientFilename()) { - its->count++; - found = true; - break; - } - } - if (!found) { - sil.push_back(SourcenameItem(cur_src->GetClientFilename(), 1)); - } - } - for (SourcenameItemList::const_iterator its = sil.begin() ; its != sil.end(); ++its ) { - // Tag children are evaluated by index, not by name - sn.AddTag(CECTag(EC_TAG_PARTFILE_SOURCE_NAMES, its->name)); - snc.AddTag(CECTag(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS, (uint64) its->count)); - } - if (AddTag(sn, valuemap) && valuemap) { - // If there was a change in the list of names, - // make sure that the counts are updated too. - valuemap->ForgetTag(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS); - } - AddTag(snc, valuemap); -} - -CEC_PartFile_Tag::CEC_PartFile_Tag(CPartFile *file, EC_DETAIL_LEVEL detail_level, bool detail, CValueMap *valuemap) +CEC_PartFile_Tag::CEC_PartFile_Tag(CPartFile *file, EC_DETAIL_LEVEL detail_level, CValueMap *valuemap) : CECTag(EC_TAG_PARTFILE, file->GetFileHash()) { @@ -192,10 +154,6 @@ CECTag(EC_TAG_PARTFILE, file->GetFileHash()) AddTag(EC_TAG_PARTFILE_GAINED_COMPRESSION, file->GetGainDueToCompression(), valuemap); AddTag(EC_TAG_PARTFILE_SAVED_ICH, file->TotalPacketsSavedDueToICH(), valuemap); - if (detail) { - Detail_Tag(file, valuemap); - } - // Tag for comments CECEmptyTag sc(EC_TAG_PARTFILE_COMMENTS); diff --git a/src/ExternalConn.cpp b/src/ExternalConn.cpp index 99848d7e..828cd4a6 100644 --- a/src/ExternalConn.cpp +++ b/src/ExternalConn.cpp @@ -556,7 +556,7 @@ static CECPacket *Get_EC_Response_GetDownloadQueue(CPartFile_Encoder_Map &encode CPartFile *cur_file = theApp->downloadqueue->GetFileByIndex(i); CValueMap &valuemap = tagmap.GetValueMap(cur_file); - CEC_PartFile_Tag filetag(cur_file, EC_DETAIL_INC_UPDATE, true, &valuemap); + CEC_PartFile_Tag filetag(cur_file, EC_DETAIL_INC_UPDATE, &valuemap); CPartFile_Encoder &enc = encoders[cur_file]; enc.Encode(&filetag); @@ -565,7 +565,7 @@ static CECPacket *Get_EC_Response_GetDownloadQueue(CPartFile_Encoder_Map &encode return response; } -static CECPacket *Get_EC_Response_GetDownloadQueue(const CECPacket *request, CPartFile_Encoder_Map &encoders, bool detail = false) +static CECPacket *Get_EC_Response_GetDownloadQueue(const CECPacket *request, CPartFile_Encoder_Map &encoders) { CECPacket *response = new CECPacket(EC_OP_DLOAD_QUEUE); @@ -583,7 +583,7 @@ static CECPacket *Get_EC_Response_GetDownloadQueue(const CECPacket *request, CPa continue; } - CEC_PartFile_Tag filetag(cur_file, detail_level, detail); + CEC_PartFile_Tag filetag(cur_file, detail_level); CPartFile_Encoder &enc = encoders[cur_file]; if ( detail_level != EC_DETAIL_UPDATE ) { @@ -954,7 +954,6 @@ void CPartFile_Encoder::Encode(CECTag *parent) // // Requested blocks // - // that's the next thing to go ArrayOfUInts64 req_buffer; const CPartFile::CReqBlockPtrList& requestedblocks = m_file->GetRequestedBlockList(); CPartFile::CReqBlockPtrList::const_iterator curr_pos2 = requestedblocks.begin(); @@ -970,6 +969,70 @@ void CPartFile_Encoder::Encode(CECTag *parent) parent->AddTag(CECTag(EC_TAG_PARTFILE_REQ_STATUS, req_enc_size, (void *)req_enc_data)); } delete[] req_enc_data; + + // + // Source names + // + // First count occurrence of all source names + // + CECEmptyTag sourceNames(EC_TAG_PARTFILE_SOURCE_NAMES); + typedef std::map strIntMap; + strIntMap nameMap; + const CPartFile::SourceSet &sources = m_file->GetSourceList(); + for (CPartFile::SourceSet::const_iterator it = sources.begin(); it != sources.end(); ++it) { + CUpDownClient *cur_src = *it; + if (cur_src->GetRequestFile() != m_file || cur_src->GetClientFilename().Length() == 0) { + continue; + } + const wxString &name = cur_src->GetClientFilename(); + strIntMap::iterator itm = nameMap.find(name); + if (itm == nameMap.end()) { + nameMap[name] = 1; + } else { + itm->second++; + } + } + // + // Go through our last list + // + for (SourcenameItemMap::iterator it1 = m_sourcenameItemMap.begin(); it1 != m_sourcenameItemMap.end();) { + SourcenameItemMap::iterator it2 = it1++; + strIntMap::iterator itm = nameMap.find(it2->second.name); + if (itm == nameMap.end()) { + // name doesn't exist anymore, tell client to forget it + CECTag tag(EC_TAG_PARTFILE_SOURCE_NAMES, it2->first); + tag.AddTag(CECIntTag(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS, 0)); + sourceNames.AddTag(tag); + // and forget it + m_sourcenameItemMap.erase(it2); + } else { + // update count if it changed + if (it2->second.count != itm->second) { + CECTag tag(EC_TAG_PARTFILE_SOURCE_NAMES, it2->first); + tag.AddTag(CECIntTag(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS, itm->second)); + sourceNames.AddTag(tag); + it2->second.count = itm->second; + } + // remove it from nameMap so that only new names are left there + nameMap.erase(itm); + } + } + // + // Add new names + // + for (strIntMap::iterator it3 = nameMap.begin(); it3 != nameMap.end(); it3++) { + int id = ++m_sourcenameID; + CECIntTag tag(EC_TAG_PARTFILE_SOURCE_NAMES, id); + tag.AddTag(CECTag(EC_TAG_PARTFILE_SOURCE_NAMES, it3->first)); + tag.AddTag(CECIntTag(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS, it3->second)); + sourceNames.AddTag(tag); + // remember it + m_sourcenameItemMap[id] = SourcenameItem(it3->first, it3->second); + } + if (sourceNames.HasChildTags()) { + parent->AddTag(sourceNames); + } + } void CPartFile_Encoder::ResetEncoder() @@ -1114,14 +1177,6 @@ CECPacket *CECServerSocket::ProcessRequest2(const CECPacket *request, response = Get_EC_Response_GetDownloadQueue(request, enc_part_map); } break; - // transmit source names and comments only if file detail dialog is open - case EC_OP_GET_DLOAD_QUEUE_DETAIL: - if ( request->GetDetailLevel() == EC_DETAIL_INC_UPDATE ) { - response = Get_EC_Response_GetDownloadQueue(enc_part_map, objmap); - } else { - response = Get_EC_Response_GetDownloadQueue(request, enc_part_map, true); - } - break; case EC_OP_GET_ULOAD_QUEUE: response = Get_EC_Response_GetClientQueue(request, objmap, EC_OP_ULOAD_QUEUE); break; diff --git a/src/ExternalConn.h b/src/ExternalConn.h index e9574bee..ba974978 100644 --- a/src/ExternalConn.h +++ b/src/ExternalConn.h @@ -34,6 +34,7 @@ #include "amuleIPV4Address.h" // for amuleIPV4Address #include "RLE.h" // for RLE #include "DownloadQueue.h" +#include "PartFile.h" // for SourcenameItemMap class wxSocketServer; class wxSocketEvent; @@ -86,9 +87,11 @@ class CFileEncoderMap : public std::map { */ class CPartFile_Encoder : public PartFileEncoderData { CPartFile *m_file; + SourcenameItemMap m_sourcenameItemMap; + int m_sourcenameID; public: // encoder side - CPartFile_Encoder(CPartFile *file = 0) { m_file = file; } + CPartFile_Encoder(CPartFile *file = 0) { m_file = file; m_sourcenameID = 0; } // encode - take data from m_file void Encode(CECTag *parent_tag); diff --git a/src/FileDetailDialog.cpp b/src/FileDetailDialog.cpp index eee5678d..81c601bb 100644 --- a/src/FileDetailDialog.cpp +++ b/src/FileDetailDialog.cpp @@ -158,9 +158,9 @@ void CFileDetailDialog::FillSourcenameList() // update #ifdef CLIENT_GUI - const SourcenameItemList &sources = m_file->GetSourcenameItemList(); - for (SourcenameItemList::const_iterator it = sources.begin(); it != sources.end(); ++it) { - const SourcenameItem &cur_src = *it; + const SourcenameItemMap &sources = m_file->GetSourcenameItemMap(); + for (SourcenameItemMap::const_iterator it = sources.begin(); it != sources.end(); ++it) { + const SourcenameItem &cur_src = it->second; itempos = pmyListCtrl->FindItem(-1,cur_src.name); if (itempos == -1) { int itemid = pmyListCtrl->InsertItem(0, cur_src.name); diff --git a/src/PartFile.h b/src/PartFile.h index 79cbad48..6b83de05 100644 --- a/src/PartFile.h +++ b/src/PartFile.h @@ -79,14 +79,14 @@ class SourcenameItem { public: wxString name; - long count; + int count; public: - SourcenameItem(const wxString &n, long c) + SourcenameItem(const wxString &n = EmptyString, int c = 0) : name(n), count(c) {} }; -typedef std::list SourcenameItemList; +typedef std::map SourcenameItemMap; class CPartFile : public CKnownFile { public: @@ -403,11 +403,9 @@ private: #ifdef CLIENT_GUI uint32 m_kbpsDown; uint8 m_iDownPriorityEC; - SourcenameItemList m_SourcenameItem_list; + SourcenameItemMap m_SourcenameItemMap; public: - SourcenameItemList &GetSourcenameItemList() { return m_SourcenameItem_list; } - void ClearSourcenameItemList() { m_SourcenameItem_list.clear(); } - void AddSourcenameItemList(const wxString &name, long count) { m_SourcenameItem_list.push_back(SourcenameItem(name, count)); } + SourcenameItemMap &GetSourcenameItemMap() { return m_SourcenameItemMap; } #endif public: const FileRatingList &GetFileRatingList() { return m_FileRatingList; } diff --git a/src/amule-remote-gui.cpp b/src/amule-remote-gui.cpp index de3c0c1d..ba72ec09 100644 --- a/src/amule-remote-gui.cpp +++ b/src/amule-remote-gui.cpp @@ -1426,35 +1426,22 @@ void CDownQueueRem::ProcessItemUpdate(CEC_PartFile_Tag *tag, CPartFile *file) // Get source names and counts CECTag *srcnametag = tag->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES); - CECTag *srccounttag = tag->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS); - // Full update (names and counts) if (srcnametag) { + SourcenameItemMap &map = file->GetSourcenameItemMap(); size_t max = srcnametag->GetTagCount(); - // Some sanity checks (this shouldn't go wrong) - if (!srccounttag) { - AddLogLineN(wxT("Source names missing counts - too old core ?")); - } else if (srccounttag->GetTagCount() != max) { - AddLogLineN(CFormat(wxT("%d source names and %d source counts - should not happen.")) - % max % srccounttag->GetTagCount()); - } else { - file->ClearSourcenameItemList(); - for (size_t i = 0; i < max; i++) { - wxString name = srcnametag->GetTagByIndex(i)->GetStringData(); - long count = srccounttag->GetTagByIndex(i)->GetInt(); - file->AddSourcenameItemList(name, count); - } - } - // Only counts updated - } else if (srccounttag) { - size_t max = srccounttag->GetTagCount(); - SourcenameItemList &list = file->GetSourcenameItemList(); - if (list.size() != max) { - AddLogLineN(CFormat(wxT("%d source items and %d source counts - should not happen.")) - % list.size() % max); - } else { - SourcenameItemList::iterator it = list.begin(); - for (size_t i = 0; i < max; i++, it++) { - it->count = srccounttag->GetTagByIndex(i)->GetInt(); + for (size_t i = 0; i < max; i++) { + CECTag *ntag = srcnametag->GetTagByIndex(i); + uint32 key = ntag->GetInt(); + int count = ntag->GetTagByNameSafe(EC_TAG_PARTFILE_SOURCE_NAMES_COUNTS)->GetInt(); + if (count == 0) { + map.erase(key); + } else { + SourcenameItem &item = map[key]; + item.count = count; + CECTag *nametag = ntag->GetTagByName(EC_TAG_PARTFILE_SOURCE_NAMES); + if (nametag) { + item.name = nametag->GetStringData(); + } } } } diff --git a/src/libs/ec/abstracts/ECCodes.abstract b/src/libs/ec/abstracts/ECCodes.abstract index 02b26f39..adb99d5b 100644 --- a/src/libs/ec/abstracts/ECCodes.abstract +++ b/src/libs/ec/abstracts/ECCodes.abstract @@ -133,7 +133,6 @@ EC_OP_KAD_STOP 0x49 EC_OP_CONNECT 0x4A EC_OP_DISCONNECT 0x4B -EC_OP_GET_DLOAD_QUEUE_DETAIL 0x4C EC_OP_KAD_UPDATE_FROM_URL 0x4D EC_OP_KAD_BOOTSTRAP_FROM_IP 0x4E diff --git a/src/libs/ec/c#/ECCodes.cs b/src/libs/ec/c#/ECCodes.cs index 290a2722..5d32f9bc 100644 --- a/src/libs/ec/c#/ECCodes.cs +++ b/src/libs/ec/c#/ECCodes.cs @@ -35,7 +35,7 @@ public enum ECFlags { EC_FLAG_HAS_ID = 0x00000004, EC_FLAG_ACCEPTS = 0x00000010, EC_FLAG_NOTIFY = 0x00008000, - + EC_FLAG_UNKNOWN_MASK = 0xff7f7f08 }; public enum ECOpCodes { EC_OP_NOOP = 0x01, @@ -113,7 +113,6 @@ public enum ECOpCodes { EC_OP_KAD_STOP = 0x49, EC_OP_CONNECT = 0x4A, EC_OP_DISCONNECT = 0x4B, - EC_OP_GET_DLOAD_QUEUE_DETAIL = 0x4C, EC_OP_KAD_UPDATE_FROM_URL = 0x4D, EC_OP_KAD_BOOTSTRAP_FROM_IP = 0x4E, EC_OP_AUTH_SALT = 0x4F, diff --git a/src/libs/ec/cpp/ECCodes.h b/src/libs/ec/cpp/ECCodes.h index 7ae48ae4..a135c9b7 100644 --- a/src/libs/ec/cpp/ECCodes.h +++ b/src/libs/ec/cpp/ECCodes.h @@ -121,7 +121,6 @@ enum ECOpCodes { EC_OP_KAD_STOP = 0x49, EC_OP_CONNECT = 0x4A, EC_OP_DISCONNECT = 0x4B, - EC_OP_GET_DLOAD_QUEUE_DETAIL = 0x4C, EC_OP_KAD_UPDATE_FROM_URL = 0x4D, EC_OP_KAD_BOOTSTRAP_FROM_IP = 0x4E, EC_OP_AUTH_SALT = 0x4F, @@ -517,7 +516,6 @@ wxString GetDebugNameECOpCodes(uint8 arg) case 0x49: return wxT("EC_OP_KAD_STOP"); case 0x4A: return wxT("EC_OP_CONNECT"); case 0x4B: return wxT("EC_OP_DISCONNECT"); - case 0x4C: return wxT("EC_OP_GET_DLOAD_QUEUE_DETAIL"); case 0x4D: return wxT("EC_OP_KAD_UPDATE_FROM_URL"); case 0x4E: return wxT("EC_OP_KAD_BOOTSTRAP_FROM_IP"); case 0x4F: return wxT("EC_OP_AUTH_SALT"); diff --git a/src/libs/ec/cpp/ECSpecialTags.h b/src/libs/ec/cpp/ECSpecialTags.h index 51b7a419..a4311c3f 100644 --- a/src/libs/ec/cpp/ECSpecialTags.h +++ b/src/libs/ec/cpp/ECSpecialTags.h @@ -204,8 +204,7 @@ class CEC_ConnState_Tag : public CECTag { class CEC_PartFile_Tag : public CECTag { public: - CEC_PartFile_Tag(CPartFile *file, EC_DETAIL_LEVEL detail_level, bool detail = false, CValueMap *valuemap = NULL); - void Detail_Tag(CPartFile *file, CValueMap *valuemap); + CEC_PartFile_Tag(CPartFile *file, EC_DETAIL_LEVEL detail_level, CValueMap *valuemap = NULL); // template needs it CMD4Hash ID() const { return GetMD4Data(); } diff --git a/src/libs/ec/cpp/ECTag.cpp b/src/libs/ec/cpp/ECTag.cpp index 6d3ea5d4..36271fe9 100644 --- a/src/libs/ec/cpp/ECTag.cpp +++ b/src/libs/ec/cpp/ECTag.cpp @@ -714,7 +714,7 @@ void CECTag::DebugPrint(int level, bool print_empty) const s2 = wxT("empty"); } else { // Make a hex dump (limited to maxOutput) - const int maxOutput = 50; + const uint32 maxOutput = 50; for (uint32 i = 0; i < m_dataLen; i++) { if (i == maxOutput) { s2 += wxT("..."); diff --git a/src/libs/ec/cpp/ECTag.h b/src/libs/ec/cpp/ECTag.h index c8f7b24c..b77e971d 100644 --- a/src/libs/ec/cpp/ECTag.h +++ b/src/libs/ec/cpp/ECTag.h @@ -138,8 +138,9 @@ class CECTag { CECTag* GetTagByName(ec_tagname_t name); const CECTag* GetTagByNameSafe(ec_tagname_t name) const; - size_t GetTagCount(void) const { return m_tagList.size(); } - const void * GetTagData(void) const { + size_t GetTagCount() const { return m_tagList.size(); } + bool HasChildTags() const { return !m_tagList.empty(); } + const void * GetTagData() const { EC_ASSERT(m_dataType == EC_TAGTYPE_CUSTOM); return m_tagData; } @@ -361,5 +362,18 @@ class CECEmptyTag : public CECTag { CECEmptyTag(ec_tagname_t name = 0) : CECTag(name, 0, (const void *) NULL) {} }; +/** + * An integer TAG + * + * This is just to easily overcome ctor ambiguity. It's prettier to write + * CECIntTag(name, some_value) + * instead of + * CECTag(name, (uint64)value) + */ +class CECIntTag : public CECTag { + public: + CECIntTag(ec_tagname_t name, uint64 data) : CECTag(name, data) {} +}; + #endif /* ECTAG_H */ // File_checked_for_headers diff --git a/src/libs/ec/java/ECCodes.java b/src/libs/ec/java/ECCodes.java index 14c2ccfb..2b9726f7 100644 --- a/src/libs/ec/java/ECCodes.java +++ b/src/libs/ec/java/ECCodes.java @@ -111,7 +111,6 @@ public final static byte EC_OP_KAD_START = 0x48; public final static byte EC_OP_KAD_STOP = 0x49; public final static byte EC_OP_CONNECT = 0x4A; public final static byte EC_OP_DISCONNECT = 0x4B; -public final static byte EC_OP_GET_DLOAD_QUEUE_DETAIL = 0x4C; public final static byte EC_OP_KAD_UPDATE_FROM_URL = 0x4D; public final static byte EC_OP_KAD_BOOTSTRAP_FROM_IP = 0x4E; public final static byte EC_OP_AUTH_SALT = 0x4F; diff --git a/src/remote-gui.net/ECCodes.cs b/src/remote-gui.net/ECCodes.cs index 290a2722..5d32f9bc 100644 --- a/src/remote-gui.net/ECCodes.cs +++ b/src/remote-gui.net/ECCodes.cs @@ -35,7 +35,7 @@ public enum ECFlags { EC_FLAG_HAS_ID = 0x00000004, EC_FLAG_ACCEPTS = 0x00000010, EC_FLAG_NOTIFY = 0x00008000, - + EC_FLAG_UNKNOWN_MASK = 0xff7f7f08 }; public enum ECOpCodes { EC_OP_NOOP = 0x01, @@ -113,7 +113,6 @@ public enum ECOpCodes { EC_OP_KAD_STOP = 0x49, EC_OP_CONNECT = 0x4A, EC_OP_DISCONNECT = 0x4B, - EC_OP_GET_DLOAD_QUEUE_DETAIL = 0x4C, EC_OP_KAD_UPDATE_FROM_URL = 0x4D, EC_OP_KAD_BOOTSTRAP_FROM_IP = 0x4E, EC_OP_AUTH_SALT = 0x4F, -- 2.11.4.GIT