Conform to datId = senderId
This commit is contained in:
parent
6d3774bc99
commit
9104f40aaf
4 changed files with 46 additions and 32 deletions
|
@ -10,7 +10,7 @@
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ConfigFile::ConfigFile() {
|
ConfigFile::ConfigFile() : curDataSum(0) {
|
||||||
selfId = randId();
|
selfId = randId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,11 +48,6 @@ bool ConfigFile::read(const char* path) {
|
||||||
bootstrapNodes.push_back(Neighbour(id, addr));
|
bootstrapNodes.push_back(Neighbour(id, addr));
|
||||||
}
|
}
|
||||||
else if(attr == "data") {
|
else if(attr == "data") {
|
||||||
u64 id;
|
|
||||||
handle >> hex >> id >> dec;
|
|
||||||
if(id == 0)
|
|
||||||
id = randId();
|
|
||||||
|
|
||||||
string dataStr;
|
string dataStr;
|
||||||
getline(handle, dataStr);
|
getline(handle, dataStr);
|
||||||
|
|
||||||
|
@ -63,7 +58,16 @@ bool ConfigFile::read(const char* path) {
|
||||||
if(nonWSPos == dataStr.size())
|
if(nonWSPos == dataStr.size())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
data.push_back(make_pair(id, dataStr.substr(nonWSPos)));
|
std::string realDat = dataStr.substr(nonWSPos);
|
||||||
|
if(curDataSum + realDat.size() + 12 + 2 > 0xff) {
|
||||||
|
fprintf(stderr, "Too much data, won't fit. Discarding `%s`\n",
|
||||||
|
realDat.c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
curDataSum += realDat.size() + 2;
|
||||||
|
|
||||||
|
data.push_back(realDat);
|
||||||
}
|
}
|
||||||
else if(attr.empty())
|
else if(attr.empty())
|
||||||
continue;
|
continue;
|
||||||
|
@ -96,8 +100,7 @@ bool ConfigFile::write(const char* path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto dat : data) {
|
for(auto dat : data) {
|
||||||
handle << "data " << hex << dat.first << dec << " "
|
handle << "data " << dat << '\n';
|
||||||
<< dat.second << '\n';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handle.close();
|
handle.close();
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
class ConfigFile {
|
class ConfigFile {
|
||||||
public:
|
public:
|
||||||
|
typedef std::string CfgData;
|
||||||
ConfigFile();
|
ConfigFile();
|
||||||
|
|
||||||
bool read(const char* path);
|
bool read(const char* path);
|
||||||
|
@ -26,7 +27,7 @@ class ConfigFile {
|
||||||
};
|
};
|
||||||
/** Bootstrap nodes. No setter: wouldn't be useful. */
|
/** Bootstrap nodes. No setter: wouldn't be useful. */
|
||||||
|
|
||||||
const std::vector<std::pair<u64, std::string> >& getData() const {
|
const std::vector<CfgData>& getData() const {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
/** Data to publish. */
|
/** Data to publish. */
|
||||||
|
@ -36,6 +37,7 @@ class ConfigFile {
|
||||||
|
|
||||||
u64 selfId;
|
u64 selfId;
|
||||||
std::vector<Neighbour> bootstrapNodes;
|
std::vector<Neighbour> bootstrapNodes;
|
||||||
std::vector<std::pair<u64, std::string> > data;
|
std::vector<CfgData> data;
|
||||||
|
size_t curDataSum;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -85,22 +85,31 @@ void DataStore::setFlooded(u64 id) {
|
||||||
|
|
||||||
void DataStore::dump() {
|
void DataStore::dump() {
|
||||||
for(auto it=data.begin(); it != data.end(); ++it) {
|
for(auto it=data.begin(); it != data.end(); ++it) {
|
||||||
printf(">> DATA %lX (%u) ", it->first, curSeqno[it->first]);
|
|
||||||
Bytes dat = it->second.data;
|
Bytes dat = it->second.data;
|
||||||
if(dat.size() < 2) {
|
while(dat.size() >= 2) {
|
||||||
printf("INVALID\n");
|
printf(">> DATA %lX (%u) ", it->first, curSeqno[it->first]);
|
||||||
continue;
|
if(dat.size() < 2) {
|
||||||
|
printf("INVALID\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
u8 type, len;
|
||||||
|
dat >> type >> len;
|
||||||
|
if(dat.size() < len) {
|
||||||
|
printf("INVALID\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(type == csts::TLV_DATA_TEXT) {
|
||||||
|
string val;
|
||||||
|
for(int i=0; i < len; i++) {
|
||||||
|
u8 c;
|
||||||
|
dat >> c;
|
||||||
|
val += c;
|
||||||
|
}
|
||||||
|
printf("'%s'\n", val.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("type=%d\n", type);
|
||||||
}
|
}
|
||||||
u8 type, len;
|
|
||||||
dat >> type >> len;
|
|
||||||
if(type == csts::TLV_DATA_TEXT) {
|
|
||||||
char val[1024];
|
|
||||||
dat.writeToBuffer(val, 1023);
|
|
||||||
val[min((int)dat.size(), 1023)] = '\0';
|
|
||||||
printf("'%s'\n", val);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printf("type=%d\n", type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
main.cpp
14
main.cpp
|
@ -70,15 +70,15 @@ int main(int argc, char** argv) {
|
||||||
Protocol proto(addr, cfg.getSelfId());
|
Protocol proto(addr, cfg.getSelfId());
|
||||||
|
|
||||||
DataStore dataStore(&proto);
|
DataStore dataStore(&proto);
|
||||||
|
Bytes selfData;
|
||||||
for(auto dat : cfg.getData()) {
|
for(auto dat : cfg.getData()) {
|
||||||
Bytes pck;
|
selfData << csts::TLV_DATA_TEXT << (u8)dat.size();
|
||||||
pck << csts::TLV_DATA_TEXT << (u8)dat.second.size();
|
for(u8 chr : dat)
|
||||||
for(u8 chr : dat.second)
|
selfData << chr;
|
||||||
pck << chr;
|
fprintf(stderr, "[INFO] Adding data `%s`\n",
|
||||||
dataStore.addData(pck, time(NULL), dat.first, true);
|
dat.c_str());
|
||||||
fprintf(stderr, "[INFO] Adding data `%s` (%lX)\n",
|
|
||||||
dat.second.c_str(), dat.first);
|
|
||||||
}
|
}
|
||||||
|
dataStore.addData(selfData, time(NULL), cfg.getSelfId(), true);
|
||||||
|
|
||||||
Neighbours neighboursManager(&proto, &dataStore);
|
Neighbours neighboursManager(&proto, &dataStore);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue