00001 /* 00002 00003 Copyright (C) 2005-2007 by Peter Dimov. 00004 00005 This file is part of Calitko (http://www.calitko.org). 00006 00007 Calitko is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Calitko 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 Calitko; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #ifndef GNUTELLA__HANDSHAKING__HANDSHAKER_H 00024 #define GNUTELLA__HANDSHAKING__HANDSHAKER_H 00025 00026 #include "Imports.h" 00027 #include "HandshakeSession.h" // \todo Only required because of HandshakeError! REMOVE the include after moving the enum to another file! 00028 00029 namespace Gnutella { 00030 namespace Handshaking { 00031 00032 class SlotAllocator; 00033 class HandshakeSession; 00034 class HandshakerPrivate; 00035 00036 class Handshaker : public QObject 00037 { 00038 Q_OBJECT 00039 REFERENCE_OBJECT (Handshaker) 00040 00041 public: 00042 00043 Handshaker (LocalPeer *, NodeCache *, SlotAllocator *); 00044 ~Handshaker(); 00045 00046 void requestConnection (Connection *, const NodeAddress &); 00047 void acceptConnection (Connection *connection); 00048 00049 signals: 00050 void handshakingStarted (Connection *); 00051 void handshakingCompleted (Connection *, NodeInfo); 00052 void handshakingFailed (Connection *, Gnutella::Handshaking::HandshakeError); 00053 00054 private slots: 00055 void connectionEstablished (HandshakeSession *); 00056 void receivedRequest (HandshakeSession *); 00057 void receivedResponse (HandshakeSession *); 00058 void handshakingCompleted (HandshakeSession *); 00059 void handshakingFailed (HandshakeSession *); 00060 00061 private: 00062 // Interface to HandshakeSession. \todo Define a class for the interface? 00063 NodeInfo nodeInfo() const; 00064 bool hasFreePeerSlots() const; 00065 void setVisibleIp (const QHostAddress &ostAddress); 00066 void tryNodes (QStringList nodeAddresses); 00067 QStringList getTryNodes() const; 00068 00069 HandshakeSession * newSession (Connection *, const NodeAddress &); 00070 void deleteSession (HandshakeSession *); 00071 00073 bool hasRequiredFeatures (const NodeInfo &nodeInfo); 00074 bool compatibleNodeTypes (const NodeInfo &otherNodeInfo); 00075 bool hasSlotsFor (const NodeInfo &); 00076 int getRejectReason (HandshakeSession *session); 00077 00078 HandshakerPrivate *p; 00079 00080 friend class HandshakeSession; 00081 }; 00082 00083 } // namespace Handshaking 00084 } // namespace Gnutella 00085 00086 #endif // GNUTELLA__HANDSHAKING__HANDSHAKER_H