Packet.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PROTOCOLS__KAD__PACKETS__PACKET
00024 #define PROTOCOLS__KAD__PACKETS__PACKET
00025
00026 #include "Imports.h"
00027
00028 namespace Protocols {
00029 namespace Kad {
00030 namespace Packets {
00031
00033 enum Protocol {
00034 KadProtocol = 0xE4,
00035 KadPackedProtocol = 0xE5
00036 };
00037
00039 enum PacketType
00040 {
00041 BootstrapReqPacket = 0x00,
00042 BootstrapResPacket = 0x08,
00043 HelloReqPacket = 0x10,
00044 HelloResPacket = 0x18,
00045 ReqPacket = 0x20,
00046 ResPacket = 0x28,
00047 SearchReqPacket = 0x30,
00048 SearchNotesReqPacket = 0x32,
00049 SearchResPacket = 0x38,
00050 SearchNotesResPacket = 0x3A,
00051 PublishReqPacket = 0x40,
00052 PublishNotesReqPacket = 0x42,
00053 PublishResPacket = 0x48,
00054 PublishNotesResPacket = 0x4A,
00055 FirewalledReqPacket = 0x50,
00056 FindBuddyReqPacket = 0x51,
00057 CallbackReqPacket = 0x52,
00058 FirewalledResPacket = 0x58,
00059 FirewalledAckPacket = 0x59,
00060 FindBuddyResPacket = 0x5A
00061 };
00062
00063
00065
00079 class Packet : public PacketBase
00080 {
00081 public:
00082 virtual QString protocol() const;
00083 virtual QString name() const = 0;
00084 virtual Packet* copy() const = 0;
00085
00086 inline Protocol protocolId() const;
00087 inline PacketType packetType() const;
00088
00089 protected:
00090 class Data;
00091 Packet (Data *d, PacketType packetType);
00092
00093 virtual bool readHeader (const QByteArray &rawHeader);
00094 virtual bool readPayload (const QByteArray &rawPayload);
00095 virtual bool readTrailer (const QByteArray &rawTrailer);
00096
00097 virtual QByteArray writeHeader () const;
00098 virtual QByteArray writePayload () const;
00099 virtual QByteArray writeTrailer () const;
00100
00101 virtual void readPayload (BinaryReader &) = 0;
00102 virtual void writePayload (BinaryWriter &) const = 0;
00103
00104
00106
00112 class Data: public PacketBase::Data
00113 {
00114 public:
00115 mutable Protocol protocolId;
00116 PacketType packetType;
00117 };
00118
00119 private:
00120 Q_DECLARE_SHARED_DATA (Data);
00121 };
00122
00124 inline PacketType Packet::packetType() const
00125 { Q_SD (const Data); return d->packetType; }
00126
00128 inline Protocol Packet::protocolId() const
00129 { Q_SD (const Data); return d->protocolId; }
00130
00131 }
00132 }
00133 }
00134
00135 #endif // PROTOCOLS__KAD__PACKETS__PACKET