mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge master (0.70.2) into develop (0.80.0-rc2)
This commit is contained in:
@@ -18,14 +18,10 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/overlay/Cluster.h>
|
||||
#include <ripple/overlay/impl/ConnectAttempt.h>
|
||||
#include <ripple/overlay/impl/PeerImp.h>
|
||||
#include <ripple/overlay/impl/Tuning.h>
|
||||
#include <ripple/overlay/Cluster.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <beast/core/to_string.hpp>
|
||||
#include <beast/http/read.hpp>
|
||||
#include <beast/http/write.hpp>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -81,7 +77,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 +134,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 +182,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 +217,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 +237,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 +256,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 +286,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 +341,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");
|
||||
|
||||
|
||||
@@ -22,26 +22,7 @@
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/overlay/impl/OverlayImpl.h>
|
||||
#include <ripple/overlay/impl/ProtocolMessage.h>
|
||||
#include <ripple/overlay/impl/TMHello.h>
|
||||
#include <ripple/overlay/impl/Tuning.h>
|
||||
#include <ripple/overlay/Message.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#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/http/empty_body.hpp>
|
||||
#include <beast/http/parser_v1.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/buffers_iterator.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -59,7 +40,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 +53,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_;
|
||||
|
||||
@@ -21,27 +21,16 @@
|
||||
#include <ripple/app/misc/HashRouter.h>
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/app/misc/ValidatorList.h>
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/basics/make_SSLContext.h>
|
||||
#include <ripple/beast/rfc2616.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/beast/core/LexicalCast.h>
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/overlay/Cluster.h>
|
||||
#include <ripple/overlay/predicates.h>
|
||||
#include <ripple/overlay/impl/ConnectAttempt.h>
|
||||
#include <ripple/overlay/impl/PeerImp.h>
|
||||
#include <ripple/peerfinder/make_Manager.h>
|
||||
#include <ripple/rpc/json_body.h>
|
||||
#include <ripple/server/SimpleWriter.h>
|
||||
#include <ripple/overlay/Cluster.h>
|
||||
#include <ripple/overlay/impl/ConnectAttempt.h>
|
||||
#include <ripple/overlay/impl/OverlayImpl.h>
|
||||
#include <ripple/overlay/impl/PeerImp.h>
|
||||
#include <ripple/overlay/impl/TMHello.h>
|
||||
#include <ripple/peerfinder/make_Manager.h>
|
||||
#include <ripple/protocol/STExchange.h>
|
||||
#include <ripple/beast/core/ByteOrder.h>
|
||||
#include <beast/core/detail/base64.hpp>
|
||||
#include <ripple/beast/core/LexicalCast.h>
|
||||
#include <beast/http.hpp>
|
||||
#include <beast/core/detail/ci_char_traits.hpp>
|
||||
#include <ripple/beast/utility/WrappedSink.h>
|
||||
|
||||
#include <boost/utility/in_place_factory.hpp>
|
||||
|
||||
@@ -102,7 +91,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 +116,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,22 +208,22 @@ 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)
|
||||
{
|
||||
return beast::detail::ci_equal(s, "peer");
|
||||
return beast::detail::iequals(s, "peer");
|
||||
}) == types.end())
|
||||
{
|
||||
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 +274,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;
|
||||
}
|
||||
|
||||
@@ -319,21 +308,7 @@ 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 +328,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 +340,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_payload();
|
||||
return std::make_shared<SimpleWriter>(msg);
|
||||
}
|
||||
|
||||
@@ -377,12 +352,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_payload();
|
||||
return std::make_shared<SimpleWriter>(msg);
|
||||
}
|
||||
|
||||
@@ -827,17 +802,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_payload();
|
||||
handoff.response = std::make_shared<SimpleWriter>(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <ripple/basics/Resolver.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/basics/UnorderedContainers.h>
|
||||
#include <ripple/overlay/impl/TMHello.h>
|
||||
#include <ripple/peerfinder/PeerfinderManager.h>
|
||||
#include <ripple/resource/ResourceManager.h>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
@@ -248,9 +249,47 @@ 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static
|
||||
std::string
|
||||
|
||||
@@ -18,40 +18,26 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/overlay/impl/TMHello.h>
|
||||
#include <ripple/overlay/impl/PeerImp.h>
|
||||
#include <ripple/overlay/impl/Tuning.h>
|
||||
#include <ripple/app/consensus/RCLValidations.h>
|
||||
#include <ripple/app/ledger/InboundLedgers.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/consensus/LedgerTiming.h>
|
||||
#include <ripple/app/ledger/InboundTransactions.h>
|
||||
#include <ripple/app/misc/HashRouter.h>
|
||||
#include <ripple/app/misc/LoadFeeTrack.h>
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/app/misc/Transaction.h>
|
||||
#include <ripple/app/misc/Validations.h>
|
||||
#include <ripple/app/misc/ValidatorList.h>
|
||||
#include <ripple/app/tx/apply.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
#include <ripple/basics/random.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/UptimeTimer.h>
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/core/TimeKeeper.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/resource/Fees.h>
|
||||
#include <ripple/rpc/ServerHandler.h>
|
||||
#include <ripple/overlay/Cluster.h>
|
||||
#include <ripple/overlay/ClusterNode.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
#include <ripple/protocol/JsonFields.h>
|
||||
#include <ripple/beast/core/SemanticVersion.h>
|
||||
#include <ripple/beast/utility/weak_fn.h>
|
||||
#include <beast/http/write.hpp>
|
||||
#include <ripple/overlay/Cluster.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
@@ -91,7 +77,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 +211,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 +234,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::iequals(iter->value(), "public");
|
||||
}
|
||||
|
||||
std::string
|
||||
@@ -482,7 +468,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 +484,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 +595,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 +643,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 +681,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 +756,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 +786,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)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1095,7 +1080,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMTransaction> const& m)
|
||||
flags |= SF_TRUSTED;
|
||||
}
|
||||
|
||||
if (! app_.getOPs().getValidationPublicKey().size())
|
||||
if (app_.getValidationPublicKey().empty())
|
||||
{
|
||||
// For now, be paranoid and have each validator
|
||||
// check each transaction, regardless of source
|
||||
@@ -1257,8 +1242,8 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
|
||||
return;
|
||||
}
|
||||
|
||||
if (app_.getOPs().getValidationPublicKey().size() &&
|
||||
publicKey == app_.getOPs().getValidationPublicKey())
|
||||
if (!app_.getValidationPublicKey().empty() &&
|
||||
publicKey == app_.getValidationPublicKey())
|
||||
{
|
||||
JLOG(p_journal_.trace()) << "Proposal: self";
|
||||
return;
|
||||
@@ -1284,7 +1269,7 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMProposeSet> const& m)
|
||||
JLOG(p_journal_.trace()) <<
|
||||
"Proposal: " << (isTrusted ? "trusted" : "UNTRUSTED");
|
||||
|
||||
auto proposal = std::make_shared<RCLCxPeerPos> (
|
||||
auto proposal = RCLCxPeerPos(
|
||||
publicKey, signature, suppression,
|
||||
RCLCxPeerPos::Proposal{prevLedger, set.proposeseq (), proposeHash, closeTime,
|
||||
app_.timeKeeper().closeTime(),calcNodeID(publicKey)});
|
||||
@@ -1577,7 +1562,10 @@ PeerImp::onMessage (std::shared_ptr <protocol::TMValidation> const& m)
|
||||
val->setSeen (closeTime);
|
||||
}
|
||||
|
||||
if (! app_.getValidations().current (val))
|
||||
if (! isCurrent(app_.getValidations().parms(),
|
||||
app_.timeKeeper().closeTime(),
|
||||
val->getSignTime(),
|
||||
val->getSeenTime()))
|
||||
{
|
||||
JLOG(p_journal_.trace()) << "Validation: Not current";
|
||||
fee_ = Resource::feeUnwantedData;
|
||||
@@ -1887,7 +1875,7 @@ PeerImp::checkTransaction (int flags,
|
||||
void
|
||||
PeerImp::checkPropose (Job& job,
|
||||
std::shared_ptr <protocol::TMProposeSet> const& packet,
|
||||
RCLCxPeerPos::pointer peerPos)
|
||||
RCLCxPeerPos peerPos)
|
||||
{
|
||||
bool isTrusted = (job.getType () == jtPROPOSAL_t);
|
||||
|
||||
@@ -1897,7 +1885,7 @@ PeerImp::checkPropose (Job& job,
|
||||
assert (packet);
|
||||
protocol::TMProposeSet& set = *packet;
|
||||
|
||||
if (! cluster() && !peerPos->checkSign ())
|
||||
if (! cluster() && !peerPos.checkSign ())
|
||||
{
|
||||
JLOG(p_journal_.warn()) <<
|
||||
"Proposal fails sig check";
|
||||
@@ -1912,12 +1900,12 @@ PeerImp::checkPropose (Job& job,
|
||||
}
|
||||
else
|
||||
{
|
||||
if (app_.getOPs().getConsensusLCL() == peerPos->proposal().prevLedger())
|
||||
if (app_.getOPs().getConsensusLCL() == peerPos.proposal().prevLedger())
|
||||
{
|
||||
// relay untrusted proposal
|
||||
JLOG(p_journal_.trace()) <<
|
||||
"relaying UNTRUSTED proposal";
|
||||
overlay_.relay(set, peerPos->getSuppressionID());
|
||||
overlay_.relay(set, peerPos.suppressionID());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -21,26 +21,16 @@
|
||||
#define RIPPLE_OVERLAY_PEERIMP_H_INCLUDED
|
||||
|
||||
#include <ripple/app/consensus/RCLCxPeerPos.h>
|
||||
#include <ripple/basics/Log.h> // deprecated
|
||||
#include <ripple/nodestore/Database.h>
|
||||
#include <ripple/overlay/predicates.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/beast/core/ByteOrder.h>
|
||||
#include <ripple/beast/utility/WrappedSink.h>
|
||||
#include <ripple/overlay/impl/ProtocolMessage.h>
|
||||
#include <ripple/overlay/impl/OverlayImpl.h>
|
||||
#include <ripple/resource/Fees.h>
|
||||
#include <ripple/core/Config.h>
|
||||
#include <ripple/core/Job.h>
|
||||
#include <ripple/core/LoadEvent.h>
|
||||
#include <ripple/protocol/Protocol.h>
|
||||
#include <ripple/protocol/STTx.h>
|
||||
#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 <ripple/beast/asio/ssl_bundle.h>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <beast/http/parser_v1.hpp>
|
||||
#include <ripple/beast/utility/WrappedSink.h>
|
||||
#include <ripple/resource/Fees.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
@@ -151,11 +141,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;
|
||||
@@ -452,7 +442,7 @@ private:
|
||||
void
|
||||
checkPropose (Job& job,
|
||||
std::shared_ptr<protocol::TMProposeSet> const& packet,
|
||||
RCLCxPeerPos::pointer peerPos);
|
||||
RCLCxPeerPos peerPos);
|
||||
|
||||
void
|
||||
checkValidation (STValidation::pointer val,
|
||||
@@ -502,7 +492,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));
|
||||
|
||||
@@ -18,11 +18,10 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/overlay/Overlay.h>
|
||||
#include <beast/core/placeholders.hpp>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/overlay/impl/TMHello.h>
|
||||
#include <ripple/app/ledger/LedgerMaster.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/beast/rfc2616.h>
|
||||
#include <ripple/beast/core/LexicalCast.h>
|
||||
#include <ripple/core/TimeKeeper.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
#include <ripple/overlay/impl/TMHello.h>
|
||||
#include <beast/core/detail/base64.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <algorithm>
|
||||
@@ -188,7 +185,7 @@ appendHello (beast::http::fields& h,
|
||||
}
|
||||
|
||||
std::vector<ProtocolVersion>
|
||||
parse_ProtocolVersions(boost::string_ref const& value)
|
||||
parse_ProtocolVersions(beast::string_view const& value)
|
||||
{
|
||||
static boost::regex re (
|
||||
"^" // start of line
|
||||
@@ -233,7 +230,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 +247,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 +259,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 +274,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 +285,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 +294,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 +310,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 +325,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())
|
||||
|
||||
@@ -20,17 +20,15 @@
|
||||
#ifndef RIPPLE_OVERLAY_TMHELLO_H_INCLUDED
|
||||
#define RIPPLE_OVERLAY_TMHELLO_H_INCLUDED
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
#include <ripple/protocol/PublicKey.h>
|
||||
#include <ripple/protocol/UintTypes.h>
|
||||
#include <beast/http/message.hpp>
|
||||
#include <ripple/beast/utility/Journal.h>
|
||||
#include <utility>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
|
||||
#include <beast/http/message.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include "ripple.pb.h"
|
||||
#include <utility>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -84,7 +82,7 @@ verifyHello (protocol::TMHello const& h, uint256 const& sharedValue,
|
||||
excluded from the result set.
|
||||
*/
|
||||
std::vector<ProtocolVersion>
|
||||
parse_ProtocolVersions(boost::string_ref const& s);
|
||||
parse_ProtocolVersions(beast::string_view const& s);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user