1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-11-27 00:43:47 +00:00

Delay fast subsequent pasties from the same IP.

This commit is contained in:
King_DuckZ 2017-05-11 18:50:56 +01:00
parent 9e63a648a1
commit f286507edf
3 changed files with 11 additions and 6 deletions

@ -1 +1 @@
Subproject commit 9eca0bf5cb042c4cf5a7bc09a0edbec0b51fbfce
Subproject commit fbd39c27991a3f7335f0f606f7e047bff31fa288

View file

@ -71,7 +71,7 @@ namespace {
parSettings.add_default("max_pastie_size", "10000");
parSettings.add_default("truncate_long_pasties", "false");
parSettings.add_default("logging_level", "err");
parSettings.add_default("submit_min_wait", "10");
parSettings.add_default("resubmit_wait", "10");
}
} //unnamed namespace

View file

@ -30,6 +30,7 @@
#include <algorithm>
#include <boost/lexical_cast.hpp>
#include <cstdint>
#include <spdlog/spdlog.h>
extern "C" void tiger (const char* parStr, uint64_t parLength, uint64_t parHash[3], char parPadding);
@ -65,12 +66,14 @@ namespace tawashi {
}
std::string hashed_ip (const std::string& parIP) {
using dhandy::tags::hex;
uint64_t hash[3];
tiger(parIP.data(), parIP.size(), hash, 0x80);
auto h1 = dhandy::int_to_string_ary<char>(hash[0]);
auto h2 = dhandy::int_to_string_ary<char>(hash[1]);
auto h3 = dhandy::int_to_string_ary<char>(hash[2]);
auto h1 = dhandy::int_to_string_ary<char, hex>(hash[0]);
auto h2 = dhandy::int_to_string_ary<char, hex>(hash[1]);
auto h3 = dhandy::int_to_string_ary<char, hex>(hash[2]);
std::string retval(2 * sizeof(uint64_t) * 3, '0');
assert(h1.size() <= 2 * sizeof(uint64_t));
@ -80,6 +83,8 @@ namespace tawashi {
assert(h3.size() <= 2 * sizeof(uint64_t));
std::copy(h3.begin(), h3.end(), retval.begin() + 2 * sizeof(uint64_t) * 2 + 2 * sizeof(uint64_t) - h3.size());
SPDLOG_DEBUG(spdlog::get("statuslog"), "IP \"{}\" hashed -> \"{}\"", parIP, retval);
assert(retval.size() == 16 * 3);
return retval;
}
} //unnamed namespace
@ -156,7 +161,7 @@ namespace tawashi {
"lang", parLang)
) {
redis.set(ip_hash, "");
redis.expire(ip_hash, settings().as<uint32_t>("submit_min_wait"));
redis.expire(ip_hash, settings().as<uint32_t>("resubmit_wait"));
if (redis.expire(token, parExpiry))
return boost::make_optional(token);
}