PastryNeighborhoodSet module. More...
#include <PastryNeighborhoodSet.h>
Public Member Functions | |
void | initializeSet (uint32_t numberOfNeighbors, uint32_t bitsPerDigit, const NodeHandle &owner) |
Initializes the neighborhood set. | |
virtual void | dumpToStateMessage (PastryStateMessage *msg) const |
dump content of the set to a PastryStateMessage | |
virtual const NodeHandle & | findCloserNode (const OverlayKey &destination, bool optimize=false) |
try to find a node numerically closer to a given key with the same shared prefix as the current node in the neighborhood set. | |
void | findCloserNodes (const OverlayKey &destination, NodeVector *nodes) |
virtual bool | mergeNode (const NodeHandle &node, simtime_t prox) |
merge a node into NeighborhoodSet | |
virtual void | dumpToVector (std::vector< TransportAddress > &affected) const |
appends all neighborhood set entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining. | |
virtual const TransportAddress & | failedNode (const TransportAddress &failed) |
tell the neighborhood set about a failed node | |
Private Member Functions | |
virtual void | earlyInit (void) |
initialize watches etc. | |
Private Attributes | |
uint32_t | numberOfNeighbors |
std::vector< PastryExtendedNode > | neighbors |
PastryNeighborhoodSet module.
This module contains the NeighborhoodSet of the Pastry implementation.
Definition at line 45 of file PastryNeighborhoodSet.h.
void PastryNeighborhoodSet::dumpToStateMessage | ( | PastryStateMessage * | msg | ) | const [virtual] |
dump content of the set to a PastryStateMessage
msg | the PastryStateMessage to be filled with entries |
Implements PastryStateObject.
Definition at line 48 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::doSecondStage(), and BasePastry::sendStateTables().
{ uint32_t i = 0; uint32_t size = 0; std::vector<PastryExtendedNode>::const_iterator it; msg->setNeighborhoodSetArraySize(numberOfNeighbors); for (it = neighbors.begin(); it != neighbors.end(); it++) { if (!it->node.isUnspecified()) { ++size; msg->setNeighborhoodSet(i++, it->node); } } msg->setNeighborhoodSetArraySize(size); }
void PastryNeighborhoodSet::dumpToVector | ( | std::vector< TransportAddress > & | affected | ) | const [virtual] |
appends all neighborhood set entries to a given vector of TransportAddresses, needed to find all Nodes to be notified after joining.
affected | the vector to fill with leaf set entries |
Implements PastryStateObject.
Definition at line 128 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::doSecondStage().
void PastryNeighborhoodSet::earlyInit | ( | void | ) | [private, virtual] |
initialize watches etc.
Implements PastryStateObject.
Definition at line 29 of file PastryNeighborhoodSet.cc.
{ WATCH_VECTOR(neighbors); }
const TransportAddress & PastryNeighborhoodSet::failedNode | ( | const TransportAddress & | failed | ) | [virtual] |
tell the neighborhood set about a failed node
failed | the failed node |
Implements PastryStateObject.
Definition at line 137 of file PastryNeighborhoodSet.cc.
Referenced by Pastry::handleFailedNode(), and Bamboo::handleFailedNode().
{ std::vector<PastryExtendedNode>::iterator it; for (it = neighbors.begin(); it != neighbors.end(); it++) { if (it->node.isUnspecified()) break; if (it->node.getIp() == failed.getIp()) { neighbors.erase(it); neighbors.push_back(unspecNode()); break; } } // never ask for repair return TransportAddress::UNSPECIFIED_NODE; }
const NodeHandle & PastryNeighborhoodSet::findCloserNode | ( | const OverlayKey & | destination, | |
bool | optimize = false | |||
) | [virtual] |
try to find a node numerically closer to a given key with the same shared prefix as the current node in the neighborhood set.
this method is to be called, when a regular next hop couldn't be found or wasn't reachable.
destination | the destination key | |
optimize | if set, check all nodes and return the best/closest one |
Implements PastryStateObject.
Definition at line 64 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::findNode().
{ std::vector<PastryExtendedNode>::const_iterator it; if (optimize) { // pointer to later return value, initialize to unspecified, so // the specialCloserCondition() check will be done against our own // node as long as no node closer to the destination than our own was // found. const NodeHandle* ret = &NodeHandle::UNSPECIFIED_NODE; for (it = neighbors.begin(); it != neighbors.end(); it++) { if (it->node.isUnspecified()) break; if (specialCloserCondition(it->node, destination, *ret)) ret = &(it->node); } return *ret; } else { for (it = neighbors.begin(); it != neighbors.end(); it++) { if (it->node.isUnspecified()) break; if (specialCloserCondition(it->node, destination)) return it->node; } return NodeHandle::UNSPECIFIED_NODE; } }
void PastryNeighborhoodSet::findCloserNodes | ( | const OverlayKey & | destination, | |
NodeVector * | nodes | |||
) | [virtual] |
Implements PastryStateObject.
Definition at line 91 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::findNode().
void PastryNeighborhoodSet::initializeSet | ( | uint32_t | numberOfNeighbors, | |
uint32_t | bitsPerDigit, | |||
const NodeHandle & | owner | |||
) |
Initializes the neighborhood set.
This should be called on startup
numberOfNeighbors | Pastry configuration parameter | |
bitsPerDigit | number of bits per digits | |
owner | the node this table belongs to |
Definition at line 34 of file PastryNeighborhoodSet.cc.
Referenced by BasePastry::baseChangeState().
{ this->owner = owner; this->numberOfNeighbors = numberOfNeighbors; this->bitsPerDigit = bitsPerDigit; if (!neighbors.empty()) neighbors.clear(); // fill Set with unspecified node handles for (uint32_t i = numberOfNeighbors; i>0; i--) neighbors.push_back(unspecNode()); }
bool PastryNeighborhoodSet::mergeNode | ( | const NodeHandle & | node, | |
simtime_t | prox | |||
) | [virtual] |
merge a node into NeighborhoodSet
node | the node to merge | |
prox | proximity value of the node |
Implements PastryStateObject.
Definition at line 101 of file PastryNeighborhoodSet.cc.
{ std::vector<PastryExtendedNode>::iterator it; bool nodeAlreadyInVector = false; // was the node already in the list? bool nodeValueWasChanged = false; // true if the list was changed, false if the rtt was too big // look for node in the set, if it's there and the value was changed, erase it (since the position is no longer valid) for (it = neighbors.begin(); it != neighbors.end(); it++) { if (!it->node.isUnspecified() && it->node == node) { if (prox == SimTime::getMaxTime() || it->rtt == prox) return false; // nothing to do! neighbors.erase(it); nodeAlreadyInVector = true; break; } } // look for the correct position for the node for (it = neighbors.begin(); it != neighbors.end(); it++) { if (it->node.isUnspecified() || (it->rtt > prox)) { nodeValueWasChanged = true; break; } } neighbors.insert(it, PastryExtendedNode(node, prox)); // insert the entry there if (!nodeAlreadyInVector) neighbors.pop_back(); // if a new entry was inserted, erase the last entry return !nodeAlreadyInVector && nodeValueWasChanged; // return whether a new entry was added }
std::vector<PastryExtendedNode> PastryNeighborhoodSet::neighbors [private] |
Definition at line 111 of file PastryNeighborhoodSet.h.
Referenced by dumpToStateMessage(), dumpToVector(), earlyInit(), failedNode(), findCloserNode(), findCloserNodes(), initializeSet(), and mergeNode().
uint32_t PastryNeighborhoodSet::numberOfNeighbors [private] |
Definition at line 110 of file PastryNeighborhoodSet.h.
Referenced by dumpToStateMessage().