Fix republish doing weird things

This commit is contained in:
Théophile Bastian 2016-11-27 09:31:06 +01:00
parent 676a3822ed
commit 574bef34e2
3 changed files with 15 additions and 7 deletions

View file

@ -7,6 +7,7 @@
#include "dataStore.h"
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
DataStore::DataStore(Protocol* proto) : proto(proto)
@ -17,7 +18,7 @@ DataStore::~DataStore() {
void DataStore::update() {
while(!timeEvents.empty()) {
const TimeEvent& evt = timeEvents.top();
TimeEvent evt = timeEvents.top();
if(evt.time > time(NULL)) // We're done for now.
break;
@ -89,12 +90,18 @@ void DataStore::handleExpire(u64 id, u32 seqno) {
cleanData(id);
}
void DataStore::handleRepublish(u64 id) {
if(data.find(id) == data.end() || !data[id].isMine)
void DataStore::handleRepublish(u64 datId) {
if(data.find(datId) == data.end() || !data[datId].isMine) {
return;
}
curSeqno[id] = time(NULL);
handleFlood(id);
curSeqno[datId] = time(NULL);
timeEvents.push(TimeEvent(
time(NULL) + csts::TIME_REPUBLISH_DATA,
curSeqno[datId], datId, EV_REPUBLISH));
handleFlood(datId);
}
void DataStore::handleFlood(u64 id) {

View file

@ -57,7 +57,7 @@ class DataStore {
private: //meth
void handleExpire(u64 id, u32 seqno);
void handleRepublish(u64 id);
void handleRepublish(u64 datId);
void handleFlood(u64 id);
void cleanData(u64 id);

View file

@ -56,7 +56,8 @@ int main(int argc, char** argv) {
for(u8 chr : dat.second)
pck << chr;
dataStore.addData(pck, time(NULL), dat.first, true);
fprintf(stderr, "[INFO] Adding data `%s`\n", dat.second.c_str());
fprintf(stderr, "[INFO] Adding data `%s` (%lX)\n",
dat.second.c_str(), dat.first);
}
Neighbours neighboursManager(&proto, &dataStore);