mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Compare commits
13 Commits
ximinez/di
...
ximinez/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14c2ceb1f9 | ||
|
|
8941f7f3cf | ||
|
|
eb8f2e6279 | ||
|
|
a0f044f69d | ||
|
|
d7f0653f77 | ||
|
|
f2d4de23f1 | ||
|
|
1c52385243 | ||
|
|
603ec19038 | ||
|
|
0aab9ce44c | ||
|
|
e4b18fd92b | ||
|
|
2bf218344b | ||
|
|
88e7ceef6a | ||
|
|
0e6b981a56 |
@@ -16,7 +16,6 @@
|
||||
// Add new amendments to the top of this list.
|
||||
// Keep it sorted in reverse chronological order.
|
||||
|
||||
XRPL_FEATURE(DefragDirectories, Supported::no, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(LendingProtocol, Supported::no, VoteBehavior::DefaultNo)
|
||||
XRPL_FEATURE(PermissionDelegationV1_1, Supported::no, VoteBehavior::DefaultNo)
|
||||
XRPL_FIX (DirectoryLimit, Supported::yes, VoteBehavior::DefaultNo)
|
||||
|
||||
@@ -10,14 +10,6 @@ namespace ripple {
|
||||
|
||||
namespace directory {
|
||||
|
||||
struct Gap
|
||||
{
|
||||
uint64_t const page;
|
||||
SLE::pointer node;
|
||||
uint64_t const nextPage;
|
||||
SLE::pointer next;
|
||||
};
|
||||
|
||||
std::uint64_t
|
||||
createRoot(
|
||||
ApplyView& view,
|
||||
@@ -120,9 +112,7 @@ insertPage(
|
||||
return std::nullopt;
|
||||
if (!view.rules().enabled(fixDirectoryLimit) &&
|
||||
page >= dirNodeMaxPages) // Old pages limit
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// We are about to create a new node; we'll link it to
|
||||
// the chain first:
|
||||
@@ -144,8 +134,15 @@ insertPage(
|
||||
// it's the default.
|
||||
if (page != 1)
|
||||
node->setFieldU64(sfIndexPrevious, page - 1);
|
||||
XRPL_ASSERT_PARTS(
|
||||
!nextPage,
|
||||
"ripple::directory::insertPage",
|
||||
"nextPage has default value");
|
||||
/* Reserved for future use when directory pages may be inserted in
|
||||
* between two other pages instead of only at the end of the chain.
|
||||
if (nextPage)
|
||||
node->setFieldU64(sfIndexNext, nextPage);
|
||||
*/
|
||||
describe(node);
|
||||
view.insert(node);
|
||||
|
||||
@@ -161,7 +158,7 @@ ApplyView::dirAdd(
|
||||
uint256 const& key,
|
||||
std::function<void(std::shared_ptr<SLE> const&)> const& describe)
|
||||
{
|
||||
auto const root = peek(directory);
|
||||
auto root = peek(directory);
|
||||
|
||||
if (!root)
|
||||
{
|
||||
@@ -172,44 +169,6 @@ ApplyView::dirAdd(
|
||||
auto [page, node, indexes] =
|
||||
directory::findPreviousPage(*this, directory, root);
|
||||
|
||||
if (rules().enabled(featureDefragDirectories))
|
||||
{
|
||||
// If there are more nodes than just the root, and there's no space in
|
||||
// the last one, walk backwards to find one with space, or to find one
|
||||
// missing.
|
||||
std::optional<directory::Gap> gapPages;
|
||||
while (page && indexes.size() >= dirNodeMaxEntries)
|
||||
{
|
||||
// Find a page with space, or a gap in pages.
|
||||
auto [prevPage, prevNode, prevIndexes] =
|
||||
directory::findPreviousPage(*this, directory, node);
|
||||
if (!gapPages && prevPage != page - 1)
|
||||
gapPages.emplace(prevPage, prevNode, page, node);
|
||||
page = prevPage;
|
||||
node = prevNode;
|
||||
indexes = prevIndexes;
|
||||
}
|
||||
// We looped through all the pages back to the root.
|
||||
if (!page)
|
||||
{
|
||||
// If we found a gap, use it.
|
||||
if (gapPages)
|
||||
{
|
||||
return directory::insertPage(
|
||||
*this,
|
||||
gapPages->page,
|
||||
gapPages->node,
|
||||
gapPages->nextPage,
|
||||
gapPages->next,
|
||||
key,
|
||||
directory,
|
||||
describe);
|
||||
}
|
||||
std::tie(page, node, indexes) =
|
||||
directory::findPreviousPage(*this, directory, root);
|
||||
}
|
||||
}
|
||||
|
||||
// If there's space, we use it:
|
||||
if (indexes.size() < dirNodeMaxEntries)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
||||
@@ -17,6 +18,40 @@ using namespace ripple;
|
||||
|
||||
namespace {
|
||||
|
||||
struct logger
|
||||
{
|
||||
std::string name;
|
||||
logger const* const parent = nullptr;
|
||||
static std::size_t depth;
|
||||
logger(std::string n) : name(n)
|
||||
{
|
||||
std::clog << indent() << name << " begin\n";
|
||||
++depth;
|
||||
}
|
||||
|
||||
logger(logger const& p, std::string n) : parent(&p), name(n)
|
||||
{
|
||||
std::clog << indent() << parent->name << " : " << name << " begin\n";
|
||||
++depth;
|
||||
}
|
||||
|
||||
~logger()
|
||||
{
|
||||
--depth;
|
||||
if (parent)
|
||||
std::clog << indent() << parent->name << " : " << name << " end\n";
|
||||
else
|
||||
std::clog << indent() << name << " end\n";
|
||||
}
|
||||
|
||||
std::string
|
||||
indent()
|
||||
{
|
||||
return std::string(depth, ' ');
|
||||
}
|
||||
};
|
||||
std::size_t logger::depth = 0;
|
||||
|
||||
// Simple HTTP server using Beast for testing
|
||||
class TestHTTPServer
|
||||
{
|
||||
@@ -35,6 +70,7 @@ private:
|
||||
public:
|
||||
TestHTTPServer() : acceptor_(ioc_), port_(0)
|
||||
{
|
||||
logger l("TestHTTPServer()");
|
||||
// Bind to any available port
|
||||
endpoint_ = {boost::asio::ip::tcp::v4(), 0};
|
||||
acceptor_.open(endpoint_.protocol());
|
||||
@@ -50,6 +86,7 @@ public:
|
||||
|
||||
~TestHTTPServer()
|
||||
{
|
||||
logger l("~TestHTTPServer()");
|
||||
stop();
|
||||
}
|
||||
|
||||
@@ -87,6 +124,7 @@ private:
|
||||
void
|
||||
stop()
|
||||
{
|
||||
logger l("TestHTTPServer::stop");
|
||||
running_ = false;
|
||||
acceptor_.close();
|
||||
}
|
||||
@@ -94,6 +132,7 @@ private:
|
||||
void
|
||||
accept()
|
||||
{
|
||||
logger l("TestHTTPServer::accept");
|
||||
if (!running_)
|
||||
return;
|
||||
|
||||
@@ -115,31 +154,37 @@ private:
|
||||
void
|
||||
handleConnection(boost::asio::ip::tcp::socket socket)
|
||||
{
|
||||
logger l("TestHTTPServer::handleConnection");
|
||||
try
|
||||
{
|
||||
std::optional<logger> r(std::in_place, l, "read the http request");
|
||||
// Read the HTTP request
|
||||
boost::beast::flat_buffer buffer;
|
||||
boost::beast::http::request<boost::beast::http::string_body> req;
|
||||
boost::beast::http::read(socket, buffer, req);
|
||||
|
||||
// Create response
|
||||
r.emplace(l, "create response");
|
||||
boost::beast::http::response<boost::beast::http::string_body> res;
|
||||
res.version(req.version());
|
||||
res.result(status_code_);
|
||||
res.set(boost::beast::http::field::server, "TestServer");
|
||||
|
||||
// Add custom headers
|
||||
r.emplace(l, "add custom headers");
|
||||
for (auto const& [name, value] : custom_headers_)
|
||||
{
|
||||
res.set(name, value);
|
||||
}
|
||||
|
||||
// Set body and prepare payload first
|
||||
r.emplace(l, "set body and prepare payload");
|
||||
res.body() = response_body_;
|
||||
res.prepare_payload();
|
||||
|
||||
// Override Content-Length with custom headers after prepare_payload
|
||||
// This allows us to test case-insensitive header parsing
|
||||
r.emplace(l, "override content-length");
|
||||
for (auto const& [name, value] : custom_headers_)
|
||||
{
|
||||
if (boost::iequals(name, "Content-Length"))
|
||||
@@ -150,20 +195,26 @@ private:
|
||||
}
|
||||
|
||||
// Send response
|
||||
r.emplace(l, "send response");
|
||||
boost::beast::http::write(socket, res);
|
||||
|
||||
// Shutdown socket gracefully
|
||||
r.emplace(l, "shutdown socket");
|
||||
boost::system::error_code ec;
|
||||
socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec);
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
// Connection handling errors are expected
|
||||
logger c(l, "catch");
|
||||
}
|
||||
|
||||
if (running_)
|
||||
{
|
||||
logger r(l, "accept");
|
||||
accept();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function to run HTTP client test
|
||||
@@ -176,12 +227,16 @@ runHTTPTest(
|
||||
std::string& result_data,
|
||||
boost::system::error_code& result_error)
|
||||
{
|
||||
logger l("runHTTPTest");
|
||||
// Create a null journal for testing
|
||||
beast::Journal j{beast::Journal::getNullSink()};
|
||||
|
||||
std::optional<logger> r(std::in_place, l, "initializeSSLContext");
|
||||
|
||||
// Initialize HTTPClient SSL context
|
||||
HTTPClient::initializeSSLContext("", "", false, j);
|
||||
|
||||
r.emplace(l, "HTTPClient::get");
|
||||
HTTPClient::get(
|
||||
false, // no SSL
|
||||
server.ioc(),
|
||||
@@ -206,6 +261,7 @@ runHTTPTest(
|
||||
while (!completed &&
|
||||
std::chrono::steady_clock::now() - start < std::chrono::seconds(10))
|
||||
{
|
||||
r.emplace(l, "ioc.run_one");
|
||||
if (server.ioc().run_one() == 0)
|
||||
{
|
||||
break;
|
||||
@@ -219,6 +275,8 @@ runHTTPTest(
|
||||
|
||||
TEST_CASE("HTTPClient case insensitive Content-Length")
|
||||
{
|
||||
logger l("HTTPClient case insensitive Content-Length");
|
||||
|
||||
// Test different cases of Content-Length header
|
||||
std::vector<std::string> header_cases = {
|
||||
"Content-Length", // Standard case
|
||||
@@ -230,6 +288,7 @@ TEST_CASE("HTTPClient case insensitive Content-Length")
|
||||
|
||||
for (auto const& header_name : header_cases)
|
||||
{
|
||||
logger h(l, header_name);
|
||||
TestHTTPServer server;
|
||||
std::string test_body = "Hello World!";
|
||||
server.setResponseBody(test_body);
|
||||
@@ -258,6 +317,7 @@ TEST_CASE("HTTPClient case insensitive Content-Length")
|
||||
|
||||
TEST_CASE("HTTPClient basic HTTP request")
|
||||
{
|
||||
logger l("HTTPClient basic HTTP request");
|
||||
TestHTTPServer server;
|
||||
std::string test_body = "Test response body";
|
||||
server.setResponseBody(test_body);
|
||||
@@ -279,6 +339,7 @@ TEST_CASE("HTTPClient basic HTTP request")
|
||||
|
||||
TEST_CASE("HTTPClient empty response")
|
||||
{
|
||||
logger l("HTTPClient empty response");
|
||||
TestHTTPServer server;
|
||||
server.setResponseBody(""); // Empty body
|
||||
server.setHeader("Content-Length", "0");
|
||||
@@ -299,6 +360,7 @@ TEST_CASE("HTTPClient empty response")
|
||||
|
||||
TEST_CASE("HTTPClient different status codes")
|
||||
{
|
||||
logger l("HTTPClient different status codes");
|
||||
std::vector<unsigned int> status_codes = {200, 404, 500};
|
||||
|
||||
for (auto status : status_codes)
|
||||
|
||||
Reference in New Issue
Block a user