From 61316c7f9525ebb32f34263b51a64a6a421c0e13 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 12 Jun 2017 01:03:19 -0700 Subject: [PATCH] Changes for Beast version 59 --- src/ripple/app/misc/detail/WorkBase.h | 26 +++--- src/ripple/app/misc/impl/ValidatorSite.cpp | 6 +- src/ripple/basics/impl/ResolverAsio.cpp | 5 +- src/ripple/basics/random.h | 4 +- .../beast/insight/impl/StatsDCollector.cpp | 11 ++- src/ripple/beast/rfc2616.h | 13 +++ src/ripple/core/impl/SNTPClock.cpp | 21 +++-- src/ripple/net/AutoSocket.h | 5 +- src/ripple/net/impl/HTTPClient.cpp | 25 +++--- src/ripple/overlay/impl/ConnectAttempt.cpp | 43 +++++---- src/ripple/overlay/impl/ConnectAttempt.h | 11 ++- src/ripple/overlay/impl/OverlayImpl.cpp | 88 +++++++++++-------- src/ripple/overlay/impl/OverlayImpl.h | 14 ++- src/ripple/overlay/impl/PeerImp.cpp | 46 +++++----- src/ripple/overlay/impl/PeerImp.h | 11 ++- src/ripple/overlay/impl/PeerSet.cpp | 1 - src/ripple/overlay/impl/TMHello.cpp | 22 ++--- src/ripple/peerfinder/impl/Checker.h | 3 +- src/ripple/rpc/impl/ServerHandlerImp.cpp | 71 +++++++-------- src/ripple/rpc/impl/WSInfoSub.h | 10 +-- src/ripple/rpc/json_body.h | 34 +++---- src/ripple/server/Handoff.h | 6 +- src/ripple/server/SimpleWriter.h | 8 +- src/ripple/server/WSSession.h | 4 +- src/ripple/server/impl/BaseHTTPPeer.h | 13 +-- src/ripple/server/impl/BaseWSPeer.h | 58 +++++------- src/ripple/server/impl/Door.h | 5 +- src/ripple/server/impl/PlainHTTPPeer.h | 3 +- src/ripple/server/impl/SSLWSPeer.h | 1 - src/test/app/ValidatorSite_test.cpp | 36 ++++---- src/test/jtx/Env.h | 6 +- src/test/jtx/impl/JSONRPCClient.cpp | 19 ++-- src/test/jtx/impl/WSClient.cpp | 14 ++- src/test/overlay/short_read_test.cpp | 41 +++++---- src/test/server/ServerStatus_test.cpp | 46 +++++----- src/test/server/Server_test.cpp | 3 +- 36 files changed, 367 insertions(+), 366 deletions(-) diff --git a/src/ripple/app/misc/detail/WorkBase.h b/src/ripple/app/misc/detail/WorkBase.h index 49cfcd45a..2c5812b41 100644 --- a/src/ripple/app/misc/detail/WorkBase.h +++ b/src/ripple/app/misc/detail/WorkBase.h @@ -22,8 +22,7 @@ #include #include -#include -#include +#include #include #include #include @@ -61,7 +60,7 @@ protected: socket_type socket_; request_type req_; response_type res_; - beast::streambuf read_buf_; + beast::multi_buffer read_buf_; public: WorkBase( @@ -132,8 +131,8 @@ WorkBase::run() resolver_.async_resolve( query_type{host_, port_}, strand_.wrap (std::bind(&WorkBase::onResolve, impl().shared_from_this(), - beast::asio::placeholders::error, - beast::asio::placeholders::iterator))); + std::placeholders::_1, + std::placeholders::_2))); } template @@ -171,24 +170,23 @@ WorkBase::onResolve(error_code const& ec, resolver_type::iterator it) socket_.async_connect(*it, strand_.wrap (std::bind(&Impl::onConnect, impl().shared_from_this(), - beast::asio::placeholders::error))); + std::placeholders::_1))); } template void WorkBase::onStart() { - req_.method = "GET"; - req_.url = path_.empty() ? "/" : path_; + req_.method(beast::http::verb::get); + req_.target(path_.empty() ? "/" : path_); req_.version = 11; - req_.fields.replace ( + req_.replace ( "Host", host_ + ":" + port_); - req_.fields.replace ("User-Agent", BuildInfo::getFullVersionString()); - beast::http::prepare (req_); - + req_.replace ("User-Agent", BuildInfo::getFullVersionString()); + req_.prepare(); beast::http::async_write(impl().stream(), req_, strand_.wrap (std::bind (&WorkBase::onRequest, - impl().shared_from_this(), beast::asio::placeholders::error))); + impl().shared_from_this(), std::placeholders::_1))); } template @@ -200,7 +198,7 @@ WorkBase::onRequest(error_code const& ec) beast::http::async_read (impl().stream(), read_buf_, res_, strand_.wrap (std::bind (&WorkBase::onResponse, - impl().shared_from_this(), beast::asio::placeholders::error))); + impl().shared_from_this(), std::placeholders::_1))); } template diff --git a/src/ripple/app/misc/impl/ValidatorSite.cpp b/src/ripple/app/misc/impl/ValidatorSite.cpp index 90cd60655..bee0d5d4b 100644 --- a/src/ripple/app/misc/impl/ValidatorSite.cpp +++ b/src/ripple/app/misc/impl/ValidatorSite.cpp @@ -144,7 +144,7 @@ ValidatorSite::setTimer () timer_.expires_at (next->nextRefresh); timer_.async_wait (std::bind (&ValidatorSite::onTimer, this, std::distance (sites_.begin (), next), - beast::asio::placeholders::error)); + std::placeholders::_1)); } } @@ -205,12 +205,12 @@ ValidatorSite::onSiteFetch( detail::response_type&& res, std::size_t siteIdx) { - if (! ec && res.status != 200) + if (! ec && res.result() != beast::http::status::ok) { std::lock_guard lock{sites_mutex_}; JLOG (j_.warn()) << "Request for validator list at " << - sites_[siteIdx].uri << " returned " << res.status; + sites_[siteIdx].uri << " returned " << res.result_int(); } else if (! ec) { diff --git a/src/ripple/basics/impl/ResolverAsio.cpp b/src/ripple/basics/impl/ResolverAsio.cpp index da5fd9dde..ffabbb95c 100644 --- a/src/ripple/basics/impl/ResolverAsio.cpp +++ b/src/ripple/basics/impl/ResolverAsio.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -336,8 +335,8 @@ public: m_resolver.async_resolve (query, std::bind ( &ResolverAsioImpl::do_finish, this, name, - beast::asio::placeholders::error, handler, - beast::asio::placeholders::iterator, + std::placeholders::_1, handler, + std::placeholders::_2, CompletionCounter (this))); } diff --git a/src/ripple/basics/random.h b/src/ripple/basics/random.h index 3cac22f60..b4388fd58 100644 --- a/src/ripple/basics/random.h +++ b/src/ripple/basics/random.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ namespace detail { // Determines if a type can be called like an Engine template using is_engine = - beast::detail::is_call_possible; + beast::detail::is_invocable; } /** Return the default random engine. diff --git a/src/ripple/beast/insight/impl/StatsDCollector.cpp b/src/ripple/beast/insight/impl/StatsDCollector.cpp index 90c5dca61..bcad0d99c 100644 --- a/src/ripple/beast/insight/impl/StatsDCollector.cpp +++ b/src/ripple/beast/insight/impl/StatsDCollector.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -383,8 +382,8 @@ public: #endif m_socket.async_send (buffers, std::bind ( &StatsDCollectorImp::on_send, this, keepAlive, - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); buffers.clear (); size = 0; } @@ -400,8 +399,8 @@ public: #endif m_socket.async_send (buffers, std::bind ( &StatsDCollectorImp::on_send, this, keepAlive, - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); } } @@ -411,7 +410,7 @@ public: m_timer.expires_from_now(1s); m_timer.async_wait (std::bind ( &StatsDCollectorImp::on_timer, this, - beast::asio::placeholders::error)); + std::placeholders::_1)); } void on_timer (boost::system::error_code ec) diff --git a/src/ripple/beast/rfc2616.h b/src/ripple/beast/rfc2616.h index 2c9a09d7c..9771939f8 100644 --- a/src/ripple/beast/rfc2616.h +++ b/src/ripple/beast/rfc2616.h @@ -20,6 +20,8 @@ #ifndef BEAST_RFC2616_HPP #define BEAST_RFC2616_HPP +#include +#include #include #include #include @@ -464,6 +466,17 @@ token_in_list(boost::string_ref const& value, return false; } +template +bool +is_keep_alive(beast::http::message const& m) +{ + if(m.version <= 10) + return beast::http::token_list{ + m[beast::http::field::connection]}.exists("keep-alive"); + return ! beast::http::token_list{ + m[beast::http::field::connection]}.exists("close"); +} + } // rfc2616 } // beast diff --git a/src/ripple/core/impl/SNTPClock.cpp b/src/ripple/core/impl/SNTPClock.cpp index 3f9b0f844..646fc912e 100644 --- a/src/ripple/core/impl/SNTPClock.cpp +++ b/src/ripple/core/impl/SNTPClock.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -164,12 +163,12 @@ public: socket_.async_receive_from (buffer (buf_, 256), ep_, std::bind( &SNTPClientImp::onRead, this, - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); timer_.expires_from_now(NTP_QUERY_FREQUENCY); timer_.async_wait(std::bind( &SNTPClientImp::onTimer, this, - beast::asio::placeholders::error)); + std::placeholders::_1)); // VFALCO Is it correct to launch the thread // here after queuing I/O? @@ -222,7 +221,7 @@ public: timer_.expires_from_now(NTP_QUERY_FREQUENCY); timer_.async_wait(std::bind( &SNTPClientImp::onTimer, this, - beast::asio::placeholders::error)); + std::placeholders::_1)); } void @@ -286,8 +285,8 @@ public: socket_.async_receive_from(buffer(buf_, 256), ep_, std::bind(&SNTPClientImp::onRead, this, - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); } //-------------------------------------------------------------------------- @@ -339,8 +338,8 @@ public: boost::asio::ip::udp::v4 (), best->first, "ntp"); resolver_.async_resolve (query, std::bind ( &SNTPClientImp::resolveComplete, this, - beast::asio::placeholders::error, - beast::asio::placeholders::iterator)); + std::placeholders::_1, + std::placeholders::_2)); JLOG(j_.trace()) << "SNTPClock: Resolve pending for " << best->first; return true; @@ -396,8 +395,8 @@ public: reinterpret_cast (SNTPQueryData)[NTP_OFF_XMITTS_FRAC] = query.nonce; socket_.async_send_to(buffer(SNTPQueryData, 48), *sel, std::bind (&SNTPClientImp::onSend, this, - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); } } diff --git a/src/ripple/net/AutoSocket.h b/src/ripple/net/AutoSocket.h index d80af11e4..bec9ccea4 100644 --- a/src/ripple/net/AutoSocket.h +++ b/src/ripple/net/AutoSocket.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -185,8 +184,8 @@ public: std::bind ( &AutoSocket::handle_autodetect, this, cbFunc, - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); } } diff --git a/src/ripple/net/impl/HTTPClient.cpp b/src/ripple/net/impl/HTTPClient.cpp index 61fb76dbb..8adfba5cc 100644 --- a/src/ripple/net/impl/HTTPClient.cpp +++ b/src/ripple/net/impl/HTTPClient.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -196,7 +195,7 @@ public: std::bind ( &HTTPClientImp::handleDeadline, shared_from_this (), - beast::asio::placeholders::error)); + std::placeholders::_1)); } if (!mShutdown) @@ -207,8 +206,8 @@ public: std::bind ( &HTTPClientImp::handleResolve, shared_from_this (), - beast::asio::placeholders::error, - beast::asio::placeholders::iterator)); + std::placeholders::_1, + std::placeholders::_2)); } if (mShutdown) @@ -246,7 +245,7 @@ public: mSocket.async_shutdown (std::bind ( &HTTPClientImp::handleShutdown, shared_from_this (), - beast::asio::placeholders::error)); + std::placeholders::_1)); } } @@ -285,7 +284,7 @@ public: std::bind ( &HTTPClientImp::handleConnect, shared_from_this (), - beast::asio::placeholders::error)); + std::placeholders::_1)); } } @@ -325,7 +324,7 @@ public: std::bind ( &HTTPClientImp::handleRequest, shared_from_this (), - beast::asio::placeholders::error)); + std::placeholders::_1)); } else { @@ -354,8 +353,8 @@ public: mRequest, std::bind (&HTTPClientImp::handleWrite, shared_from_this (), - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); } } @@ -379,8 +378,8 @@ public: "\r\n\r\n", std::bind (&HTTPClientImp::handleHeader, shared_from_this (), - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); } } @@ -430,8 +429,8 @@ public: boost::asio::transfer_all (), std::bind (&HTTPClientImp::handleData, shared_from_this (), - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); + std::placeholders::_1, + std::placeholders::_2)); } } diff --git a/src/ripple/overlay/impl/ConnectAttempt.cpp b/src/ripple/overlay/impl/ConnectAttempt.cpp index ffc41bbee..741820085 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.cpp +++ b/src/ripple/overlay/impl/ConnectAttempt.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -81,7 +80,7 @@ ConnectAttempt::run() error_code ec; stream_.next_layer().async_connect (remote_endpoint_, strand_.wrap (std::bind (&ConnectAttempt::onConnect, - shared_from_this(), beast::asio::placeholders::error))); + shared_from_this(), std::placeholders::_1))); } //------------------------------------------------------------------------------ @@ -138,7 +137,7 @@ ConnectAttempt::setTimer() timer_.async_wait(strand_.wrap(std::bind( &ConnectAttempt::onTimer, shared_from_this(), - beast::asio::placeholders::error))); + std::placeholders::_1))); } void @@ -186,7 +185,7 @@ ConnectAttempt::onConnect (error_code ec) stream_.set_verify_mode (boost::asio::ssl::verify_none); stream_.async_handshake (boost::asio::ssl::stream_base::client, strand_.wrap (std::bind (&ConnectAttempt::onHandshake, - shared_from_this(), beast::asio::placeholders::error))); + shared_from_this(), std::placeholders::_1))); } void @@ -221,12 +220,12 @@ ConnectAttempt::onHandshake (error_code ec) overlay_.setup().public_ip, beast::IPAddressConversion::from_asio(remote_endpoint_), app_); - appendHello (req_.fields, hello); + appendHello (req_, hello); setTimer(); beast::http::async_write(stream_, req_, strand_.wrap (std::bind (&ConnectAttempt::onWrite, - shared_from_this(), beast::asio::placeholders::error))); + shared_from_this(), std::placeholders::_1))); } void @@ -241,7 +240,7 @@ ConnectAttempt::onWrite (error_code ec) return fail("onWrite", ec); beast::http::async_read(stream_, read_buf_, response_, strand_.wrap(std::bind(&ConnectAttempt::onRead, - shared_from_this(), beast::asio::placeholders::error))); + shared_from_this(), std::placeholders::_1))); } void @@ -260,7 +259,7 @@ ConnectAttempt::onRead (error_code ec) setTimer(); return stream_.async_shutdown(strand_.wrap(std::bind( &ConnectAttempt::onShutdown, shared_from_this(), - beast::asio::placeholders::error))); + std::placeholders::_1))); } if(ec) return fail("onRead", ec); @@ -290,26 +289,32 @@ ConnectAttempt::makeRequest (bool crawl, request_type { request_type m; - m.method = "GET"; - m.url = "/"; + m.method(beast::http::verb::get); + m.target("/"); m.version = 11; - m.fields.insert ("User-Agent", BuildInfo::getFullVersionString()); - m.fields.insert ("Upgrade", "RTXP/1.2"); + m.insert ("User-Agent", BuildInfo::getFullVersionString()); + m.insert ("Upgrade", "RTXP/1.2"); //std::string("RTXP/") + to_string (BuildInfo::getCurrentProtocol())); - m.fields.insert ("Connection", "Upgrade"); - m.fields.insert ("Connect-As", "Peer"); - m.fields.insert ("Crawl", crawl ? "public" : "private"); + m.insert ("Connection", "Upgrade"); + m.insert ("Connect-As", "Peer"); + m.insert ("Crawl", crawl ? "public" : "private"); return m; } void ConnectAttempt::processResponse() { - if (response_.status == 503) + if (response_.result() == beast::http::status::service_unavailable) { Json::Value json; Json::Reader r; - auto const success = r.parse(beast::to_string(response_.body.data()), json); + std::string s; + s.reserve(boost::asio::buffer_size(response_.body.data())); + for(auto const& buffer : response_.body.data()) + s.append( + boost::asio::buffer_cast(buffer), + boost::asio::buffer_size(buffer)); + auto const success = r.parse(s, json); if (success) { if (json.isObject() && json.isMember("peer-ips")) @@ -339,11 +344,11 @@ ConnectAttempt::processResponse() if (! OverlayImpl::isPeerUpgrade(response_)) { JLOG(journal_.info()) << - "HTTP Response: " << response_.status << " " << response_.reason; + "HTTP Response: " << response_.result() << " " << response_.reason(); return close(); } - auto hello = parseHello (false, response_.fields, journal_); + auto hello = parseHello (false, response_, journal_); if(! hello) return fail("processResponse: Bad TMHello"); diff --git a/src/ripple/overlay/impl/ConnectAttempt.h b/src/ripple/overlay/impl/ConnectAttempt.h index e450dd9a3..d27ff5bad 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.h +++ b/src/ripple/overlay/impl/ConnectAttempt.h @@ -31,11 +31,10 @@ #include #include #include -#include -#include -#include +#include #include -#include +#include +#include #include #include #include @@ -59,7 +58,7 @@ private: beast::http::request; using response_type = - beast::http::response; + beast::http::response; Application& app_; std::uint32_t const id_; @@ -72,7 +71,7 @@ private: std::unique_ptr ssl_bundle_; beast::asio::ssl_bundle::socket_type& socket_; beast::asio::ssl_bundle::stream_type& stream_; - beast::streambuf read_buf_; + beast::multi_buffer read_buf_; response_type response_; PeerFinder::Slot::ptr slot_; request_type req_; diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index f850d74f6..717c311a3 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -102,7 +102,7 @@ OverlayImpl::Timer::run() timer_.expires_from_now (std::chrono::seconds(1)); timer_.async_wait(overlay_.strand_.wrap( std::bind(&Timer::on_timer, shared_from_this(), - beast::asio::placeholders::error))); + std::placeholders::_1))); } void @@ -127,7 +127,7 @@ OverlayImpl::Timer::on_timer (error_code ec) timer_.expires_from_now (std::chrono::seconds(1)); timer_.async_wait(overlay_.strand_.wrap(std::bind( &Timer::on_timer, shared_from_this(), - beast::asio::placeholders::error))); + std::placeholders::_1))); } //------------------------------------------------------------------------------ @@ -219,7 +219,7 @@ OverlayImpl::onHandoff (std::unique_ptr && ssl_bundle, { auto const types = beast::rfc2616::split_commas( - request.fields["Connect-As"]); + request["Connect-As"]); if (std::find_if(types.begin(), types.end(), [](std::string const& s) { @@ -229,12 +229,12 @@ OverlayImpl::onHandoff (std::unique_ptr && ssl_bundle, handoff.moved = false; handoff.response = makeRedirectResponse(slot, request, remote_endpoint.address()); - handoff.keep_alive = is_keep_alive(request); + handoff.keep_alive = beast::rfc2616::is_keep_alive(request); return handoff; } } - auto hello = parseHello (true, request.fields, journal); + auto hello = parseHello (true, request, journal); if(! hello) { m_peerFinder->on_closed(slot); @@ -285,7 +285,7 @@ OverlayImpl::onHandoff (std::unique_ptr && ssl_bundle, handoff.moved = false; handoff.response = makeRedirectResponse(slot, request, remote_endpoint.address()); - handoff.keep_alive = is_keep_alive(request); + handoff.keep_alive = beast::rfc2616::is_keep_alive(request); return handoff; } @@ -313,27 +313,39 @@ OverlayImpl::onHandoff (std::unique_ptr && ssl_bundle, //------------------------------------------------------------------------------ +template +static +bool +is_upgrade(beast::http::header const& req) +{ + if(req.version < 11) + return false; + if(req.method() != beast::http::verb::get) + return false; + if(! beast::http::token_list{req["Connection"]}.exists("upgrade")) + return false; + return true; +} + +template +static +bool +is_upgrade(beast::http::header const& req) +{ + if(req.version < 11) + return false; + if(! beast::http::token_list{req["Connection"]}.exists("upgrade")) + return false; + return true; +} + bool OverlayImpl::isPeerUpgrade(http_request_type const& request) { if (! is_upgrade(request)) return false; auto const versions = parse_ProtocolVersions( - request.fields["Upgrade"]); - if (versions.size() == 0) - return false; - return true; -} - -bool -OverlayImpl::isPeerUpgrade(http_response_type const& response) -{ - if (! is_upgrade(response)) - return false; - if(response.status != 101) - return false; - auto const versions = parse_ProtocolVersions( - response.fields["Upgrade"]); + request["Upgrade"]); if (versions.size() == 0) return false; return true; @@ -353,11 +365,11 @@ OverlayImpl::makeRedirectResponse (PeerFinder::Slot::ptr const& slot, { beast::http::response msg; msg.version = request.version; - msg.status = 503; - msg.reason = "Service Unavailable"; - msg.fields.insert("Server", BuildInfo::getFullVersionString()); - msg.fields.insert("Remote-Address", remote_address.to_string()); - msg.fields.insert("Content-Type", "application/json"); + msg.result(beast::http::status::service_unavailable); + msg.insert("Server", BuildInfo::getFullVersionString()); + msg.insert("Remote-Address", remote_address); + msg.insert("Content-Type", "application/json"); + msg.insert(beast::http::field::connection, "close"); msg.body = Json::objectValue; { auto const result = m_peerFinder->redirect(slot); @@ -365,7 +377,7 @@ OverlayImpl::makeRedirectResponse (PeerFinder::Slot::ptr const& slot, for (auto const& _ : m_peerFinder->redirect(slot)) ips.append(_.address.to_string()); } - prepare(msg, beast::http::connection::close); + msg.prepare(); return std::make_shared(msg); } @@ -377,12 +389,12 @@ OverlayImpl::makeErrorResponse (PeerFinder::Slot::ptr const& slot, { beast::http::response msg; msg.version = request.version; - msg.status = 400; - msg.reason = "Bad Request"; - msg.fields.insert("Server", BuildInfo::getFullVersionString()); - msg.fields.insert("Remote-Address", remote_address.to_string()); + msg.result(beast::http::status::bad_request); + msg.insert("Server", BuildInfo::getFullVersionString()); + msg.insert("Remote-Address", remote_address.to_string()); + msg.insert(beast::http::field::connection, "close"); msg.body = text; - prepare(msg, beast::http::connection::close); + msg.prepare(); return std::make_shared(msg); } @@ -827,17 +839,17 @@ bool OverlayImpl::processRequest (http_request_type const& req, Handoff& handoff) { - if (req.url != "/crawl") + if (req.target() != "/crawl") return false; beast::http::response msg; msg.version = req.version; - msg.status = 200; - msg.reason = "OK"; - msg.fields.insert("Server", BuildInfo::getFullVersionString()); - msg.fields.insert("Content-Type", "application/json"); + msg.result(beast::http::status::ok); + msg.insert("Server", BuildInfo::getFullVersionString()); + msg.insert("Content-Type", "application/json"); + msg.insert("Connection", "close"); msg.body["overlay"] = crawl(); - prepare(msg, beast::http::connection::close); + msg.prepare(); handoff.response = std::make_shared(msg); return true; } diff --git a/src/ripple/overlay/impl/OverlayImpl.h b/src/ripple/overlay/impl/OverlayImpl.h index bc1e327c2..18d7e914b 100644 --- a/src/ripple/overlay/impl/OverlayImpl.h +++ b/src/ripple/overlay/impl/OverlayImpl.h @@ -248,9 +248,21 @@ public: bool isPeerUpgrade (http_request_type const& request); + template static bool - isPeerUpgrade (http_response_type const& response); + isPeerUpgrade (beast::http::response const& response) + { + if (! is_upgrade(response)) + return false; + if(response.result() != beast::http::status::switching_protocols) + return false; + auto const versions = parse_ProtocolVersions( + response["Upgrade"]); + if (versions.size() == 0) + return false; + return true; + } static std::string diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index e2ec14eee..50a797c6a 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -91,7 +92,7 @@ PeerImp::PeerImp (Application& app, id_t id, endpoint_type remote_endpoint, , fee_ (Resource::feeLightPeer) , slot_ (slot) , request_(std::move(request)) - , headers_(request_.fields) + , headers_(request_) { } @@ -225,8 +226,8 @@ PeerImp::send (Message::pointer const& m) boost::asio::async_write (stream_, boost::asio::buffer( send_queue_.front()->getBuffer()), strand_.wrap(std::bind( &PeerImp::onWriteMessage, shared_from_this(), - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred))); + std::placeholders::_1, + std::placeholders::_2))); } void @@ -248,7 +249,7 @@ PeerImp::crawl() const auto const iter = headers_.find("Crawl"); if (iter == headers_.end()) return false; - return beast::detail::ci_equal(iter->second, "public"); + return beast::detail::ci_equal(iter->value(), "public"); } std::string @@ -482,7 +483,7 @@ PeerImp::gracefulClose() return; setTimer(); stream_.async_shutdown(strand_.wrap(std::bind(&PeerImp::onShutdown, - shared_from_this(), beast::asio::placeholders::error))); + shared_from_this(), std::placeholders::_1))); } void @@ -498,7 +499,7 @@ PeerImp::setTimer() return; } timer_.async_wait(strand_.wrap(std::bind(&PeerImp::onTimer, - shared_from_this(), beast::asio::placeholders::error))); + shared_from_this(), std::placeholders::_1))); } // convenience for ignoring the error code @@ -609,9 +610,9 @@ void PeerImp::doAccept() // TODO Apply headers to connection state. - beast::write (write_buffer_, makeResponse( + beast::ostream(write_buffer_) << makeResponse( ! overlay_.peerFinder().config().peerPrivate, - request_, remote_address_, *sharedValue)); + request_, remote_address_, *sharedValue); auto const protocol = BuildInfo::make_protocol(hello_.protoversion()); JLOG(journal_.info()) << "Protocol: " << to_string(protocol); @@ -657,17 +658,16 @@ PeerImp::makeResponse (bool crawl, uint256 const& sharedValue) { http_response_type resp; - resp.status = 101; - resp.reason = "Switching Protocols"; + resp.result(beast::http::status::switching_protocols); resp.version = req.version; - resp.fields.insert("Connection", "Upgrade"); - resp.fields.insert("Upgrade", "RTXP/1.2"); - resp.fields.insert("Connect-AS", "Peer"); - resp.fields.insert("Server", BuildInfo::getFullVersionString()); - resp.fields.insert("Crawl", crawl ? "public" : "private"); + resp.insert("Connection", "Upgrade"); + resp.insert("Upgrade", "RTXP/1.2"); + resp.insert("Connect-As", "Peer"); + resp.insert("Server", BuildInfo::getFullVersionString()); + resp.insert("Crawl", crawl ? "public" : "private"); protocol::TMHello hello = buildHello(sharedValue, overlay_.setup().public_ip, remote, app_); - appendHello(resp.fields, hello); + appendHello(resp, hello); return resp; } @@ -696,8 +696,8 @@ PeerImp::onWriteResponse (error_code ec, std::size_t bytes_transferred) stream_.async_write_some (write_buffer_.data(), strand_.wrap (std::bind (&PeerImp::onWriteResponse, - shared_from_this(), beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred))); + shared_from_this(), std::placeholders::_1, + std::placeholders::_2))); } //------------------------------------------------------------------------------ @@ -771,8 +771,8 @@ PeerImp::onReadMessage (error_code ec, std::size_t bytes_transferred) // Timeout on writes only stream_.async_read_some (read_buffer_.prepare (Tuning::readBufferBytes), strand_.wrap (std::bind (&PeerImp::onReadMessage, - shared_from_this(), beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred))); + shared_from_this(), std::placeholders::_1, + std::placeholders::_2))); } void @@ -801,15 +801,15 @@ PeerImp::onWriteMessage (error_code ec, std::size_t bytes_transferred) return boost::asio::async_write (stream_, boost::asio::buffer( send_queue_.front()->getBuffer()), strand_.wrap(std::bind( &PeerImp::onWriteMessage, shared_from_this(), - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred))); + std::placeholders::_1, + std::placeholders::_2))); } if (gracefulClose_) { return stream_.async_shutdown(strand_.wrap(std::bind( &PeerImp::onShutdown, shared_from_this(), - beast::asio::placeholders::error))); + std::placeholders::_1))); } } diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h index 9b7ed91b9..2f29128ef 100644 --- a/src/ripple/overlay/impl/PeerImp.h +++ b/src/ripple/overlay/impl/PeerImp.h @@ -35,11 +35,10 @@ #include #include #include -#include -#include +#include #include #include -#include +#include #include #include #include @@ -151,11 +150,11 @@ private: Resource::Consumer usage_; Resource::Charge fee_; PeerFinder::Slot::ptr slot_; - beast::streambuf read_buffer_; + beast::multi_buffer read_buffer_; http_request_type request_; http_response_type response_; beast::http::fields const& headers_; - beast::streambuf write_buffer_; + beast::multi_buffer write_buffer_; std::queue send_queue_; bool gracefulClose_ = false; int large_sendq_ = 0; @@ -502,7 +501,7 @@ PeerImp::PeerImp (Application& app, std::unique_ptr&& s , fee_ (Resource::feeLightPeer) , slot_ (std::move(slot)) , response_(std::move(response)) - , headers_(response_.fields) + , headers_(response_) { read_buffer_.commit (boost::asio::buffer_copy(read_buffer_.prepare( boost::asio::buffer_size(buffers)), buffers)); diff --git a/src/ripple/overlay/impl/PeerSet.cpp b/src/ripple/overlay/impl/PeerSet.cpp index e89e2b2c3..ac282cc60 100644 --- a/src/ripple/overlay/impl/PeerSet.cpp +++ b/src/ripple/overlay/impl/PeerSet.cpp @@ -22,7 +22,6 @@ #include #include #include -#include namespace ripple { diff --git a/src/ripple/overlay/impl/TMHello.cpp b/src/ripple/overlay/impl/TMHello.cpp index 9fae0b4b0..cdf12c1af 100644 --- a/src/ripple/overlay/impl/TMHello.cpp +++ b/src/ripple/overlay/impl/TMHello.cpp @@ -233,7 +233,7 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) auto const iter = h.find ("Upgrade"); if (iter == h.end()) return boost::none; - auto const versions = parse_ProtocolVersions(iter->second); + auto const versions = parse_ProtocolVersions(iter->value().to_string()); if (versions.empty()) return boost::none; hello.set_protoversion( @@ -250,10 +250,10 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) if (iter == h.end()) return boost::none; auto const pk = parseBase58( - TokenType::TOKEN_NODE_PUBLIC, iter->second); + TokenType::TOKEN_NODE_PUBLIC, iter->value().to_string()); if (!pk) return boost::none; - hello.set_nodepublic (iter->second); + hello.set_nodepublic (iter->value().to_string()); } { @@ -262,14 +262,14 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) if (iter == h.end()) return boost::none; // TODO Security Review - hello.set_nodeproof (beast::detail::base64_decode (iter->second)); + hello.set_nodeproof (beast::detail::base64_decode (iter->value().to_string())); } { auto const iter = h.find (request ? "User-Agent" : "Server"); if (iter != h.end()) - hello.set_fullversion (iter->second); + hello.set_fullversion (iter->value().to_string()); } { @@ -277,7 +277,7 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) if (iter != h.end()) { std::uint64_t nettime; - if (! beast::lexicalCastChecked(nettime, iter->second)) + if (! beast::lexicalCastChecked(nettime, iter->value().to_string())) return boost::none; hello.set_nettime (nettime); } @@ -288,7 +288,7 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) if (iter != h.end()) { LedgerIndex ledgerIndex; - if (! beast::lexicalCastChecked(ledgerIndex, iter->second)) + if (! beast::lexicalCastChecked(ledgerIndex, iter->value().to_string())) return boost::none; hello.set_ledgerindex (ledgerIndex); } @@ -297,13 +297,13 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) { auto const iter = h.find ("Closed-Ledger"); if (iter != h.end()) - hello.set_ledgerclosed (beast::detail::base64_decode (iter->second)); + hello.set_ledgerclosed (beast::detail::base64_decode (iter->value().to_string())); } { auto const iter = h.find ("Previous-Ledger"); if (iter != h.end()) - hello.set_ledgerprevious (beast::detail::base64_decode (iter->second)); + hello.set_ledgerprevious (beast::detail::base64_decode (iter->value().to_string())); } { @@ -313,7 +313,7 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) bool valid; beast::IP::Address address; std::tie (address, valid) = - beast::IP::Address::from_string (iter->second); + beast::IP::Address::from_string (iter->value().to_string()); if (!valid) return boost::none; if (address.is_v4()) @@ -328,7 +328,7 @@ parseHello (bool request, beast::http::fields const& h, beast::Journal journal) bool valid; beast::IP::Address address; std::tie (address, valid) = - beast::IP::Address::from_string (iter->second); + beast::IP::Address::from_string (iter->value().to_string()); if (!valid) return boost::none; if (address.is_v4()) diff --git a/src/ripple/peerfinder/impl/Checker.h b/src/ripple/peerfinder/impl/Checker.h index c432fe194..982979e16 100644 --- a/src/ripple/peerfinder/impl/Checker.h +++ b/src/ripple/peerfinder/impl/Checker.h @@ -21,7 +21,6 @@ #define RIPPLE_PEERFINDER_CHECKER_H_INCLUDED #include -#include #include #include #include @@ -215,7 +214,7 @@ Checker::async_connect ( } op->socket_.async_connect (beast::IPAddressConversion::to_asio_endpoint ( endpoint), std::bind (&basic_async_op::operator(), op, - beast::asio::placeholders::error)); + std::placeholders::_1)); } template diff --git a/src/ripple/rpc/impl/ServerHandlerImp.cpp b/src/ripple/rpc/impl/ServerHandlerImp.cpp index 338201a60..9b07094ea 100644 --- a/src/ripple/rpc/impl/ServerHandlerImp.cpp +++ b/src/ripple/rpc/impl/ServerHandlerImp.cpp @@ -52,26 +52,16 @@ namespace ripple { -// Returns `true` if the HTTP request is a Websockets Upgrade -// http://en.wikipedia.org/wiki/HTTP/1.1_Upgrade_header#Use_with_WebSockets -static -bool -isWebsocketUpgrade( - http_request_type const& request) -{ - if (is_upgrade(request)) - return beast::detail::ci_equal( - request.fields["Upgrade"], "websocket"); - return false; -} - static bool isStatusRequest( http_request_type const& request) { - return request.version >= 11 && request.url == "/" && - request.body.size() == 0 && request.method == "GET"; + return + request.version >= 11 && + request.target() == "/" && + request.body.size() == 0 && + request.method() == beast::http::verb::get; } static @@ -83,12 +73,12 @@ unauthorizedResponse( Handoff handoff; response msg; msg.version = request.version; - msg.status = 401; - msg.reason = "Unauthorized"; - msg.fields.insert("Server", BuildInfo::getFullVersionString()); - msg.fields.insert("Content-Type", "text/html"); + msg.result(beast::http::status::unauthorized); + msg.insert("Server", BuildInfo::getFullVersionString()); + msg.insert("Content-Type", "text/html"); + msg.insert("Connection", "close"); msg.body = "Invalid protocol."; - prepare(msg, beast::http::connection::close); + msg.prepare(); handoff.response = std::make_shared(msg); return handoff; } @@ -189,7 +179,7 @@ ServerHandlerImp::onHandoff (Session& session, (session.port().protocol.count("wss") > 0) || (session.port().protocol.count("wss2") > 0); - if(isWebsocketUpgrade(request)) + if(beast::websocket::is_upgrade(request)) { if(is_ws) { @@ -229,7 +219,7 @@ ServerHandlerImp::onHandoff (Session& session, boost::asio::ip::tcp::endpoint remote_address) -> Handoff { - if(isWebsocketUpgrade(request)) + if(beast::websocket::is_upgrade(request)) { if (session.port().protocol.count("ws2") > 0 || session.port().protocol.count("ws") > 0) @@ -275,10 +265,10 @@ build_map(beast::http::fields const& h) std::map c; for (auto const& e : h) { - auto key (e.first); + auto key (e.name_string().to_string()); // TODO Replace with safe C++14 version std::transform (key.begin(), key.end(), key.begin(), ::tolower); - c [key] = e.second; + c [key] = e.value().to_string(); } return c; } @@ -312,7 +302,7 @@ ServerHandlerImp::onRequest (Session& session) // Check user/password authorization if (! authorized ( - session.port(), build_map(session.request().fields))) + session.port(), build_map(session.request()))) { HTTPReply (403, "Forbidden", makeOutput (session), app_.journal ("RPC")); session.close (true); @@ -342,7 +332,7 @@ ServerHandlerImp::onWSMessage( jvResult[jss::type] = jss::error; jvResult[jss::error] = "jsonInvalid"; jvResult[jss::value] = buffers_to_string(buffers); - beast::streambuf sb; + beast::multi_buffer sb; Json::stream(jvResult, [&sb](auto const p, auto const n) { @@ -368,7 +358,7 @@ ServerHandlerImp::onWSMessage( this->processSession(session, c, jv); auto const s = to_string(jr); auto const n = s.length(); - beast::streambuf sb(n); + beast::multi_buffer sb(n); sb.commit(boost::asio::buffer_copy( sb.prepare(n), boost::asio::buffer(s.c_str(), n))); session->send(std::make_shared< @@ -511,23 +501,23 @@ ServerHandlerImp::processSession (std::shared_ptr const& session, [&] { auto const iter = - session->request().fields.find( + session->request().find( "X-Forwarded-For"); - if(iter != session->request().fields.end()) - return iter->second; + if(iter != session->request().end()) + return iter->value().to_string(); return std::string{}; }(), [&] { auto const iter = - session->request().fields.find( + session->request().find( "X-User"); - if(iter != session->request().fields.end()) - return iter->second; + if(iter != session->request().end()) + return iter->value().to_string(); return std::string{}; }()); - if(is_keep_alive(session->request())) + if(beast::rfc2616::is_keep_alive(session->request())) session->complete(); else session->close (true); @@ -738,8 +728,7 @@ ServerHandlerImp::statusResponse( std::string reason; if (app_.serverOkay(reason)) { - msg.status = 200; - msg.reason = "OK"; + msg.result(beast::http::status::ok); msg.body = "" + systemName() + " Test page for rippled

