Commit 162ac4bd authored by Ivan Vilata-i-Balaguer's avatar Ivan Vilata-i-Balaguer
Browse files

Merge branch 'front-end-list-groups' into master.

This adds a link to the client front-end to retrieve a list of groups being
announced by this client.  Directly available as `/groups.txt` from the
front-end.
parents 9d00eb08 1f8032e0
......@@ -514,6 +514,10 @@ struct Client::Impl {
return *_newest_proto_seen;
}
std::set<std::string> get_announced_groups() const {
return _dht_groups->groups();
}
void set_log_level(log_level_t l) {
cerr << "Setting cache/client Cache log level to " << l << "\n";
_log_level = l;
......@@ -608,6 +612,11 @@ unsigned Client::get_newest_proto_version() const
return _impl->get_newest_proto_version();
}
std::set<std::string> Client::get_announced_groups() const
{
return _impl->get_announced_groups();
}
void Client::set_log_level(log_level_t l)
{
_impl->set_log_level(l);
......
......@@ -7,6 +7,7 @@
#include "cache_entry.h"
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/filesystem.hpp>
#include <set>
namespace ouinet {
......@@ -59,6 +60,10 @@ public:
// (e.g. to warn about potential upgrades).
unsigned get_newest_proto_version() const;
// Get all groups being announced to the distributed cache index
// by this client.
std::set<std::string> get_announced_groups() const;
~Client();
void set_log_level(log_level_t);
......
......@@ -180,6 +180,19 @@ static void load_log_file(stringstream& out_ss) {
, ostreambuf_iterator<char>(out_ss));
}
void ClientFrontEnd::handle_group_list( const Request&
, Response& res
, std::stringstream& ss
, cache::Client* cache_client)
{
res.set(http::field::content_type, "text/plain");
if (!cache_client) return;
for (const auto& g : cache_client->get_announced_groups())
ss << g << std::endl;
}
void ClientFrontEnd::handle_portal( ClientConfig& config
, const Request& req, Response& res, stringstream& ss
, cache::Client* cache_client
......@@ -329,6 +342,7 @@ void ClientFrontEnd::handle_portal( ClientConfig& config
"name=\"purge_cache\" "
"value=\"Purge cache now\"/>\n"
"</form>\n";
ss << "<a href=\"" << group_list_apath << "\">See announced groups</a>\n";
}
ss << " </body>\n"
......@@ -451,6 +465,8 @@ Response ClientFrontEnd::serve( ClientConfig& config
} else if (path == "/logfile.txt") {
res.set(http::field::content_type, "text/plain");
load_log_file(ss);
} else if (path == group_list_apath) {
handle_group_list(req, res, ss, cache_client);
} else if (path == "/api/status") {
sys::error_code e;
handle_status( config, udp_port, upnps, reachability
......
......@@ -34,6 +34,11 @@ class ClientFrontEnd {
= boost::intrusive::list_base_hook
<boost::intrusive::link_mode
<boost::intrusive::auto_unlink>>;
public:
// Absolute paths of allowed URLs.
inline static const std::string group_list_apath = "/groups.txt";
public:
using Request = http::request<http::string_body>;
using Response = http::response<http::dynamic_body>;
......@@ -95,6 +100,11 @@ private:
void handle_ca_pem( const Request&, Response&, std::stringstream&
, const CACertificate& );
void handle_group_list( const Request&
, Response&
, std::stringstream&
, cache::Client*);
void handle_portal( ClientConfig&
, const Request&
, Response&
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment