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

Network.h

Go to the documentation of this file.
00001 //
00002 // Network.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_NETWORK_H__544414B1_3698_4C92_B0B0_1DC56AB48074__INCLUDED_)
00023 #define AFX_NETWORK_H__544414B1_3698_4C92_B0B0_1DC56AB48074__INCLUDED_
00024 
00025 #pragma once
00026 
00027 class CNeighbour;
00028 class CBuffer;
00029 class CPacket;
00030 class CG2Packet;
00031 class CRouteCache;
00032 class CQueryKeys;
00033 class CQuerySearch;
00034 class CQueryHit;
00035 
00036 
00037 class CNetwork
00038 {
00039 // Construction
00040 public:
00041         CNetwork();
00042         virtual ~CNetwork();
00043 
00044 // Attributes
00045 public:
00046         CRouteCache*    NodeRoute;
00047         CRouteCache*    QueryRoute;
00048         CQueryKeys*             QueryKeys;
00049 public:
00050         CMutex                  m_pSection;
00051         CEvent                  m_pWakeup;
00052         SOCKADDR_IN             m_pHost;
00053         BOOL                    m_bEnabled;                             // If the network "enabled" (Connected or trying)
00054         BOOL                    m_bAutoConnect;
00055         DWORD                   m_tStartedConnecting;   // The time Shareaza started trying to connect
00056         DWORD                   m_tLastConnect;                 // The last time a neighbout connection attempt was made
00057 protected:
00058         HANDLE                  m_hThread;
00059         DWORD                   m_nSequence;
00060         CMapPtrToPtr    m_pLookups;
00061 
00062 // Operations
00063 public:
00064         BOOL            IsAvailable() const;
00065         BOOL            IsConnected() const;
00066         BOOL            IsListening() const;
00067         int                     IsWellConnected() const;
00068         BOOL            IsStable() const;
00069         DWORD           GetStableTime() const;
00070         BOOL            IsConnectedTo(IN_ADDR* pAddress);
00071         BOOL            ReadyToTransfer(DWORD tNow) const;              // Are we ready to start downloading?
00072 public:
00073         BOOL            Connect(BOOL bAutoConnect = FALSE);
00074         void            Disconnect();
00075         BOOL            ConnectTo(LPCTSTR pszAddress, int nPort = 0, PROTOCOLID nProtocol = PROTOCOL_NULL, BOOL bNoUltraPeer = FALSE);
00076         void            AcquireLocalAddress(LPCTSTR pszHeader);
00077         BOOL            Resolve(LPCTSTR pszHost, int nPort, SOCKADDR_IN* pHost, BOOL bNames = TRUE) const;
00078         BOOL            AsyncResolve(LPCTSTR pszAddress, WORD nPort, PROTOCOLID nProtocol, BYTE nCommand);
00079         WORD            RandomPort() const;
00080         void            CreateID(GGUID& oID);
00081         BOOL            IsFirewalledAddress(LPVOID pAddress, BOOL bIncludeSelf = FALSE);
00082 public:
00083         BOOL            GetNodeRoute(GGUID* pGUID, CNeighbour** ppNeighbour, SOCKADDR_IN* pEndpoint);
00084         BOOL            RoutePacket(CG2Packet* pPacket);
00085         BOOL            SendPush(GGUID* pGUID, DWORD nIndex = 0);
00086         BOOL            RouteHits(CQueryHit* pHits, CPacket* pPacket);
00087         void            OnWinsock(WPARAM wParam, LPARAM lParam);
00088         void            OnQuerySearch(CQuerySearch* pSearch);
00089         void            OnQueryHits(CQueryHit* pHits);
00090 protected:
00091         static UINT     ThreadStart(LPVOID pParam);
00092         void            OnRun();
00093 
00094         friend class CHandshakes;
00095         friend class CNeighbours;
00096 };
00097 
00098 extern CNetwork Network;
00099 
00100 
00101 #endif // !defined(AFX_NETWORK_H__544414B1_3698_4C92_B0B0_1DC56AB48074__INCLUDED_)

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