mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-28 15:05:53 +00:00
Use cluster state in Slot instead of PeerImp
This commit is contained in:
committed by
Nik Bougalis
parent
cd8ec89cbb
commit
fb0d44d403
@@ -72,6 +72,11 @@ public:
|
|||||||
id_t
|
id_t
|
||||||
id() const = 0;
|
id() const = 0;
|
||||||
|
|
||||||
|
/** Returns `true` if this connection is a member of the cluster. */
|
||||||
|
virtual
|
||||||
|
bool
|
||||||
|
cluster() const = 0;
|
||||||
|
|
||||||
virtual
|
virtual
|
||||||
RippleAddress const&
|
RippleAddress const&
|
||||||
getNodePublic() const = 0;
|
getNodePublic() const = 0;
|
||||||
@@ -79,16 +84,6 @@ public:
|
|||||||
virtual
|
virtual
|
||||||
Json::Value json() = 0;
|
Json::Value json() = 0;
|
||||||
|
|
||||||
// VFALCO TODO Replace both with
|
|
||||||
// boost::optional<std::string> const& cluster_id();
|
|
||||||
virtual
|
|
||||||
bool
|
|
||||||
isInCluster() const = 0;
|
|
||||||
|
|
||||||
virtual
|
|
||||||
std::string const&
|
|
||||||
getClusterNodeName() const = 0;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Ledger
|
// Ledger
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -241,15 +241,18 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
|
|||||||
|
|
||||||
handoff.moved = true;
|
handoff.moved = true;
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
protocol::TMHello hello;
|
protocol::TMHello hello;
|
||||||
std::tie(hello, success) = parseHello (request, journal_);
|
std::tie(hello, success) = parseHello (request, journal_);
|
||||||
if(! success)
|
if(! success)
|
||||||
return handoff;
|
return handoff;
|
||||||
|
|
||||||
uint256 sharedValue;
|
uint256 sharedValue;
|
||||||
std::tie(sharedValue, success) = makeSharedValue(
|
std::tie(sharedValue, success) = makeSharedValue(
|
||||||
ssl_bundle->stream.native_handle(), journal_);
|
ssl_bundle->stream.native_handle(), journal_);
|
||||||
if(! success)
|
if(! success)
|
||||||
return handoff;
|
return handoff;
|
||||||
|
|
||||||
RippleAddress publicKey;
|
RippleAddress publicKey;
|
||||||
std::tie(publicKey, success) = verifyHello (hello,
|
std::tie(publicKey, success) = verifyHello (hello,
|
||||||
sharedValue, journal_, getApp());
|
sharedValue, journal_, getApp());
|
||||||
@@ -257,11 +260,11 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
|
|||||||
return handoff;
|
return handoff;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
bool clusterNode = getApp().getUNL().nodeInCluster(
|
bool const cluster = getApp().getUNL().nodeInCluster(
|
||||||
publicKey, name);
|
publicKey, name);
|
||||||
auto const result = m_peerFinder->activate (slot,
|
|
||||||
RipplePublicKey(publicKey), clusterNode);
|
|
||||||
|
|
||||||
|
auto const result = m_peerFinder->activate (slot,
|
||||||
|
RipplePublicKey(publicKey), cluster);
|
||||||
if (result != PeerFinder::Result::success)
|
if (result != PeerFinder::Result::success)
|
||||||
{
|
{
|
||||||
if (journal_.trace) journal_.trace <<
|
if (journal_.trace) journal_.trace <<
|
||||||
@@ -352,7 +355,7 @@ OverlayImpl::connect (beast::IP::Endpoint const& remote_endpoint)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
OverlayImpl::remove (PeerFinder::Slot::ptr const& slot)
|
OverlayImpl::remove (PeerFinder::Slot::ptr const& slot)
|
||||||
@@ -363,11 +366,11 @@ OverlayImpl::remove (PeerFinder::Slot::ptr const& slot)
|
|||||||
m_peers.erase (iter);
|
m_peers.erase (iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Stoppable
|
// Stoppable
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Caller must hold the mutex
|
// Caller must hold the mutex
|
||||||
void
|
void
|
||||||
@@ -464,18 +467,18 @@ OverlayImpl::onChildrenStopped ()
|
|||||||
checkStopped ();
|
checkStopped ();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// PropertyStream
|
// PropertyStream
|
||||||
//
|
//
|
||||||
//--------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
void
|
void
|
||||||
OverlayImpl::onWrite (beast::PropertyStream::Map& stream)
|
OverlayImpl::onWrite (beast::PropertyStream::Map& stream)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/** A peer has connected successfully
|
/** A peer has connected successfully
|
||||||
This is called after the peer handshake has been completed and during
|
This is called after the peer handshake has been completed and during
|
||||||
peer activation. At this point, the peer address and the public key
|
peer activation. At this point, the peer address and the public key
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ PeerImp::PeerImp (id_t id, beast::IP::Endpoint remoteAddress,
|
|||||||
|
|
||||||
PeerImp::~PeerImp ()
|
PeerImp::~PeerImp ()
|
||||||
{
|
{
|
||||||
if (clusterNode_)
|
if (cluster())
|
||||||
if (journal_.warning) journal_.warning <<
|
if (journal_.warning) journal_.warning <<
|
||||||
name_ << " left cluster";
|
name_ << " left cluster";
|
||||||
if (state_ == State::active)
|
if (state_ == State::active)
|
||||||
@@ -192,7 +192,7 @@ PeerImp::json()
|
|||||||
if (m_inbound)
|
if (m_inbound)
|
||||||
ret["inbound"] = true;
|
ret["inbound"] = true;
|
||||||
|
|
||||||
if (clusterNode_)
|
if (cluster())
|
||||||
{
|
{
|
||||||
ret["cluster"] = true;
|
ret["cluster"] = true;
|
||||||
|
|
||||||
@@ -708,13 +708,13 @@ PeerImp::processResponse (beast::http::message const& m,
|
|||||||
"Protocol: " << to_string(protocol);
|
"Protocol: " << to_string(protocol);
|
||||||
if(journal_.info) journal_.info <<
|
if(journal_.info) journal_.info <<
|
||||||
"Public Key: " << publicKey_.humanNodePublic();
|
"Public Key: " << publicKey_.humanNodePublic();
|
||||||
clusterNode_ = getApp().getUNL().nodeInCluster(publicKey_, name_);
|
bool const cluster = getApp().getUNL().nodeInCluster(publicKey_, name_);
|
||||||
if (clusterNode_)
|
if (cluster)
|
||||||
if (journal_.info) journal_.info <<
|
if (journal_.info) journal_.info <<
|
||||||
"Cluster name: " << name_;
|
"Cluster name: " << name_;
|
||||||
|
|
||||||
auto const result = overlay_.peerFinder().activate (slot_,
|
auto const result = overlay_.peerFinder().activate (
|
||||||
RipplePublicKey(publicKey_), clusterNode_);
|
slot_, RipplePublicKey(publicKey_), cluster);
|
||||||
if (result != PeerFinder::Result::success)
|
if (result != PeerFinder::Result::success)
|
||||||
return fail("Outbound slots full");
|
return fail("Outbound slots full");
|
||||||
|
|
||||||
@@ -787,8 +787,8 @@ void PeerImp::doAccept()
|
|||||||
"Protocol: " << to_string(protocol);
|
"Protocol: " << to_string(protocol);
|
||||||
if(journal_.info) journal_.info <<
|
if(journal_.info) journal_.info <<
|
||||||
"Public Key: " << publicKey_.humanNodePublic();
|
"Public Key: " << publicKey_.humanNodePublic();
|
||||||
clusterNode_ = getApp().getUNL().nodeInCluster(publicKey_, name_);
|
bool const cluster = getApp().getUNL().nodeInCluster(publicKey_, name_);
|
||||||
if (clusterNode_)
|
if (cluster)
|
||||||
if (journal_.info) journal_.info <<
|
if (journal_.info) journal_.info <<
|
||||||
"Cluster name: " << name_;
|
"Cluster name: " << name_;
|
||||||
|
|
||||||
@@ -1075,8 +1075,8 @@ PeerImp::on_message (std::shared_ptr <protocol::TMHello> const& m)
|
|||||||
"Protocol: " << to_string(protocol);
|
"Protocol: " << to_string(protocol);
|
||||||
if(journal_.info) journal_.info <<
|
if(journal_.info) journal_.info <<
|
||||||
"Public Key: " << publicKey_.humanNodePublic();
|
"Public Key: " << publicKey_.humanNodePublic();
|
||||||
clusterNode_ = getApp().getUNL().nodeInCluster(publicKey_, name_);
|
bool const cluster = getApp().getUNL().nodeInCluster(publicKey_, name_);
|
||||||
if (clusterNode_)
|
if (cluster)
|
||||||
if (journal_.info) journal_.info <<
|
if (journal_.info) journal_.info <<
|
||||||
"Cluster name: " << name_;
|
"Cluster name: " << name_;
|
||||||
|
|
||||||
@@ -1086,7 +1086,7 @@ PeerImp::on_message (std::shared_ptr <protocol::TMHello> const& m)
|
|||||||
hello_ = *m;
|
hello_ = *m;
|
||||||
|
|
||||||
auto const result = overlay_.peerFinder().activate (slot_,
|
auto const result = overlay_.peerFinder().activate (slot_,
|
||||||
RipplePublicKey (publicKey_), clusterNode_);
|
RipplePublicKey (publicKey_), cluster);
|
||||||
|
|
||||||
if (result == PeerFinder::Result::success)
|
if (result == PeerFinder::Result::success)
|
||||||
{
|
{
|
||||||
@@ -1236,7 +1236,8 @@ PeerImp::error_code
|
|||||||
PeerImp::on_message (std::shared_ptr <protocol::TMCluster> const& m)
|
PeerImp::on_message (std::shared_ptr <protocol::TMCluster> const& m)
|
||||||
{
|
{
|
||||||
error_code ec;
|
error_code ec;
|
||||||
if (!clusterNode_)
|
// VFALCO NOTE I think we should drop the peer immediately
|
||||||
|
if (! cluster())
|
||||||
{
|
{
|
||||||
charge (Resource::feeUnwantedData);
|
charge (Resource::feeUnwantedData);
|
||||||
return ec;
|
return ec;
|
||||||
@@ -1387,7 +1388,7 @@ PeerImp::on_message (std::shared_ptr <protocol::TMTransaction> const& m)
|
|||||||
p_journal_.debug <<
|
p_journal_.debug <<
|
||||||
"Got tx " << txID;
|
"Got tx " << txID;
|
||||||
|
|
||||||
if (clusterNode_)
|
if (cluster())
|
||||||
{
|
{
|
||||||
if (! m->has_deferred () || ! m->deferred ())
|
if (! m->has_deferred () || ! m->deferred ())
|
||||||
{
|
{
|
||||||
@@ -2053,7 +2054,7 @@ PeerImp::checkPropose (Job& job,
|
|||||||
"proposal with previous ledger";
|
"proposal with previous ledger";
|
||||||
memcpy (prevLedger.begin (), set.previousledger ().data (), 256 / 8);
|
memcpy (prevLedger.begin (), set.previousledger ().data (), 256 / 8);
|
||||||
|
|
||||||
if (!clusterNode_ && !proposal->checkSign (set.signature ()))
|
if (! cluster() && !proposal->checkSign (set.signature ()))
|
||||||
{
|
{
|
||||||
p_journal_.warning <<
|
p_journal_.warning <<
|
||||||
"Proposal with previous ledger fails sig check";
|
"Proposal with previous ledger fails sig check";
|
||||||
@@ -2114,7 +2115,7 @@ PeerImp::checkValidation (Job&, STValidation::pointer val,
|
|||||||
{
|
{
|
||||||
// VFALCO Which functions throw?
|
// VFALCO Which functions throw?
|
||||||
uint256 signingHash = val->getSigningHash();
|
uint256 signingHash = val->getSigningHash();
|
||||||
if (!clusterNode_ && !val->isValid (signingHash))
|
if (! cluster() && !val->isValid (signingHash))
|
||||||
{
|
{
|
||||||
p_journal_.warning <<
|
p_journal_.warning <<
|
||||||
"Validation is invalid";
|
"Validation is invalid";
|
||||||
@@ -2248,7 +2249,7 @@ PeerImp::getLedger (std::shared_ptr<protocol::TMGetLedger> const& m)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (getApp().getFeeTrack().isLoadedLocal() && !clusterNode_)
|
if (getApp().getFeeTrack().isLoadedLocal() && ! cluster())
|
||||||
{
|
{
|
||||||
p_journal_.debug <<
|
p_journal_.debug <<
|
||||||
"GetLedger: Too busy";
|
"GetLedger: Too busy";
|
||||||
|
|||||||
@@ -123,9 +123,6 @@ private:
|
|||||||
State state_; // Current state
|
State state_; // Current state
|
||||||
bool detaching_ = false;
|
bool detaching_ = false;
|
||||||
|
|
||||||
// True if peer is a node in our cluster
|
|
||||||
bool clusterNode_ = false;
|
|
||||||
|
|
||||||
// Node public key of peer.
|
// Node public key of peer.
|
||||||
RippleAddress publicKey_;
|
RippleAddress publicKey_;
|
||||||
|
|
||||||
@@ -239,6 +236,12 @@ public:
|
|||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
cluster() const override
|
||||||
|
{
|
||||||
|
return slot_->cluster();
|
||||||
|
}
|
||||||
|
|
||||||
RippleAddress const&
|
RippleAddress const&
|
||||||
getNodePublic () const override
|
getNodePublic () const override
|
||||||
{
|
{
|
||||||
@@ -248,18 +251,6 @@ public:
|
|||||||
Json::Value
|
Json::Value
|
||||||
json() override;
|
json() override;
|
||||||
|
|
||||||
bool
|
|
||||||
isInCluster () const override
|
|
||||||
{
|
|
||||||
return clusterNode_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string const&
|
|
||||||
getClusterNodeName() const override
|
|
||||||
{
|
|
||||||
return name_;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Ledger
|
// Ledger
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ struct peer_in_cluster
|
|||||||
if (skipPeer (peer))
|
if (skipPeer (peer))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!peer->isInCluster ())
|
if (! peer->cluster())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user