CreditsDb Class Reference

CreditsDb class stores and maintains ClientCredits type objects, which represent eDonkey2000 client credits. More...

#include <creditsdb.h>

List of all members.


Public Member Functions

void initCrypting ()
 Initializes public/private RSA keypair either by loading it from file, or creating new one if needed.
void load (const std::string &file)
 Load the contents from file, adding all entries found there to list.
void save (const std::string &file) const
 Save the contents to file.
PublicKey getPublicKey () const
Creditsfind (const PublicKey &key) const
 Find credits, looking with PublicKey.
Creditsfind (const Hash< MD4Hash > &hash) const
 Find credits, looking with userhash.
Creditscreate (PublicKey key, const Hash< MD4Hash > &hash)
 Create credits entry for specified publickey/hash.

Static Public Member Functions

static CreditsDbinstance ()
 Singleton, lazy instanciating.
static std::string createSignature (PublicKey key, uint32_t challenge, IpType ipType, uint32_t ip)
 Creates a signature to be sent to client owning target credits.
static bool verifySignature (PublicKey key, uint32_t challenge, const std::string &sign, IpType ipType, uint32_t ip)
 Attempts to verify signature against public key stored here.

Private Member Functions

 CreditsDb ()
 Singleton.
 ~CreditsDb ()
 Singleton.
 CreditsDb (const CreditsDb &)
 No copying allowed.
const CreditsDboperator= (const CreditsDb &)
 No copying allowed.
void loadCryptKey (const std::string &where)
 Loads private RSA key from file, and calculates public RSA key from it.
void createCryptKey (const std::string &where)
 Creates new public/private RSA keypair, and saves it to file.

Private Attributes

PublicKey m_pubKey
 Public RSA key.
boost::scoped_ptr< Detail::CreditsListm_list

Detailed Description

CreditsDb class stores and maintains ClientCredits type objects, which represent eDonkey2000 client credits.

Actually, what this means is we store the clients userhash and public key, and keep track of how much we have sent data to the client, and how much we have received back. All of this forms the base for eMule extended protocol feature, which rewards uploaders based on their credits. More on that in UploadQueue-related classes. Note that not all clients connecting to eDonkey2000 network support credits, and thus only clients giving back credits should be rewarded here. At the point of this writing (15/10/2004), only eMule-derived clients, plus ShareAza fully support this system as far as I know.

CreditsDb stores its contents at config/ed2k/clients.met between sessions. The file format conforms to eMule's respective file format.

This class is a Singleton, the only instance of this class may be retrieved through instance() member function.

Definition at line 108 of file creditsdb.h.


Constructor & Destructor Documentation

CreditsDb::CreditsDb  )  [private]
 

Singleton.

Definition at line 136 of file creditsdb.cpp.

Referenced by instance().

CreditsDb::~CreditsDb  )  [private]
 

Singleton.

Definition at line 137 of file creditsdb.cpp.

CreditsDb::CreditsDb const CreditsDb  )  [private]
 

No copying allowed.


Member Function Documentation

static CreditsDb& CreditsDb::instance  )  [inline, static]
 

Singleton, lazy instanciating.

Definition at line 111 of file creditsdb.h.

References CreditsDb().

Referenced by ED2K::onExit(), ED2K::onInit(), Client::onPacket(), Client::sendNextChunk(), and verifySignature().

void CreditsDb::initCrypting  ) 
 

Initializes public/private RSA keypair either by loading it from file, or creating new one if needed.

Definition at line 206 of file creditsdb.cpp.

References createCryptKey(), and loadCryptKey().

Referenced by ED2K::onInit().

void CreditsDb::load const std::string &  file  ) 
 

Load the contents from file, adding all entries found there to list.

Parameters:
file File to read data from
Exceptions:
std::runtime_error if parsing fails

Definition at line 139 of file creditsdb.cpp.

References CM_VER, CM_VER29, and m_list.

Referenced by ED2K::onInit().

void CreditsDb::save const std::string &  file  )  const
 

Save the contents to file.

Parameters:
file File to write to

Definition at line 172 of file creditsdb.cpp.

References CM_VER29.

Referenced by ED2K::onExit().

PublicKey CreditsDb::getPublicKey  )  const [inline]
 

Returns:
Own public key

Definition at line 141 of file creditsdb.h.

References m_pubKey.

Credits * CreditsDb::find const PublicKey key  )  const
 

Find credits, looking with PublicKey.

Parameters:
key Client's PublicKey to search for
Returns:
Pointer to Credits object corresponding to
Parameters:
key,or 0 if not found.

Definition at line 194 of file creditsdb.cpp.

References Detail::ID_PubKey, and m_list.

Referenced by Client::onPacket().

Credits * CreditsDb::find const Hash< MD4Hash > &  hash  )  const
 

Find credits, looking with userhash.

Parameters:
hash Client's userhash
Returns:
Pointer to Credits object corresponding to
Parameters:
hash,or 0 if not found.
Note:
Usage of this function is discouraged, due to hash-stealers.

Definition at line 200 of file creditsdb.cpp.

References Detail::ID_Hash, and m_list.

Credits * CreditsDb::create PublicKey  key,
const Hash< MD4Hash > &  hash
 

Create credits entry for specified publickey/hash.

Definition at line 320 of file creditsdb.cpp.

References Detail::ID_PubKey, and m_list.

Referenced by Client::onPacket(), and Client::sendNextChunk().

std::string CreditsDb::createSignature PublicKey  key,
uint32_t  challenge,
IpType  ipType,
uint32_t  ip
[static]
 

Creates a signature to be sent to client owning target credits.

Parameters:
key Remote client's public key
callenge Challenge value
ipType Type of IP (if any) to include
ip The ip to be included (if any)
Returns:
Signature to be sent back to client

Definition at line 263 of file creditsdb.cpp.

References PublicKey::c_str(), s_signer, and PublicKey::size().

bool CreditsDb::verifySignature PublicKey  key,
uint32_t  challenge,
const std::string &  sign,
IpType  ipType,
uint32_t  ip
[static]
 

Attempts to verify signature against public key stored here.

Parameters:
key Remote client's public key
challenge Challenge value sent to this client previously
sign The signature the remote client sent back
ipType Type of IP included in the signature (if any)
ip IP address included in the signature (if any)
Returns:
True if verification succeeds, false otherwise

Definition at line 293 of file creditsdb.cpp.

References PublicKey::c_str(), instance(), m_pubKey, and PublicKey::size().

Referenced by Client::onPacket().

const CreditsDb& CreditsDb::operator= const CreditsDb  )  [private]
 

No copying allowed.

void CreditsDb::loadCryptKey const std::string &  where  )  [private]
 

Loads private RSA key from file, and calculates public RSA key from it.

Parameters:
where File to read private key from.

Definition at line 226 of file creditsdb.cpp.

References m_pubKey, s_signer, and s_verifier.

Referenced by initCrypting().

void CreditsDb::createCryptKey const std::string &  where  )  [private]
 

Creates new public/private RSA keypair, and saves it to file.

Parameters:
where File to write private key to.

Definition at line 246 of file creditsdb.cpp.

Referenced by initCrypting().


Member Data Documentation

PublicKey CreditsDb::m_pubKey [private]
 

Public RSA key.

Definition at line 217 of file creditsdb.h.

Referenced by getPublicKey(), loadCryptKey(), and verifySignature().

boost::scoped_ptr<Detail::CreditsList> CreditsDb::m_list [private]
 

Definition at line 219 of file creditsdb.h.

Referenced by create(), find(), and load().


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