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
@@ -22,16 +22,16 @@
|
||||
|
||||
#include <ripple/server/Writer.h>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/streambuf_body.hpp>
|
||||
#include <beast/http/dynamic_body.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
using http_request_type =
|
||||
beast::http::request<beast::http::streambuf_body>;
|
||||
beast::http::request<beast::http::dynamic_body>;
|
||||
|
||||
using http_response_type =
|
||||
beast::http::response<beast::http::streambuf_body>;
|
||||
beast::http::response<beast::http::dynamic_body>;
|
||||
|
||||
/** Used to indicate the result of a server connection handoff. */
|
||||
struct Handoff
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
#define RIPPLE_SERVER_SIMPLEWRITER_H_INCLUDED
|
||||
|
||||
#include <ripple/server/Writer.h>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/write_dynabuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
#include <utility>
|
||||
@@ -32,7 +32,7 @@ namespace ripple {
|
||||
/// Deprecated: Writer that serializes a HTTP/1 message
|
||||
class SimpleWriter : public Writer
|
||||
{
|
||||
beast::streambuf sb_;
|
||||
beast::multi_buffer sb_;
|
||||
|
||||
public:
|
||||
template<bool isRequest, class Body, class Headers>
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
SimpleWriter(beast::http::message<
|
||||
isRequest, Body, Headers> const& msg)
|
||||
{
|
||||
beast::write(sb_, msg);
|
||||
beast::ostream(sb_) << msg;
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <ripple/server/Handoff.h>
|
||||
#include <ripple/server/Port.h>
|
||||
#include <ripple/server/Writer.h>
|
||||
#include <beast/core/prepare_buffers.hpp>
|
||||
#include <beast/core/buffer_prefix.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/logic/tribool.hpp>
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
n_ = sb_.size();
|
||||
done = true;
|
||||
}
|
||||
auto const pb = beast::prepare_buffers(n_, sb_.data());
|
||||
auto const pb = beast::buffer_prefix(n_, sb_.data());
|
||||
std::vector<boost::asio::const_buffer> vb (
|
||||
std::distance(pb.begin(), pb.end()));
|
||||
std::copy(pb.begin(), pb.end(), std::back_inserter(vb));
|
||||
|
||||
@@ -24,12 +24,11 @@
|
||||
#include <ripple/server/Session.h>
|
||||
#include <ripple/server/impl/io_list.h>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <ripple/beast/asio/ssl_error.h> // for is_short_read?
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/parser_v1.hpp>
|
||||
#include <beast/http/streambuf_body.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <beast/http/dynamic_body.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl/stream.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
@@ -288,7 +287,7 @@ start_timer()
|
||||
return fail(ec, "start_timer");
|
||||
timer_.async_wait(strand_.wrap(std::bind(
|
||||
&BaseHTTPPeer<Handler, Impl>::on_timer, impl().shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
// Convenience for discarding the error code
|
||||
@@ -328,6 +327,8 @@ do_read(yield_context do_yield)
|
||||
beast::http::async_read(impl().stream_,
|
||||
read_buf_, message_, do_yield[ec]);
|
||||
cancel_timer();
|
||||
if(ec == beast::http::error::end_of_stream)
|
||||
return do_close();
|
||||
if(ec)
|
||||
return fail(ec, "http::read");
|
||||
do_request();
|
||||
@@ -361,8 +362,8 @@ on_write(error_code const& ec,
|
||||
using namespace beast::asio;
|
||||
return boost::asio::async_write(impl().stream_, v,
|
||||
strand_.wrap(std::bind(&BaseHTTPPeer::on_write,
|
||||
impl().shared_from_this(), placeholders::error,
|
||||
placeholders::bytes_transferred)));
|
||||
impl().shared_from_this(), std::placeholders::_1,
|
||||
std::placeholders::_2)));
|
||||
}
|
||||
if(! complete_)
|
||||
return;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include <ripple/beast/utility/rngfill.h>
|
||||
#include <ripple/crypto/csprng.h>
|
||||
#include <beast/websocket.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <cassert>
|
||||
|
||||
@@ -48,9 +48,8 @@ private:
|
||||
friend class BasePeer<Handler, Impl>;
|
||||
|
||||
http_request_type request_;
|
||||
beast::websocket::opcode op_;
|
||||
beast::streambuf rb_;
|
||||
beast::streambuf wb_;
|
||||
beast::multi_buffer rb_;
|
||||
beast::multi_buffer wb_;
|
||||
std::list<std::shared_ptr<WSMsg>> wq_;
|
||||
bool do_close_ = false;
|
||||
beast::websocket::close_reason cr_;
|
||||
@@ -105,25 +104,6 @@ public:
|
||||
complete() override;
|
||||
|
||||
protected:
|
||||
struct identity
|
||||
{
|
||||
template<class Body, class Headers>
|
||||
void
|
||||
operator()(beast::http::message<true, Body, Headers>& req) const
|
||||
{
|
||||
req.fields.replace("User-Agent",
|
||||
BuildInfo::getFullVersionString());
|
||||
}
|
||||
|
||||
template<class Body, class Headers>
|
||||
void
|
||||
operator()(beast::http::message<false, Body, Headers>& resp) const
|
||||
{
|
||||
resp.fields.replace("Server",
|
||||
BuildInfo::getFullVersionString());
|
||||
}
|
||||
};
|
||||
|
||||
Impl&
|
||||
impl()
|
||||
{
|
||||
@@ -199,17 +179,21 @@ run()
|
||||
if(! strand_.running_in_this_thread())
|
||||
return strand_.post(std::bind(
|
||||
&BaseWSPeer::run, impl().shared_from_this()));
|
||||
impl().ws_.set_option(beast::websocket::decorate(identity{}));
|
||||
impl().ws_.set_option(port().pmd_options);
|
||||
impl().ws_.set_option(beast::websocket::ping_callback{
|
||||
impl().ws_.ping_callback(
|
||||
std::bind(&BaseWSPeer::on_ping_pong, this,
|
||||
std::placeholders::_1, std::placeholders::_2)});
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
using namespace beast::asio;
|
||||
start_timer();
|
||||
close_on_timer_ = true;
|
||||
impl().ws_.async_accept(request_, strand_.wrap(std::bind(
|
||||
&BaseWSPeer::on_ws_handshake, impl().shared_from_this(),
|
||||
placeholders::error)));
|
||||
impl().ws_.async_accept_ex(request_,
|
||||
[](auto & res)
|
||||
{
|
||||
res.replace(beast::http::field::server,
|
||||
BuildInfo::getFullVersionString());
|
||||
},
|
||||
strand_.wrap(std::bind(&BaseWSPeer::on_ws_handshake,
|
||||
impl().shared_from_this(), std::placeholders::_1)));
|
||||
}
|
||||
|
||||
template<class Handler, class Impl>
|
||||
@@ -227,7 +211,7 @@ send(std::shared_ptr<WSMsg> w)
|
||||
{
|
||||
JLOG(this->j_.info()) <<
|
||||
"closing slow client";
|
||||
cr_.code = static_cast<beast::websocket::close_code::value>(4000);
|
||||
cr_.code = static_cast<beast::websocket::close_code>(4000);
|
||||
cr_.reason = "Client is too slow.";
|
||||
wq_.erase(std::next(wq_.begin()), wq_.end());
|
||||
close();
|
||||
@@ -250,7 +234,7 @@ close()
|
||||
if(wq_.empty())
|
||||
impl().ws_.async_close({}, strand_.wrap(std::bind(
|
||||
&BaseWSPeer::on_close, impl().shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
template<class Handler, class Impl>
|
||||
@@ -305,12 +289,12 @@ on_write(error_code const& ec)
|
||||
impl().ws_.async_write_frame(
|
||||
result.first, result.second, strand_.wrap(std::bind(
|
||||
&BaseWSPeer::on_write, impl().shared_from_this(),
|
||||
placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
else
|
||||
impl().ws_.async_write_frame(
|
||||
result.first, result.second, strand_.wrap(std::bind(
|
||||
&BaseWSPeer::on_write_fin, impl().shared_from_this(),
|
||||
placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
template<class Handler, class Impl>
|
||||
@@ -324,7 +308,7 @@ on_write_fin(error_code const& ec)
|
||||
if(do_close_)
|
||||
impl().ws_.async_close(cr_, strand_.wrap(std::bind(
|
||||
&BaseWSPeer::on_close, impl().shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
else if(! wq_.empty())
|
||||
on_write({});
|
||||
}
|
||||
@@ -338,9 +322,9 @@ do_read()
|
||||
return strand_.post(std::bind(
|
||||
&BaseWSPeer::do_read, impl().shared_from_this()));
|
||||
using namespace beast::asio;
|
||||
impl().ws_.async_read(op_, rb_, strand_.wrap(
|
||||
impl().ws_.async_read(rb_, strand_.wrap(
|
||||
std::bind(&BaseWSPeer::on_read,
|
||||
impl().shared_from_this(), placeholders::error)));
|
||||
impl().shared_from_this(), std::placeholders::_1)));
|
||||
}
|
||||
|
||||
template<class Handler, class Impl>
|
||||
@@ -385,7 +369,7 @@ start_timer()
|
||||
return fail(ec, "start_timer");
|
||||
timer_.async_wait(strand_.wrap(std::bind(
|
||||
&BaseWSPeer<Handler, Impl>::on_timer, impl().shared_from_this(),
|
||||
beast::asio::placeholders::error)));
|
||||
std::placeholders::_1)));
|
||||
}
|
||||
|
||||
// Convenience for discarding the error code
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
#include <ripple/server/impl/PlainHTTPPeer.h>
|
||||
#include <ripple/server/impl/SSLHTTPPeer.h>
|
||||
#include <ripple/beast/asio/ssl_bundle.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
@@ -225,7 +224,7 @@ do_detect(boost::asio::yield_context do_yield)
|
||||
{
|
||||
bool ssl;
|
||||
error_code ec;
|
||||
beast::streambuf buf(16);
|
||||
beast::multi_buffer buf(16);
|
||||
timer_.expires_from_now(std::chrono::seconds(15));
|
||||
std::tie(ec, ssl) = detect_ssl(socket_, buf, do_yield);
|
||||
error_code unused;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED
|
||||
#define RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED
|
||||
|
||||
#include <ripple/beast/rfc2616.h>
|
||||
#include <ripple/server/impl/BaseHTTPPeer.h>
|
||||
#include <ripple/server/impl/PlainWSPeer.h>
|
||||
#include <memory>
|
||||
@@ -132,7 +133,7 @@ do_request()
|
||||
}
|
||||
|
||||
// Perform half-close when Connection: close and not SSL
|
||||
if (! is_keep_alive(this->message_))
|
||||
if (! beast::rfc2616::is_keep_alive(this->message_))
|
||||
stream_.shutdown(socket_type::shutdown_receive, ec);
|
||||
if (ec)
|
||||
return this->fail(ec, "request");
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <ripple/server/impl/BaseHTTPPeer.h>
|
||||
#include <ripple/server/WSSession.h>
|
||||
#include <ripple/beast/asio/ssl_bundle.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/websocket/ssl.hpp>
|
||||
#include <memory>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user