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_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
00040 public:
00041 CNetwork();
00042 virtual ~CNetwork();
00043
00044
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;
00054 BOOL m_bAutoConnect;
00055 DWORD m_tStartedConnecting;
00056 DWORD m_tLastConnect;
00057 protected:
00058 HANDLE m_hThread;
00059 DWORD m_nSequence;
00060 CMapPtrToPtr m_pLookups;
00061
00062
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;
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_)