Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

DiscoveryServices.h

Go to the documentation of this file.
00001 //
00002 // DiscoveryServices.h
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 // Construction
00033 public:
00034         CDiscoveryServices();
00035         virtual ~CDiscoveryServices();
00036         
00037         enum { wcmHosts, wcmCaches, wcmUpdate, wcmSubmit, wcmServerMet };
00038 
00039 // Attributes
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;                                     // Time a webcache was last queried
00049         PROTOCOLID                      m_nLastQueryProtocol;           // Protocol that was queried most recently
00050         DWORD                           m_tUpdated;                                     // Time a webcache was last updated
00051         PROTOCOLID                      m_nLastUpdateProtocol;          // Protocol that had a service update most recently
00052         DWORD                           m_tExecute;                                     // Time the Execute() function was last run
00053         BOOL                            m_bFirstTime;
00054 
00055         DWORD                           m_tMetQueried;                          // Time a MET was last queried
00056 
00057 // Operations
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 // Construction
00106 public:
00107         CDiscoveryService(int nType = 0, LPCTSTR pszAddress = NULL);
00108         virtual ~CDiscoveryService();
00109 
00110 // Attributes
00111 public:
00112         int                     m_nType;
00113         CString         m_sAddress;
00114 public:
00115         BOOL            m_bGnutella2;                   // Webcache supports Gnutella 2
00116         BOOL            m_bGnutella1;                   // Webcache supports Gnutella
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 // Operations
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_)

Generated on Thu Dec 15 10:39:38 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2