00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(AFX_HOSTCACHE_H__7F2764B0_BB17_4FF0_AF03_7BB7D4E22F7F__INCLUDED_)
00023 #define AFX_HOSTCACHE_H__7F2764B0_BB17_4FF0_AF03_7BB7D4E22F7F__INCLUDED_
00024
00025 #pragma once
00026
00027 class CHostCacheHost;
00028 class CNeighbour;
00029 class CG1Packet;
00030 class CVendor;
00031
00032
00033 class CHostCacheList
00034 {
00035
00036 public:
00037 CHostCacheList(PROTOCOLID nProtocol);
00038 virtual ~CHostCacheList();
00039
00040
00041 public:
00042 PROTOCOLID m_nProtocol;
00043 DWORD m_nHosts;
00044 DWORD m_nCookie;
00045 CHostCacheHost* m_pNewest;
00046 CHostCacheHost* m_pOldest;
00047 protected:
00048 DWORD m_nBuffer;
00049 CHostCacheHost* m_pBuffer;
00050 CHostCacheHost* m_pFree;
00051 CHostCacheHost* m_pHash[256];
00052
00053
00054 public:
00055 CHostCacheHost* Add(IN_ADDR* pAddress, WORD nPort, DWORD tSeen = 0, LPCTSTR pszVendor = NULL);
00056 BOOL Add(LPCTSTR pszHost, DWORD tSeen = 0, LPCTSTR pszVendor = NULL);
00057 CHostCacheHost* Find(IN_ADDR* pAddress) const;
00058 BOOL Check(CHostCacheHost* pHost) const;
00059 void Remove(CHostCacheHost* pHost);
00060 void OnFailure(IN_ADDR* pAddress, WORD nPort);
00061 DWORD CountHosts() const;
00062 void PruneByQueryAck();
00063 void PruneOldHosts();
00064 void Clear();
00065 void Serialize(CArchive& ar, int nVersion);
00066 int Import(LPCTSTR pszFile);
00067 int ImportMET(CFile* pFile);
00068 int LoadDefaultED2KServers();
00069 protected:
00070 CHostCacheHost* AddInternal(IN_ADDR* pAddress, WORD nPort, DWORD tSeen, LPCTSTR pszVendor);
00071 void RemoveOldest();
00072
00073
00074 public:
00075
00076 inline CHostCacheHost* GetNewest() const
00077 {
00078 return m_pNewest;
00079 }
00080
00081 inline CHostCacheHost* GetOldest() const
00082 {
00083 return m_pOldest;
00084 }
00085
00086 };
00087
00088 class CHostCacheHost
00089 {
00090
00091 public:
00092 CHostCacheHost();
00093
00094
00095 public:
00096 CHostCacheHost* m_pNextHash;
00097 CHostCacheHost* m_pPrevTime;
00098 CHostCacheHost* m_pNextTime;
00099
00100
00101 public:
00102 PROTOCOLID m_nProtocol;
00103 IN_ADDR m_pAddress;
00104 WORD m_nPort;
00105 CVendor* m_pVendor;
00106 BOOL m_bPriority;
00107 DWORD m_nUserCount;
00108 DWORD m_nUserLimit;
00109 DWORD m_nFileLimit;
00110 CString m_sName;
00111 CString m_sDescription;
00112 DWORD m_nTCPFlags;
00113 DWORD m_nUDPFlags;
00114
00115
00116 public:
00117 DWORD m_tAdded;
00118 DWORD m_tSeen;
00119 DWORD m_tRetryAfter;
00120 DWORD m_tConnect;
00121 DWORD m_tQuery;
00122 DWORD m_tAck;
00123 DWORD m_tStats;
00124 DWORD m_tFailure;
00125 DWORD m_nFailures;
00126
00127
00128 public:
00129 DWORD m_tKeyTime;
00130 DWORD m_nKeyValue;
00131 DWORD m_nKeyHost;
00132
00133
00134 public:
00135 void Update(WORD nPort, DWORD tSeen = 0, LPCTSTR pszVendor = NULL);
00136 CNeighbour* ConnectTo(BOOL bAutomatic = FALSE);
00137 CG1Packet* ToG1Ping(int nTTL = 0, GGUID* pGUID = NULL);
00138 CString ToString() const;
00139 BOOL CanConnect(DWORD tNow = 0) const;
00140 BOOL CanQuote(DWORD tNow = 0) const;
00141 BOOL CanQuery(DWORD tNow = 0) const;
00142 void SetKey(DWORD nKey, IN_ADDR* pHost = NULL);
00143 protected:
00144 void Serialize(CArchive& ar, int nVersion);
00145 void Reset(IN_ADDR* pAddress);
00146
00147 friend class CHostCacheList;
00148 friend class CHostCacheLinks;
00149 };
00150
00151
00152 class CHostCache
00153 {
00154
00155 public:
00156 CHostCache();
00157
00158
00159 public:
00160 CHostCacheList Gnutella1;
00161 CHostCacheList Gnutella2;
00162 CHostCacheList eDonkey;
00163 CPtrList m_pList;
00164
00165
00166 public:
00167 BOOL Load();
00168 BOOL Save();
00169 void Clear();
00170 protected:
00171 void Serialize(CArchive& ar);
00172 public:
00173 CHostCacheHost* Find(IN_ADDR* pAddress) const;
00174 BOOL Check(CHostCacheHost* pHost) const;
00175 void Remove(CHostCacheHost* pHost);
00176 void OnFailure(IN_ADDR* pAddress, WORD nPort);
00177
00178
00179 public:
00180 inline CHostCacheList* ForProtocol(PROTOCOLID nProtocol)
00181 {
00182 switch ( nProtocol )
00183 {
00184 case PROTOCOL_G1:
00185 return &Gnutella1;
00186 case PROTOCOL_G2:
00187 return &Gnutella2;
00188 case PROTOCOL_ED2K:
00189 return &eDonkey;
00190 default:
00191 ASSERT(FALSE);
00192 return NULL;
00193 }
00194 }
00195 };
00196
00197 extern CHostCache HostCache;
00198
00199 #endif // !defined(AFX_HOSTCACHE_H__7F2764B0_BB17_4FF0_AF03_7BB7D4E22F7F__INCLUDED_)