10000 ci: fix clang tidy after PR 2863 by canepat · Pull Request #2875 · erigontech/silkworm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ci: fix clang tidy after PR 2863 #2875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion silkworm/rpc/http/chunker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
current_chunk_.reserve(kDefaultMaxChunkSize);
}

~Chunker() {}
~Chunker() = default;

Check warning on line 22 in silkworm/rpc/http/chunker.hpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/chunker.hpp#L22

Added line #L22 was not covered by tests

void queue_data(const std::string& new_buffer) {
size_t position = 0;
Expand Down
91 changes: 47 additions & 44 deletions silkworm/rpc/http/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@
auto gzip_encoding_requested = accept_encoding.contains(kGzipEncoding) && http_compression_;

RequestData request_data{
.request_keep_alive_ = parser.get().keep_alive(),
.request_http_version_ = parser.get().version(),
.gzip_encoding_requested_ = gzip_encoding_requested,
.vary_ = req[boost::beast::http::field::vary],
.origin_ = req[boost::beast::http::field::origin],
.method_ = req.method(),
.request_keep_alive = parser.get().keep_alive(),
.request_http_version = parser.get().version(),
.gzip_encoding_requested = gzip_encoding_requested,
.vary = req[boost::beast::http::field::vary],
.origin = req[boost::beast::http::field::origin],
.method = req.method(),

Check warning on line 111 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L106-L111

Added lines #L106 - L111 were not covered by tests
};

if (boost::beast::websocket::is_upgrade(parser.get())) {
Expand Down Expand Up @@ -153,7 +153,7 @@
}

Task<void> Connection::handle_preflight(const RequestWithStringBody& req, RequestData& request_data) {
boost::beast::http::response<boost::beast::http::string_body> res{boost::beast::http::status::no_content, request_data.request_http_version_};
boost::beast::http::response<boost::beast::http::string_body> res{boost::beast::http::status::no_content, request_data.request_http_version};

Check warning on line 156 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L156

Added line #L156 was not covered by tests
std::string vary = req[boost::beast::http::field::vary];

if (vary.empty()) {
Expand Down Expand Up @@ -193,7 +193,7 @@
co_return;
}

if (http_compression_ && !accept_encoding.empty() && !accept_encoding.contains(kIdentity) && !request_data.gzip_encoding_requested_) {
if (http_compression_ && !accept_encoding.empty() && !accept_encoding.contains(kIdentity) && !request_data.gzip_encoding_requested) {
co_await do_write("unsupported requested compression\n", boost::beast::http::status::unsupported_media_type, request_data, kGzipEncoding);
co_return;
}
Expand All @@ -220,9 +220,10 @@
request_map_.emplace(request_id_, std::move(request_data));
auto rsp_content = co_await handler_->handle(req.body(), request_id_);
if (rsp_content) {
// no streaming api
co_await do_write(rsp_content->append("\n"), boost::beast::http::status::ok, request_data, request_data.gzip_encoding_requested_ ? kGzipEncoding : "", request_data.gzip_encoding_requested_);
auto it = request_map_.find(request_id_);
// no streaming
const auto& req_data = request_map_.at(request_id_);

Check warning on line 224 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L224

Added line #L224 was not covered by tests
co_await do_write(rsp_content->append("\n"), boost::beast::http::status::ok, req_data, req_data.gzip_encoding_requested ? kGzipEncoding : "", req_data.gzip_encoding_requested);
const auto it = request_map_.find(request_id_);

Check warning on line 226 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L226

Added line #L226 was not covered by tests
if (it != request_map_.end()) {
request_map_.erase(it);
}
Expand All @@ -233,12 +234,12 @@
//! Write chunked response headers
Task<void> Connection::create_chunk_header(RequestData& request_data) {
try {
boost::beast::http::response<boost::beast::http::empty_body> rsp{boost::beast::http::status::ok, request_data.request_http_version_};
boost::beast::http::response<boost::beast::http::empty_body> rsp{boost::beast::http::status::ok, request_data.request_http_version};

Check warning on line 237 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L237

Added line #L237 was not covered by tests
rsp.set(boost::beast::http::field::content_type, "application/json");
rsp.set(boost::beast::http::field::date, get_date_time());
rsp.chunked(true);

if (request_data.gzip_encoding_requested_) {
if (request_data.gzip_encoding_requested) {
rsp.set(boost::beast::http::field::content_encoding, kGzipEncoding);
}

Expand All @@ -258,47 +259,49 @@
}

Task<void> Connection::open_stream(uint64_t request_id) {
auto request_data_it = request_map_.find(request_id);
const auto request_data_it = request_map_.find(request_id);

Check warning on line 262 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L262

Added line #L262 was not covered by tests
if (request_data_it == request_map_.end()) {
SILK_ERROR << "Connection::open_stream request_id not found: " << request_id;
co_return;
SILKWORM_ASSERT(false);

Check warning on line 265 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L265

Added line #L265 was not covered by tests
}
auto& request_data = request_data_it->second;

// add chunking supports
request_data.chunk_ = std::make_unique<Chunker>();
request_data.chunk = std::make_unique<Chunker>();

Check warning on line 270 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L270

Added line #L270 was not covered by tests

co_return;
}

Task<void> Connection::close_stream(uint64_t request_id) {
auto request_data_it = request_map_.find(request_id);
const auto request_data_it = request_map_.find(request_id);

Check warning on line 276 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L276

Added line #L276 was not covered by tests
if (request_data_it == request_map_.end()) {
SILK_ERROR << "Connection::close_stream request_id not found: " << request_id;
co_return;
SILKWORM_ASSERT(false);

Check warning on line 279 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L279

Added line #L279 was not covered by tests
}
auto& request_data = request_data_it->second;

try {
// get chunk remainder and flush it
auto [chunk, first_chunk] = request_data.chunk_->get_remainder();
// Get remaining chunk and flush it
auto [chunk, first_chunk] = request_data.chunk->get_remainder();

Check warning on line 285 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L285

Added line #L285 was not covered by tests
if (first_chunk) {
if (!chunk.empty()) {
// it is first chunk so send full msg without chunking
co_await do_write(chunk, boost::beast::http::status::ok, request_data, request_data.gzip_encoding_requested_ ? kGzipEncoding : "", /* to_be_compressed */ false); // data already compressed if nec
// If it is the first chunk, send without chunking
co_await do_write(chunk, boost::beast::http::status::ok, request_data, request_data.gzip_encoding_requested ? kGzipEncoding : "", /* to_be_compressed */ false); // data already compressed if nec
}
} else {
// already a chunk is generated
// A previous chunk was already generated
if (!chunk.empty()) {
// send new one
// Send the new one
co_await send_chunk(chunk);
}
co_await boost::asio::async_write(socket_, boost::beast::http::make_chunk_last(), boost::asio::use_awaitable);
}
} catch (const boost::system::system_error& se) {
request_map_.erase(request_data_it);

Check warning on line 300 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L300

Added line #L300 was not covered by tests
SILK_TRACE << "Connection::close system_error: " << se.what();
throw;
} catch (const std::exception& e) {
request_map_.erase(request_data_it);

Check warning on line 304 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L304

Added line #L304 was not covered by tests
SILK_ERROR << "Connection::close exception: " << e.what();
throw;
}
Expand All @@ -309,10 +312,10 @@

//! Write chunked response content to the underlying socket
Task<size_t> Connection::write(uint64_t request_id, std::string_view content, bool last) {
auto request_data_it = request_map_.find(request_id);
const auto request_data_it = request_map_.find(request_id);

Check warning on line 315 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L315

Added line #L315 was not covered by tests
if (request_data_it == request_map_.end()) {
SILK_ERROR << "Connection::write request_id not found: " << request_id;
co_return 0;
SILKWORM_ASSERT(false);

Check warning on line 318 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L318

Added line #L318 was not covered by tests
}
auto& request_data = request_data_it->second;

Expand All @@ -321,19 +324,19 @@
response.append("\n");
}

if (request_data.gzip_encoding_requested_) {
if (request_data.gzip_encoding_requested) {
std::string compressed_content;
co_await compress(response.data(), compressed_content);
co_await compress(response, compressed_content);

Check warning on line 329 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L329

Added line #L329 was not covered by tests
// queued compressed buffer
request_data.chunk_->queue_data(std::move(compressed_content));
request_data.chunk->queue_data(compressed_content);

Check warning on line 331 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L331

Added line #L331 was not covered by tests
} else {
// queued clear buffer
request_data.chunk_->queue_data(std::move(response));
request_data.chunk->queue_data(response);

Check warning on line 334 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L334

Added line #L334 was not covered by tests
}

// until completed chunk are present
while (request_data.chunk_->has_chunks()) {
auto [complete_chunk, first_chunk] = request_data.chunk_->get_complete_chunk();
while (request_data.chunk->has_chunks()) {
auto [complete_chunk, first_chunk] = request_data.chunk->get_complete_chunk();

Check warning on line 339 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L339

Added line #L339 was not covered by tests

if (first_chunk) {
co_await create_chunk_header(request_data);
Expand All @@ -360,10 +363,10 @@
co_return bytes_transferred;
}

Task<void> Connection::do_write(const std::string& content, boost::beast::http::status http_status, RequestData& request_data, std::string_view content_encoding, bool to_be_compressed) {
Task<void> Connection::do_write(const std::string& content, boost::beast::http::status http_status, const RequestData& request_data, std::string_view content_encoding, bool to_be_compressed) {

Check warning on line 366 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L366

Added line #L366 was not covered by tests
try {
SILK_TRACE << "Connection::do_write response: " << http_status << " content: " << content;
boost::beast::http::response<boost::beast::http::string_body> res{http_status, request_data.request_http_version_};
boost::beast::http::response<boost::beast::http::string_body> res{http_status, request_data.request_http_version};

Check warning on line 369 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L369

Added line #L369 was not covered by tests

if (http_status != boost::beast::http::status::ok) {
res.set(boost::beast::http::field::content_type, "text/plain");
Expand All @@ -373,7 +376,7 @@

res.set(boost::beast::http::field::date, get_date_time());
res.erase(boost::beast::http::field::host);
res.keep_alive(request_data.request_keep_alive_);
res.keep_alive(request_data.request_keep_alive);

Check warning on line 379 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L379

Added line #L379 was not covered by tests
if (http_status == boost::beast::http::status::ok && !content_encoding.empty()) {
// Positive response w/ compression required
res.set(boost::beast::http::field::content_encoding, content_encoding);
Expand All @@ -385,7 +388,7 @@
res.body() = std::move(compressed_content);
} else {
res.content_length(content.size());
res.body() = std::move(content);
res.body() = content;

Check warning on line 391 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L391

Added line #L391 was not covered by tests
}

} else {
Expand All @@ -394,7 +397,7 @@
res.set(boost::beast::http::field::accept_encoding, content_encoding); // Indicate the supported encoding
}
res.content_length(content.size());
res.body() = std::move(content);
res.body() = content;

Check warning on line 400 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L400

Added line #L400 was not covered by tests
}

set_cors<boost::beast::http::string_body>(res, request_data);
Expand Down Expand Up @@ -463,30 +466,30 @@
}

template <class Body>
void Connection::set_cors(boost::beast::http::response<Body>& res, RequestData& request_data) {
if (request_data.vary_.empty()) {
void Connection::set_cors(boost::beast::http::response<Body>& res, const RequestData& request_data) {

Check warning on line 469 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L469

Added line #L469 was not covered by tests
if (request_data.vary.empty()) {
res.set(boost::beast::http::field::vary, "Origin");
} else {
auto vary{request_data.vary_};
auto vary{request_data.vary};

Check warning on line 473 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L473

Added line #L473 was not covered by tests
res.set(boost::beast::http::field::vary, vary.append(" Origin"));
}

if (request_data.origin_.empty()) {
if (request_data.origin.empty()) {
return;
}

if (!is_origin_allowed(allowed_origins_, request_data.origin_)) {
if (!is_origin_allowed(allowed_origins_, request_data.origin)) {
return;
}

if (!is_method_allowed(request_data.method_)) {
if (!is_method_allowed(request_data.method)) {
return;
}

if (allowed_origins_.at(0) == "*") {
res.set(boost::beast::http::field::access_control_allow_origin, "*");
} else {
res.set(boost::beast::http::field::access_control_allow_origin, request_data.origin_);
res.set(boost::beast::http::field::access_control_allow_origin, request_data.origin);

Check warning on line 492 in silkworm/rpc/http/connection.cpp

View check run for this annotation

Codecov / codecov/patch

silkworm/rpc/http/connection.cpp#L492

Added line #L492 was not covered by tests
}
}

Expand Down
18 changes: 9 additions & 9 deletions silkworm/rpc/http/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ using RequestWithStringBody = boost::beast::http::request<boost::beast::http::st
inline constexpr size_t kDefaultCapacity = 4 * 1024;

struct RequestData {
bool request_keep_alive_{false};
unsigned int request_http_version_{11};
bool gzip_encoding_requested_{false};
std::string vary_;
std::string origin_;
boost::beast::http::verb method_{boost::beast::http::verb::unknown};
std::unique_ptr<Chunker> chunk_;
bool request_keep_alive{false};
unsigned int request_http_version{11};
bool gzip_encoding_requested{false};
std::string vary;
std::string origin;
boost::beast::http::verb method{boost::beast::http::verb::unknown};
std::unique_ptr<Chunker> chunk;
};

//! Represents a single connection from a client.
Expand Down Expand Up @@ -87,13 +87,13 @@ class Connection : public StreamWriter {
Task<void> do_upgrade(const RequestWithStringBody& req);

template <class Body>
void set_cors(boost::beast::http::response<Body>& res, RequestData& request_data);
void set_cors(boost::beast::http::response<Body>& res, const RequestData& request_data);

//! Perform an asynchronous read operation.
Task<bool> do_read();

//! Perform an asynchronous write operation.
Task<void> do_write(const std::string& content, boost::beast::http::status http_status, RequestData& request_data, std::string_view content_encoding = "", bool to_be_compressed = false);
Task<void> do_write(const std::string& content, boost::beast::http::status http_status, const RequestData& request_data, std::string_view content_encoding = "", bool to_be_compressed = false);

static std::string get_date_time();

Expand Down
Loading
0