Example #1
0
bool NodeStore::update(NodeRef &node, NodeRefList *nl)
{
        Mutex::AutoLocker l(mutex);
	bool found = false;
	
	if (!node)
		return false;

	// There may be undefined nodes in the node store that should
	// be removed/merged with a 'defined' node that we create from a 
	// node description. We loop through all nodes in the store and
	// compare their interface lists with the one in the 'defined' node.
	// If any interfaces match, we remove the matching nodes in the store 
	// and eventually replace them with the new one.
	for (NodeStore::iterator it = begin(); it != end();) {
		NodeRecord *nr = *it;
		bool found_now = false;
		
		nr->node.lock();

		const InterfaceRefList *ifaces = nr->node->getInterfaces();

		for (InterfaceRefList::const_iterator it2 = ifaces->begin(); it2 != ifaces->end(); it2++) {
			InterfaceRef iface = *it2;

			if (node->hasInterface(iface)) {
				// Transfer all the "up" interface states to the updated node
				if (iface->isUp())
					node->setInterfaceUp(iface);

				found_now = true;
			}
		}
		nr->node.unlock();

		if (found_now) {
			if (nl)
				nl->push_back(nr->node);
			
			nr->node->setStored(false);

			node->setExchangedNodeDescription(nr->node->hasExchangedNodeDescription());
				
			it = erase(it);
			delete nr;
			found = true;
		} else {
			it++;
		}
	}
	if (found) {
		node->setStored(true);
		push_back(new NodeRecord(node));
	}

	return found;
}
Example #2
0
NodeRef NodeStore::retrieve(const InterfaceRef &iface, bool mustBeNeighbor)
{
        Mutex::AutoLocker l(mutex);

        if (!iface)
	        return NULL;

	for (NodeStore::iterator it = begin(); it != end(); it++) {
		NodeRecord *nr = *it;
		NodeRef node = nr->node;

		if (mustBeNeighbor && !node->isNeighbor())
			continue;

		if (node->hasInterface(iface)) 
			return node;
	}

	return NULL;
}