diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index 09bbc2bd5f..eacd825e0f 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -123,7 +123,7 @@ namespace eosio { std::map categories_by_address; - http_plugin_state plugin_state{logger()}; + std::shared_ptr plugin_state{new http_plugin_state(logger())}; std::atomic listening; @@ -202,7 +202,7 @@ namespace eosio { return true; auto [host, port] = fc::split_host_port(address); boost::system::error_code ec; - tcp::resolver resolver(plugin_state.thread_pool.get_executor()); + tcp::resolver resolver(plugin_state->thread_pool.get_executor()); auto endpoints = resolver.resolve(host, port, boost::asio::ip::tcp::resolver::passive, ec); if (ec) { fc_wlog(logger(), "Cannot resolve address ${addr}: ${msg}", ("addr", address)("msg", ec.message())); @@ -232,7 +232,7 @@ namespace eosio { ->run_session(); }; - fc::create_listener(plugin_state.thread_pool.get_executor(), logger(), accept_timeout, address, + fc::create_listener(plugin_state->thread_pool.get_executor(), logger(), accept_timeout, address, extra_listening_log_info, create_session); } @@ -328,33 +328,33 @@ namespace eosio { cfg.add_options() ("access-control-allow-origin", bpo::value()->notifier([this](const string& v) { - my->plugin_state.access_control_allow_origin = v; + my->plugin_state->access_control_allow_origin = v; fc_ilog( logger(), "configured http with Access-Control-Allow-Origin: ${o}", - ("o", my->plugin_state.access_control_allow_origin) ); + ("o", my->plugin_state->access_control_allow_origin) ); }), "Specify the Access-Control-Allow-Origin to be returned on each request") ("access-control-allow-headers", bpo::value()->notifier([this](const string& v) { - my->plugin_state.access_control_allow_headers = v; + my->plugin_state->access_control_allow_headers = v; fc_ilog( logger(), "configured http with Access-Control-Allow-Headers : ${o}", - ("o", my->plugin_state.access_control_allow_headers) ); + ("o", my->plugin_state->access_control_allow_headers) ); }), "Specify the Access-Control-Allow-Headers to be returned on each request") ("access-control-max-age", bpo::value()->notifier([this](const string& v) { - my->plugin_state.access_control_max_age = v; + my->plugin_state->access_control_max_age = v; fc_ilog( logger(), "configured http with Access-Control-Max-Age : ${o}", - ("o", my->plugin_state.access_control_max_age) ); + ("o", my->plugin_state->access_control_max_age) ); }), "Specify the Access-Control-Max-Age to be returned on each request.") ("access-control-allow-credentials", bpo::bool_switch()->notifier([this](bool v) { - my->plugin_state.access_control_allow_credentials = v; + my->plugin_state->access_control_allow_credentials = v; if( v ) fc_ilog( logger(), "configured http with Access-Control-Allow-Credentials: true" ); })->default_value(false), "Specify if Access-Control-Allow-Credentials: true should be returned on each request.") - ("max-body-size", bpo::value()->default_value(my->plugin_state.max_body_size), + ("max-body-size", bpo::value()->default_value(my->plugin_state->max_body_size), "The maximum body size in bytes allowed for incoming RPC requests") ("http-max-bytes-in-flight-mb", bpo::value()->default_value(500), "Maximum size in megabytes http_plugin should use for processing http requests. -1 for unlimited. 429 error response when exceeded." ) @@ -368,7 +368,7 @@ namespace eosio { "If set to false, then any incoming \"Host\" header is considered valid") ("http-alias", bpo::value>()->composing(), "Additionally acceptable values for the \"Host\" header of incoming HTTP requests, can be specified multiple times. Includes http/s_server_address by default.") - ("http-threads", bpo::value()->default_value( my->plugin_state.thread_pool_size ), + ("http-threads", bpo::value()->default_value( my->plugin_state->thread_pool_size ), "Number of worker threads in http thread pool") ("http-keep-alive", bpo::value()->default_value(true), "If set to false, do not keep HTTP connections alive, even if client requests.") @@ -378,38 +378,38 @@ namespace eosio { void http_plugin::plugin_initialize(const variables_map& options) { try { handle_sighup(); // setup logging - my->plugin_state.max_body_size = options.at( "max-body-size" ).as(); + my->plugin_state->max_body_size = options.at( "max-body-size" ).as(); verbose_http_errors = options.at( "verbose-http-errors" ).as(); - my->plugin_state.thread_pool_size = options.at( "http-threads" ).as(); - EOS_ASSERT( my->plugin_state.thread_pool_size > 0, chain::plugin_config_exception, - "http-threads ${num} must be greater than 0", ("num", my->plugin_state.thread_pool_size)); + my->plugin_state->thread_pool_size = options.at( "http-threads" ).as(); + EOS_ASSERT( my->plugin_state->thread_pool_size > 0, chain::plugin_config_exception, + "http-threads ${num} must be greater than 0", ("num", my->plugin_state->thread_pool_size)); auto max_bytes_mb = options.at( "http-max-bytes-in-flight-mb" ).as(); EOS_ASSERT( (max_bytes_mb >= -1 && max_bytes_mb < std::numeric_limits::max() / (1024 * 1024)), chain::plugin_config_exception, "http-max-bytes-in-flight-mb (${max_bytes_mb}) must be equal to or greater than -1 and less than ${max}", ("max_bytes_mb", max_bytes_mb) ("max", std::numeric_limits::max() / (1024 * 1024)) ); if ( max_bytes_mb == -1 ) { - my->plugin_state.max_bytes_in_flight = std::numeric_limits::max(); + my->plugin_state->max_bytes_in_flight = std::numeric_limits::max(); } else { - my->plugin_state.max_bytes_in_flight = max_bytes_mb * 1024 * 1024; + my->plugin_state->max_bytes_in_flight = max_bytes_mb * 1024 * 1024; } - my->plugin_state.max_requests_in_flight = options.at( "http-max-in-flight-requests" ).as(); + my->plugin_state->max_requests_in_flight = options.at( "http-max-in-flight-requests" ).as(); int64_t max_reponse_time_ms = options.at("http-max-response-time-ms").as(); EOS_ASSERT( max_reponse_time_ms == -1 || max_reponse_time_ms >= 0, chain::plugin_config_exception, "http-max-response-time-ms must be -1, or non-negative: ${m}", ("m", max_reponse_time_ms) ); - my->plugin_state.max_response_time = max_reponse_time_ms == -1 ? + my->plugin_state->max_response_time = max_reponse_time_ms == -1 ? fc::microseconds::maximum() : fc::microseconds( max_reponse_time_ms * 1000 ); - my->plugin_state.validate_host = options.at("http-validate-host").as(); + my->plugin_state->validate_host = options.at("http-validate-host").as(); if( options.count( "http-alias" )) { const auto& aliases = options["http-alias"].as>(); for (const auto& alias : aliases ) { auto [host, port] = fc::split_host_port(alias); - my->plugin_state.valid_hosts.insert(host); + my->plugin_state->valid_hosts.insert(host); } } - my->plugin_state.keep_alive = options.at("http-keep-alive").as(); + my->plugin_state->keep_alive = options.at("http-keep-alive").as(); std::string http_server_address; if (options.count("http-server-address")) { @@ -467,7 +467,7 @@ namespace eosio { my->categories_by_address[address].insert(category); } } - my->plugin_state.server_header = current_http_plugin_defaults.server_header; + my->plugin_state->server_header = current_http_plugin_defaults.server_header; //watch out for the returns above when adding new code here @@ -479,7 +479,7 @@ namespace eosio { { // The reason we post here is because we want blockchain replay to happen before we start listening. try { - my->plugin_state.thread_pool.start( my->plugin_state.thread_pool_size, [](const fc::exception& e) { + my->plugin_state->thread_pool.start( my->plugin_state->thread_pool_size, [](const fc::exception& e) { fc_elog( logger(), "Exception in http thread pool, exiting: ${e}", ("e", e.to_detail_string()) ); app().quit(); } ); @@ -507,10 +507,10 @@ namespace eosio { } void http_plugin::plugin_shutdown() { - my->plugin_state.thread_pool.stop(); + my->plugin_state->thread_pool.stop(); // release http_plugin_impl_ptr shared_ptrs captured in url handlers - my->plugin_state.url_handlers.clear(); + my->plugin_state->url_handlers.clear(); fc_ilog( logger(), "exit shutdown"); } @@ -528,20 +528,20 @@ namespace eosio { void http_plugin::add_handler(api_entry&& entry, appbase::exec_queue q, int priority, http_content_type content_type) { log_add_handler(my.get(), entry); std::string path = entry.path; - auto p = my->plugin_state.url_handlers.emplace(path, my->make_app_thread_url_handler(std::move(entry), q, priority, my, content_type)); + auto p = my->plugin_state->url_handlers.emplace(path, my->make_app_thread_url_handler(std::move(entry), q, priority, my, content_type)); EOS_ASSERT( p.second, chain::plugin_config_exception, "http url ${u} is not unique", ("u", path) ); } void http_plugin::add_async_handler(api_entry&& entry, http_content_type content_type) { log_add_handler(my.get(), entry); std::string path = entry.path; - auto p = my->plugin_state.url_handlers.emplace(path, my->make_http_thread_url_handler(std::move(entry), content_type)); + auto p = my->plugin_state->url_handlers.emplace(path, my->make_http_thread_url_handler(std::move(entry), content_type)); EOS_ASSERT( p.second, chain::plugin_config_exception, "http url ${u} is not unique", ("u", path) ); } void http_plugin::post_http_thread_pool(std::function f) { if( f ) - boost::asio::post( my->plugin_state.thread_pool.get_executor(), f ); + boost::asio::post( my->plugin_state->thread_pool.get_executor(), f ); } void http_plugin::handle_exception( const char* api_name, const char* call_name, const string& body, const url_response_callback& cb) { @@ -613,15 +613,15 @@ namespace eosio { } fc::microseconds http_plugin::get_max_response_time()const { - return my->plugin_state.max_response_time; + return my->plugin_state->max_response_time; } size_t http_plugin::get_max_body_size()const { - return my->plugin_state.max_body_size; + return my->plugin_state->max_body_size; } void http_plugin::register_update_metrics(std::function&& fun) { - my->plugin_state.update_metrics = std::move(fun); + my->plugin_state->update_metrics = std::move(fun); } std::atomic& http_plugin::listening() { diff --git a/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp b/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp index 4ad2d928f0..dac0468216 100644 --- a/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp +++ b/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp @@ -69,6 +69,8 @@ std::string to_log_string(const T& req, size_t max_size = 1024) { template class beast_http_session : public detail::abstract_conn, public std::enable_shared_from_this> { + + std::shared_ptr plugin_state_; Socket socket_; api_category_set categories_; beast::flat_buffer buffer_; @@ -83,7 +85,6 @@ class beast_http_session : public detail::abstract_conn, // HTTP response object std::optional> res_; - http_plugin_state& plugin_state_; std::string remote_endpoint_; std::string local_address_; @@ -112,12 +113,12 @@ class beast_http_session : public detail::abstract_conn, res_->version(req.version()); res_->set(http::field::content_type, "application/json"); res_->keep_alive(req.keep_alive()); - if(plugin_state_.server_header.size()) - res_->set(http::field::server, plugin_state_.server_header); + if(plugin_state_->server_header.size()) + res_->set(http::field::server, plugin_state_->server_header); // Request path must be absolute and not contain "..". if(req.target().empty() || req.target()[0] != '/' || req.target().find("..") != beast::string_view::npos) { - fc_dlog( plugin_state_.get_logger(), "Return bad_reqest: ${target}", ("target", std::string(req.target())) ); + fc_dlog( plugin_state_->get_logger(), "Return bad_reqest: ${target}", ("target", std::string(req.target())) ); error_results results{static_cast(http::status::bad_request), "Illegal request-target"}; send_response( fc::json::to_string( results, fc::time_point::maximum() ), static_cast(http::status::bad_request) ); @@ -126,23 +127,23 @@ class beast_http_session : public detail::abstract_conn, try { if(!allow_host(req)) { - fc_dlog( plugin_state_.get_logger(), "bad host: ${HOST}", ("HOST", std::string(req["host"]))); + fc_dlog( plugin_state_->get_logger(), "bad host: ${HOST}", ("HOST", std::string(req["host"]))); error_results results{static_cast(http::status::bad_request), "Disallowed HTTP HOST header in the request"}; send_response( fc::json::to_string( results, fc::time_point::maximum() ), static_cast(http::status::bad_request) ); return; } - if(!plugin_state_.access_control_allow_origin.empty()) { - res_->set("Access-Control-Allow-Origin", plugin_state_.access_control_allow_origin); + if(!plugin_state_->access_control_allow_origin.empty()) { + res_->set("Access-Control-Allow-Origin", plugin_state_->access_control_allow_origin); } - if(!plugin_state_.access_control_allow_headers.empty()) { - res_->set("Access-Control-Allow-Headers", plugin_state_.access_control_allow_headers); + if(!plugin_state_->access_control_allow_headers.empty()) { + res_->set("Access-Control-Allow-Headers", plugin_state_->access_control_allow_headers); } - if(!plugin_state_.access_control_max_age.empty()) { - res_->set("Access-Control-Max-Age", plugin_state_.access_control_max_age); + if(!plugin_state_->access_control_max_age.empty()) { + res_->set("Access-Control-Max-Age", plugin_state_->access_control_max_age); } - if(plugin_state_.access_control_allow_credentials) { + if(plugin_state_->access_control_allow_credentials) { res_->set("Access-Control-Allow-Credentials", "true"); } @@ -152,35 +153,35 @@ class beast_http_session : public detail::abstract_conn, return; } - fc_dlog( plugin_state_.get_logger(), "Request: ${ep} ${r}", + fc_dlog( plugin_state_->get_logger(), "Request: ${ep} ${r}", ("ep", remote_endpoint_)("r", to_log_string(req)) ); std::string resource = std::string(req.target()); // look for the URL handler to handle this resource - auto handler_itr = plugin_state_.url_handlers.find(resource); - if(handler_itr != plugin_state_.url_handlers.end() && categories_.contains(handler_itr->second.category)) { - if(plugin_state_.get_logger().is_enabled(fc::log_level::all)) - plugin_state_.get_logger().log(FC_LOG_MESSAGE(all, "resource: ${ep}", ("ep", resource))); + auto handler_itr = plugin_state_->url_handlers.find(resource); + if(handler_itr != plugin_state_->url_handlers.end() && categories_.contains(handler_itr->second.category)) { + if(plugin_state_->get_logger().is_enabled(fc::log_level::all)) + plugin_state_->get_logger().log(FC_LOG_MESSAGE(all, "resource: ${ep}", ("ep", resource))); std::string body = req.body(); auto content_type = handler_itr->second.content_type; set_content_type_header(content_type); - if (plugin_state_.update_metrics) - plugin_state_.update_metrics({resource}); + if (plugin_state_->update_metrics) + plugin_state_->update_metrics({resource}); handler_itr->second.fn(this->shared_from_this(), std::move(resource), std::move(body), - make_http_response_handler(plugin_state_, this->shared_from_this(), content_type)); + make_http_response_handler(*plugin_state_, this->shared_from_this(), content_type)); } else if (resource == "/v1/node/get_supported_apis") { http_plugin::get_supported_apis_result result; - for (const auto& handler : plugin_state_.url_handlers) { + for (const auto& handler : plugin_state_->url_handlers) { if (categories_.contains(handler.second.category)) result.apis.push_back(handler.first); } send_response(fc::json::to_string(fc::variant(result), fc::time_point::maximum()), 200); } else { - fc_dlog( plugin_state_.get_logger(), "404 - not found: ${ep}", ("ep", resource) ); + fc_dlog( plugin_state_->get_logger(), "404 - not found: ${ep}", ("ep", resource) ); error_results results{static_cast(http::status::not_found), "Not Found", error_results::error_info( fc::exception( FC_LOG_MESSAGE( error, "Unknown Endpoint" ) ), http_plugin::verbose_errors() )}; @@ -204,7 +205,7 @@ class beast_http_session : public detail::abstract_conn, res->result(http::status::unauthorized); continue_state_ = continue_state_t::reject; } - res->set(http::field::server, plugin_state_.server_header); + res->set(http::field::server, plugin_state_->server_header); http::async_write( socket_, @@ -227,21 +228,21 @@ class beast_http_session : public detail::abstract_conn, } virtual std::string verify_max_bytes_in_flight(size_t extra_bytes) final { - auto bytes_in_flight_size = plugin_state_.bytes_in_flight.load() + extra_bytes; - if(bytes_in_flight_size > plugin_state_.max_bytes_in_flight) { - fc_dlog(plugin_state_.get_logger(), "429 - too many bytes in flight: ${bytes}", ("bytes", bytes_in_flight_size)); + auto bytes_in_flight_size = plugin_state_->bytes_in_flight.load() + extra_bytes; + if(bytes_in_flight_size > plugin_state_->max_bytes_in_flight) { + fc_dlog(plugin_state_->get_logger(), "429 - too many bytes in flight: ${bytes}", ("bytes", bytes_in_flight_size)); return "Too many bytes in flight: " + std::to_string( bytes_in_flight_size ); } return {}; } virtual std::string verify_max_requests_in_flight() final { - if(plugin_state_.max_requests_in_flight < 0) + if(plugin_state_->max_requests_in_flight < 0) return {}; - auto requests_in_flight_num = plugin_state_.requests_in_flight.load(); - if(requests_in_flight_num > plugin_state_.max_requests_in_flight) { - fc_dlog(plugin_state_.get_logger(), "429 - too many requests in flight: ${requests}", ("requests", requests_in_flight_num)); + auto requests_in_flight_num = plugin_state_->requests_in_flight.load(); + if(requests_in_flight_num > plugin_state_->max_requests_in_flight) { + fc_dlog(plugin_state_->get_logger(), "429 - too many requests in flight: ${requests}", ("requests", requests_in_flight_num)); return "Too many requests in flight: " + std::to_string( requests_in_flight_num ); } return {}; @@ -251,13 +252,13 @@ class beast_http_session : public detail::abstract_conn, // shared_from_this() requires default constructor beast_http_session() = default; - beast_http_session(Socket&& socket, http_plugin_state& plugin_state, std::string remote_endpoint, + beast_http_session(Socket&& socket, std::shared_ptr plugin_state, std::string remote_endpoint, api_category_set categories, const std::string& local_address) - : socket_(std::move(socket)), categories_(categories), plugin_state_(plugin_state), + : plugin_state_(std::move(plugin_state)), socket_(std::move(socket)), categories_(categories), remote_endpoint_(std::move(remote_endpoint)), local_address_(local_address) { - plugin_state_.requests_in_flight += 1; + plugin_state_->requests_in_flight += 1; req_parser_.emplace(); - req_parser_->body_limit(plugin_state_.max_body_size); + req_parser_->body_limit(plugin_state_->max_body_size); res_.emplace(); session_begin_ = steady_clock::now(); @@ -269,14 +270,14 @@ class beast_http_session : public detail::abstract_conn, virtual ~beast_http_session() { is_send_exception_response_ = false; - plugin_state_.requests_in_flight -= 1; - if(plugin_state_.get_logger().is_enabled(fc::log_level::all)) { + plugin_state_->requests_in_flight -= 1; + if(plugin_state_->get_logger().is_enabled(fc::log_level::all)) { auto session_time = steady_clock::now() - session_begin_; auto session_time_us = std::chrono::duration_cast(session_time).count(); - plugin_state_.get_logger().log(FC_LOG_MESSAGE(all, "session time ${t}", ("t", session_time_us))); - plugin_state_.get_logger().log(FC_LOG_MESSAGE(all, " read ${t}", ("t", read_time_us_))); - plugin_state_.get_logger().log(FC_LOG_MESSAGE(all, " handle ${t}", ("t", handle_time_us_))); - plugin_state_.get_logger().log(FC_LOG_MESSAGE(all, " write ${t}", ("t", write_time_us_))); + plugin_state_->get_logger().log(FC_LOG_MESSAGE(all, "session time ${t}", ("t", session_time_us))); + plugin_state_->get_logger().log(FC_LOG_MESSAGE(all, " read ${t}", ("t", read_time_us_))); + plugin_state_->get_logger().log(FC_LOG_MESSAGE(all, " handle ${t}", ("t", handle_time_us_))); + plugin_state_->get_logger().log(FC_LOG_MESSAGE(all, " write ${t}", ("t", write_time_us_))); } } @@ -299,7 +300,7 @@ class beast_http_session : public detail::abstract_conn, if(ec == http::error::end_of_stream || ec == asio::error::connection_reset) return do_eof(); - return fail(ec, "read_header", plugin_state_.get_logger(), "closing connection"); + return fail(ec, "read_header", plugin_state_->get_logger(), "closing connection"); } // Check for the Expect field value @@ -307,7 +308,7 @@ class beast_http_session : public detail::abstract_conn, bool do_continue = true; auto sv = req_parser_->get()[http::field::content_length]; if (uint64_t sz; !sv.empty() && std::from_chars(sv.data(), sv.data() + sv.size(), sz).ec == std::errc() && - sz > plugin_state_.max_body_size) { + sz > plugin_state_->max_body_size) { do_continue = false; } send_100_continue_response(do_continue); @@ -339,7 +340,7 @@ class beast_http_session : public detail::abstract_conn, if(ec == http::error::end_of_stream || ec == asio::error::connection_reset) return do_eof(); - return fail(ec, "read", plugin_state_.get_logger(), "closing connection"); + return fail(ec, "read", plugin_state_->get_logger(), "closing connection"); } auto req = req_parser_->release(); @@ -358,7 +359,7 @@ class beast_http_session : public detail::abstract_conn, boost::ignore_unused(bytes_transferred); if(ec) { - return fail(ec, "write", plugin_state_.get_logger(), "closing connection"); + return fail(ec, "write", plugin_state_->get_logger(), "closing connection"); } auto dt = steady_clock::now() - write_begin_; @@ -391,7 +392,7 @@ class beast_http_session : public detail::abstract_conn, // create a new parser to clear state req_parser_.emplace(); - req_parser_->body_limit(plugin_state_.max_body_size); + req_parser_->body_limit(plugin_state_->max_body_size); // Read another request do_read_header(); @@ -406,26 +407,26 @@ class beast_http_session : public detail::abstract_conn, throw; } catch(const fc::exception& e) { err_str = e.to_detail_string(); - fc_elog(plugin_state_.get_logger(), "fc::exception: ${w}", ("w", err_str)); + fc_elog(plugin_state_->get_logger(), "fc::exception: ${w}", ("w", err_str)); if( is_send_exception_response_ ) { error_results results{static_cast(http::status::internal_server_error), "Internal Service Error", error_results::error_info( e, http_plugin::verbose_errors() )}; - err_str = fc::json::to_string( results, fc::time_point::now().safe_add(plugin_state_.max_response_time) ); + err_str = fc::json::to_string( results, fc::time_point::now().safe_add(plugin_state_->max_response_time) ); } } catch(std::exception& e) { err_str = e.what(); - fc_elog(plugin_state_.get_logger(), "std::exception: ${w}", ("w", err_str)); + fc_elog(plugin_state_->get_logger(), "std::exception: ${w}", ("w", err_str)); if( is_send_exception_response_ ) { error_results results{static_cast(http::status::internal_server_error), "Internal Service Error", error_results::error_info( fc::exception( FC_LOG_MESSAGE( error, err_str ) ), http_plugin::verbose_errors() )}; - err_str = fc::json::to_string( results, fc::time_point::now().safe_add(plugin_state_.max_response_time) ); + err_str = fc::json::to_string( results, fc::time_point::now().safe_add(plugin_state_->max_response_time) ); } } catch(...) { err_str = "Unknown exception"; - fc_elog(plugin_state_.get_logger(), err_str); + fc_elog(plugin_state_->get_logger(), err_str); if( is_send_exception_response_ ) { error_results results{static_cast(http::status::internal_server_error), "Internal Service Error", @@ -436,10 +437,10 @@ class beast_http_session : public detail::abstract_conn, } } } catch (fc::timeout_exception& e) { - fc_elog( plugin_state_.get_logger(), "Timeout exception ${te} attempting to handle exception: ${e}", ("te", e.to_detail_string())("e", err_str) ); + fc_elog( plugin_state_->get_logger(), "Timeout exception ${te} attempting to handle exception: ${e}", ("te", e.to_detail_string())("e", err_str) ); err_str = R"xxx({"message": "Internal Server Error"})xxx"; } catch (...) { - fc_elog( plugin_state_.get_logger(), "Exception attempting to handle exception: ${e}", ("e", err_str) ); + fc_elog( plugin_state_->get_logger(), "Exception attempting to handle exception: ${e}", ("e", err_str) ); err_str = R"xxx({"message": "Internal Server Error"})xxx"; } @@ -455,11 +456,11 @@ class beast_http_session : public detail::abstract_conn, } void increment_bytes_in_flight(size_t sz) { - plugin_state_.bytes_in_flight += sz; + plugin_state_->bytes_in_flight += sz; } void decrement_bytes_in_flight(size_t sz) { - plugin_state_.bytes_in_flight -= sz; + plugin_state_->bytes_in_flight -= sz; } virtual void send_response(std::string&& json, unsigned int code) final { @@ -474,9 +475,9 @@ class beast_http_session : public detail::abstract_conn, res_->prepare_payload(); // Determine if we should close the connection after - bool close = !(plugin_state_.keep_alive) || res_->need_eof(); + bool close = !(plugin_state_->keep_alive) || res_->need_eof(); - fc_dlog( plugin_state_.get_logger(), "Response: ${ep} ${b}", + fc_dlog( plugin_state_->get_logger(), "Response: ${ep} ${b}", ("ep", remote_endpoint_)("b", to_log_string(*res_)) ); // Write the response @@ -516,7 +517,7 @@ class beast_http_session : public detail::abstract_conn, if constexpr(std::is_same_v) { const std::string host_str(req["host"]); if (host_str != local_address_) - return eosio::allow_host(host_str, socket_, plugin_state_); + return eosio::allow_host(host_str, socket_, *plugin_state_); } return true; }