#include <source/ariba/utility/types/Identifier.h>
Public Member Functions | |
virtual void | clearAddress () |
virtual bool | setAddress (string address) |
virtual string | getAddress () const |
Identifier () | |
Identifier (uint32_t num) | |
Identifier (const unsigned char *buffer, uint size) | |
Identifier (const std::string &str, uint base=16) | |
Identifier (const Identifier &rhs) | |
virtual | ~Identifier () |
virtual std::string | toString (uint base=16) const |
bool | isUnspecified () const |
bool | operator< (const Identifier &compKey) const |
bool | operator> (const Identifier &compKey) const |
bool | operator<= (const Identifier &compKey) const |
bool | operator>= (const Identifier &compKey) const |
bool | operator== (const Identifier &compKey) const |
bool | operator!= (const Identifier &compKey) const |
int | compareTo (const Identifier &compKey) const |
Identifier & | operator= (const Identifier &rhs) |
Identifier & | operator-- () |
Identifier & | operator++ () |
Identifier & | operator+= (const Identifier &rhs) |
Identifier & | operator-= (const Identifier &rhs) |
Identifier | operator+ (const Identifier &rhs) const |
Identifier | operator- (const Identifier &rhs) const |
Identifier | operator-- (int) |
Identifier | operator++ (int) |
Identifier | operator>> (uint num) const |
Identifier | operator<< (uint num) const |
Identifier | operator & (const Identifier &rhs) const |
Identifier | operator| (const Identifier &rhs) const |
Identifier | operator^ (const Identifier &rhs) const |
Identifier | operator~ () const |
IdentifierBit | operator[] (uint n) |
Identifier & | setBitAt (uint pos, bool value) |
uint32_t | get (uint p, uint n) const |
size_t | hash () const |
int | log_2 () const |
Identifier | randomSuffix (uint pos) const |
Identifier | randomPrefix (uint pos) const |
uint | sharedPrefixLength (const Identifier &compKey) const |
bool | isBetween (const Identifier &keyA, const Identifier &keyB) const |
bool | isBetweenR (const Identifier &keyA, const Identifier &keyB) const |
bool | isBetweenL (const Identifier &keyA, const Identifier &keyB) const |
bool | isBetweenLR (const Identifier &keyA, const Identifier &keyB) const |
Static Public Member Functions | |
static void | setKeyLength (uint length) |
static uint | getLength () |
static Identifier | random () |
static Identifier | max () |
static Identifier | sha1 (const string &value) |
static Identifier | sha1 (const uint8_t *value, size_t length) |
static Identifier | pow2 (uint exponent) |
Static Public Attributes | |
static const Identifier | UNSPECIFIED_KEY |
static const Identifier | ZERO |
static const Identifier | ONE |
Private Member Functions | |
use_logging_h (Identifier) | |
void | seed () |
void | trim () |
void | clear () |
Private Attributes | |
VSERIALIZEABLE | |
bool | isUnspec |
mp_limb_t | key [array_size+1] |
Static Private Attributes | |
static uint | keyLength = MAX_KEYLENGTH |
static uint | aSize |
static mp_limb_t | GMP_MSB_MASK |
static const size_t | array_size |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Identifier &c) |
This class is the base for all identifier classes.
Definition at line 65 of file Identifier.h.
ariba::utility::Identifier::Identifier | ( | ) |
ariba::utility::Identifier::Identifier | ( | uint32_t | num | ) |
Constructs an overlay key initialized with a common integer
num | The integer to initialize this key with |
Definition at line 98 of file Identifier.cpp.
References clearAddress(), key, seed(), and trim().
ariba::utility::Identifier::Identifier | ( | const unsigned char * | buffer, | |
uint | size | |||
) |
Constructs a key out of a buffer
buffer | Source buffer | |
size | Buffer size (in bytes) |
Definition at line 106 of file Identifier.cpp.
References aSize, clearAddress(), key, seed(), and trim().
ariba::utility::Identifier::Identifier | ( | const std::string & | str, | |
uint | base = 16 | |||
) |
Constructs a key out of a string number.
Definition at line 117 of file Identifier.cpp.
References clearAddress(), key, logging_error, seed(), and trim().
ariba::utility::Identifier::Identifier | ( | const Identifier & | rhs | ) |
Copy constructor.
rhs | The key to copy. |
Definition at line 148 of file Identifier.cpp.
References seed().
ariba::utility::Identifier::~Identifier | ( | ) | [virtual] |
ariba::utility::Identifier::use_logging_h | ( | Identifier | ) | [private] |
void ariba::utility::Identifier::clearAddress | ( | ) | [virtual] |
Definition at line 71 of file Identifier.cpp.
References array_size, isUnspec, key, and trim().
Referenced by Identifier(), and sha1().
bool ariba::utility::Identifier::setAddress | ( | string | address | ) | [virtual] |
Definition at line 78 of file Identifier.cpp.
string ariba::utility::Identifier::getAddress | ( | ) | const [virtual] |
std::string ariba::utility::Identifier::toString | ( | uint | base = 16 |
) | const [virtual] |
Returns a string representation of this key
Definition at line 198 of file Identifier.cpp.
References aSize, ariba::utility::HEX, isUnspec, key, keyLength, logging_error, and MAX_KEYLENGTH.
Referenced by ariba::utility::PathloadMeasurement::blockingFunction(), ariba::overlay::BaseOverlay::dropLink(), ariba::communication::BaseCommunication::dropLink(), ariba::overlay::OneHop::eventFunction(), ariba::overlay::Chord::eventFunction(), ariba::overlay::BaseOverlay::eventFunction(), ariba::overlay::BaseOverlay::joinSpoVNet(), ariba::utility::PathloadMeasurement::measure(), ariba::application::pingpong::PingPong::onJoinCompleted(), ariba::application::pingpong::PingPong::onJoinFailed(), ariba::application::pingpong::PingPong::onLeaveCompleted(), ariba::application::pingpong::PingPong::onLeaveFailed(), ariba::application::pingpong::PingPong::onLinkChanged(), ariba::overlay::OneHop::onLinkDown(), ariba::overlay::Chord::onLinkDown(), ariba::application::pingpong::PingPong::onLinkDown(), ariba::application::pingpong::PingPong::onLinkFail(), ariba::application::pingpong::PingPong::onLinkRequest(), ariba::overlay::Chord::onLinkUp(), ariba::overlay::BaseOverlay::onLinkUp(), ariba::application::pingpong::PingPong::onLinkUp(), ariba::overlay::OneHop::onMessage(), ariba::overlay::Chord::onMessage(), ariba::application::pingpong::PingPong::onMessage(), ariba::overlay::BaseOverlay::onNodeJoin(), ariba::utility::operator<<(), ariba::overlay::BaseOverlay::receiveMessage(), ariba::communication::BaseCommunication::receiveMessage(), ariba::overlay::OneHop::resolveNode(), ariba::overlay::OneHop::routeMessage(), ariba::overlay::Chord::send_discovery_to(), ariba::overlay::BaseOverlay::sendMessage(), ariba::communication::BaseCommunication::sendMessage(), ariba::application::pingpong::PingPong::startup(), ariba::utility::OvlVis::visChangeNodeColor(), ariba::utility::OvlVis::visChangeNodeIcon(), ariba::utility::OvlVis::visChangeStatus(), ariba::utility::OvlVis::visCLIOEndMeasurement(), ariba::utility::OvlVis::visCLIOInitMeasurement(), ariba::utility::OvlVis::visConnect(), ariba::utility::OvlVis::visCreate(), ariba::utility::OvlVis::visDeleteNodeLabel(), ariba::utility::OvlVis::visFailedConnect(), ariba::utility::OvlVis::visSendMessage(), ariba::utility::OvlVis::visShowLinkBubble(), ariba::utility::OvlVis::visShowNodeBubble(), ariba::utility::OvlVis::visShowNodeLabel(), ariba::utility::OvlVis::visShowOnLinkIcon(), ariba::utility::OvlVis::visShowShiftedNodeIcon(), and ariba::utility::OvlVis::visShutdown().
bool ariba::utility::Identifier::isUnspecified | ( | ) | const |
Returns true, if the key is unspecified
Definition at line 194 of file Identifier.cpp.
References isUnspec.
Referenced by ariba::overlay::BaseOverlay::establishLink(), ariba::overlay::Chord::eventFunction(), ariba::overlay::Chord::onLinkUp(), operator==(), ariba::overlay::Chord::resolveNode(), ariba::overlay::Chord::send(), and ariba::overlay::BaseOverlay::updateOvlVis().
bool ariba::utility::Identifier::operator< | ( | const Identifier & | compKey | ) | const |
compares this to a given Identifier
compKey | the the Identifier to compare this to |
Definition at line 308 of file Identifier.cpp.
References compareTo().
bool ariba::utility::Identifier::operator> | ( | const Identifier & | compKey | ) | const |
compares this to a given Identifier
compKey | the the Identifier to compare this to |
Definition at line 311 of file Identifier.cpp.
References compareTo().
bool ariba::utility::Identifier::operator<= | ( | const Identifier & | compKey | ) | const |
compares this to a given Identifier
compKey | the the Identifier to compare this to |
Definition at line 314 of file Identifier.cpp.
References compareTo().
bool ariba::utility::Identifier::operator>= | ( | const Identifier & | compKey | ) | const |
compares this to a given Identifier
compKey | the the Identifier to compare this to |
Definition at line 317 of file Identifier.cpp.
References compareTo().
bool ariba::utility::Identifier::operator== | ( | const Identifier & | compKey | ) | const |
compares this to a given Identifier
compKey | the the Identifier to compare this to |
Definition at line 320 of file Identifier.cpp.
References compareTo(), and isUnspecified().
bool ariba::utility::Identifier::operator!= | ( | const Identifier & | compKey | ) | const |
compares this to a given Identifier
compKey | the the Identifier to compare this to |
Definition at line 327 of file Identifier.cpp.
References compareTo().
int ariba::utility::Identifier::compareTo | ( | const Identifier & | compKey | ) | const |
Unifies all compare operations in one method
compKey | key to compare with |
Definition at line 674 of file Identifier.cpp.
References aSize, isUnspec, and key.
Referenced by operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), and sharedPrefixLength().
Identifier & ariba::utility::Identifier::operator= | ( | const Identifier & | rhs | ) |
assigns Identifier of rhs to this->key
rhs | the Identifier with the defined key |
Definition at line 247 of file Identifier.cpp.
References aSize, isUnspec, and key.
Referenced by ariba::utility::LinkID::operator=().
Identifier & ariba::utility::Identifier::operator-- | ( | ) |
substracts 1 from this->key
Definition at line 254 of file Identifier.cpp.
References ONE.
Identifier & ariba::utility::Identifier::operator++ | ( | ) |
adds 1 to this->key
Definition at line 266 of file Identifier.cpp.
References ONE.
Identifier & ariba::utility::Identifier::operator+= | ( | const Identifier & | rhs | ) |
adds rhs->key to this->key
rhs | the Identifier with the defined key |
Definition at line 278 of file Identifier.cpp.
Identifier & ariba::utility::Identifier::operator-= | ( | const Identifier & | rhs | ) |
substracts rhs->key from this->key
rhs | the Identifier with the defined key |
Definition at line 286 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator+ | ( | const Identifier & | rhs | ) | const |
adds rhs->key to this->key
rhs | the Identifier with the defined key |
Definition at line 294 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator- | ( | const Identifier & | rhs | ) | const |
substracts rhs->key from this->key
rhs | the Identifier with the defined key |
Definition at line 301 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator-- | ( | int | ) |
substracts 1 from this->key
Definition at line 259 of file Identifier.cpp.
References ONE.
Identifier ariba::utility::Identifier::operator++ | ( | int | ) |
adds 1 to this->key
Definition at line 271 of file Identifier.cpp.
References ONE.
Identifier ariba::utility::Identifier::operator>> | ( | uint | num | ) | const |
bitwise shift right
num | number of bits to shift |
Definition at line 373 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator<< | ( | uint | num | ) | const |
bitwise shift left
num | number of bits to shift |
Definition at line 392 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator & | ( | const Identifier & | rhs | ) | const |
bitwise AND of rhs->key and this->key
rhs | the Identifier AND is calculated with |
Definition at line 352 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator| | ( | const Identifier & | rhs | ) | const |
bitwise OR of rhs->key and this->key
rhs | the Identifier OR is calculated with |
Definition at line 342 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator^ | ( | const Identifier & | rhs | ) | const |
bitwise XOR of rhs->key and this->key
rhs | the Identifier XOR is calculated with |
Definition at line 332 of file Identifier.cpp.
Identifier ariba::utility::Identifier::operator~ | ( | ) | const |
bitwise NOT of this->key
Definition at line 362 of file Identifier.cpp.
IdentifierBit ariba::utility::Identifier::operator[] | ( | uint | n | ) |
returns the n-th bit of this->key
n | the position of the returned bit |
Definition at line 411 of file Identifier.cpp.
Identifier & ariba::utility::Identifier::setBitAt | ( | uint | pos, | |
bool | value | |||
) |
sets a bit of this->key
pos | the position of the bit to set | |
value | new value for bit at position pos |
Definition at line 415 of file Identifier.cpp.
References key.
Referenced by ariba::utility::IdentifierBit::operator=(), and ariba::utility::IdentifierBit::operator^=().
uint32_t ariba::utility::Identifier::get | ( | uint | p, | |
uint | n | |||
) | const |
Returns a sub integer at position p with n-bits. p is counted starting from the least significant bit of the key as bit 0. Bit p of the key becomes bit 0 of the returned integer.
p | the position of the sub-integer | |
n | the number of bits to be returned (max.32) |
Definition at line 435 of file Identifier.cpp.
References key, keyLength, and logging_error.
size_t ariba::utility::Identifier::hash | ( | ) | const |
Returns a hash value for the key
Definition at line 535 of file Identifier.cpp.
References key.
int ariba::utility::Identifier::log_2 | ( | ) | const |
Returns the position of the msb in this key, which represents just the logarithm to base 2.
Definition at line 513 of file Identifier.cpp.
Identifier ariba::utility::Identifier::randomSuffix | ( | uint | pos | ) | const |
Fills the suffix starting at pos with random bits to lsb.
pos |
Definition at line 451 of file Identifier.cpp.
Identifier ariba::utility::Identifier::randomPrefix | ( | uint | pos | ) | const |
Fills the prefix starting at pos with random bits to msb.
pos |
Definition at line 467 of file Identifier.cpp.
uint ariba::utility::Identifier::sharedPrefixLength | ( | const Identifier & | compKey | ) | const |
Calculates the number of equal bits from the left with another Key (shared prefix length)
compKey | the Key to compare with |
Definition at line 486 of file Identifier.cpp.
References aSize, compareTo(), key, and keyLength.
bool ariba::utility::Identifier::isBetween | ( | const Identifier & | keyA, | |
const Identifier & | keyB | |||
) | const |
Returns true, if this key is element of the interval (keyA, keyB) on the ring.
keyA | The left border of the interval | |
keyB | The right border of the interval |
Definition at line 540 of file Identifier.cpp.
References isUnspec.
bool ariba::utility::Identifier::isBetweenR | ( | const Identifier & | keyA, | |
const Identifier & | keyB | |||
) | const |
Returns true, if this key is element of the interval (keyA, keyB] on the ring.
keyA | The left border of the interval | |
keyB | The right border of the interval |
Definition at line 549 of file Identifier.cpp.
References isUnspec.
bool ariba::utility::Identifier::isBetweenL | ( | const Identifier & | keyA, | |
const Identifier & | keyB | |||
) | const |
Returns true, if this key is element of the interval [keyA, keyB) on the ring.
keyA | The left border of the interval | |
keyB | The right border of the interval |
Definition at line 558 of file Identifier.cpp.
References isUnspec.
bool ariba::utility::Identifier::isBetweenLR | ( | const Identifier & | keyA, | |
const Identifier & | keyB | |||
) | const |
Returns true, if this key is element of the interval [keyA, keyB] on the ring.
keyA | The left border of the interval | |
keyB | The right border of the interval |
Definition at line 567 of file Identifier.cpp.
References isUnspec.
void ariba::utility::Identifier::setKeyLength | ( | uint | length | ) | [static] |
Set the length of an Identifier
length | keylength in bits |
Definition at line 171 of file Identifier.cpp.
References aSize, GMP_MSB_MASK, keyLength, logging_error, and MAX_KEYLENGTH.
uint ariba::utility::Identifier::getLength | ( | ) | [static] |
Returns the length in number of bits.
Definition at line 190 of file Identifier.cpp.
References keyLength.
Identifier ariba::utility::Identifier::random | ( | ) | [static] |
Returns a random key.
Definition at line 600 of file Identifier.cpp.
References aSize, key, trim(), and ZERO.
Referenced by ariba::utility::LinkID::create().
Identifier ariba::utility::Identifier::max | ( | ) | [static] |
Identifier ariba::utility::Identifier::sha1 | ( | const string & | value | ) | [static] |
Returns a key with the SHA1 cryptographic hash of a string
value | A string value. |
Definition at line 617 of file Identifier.cpp.
References aSize, clearAddress(), CSHA1::Final(), CSHA1::GetHash(), isUnspec, key, CSHA1::Reset(), trim(), and CSHA1::Update().
Identifier ariba::utility::Identifier::sha1 | ( | const uint8_t * | value, | |
size_t | length | |||
) | [static] |
Definition at line 637 of file Identifier.cpp.
References aSize, CSHA1::Final(), CSHA1::GetHash(), isUnspec, key, CSHA1::Reset(), trim(), and CSHA1::Update().
Identifier ariba::utility::Identifier::pow2 | ( | uint | exponent | ) | [static] |
Returns a key 2^exponent.
exponent | The exponent. |
Definition at line 654 of file Identifier.cpp.
void ariba::utility::Identifier::seed | ( | ) | [private] |
Definition at line 157 of file Identifier.cpp.
References ariba::utility::randstate.
Referenced by Identifier().
void ariba::utility::Identifier::trim | ( | ) | [inline, private] |
trims key after key operations
Definition at line 668 of file Identifier.cpp.
References array_size, GMP_MSB_MASK, and key.
Referenced by clearAddress(), Identifier(), max(), operator+=(), operator-=(), operator<<(), operator>>(), operator~(), random(), randomPrefix(), randomSuffix(), and sha1().
void ariba::utility::Identifier::clear | ( | ) | [private] |
set this->key to 0 and isUnspec to false
std::ostream& operator<< | ( | std::ostream & | os, | |
const Identifier & | c | |||
) | [friend] |
Common stdc++ console output method
Definition at line 580 of file Identifier.cpp.
const Identifier ariba::utility::Identifier::UNSPECIFIED_KEY [static] |
Identifier without defined key
Definition at line 82 of file Identifier.h.
const Identifier ariba::utility::Identifier::ZERO [static] |
Identifier with key initialized as 0
Definition at line 83 of file Identifier.h.
Referenced by operator<<(), operator>>(), pow2(), and random().
const Identifier ariba::utility::Identifier::ONE [static] |
Identifier with key initialized as 1
Definition at line 84 of file Identifier.h.
Referenced by operator++(), and operator--().
uint ariba::utility::Identifier::keyLength = MAX_KEYLENGTH [static, private] |
actual length of the key
Definition at line 499 of file Identifier.h.
Referenced by get(), getLength(), setKeyLength(), sharedPrefixLength(), and toString().
uint ariba::utility::Identifier::aSize [static, private] |
Initial value:
Identifier::keyLength / (8 * sizeof(mp_limb_t)) + (Identifier::keyLength % (8 * sizeof(mp_limb_t)) != 0 ? 1 : 0)
Definition at line 500 of file Identifier.h.
Referenced by compareTo(), Identifier(), log_2(), max(), operator &(), operator+=(), operator-=(), operator<<(), operator=(), operator>>(), operator^(), operator|(), operator~(), random(), randomPrefix(), setKeyLength(), sha1(), sharedPrefixLength(), and toString().
mp_limb_t ariba::utility::Identifier::GMP_MSB_MASK [static, private] |
Initial value:
(Identifier::keyLength % GMP_LIMB_BITS) != 0 ? (((mp_limb_t) 1 << (Identifier::keyLength % GMP_LIMB_BITS)) - 1) : (mp_limb_t) -1
Definition at line 501 of file Identifier.h.
Referenced by setKeyLength(), and trim().
bool ariba::utility::Identifier::isUnspec [private] |
is this->key unspecified?
Definition at line 505 of file Identifier.h.
Referenced by clearAddress(), compareTo(), Identifier(), isBetween(), isBetweenL(), isBetweenLR(), isBetweenR(), isUnspecified(), max(), operator+=(), operator-=(), operator<<(), operator=(), operator>>(), sha1(), and toString().
const size_t ariba::utility::Identifier::array_size [static, private] |
Initial value:
MAX_KEYLENGTH / (8 * sizeof(mp_limb_t)) + (MAX_KEYLENGTH % (8 * sizeof(mp_limb_t)) != 0 ? 1 : 0)
Definition at line 509 of file Identifier.h.
Referenced by clearAddress(), and trim().
mp_limb_t ariba::utility::Identifier::key[array_size+1] [private] |
the overlay key this object represents
Definition at line 513 of file Identifier.h.
Referenced by clearAddress(), compareTo(), get(), hash(), Identifier(), log_2(), max(), operator &(), operator+=(), operator-=(), operator<<(), operator=(), operator>>(), operator^(), operator|(), operator~(), pow2(), random(), randomPrefix(), randomSuffix(), setBitAt(), sha1(), sharedPrefixLength(), toString(), and trim().