campaignd: Allow exempting hostmasks from download count bumps
This commit is contained in:
parent
09a1aeb0ab
commit
ba61721ba3
2 changed files with 21 additions and 1 deletions
|
@ -156,6 +156,7 @@ server::server(const std::string& cfg_file, size_t min_threads, size_t max_threa
|
|||
, feedback_url_format_()
|
||||
, blacklist_()
|
||||
, blacklist_file_()
|
||||
, stats_exempt_ips_()
|
||||
, port_(load_config())
|
||||
, net_manager_(min_threads, max_threads)
|
||||
, server_manager_(port_)
|
||||
|
@ -219,6 +220,8 @@ int server::load_config()
|
|||
blacklist_file_ = cfg_["blacklist_file"].str();
|
||||
load_blacklist();
|
||||
|
||||
stats_exempt_ips_ = utils::split(cfg_["stats_exempt_ips"].str());
|
||||
|
||||
// Load any configured hooks.
|
||||
hooks_.insert(std::make_pair(std::string("hook_post_upload"), cfg_["hook_post_upload"]));
|
||||
hooks_.insert(std::make_pair(std::string("hook_post_erase"), cfg_["hook_post_erase"]));
|
||||
|
@ -319,6 +322,18 @@ void server::fire(const std::string& hook, const std::string& addon)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool server::ignore_address_stats(const std::string& addr) const
|
||||
{
|
||||
BOOST_FOREACH(const std::string& mask, stats_exempt_ips_) {
|
||||
// TODO: we want CIDR subnet mask matching here, not glob matching!
|
||||
if(utils::wildcard_string_match(addr, mask)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void server::send_message(const std::string& msg, network::connection sock)
|
||||
{
|
||||
config cfg;
|
||||
|
@ -612,7 +627,7 @@ void server::handle_request_campaign(const server::request& req)
|
|||
// Clients doing upgrades or some other specific thing shouldn't bump
|
||||
// the downloads count. Default to true for compatibility with old
|
||||
// clients that won't tell us what they are trying to do.
|
||||
if(req.cfg["increase_downloads"].to_bool(true)) {
|
||||
if(req.cfg["increase_downloads"].to_bool(true) && !ignore_address_stats(req.addr)) {
|
||||
const int downloads = campaign["downloads"].to_int() + 1;
|
||||
campaign["downloads"] = downloads;
|
||||
}
|
||||
|
|
|
@ -97,6 +97,8 @@ private:
|
|||
blacklist blacklist_;
|
||||
std::string blacklist_file_;
|
||||
|
||||
std::vector<std::string> stats_exempt_ips_;
|
||||
|
||||
int port_;
|
||||
|
||||
const network::manager net_manager_;
|
||||
|
@ -139,6 +141,9 @@ private:
|
|||
/** Retrieves the contents of the [server_info] WML node. */
|
||||
config& server_info() { return cfg_.child("server_info"); }
|
||||
|
||||
/** Checks if the specified address should never bump download counts. */
|
||||
bool ignore_address_stats(const std::string& addr) const;
|
||||
|
||||
//
|
||||
// Request handling.
|
||||
//
|
||||
|
|
Loading…
Add table
Reference in a new issue