Gnutella::Packets::QueryHits Class Reference

#include <QueryHits.h> [code]

Inherits Gnutella::Packets::Packet.

Inheritance diagram for Gnutella::Packets::QueryHits:

Inheritance graph
[legend]
Collaboration diagram for Gnutella::Packets::QueryHits:

Collaboration graph
[legend]
List of all members.

Detailed Description

Encapsulates the QueryHits Gnutella packet.

The table below presents the data fields stored in a query hits' payload and how they can be accessed using the QueryHits interface. For a detailed documentation of all basic Gnutella packets and the usage of all their fileds please refer to The Annotated Gnutella Protocol Specification v0.4.

Byte Offset Field Name getFunction setFunction
0 # of Hits N/A N/A
1..2 Port N/A N/A
3..6 IP Address N/A N/A
7..10 Speed N/A N/A
11..10+N Result Set N/A N/A
11+N..L-17 Optional QueryHits DataN/A N/A
L-16..L-1 Servent ID N/A N/A

The speed field may contain a number of flags as described in the table below. If bit 15 is set to 1, then the flags are set as by the specification. If it is not set, then the field contains just the maximum upload speed.

Bit Flag Name getFunction setFunction
15 Enable flags N/A N/A
14 Firewalled Indicator N/A N/A
13 XML Metadata N/A N/A
12 Leaf-Guided Dynamic Query N/A N/A
11 GGEP "H" Allowed N/A N/A
10 Out of Band Query N/A N/A

Use the function xxx() to access the results from the result set. Each result entry has the structure below:

Byte Offset Field Name getFunction setFunction
0..3 File Index N/A N/A
4..7 File Size N/A N/A
8..7+K Shared File Name N/A N/A
8+K NUL (0x00) Terminator N/A N/A
9+K..R-2 Optional Result Data N/A N/A
R-1 NUL (0x00) Terminator N/A N/A

The optional QueryHits data field has the following structure:

Byte Offset Field Name getFunction setFunction
0..3 Vendor Code N/A N/A
4 Open area size N/A N/A
5 "Knows" flags byte N/A N/A
6 "Sets" flags byte N/A N/A
7..8 XML size + 1 N/A N/A
9 Private Vendor Flag N/A N/A
10..P-1 GGEP block N/A N/A
P..K-1 XML data + NULL N/A N/A

If the open area size is exactly equal to two, then only the two flag bytes are there. The XML size field should not be read out. The GGEP block will be there only if the corresponding bits in the flags bytes are set.

The tables below describe the meaning of each bit in the two flag bytes. The first byte marks which flags are recognized, whereas the second marks whether the corresponding flag is set or not. The Push flag is an exception to this rule - secong byte's bit determines whether the first byte's bit is meaningful.

Bit Flag Name getFunction setFunction
7 Reserved N/A N/A
6 Reserved N/A N/A
5 GGEP Block in QueryHits Data N/A N/A
4 Speed is Average Upload Speed N/A N/A
3 Have Uploaded N/A N/A
2 Busy N/A N/A
1 Reserved N/A N/A
0 Push N/A N/A

Todo:
Add functions to modify the speed flags.

Implement the query hits data extension.

Substitute Result::fileName with QFileInfo. It provides functions to get the extension, path, etc.

Add setter functions.

Forbid changing the result entries. Payload would need to be invalidated.

Definition at line 126 of file QueryHits.h.

Public Types

typedef Extensions::ExtensionBlock ResultData

Public Member Functions

 QueryHits (const QByteArray &rawHeader, const QByteArray &rawPayload)
 QueryHits ()
 ~QueryHits ()
QueryHitscopy () const
 A virtual copy contructor.
QString name () const
uchar numberOfHits () const
quint16 port () const
QHostAddress ipAddress () const
quint32 speed () const
const Resultresult (int &index) const
const QUuid & serventId () const
 Gets the servent ID payload field.
void setPort (quint16 port)
void setIpAddress (const QHostAddress &ipAddress)
void setSpeed (quint32 speed)
void setServentId (const QUuid &serventId)
void appendResult (Result &result)

Static Public Member Functions

static QueryHitscastFrom (Packet &packet)
static const QueryHitscastFrom (const Packet &packet)

Protected Member Functions

bool prepareReadPayload (const QByteArray &rawPayload)
 Verifies the structure of the rawPayload.
bool prepareReadQueryHitsData (const QByteArray &rawQueryHitsData)
void readPayload (QDataStream &stream)
 Reads the payload fields from the stream. The structure of the data in the stream is already verified by verifyPayload().
void readQueryHitsData (QDataStream &stream)
int prepareWritePayload () const
 Gets ready to write the payload and returns the payload length.
int prepareWriteQueryHitsData () const
void writePayload (QDataStream &stream) const
 Writes the payload fields into the stream.
void writeQueryHitsData (QDataStream &stream) const

Private Types

typedef QList< ResultResultSet

Private Attributes

Gnutella::Packets::QueryHits::Data p

Classes

struct  Data
struct  QueryHitsData
struct  Result


