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_DISCOVERYSERVICES_H__2AD74990_0834_4FE8_AE38_1DD609232BC7__INCLUDED_)
00023 #define AFX_DISCOVERYSERVICES_H__2AD74990_0834_4FE8_AE38_1DD609232BC7__INCLUDED_
00024
00025 #pragma once
00026
00027 class CDiscoveryService;
00028
00029
00030 class CDiscoveryServices
00031 {
00032
00033 public:
00034 CDiscoveryServices();
00035 virtual ~CDiscoveryServices();
00036
00037 enum { wcmHosts, wcmCaches, wcmUpdate, wcmSubmit, wcmServerMet };
00038
00039
00040 protected:
00041 CPtrList m_pList;
00042 HANDLE m_hThread;
00043 HINTERNET m_hInternet;
00044 HINTERNET m_hRequest;
00045 CDiscoveryService* m_pWebCache;
00046 int m_nWebCache;
00047 CDiscoveryService* m_pSubmit;
00048 DWORD m_tQueried;
00049 PROTOCOLID m_nLastQueryProtocol;
00050 DWORD m_tUpdated;
00051 PROTOCOLID m_nLastUpdateProtocol;
00052 DWORD m_tExecute;
00053 BOOL m_bFirstTime;
00054
00055 DWORD m_tMetQueried;
00056
00057
00058 public:
00059 POSITION GetIterator() const;
00060 CDiscoveryService* GetNext(POSITION& pos) const;
00061 BOOL Check(CDiscoveryService* pService, int nType = -1) const;
00062 int GetCount(int nType = 0, PROTOCOLID nProtocol = PROTOCOL_NULL) const;
00063 CDiscoveryService* Add(LPCTSTR pszAddress, int nType, PROTOCOLID nProtocol = PROTOCOL_NULL);
00064 CDiscoveryService* Add(CDiscoveryService* pService);
00065 void Remove(CDiscoveryService* pService, BOOL bCheck = TRUE);
00066 BOOL CheckWebCacheValid(LPCTSTR pszAddress);
00067 BOOL CheckMinimumServices();
00068 BOOL QueryForHosts(PROTOCOLID nProtocol);
00069 DWORD MetQueried() const;
00070 CDiscoveryService* GetByAddress(LPCTSTR pszAddress) const;
00071 void Clear();
00072
00073 public:
00074 BOOL Load();
00075 BOOL Save();
00076 BOOL Update();
00077 BOOL Execute(BOOL bSecondary = FALSE);
00078 void Stop();
00079 void OnGnutellaAdded(IN_ADDR* pAddress, int nCount);
00080 void OnGnutellaFailed(IN_ADDR* pAddress);
00081 protected:
00082 void Serialize(CArchive& ar);
00083 BOOL EnoughServices() const;
00084 void AddDefaults();
00085 int ExecuteBootstraps(int nCount);
00086 BOOL RequestRandomService(PROTOCOLID nProtocol);
00087 CDiscoveryService* GetRandomService(PROTOCOLID nProtocol);
00088 CDiscoveryService* GetRandomWebCache(PROTOCOLID nProtocol, BOOL bWorkingOnly, CDiscoveryService* pExclude = NULL, BOOL bForUpdate = FALSE);
00089 BOOL RequestWebCache(CDiscoveryService* pService, int nMode, PROTOCOLID nProtocol);
00090 void StopWebRequest();
00091 protected:
00092 static UINT ThreadStart(LPVOID pParam);
00093 void OnRun();
00094 BOOL RunWebCacheGet(BOOL bCache);
00095 BOOL RunWebCacheUpdate();
00096 BOOL RunServerMet();
00097 BOOL SendWebCacheRequest(CString strURL, CString& strOutput);
00098
00099 friend class CDiscoveryService;
00100 };
00101
00102
00103 class CDiscoveryService
00104 {
00105
00106 public:
00107 CDiscoveryService(int nType = 0, LPCTSTR pszAddress = NULL);
00108 virtual ~CDiscoveryService();
00109
00110
00111 public:
00112 int m_nType;
00113 CString m_sAddress;
00114 public:
00115 BOOL m_bGnutella2;
00116 BOOL m_bGnutella1;
00117 DWORD m_tCreated;
00118 DWORD m_tAccessed;
00119 DWORD m_nAccesses;
00120 DWORD m_tUpdated;
00121 DWORD m_nUpdates;
00122 DWORD m_nHosts;
00123 DWORD m_nFailures;
00124 DWORD m_nAccessPeriod;
00125 DWORD m_nUpdatePeriod;
00126
00127 enum
00128 {
00129 dsNull, dsGnutella, dsWebCache, dsServerMet, dsBlocked
00130 };
00131
00132
00133 public:
00134 void Remove(BOOL bCheck = TRUE);
00135 BOOL Execute(int nMode = 0);
00136 void OnAccess();
00137 void OnHostAdd(int nCount = 1);
00138 void OnSuccess();
00139 void OnFailure();
00140 protected:
00141 void Serialize(CArchive& ar, int nVersion);
00142 BOOL ResolveGnutella();
00143
00144 friend class CDiscoveryServices;
00145
00146 };
00147
00148 extern CDiscoveryServices DiscoveryServices;
00149
00150
00151 #endif // !defined(AFX_DISCOVERYSERVICES_H__2AD74990_0834_4FE8_AE38_1DD609232BC7__INCLUDED_)