Fix republish doing weird things
This commit is contained in:
parent
676a3822ed
commit
574bef34e2
3 changed files with 15 additions and 7 deletions
|
@ -7,6 +7,7 @@
|
||||||
#include "dataStore.h"
|
#include "dataStore.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstdlib>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
DataStore::DataStore(Protocol* proto) : proto(proto)
|
DataStore::DataStore(Protocol* proto) : proto(proto)
|
||||||
|
@ -17,7 +18,7 @@ DataStore::~DataStore() {
|
||||||
|
|
||||||
void DataStore::update() {
|
void DataStore::update() {
|
||||||
while(!timeEvents.empty()) {
|
while(!timeEvents.empty()) {
|
||||||
const TimeEvent& evt = timeEvents.top();
|
TimeEvent evt = timeEvents.top();
|
||||||
if(evt.time > time(NULL)) // We're done for now.
|
if(evt.time > time(NULL)) // We're done for now.
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -89,12 +90,18 @@ void DataStore::handleExpire(u64 id, u32 seqno) {
|
||||||
cleanData(id);
|
cleanData(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::handleRepublish(u64 id) {
|
void DataStore::handleRepublish(u64 datId) {
|
||||||
if(data.find(id) == data.end() || !data[id].isMine)
|
if(data.find(datId) == data.end() || !data[datId].isMine) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
curSeqno[id] = time(NULL);
|
curSeqno[datId] = time(NULL);
|
||||||
handleFlood(id);
|
|
||||||
|
timeEvents.push(TimeEvent(
|
||||||
|
time(NULL) + csts::TIME_REPUBLISH_DATA,
|
||||||
|
curSeqno[datId], datId, EV_REPUBLISH));
|
||||||
|
|
||||||
|
handleFlood(datId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataStore::handleFlood(u64 id) {
|
void DataStore::handleFlood(u64 id) {
|
||||||
|
|
|
@ -57,7 +57,7 @@ class DataStore {
|
||||||
|
|
||||||
private: //meth
|
private: //meth
|
||||||
void handleExpire(u64 id, u32 seqno);
|
void handleExpire(u64 id, u32 seqno);
|
||||||
void handleRepublish(u64 id);
|
void handleRepublish(u64 datId);
|
||||||
void handleFlood(u64 id);
|
void handleFlood(u64 id);
|
||||||
|
|
||||||
void cleanData(u64 id);
|
void cleanData(u64 id);
|
||||||
|
|
3
main.cpp
3
main.cpp
|
@ -56,7 +56,8 @@ int main(int argc, char** argv) {
|
||||||
for(u8 chr : dat.second)
|
for(u8 chr : dat.second)
|
||||||
pck << chr;
|
pck << chr;
|
||||||
dataStore.addData(pck, time(NULL), dat.first, true);
|
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);
|
Neighbours neighboursManager(&proto, &dataStore);
|
||||||
|
|
Loading…
Reference in a new issue