Member Typedef Documentation

typedef Extensions::ExtensionBlock Gnutella::Packets::QueryHits::ResultData
 

Definition at line 129 of file QueryHits.h.

typedef QList<Result> Gnutella::Packets::QueryHits::ResultSet [private]
 

Definition at line 202 of file QueryHits.h.


Constructor & Destructor Documentation

QueryHits::QueryHits const QByteArray &  rawHeader,
const QByteArray &  rawPayload
 

Creates a QueryHits object from the raw bytes in rawHeader and rawPayload.

Definition at line 42 of file QueryHits.cpp.

QueryHits::QueryHits  ) 
 

Definition at line 48 of file QueryHits.cpp.

QueryHits::~QueryHits  ) 
 

Definition at line 57 of file QueryHits.cpp.


Member Function Documentation

void QueryHits::appendResult Result result  ) 
 

Definition at line 379 of file QueryHits.cpp.

static const QueryHits& Gnutella::Packets::QueryHits::castFrom const Packet packet  )  [inline, static]
 

Definition at line 149 of file QueryHits.h.

static QueryHits& Gnutella::Packets::QueryHits::castFrom Packet packet  )  [inline, static]
 

Definition at line 148 of file QueryHits.h.

QueryHits* Gnutella::Packets::QueryHits::copy  )  const [inline, virtual]
 

A virtual copy contructor.

Implements Gnutella::Packets::Packet.

Definition at line 155 of file QueryHits.h.

QHostAddress Gnutella::Packets::QueryHits::ipAddress  )  const [inline]
 

Definition at line 162 of file QueryHits.h.

QString Gnutella::Packets::QueryHits::name  )  const [inline, virtual]
 

Todo:
remove this?

Implements Gnutella::Packets::Packet.

Definition at line 157 of file QueryHits.h.

uchar Gnutella::Packets::QueryHits::numberOfHits  )  const [inline]
 

Definition at line 160 of file QueryHits.h.

quint16 Gnutella::Packets::QueryHits::port  )  const [inline]
 

Definition at line 161 of file QueryHits.h.

bool QueryHits::prepareReadPayload const QByteArray &  rawPayload  )  [protected, virtual]
 

Verifies the structure of the rawPayload.

Verifies if the rawPayload can be correctly parsed by readPayload(). The function just goes over the whole rawPayload and checks if the structure of the payload is correct. Some data may be gathered and stored to ease the work of readPayload(). For example, the size of the query hit data field can only be calculated with knowledge of the payloadLength, which is not available in the QDataStream object passed to readPayload(). The size of this field is read here and stored for use later in readPayload().

Implements Gnutella::Packets::Packet.

Definition at line 72 of file QueryHits.cpp.

bool QueryHits::prepareReadQueryHitsData const QByteArray &  rawQueryHitsData  )  [protected]
 

Definition at line 181 of file QueryHits.cpp.

int QueryHits::prepareWritePayload  )  const [protected, virtual]
 

Gets ready to write the payload and returns the payload length.

Implements Gnutella::Packets::Packet.

Definition at line 139 of file QueryHits.cpp.

int QueryHits::prepareWriteQueryHitsData  )  const [protected]
 

Definition at line 255 of file QueryHits.cpp.

void QueryHits::readPayload QDataStream &  stream  )  [protected, virtual]
 

Reads the payload fields from the stream. The structure of the data in the stream is already verified by verifyPayload().

Implements Gnutella::Packets::Packet.

Definition at line 110 of file QueryHits.cpp.

void QueryHits::readQueryHitsData QDataStream &  stream  )  [protected]
 

Definition at line 224 of file QueryHits.cpp.

const QueryHits::Result & QueryHits::result int &  index  )  const
 

Definition at line 316 of file QueryHits.cpp.

const QUuid& Gnutella::Packets::QueryHits::serventId  )  const [inline]
 

Gets the servent ID payload field.

Definition at line 166 of file QueryHits.h.

void QueryHits::setIpAddress const QHostAddress &  ipAddress  ) 
 

Definition at line 355 of file QueryHits.cpp.

void QueryHits::setPort quint16  port  ) 
 

Definition at line 349 of file QueryHits.cpp.

void QueryHits::setServentId const QUuid &  serventId  ) 
 

Definition at line 367 of file QueryHits.cpp.

void QueryHits::setSpeed quint32  speed  ) 
 

Definition at line 361 of file QueryHits.cpp.

quint32 Gnutella::Packets::QueryHits::speed  )  const [inline]
 

Definition at line 163 of file QueryHits.h.

void QueryHits::writePayload QDataStream &  stream  )  const [protected, virtual]
 

Writes the payload fields into the stream.

Implements Gnutella::Packets::Packet.

Definition at line 159 of file QueryHits.cpp.

void QueryHits::writeQueryHitsData QDataStream &  stream  )  const [protected]
 

Definition at line 286 of file QueryHits.cpp.


Member Data Documentation

struct Gnutella::Packets::QueryHits::Data Gnutella::Packets::QueryHits::p [private]
 


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