The basic MaceKey interface is specified by the class MaceKey_interface. MaceKey and all its sub-helpers provide that interface. Each sub-helper is also mapped to a address family, as defined in MaceBasics.h MaceKey's also throw 3 exceptions:
To construct most MaceKey's, you can pass in a type (ipv4, sha32, sha160, or string_key), and a string. The string will be interpreted as appropriate for that MaceKey sub-type.
e.g.
using mace::MaceKey; MaceKey a = MaceKey(ipv4, "10.0.0.1:12345"); MaceKey b = MaceKey(ipv4, "www.google.com"); MaceKey c = MaceKey(sha160, "Some string to hash to produce the address"); MaceKey d = Macekey(string_key, "a string which serves as an address");
Additionally there is a MaceKey constructor that parses a string with a family prefix, and constructs an appropriate MaceKey:
mace::MaceKey e = mace::MaceKey("IPV4/www.ibm.com:12345");
There are also constructors which do more specific constructions based on the MaceKey subtype.
Implementation Note: The helper classes are all privately enclosed in MaceKey, to prevent outside code from ever creating or referencing them. Before adding new MaceKey helper classes, take a good look at this code. You'll have to add a new address family, both here and in MaceBasics.h, and there are a number of places code should be added. In particular, you'll want to note the bitarr_MaceKey, MaceKey_exception, and intarr_MaceKey classes as they may be helpful.
Definition in file MaceKey.h.
#include <stdint.h>
#include <inttypes.h>
#include <sys/types.h>
#include "m_net.h"
#include <iomanip>
#include <cassert>
#include <boost/shared_ptr.hpp>
#include <string>
#include "Serializable.h"
#include "Exception.h"
#include "HashUtil.h"
#include "Log.h"
#include "MaceBasics.h"
#include "Collections.h"
Go to the source code of this file.
Namespaces | |
namespace | mace |
namespace | __gnu_cxx |
Classes | |
class | mace::SockAddr |
Helper class to represent an IP and port pair. More... | |
class | mace::MaceAddr |
Helper class to represent Mace addresses. More... | |
class | mace::MaceKey_interface |
The generic interface for MaceKey and its helper classes. More... | |
class | mace::MaceKey |
The base class of Mace addresses. More... | |
class | mace::MaceKeyDiff |
A class to represent the difference between two bit array MaceKey objects (big integers). (like TimeDiff in other languages). More... | |
Functions | |
MaceKey | mace::operator+ (const MaceKey &, const MaceKeyDiff &) throw (InvalidMaceKeyException) |
adds a MaceKeyDiff to a MaceKey | |
MaceKey | mace::operator- (const MaceKey &, const MaceKeyDiff &) throw (InvalidMaceKeyException) |
subtracts a MaceKeyDiff from a MaceKey | |
MaceKey | mace::operator+ (const MaceKey &, uint32_t) throw (InvalidMaceKeyException) |
adds a 32-bit integer as an implicit MaceKeyDiff | |
MaceKey | mace::operator- (const MaceKey &, uint32_t) throw (InvalidMaceKeyException) |
subtracts a 32-bit integer as an implicit MaceKeyDiff | |
MaceKeyDiff | mace::operator- (const MaceKey &to, const MaceKey &from) throw (InvalidMaceKeyException) |
returns the length between two points on the circle (i.e. between the two ids in id-space). | |
Variables | |
const mace::MaceKey::ipv4_type | mace::ipv4 = mace::MaceKey::ipv4_type() |
defines an object for passing into the Macekey constructor | |
const mace::MaceKey::sha160_type | mace::sha160 = mace::MaceKey::sha160_type() |
defines an object for passing into the Macekey constructor | |
const mace::MaceKey::sha32_type | mace::sha32 = mace::MaceKey::sha32_type() |
defines an object for passing into the Macekey constructor | |
const mace::MaceKey::string_type | mace::string_key = mace::MaceKey::string_type() |
defines an object for passing into the Macekey constructor |