Protocols::BitTorrent::Trackers::PeerInfo Class Reference

#include <PeerInfo.h> [code]

Collaboration diagram for Protocols::BitTorrent::Trackers::PeerInfo:

Collaboration graph
[legend]
List of all members.

Detailed Description

Represents peer info (peer ID, IP address/DNS name and port).

Provides value semantics (objects copying is allowed).

It does not throw its own exceptions and lets any thrown exceptions through to the user. In case an exception (e.g. bad_alloc) gets thrown, the TrackerRequest object will be left in an unchanged state. Thus the class meets the strong guarantee of exception safety.

Todo:
Move this module out of the Trackers package? It will be used also in transfers so maybe we should move it somewhere else.

Definition at line 45 of file PeerInfo.h.

Public Types

typedef FixedSizeByteArray< 20 > PeerId
 Peer ID - used as a unique ID for the client (20B long).

Public Member Functions

 PeerInfo (const PeerInfo &)
 Copy constructor.
PeerInfooperator= (const PeerInfo &)
 Assignment operator.
bool operator== (const PeerInfo &) const
 Equality comparison.
bool operator!= (const PeerInfo &) const
 Inequality comparison.
 PeerInfo ()
 Default constructor.
 PeerInfo (const QByteArray &host, uint port, const PeerId &peerId)
 Constructor.
 ~PeerInfo ()
 Destructor.
PeerId peerId () const
QByteArray host () const
uint port () const
void setPeerId (PeerId peerId)
 Sets the peer ID.
void setHost (QByteArray host)
 Sets the host.
void setPort (uint port)
 Sets the port.
Uri toUri () const

Static Public Member Functions

static PeerInfo fromUri (const Uri &peerInfo)
 Named ctor for creating a PeerInfo object from URI object.

Private Attributes

Uri peerInfo

Static Private Attributes

static const char * PeerSchemeName = "bt-peer"
 BitPeerInfo peer scheme name.
static const char * PeerIdQueryItemKeyName = "id"
 Name of the peer ID query item key in the PeerInfo query part.
static const char * PeerNullPort = "0"
 Peer port default value.
static const char * PeerNullHost = "0.0.0.0"
 Peer host default value.


Member Typedef Documentation

typedef FixedSizeByteArray<20> Protocols::BitTorrent::Trackers::PeerInfo::PeerId
 

Peer ID - used as a unique ID for the client (20B long).

Definition at line 52 of file PeerInfo.h.


Constructor & Destructor Documentation

PeerInfo::PeerInfo const PeerInfo other  ) 
 

Copy constructor.

Parameters:
other Object that will be used as a model in the object creation.
Constructs a copy of the other object.

Definition at line 75 of file PeerInfo.cpp.

PeerInfo::PeerInfo  ) 
 

Default constructor.

Creates and initializes an empty PeerInfo object. It will have host set to "0.0.0.0", port will be set to zero and peer ID to 20B long array of zero bytes.

Definition at line 33 of file PeerInfo.cpp.

PeerInfo::PeerInfo const QByteArray &  host,
uint  port,
const PeerId peerId
 

Constructor.

Parameters:
host Peer host (address or DNS name).
port Peer port number.
peerId Peer ID.
Precondition:
host must not be empty.
Creates and initializes an PeerInfo object from the selected arguments.

Definition at line 51 of file PeerInfo.cpp.

PeerInfo::~PeerInfo  ) 
 

Destructor.

Destroys a PeerInfo object.

Definition at line 65 of file PeerInfo.cpp.


Member Function Documentation

PeerInfo::PeerInfo PeerInfo::fromUri const Uri peerInfo  )  [static]
 

Named ctor for creating a PeerInfo object from URI object.

Parameters:
peerInfo Peer info in a URI format.
Returns:
PeerInfo object created and initialized from the peerInfo URI.
Precondition:
peerInfo URI must have at least valid scheme ("bt-peer") specified and must be in the following format: bt-peer://host:port?id=peerId
Note:
If some part of the URI is missing, default values will be set. See PeerInfo() ctor for more info about default values. Extra fields (like user info) will be ignored.
See also:
toUri()

Definition at line 196 of file PeerInfo.cpp.

QByteArray PeerInfo::host  )  const
 

Returns:
Peer host (address or DNS name).

Definition at line 122 of file PeerInfo.cpp.

bool PeerInfo::operator!= const PeerInfo other  )  const
 

Inequality comparison.

Returns:
true if this object is not equal to the other object.

false otherwise.

Definition at line 109 of file PeerInfo.cpp.

PeerInfo & PeerInfo::operator= const PeerInfo other  ) 
 

Assignment operator.

Parameters:
other Object that will be assigned to this object.
Returns:
Reference to this object.

Definition at line 85 of file PeerInfo.cpp.

bool PeerInfo::operator== const PeerInfo other  )  const
 

Equality comparison.

Returns:
true if this object is equal to the other object.

false otherwise.

Definition at line 96 of file PeerInfo.cpp.

PeerInfo::PeerId PeerInfo::peerId  )  const
 

Returns:
Peer ID.

Definition at line 115 of file PeerInfo.cpp.

uint PeerInfo::port  )  const
 

Returns:
Peer port.

Definition at line 128 of file PeerInfo.cpp.

void PeerInfo::setHost QByteArray  host  ) 
 

Sets the host.

Parameters:
host Host (address or DNS name) to be set.
Precondition:
host must not be empty.

Definition at line 152 of file PeerInfo.cpp.

void PeerInfo::setPeerId PeerId  peerId  ) 
 

Sets the peer ID.

Parameters:
peerId New peer ID to be set.

Definition at line 137 of file PeerInfo.cpp.

void PeerInfo::setPort uint  port  ) 
 

Sets the port.

Parameters:
port Port number to be set.

Definition at line 162 of file PeerInfo.cpp.

Uri PeerInfo::toUri  )  const
 

The URI will be in the following format: bt-peer://host:port?id=peerId

See also:
fromUri()

Definition at line 176 of file PeerInfo.cpp.


Member Data Documentation

const char * PeerInfo::PeerIdQueryItemKeyName = "id" [static, private]
 

Name of the peer ID query item key in the PeerInfo query part.

Definition at line 76 of file PeerInfo.h.

Uri Protocols::BitTorrent::Trackers::PeerInfo::peerInfo [private]
 

Definition at line 73 of file PeerInfo.h.

const char * PeerInfo::PeerNullHost = "0.0.0.0" [static, private]
 

Peer host default value.

Definition at line 78 of file PeerInfo.h.

const char * PeerInfo::PeerNullPort = "0" [static, private]
 

Peer port default value.

Definition at line 77 of file PeerInfo.h.

const char * PeerInfo::PeerSchemeName = "bt-peer" [static, private]
 

BitPeerInfo peer scheme name.

Note:
This scheme name is not registered and it's only for internal usage.

Definition at line 75 of file PeerInfo.h.


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