PeerInfoPacket.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__PEER_INFO_PACKET_H
00024 #define PROTOCOLS__KAD__PACKETS__PEER_INFO_PACKET_H
00025
00026 #include "Imports.h"
00027 #include "Packet.h"
00028
00029 namespace Protocols {
00030 namespace Kad {
00031 namespace Packets {
00032
00034
00040 template <PacketType type>
00041 class PeerInfoPacket: public Packet
00042 {
00043 public:
00044 virtual QString name() const;
00045 virtual PeerInfoPacket* copy() const;
00046
00047 PeerInfoPacket();
00048
00049 protected:
00050 virtual void readPayload (BinaryReader &);
00051 virtual void writePayload (BinaryWriter &) const;
00052
00053 enum Constants
00054 {
00055 PayloadLength = 25,
00056 };
00057
00059
00062 class Data: public Packet::Data
00063 {
00064 Q_SHARED_DATA_COPY (Data);
00065
00066 public:
00067 UInt128 id;
00068 quint32 ip;
00069 quint16 udpPort;
00070 quint16 tcpPort;
00071 quint8 notUsed;
00072 };
00073
00074 Q_DECLARE_SHARED_DATA (Data);
00075
00076 private:
00078 static const QString name_;
00079 };
00080
00082
00086 template <PacketType type>
00087 QString PeerInfoPacket <type>::name() const
00088 {
00089 return name_;
00090 }
00091
00093 template <PacketType type>
00094 PeerInfoPacket<type>* PeerInfoPacket <type>::copy() const
00095 {
00096 return new PeerInfoPacket (*this);
00097 }
00098
00100
00105 template <PacketType type>
00106 PeerInfoPacket <type>::PeerInfoPacket()
00107 : Packet (new Data, type)
00108 {
00109 }
00110
00112
00118 template <PacketType type>
00119 void PeerInfoPacket <type>::readPayload (BinaryReader &reader)
00120 {
00121 Q_SD (Data);
00122
00123
00124 d->id.readFromBinaryReader (reader);
00125 d->ip = reader.readUInt32();
00126 d->udpPort = reader.readUInt16();
00127 d->tcpPort = reader.readUInt16();
00128 d->notUsed = static_cast <quint8> (reader.readByte());
00129 }
00130
00132 template <PacketType type>
00133 void PeerInfoPacket <type>::writePayload (BinaryWriter &writer) const
00134 {
00135 Q_SD (const Data);
00136 writer.reserve (PayloadLength);
00137
00138 d->id.writeToBinaryWriter (writer);
00139 writer.writeUInt32 (d->ip);
00140 writer.writeUInt16 (d->udpPort);
00141 writer.writeUInt16 (d->tcpPort);
00142 writer.writeByte (static_cast <uchar> (d->notUsed));
00143 }
00144
00145 }
00146 }
00147 }
00148
00149 #endif // PROTOCOLS__KAD__PACKETS__PEER_INFO_PACKET_H