mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-07 20:25:49 +00:00
Changes for Beast version 59
This commit is contained in:
committed by
Miguel Portilla
parent
49bdf2e72d
commit
61316c7f95
@@ -22,8 +22,7 @@
|
||||
|
||||
#include <ripple/app/misc/detail/Work.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/http/empty_body.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
@@ -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<Impl>::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<class Impl>
|
||||
@@ -171,24 +170,23 @@ WorkBase<Impl>::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<class Impl>
|
||||
void
|
||||
WorkBase<Impl>::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<class Impl>
|
||||
@@ -200,7 +198,7 @@ WorkBase<Impl>::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<class Impl>
|
||||
|
||||
@@ -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 <std::mutex> 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)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <ripple/basics/ResolverAsio.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <ripple/beast/core/WaitableEvent.h>
|
||||
#include <boost/asio.hpp>
|
||||
#include <atomic>
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <ripple/basics/win32_workaround.h>
|
||||
#include <ripple/beast/xor_shift_engine.h>
|
||||
#include <beast/core/detail/is_call_possible.hpp>
|
||||
#include <beast/core/detail/type_traits.hpp>
|
||||
#include <boost/thread/tss.hpp>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
@@ -52,7 +52,7 @@ namespace detail {
|
||||
// Determines if a type can be called like an Engine
|
||||
template <class Engine, class Result = typename Engine::result_type>
|
||||
using is_engine =
|
||||
beast::detail::is_call_possible<Engine, Result()>;
|
||||
beast::detail::is_invocable<Engine, Result()>;
|
||||
}
|
||||
|
||||
/** Return the default random engine.
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <ripple/beast/insight/GaugeImpl.h>
|
||||
#include <ripple/beast/insight/MeterImpl.h>
|
||||
#include <ripple/beast/insight/StatsDCollector.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <ripple/beast/core/List.h>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
@@ -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)
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef BEAST_RFC2616_HPP
|
||||
#define BEAST_RFC2616_HPP
|
||||
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/rfc7230.hpp>
|
||||
#include <boost/range/algorithm/equal.hpp>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
@@ -464,6 +466,17 @@ token_in_list(boost::string_ref const& value,
|
||||
return false;
|
||||
}
|
||||
|
||||
template<bool isRequest, class Body, class Fields>
|
||||
bool
|
||||
is_keep_alive(beast::http::message<isRequest, Body, Fields> 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
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/random.h>
|
||||
#include <ripple/beast/core/CurrentThreadName.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <cmath>
|
||||
@@ -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<std::uint32_t*> (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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <beast/core/bind_handler.hpp>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/net/HTTPClient.h>
|
||||
#include <ripple/net/AutoSocket.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <ripple/beast/core/LexicalCast.h>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <ripple/overlay/impl/PeerImp.h>
|
||||
#include <ripple/overlay/impl/Tuning.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <beast/core/to_string.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
|
||||
@@ -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<char const*>(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");
|
||||
|
||||
|
||||
@@ -31,11 +31,10 @@
|
||||
#include <ripple/beast/asio/ssl_bundle.h>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <ripple/beast/utility/WrappedSink.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/http/empty_body.hpp>
|
||||
#include <beast/http/parser_v1.hpp>
|
||||
#include <beast/http/string_body.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/buffers_iterator.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
@@ -59,7 +58,7 @@ private:
|
||||
beast::http::request<beast::http::empty_body>;
|
||||
|
||||
using response_type =
|
||||
beast::http::response<beast::http::streambuf_body>;
|
||||
beast::http::response<beast::http::dynamic_body>;
|
||||
|
||||
Application& app_;
|
||||
std::uint32_t const id_;
|
||||
@@ -72,7 +71,7 @@ private:
|
||||
std::unique_ptr<beast::asio::ssl_bundle> 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_;
|
||||
|
||||
@@ -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 <beast::asio::ssl_bundle>&& 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 <beast::asio::ssl_bundle>&& 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 <beast::asio::ssl_bundle>&& 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 <beast::asio::ssl_bundle>&& ssl_bundle,
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<class Fields>
|
||||
static
|
||||
bool
|
||||
is_upgrade(beast::http::header<true, Fields> 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<class Fields>
|
||||
static
|
||||
bool
|
||||
is_upgrade(beast::http::header<false, Fields> 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<json_body> 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<SimpleWriter>(msg);
|
||||
}
|
||||
|
||||
@@ -377,12 +389,12 @@ OverlayImpl::makeErrorResponse (PeerFinder::Slot::ptr const& slot,
|
||||
{
|
||||
beast::http::response<beast::http::string_body> 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<SimpleWriter>(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<json_body> 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<SimpleWriter>(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -248,9 +248,21 @@ public:
|
||||
bool
|
||||
isPeerUpgrade (http_request_type const& request);
|
||||
|
||||
template<class Body>
|
||||
static
|
||||
bool
|
||||
isPeerUpgrade (http_response_type const& response);
|
||||
isPeerUpgrade (beast::http::response<Body> 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
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/beast/core/SemanticVersion.h>
|
||||
#include <ripple/beast/utility/weak_fn.h>
|
||||
#include <beast/core/ostream.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,10 @@
|
||||
#include <ripple/protocol/STValidation.h>
|
||||
#include <ripple/beast/core/ByteOrder.h>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <ripple/beast/asio/ssl_bundle.h>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/parser_v1.hpp>
|
||||
#include <beast/http/parser.hpp>
|
||||
#include <ripple/beast/utility/WrappedSink.h>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
@@ -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<Message::pointer> send_queue_;
|
||||
bool gracefulClose_ = false;
|
||||
int large_sendq_ = 0;
|
||||
@@ -502,7 +501,7 @@ PeerImp::PeerImp (Application& app, std::unique_ptr<beast::asio::ssl_bundle>&& 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));
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/overlay/Overlay.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
|
||||
@@ -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<PublicKey>(
|
||||
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())
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#define RIPPLE_PEERFINDER_CHECKER_H_INCLUDED
|
||||
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
#include <boost/asio/detail/handler_invoke_helpers.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
@@ -215,7 +214,7 @@ Checker<Protocol>::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 <class Protocol>
|
||||
|
||||
@@ -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<string_body> 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<SimpleWriter>(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 <std::string, std::string> 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<Session> 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 = "<!DOCTYPE html><html><head><title>" + systemName() +
|
||||
" Test page for rippled</title></head><body><h1>" +
|
||||
systemName() + " Test</h1><p>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 = "<HTML><BODY>Server cannot accept clients: " +
|
||||
reason + "</BODY></HTML>";
|
||||
}
|
||||
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<SimpleWriter>(msg);
|
||||
return handoff;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define RIPPLE_RPC_JSON_BODY_H
|
||||
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <beast/core/streambuf.hpp>
|
||||
#include <beast/core/multi_buffer.hpp>
|
||||
#include <beast/http/message.hpp>
|
||||
|
||||
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<bool isRequest, class Fields>
|
||||
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<std::pair<const_buffers_type, bool>>
|
||||
get(beast::error_code& ec)
|
||||
{
|
||||
return sb_.size();
|
||||
return {{buffer_.data(), false}};
|
||||
}
|
||||
|
||||
template<class Writef>
|
||||
bool
|
||||
write(beast::error_code&, Writef&& wf) noexcept
|
||||
void
|
||||
finish(beast::error_code&)
|
||||
{
|
||||
wf(sb_.data());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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