" + systemName() + " Test

This page shows rippled http(s) " @@ -747,15 +736,15 @@ ServerHandlerImp::statusResponse( } else { - msg.status = 500; - msg.reason = "Internal Server Error"; + msg.result(beast::http::status::internal_server_error); msg.body = "Server cannot accept clients: " + reason + ""; } msg.version = request.version; - msg.fields.insert("Server", BuildInfo::getFullVersionString()); - msg.fields.insert("Content-Type", "text/html"); - prepare(msg, beast::http::connection::close); + msg.insert("Server", BuildInfo::getFullVersionString()); + msg.insert("Content-Type", "text/html"); + msg.insert("Connection", "close"); + msg.prepare(); handoff.response = std::make_shared(msg); return handoff; } diff --git a/src/ripple/rpc/impl/WSInfoSub.h b/src/ripple/rpc/impl/WSInfoSub.h index e27677b0d..c53a33471 100644 --- a/src/ripple/rpc/impl/WSInfoSub.h +++ b/src/ripple/rpc/impl/WSInfoSub.h @@ -42,17 +42,17 @@ public: : InfoSub(source) , ws_(ws) { - auto const& h = ws->request().fields; + auto const& h = ws->request(); auto it = h.find("X-User"); if (it != h.end() && isIdentified( ws->port(), beast::IPAddressConversion::from_asio( - ws->remote_endpoint()).address(), it->second)) + ws->remote_endpoint()).address(), it->value().to_string())) { - user_ = it->second; + user_ = it->value().to_string(); it = h.find("X-Forwarded-For"); if (it != h.end()) - fwdfor_ = it->second; + fwdfor_ = it->value().to_string(); } } @@ -74,7 +74,7 @@ public: auto sp = ws_.lock(); if(! sp) return; - beast::streambuf sb; + beast::multi_buffer sb; stream(jv, [&](void const* data, std::size_t n) { diff --git a/src/ripple/rpc/json_body.h b/src/ripple/rpc/json_body.h index 9a92324c4..6dc1e8786 100644 --- a/src/ripple/rpc/json_body.h +++ b/src/ripple/rpc/json_body.h @@ -21,7 +21,7 @@ #define RIPPLE_RPC_JSON_BODY_H #include -#include +#include #include namespace ripple { @@ -31,21 +31,28 @@ struct json_body { using value_type = Json::Value; - class writer + class reader { - beast::streambuf sb_; + using dynamic_buffer_type = beast::multi_buffer; + + dynamic_buffer_type buffer_; public: + using const_buffers_type = + typename dynamic_buffer_type::const_buffers_type; + + using is_deferred = std::false_type; + template explicit - writer(beast::http::message< - isRequest, json_body, Fields> const& m) noexcept + reader(beast::http::message< + isRequest, json_body, Fields> const& m) { stream(m.body, [&](void const* data, std::size_t n) { - sb_.commit(boost::asio::buffer_copy( - sb_.prepare(n), boost::asio::buffer(data, n))); + buffer_.commit(boost::asio::buffer_copy( + buffer_.prepare(n), boost::asio::buffer(data, n))); }); } @@ -54,18 +61,15 @@ struct json_body { } - std::uint64_t - content_length() const noexcept + boost::optional> + get(beast::error_code& ec) { - return sb_.size(); + return {{buffer_.data(), false}}; } - template - bool - write(beast::error_code&, Writef&& wf) noexcept + void + finish(beast::error_code&) { - wf(sb_.data()); - return true; } }; }; diff --git a/src/ripple/server/Handoff.h b/src/ripple/server/Handoff.h index 474d67955..48220545f 100644 --- a/src/ripple/server/Handoff.h +++ b/src/ripple/server/Handoff.h @@ -22,16 +22,16 @@ #include #include -#include +#include #include namespace ripple { using http_request_type = - beast::http::request; + beast::http::request; using http_response_type = - beast::http::response; + beast::http::response; /** Used to indicate the result of a server connection handoff. */ struct Handoff diff --git a/src/ripple/server/SimpleWriter.h b/src/ripple/server/SimpleWriter.h index a05d8cfbe..9d17dbd1c 100644 --- a/src/ripple/server/SimpleWriter.h +++ b/src/ripple/server/SimpleWriter.h @@ -21,8 +21,8 @@ #define RIPPLE_SERVER_SIMPLEWRITER_H_INCLUDED #include -#include -#include +#include +#include #include #include #include @@ -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 @@ -40,7 +40,7 @@ public: SimpleWriter(beast::http::message< isRequest, Body, Headers> const& msg) { - beast::write(sb_, msg); + beast::ostream(sb_) << msg; } bool diff --git a/src/ripple/server/WSSession.h b/src/ripple/server/WSSession.h index 254d86d64..b89e5d3cc 100644 --- a/src/ripple/server/WSSession.h +++ b/src/ripple/server/WSSession.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -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 vb ( std::distance(pb.begin(), pb.end())); std::copy(pb.begin(), pb.end(), std::back_inserter(vb)); diff --git a/src/ripple/server/impl/BaseHTTPPeer.h b/src/ripple/server/impl/BaseHTTPPeer.h index f9c212d86..070ecbe07 100644 --- a/src/ripple/server/impl/BaseHTTPPeer.h +++ b/src/ripple/server/impl/BaseHTTPPeer.h @@ -24,12 +24,11 @@ #include #include #include -#include #include // for is_short_read? #include #include -#include -#include +#include +#include #include #include #include @@ -288,7 +287,7 @@ start_timer() return fail(ec, "start_timer"); timer_.async_wait(strand_.wrap(std::bind( &BaseHTTPPeer::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; diff --git a/src/ripple/server/impl/BaseWSPeer.h b/src/ripple/server/impl/BaseWSPeer.h index 5e9946837..1b82e4346 100644 --- a/src/ripple/server/impl/BaseWSPeer.h +++ b/src/ripple/server/impl/BaseWSPeer.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include @@ -48,9 +48,8 @@ private: friend class BasePeer; http_request_type request_; - beast::websocket::opcode op_; - beast::streambuf rb_; - beast::streambuf wb_; + beast::multi_buffer rb_; + beast::multi_buffer wb_; std::list> wq_; bool do_close_ = false; beast::websocket::close_reason cr_; @@ -105,25 +104,6 @@ public: complete() override; protected: - struct identity - { - template - void - operator()(beast::http::message& req) const - { - req.fields.replace("User-Agent", - BuildInfo::getFullVersionString()); - } - - template - void - operator()(beast::http::message& 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 @@ -227,7 +211,7 @@ send(std::shared_ptr w) { JLOG(this->j_.info()) << "closing slow client"; - cr_.code = static_cast(4000); + cr_.code = static_cast(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 @@ -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 @@ -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 @@ -385,7 +369,7 @@ start_timer() return fail(ec, "start_timer"); timer_.async_wait(strand_.wrap(std::bind( &BaseWSPeer::on_timer, impl().shared_from_this(), - beast::asio::placeholders::error))); + std::placeholders::_1))); } // Convenience for discarding the error code diff --git a/src/ripple/server/impl/Door.h b/src/ripple/server/impl/Door.h index 3d9020fbc..322c3e1f9 100644 --- a/src/ripple/server/impl/Door.h +++ b/src/ripple/server/impl/Door.h @@ -26,8 +26,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -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; diff --git a/src/ripple/server/impl/PlainHTTPPeer.h b/src/ripple/server/impl/PlainHTTPPeer.h index ec3e34579..735511398 100644 --- a/src/ripple/server/impl/PlainHTTPPeer.h +++ b/src/ripple/server/impl/PlainHTTPPeer.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED #define RIPPLE_SERVER_PLAINHTTPPEER_H_INCLUDED +#include #include #include #include @@ -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"); diff --git a/src/ripple/server/impl/SSLWSPeer.h b/src/ripple/server/impl/SSLWSPeer.h index 383ebfd28..1bf9afe49 100644 --- a/src/ripple/server/impl/SSLWSPeer.h +++ b/src/ripple/server/impl/SSLWSPeer.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include diff --git a/src/test/app/ValidatorSite_test.cpp b/src/test/app/ValidatorSite_test.cpp index 7a96691ae..eb8d0605e 100644 --- a/src/test/app/ValidatorSite_test.cpp +++ b/src/test/app/ValidatorSite_test.cpp @@ -17,7 +17,6 @@ */ //============================================================================== -#include #include #include #include @@ -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) diff --git a/src/test/jtx/Env.h b/src/test/jtx/Env.h index 3cea99248..9dbbe9597 100644 --- a/src/test/jtx/Env.h +++ b/src/test/jtx/Env.h @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include #include @@ -642,7 +642,7 @@ protected: FN const&... fN) { maybe_invoke(stx, f, - beast::detail::is_call_possible()); invoke(stx, fN...); } @@ -676,7 +676,7 @@ protected: FN const&... fN) { maybe_invoke(jt, f, - beast::detail::is_call_possible()); invoke(jt, fN...); } diff --git a/src/test/jtx/impl/JSONRPCClient.cpp b/src/test/jtx/impl/JSONRPCClient.cpp index 72ad45e4d..5250550c4 100644 --- a/src/test/jtx/impl/JSONRPCClient.cpp +++ b/src/test/jtx/impl/JSONRPCClient.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -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 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 res; + response res; read(stream_, bin_, res); Json::Reader jr; diff --git a/src/test/jtx/impl/WSClient.cpp b/src/test/jtx/impl/WSClient.cpp index ce3d56699..9f5de744b 100644 --- a/src/test/jtx/impl/WSClient.cpp +++ b/src/test/jtx/impl/WSClient.cpp @@ -24,8 +24,7 @@ #include #include #include -#include -#include +#include #include #include @@ -95,8 +94,7 @@ class WSClientImpl : public WSClient std::thread thread_; boost::asio::ip::tcp::socket stream_; beast::websocket::stream 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 diff --git a/src/test/overlay/short_read_test.cpp b/src/test/overlay/short_read_test.cpp index 7d2f99550..20bf5af05 100644 --- a/src/test/overlay/short_read_test.cpp +++ b/src/test/overlay/short_read_test.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -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 diff --git a/src/test/server/ServerStatus_test.cpp b/src/test/server/ServerStatus_test.cpp index 94d238571..16158fde4 100644 --- a/src/test/server/ServerStatus_test.cpp +++ b/src/test/server/ServerStatus_test.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -86,17 +85,18 @@ class ServerStatus_test : using namespace beast::http; request 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 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( diff --git a/src/test/server/Server_test.cpp b/src/test/server/Server_test.cpp index 4f59e6886..b5e38f8d5 100644 --- a/src/test/server/Server_test.cpp +++ b/src/test/server/Server_test.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -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);