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_LOCAL_PEER_H 00024 #define GNUTELLA_LOCAL_PEER_H 00025 00026 #include "Gnutella/Namespace.h" 00027 // breaks MOC FORWARD_DECLARE2 (Protocols, Transports, class Connection) 00028 namespace Protocols { namespace Transports { class Connection; }} 00029 #include "Gnutella/Bootstrapping/Namespace.h" 00030 #include "Gnutella/Handshaking/Namespace.h" 00031 #include "Gnutella/PacketProcessing/Namespace.h" 00032 #include "Gnutella/Searching/Namespace.h" 00033 #include "UIs/Searching/Namespace.h" 00034 00035 // get away with these: 00036 class UIs::Searching::SearchModel; 00037 #include "Gnutella/Packets/Query.h" 00038 00039 // Open containing namespaces: 00040 namespace Gnutella { 00042 00043 using Protocols::Transports::Connection; 00044 using Gnutella::NodeInfo; 00045 using Gnutella::Bootstrapping::NodeCache; 00046 using Gnutella::Bootstrapping::UdpHostCache; 00047 using Gnutella::Handshaking::SlotAllocator; 00048 using Gnutella::PacketProcessing::PacketProcessor; 00049 using Gnutella::Searching::Searcher; 00050 using UIs::Searching::SearchModel; 00051 00052 class LocalPeerPrivate; 00053 class Workaround; 00054 00055 // get these away: 00056 using Gnutella::Packets::Query; 00057 00059 00061 class LocalPeer : public QObject 00062 { 00063 Q_OBJECT 00064 REFERENCE_OBJECT (LocalPeer) 00065 00066 public: 00067 LocalPeer(); 00068 ~LocalPeer(); 00069 00070 bool connectToNetwork(); 00071 bool disconnectFromNetwork(); 00072 00073 void connectToPeer (const QString &hostName, quint16 port); 00074 void disconnectFromPeer (Connection *); 00075 00076 void startSearch (SearchModel *searchModel, QString &query); 00077 void stopSearch (SearchModel *searchModel); 00078 00079 QHostAddress serverIpAddress() const; 00080 quint16 serverPort() const; 00081 // <pd_todo> If server is running, shut it down and start it on new port. Address is required for pongs! 00082 void setServerIpAddress (const QHostAddress &ipAddress); 00083 void setServerPort (quint16 port); 00084 00085 const NodeInfo & nodeInfo() const; 00086 bool isUltrapeer() const; 00087 NodeCache * nodeCache(); 00088 UdpHostCache * udpHostCache(); 00089 SlotAllocator * slotAllocator(); 00090 PacketProcessor * packetProcessor(); 00091 Searcher * searcher(); 00092 QAbstractItemModel * nodeModel(); 00093 QAbstractItemModel * packetModel(); 00094 00095 private slots: 00096 void newConnection(); 00097 void acceptHandshakeConnection (QTcpSocket *); 00098 // <pd_todo> void acceptTransferConnection(); 00099 00100 private: 00101 friend class Workaround; // \todo Workaround! See Private's ctor! 00102 LocalPeerPrivate *p; 00103 }; 00104 00105 // Close containing namespaces: 00106 } // namespace Gnutella 00108 00109 #endif // GNUTELLA_LOCAL_PEER_H