mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Changes for Beast version 59
This commit is contained in:
committed by
Miguel Portilla
parent
49bdf2e72d
commit
61316c7f95
@@ -17,7 +17,6 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/detail/base64.hpp>
|
||||
#include <beast/http.hpp>
|
||||
#include <ripple/app/misc/ValidatorSite.h>
|
||||
@@ -91,7 +90,7 @@ public:
|
||||
acceptor_.listen(boost::asio::socket_base::max_connections);
|
||||
acceptor_.async_accept(sock_,
|
||||
std::bind(&http_sync_server::on_accept, this,
|
||||
beast::asio::placeholders::error));
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
~http_sync_server()
|
||||
@@ -134,14 +133,14 @@ private:
|
||||
std::thread{lambda{++id_, *this, std::move(sock_)}}.detach();
|
||||
acceptor_.async_accept(sock_,
|
||||
std::bind(&http_sync_server::on_accept, this,
|
||||
beast::asio::placeholders::error));
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
void
|
||||
do_peer(int id, socket_type&& sock0)
|
||||
{
|
||||
socket_type sock(std::move(sock0));
|
||||
beast::streambuf sb;
|
||||
beast::multi_buffer sb;
|
||||
error_code ec;
|
||||
for(;;)
|
||||
{
|
||||
@@ -149,44 +148,41 @@ private:
|
||||
beast::http::read(sock, sb, req, ec);
|
||||
if(ec)
|
||||
break;
|
||||
auto path = req.url;
|
||||
auto path = req.target().to_string();
|
||||
if(path != "/validators")
|
||||
{
|
||||
resp_type res;
|
||||
res.status = 404;
|
||||
res.reason = "Not Found";
|
||||
res.result(beast::http::status::not_found);
|
||||
res.version = req.version;
|
||||
res.fields.insert("Server", "http_sync_server");
|
||||
res.fields.insert("Content-Type", "text/html");
|
||||
res.insert("Server", "http_sync_server");
|
||||
res.insert("Content-Type", "text/html");
|
||||
res.body = "The file '" + path + "' was not found";
|
||||
prepare(res);
|
||||
res.prepare();
|
||||
write(sock, res, ec);
|
||||
if(ec)
|
||||
break;
|
||||
}
|
||||
resp_type res;
|
||||
res.status = 200;
|
||||
res.reason = "OK";
|
||||
res.result(beast::http::status::ok);
|
||||
res.version = req.version;
|
||||
res.fields.insert("Server", "http_sync_server");
|
||||
res.fields.insert("Content-Type", "application/json");
|
||||
res.insert("Server", "http_sync_server");
|
||||
res.insert("Content-Type", "application/json");
|
||||
|
||||
res.body = list_;
|
||||
try
|
||||
{
|
||||
prepare(res);
|
||||
res.prepare();
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
res = {};
|
||||
res.status = 500;
|
||||
res.reason = "Internal Error";
|
||||
res.result(beast::http::status::internal_server_error);
|
||||
res.version = req.version;
|
||||
res.fields.insert("Server", "http_sync_server");
|
||||
res.fields.insert("Content-Type", "text/html");
|
||||
res.insert("Server", "http_sync_server");
|
||||
res.insert("Content-Type", "text/html");
|
||||
res.body =
|
||||
std::string{"An internal error occurred"} + e.what();
|
||||
prepare(res);
|
||||
res.prepare();
|
||||
}
|
||||
write(sock, res, ec);
|
||||
if(ec)
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
#include <ripple/protocol/STAmount.h>
|
||||
#include <ripple/protocol/STObject.h>
|
||||
#include <ripple/protocol/STTx.h>
|
||||
#include <beast/core/detail/is_call_possible.hpp>
|
||||
#include <beast/core/detail/type_traits.hpp>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
@@ -642,7 +642,7 @@ protected:
|
||||
FN const&... fN)
|
||||
{
|
||||
maybe_invoke(stx, f,
|
||||
beast::detail::is_call_possible<F,
|
||||
beast::detail::is_invocable<F,
|
||||
void(Env&, STTx const&)>());
|
||||
invoke(stx, fN...);
|
||||
}
|
||||
@@ -676,7 +676,7 @@ protected:
|
||||
FN const&... fN)
|
||||
{
|
||||
maybe_invoke(jt, f,
|
||||
beast::detail::is_call_possible<F,
|
||||
beast::detail::is_invocable<F,
|
||||
void(Env&, JTx&)>());
|
||||
invoke(jt, fN...);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/server/Port.h>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/streambuf_body.hpp>
|
||||
#include <beast/http/dynamic_body.hpp>
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
@@ -74,8 +74,8 @@ class JSONRPCClient : public AbstractClient
|
||||
boost::asio::ip::tcp::endpoint ep_;
|
||||
boost::asio::io_service ios_;
|
||||
boost::asio::ip::tcp::socket stream_;
|
||||
beast::streambuf bin_;
|
||||
beast::streambuf bout_;
|
||||
beast::multi_buffer bin_;
|
||||
beast::multi_buffer bout_;
|
||||
unsigned rpc_version_;
|
||||
|
||||
public:
|
||||
@@ -109,12 +109,11 @@ public:
|
||||
using namespace std::string_literals;
|
||||
|
||||
request<string_body> req;
|
||||
req.method = "POST";
|
||||
req.url = "/";
|
||||
req.method(beast::http::verb::post);
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Content-Type", "application/json; charset=UTF-8");
|
||||
req.fields.insert("Host",
|
||||
ep_.address().to_string() + ":" + std::to_string(ep_.port()));
|
||||
req.insert("Content-Type", "application/json; charset=UTF-8");
|
||||
req.insert("Host", ep_);
|
||||
{
|
||||
Json::Value jr;
|
||||
jr[jss::method] = cmd;
|
||||
@@ -131,10 +130,10 @@ public:
|
||||
}
|
||||
req.body = to_string(jr);
|
||||
}
|
||||
prepare(req);
|
||||
req.prepare();
|
||||
write(stream_, req);
|
||||
|
||||
response<streambuf_body> res;
|
||||
response<dynamic_body> res;
|
||||
read(stream_, bin_, res);
|
||||
|
||||
Json::Reader jr;
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/server/Port.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/websocket.hpp>
|
||||
|
||||
#include <condition_variable>
|
||||
@@ -95,8 +94,7 @@ class WSClientImpl : public WSClient
|
||||
std::thread thread_;
|
||||
boost::asio::ip::tcp::socket stream_;
|
||||
beast::websocket::stream<boost::asio::ip::tcp::socket&> ws_;
|
||||
beast::websocket::opcode op_;
|
||||
beast::streambuf rb_;
|
||||
beast::multi_buffer rb_;
|
||||
|
||||
bool peerClosed_ = false;
|
||||
|
||||
@@ -139,9 +137,9 @@ public:
|
||||
stream_.connect(ep);
|
||||
ws_.handshake(ep.address().to_string() +
|
||||
":" + std::to_string(ep.port()), "/");
|
||||
ws_.async_read(op_, rb_,
|
||||
ws_.async_read(rb_,
|
||||
strand_.wrap(std::bind(&WSClientImpl::on_read_msg,
|
||||
this, beast::asio::placeholders::error)));
|
||||
this, std::placeholders::_1)));
|
||||
}
|
||||
catch(std::exception&)
|
||||
{
|
||||
@@ -278,9 +276,9 @@ private:
|
||||
msgs_.push_front(m);
|
||||
cv_.notify_all();
|
||||
}
|
||||
ws_.async_read(op_, rb_, strand_.wrap(
|
||||
ws_.async_read(rb_, strand_.wrap(
|
||||
std::bind(&WSClientImpl::on_read_msg,
|
||||
this, beast::asio::placeholders::error)));
|
||||
this, std::placeholders::_1)));
|
||||
}
|
||||
|
||||
// Called when the read op terminates
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <ripple/basics/make_SSLContext.h>
|
||||
#include <ripple/beast/core/CurrentThreadName.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@@ -211,7 +210,7 @@ private:
|
||||
{
|
||||
acceptor_.async_accept(socket_, strand_.wrap(std::bind(
|
||||
&Acceptor::on_accept, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -237,7 +236,7 @@ private:
|
||||
p->run();
|
||||
acceptor_.async_accept(socket_, strand_.wrap(std::bind(
|
||||
&Acceptor::on_accept, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -281,10 +280,10 @@ private:
|
||||
{
|
||||
timer_.expires_from_now(std::chrono::seconds(3));
|
||||
timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer,
|
||||
shared_from_this(), beast::asio::placeholders::error)));
|
||||
shared_from_this(), std::placeholders::_1)));
|
||||
stream_.async_handshake(stream_type::server, strand_.wrap(
|
||||
std::bind(&Connection::on_handshake, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -319,8 +318,8 @@ private:
|
||||
#if 1
|
||||
boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap(
|
||||
std::bind(&Connection::on_read, shared_from_this(),
|
||||
beast::asio::placeholders::error,
|
||||
beast::asio::placeholders::bytes_transferred)));
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
#else
|
||||
close();
|
||||
#endif
|
||||
@@ -334,7 +333,7 @@ private:
|
||||
server_.test_.log << "[server] read: EOF" << std::endl;
|
||||
return stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
if (ec)
|
||||
return fail("read", ec);
|
||||
@@ -344,8 +343,8 @@ private:
|
||||
write(buf_, "BYE\n");
|
||||
boost::asio::async_write(stream_, buf_.data(), strand_.wrap(
|
||||
std::bind(&Connection::on_write, shared_from_this(),
|
||||
beast::asio::placeholders::error,
|
||||
beast::asio::placeholders::bytes_transferred)));
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -356,7 +355,7 @@ private:
|
||||
return fail("write", ec);
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -432,10 +431,10 @@ private:
|
||||
{
|
||||
timer_.expires_from_now(std::chrono::seconds(3));
|
||||
timer_.async_wait(strand_.wrap(std::bind(&Connection::on_timer,
|
||||
shared_from_this(), beast::asio::placeholders::error)));
|
||||
shared_from_this(), std::placeholders::_1)));
|
||||
socket_.async_connect(endpoint(), strand_.wrap(std::bind(
|
||||
&Connection::on_connect, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -469,7 +468,7 @@ private:
|
||||
return fail("connect", ec);
|
||||
stream_.async_handshake(stream_type::client, strand_.wrap(
|
||||
std::bind(&Connection::on_handshake, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -482,12 +481,12 @@ private:
|
||||
#if 1
|
||||
boost::asio::async_write(stream_, buf_.data(), strand_.wrap(
|
||||
std::bind(&Connection::on_write, shared_from_this(),
|
||||
beast::asio::placeholders::error,
|
||||
beast::asio::placeholders::bytes_transferred)));
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
#else
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -500,12 +499,12 @@ private:
|
||||
#if 1
|
||||
boost::asio::async_read_until(stream_, buf_, "\n", strand_.wrap(
|
||||
std::bind(&Connection::on_read, shared_from_this(),
|
||||
beast::asio::placeholders::error,
|
||||
beast::asio::placeholders::bytes_transferred)));
|
||||
std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
#else
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -517,7 +516,7 @@ private:
|
||||
buf_.commit(bytes_transferred);
|
||||
stream_.async_shutdown(strand_.wrap(std::bind(
|
||||
&Connection::on_shutdown, shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <test/jtx/WSClient.h>
|
||||
#include <test/jtx/JSONRPCClient.h>
|
||||
#include <ripple/core/DeadlineTimer.h>
|
||||
#include <beast/core/to_string.hpp>
|
||||
#include <beast/http.hpp>
|
||||
#include <beast/test/yield_to.hpp>
|
||||
#include <beast/websocket/detail/mask.hpp>
|
||||
@@ -86,17 +85,18 @@ class ServerStatus_test :
|
||||
using namespace beast::http;
|
||||
request<string_body> req;
|
||||
|
||||
req.url = "/";
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", host + ":" + to_string(port));
|
||||
req.fields.insert("User-Agent", "test");
|
||||
req.method = "GET";
|
||||
req.fields.insert("Upgrade", "websocket");
|
||||
req.insert("Host", host + ":" + to_string(port));
|
||||
req.insert("User-Agent", "test");
|
||||
req.method(beast::http::verb::get);
|
||||
req.insert("Upgrade", "websocket");
|
||||
beast::websocket::detail::maskgen maskgen;
|
||||
std::string key = beast::websocket::detail::make_sec_ws_key(maskgen);
|
||||
req.fields.insert("Sec-WebSocket-Key", key);
|
||||
req.fields.insert("Sec-WebSocket-Version", "13");
|
||||
prepare(req, connection::upgrade);
|
||||
beast::websocket::detail::sec_ws_key_type key;
|
||||
beast::websocket::detail::make_sec_ws_key(key, maskgen);
|
||||
req.insert("Sec-WebSocket-Key", key);
|
||||
req.insert("Sec-WebSocket-Version", "13");
|
||||
req.insert(beast::http::field::connection, "upgrade");
|
||||
return req;
|
||||
}
|
||||
|
||||
@@ -109,21 +109,21 @@ class ServerStatus_test :
|
||||
using namespace beast::http;
|
||||
request<string_body> req;
|
||||
|
||||
req.url = "/";
|
||||
req.target("/");
|
||||
req.version = 11;
|
||||
req.fields.insert("Host", host + ":" + to_string(port));
|
||||
req.fields.insert("User-Agent", "test");
|
||||
req.insert("Host", host + ":" + to_string(port));
|
||||
req.insert("User-Agent", "test");
|
||||
if(body.empty())
|
||||
{
|
||||
req.method = "GET";
|
||||
req.method(beast::http::verb::get);
|
||||
}
|
||||
else
|
||||
{
|
||||
req.method = "POST";
|
||||
req.fields.insert("Content-Type", "application/json; charset=UTF-8");
|
||||
req.method(beast::http::verb::post);
|
||||
req.insert("Content-Type", "application/json; charset=UTF-8");
|
||||
req.body = body;
|
||||
}
|
||||
prepare(req);
|
||||
req.prepare();
|
||||
|
||||
return req;
|
||||
}
|
||||
@@ -142,7 +142,7 @@ class ServerStatus_test :
|
||||
using namespace beast::http;
|
||||
io_service& ios = get_io_service();
|
||||
ip::tcp::resolver r{ios};
|
||||
beast::streambuf sb;
|
||||
beast::multi_buffer sb;
|
||||
|
||||
auto it =
|
||||
r.async_resolve(
|
||||
@@ -287,7 +287,7 @@ class ServerStatus_test :
|
||||
doWSRequest(env, yield, false, resp, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.status == 401);
|
||||
BEAST_EXPECT(resp.result() == beast::http::status::unauthorized);
|
||||
}
|
||||
|
||||
//secure request
|
||||
@@ -297,7 +297,7 @@ class ServerStatus_test :
|
||||
doWSRequest(env, yield, true, resp, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.status == 401);
|
||||
BEAST_EXPECT(resp.result() == beast::http::status::unauthorized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ class ServerStatus_test :
|
||||
doHTTPRequest(env, yield, false, resp, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.status == 200);
|
||||
BEAST_EXPECT(resp.result() == beast::http::status::ok);
|
||||
}
|
||||
|
||||
//secure request
|
||||
@@ -330,7 +330,7 @@ class ServerStatus_test :
|
||||
doHTTPRequest(env, yield, true, resp, ec);
|
||||
if(! BEAST_EXPECTS(! ec, ec.message()))
|
||||
return;
|
||||
BEAST_EXPECT(resp.status == 200);
|
||||
BEAST_EXPECT(resp.result() == beast::http::status::ok);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -362,7 +362,7 @@ class ServerStatus_test :
|
||||
|
||||
io_service& ios = get_io_service();
|
||||
ip::tcp::resolver r{ios};
|
||||
beast::streambuf sb;
|
||||
beast::multi_buffer sb;
|
||||
|
||||
auto it =
|
||||
r.async_resolve(
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/basics/make_SSLContext.h>
|
||||
#include <ripple/beast/rfc2616.h>
|
||||
#include <ripple/server/Server.h>
|
||||
#include <ripple/server/Session.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
@@ -123,7 +124,7 @@ public:
|
||||
onRequest (Session& session)
|
||||
{
|
||||
session.write (std::string ("Hello, world!\n"));
|
||||
if (is_keep_alive(session.request()))
|
||||
if (beast::rfc2616::is_keep_alive(session.request()))
|
||||
session.complete();
|
||||
else
|
||||
session.close (true);
|
||||
|
||||
Reference in New Issue
Block a user