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 __PREFS_H__ 40#define __PREFS_H__ 41 42#include "../utils/UInt128.h" 43#include "../../Preferences.h" 44#include <protocol/kad/Constants.h> 45#include <time.h> 46#include <vector> 47 48//////////////////////////////////////// 49namespace Kademlia { 50//////////////////////////////////////// 51 52class CPrefs 53{ 54public: 55 CPrefs(); 56 ~CPrefs(); 57 58 void SetKadID(const CUInt128 &id) throw() { m_clientID = id; } 59 const CUInt128& GetKadID() const throw() { return m_clientID; } 60 61 void SetClientHash(const CUInt128 &id) throw() { m_clientHash = id; } 62 const CUInt128& GetClientHash() const throw() { return m_clientHash; } 63 64 uint32_t GetIPAddress() const throw() { return m_ip; } 65 void SetIPAddress(uint32_t val) throw(); 66 67 bool GetRecheckIP() const throw() { return (m_recheckip < KADEMLIAFIREWALLCHECKS); } 68 void SetRecheckIP() { m_recheckip = 0; SetFirewalled(); } 69 void IncRecheckIP() throw() { m_recheckip++; } 70 71 bool HasHadContact() const throw() { return m_lastContact ? ((time(NULL) - m_lastContact) < KADEMLIADISCONNECTDELAY) : false; } 72 void SetLastContact() throw() { m_lastContact = time(NULL); } 73 bool HasLostConnection() const throw() { return m_lastContact ? !((time(NULL) - m_lastContact) < KADEMLIADISCONNECTDELAY) : false; } 74 uint32_t GetLastContact() const throw() { return m_lastContact; } 75 76 bool GetFirewalled() const throw(); 77 void SetFirewalled(); 78 void IncFirewalled(); 79 80 uint8_t GetTotalFile() const throw() { return m_totalFile; } 81 void SetTotalFile(uint8_t val) throw() { m_totalFile = val; } 82 83 uint8_t GetTotalStoreSrc() const throw() { return m_totalStoreSrc; } 84 void SetTotalStoreSrc(uint8_t val) throw() { m_totalStoreSrc = val; } 85 86 uint8_t GetTotalStoreKey() const throw() { return m_totalStoreKey; } 87 void SetTotalStoreKey(uint8_t val) throw() { m_totalStoreKey = val; } 88 89 uint8_t GetTotalSource() const throw() { return m_totalSource; } 90 void SetTotalSource(uint8_t val) throw() { m_totalSource = val; } 91 92 uint8_t GetTotalNotes() const throw() { return m_totalNotes; } 93 void SetTotalNotes(uint8_t val) throw() { m_totalNotes = val; } 94 95 uint8_t GetTotalStoreNotes() const throw() { return m_totalStoreNotes; } 96 void SetTotalStoreNotes(uint8_t val) throw() { m_totalStoreNotes = val; } 97 98 uint32_t GetKademliaUsers() const throw() { return m_kademliaUsers; } 99 void SetKademliaUsers(uint32_t val) throw() { m_kademliaUsers = val; } 100 101 uint32_t GetKademliaFiles() const throw() { return m_kademliaFiles; } 102 void SetKademliaFiles(); 103 104 bool GetPublish() const throw() { return m_Publish; } 105 void SetPublish(bool val) throw() { m_Publish = val; } 106 107 bool GetFindBuddy() throw() { return m_findBuddy ? m_findBuddy = false, true : false; } 108 void SetFindBuddy(bool val = true) throw() { m_findBuddy = val; } 109 110 bool GetUseExternKadPort() const; 111 void SetUseExternKadPort(bool val) throw() { m_useExternKadPort = val; } 112 113 uint16_t GetExternalKadPort() const throw() { return m_externKadPort; } 114 uint16_t GetInternKadPort() const throw() { return thePrefs::GetUDPPort(); } 115 void SetExternKadPort(uint16_t port, uint32_t fromIP); 116 bool FindExternKadPort(bool reset = false); 117 118 static uint8_t GetMyConnectOptions(bool encryption = true, bool callback = true); 119 static uint32_t GetUDPVerifyKey(uint32_t targetIP); 120 121 // Statistics 122 void StatsIncUDPFirewalledNodes(bool firewalled) throw() { firewalled ? ++m_statsUDPFirewalledNodes : ++m_statsUDPOpenNodes; } 123 void StatsIncTCPFirewalledNodes(bool firewalled) throw() { firewalled ? ++m_statsTCPFirewalledNodes : ++m_statsTCPOpenNodes; } 124 float StatsGetFirewalledRatio(bool udp) const throw(); 125 float StatsGetKadV8Ratio(); 126 127private: 128 wxString m_filename; 129 130 time_t m_lastContact; 131 CUInt128 m_clientID; 132 CUInt128 m_clientHash; 133 uint32_t m_ip; 134 uint32_t m_ipLast; 135 uint32_t m_recheckip; 136 uint32_t m_firewalled; 137 uint32_t m_kademliaUsers; 138 uint32_t m_kademliaFiles; 139 uint8_t m_totalFile; 140 uint8_t m_totalStoreSrc; 141 uint8_t m_totalStoreKey; 142 uint8_t m_totalSource; 143 uint8_t m_totalNotes; 144 uint8_t m_totalStoreNotes; 145 bool m_Publish; 146 bool m_findBuddy; 147 bool m_lastFirewallState; 148 bool m_useExternKadPort; 149 uint16_t m_externKadPort; 150 std::vector<uint32_t> m_externPortIPs; 151 std::vector<uint16_t> m_externPorts; 152 153 // Statistics 154 uint32_t m_statsUDPOpenNodes; 155 uint32_t m_statsUDPFirewalledNodes; 156 uint32_t m_statsTCPOpenNodes; 157 uint32_t m_statsTCPFirewalledNodes; 158 time_t m_statsKadV8LastChecked; 159 float m_statsKadV8Ratio; 160 161 void Init(const wxString& filename); 162 // void Reset(); 163 // void SetDefaults(); 164 void ReadFile(); 165 void WriteFile(); 166}; 167 168} // End namespace 169 170#include "Kademlia.h" 171 172inline bool Kademlia::CPrefs::GetUseExternKadPort() const 173{ 174 return m_useExternKadPort && !Kademlia::CKademlia::IsRunningInLANMode(); 175} 176 177#endif //__PREFS_H__ 178// File_checked_for_headers 179