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 PACKETMONITOR_H 00024 #define PACKETMONITOR_H 00025 /* 00026 #include "Gnutella/Namespace.h" 00027 #include "PacketFilter.h" 00028 #include "PacketMap.h" 00029 #include "Gnutella/Connections/ConnectionMap.h" 00030 00031 // Open containing namespaces: 00032 namespace Gnutella { 00033 namespace PacketProcessing { 00035 00036 using Gnutella::LocalPeer; 00037 // \todo Put PacketMap in the same namespace? or in Packets? 00038 using Gnutella::Connections::ConnectionMap; 00039 00040 class PacketMonitor : public PacketFilter 00041 { 00042 public: 00043 PacketMonitor (LocalPeer *localPeer); 00044 ~PacketMonitor(); 00045 00046 bool filterInput (ConnectionId id, const Packet &packet); 00047 bool filterOutput (ConnectionId id, const Packet &packet); 00048 00049 protected: 00050 00051 struct ConnectionStats 00052 { 00053 quint32 totalCount; 00054 quint32 unknownCount; 00055 quint32 badCount; 00056 quint64 totalBytes; 00057 quint64 unknownBytes; 00058 quint64 badBytes; 00059 00060 ConnectionStats() : totalCount (0), unknownCount (0), badCount (0), totalBytes (0), unknownBytes (0), badBytes (0) {} 00061 }; 00062 00063 struct PacketStats 00064 { 00065 quint32 count; 00066 quint32 badCount; 00067 quint64 bytes; 00068 quint64 badBytes; 00069 00070 PacketStats() : count (0), badCount (0), bytes (0), badBytes (0) {} 00071 PacketStats(PayloadDescriptor) : count (0), badCount (0), bytes (0), badBytes (0) {} 00072 }; 00073 00074 bool filter (ConnectionStats *connectionStats, PacketStats *packetStats, const Packet &packet); 00075 00076 void addConnection (ConnectionId id, const NodeInfo &); 00077 void removeConnection (ConnectionId id); 00078 00079 private: 00080 ConnectionMap <ConnectionStats> connectionInputStats; 00081 PacketMap <PacketStats> connectionInputPacketStats; 00082 00083 ConnectionMap <ConnectionStats> connectionOutputStats; 00084 PacketMap <PacketStats> connectionOutputPacketStats; 00085 00086 LocalPeer *localPeer; 00087 00088 QFile logFile; 00089 QTextStream *log; 00090 }; 00091 00092 // Close containing namespaces: 00093 }; // namespace PacketProcessing 00094 }; // namespace Gnutella 00096 */ 00097 #endif // PACKETMONITOR_H