mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 02:25:53 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -21,21 +21,21 @@
|
||||
#define RIPPLE_OVERLAY_OVERLAYIMPL_H_INCLUDED
|
||||
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/basics/Resolver.h>
|
||||
#include <ripple/basics/UnorderedContainers.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/core/Job.h>
|
||||
#include <ripple/overlay/Overlay.h>
|
||||
#include <ripple/overlay/impl/TrafficCount.h>
|
||||
#include <ripple/server/Handoff.h>
|
||||
#include <ripple/rpc/ServerHandler.h>
|
||||
#include <ripple/basics/Resolver.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/basics/UnorderedContainers.h>
|
||||
#include <ripple/overlay/impl/Handshake.h>
|
||||
#include <ripple/overlay/impl/TrafficCount.h>
|
||||
#include <ripple/peerfinder/PeerfinderManager.h>
|
||||
#include <ripple/resource/ResourceManager.h>
|
||||
#include <ripple/rpc/ServerHandler.h>
|
||||
#include <ripple/server/Handoff.h>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl/context.hpp>
|
||||
#include <boost/asio/strand.hpp>
|
||||
#include <boost/asio/basic_waitable_timer.hpp>
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <atomic>
|
||||
@@ -62,13 +62,13 @@ public:
|
||||
protected:
|
||||
OverlayImpl& overlay_;
|
||||
|
||||
explicit
|
||||
Child (OverlayImpl& overlay);
|
||||
explicit Child(OverlayImpl& overlay);
|
||||
|
||||
virtual ~Child();
|
||||
|
||||
public:
|
||||
virtual void stop() = 0;
|
||||
virtual void
|
||||
stop() = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -78,14 +78,11 @@ private:
|
||||
using endpoint_type = boost::asio::ip::tcp::endpoint;
|
||||
using error_code = boost::system::error_code;
|
||||
|
||||
struct Timer
|
||||
: Child
|
||||
, std::enable_shared_from_this<Timer>
|
||||
struct Timer : Child, std::enable_shared_from_this<Timer>
|
||||
{
|
||||
boost::asio::basic_waitable_timer <clock_type> timer_;
|
||||
boost::asio::basic_waitable_timer<clock_type> timer_;
|
||||
|
||||
explicit
|
||||
Timer (OverlayImpl& overlay);
|
||||
explicit Timer(OverlayImpl& overlay);
|
||||
|
||||
void
|
||||
stop() override;
|
||||
@@ -94,33 +91,31 @@ private:
|
||||
run();
|
||||
|
||||
void
|
||||
on_timer (error_code ec);
|
||||
on_timer(error_code ec);
|
||||
};
|
||||
|
||||
Application& app_;
|
||||
boost::asio::io_service& io_service_;
|
||||
boost::optional<boost::asio::io_service::work> work_;
|
||||
boost::asio::io_service::strand strand_;
|
||||
std::recursive_mutex mutex_; // VFALCO use std::mutex
|
||||
std::recursive_mutex mutex_; // VFALCO use std::mutex
|
||||
std::condition_variable_any cond_;
|
||||
std::weak_ptr<Timer> timer_;
|
||||
boost::container::flat_map<
|
||||
Child*, std::weak_ptr<Child>> list_;
|
||||
boost::container::flat_map<Child*, std::weak_ptr<Child>> list_;
|
||||
Setup setup_;
|
||||
beast::Journal const journal_;
|
||||
ServerHandler& serverHandler_;
|
||||
Resource::Manager& m_resourceManager;
|
||||
std::unique_ptr <PeerFinder::Manager> m_peerFinder;
|
||||
std::unique_ptr<PeerFinder::Manager> m_peerFinder;
|
||||
TrafficCount m_traffic;
|
||||
hash_map <std::shared_ptr<PeerFinder::Slot>,
|
||||
std::weak_ptr <PeerImp>> m_peers;
|
||||
hash_map<std::shared_ptr<PeerFinder::Slot>, std::weak_ptr<PeerImp>> m_peers;
|
||||
hash_map<Peer::id_t, std::weak_ptr<PeerImp>> ids_;
|
||||
Resolver& m_resolver;
|
||||
std::atomic <Peer::id_t> next_id_;
|
||||
std::atomic<Peer::id_t> next_id_;
|
||||
int timer_count_;
|
||||
std::atomic <uint64_t> jqTransOverflow_ {0};
|
||||
std::atomic <uint64_t> peerDisconnects_ {0};
|
||||
std::atomic <uint64_t> peerDisconnectsCharges_ {0};
|
||||
std::atomic<uint64_t> jqTransOverflow_{0};
|
||||
std::atomic<uint64_t> peerDisconnects_{0};
|
||||
std::atomic<uint64_t> peerDisconnectsCharges_{0};
|
||||
|
||||
// Last time we crawled peers for shard info. 'cs' = crawl shards
|
||||
std::atomic<std::chrono::seconds> csLast_{std::chrono::seconds{0}};
|
||||
@@ -134,15 +129,22 @@ private:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
public:
|
||||
OverlayImpl (Application& app, Setup const& setup, Stoppable& parent,
|
||||
ServerHandler& serverHandler, Resource::Manager& resourceManager,
|
||||
Resolver& resolver, boost::asio::io_service& io_service,
|
||||
BasicConfig const& config, beast::insight::Collector::ptr const& collector);
|
||||
OverlayImpl(
|
||||
Application& app,
|
||||
Setup const& setup,
|
||||
Stoppable& parent,
|
||||
ServerHandler& serverHandler,
|
||||
Resource::Manager& resourceManager,
|
||||
Resolver& resolver,
|
||||
boost::asio::io_service& io_service,
|
||||
BasicConfig const& config,
|
||||
beast::insight::Collector::ptr const& collector);
|
||||
|
||||
~OverlayImpl();
|
||||
|
||||
OverlayImpl (OverlayImpl const&) = delete;
|
||||
OverlayImpl& operator= (OverlayImpl const&) = delete;
|
||||
OverlayImpl(OverlayImpl const&) = delete;
|
||||
OverlayImpl&
|
||||
operator=(OverlayImpl const&) = delete;
|
||||
|
||||
PeerFinder::Manager&
|
||||
peerFinder()
|
||||
@@ -169,9 +171,10 @@ public:
|
||||
}
|
||||
|
||||
Handoff
|
||||
onHandoff (std::unique_ptr <stream_type>&& bundle,
|
||||
onHandoff(
|
||||
std::unique_ptr<stream_type>&& bundle,
|
||||
http_request_type&& request,
|
||||
endpoint_type remote_endpoint) override;
|
||||
endpoint_type remote_endpoint) override;
|
||||
|
||||
void
|
||||
connect(beast::IP::Endpoint const& remote_endpoint) override;
|
||||
@@ -189,30 +192,27 @@ public:
|
||||
getActivePeers() override;
|
||||
|
||||
void
|
||||
check () override;
|
||||
check() override;
|
||||
|
||||
void
|
||||
checkSanity (std::uint32_t) override;
|
||||
void checkSanity(std::uint32_t) override;
|
||||
|
||||
std::shared_ptr<Peer>
|
||||
findPeerByShortID (Peer::id_t const& id) override;
|
||||
findPeerByShortID(Peer::id_t const& id) override;
|
||||
|
||||
std::shared_ptr<Peer>
|
||||
findPeerByPublicKey (PublicKey const& pubKey) override;
|
||||
findPeerByPublicKey(PublicKey const& pubKey) override;
|
||||
|
||||
void
|
||||
send (protocol::TMProposeSet& m) override;
|
||||
send(protocol::TMProposeSet& m) override;
|
||||
|
||||
void
|
||||
send (protocol::TMValidation& m) override;
|
||||
send(protocol::TMValidation& m) override;
|
||||
|
||||
void
|
||||
relay (protocol::TMProposeSet& m,
|
||||
uint256 const& uid) override;
|
||||
relay(protocol::TMProposeSet& m, uint256 const& uid) override;
|
||||
|
||||
void
|
||||
relay (protocol::TMValidation& m,
|
||||
uint256 const& uid) override;
|
||||
relay(protocol::TMValidation& m, uint256 const& uid) override;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
@@ -220,10 +220,10 @@ public:
|
||||
//
|
||||
|
||||
void
|
||||
add_active (std::shared_ptr<PeerImp> const& peer);
|
||||
add_active(std::shared_ptr<PeerImp> const& peer);
|
||||
|
||||
void
|
||||
remove (std::shared_ptr<PeerFinder::Slot> const& slot);
|
||||
remove(std::shared_ptr<PeerFinder::Slot> const& slot);
|
||||
|
||||
/** Called when a peer has connected successfully
|
||||
This is called after the peer handshake has been completed and during
|
||||
@@ -231,18 +231,18 @@ public:
|
||||
are known.
|
||||
*/
|
||||
void
|
||||
activate (std::shared_ptr<PeerImp> const& peer);
|
||||
activate(std::shared_ptr<PeerImp> const& peer);
|
||||
|
||||
// Called when an active peer is destroyed.
|
||||
void
|
||||
onPeerDeactivate (Peer::id_t id);
|
||||
onPeerDeactivate(Peer::id_t id);
|
||||
|
||||
// UnaryFunc will be called as
|
||||
// void(std::shared_ptr<PeerImp>&&)
|
||||
//
|
||||
template <class UnaryFunc>
|
||||
void
|
||||
for_each (UnaryFunc&& f)
|
||||
for_each(UnaryFunc&& f)
|
||||
{
|
||||
std::vector<std::weak_ptr<PeerImp>> wp;
|
||||
{
|
||||
@@ -264,64 +264,61 @@ public:
|
||||
}
|
||||
|
||||
std::size_t
|
||||
selectPeers (PeerSet& set, std::size_t limit, std::function<
|
||||
bool(std::shared_ptr<Peer> const&)> score) override;
|
||||
selectPeers(
|
||||
PeerSet& set,
|
||||
std::size_t limit,
|
||||
std::function<bool(std::shared_ptr<Peer> const&)> score) override;
|
||||
|
||||
// Called when TMManifests is received from a peer
|
||||
void
|
||||
onManifests (
|
||||
onManifests(
|
||||
std::shared_ptr<protocol::TMManifests> const& m,
|
||||
std::shared_ptr<PeerImp> const& from);
|
||||
std::shared_ptr<PeerImp> const& from);
|
||||
|
||||
static
|
||||
bool
|
||||
isPeerUpgrade (http_request_type const& request);
|
||||
static bool
|
||||
isPeerUpgrade(http_request_type const& request);
|
||||
|
||||
template<class Body>
|
||||
static
|
||||
bool
|
||||
isPeerUpgrade (boost::beast::http::response<Body> const& response)
|
||||
template <class Body>
|
||||
static bool
|
||||
isPeerUpgrade(boost::beast::http::response<Body> const& response)
|
||||
{
|
||||
if (! is_upgrade(response))
|
||||
if (!is_upgrade(response))
|
||||
return false;
|
||||
return response.result() == boost::beast::http::status::switching_protocols;
|
||||
return response.result() ==
|
||||
boost::beast::http::status::switching_protocols;
|
||||
}
|
||||
|
||||
template<class Fields>
|
||||
static
|
||||
bool
|
||||
template <class Fields>
|
||||
static bool
|
||||
is_upgrade(boost::beast::http::header<true, Fields> const& req)
|
||||
{
|
||||
if(req.version() < 11)
|
||||
if (req.version() < 11)
|
||||
return false;
|
||||
if(req.method() != boost::beast::http::verb::get)
|
||||
if (req.method() != boost::beast::http::verb::get)
|
||||
return false;
|
||||
if(! boost::beast::http::token_list{req["Connection"]}.exists("upgrade"))
|
||||
if (!boost::beast::http::token_list{req["Connection"]}.exists(
|
||||
"upgrade"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class Fields>
|
||||
static
|
||||
bool
|
||||
template <class Fields>
|
||||
static bool
|
||||
is_upgrade(boost::beast::http::header<false, Fields> const& req)
|
||||
{
|
||||
if(req.version() < 11)
|
||||
if (req.version() < 11)
|
||||
return false;
|
||||
if(! boost::beast::http::token_list{req["Connection"]}.exists("upgrade"))
|
||||
if (!boost::beast::http::token_list{req["Connection"]}.exists(
|
||||
"upgrade"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
std::string
|
||||
makePrefix (std::uint32_t id);
|
||||
static std::string
|
||||
makePrefix(std::uint32_t id);
|
||||
|
||||
void
|
||||
reportTraffic (
|
||||
TrafficCount::category cat,
|
||||
bool isInbound,
|
||||
int bytes);
|
||||
reportTraffic(TrafficCount::category cat, bool isInbound, int bytes);
|
||||
|
||||
void
|
||||
incJqTransOverflow() override
|
||||
@@ -377,12 +374,16 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Writer>
|
||||
makeRedirectResponse (std::shared_ptr<PeerFinder::Slot> const& slot,
|
||||
http_request_type const& request, address_type remote_address);
|
||||
makeRedirectResponse(
|
||||
std::shared_ptr<PeerFinder::Slot> const& slot,
|
||||
http_request_type const& request,
|
||||
address_type remote_address);
|
||||
|
||||
std::shared_ptr<Writer>
|
||||
makeErrorResponse (std::shared_ptr<PeerFinder::Slot> const& slot,
|
||||
http_request_type const& request, address_type remote_address,
|
||||
makeErrorResponse(
|
||||
std::shared_ptr<PeerFinder::Slot> const& slot,
|
||||
http_request_type const& request,
|
||||
address_type remote_address,
|
||||
std::string msg);
|
||||
|
||||
/** Handles crawl requests. Crawl returns information about the
|
||||
@@ -391,8 +392,7 @@ private:
|
||||
@return true if the request was handled.
|
||||
*/
|
||||
bool
|
||||
processCrawl (http_request_type const& req,
|
||||
Handoff& handoff);
|
||||
processCrawl(http_request_type const& req, Handoff& handoff);
|
||||
|
||||
/** Handles validator list requests.
|
||||
Using a /vl/<hex-encoded public key> URL, will retrieve the
|
||||
@@ -402,16 +402,14 @@ private:
|
||||
@return true if the request was handled.
|
||||
*/
|
||||
bool
|
||||
processValidatorList (http_request_type const& req,
|
||||
Handoff& handoff);
|
||||
processValidatorList(http_request_type const& req, Handoff& handoff);
|
||||
|
||||
/** Handles non-peer protocol requests.
|
||||
|
||||
@return true if the request was handled.
|
||||
*/
|
||||
bool
|
||||
processRequest (http_request_type const& req,
|
||||
Handoff& handoff);
|
||||
processRequest(http_request_type const& req, Handoff& handoff);
|
||||
|
||||
/** Returns information about peers on the overlay network.
|
||||
Reported through the /crawl API
|
||||
@@ -467,12 +465,12 @@ private:
|
||||
//
|
||||
|
||||
void
|
||||
onWrite (beast::PropertyStream::Map& stream) override;
|
||||
onWrite(beast::PropertyStream::Map& stream) override;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
remove (Child& child);
|
||||
remove(Child& child);
|
||||
|
||||
void
|
||||
stop();
|
||||
@@ -484,14 +482,16 @@ private:
|
||||
sendEndpoints();
|
||||
|
||||
private:
|
||||
|
||||
struct TrafficGauges{
|
||||
TrafficGauges (char const* name, beast::insight::Collector::ptr const& collector)
|
||||
: bytesIn(collector->make_gauge(name,"Bytes_In"))
|
||||
, bytesOut(collector->make_gauge(name,"Bytes_Out"))
|
||||
, messagesIn(collector->make_gauge(name,"Messages_In"))
|
||||
, messagesOut(collector->make_gauge(name,"Messages_Out"))
|
||||
{
|
||||
struct TrafficGauges
|
||||
{
|
||||
TrafficGauges(
|
||||
char const* name,
|
||||
beast::insight::Collector::ptr const& collector)
|
||||
: bytesIn(collector->make_gauge(name, "Bytes_In"))
|
||||
, bytesOut(collector->make_gauge(name, "Bytes_Out"))
|
||||
, messagesIn(collector->make_gauge(name, "Messages_In"))
|
||||
, messagesOut(collector->make_gauge(name, "Messages_Out"))
|
||||
{
|
||||
}
|
||||
beast::insight::Gauge bytesIn;
|
||||
beast::insight::Gauge bytesOut;
|
||||
@@ -499,36 +499,36 @@ private:
|
||||
beast::insight::Gauge messagesOut;
|
||||
};
|
||||
|
||||
|
||||
struct Stats
|
||||
{
|
||||
|
||||
template <class Handler>
|
||||
Stats (
|
||||
Handler const& handler,
|
||||
beast::insight::Collector::ptr const& collector,
|
||||
std::vector<TrafficGauges>&& trafficGauges_)
|
||||
: peerDisconnects (collector->make_gauge("Overlay","Peer_Disconnects"))
|
||||
, trafficGauges (std::move(trafficGauges_))
|
||||
, hook (collector->make_hook (handler))
|
||||
{
|
||||
}
|
||||
|
||||
Stats(
|
||||
Handler const& handler,
|
||||
beast::insight::Collector::ptr const& collector,
|
||||
std::vector<TrafficGauges>&& trafficGauges_)
|
||||
: peerDisconnects(
|
||||
collector->make_gauge("Overlay", "Peer_Disconnects"))
|
||||
, trafficGauges(std::move(trafficGauges_))
|
||||
, hook(collector->make_hook(handler))
|
||||
{
|
||||
}
|
||||
|
||||
beast::insight::Gauge peerDisconnects;
|
||||
std::vector<TrafficGauges> trafficGauges;
|
||||
beast::insight::Hook hook;
|
||||
};
|
||||
|
||||
|
||||
Stats m_stats;
|
||||
std::mutex m_statsMutex;
|
||||
|
||||
private:
|
||||
void collect_metrics()
|
||||
{
|
||||
void
|
||||
collect_metrics()
|
||||
{
|
||||
auto counts = m_traffic.getCounts();
|
||||
std::lock_guard lock (m_statsMutex);
|
||||
std::lock_guard lock(m_statsMutex);
|
||||
assert(counts.size() == m_stats.trafficGauges.size());
|
||||
|
||||
|
||||
for (std::size_t i = 0; i < counts.size(); ++i)
|
||||
{
|
||||
m_stats.trafficGauges[i].bytesIn = counts[i].bytesIn;
|
||||
@@ -540,6 +540,6 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user