Protocols::Gnutella::Packets::PacketBase Class Reference

#include <PacketBase.h> [code]

Inherits Protocols::Generics::PacketBase.

Inherited by Protocols::Gnutella::Packets::Ping, Protocols::Gnutella::Packets::Pong, Protocols::Gnutella::Packets::Push, Protocols::Gnutella::Packets::Query, and Protocols::Gnutella::Packets::QueryHits.

Inheritance diagram for Protocols::Gnutella::Packets::PacketBase:

Inheritance graph
[legend]
Collaboration diagram for Protocols::Gnutella::Packets::PacketBase:

Collaboration graph
[legend]
List of all members.

Detailed Description

Base class for all Gnutella packets.

A typical Gnutella packet consists of two parts: header and payload. All packet types share the same header structure but have different payload structure. The table below presents the data fields stored in a header and how they can be accessed using the PacketBase interface. For a detailed documentation of all basic Gnutella packets and the usage of all their fileds please refer to:

http://gnutella-specs.rakjar.de/index.php/Standard_Message_Architecture.

PacketBase class is an abstract class that defines a common interface for all Gnutella packets.The functions rawHeader() and rawPayload() can be used to get the packet as raw bytes ready for transmission.

If you derive from PacketBase, make sure you provide implementation for readPayload() and writePayload().

See also:
PingPacket, PongPacket, QueryPacket, QueryHitsPacket, PushPacket, QueryRoutingPatch, QueryRoutingReset, VendorMessages.

Definition at line 103 of file PacketBase.h.

Public Member Functions

virtual QString protocol () const
 Returns the string "Gnutella".
virtual QString name () const =0
 Returns the name of the PacketBase type the dynamic object belongs to.
virtual auto_ptr< DataBasecopy () const =0
 Virtual copy constructor.
const QUuid & descriptorId () const
 Gets the value of the descriptor ID header field.
void setDescriptorId (const QUuid &descriptorId)
 Sets the value of the descriptror ID header field.
PacketType packetType () const
 Gets the payload desctiptor header field.
uchar ttl () const
 Gets the value of the TTL header field.
void setTtl (uchar ttl)
 Sets the value of the TTL header field.
uchar hops () const
 Gets the value of the hops header field.
void setHops (uchar hops)
 Gets the value of the hops header field.
void doHop ()
 Increments hops and decrements ttl by one.

Protected Member Functions

 PacketBase (Data *d, PacketType packetType)
 Constructs a PacketBase object.
virtual bool readHeader (const QByteArray &rawHeader)
 Reads the header fields from raw data.
virtual bool readPayload (const QByteArray &rawPayload)
 Reads the payload fields from raw bytes.
virtual QByteArray writeHeader () const
 Writes the packet header fields and returns the raw bytes.
virtual QByteArray writePayload () const
 Returns the raw bytes representation of the payload fields.
virtual void readPayload (BinaryReader &)=0
 Reads the payload fields from binaryReader.
virtual void writePayload (BinaryWriter &) const =0

Private Member Functions

 Q_DECLARE_SHARED_DATA (Data)

Classes

class  Data


Constructor & Destructor Documentation

PacketBase::PacketBase Data dd,
PacketType  packetType
[protected]
 

Constructs a PacketBase object.

Parameters:
dd is the pointer to the derived class's private data struct, which must be derived from Data.
packetType is the PacketType corresponding to the derived class that calls this ctor. The corresponding header field is set.
Note:
Make sure packetType matches the packet type you are implementing in the derived class.

Definition at line 43 of file PacketBase.cpp.


Member Function Documentation

virtual auto_ptr<DataBase> Protocols::Gnutella::Packets::PacketBase::copy  )  const [pure virtual]
 

Virtual copy constructor.

Implements Protocols::Generics::PacketBase.

Implemented in Protocols::Gnutella::Packets::Ping, Protocols::Gnutella::Packets::Pong, Protocols::Gnutella::Packets::Push, Protocols::Gnutella::Packets::Query, and Protocols::Gnutella::Packets::QueryHits.

const QUuid & Protocols::Gnutella::Packets::PacketBase::descriptorId  )  const [inline]
 

Gets the value of the descriptor ID header field.

Definition at line 162 of file PacketBase.h.

void Protocols::Gnutella::Packets::PacketBase::doHop  )  [inline]
 

Increments hops and decrements ttl by one.

Definition at line 190 of file PacketBase.h.

uchar Protocols::Gnutella::Packets::PacketBase::hops  )  const [inline]
 

Gets the value of the hops header field.

Definition at line 182 of file PacketBase.h.

