void DataManager::onSendResult(Event *e) { DataObjectRef& dObj = e->getDataObject(); NodeRef node = e->getNode(); if (!dObj) { HAGGLE_ERR("No data object in send result\n"); return; } if(dObj->isControlMessage()) { // MOS - keep control messages out of Bloom filter return; } if (!node) { HAGGLE_ERR("No node in send result\n"); return; } if (!node->isStored()) { HAGGLE_DBG2("Send result node %s is not in node store, trying to retrieve\n", node->getName().c_str()); NodeRef peer = kernel->getNodeStore()->retrieve(node); if (peer) { HAGGLE_DBG2("Found node %s in node store, using the one in store\n", node->getName().c_str()); node = peer; } else { HAGGLE_ERR("Did not find node %s in node store\n", node->getName().c_str()); } } if (e->getType() == EVENT_TYPE_DATAOBJECT_SEND_SUCCESSFUL) { // Add data object to node's bloomfilter. HAGGLE_DBG("Adding data object [%s] to node %s's bloomfilter\n", DataObject::idString(dObj).c_str(), node->getName().c_str()); node->getBloomfilter()->add(dObj); if (dataObjectsSent.size() >= MAX_DATAOBJECTS_LISTED) { dataObjectsSent.pop_front(); } dataObjectsSent.push_back(dObj->getIdStr()); // SW: JLM: START CACHE STRATEGY: if ((e->getType() == EVENT_TYPE_DATAOBJECT_SEND_SUCCESSFUL) && cacheStrategy && !cacheStrategy->isDone()) { cacheStrategy->handleSendSuccess(dObj, node); } // SW: JLM: END CACHE STRATEGY. } }
void DataManager::onIncomingDataObject(Event *e) { if (!e || !e->hasData()) return; DataObjectRef& dObj = e->getDataObject(); if (!dObj) { HAGGLE_DBG("Incoming data object event without data object!\n"); return; } if(dObj->isControlMessage()) { // MOS - keep control messages out of Bloom filter return; } // Add the data object to the bloomfilter of the one who sent it: NodeRef peer = e->getNode(); // JM End: Associate origin social group to DO if (!peer || peer->getType() == Node::TYPE_UNDEFINED) { // No valid node in event, try to figure out from interface // Find the interface it came from: const InterfaceRef& iface = dObj->getRemoteInterface(); if (iface) { HAGGLE_DBG2("Incoming data object [%s] has no valid peer node but valid peer interface %s\n", DataObject::idString(dObj).c_str(), iface->getIdentifierStr()); peer = kernel->getNodeStore()->retrieve(iface); if(peer && peer->getType() != Node::TYPE_UNDEFINED) HAGGLE_DBG2("Setting incoming data object peer node to %s\n", peer->getName().c_str()); } else { HAGGLE_DBG("No valid peer interface in data object, cannot figure out peer node\n"); } } if (peer) { if (peer->getType() != Node::TYPE_APPLICATION && peer->getType() != Node::TYPE_UNDEFINED) { // Add the data object to the peer's bloomfilter so that // we do not send the data object back. HAGGLE_DBG("Adding data object [%s] to peer node %s's (%s num=%lu) bloomfilter\n", DataObject::idString(dObj).c_str(), peer->getName().c_str(), peer->isStored() ? "stored" : "not stored", peer->getNum()); /* LOG_ADD("%s: BLOOMFILTER:ADD %s\t%s:%s\n", Timeval::now().getAsString().c_str(), dObj->getIdStr(), peer->getTypeStr(), peer->getIdStr()); */ peer->getBloomfilter()->add(dObj); } } else { HAGGLE_DBG("No valid peer node for incoming data object [%s]\n", dObj->getIdStr()); } // Check if this is a control message from an application. We do not want // to bloat our bloomfilter with such messages, because they are sent // everytime an application connects. if (!dObj->isControlMessage()) { // Add the incoming data object also to our own bloomfilter // We do this early in order to avoid receiving duplicates in case // the same object is received at nearly the same time from multiple neighbors if (localBF->has(dObj)) { HAGGLE_DBG("Data object [%s] already in our bloomfilter, marking as duplicate...\n", dObj->getIdStr()); dObj->setDuplicate(); } else { if(!dObj->isNodeDescription()) { // MOS - local BF only contains data objects in new design localBF->add(dObj); HAGGLE_DBG("Adding data object [%s] to our bloomfilter, #objs=%d\n", DataObject::idString(dObj).c_str(), localBF->numObjects()); kernel->getThisNode()->getBloomfilter()->add(dObj); // MOS if(isNodeDescUpdateOnReceptionEnabled) { // MOS - immediately disseminate updated bloomfilter kernel->getThisNode()->setNodeDescriptionCreateTime(); kernel->addEvent(new Event(EVENT_TYPE_NODE_DESCRIPTION_SEND)); } } if(!periodicBloomfilterUpdateEvent->isScheduled()) // MOS - update now happening periodically kernel->getThisNode()->setBloomfilter(*localBF, setCreateTimeOnBloomfilterUpdate); } } }