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 PACKETROUTER_H 00024 #define PACKETROUTER_H 00025 00026 #include "Gnutella/Packets/Namespace.h" 00027 #include "Gnutella/PacketProcessing/PacketSession.h" 00028 #include "Gnutella/PacketProcessing/PacketProcessor.h" 00029 00030 // Open containing namespaces: 00031 namespace Gnutella { 00032 namespace PacketProcessing { 00034 00035 using Gnutella::Packets::Query; 00036 using Gnutella::Packets::QueryHits; 00037 using Gnutella::Packets::Push; 00038 using Gnutella::PacketProcessing::PacketSession; 00039 00044 class PacketRouter : QObject 00045 { 00046 Q_OBJECT 00047 00048 public: 00049 typedef PacketProcessor::Sessions Paths; 00050 00051 PacketRouter(); 00052 ~PacketRouter(); 00053 00054 bool isDuplicate (const Packet &); 00055 void addQueryPath (const Query &, PacketSession *); 00056 void addQueryHitsPath (const QueryHits &, PacketSession *); 00057 // Well, requiring specific types improves type-safety and guarantees we are not 00058 // saving path for the wrong packet type by mistake. Maybe we should rethink the 00059 // concept of this packet router. 00060 void addQueryStatusRequestPath (const Packet &, PacketSession *); 00061 Paths queryHitsRoutePaths (const Packet &); // \todo Pass only the descriptorId? 00062 Paths pushRoutePaths (const Push &); 00063 Paths queryStatusResponsePaths (const Packet &); 00064 00065 private slots: 00066 void clearExpiredPaths (); 00067 00068 private: 00069 00070 typedef QSet <PacketSession *> PathSet; 00071 typedef QHash <QUuid, PathSet *> PacketPaths; 00072 typedef QPair <QUuid, QTime> Expiration; 00073 typedef QList <Expiration*> PathExpirations; 00074 00075 PacketPaths queryPaths; 00076 PacketPaths queryHitsPaths; 00077 PacketPaths queryStatusRequestPaths; 00078 00079 PathExpirations queryExpirations; 00080 PathExpirations queryHitsExpirations; 00081 PathExpirations queryStatusRequestExpirations; 00082 QTimer expirationTimer; 00083 }; 00084 00085 // Close containing namespaces: 00086 } // namespace PacketProcessing 00087 } // namespace Gnutella 00089 00090 #endif // PACKETROUTER_H