Exemple #1
0
void SecurityManager::onRepositoryData(Event *e)
{
	RepositoryEntryRef re;
	
	if (!e->getData()) {
		signalIsReadyForStartup();
		return;
	}
	
	HAGGLE_DBG("Got repository callback\n");
	
	DataStoreQueryResult *qr = static_cast < DataStoreQueryResult * >(e->getData());
	
	if (qr->countRepositoryEntries() == 0) {
		HAGGLE_DBG("No repository entries, generating new certificate and keypair\n");
		helper->addTask(new SecurityTask(SECURITY_TASK_GENERATE_CERTIFICATE));
		
		// Delay signalling that we are ready for startup until we get the 
		// task result indicating our certificate is ready.
		delete qr;
		return;
	}
	
	while ((re = qr->detachFirstRepositoryEntry())) {
		if (strcmp(re->getKey(), "privkey") == 0) {
			
			// Just to make sure
			if (privKey)
				RSA_free(privKey);
			
			privKey = stringToRSAKey(re->getValueStr(), KEY_TYPE_PRIVATE);
			
			HAGGLE_DBG("Read my own private key from repository\n");
		} else {
			CertificateRef c = Certificate::fromPEM(re->getValueStr());
			
			if (c) {
				if (c->getSubject() == kernel->getThisNode()->getIdStr())
					myCert = c;
				
				storeCertificate(c);
				HAGGLE_DBG("Read certificate for subject '%s' from repository\n", 
					   c->getSubject().c_str());
			} else {
				HAGGLE_ERR("Could not read certificate from repository\n");
			}
		}
	}
	
	delete qr;
	
	signalIsReadyForStartup();
}
bool ForwarderRank::setSaveState(RepositoryEntryRef& e)
{
	if (strcmp(e->getAuthority(), getName()) != 0)
		return false;
	
	string value = e->getValueStr();
	size_t pos = value.find(':');
	
	bubble_metric_t& metric = rib[id_from_string(e->getKey())];
	
	// The first part of the value is the label metric
	metric.first = value.substr(0, pos).c_str();
	// The second part is the rank
	metric.second = atol(value.substr(pos + 1).c_str());
	
	HAGGLE_DBG("HAGGLE_DBG: orig string=%s label=%s, rank=%ld\n", 
		e->getValue(), metric.first.c_str(), metric.second);
	
	rib_timestamp = Timeval::now();
	
	return true;
}
Exemple #3
0
void DataManager::onGetLocalBF(Event *e)
{
	if (!e || !e->hasData())
		return;
	
	DataStoreQueryResult *qr = static_cast < DataStoreQueryResult * >(e->getData());
	
	HAGGLE_DBG("Got repository callback\n");
	
	// Are there any repository entries?
	if (qr->countRepositoryEntries() != 0) {
		RepositoryEntryRef re;
		
		// Then this is most likely the local bloomfilter:
		
		re = qr->detachFirstRepositoryEntry();
		// Was there a repository entry? => was this really what we expected?
		if (re) {
			HAGGLE_DBG("Retrieved bloomfilter from data store\n");
			// Yes:
			
			Bloomfilter *tmpBF = Bloomfilter::create(re->getValueBlob(), re->getValueLen());

			if (tmpBF) {
				if (localBF)
					delete localBF;
				
				localBF = tmpBF;
				kernel->getThisNode()->setBloomfilter(*localBF, setCreateTimeOnBloomfilterUpdate);
			}
		}
		RepositoryEntryRef lbf = new RepositoryEntry("DataManager", "Local Bloomfilter");
		kernel->getDataStore()->deleteRepository(lbf);
	} else {
		// Don't do anything... for now.
	}
	
	delete qr;
}
Exemple #4
0
// SW: check if forwarder is interested in this repository data
bool Forwarder::isReleventRepositoryData(RepositoryEntryRef &re)
{
    return 0 == strcmp(re->getAuthority(), getName());
}