Skip to content

Commit

Permalink
add also Neighbor singleton's to_json
Browse files Browse the repository at this point in the history
- fix ridiculous curly braces in json initializer lists
  • Loading branch information
astibal committed Apr 20, 2024
1 parent 47ea9f0 commit d10efe8
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/proxy/nbrhood.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ struct Neighbor {
}

[[nodiscard]] nlohmann::json to_json() const {
return { {"counter"}, {counter} };
auto now_de = epoch_days(time(nullptr));

return { now_de - days_epoch, counter };
}
};
using stats_lists_t = std::vector<stats_entry_t>;
Expand Down Expand Up @@ -109,9 +111,9 @@ struct Neighbor {
}

return {
{ {"hostname"}, { hostname } },
{ {"last_seen"}, { last_seen} },
{ {"stats"}, { js } }
{ "hostname", hostname },
{ "last_seen", last_seen },
{ "stats", js }
};
}

Expand Down Expand Up @@ -143,6 +145,8 @@ class NbrHood {
explicit NbrHood(size_t max_size): nbrs_(max_size) {}

nbr_cache_t& cache() { return nbrs_; }
nbr_cache_t const& cache() const { return nbrs_; }

void update(Neighbor const& n) {
auto lc_ = std::scoped_lock(cache().lock());

Expand All @@ -155,6 +159,18 @@ class NbrHood {
}
}

[[nodiscard]] nlohmann::json to_json() const {
auto lc_ = std::scoped_lock(cache().lock());

auto ret = nlohmann::json();

for(auto const& [ _, nbr]: cache().get_map_ul()) {
ret.push_back( nbr.first->to_json());
}

return ret;
}

static NbrHood& instance() {
static NbrHood r(1000);
return r;
Expand Down

0 comments on commit d10efe8

Please sign in to comment.