libktorrent  2.2.0
Public Member Functions | List of all members
dht::Database Class Reference

#include <database.h>

Public Member Functions

bool checkToken (const QByteArray &token, const net::Address &addr)
 
bool contains (const dht::Key &key) const
 Test whether or not the DB contains a key.
 
void expire (bt::TimeStamp now)
 
QByteArray genToken (const net::Address &addr)
 
void insert (const dht::Key &key)
 Insert an empty item (only if it isn't already in the DB)
 
void sample (const dht::Key &key, DBItemList &dbl, bt::Uint32 max_entries, bt::Uint32 ip_version)
 
void store (const dht::Key &key, const DBItem &dbi)
 

Detailed Description

Author
Joris Guisson

Class where all the key value paires get stored.

Definition at line 96 of file database.h.

Member Function Documentation

◆ checkToken()

bool dht::Database::checkToken ( const QByteArray &  token,
const net::Address addr 
)

Check if a received token is OK.

Parameters
tokenThe token received
addrThe address of the peer
Returns
true if the token was given to this peer, false other wise

◆ expire()

void dht::Database::expire ( bt::TimeStamp  now)

Expire all items older then 30 minutes

Parameters
nowThe time it is now (we pass this along so we only have to calculate it once)

◆ genToken()

QByteArray dht::Database::genToken ( const net::Address addr)

Generate a write token, which will give peers write access to the DB.

Parameters
addrThe address of the peer
Returns
A QByteArray

◆ sample()

void dht::Database::sample ( const dht::Key key,
DBItemList &  dbl,
bt::Uint32  max_entries,
bt::Uint32  ip_version 
)

Get max_entries items from the database, which have the same key, items are taken randomly from the list. If the key is not present no items will be returned, if there are fewer then max_entries items for the key, all entries will be returned

Parameters
keyThe key to search for
dblThe list to store the items in
max_entriesThe maximum number entries
ip_versionWanted IP version (4 or 6)

◆ store()

void dht::Database::store ( const dht::Key key,
const DBItem dbi 
)

Store an entry in the database

Parameters
keyThe key
dbiThe DBItem to store

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