virtual QString Protocols::Gnutella::Packets::PacketBase::name  )  const [pure virtual]
 

Returns the name of the PacketBase type the dynamic object belongs to.

Todo:
Better use PacketId (which possibly contains the ProtocolId)?

Implements Protocols::Generics::PacketBase.

Implemented in Protocols::Gnutella::Packets::Ping, Protocols::Gnutella::Packets::Pong, Protocols::Gnutella::Packets::Push, Protocols::Gnutella::Packets::Query, and Protocols::Gnutella::Packets::QueryHits.

PacketType Protocols::Gnutella::Packets::PacketBase::packetType  )  const [inline]
 

Gets the payload desctiptor header field.

Definition at line 170 of file PacketBase.h.

QString PacketBase::protocol  )  const [virtual]
 

Returns the string "Gnutella".

Implements Protocols::Generics::PacketBase.

Definition at line 28 of file PacketBase.cpp.

Protocols::Gnutella::Packets::PacketBase::Q_DECLARE_SHARED_DATA Data   )  [private]
 

bool PacketBase::readHeader const QByteArray &  rawHeader  )  [protected, virtual]
 

Reads the header fields from raw data.

Parameters:
rawHeader is the raw header buffer from which to parse the header fields.
Returns:
true if the format of the header was correct and the fields were parsed.

false otherwise.

Note:
The header fields could have changed even if the function returns false.

Implements Protocols::Generics::PacketBase.

Definition at line 65 of file PacketBase.cpp.

void PacketBase::readPayload BinaryReader binaryReader  )  [protected, pure virtual]
 

Reads the payload fields from binaryReader.

Parameters:
binaryReader is the BinaryReader object from which to read the payload fields.
Note:
This function is called by the implementation of bool PacketBase::readPayload (const QByteArray &). You could chose to implement either of them.

Implemented in Protocols::Gnutella::Packets::Ping, Protocols::Gnutella::Packets::Pong, Protocols::Gnutella::Packets::Push, Protocols::Gnutella::Packets::Query, and Protocols::Gnutella::Packets::QueryHits.

bool PacketBase::readPayload const QByteArray &  rawPayload  )  [protected, virtual]
 

Reads the payload fields from raw bytes.

Parameters:
rawPayload are the raw payload bytes to parse.
Returns:
true if the payload could be correctly parsed and all read fields were set.

false otherwise.

A derived class can either choose to override this function or override PacketBase::readPayload (BinaryReader& ), which makes parsing using the BinaryReader object much easier.

Note:
Some or all payload fields may have changed even if parsing failed and the function returned false.

Implements Protocols::Generics::PacketBase.

Definition at line 110 of file PacketBase.cpp.

void Protocols::Gnutella::Packets::PacketBase::setDescriptorId const QUuid &  descriptorId  )  [inline]
 

Sets the value of the descriptror ID header field.

Definition at line 166 of file PacketBase.h.

void Protocols::Gnutella::Packets::PacketBase::setHops uchar  hops  )  [inline]
 

Gets the value of the hops header field.

Definition at line 186 of file PacketBase.h.

void Protocols::Gnutella::Packets::PacketBase::setTtl uchar  ttl  )  [inline]
 

Sets the value of the TTL header field.

Definition at line 178 of file PacketBase.h.

uchar Protocols::Gnutella::Packets::PacketBase::ttl  )  const [inline]
 

Gets the value of the TTL header field.

Definition at line 174 of file PacketBase.h.

QByteArray PacketBase::writeHeader  )  const [protected, virtual]
 

Writes the packet header fields and returns the raw bytes.

Implements Protocols::Generics::PacketBase.

Definition at line 81 of file PacketBase.cpp.

virtual void Protocols::Gnutella::Packets::PacketBase::writePayload BinaryWriter  )  const [protected, pure virtual]
 

Implemented in Protocols::Gnutella::Packets::Ping, Protocols::Gnutella::Packets::Pong, Protocols::Gnutella::Packets::Push, Protocols::Gnutella::Packets::Query, and Protocols::Gnutella::Packets::QueryHits.

QByteArray PacketBase::writePayload  )  const [protected, virtual]
 

Returns the raw bytes representation of the payload fields.

Returns:
A byte array containing the raw bytes representation of the packet's payload.
Note:
A derived class can either choose to override this function or override PacketBase::writePayload (BinaryWriter &), which wakes writing fields into a QByteArray buffer much easier.

Implements Protocols::Generics::PacketBase.

Definition at line 137 of file PacketBase.cpp.


The documentation for this class was generated from the following files: