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 PACKETPROCESSOR_H 00024 #define PACKETPROCESSOR_H 00025 00026 #include "Gnutella/Namespace.h" 00027 #include "Gnutella/NodeInfo.h" 00028 #include "Gnutella/Packets/Namespace.h" 00029 // breaks MOC FORWARD_DECLARE2 (Protocols, Transports, class Connection) 00030 namespace Protocols { namespace Transports { class Connection; }} 00031 FORWARD_DECLARE3 (Gnutella, Packets, VendorMessages, class QueryStatusRequest) 00032 #include "Gnutella/Bootstrapping/NodeCache.h" 00033 00034 // Open containing namespaces: 00035 namespace Gnutella { 00036 namespace PacketProcessing { 00038 00039 class PacketSession; 00040 using Gnutella::LocalPeer; 00041 using Gnutella::NodeInfo; 00042 using Gnutella::Packets::Packet; 00043 using Gnutella::Packets::Ping; 00044 using Gnutella::Packets::Pong; 00045 using Gnutella::Packets::Query; 00046 using Gnutella::Packets::QueryHits; 00047 using Gnutella::Packets::Push; 00048 using Gnutella::Packets::VendorMessages::QueryStatusRequest; 00049 using Protocols::Transports::Connection; 00050 using Gnutella::Bootstrapping::NodeCache; 00051 00052 class PacketProcessorPrivate; 00053 00060 class PacketProcessor : public QObject 00061 { 00062 Q_OBJECT 00063 REFERENCE_OBJECT (PacketProcessor) 00064 00065 public: 00066 typedef QSet <PacketSession *> Sessions; 00067 00068 PacketProcessor (LocalPeer *); 00069 ~PacketProcessor(); 00070 00071 public slots: 00072 void addConnection (Connection *connection, NodeInfo nodeInfo); 00073 void sendPacket (const Packet &); 00074 00075 private slots: 00076 void packetReceived (Packet &packet, PacketSession *); 00077 void sessionClosed (PacketSession *); 00078 00079 signals: 00080 void receivedPong (const Pong &); 00081 void receivedPing (const Ping &); 00082 void receivedQuery (const Query &); 00083 void receivedQueryHits (const QueryHits &); 00084 void receivedPush (const Push &); 00085 void processQueryStatusRequest (const QueryStatusRequest &); 00086 00087 private: 00088 void notifyHandlers (Packet &packet); 00089 void routePacket (const Packet &packet); 00090 00091 PacketProcessorPrivate *d; 00092 }; 00093 00094 // Close containing namespaces: 00095 } // namespace PacketProcessing 00096 } // namespace Gnutella 00098 00099 #endif // PACKETPROCESSOR_H