OverSim
|
#include <I3Identifier.h>
Public Member Functions | |
I3Identifier () | |
Constructor. | |
I3Identifier (unsigned char b) | |
Constructs an identifier filled with a byte. | |
I3Identifier (int prefixL, int keyL) | |
Constructor for variable prefix length, key length. | |
I3Identifier (const I3Identifier &id) | |
Copy constructor. | |
I3Identifier (std::string s) | |
Constructs an identifier from the hash of a string. | |
int | getKeyLength () const |
Returns the key length (total length) in bits. | |
int | getPrefixLength () const |
Returns the prefix length in bits. | |
void | clear () |
Sets all bits to 0. | |
int | compareTo (const I3Identifier &) const |
Comparation function. | |
bool | operator< (const I3Identifier &) const |
"Less than" comparation function | |
bool | operator> (const I3Identifier &) const |
"Greater than" comparation function | |
bool | operator== (const I3Identifier &) const |
"Equals" comparation function | |
I3Identifier & | operator= (const I3Identifier &) |
Copy operator. | |
bool | isClear () |
Checks if this identifier has been cleared. | |
bool | isMatch (const I3Identifier &id) const |
Checks if this identifier's first prefixLength bits equal those of id. | |
int | distanceTo (const I3Identifier &id) const |
Returns the "distance to" a identifier. | |
void | createFromHash (const std::string &s, const std::string &o="") |
Creates an identifier from the hash of a string. | |
void | createRandomKey () |
void | createRandomPrefix () |
void | createRandomSuffix () |
int | length () const |
OverlayKey | asOverlayKey () const |
Creates an OverlayKey from an identifier, to be used in the overlay underneath. | |
void | setName (std::string s) |
std::string | getName () |
~I3Identifier () | |
Destructor. |
Protected Member Functions | |
void | initKey (int prefixL, int keyL) |
Inits the key with a given prefix length and key length. |
Protected Attributes | |
unsigned char * | key |
Identifier bits. | |
unsigned short | prefixLength |
Size of prefix in bits. | |
unsigned short | keyLength |
Size of identifier in bits. | |
std::string | name |
Friends | |
std::ostream & | operator<< (std::ostream &os, const I3Identifier &id) |
String stream output operator. |
Definition at line 40 of file I3Identifier.h.
I3Identifier::I3Identifier | ( | ) |
Constructor.
Definition at line 36 of file I3Identifier.cc.
I3Identifier::I3Identifier | ( | unsigned char | b | ) |
Constructs an identifier filled with a byte.
b | Byte to fill with |
I3Identifier::I3Identifier | ( | int | prefixL, |
int | keyL | ||
) |
Constructor for variable prefix length, key length.
prefixL | Prefix length |
keyL | Key length |
Definition at line 41 of file I3Identifier.cc.
I3Identifier::I3Identifier | ( | const I3Identifier & | id | ) |
I3Identifier::I3Identifier | ( | std::string | s | ) |
Constructs an identifier from the hash of a string.
s | String to be hashed |
Definition at line 52 of file I3Identifier.cc.
I3Identifier::~I3Identifier | ( | ) |
Destructor.
Definition at line 230 of file I3Identifier.cc.
OverlayKey I3Identifier::asOverlayKey | ( | ) | const |
Creates an OverlayKey from an identifier, to be used in the overlay underneath.
No hashing is done, the first min(OverlayKey::keySize, keyLength) bits are copied directly.
Definition at line 124 of file I3Identifier.cc.
Referenced by I3::handleUDPMessage(), and I3::sendPacket().
void I3Identifier::clear | ( | ) |
Sets all bits to 0.
Definition at line 58 of file I3Identifier.cc.
Referenced by I3Trigger::clear(), and I3SubIdentifier::setIPAddress().
int I3Identifier::compareTo | ( | const I3Identifier & | id | ) | const |
Comparation function.
Definition at line 81 of file I3Identifier.cc.
Referenced by I3Trigger::compareTo(), and I3SubIdentifier::compareTo().
void I3Identifier::createFromHash | ( | const std::string & | s, |
const std::string & | o = "" |
||
) |
Creates an identifier from the hash of a string.
s | String to be hashed to form the prefix |
o | String to be hashed to form the remaining bits |
Definition at line 129 of file I3Identifier.cc.
Referenced by I3HostMobility::discoverPartners(), I3LatencyStretch::handleTimerEvent(), and I3SessionClient::handleTimerEvent().
void I3Identifier::createRandomKey | ( | ) |
Definition at line 162 of file I3Identifier.cc.
Referenced by I3BaseApp::bootstrapI3(), I3Triggers::deliver(), and I3BaseApp::retrieveClosestIdentifier().
void I3Identifier::createRandomPrefix | ( | ) |
Definition at line 168 of file I3Identifier.cc.
void I3Identifier::createRandomSuffix | ( | ) |
Definition at line 175 of file I3Identifier.cc.
Referenced by I3HostMobility::discoverPartners(), I3LatencyStretch::handleTimerEvent(), I3SessionClient::handleTimerEvent(), and I3Anycast::initializeI3().
int I3Identifier::distanceTo | ( | const I3Identifier & | id | ) | const |
Returns the "distance to" a identifier.
This is used when many triggers match an identifier, to check which is the biggest prefix match. The distance is defined as the index of the byte (counting from the end) which is the first that is not equal, multiplied by 256, then added the XOR'ing of the differing byte. That way an earlier differing bits are considered "further" from later differing ones (notice that this distance is not a real metric!)
id | Identifier to be compared to |
Definition at line 113 of file I3Identifier.cc.
Referenced by I3::findClosestMatch().
int I3Identifier::getKeyLength | ( | ) | const |
Returns the key length (total length) in bits.
Definition at line 76 of file I3Identifier.cc.
std::string I3Identifier::getName | ( | ) |
Definition at line 190 of file I3Identifier.cc.
int I3Identifier::getPrefixLength | ( | ) | const |
Returns the prefix length in bits.
Definition at line 71 of file I3Identifier.cc.
|
protected |
Inits the key with a given prefix length and key length.
prefixL | Prefix length |
keyL | Key (identifier) length |
Definition at line 29 of file I3Identifier.cc.
bool I3Identifier::isClear | ( | ) |
Checks if this identifier has been cleared.
Definition at line 63 of file I3Identifier.cc.
bool I3Identifier::isMatch | ( | const I3Identifier & | id | ) | const |
Checks if this identifier's first prefixLength bits equal those of id.
id | Identifier to be matched against |
Definition at line 108 of file I3Identifier.cc.
int I3Identifier::length | ( | ) | const |
Definition at line 182 of file I3Identifier.cc.
Referenced by I3SubIdentifier::length(), and I3Trigger::length().
bool I3Identifier::operator< | ( | const I3Identifier & | id | ) | const |
"Less than" comparation function
Definition at line 86 of file I3Identifier.cc.
I3Identifier & I3Identifier::operator= | ( | const I3Identifier & | id | ) |
bool I3Identifier::operator== | ( | const I3Identifier & | id | ) | const |
"Equals" comparation function
Definition at line 96 of file I3Identifier.cc.
bool I3Identifier::operator> | ( | const I3Identifier & | id | ) | const |
"Greater than" comparation function
Definition at line 91 of file I3Identifier.cc.
void I3Identifier::setName | ( | std::string | s | ) |
Definition at line 186 of file I3Identifier.cc.
Referenced by I3BaseApp::retrieveClosestIdentifier().
|
friend |
String stream output operator.
os | String stream |
id | I3Identifier to be output |
Definition at line 195 of file I3Identifier.cc.
|
protected |
Identifier bits.
Definition at line 142 of file I3Identifier.h.
|
protected |
Size of identifier in bits.
Definition at line 148 of file I3Identifier.h.
|
protected |
Definition at line 150 of file I3Identifier.h.
|
protected |
Size of prefix in bits.
Definition at line 145 of file I3Identifier.h.