Added bad and duplicate message counters to socket_session (#55)

This commit is contained in:
Ravin Perera
2019-11-07 06:57:34 +05:30
committed by GitHub
parent 8a153d5bb5
commit d16b43406b
13 changed files with 210 additions and 215 deletions

View File

@@ -1,6 +1,7 @@
#include "../pchheader.hpp"
#include "../jsonschema/usrmsg_helpers.hpp"
#include "../sock/socket_server.hpp"
#include "../sock/socket_session.hpp"
#include "../sock/socket_session_handler.hpp"
#include "../util.hpp"
#include "../conf.hpp"
@@ -81,8 +82,8 @@ int verify_challenge(std::string_view message, sock::socket_session<user_outboun
// All good. Unique public key.
// Promote the connection from pending-challenges to authenticated users.
session->flags.reset(util::SESSION_FLAG::USER_CHALLENGE_ISSUED); // Clear challenge-issued flag
session->flags.set(util::SESSION_FLAG::USER_AUTHED); // Set the user-authed flag
session->flags.reset(sock::SESSION_FLAG::USER_CHALLENGE_ISSUED); // Clear challenge-issued flag
session->flags.set(sock::SESSION_FLAG::USER_AUTHED); // Set the user-authed flag
add_user(session, userpubkey); // Add the user to the global authed user list
ctx.pending_challenges.erase(session->uniqueid); // Remove the stored challenge
@@ -203,15 +204,16 @@ void start_listening()
{
auto address = net::ip::make_address(conf::cfg.listenip);
listener_ctx.sess_opts.max_message_size = conf::cfg.pubmaxsize;
listener_ctx.sess_opts.max_bytes_per_minute = conf::cfg.pubmaxcpm;
listener_ctx.default_sess_opts.max_socket_read_len = conf::cfg.pubmaxsize;
listener_ctx.default_sess_opts.max_rawbytes_per_minute = conf::cfg.pubmaxcpm;
listener_ctx.default_sess_opts.max_badmsgs_per_minute = conf::cfg.pubmaxbadmpm;
std::make_shared<sock::socket_server<user_outbound_message>>(
listener_ctx.ioc,
listener_ctx.ssl_ctx,
tcp::endpoint{address, conf::cfg.pubport},
listener_ctx.global_usr_session_handler,
listener_ctx.sess_opts)
listener_ctx.default_sess_opts)
->run();
listener_ctx.listener_thread = std::thread([&] { listener_ctx.ioc.run(); });