PacketSession.h

Go to the documentation of this file.
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__PACKET_PROCESSING__PACKET_SESSION_H
00024 #define GNUTELLA__PACKET_PROCESSING__PACKET_SESSION_H
00025 
00026 #include "Gnutella/Packets/Namespace.h"
00027 #include "Protocols/Transports/Connection.h"
00028 #include "Gnutella/NodeInfo.h"
00029 
00030 namespace Gnutella { namespace PacketProcessing { namespace QueryRouting { class QueryRoutingTable; }}}
00031 
00032 // Open containing namespaces:
00033 namespace Gnutella {
00034 namespace PacketProcessing {
00036 
00037 using Protocols::Transports::Connection;
00038 using Gnutella::NodeInfo;
00039 using Gnutella::Packets::Packet;
00040 using Gnutella::PacketProcessing::QueryRouting::QueryRoutingTable;
00041 
00042 class PacketSessionPrivate;
00043 
00044 // \todo Maybe use some abstract DataSession base instead of QObject?
00045 class PacketSession : public QObject
00046 {
00047     Q_OBJECT
00048     REFERENCE_OBJECT (PacketSession)
00049 
00050 public:
00052 
00056     enum CloseCode
00057     {
00058         CloseNoBye          = 0,    
00059         ExittingNormally    = 200,  
00060         ExplicitClose       = 201,  
00061         TooBigPackets       = 400,  
00062         TooManyDuplicates   = 401,  
00063         BadQueries          = 402,  
00064         TooHighTtlHops      = 403,  
00065         ManyUnknownPackets  = 404,  
00066         InactivityTimeout   = 405,  
00067         NoTtl1PingReply     = 406,  
00068         NotSharingEnough    = 407,  
00069         InternalError       = 500,  
00070         ProtocolDesync      = 501,  
00071         SendQueueFull       = 502   
00072     };
00073 
00074                 PacketSession (Connection *, const NodeInfo &);
00075                 ~PacketSession();
00076 
00077     NodeInfo                    nodeInfo() const;
00078     const QueryRoutingTable &   queryRoutingTable() const;
00079 
00080     void        closeSession (CloseCode);
00081 
00082     void        sendPacket (const Packet &packet);
00083     void        sendQrt (const QueryRoutingTable &);
00084 
00085     int         readTimeout() const;
00086     void        setReadTimeout (int);
00087 
00088     void        deleteLater();
00089 
00090 signals:
00091     void    packetRead (Packet &, PacketSession *);
00092     void    qrtRead (PacketSession *);
00093     void    sessionClosed (PacketSession *);
00094 
00095 private slots:
00096     void    readTimeout();
00097     void    connectionClosed();
00098     void    packetRead();
00099     void    packetWritten();
00100     void    qrtRead();
00101     void    readError();
00102     //void  writeError();
00103 
00104 private:
00105     PacketSessionPrivate    *p;
00106 };
00107 
00108 // Close containing namespaces:
00109 } // namespace PacketProcessing
00110 } // namespace Gnutella
00112 
00113 #endif // GNUTELLA__PACKET_PROCESSING__PACKET_SESSION_H