1// -*- C++ -*- 2// This file is part of the aMule Project. 3// 4// Copyright (c) 2004-2011 Angel Vidal ( kry@amule.org ) 5// Copyright (c) 2004-2011 aMule Team ( admin@amule.org / http://www.amule.org ) 6// Copyright (c) 2003-2011 Barry Dunne (http://www.emule-project.net) 7// 8// Any parts of this program derived from the xMule, lMule or eMule project, 9// or contributed by third-party developers are copyrighted by their 10// respective authors. 11// 12// This program is free software; you can redistribute it and/or modify 13// it under the terms of the GNU General Public License as published by 14// the Free Software Foundation; either version 2 of the License, or 15// (at your option) any later version. 16// 17// This program is distributed in the hope that it will be useful, 18// but WITHOUT ANY WARRANTY; without even the implied warranty of 19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20// GNU General Public License for more details. 21// 22// You should have received a copy of the GNU General Public License 23// along with this program; if not, write to the Free Software 24// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 25// 26 27// Note To Mods // 28/* 29Please do not change anything here and release it.. 30There is going to be a new forum created just for the Kademlia side of the client.. 31If you feel there is an error or a way to improve something, please 32post it in the forum first and let us look at it.. If it is a real improvement, 33it will be added to the offical client.. Changing something without knowing 34what all it does can cause great harm to the network if released in mass form.. 35Any mod that changes anything within the Kademlia side will not be allowed to advertise 36there client on the eMule forum.. 37*/ 38 39#ifndef __KAD_ENTRY_H__ 40#define __KAD_ENTRY_H__ 41 42 43#include "../utils/UInt128.h" 44#include "../../Tag.h" 45#include <time.h> 46#include <list> 47#include <map> 48 49struct SSearchTerm; 50class CFileDataIO; 51 52//////////////////////////////////////// 53namespace Kademlia { 54//////////////////////////////////////// 55 56class CEntry 57{ 58protected: 59 struct sFileNameEntry { 60 wxString m_filename; 61 uint32_t m_popularityIndex; 62 }; 63 64public: 65 CEntry() 66 { 67 m_uIP = 0; 68 m_uTCPport = 0; 69 m_uUDPport = 0; 70 m_uSize = 0; 71 m_tLifeTime = time(NULL); 72 m_bSource = false; 73 } 74 75 virtual ~CEntry(); 76 virtual CEntry* Copy() const; 77 virtual bool IsKeyEntry() const throw() { return false; } 78 79 bool GetIntTagValue(const wxString& tagname, uint64_t& value, bool includeVirtualTags = true) const; 80 wxString GetStrTagValue(const wxString& tagname) const; 81 82 void AddTag(CTag *tag) { m_taglist.push_back(tag); } 83 uint32_t GetTagCount() const { return m_taglist.size() + ((m_uSize != 0) ? 1 : 0) + (GetCommonFileName().IsEmpty() ? 0 : 1); } 84 void WriteTagList(CFileDataIO* data) { WriteTagListInc(data, 0); } 85 86 wxString GetCommonFileNameLowerCase() const { return GetCommonFileName().MakeLower(); } 87 wxString GetCommonFileName() const; 88 void SetFileName(const wxString& name); 89 90 uint32_t m_uIP; 91 uint16_t m_uTCPport; 92 uint16_t m_uUDPport; 93 CUInt128 m_uKeyID; 94 CUInt128 m_uSourceID; 95 uint64_t m_uSize; 96 time_t m_tLifeTime; 97 bool m_bSource; 98 99protected: 100 void WriteTagListInc(CFileDataIO *data, uint32_t increaseTagNumber = 0); 101 typedef std::list<sFileNameEntry> FileNameList; 102 FileNameList m_filenames; 103 TagPtrList m_taglist; 104}; 105 106class CKeyEntry : public CEntry 107{ 108 protected: 109 struct sPublishingIP { 110 uint32_t m_ip; 111 time_t m_lastPublish; 112 }; 113 114 public: 115 CKeyEntry(); 116 virtual ~CKeyEntry(); 117 118 virtual CEntry* Copy() const { return CEntry::Copy(); } 119 virtual bool IsKeyEntry() const throw() { return true; } 120 121 bool SearchTermsMatch(const SSearchTerm *searchTerm) const; 122 void MergeIPsAndFilenames(CKeyEntry* fromEntry); 123 void CleanUpTrackedPublishers(); 124 double GetTrustValue(); 125 void WritePublishTrackingDataToFile(CFileDataIO *data); 126 void ReadPublishTrackingDataFromFile(CFileDataIO *data); 127 void DirtyDeletePublishData(); 128 void WriteTagListWithPublishInfo(CFileDataIO *data); 129 static void ResetGlobalTrackingMap() { s_globalPublishIPs.clear(); } 130 131 protected: 132 void ReCalculateTrustValue(); 133 static void AdjustGlobalPublishTracking(uint32_t ip, bool increase, const wxString& dbgReason); 134 135 typedef std::list<sPublishingIP> PublishingIPList; 136 typedef std::map<uint32_t, uint32_t> GlobalPublishIPMap; 137 138 uint32_t m_lastTrustValueCalc; 139 double m_trustValue; 140 PublishingIPList * m_publishingIPs; 141 static GlobalPublishIPMap s_globalPublishIPs; // tracks count of publishings for each 255.255.255.0/24 subnet 142}; 143 144} 145 146#endif // __KAD_ENTRY_H__ 147// File_checked_for_headers 148