00001 // 00002 // ShakeNeighbour.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 // CShakeNeighbour reads and sends handshake headers to negotiate the Gnutella or Gnutella2 handshake 00023 // http://wiki.shareaza.com/static/Developers.Code.CShakeNeighbour 00024 00025 // Make the compiler only include the lines here once, this is the same thing as pragma once 00026 #if !defined(AFX_SHAKENEIGHBOUR_H__259E22A0_EFA9_4684_B642_B98CE4CE682F__INCLUDED_) 00027 #define AFX_SHAKENEIGHBOUR_H__259E22A0_EFA9_4684_B642_B98CE4CE682F__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 // Define the class CShakeNeighbour to inherit from CNeighbour, which inherits from CConnection, picking up a socket 00036 class CShakeNeighbour : public CNeighbour 00037 { 00038 00039 public: 00040 00041 // Make a new CShakeNeighbour object, and delete this one 00042 CShakeNeighbour(); // Make a new blank CShakeNeighbour object 00043 virtual ~CShakeNeighbour(); // Delete this CShakeNeighbour object, virtual means we expect a derived class to redefine this 00044 00045 protected: 00046 00047 // Shareaza Settings allow us to send and receive compressed data 00048 BOOL m_bCanDeflate; 00049 00050 // Set to true when we have sent the following handshake header 00051 BOOL m_bSentAddress; // We told the remote computer our Internet IP address that we are listening on 00052 // We sent it a header like this 00053 // 00054 // Listen-IP: 1.2.3.4:5 00055 // 00056 00057 // Set to true when we have received the following handshake headers 00058 BOOL m_bG2Send; // The remote computer is going to send us Gnutella2 packets 00059 // It sent us a header like one of these 00060 // 00061 // Content-Type: application/x-gnutella2 00062 // Content-Type: application/x-shareaza 00063 // 00064 BOOL m_bG2Accept; // The remote computer accepts Gnutella2 packets 00065 // It sent us a header like one of these 00066 // 00067 // Accept: application/x-gnutella2 00068 // Accept: application/x-shareaza 00069 // 00070 BOOL m_bDeflateSend; // All the data from the remote computer is going to be compressed 00071 // It sent us a header like this 00072 // 00073 // Content-Encoding: deflate 00074 // 00075 BOOL m_bDeflateAccept; // The remote computer accepts compressed data 00076 // It sent us a header like this 00077 // 00078 // Accept-Encoding: deflate 00079 // 00080 TRISTATE m_bUltraPeerSet; // The remote computer is an ultrapeer or hub, true, a leaf, false, or hasn't told us yet, unknown 00081 // True if it sent us a header like this 00082 // 00083 // X-Ultrapeer: True 00084 // X-Hub: True 00085 // 00086 // False if it sent us a header like this 00087 // 00088 // X-Ultrapeer: False 00089 // X-Hub: False 00090 // 00091 // Unknown if it hasn't sent us any headers like that yet 00092 TRISTATE m_bUltraPeerNeeded; // True if the remote computer has told us it needs more connections to ultrapeers or hubs 00093 // True if it sent us a header like this 00094 // 00095 // X-Ultrapeer-Needed: True 00096 // X-Hub-Needed: True 00097 // 00098 // False if it sent us a header like this 00099 // 00100 // X-Ultrapeer-Needed: False 00101 // X-Hub-Needed: False 00102 // 00103 // Unknown if it hasn't sent us any headers like that yet 00104 00105 // Possibly not in use (do) 00106 TRISTATE m_bUltraPeerLoaded; 00107 00108 public: 00109 00110 // Connect, disconnect, and copy 00111 virtual BOOL ConnectTo(IN_ADDR* pAddress, WORD nPost, BOOL bAutomatic = FALSE, BOOL bNoUltraPeer = FALSE); // Connect to an ip address and port number 00112 virtual void AttachTo(CConnection* pConnection); // Copy the values from the given CConnection object into the CConnection core of this one 00113 virtual void Close(UINT nError = IDS_CONNECTION_CLOSED ); // Close the socket and log the reason the connection didn't work 00114 00115 protected: 00116 00117 // Read headers and respond to them 00118 virtual BOOL OnConnected(); // Send the remote computer our first big block of Gnutella headers 00119 virtual BOOL OnRead(); // Read data from the remote computer, and look at it as a handshake 00120 virtual void OnDropped(BOOL bError); // Document that the connection was lost and why, and put everything away 00121 virtual BOOL OnRun(); // Make sure the handshake hasn't been taking too long 00122 virtual BOOL OnHeaderLine(CString& strHeader, CString& strValue); // Reads a header line and sets a corresponding member variable to true 00123 virtual BOOL OnHeadersComplete(); // Responds to a group of headers by closing, sending a response, or turning this object into a more specific one 00124 virtual BOOL OnHeadersCompleteG1(); 00125 virtual BOOL OnHeadersCompleteG2(); 00126 00127 // Send headers to the remote computer 00128 void SendMinimalHeaders(); // Tell the remote computer we are Shareaza, and try to setup Gnutella2 communications 00129 void SendPublicHeaders(); // Send our first big group of Gnutella headers to the remote computer 00130 void SendPrivateHeaders(); // Reply to a remote computer's headers, confirming Gnutella2 packets and data compression 00131 void SendHostHeaders(LPCTSTR pszMessage = NULL); // Send a 503 error message, and the "X-Try-Ultrapeers:" header 00132 BOOL ReadResponse(); // Read the first line of a new group of headers from the remote computer 00133 void OnHandshakeComplete(); // Turn this object into one specialized for Gnutella or Gnutella2 00134 00135 BOOL IsClientObsolete(); // Checks the user agent to see if it's an old client. 00136 BOOL IsClientBad(); // Checks to see if it's a GPL violator or glitchy client. 00137 BOOL IsClientBanned(); // Checks to see if it's a leecher. (Clients are blocked) 00138 }; 00139 00140 // End the group of lines to only include once, pragma once doesn't require an endif at the bottom 00141 #endif // !defined(AFX_SHAKENEIGHBOUR_H__259E22A0_EFA9_4684_B642_B98CE4CE682F__INCLUDED_)