00001 // 00002 // G1Neighbour.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 // A CG1Neighbour object represents a remote computer running Gnutella software with which we are exchanging Gnutella packets 00023 // http://wiki.shareaza.com/static/Developers.Code.CG1Neighbour 00024 00025 // Make the compiler only include the lines here once, this is the same thing as pragma once 00026 #if !defined(AFX_G1NEIGHBOUR_H__BF099C28_0FD5_4A9A_B36E_6490DA6FB62F__INCLUDED_) 00027 #define AFX_G1NEIGHBOUR_H__BF099C28_0FD5_4A9A_B36E_6490DA6FB62F__INCLUDED_ 00028 00029 // Only include the lines beneath this one once 00030 #pragma once 00031 00032 // Copy in the contents of these files here before compiling 00033 #include "Neighbour.h" 00034 00035 // Tell the compiler these classes exist, and it will find out more about them soon 00036 class CG1Packet; 00037 class CG1PacketBuffer; 00038 class CPongItem; 00039 00040 // A CG1Neighbour object represents a remote computer running Gnutella software with which we are exchanging Gnutella packets 00041 class CG1Neighbour : public CNeighbour // Inherit from CNeighbour and from that CConnection to get compression features and the connection socket 00042 { 00043 00044 public: 00045 00046 // Make a new CG1Neighbour object, and delete this one 00047 CG1Neighbour(CNeighbour* pBase); // Takes a pointer to a CShakeNeighbour object that determined the remote computer is running Gnutella 00048 virtual ~CG1Neighbour(); 00049 00050 protected: 00051 00052 // The tick count when something last happened 00053 DWORD m_tLastInPing; // When the remote computer last sent us a ping packet 00054 DWORD m_tLastOutPing; // When we last sent a ping packet to the remote computer 00055 DWORD m_tClusterHost; // When we last called SendClusterAdvisor (do) 00056 DWORD m_tClusterSent; // When that method last sent a vendor specific cluster advisor packet 00057 00058 protected: 00059 00060 // (do) 00061 BYTE m_nPongNeeded[PONG_NEEDED_BUFFER]; // This is just an array of 32 bytes 00062 00063 // Information about the most recent ping packet the remote computer has sent us 00064 GGUID m_pLastPingID; // The GUID of the most recent ping packet the remote computer has sent us 00065 BYTE m_nLastPingHops; // The number of hops that packet has travelled, adding 1 (do) 00066 00067 // A hops flow byte specific to BearShare (do) 00068 BYTE m_nHopsFlow; 00069 00070 protected: 00071 00072 // Holds the packets we are going to send to the remote computer 00073 CG1PacketBuffer* m_pOutbound; 00074 00075 public: 00076 00077 // Send a packet to the remote computer 00078 virtual BOOL Send(CPacket* pPacket, BOOL bRelease = TRUE, BOOL bBuffered = FALSE); 00079 00080 // Ping and Pong packets 00081 BOOL SendPing(DWORD dwNow = 0, GGUID* pGUID = NULL); 00082 void OnNewPong(CPongItem* pPong); 00083 00084 // Query packet 00085 virtual BOOL SendQuery(CQuerySearch* pSearch, CPacket* pPacket, BOOL bLocal); 00086 00087 // Push packet 00088 void SendG2Push(GGUID* pGUID, CPacket* pPacket); 00089 00090 protected: 00091 00092 // Send and recieve packets 00093 virtual BOOL OnRead(); // Read in data from the socket, decompress it, and call ProcessPackets 00094 virtual BOOL OnWrite(); // Sends all the packets from the outbound packet buffer to the remote computer 00095 virtual BOOL OnRun(); // Makes sure the remote computer hasn't been silent too long, and sends a ping every so often 00096 00097 protected: 00098 00099 // Read and respond to packets from the remote computer 00100 BOOL ProcessPackets(); // Cuts up the recieved data into packets, and calls OnPacket for each one 00101 BOOL OnPacket(CG1Packet* pPacket); // Sorts the packet and calls one of the methods below 00102 00103 // Ping and pong packets 00104 BOOL OnPing(CG1Packet* pPacket); 00105 BOOL OnPong(CG1Packet* pPacket); 00106 00107 // Bye packet 00108 BOOL OnBye(CG1Packet* pPacket); 00109 00110 // Vendor specific packet 00111 BOOL OnVendor(CG1Packet* pPacket); 00112 00113 // Push packet 00114 BOOL OnPush(CG1Packet* pPacket); 00115 00116 // Query and query hit packets 00117 BOOL OnQuery(CG1Packet* pPacket); 00118 BOOL OnHit(CG1Packet* pPacket); 00119 00120 // Cluster advisor vendor specific packet 00121 void SendClusterAdvisor(); 00122 BOOL OnClusterAdvisor(CG1Packet* pPacket); 00123 }; 00124 00125 // End the group of lines to only include once, pragma once doesn't require an endif at the bottom 00126 #endif // !defined(AFX_G1NEIGHBOUR_H__BF099C28_0FD5_4A9A_B36E_6490DA6FB62F__INCLUDED_)