Skip to content

Commit

Permalink
improve output somewhat (add tracker name when reporting a match), cl…
Browse files Browse the repository at this point in the history
…ean up code a bit
  • Loading branch information
berthubert committed Apr 25, 2024
1 parent 9fb8857 commit ef47d7c
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions teller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using namespace std;

struct TrackerConf
{
string name; // superfluous but makes life easier
double freq{400};
double balance{0.5}; // 0 is left, 1 is right
std::atomic<int64_t> counter{0};
Expand Down Expand Up @@ -86,6 +87,7 @@ int main(int argc, char** argv)
auto tellerarr = conftbl.as_table();
for(const auto& t : *tellerarr) {
auto& entry = trackerdb[(string)t.first];
entry.name = t.first;
entry.balance = conftbl[t.first]["balance"].value_or(0.5);
entry.freq = conftbl[t.first]["freq"].value_or(500);
cout <<"Want to play sound for tracker "<<t.first<<", balance= "<<entry.balance<<" frequency = "<<entry.freq<<endl;
Expand Down Expand Up @@ -113,7 +115,7 @@ int main(int argc, char** argv)
});
}
else {
cout<<"Not array?"<<endl;
cout<<"Not array, or empty"<<endl;
}

track = trackertbl[t.first]["negative"].as_array();
Expand All @@ -126,7 +128,7 @@ int main(int argc, char** argv)
});
}
else {
cout<<"Negative "<<t.first<<" not array?"<<endl;
cout<<"Negative "<<t.first<<" not array, or empty"<<endl;
}
}

Expand All @@ -150,17 +152,19 @@ int main(int argc, char** argv)
auto pos = line.find('>');
if(pos == string::npos)
continue;
auto pos2 = line.find('.', pos);
auto pos2 = line.find('.', pos); // this misses out on IPv6 ICMP
if(pos2 == string::npos) continue;
line.resize(pos2);
string ip = line.substr(pos+2, pos2 - pos - 2);

if(tracksneg.lookup(&line.at(pos+2))) {
cout<<ip<<" negative match"<<endl;
if(auto fptr = tracksneg.lookup(ip.c_str())) {
auto ptr = (TrackerConf*)fptr;
cout<<ip<<" negative match ("<<ptr->name<<")"<<endl;
}
else if(auto fptr = trackspos.lookup(&line.at(pos+2))) {
cout<<ip<<" match!"<<endl;
((TrackerConf*)fptr)->counter++;
else if(auto fptr = trackspos.lookup(ip.c_str())) {
auto ptr = (TrackerConf*)fptr;
cout<<ip<<" match ("<<ptr->name<<")"<<endl;
ptr->counter++;
}
}
else {
Expand All @@ -179,13 +183,15 @@ int main(int argc, char** argv)

line.resize(pos2);
string ip=line.substr(pos+2, pos2 - pos - 2);
// cout<<&line.at(pos+2)<<endl;
if(tracksneg.lookup(&line.at(pos+2))) {
cout<<ip<<" negative match"<<endl;

if(auto fptr = tracksneg.lookup(ip.c_str())) {
auto ptr = (TrackerConf*)fptr;
cout<<ip<<" negative match ("<<ptr->name<<")"<<endl;
}
else if(auto fptr = trackspos.lookup(&line.at(pos+2))) {
cout<<ip<<" match!"<<endl;
((TrackerConf*)fptr)->counter++;
else if(auto fptr = trackspos.lookup(ip.c_str())) {
auto ptr = (TrackerConf*)fptr;
cout<<ip<<" match ("<<ptr->name<<")"<<endl;
ptr->counter++;
}
}

Expand Down

0 comments on commit ef47d7c

Please sign in to comment.