PacketBase.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__BIT_TORRENT__PACKETS__PACKET_BASE_H
00024 #define PROTOCOLS__BIT_TORRENT__PACKETS__PACKET_BASE_H
00025
00026 #include "Imports.h"
00027
00028 namespace Protocols {
00029 namespace BitTorrent {
00030 namespace Packets {
00031
00033
00034 enum PacketType
00035 {
00036 KeepalivePacket = 0xFF,
00037 ChokePacket = 0x00,
00038 UnchokePacket = 0x01,
00039 InterestedPacket = 0x02,
00040 NotInterestedPacket = 0x03,
00041 HavePacket = 0x04,
00042 BitFieldPacket = 0x05,
00043 RequestPacket = 0x06,
00044 PiecePacket = 0x07,
00045 CancelPacket = 0x08,
00046 PortPacket = 0x09,
00047
00048
00049
00050 SuggestPiecePacket = 0x0D,
00051 HaveAllPacket = 0x0E,
00052 HaveNonePacket = 0x0F,
00053 RejectRequestPacket = 0x10,
00054 AllowedFastPacket = 0x11
00055 };
00056
00058
00074 class PacketBase : public GenericsPacketBase
00075 {
00076 public:
00077 virtual QString protocol() const;
00078 virtual QString name() const = 0;
00079 virtual auto_ptr <DataBase>
00080 copy() const = 0;
00081
00082 inline PacketType packetType() const;
00083
00084 protected:
00085 class Data;
00086 PacketBase (Data *d, PacketType packetType);
00087
00088 virtual bool readHeader (const QByteArray &rawHeader);
00089 virtual bool readPayload (const QByteArray &rawPayload);
00090
00091 virtual QByteArray writeHeader () const;
00092 virtual QByteArray writePayload () const;
00093
00094 virtual void readPayload (BinaryReader &) = 0;
00095 virtual void writePayload (BinaryWriter &) const = 0;
00096
00098
00104 class Data: public GenericsPacketBase::Data
00105 {
00106 public:
00107 PacketType packetType;
00108 };
00109
00110 private:
00111 Q_DECLARE_SHARED_DATA (Data);
00112 };
00113
00115
00118 inline PacketType PacketBase::packetType() const
00119 { Q_SD (const Data); return d->packetType; }
00120
00121 }
00122 }
00123 }
00124
00125 #endif // PROTOCOLS__BIT_TORRENT__PACKETS__PACKET_BASE_H