libktorrent  2.2.0
Public Member Functions | Static Public Member Functions | Friends | List of all members
dht::Key Class Reference

Key in the distributed hash table. More...

#include <key.h>

Inheritance diagram for dht::Key:
Inheritance graph
[legend]

Public Member Functions

 Key ()
 
 Key (const bt::SHA1Hash &k)
 
 Key (const bt::Uint8 *d)
 
 Key (const QByteArray &ba)
 
 ~Key () override
 Destructor.
 
bool operator!= (const Key &other) const
 
Key operator/ (int value) const
 
bool operator< (const Key &other) const
 
bool operator<= (const Key &other) const
 
bool operator== (const Key &other) const
 
bool operator> (const Key &other) const
 
bool operator>= (const Key &other) const
 
- Public Member Functions inherited from bt::SHA1Hash
 SHA1Hash ()
 
 SHA1Hash (const SHA1Hash &other)
 
 SHA1Hash (const Uint8 *h)
 
virtual ~SHA1Hash ()
 
const Uint8 * getData () const
 
bool operator!= (const SHA1Hash &other) const
 
SHA1Hashoperator= (const SHA1Hash &other)
 
bool operator== (const SHA1Hash &other) const
 
Uint8 operator[] (const Uint32 idx) const
 Get the idx'th byte of the hash.
 
QByteArray toByteArray () const
 
QString toString () const
 
QString toURLString () const
 

Static Public Member Functions

static Key distance (const Key &a, const Key &b)
 
static Key max ()
 Get the maximum key (all FF)
 
static Key mid (const Key &a, const Key &b)
 
static Key min ()
 Get the minimum key (all zeros)
 
static Key random ()
 
- Static Public Member Functions inherited from bt::SHA1Hash
static SHA1Hash generate (const Uint8 *data, Uint32 len)
 

Friends

KTORRENT_EXPORT Key operator+ (const Key &a, bt::Uint8 value)
 
KTORRENT_EXPORT Key operator+ (const Key &a, const Key &b)
 
KTORRENT_EXPORT Key operator- (const Key &a, const Key &b)
 

Additional Inherited Members

- Protected Attributes inherited from bt::SHA1Hash
Uint8 hash [20]
 

Detailed Description

Author
Joris Guisson Key's in the distributed hash table are just SHA-1 hashes. Key provides all necesarry operators to be used as a value.

Definition at line 56 of file key.h.

Constructor & Destructor Documentation

◆ Key() [1/4]

dht::Key::Key ( )

Constructor, sets key to 0.

◆ Key() [2/4]

dht::Key::Key ( const bt::SHA1Hash k)

Copy constructor. Seeing that Key doesn't add any data we just pass a SHA1Hash, Key's are automatically covered by this

Parameters
kHash to copy

◆ Key() [3/4]

dht::Key::Key ( const QByteArray &  ba)

Make a key out of a bytearray

Parameters
baThe QByteArray

◆ Key() [4/4]

dht::Key::Key ( const bt::Uint8 *  d)

Make a key out of a 20 byte array.

Parameters
dThe array

Member Function Documentation

◆ distance()

static Key dht::Key::distance ( const Key a,
const Key b 
)
static

The distance of two keys is the keys xor together.

Parameters
aThe first key
bThe second key
Returns
a xor b

◆ mid()

static Key dht::Key::mid ( const Key a,
const Key b 
)
static

Calculate the middle between two keys.

Parameters
aThe first key
bThe second key
Returns
The middle

◆ operator!=()

bool dht::Key::operator!= ( const Key other) const

Inequality operator.

Parameters
otherThe key to compare
Returns
true if this key is not equal to other

◆ operator/()

Key dht::Key::operator/ ( int  value) const

Divide by a number operator

◆ operator<()

bool dht::Key::operator< ( const Key other) const

Smaller then operator.

Parameters
otherThe key to compare
Returns
rue if this key is smaller then other

◆ operator<=()

bool dht::Key::operator<= ( const Key other) const

Smaller then or equal operator.

Parameters
otherThe key to compare
Returns
rue if this key is smaller then or equal to other

◆ operator==()

bool dht::Key::operator== ( const Key other) const

Equality operator.

Parameters
otherThe key to compare
Returns
true if this key is equal to other

◆ operator>()

bool dht::Key::operator> ( const Key other) const

Greater then operator.

Parameters
otherThe key to compare
Returns
rue if this key is greater then other

◆ operator>=()

bool dht::Key::operator>= ( const Key other) const

Greater then or equal operator.

Parameters
otherThe key to compare
Returns
rue if this key is greater then or equal to other

◆ random()

static Key dht::Key::random ( )
static

Create a random key.

Returns
A random Key

Friends And Related Function Documentation

◆ operator+ [1/2]

KTORRENT_EXPORT Key operator+ ( const Key a,
bt::Uint8  value 
)
friend

Addition for key and a value

Parameters
aThe key
bThe value

◆ operator+ [2/2]

KTORRENT_EXPORT Key operator+ ( const Key a,
const Key b 
)
friend

Addition for keys

Parameters
aThe first key
bThe second key

◆ operator-

KTORRENT_EXPORT Key operator- ( const Key a,
const Key b 
)
friend

Subtraction for keys

Parameters
aThe first key
bThe second key

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