mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Tidy up PeerSet:
* Move PeerSet to overlay/ * Remove unused functions * Make some public members private * Rename some functions * Add comments
This commit is contained in:
@@ -1934,14 +1934,6 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\app\peers\ClusterNodeStatus.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\app\peers\PeerSet.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='debug.classic|x64'">..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='release.classic|x64'">..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\app\peers\PeerSet.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\app\peers\UniqueNodeList.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
@@ -2700,6 +2692,10 @@
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\overlay\impl\PeerSet.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\impl\ProtocolMessage.h">
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\overlay\impl\TMHello.cpp">
|
||||
@@ -2720,6 +2716,8 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\PeerSet.h">
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
|
||||
</ClInclude>
|
||||
<None Include="..\..\src\ripple\overlay\README.md">
|
||||
|
||||
@@ -2532,12 +2532,6 @@
|
||||
<ClInclude Include="..\..\src\ripple\app\peers\ClusterNodeStatus.h">
|
||||
<Filter>ripple\app\peers</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\app\peers\PeerSet.cpp">
|
||||
<Filter>ripple\app\peers</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\app\peers\PeerSet.h">
|
||||
<Filter>ripple\app\peers</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\app\peers\UniqueNodeList.cpp">
|
||||
<Filter>ripple\app\peers</Filter>
|
||||
</ClCompile>
|
||||
@@ -3228,6 +3222,9 @@
|
||||
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
|
||||
<Filter>ripple\overlay\impl</Filter>
|
||||
</ClInclude>
|
||||
<ClCompile Include="..\..\src\ripple\overlay\impl\PeerSet.cpp">
|
||||
<Filter>ripple\overlay\impl</Filter>
|
||||
</ClCompile>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\impl\ProtocolMessage.h">
|
||||
<Filter>ripple\overlay\impl</Filter>
|
||||
</ClInclude>
|
||||
@@ -3255,6 +3252,9 @@
|
||||
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
|
||||
<Filter>ripple\overlay</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\PeerSet.h">
|
||||
<Filter>ripple\overlay</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
|
||||
<Filter>ripple\overlay</Filter>
|
||||
</ClInclude>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#define RIPPLE_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
|
||||
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/peers/PeerSet.h>
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
#include <ripple/basics/CountedObject.h>
|
||||
#include <set>
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef RIPPLE_APP_TX_TRANSACTIONACQUIRE_H_INCLUDED
|
||||
#define RIPPLE_APP_TX_TRANSACTIONACQUIRE_H_INCLUDED
|
||||
|
||||
#include <ripple/app/peers/PeerSet.h>
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
#include <ripple/shamap/SHAMap.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
#ifndef RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
|
||||
#define RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
|
||||
|
||||
#include <ripple/app/peers/PeerSet.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <ripple/overlay/Peer.h>
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
#include <ripple/server/Handoff.h>
|
||||
#include <beast/asio/ssl_bundle.h>
|
||||
#include <beast/http/message.h>
|
||||
|
||||
@@ -29,30 +29,45 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
/** A set of peers used to acquire data.
|
||||
/** Supports data retrieval by managing a set of peers.
|
||||
|
||||
A peer set is used to acquire a ledger or a transaction set.
|
||||
When desired data (such as a ledger or a transaction set)
|
||||
is missing locally it can be obtained by querying connected
|
||||
peers. This class manages common aspects of the retrieval.
|
||||
Callers maintain the set by adding and removing peers depending
|
||||
on whether the peers have useful information.
|
||||
|
||||
This class is an "active" object. It maintains its own timer
|
||||
and dispatches work to a job queue. Implementations derive
|
||||
from this class and override the abstract hook functions in
|
||||
the base.
|
||||
|
||||
The data is represented by its hash.
|
||||
*/
|
||||
class PeerSet
|
||||
{
|
||||
public:
|
||||
typedef beast::abstract_clock <std::chrono::steady_clock> clock_type;
|
||||
|
||||
/** Returns the hash of the data we want. */
|
||||
uint256 const& getHash () const
|
||||
{
|
||||
return mHash;
|
||||
}
|
||||
|
||||
/** Returns true if we got all the data. */
|
||||
bool isComplete () const
|
||||
{
|
||||
return mComplete;
|
||||
}
|
||||
|
||||
/** Returns false if we failed to get the data. */
|
||||
bool isFailed () const
|
||||
{
|
||||
return mFailed;
|
||||
}
|
||||
|
||||
/** Returns the number of times we timed out. */
|
||||
int getTimeouts () const
|
||||
{
|
||||
return mTimeouts;
|
||||
@@ -60,22 +75,13 @@ public:
|
||||
|
||||
bool isActive ();
|
||||
|
||||
/** Called to indicate that forward progress has been made. */
|
||||
void progress ()
|
||||
{
|
||||
mProgress = true;
|
||||
mAggressive = false;
|
||||
}
|
||||
|
||||
void clearProgress ()
|
||||
{
|
||||
mProgress = false;
|
||||
}
|
||||
|
||||
bool isProgress ()
|
||||
{
|
||||
return mProgress;
|
||||
}
|
||||
|
||||
void touch ()
|
||||
{
|
||||
mLastAction = m_clock.now();
|
||||
@@ -86,22 +92,12 @@ public:
|
||||
return mLastAction;
|
||||
}
|
||||
|
||||
// VFALCO TODO Rename this to addPeerToSet
|
||||
//
|
||||
bool peerHas (Peer::ptr const&);
|
||||
/** Insert a peer to the managed set.
|
||||
This will call the derived class hook function.
|
||||
@return `true` If the peer was added
|
||||
*/
|
||||
bool insert (Peer::ptr const&);
|
||||
|
||||
// VFALCO Workaround for MSVC std::function which doesn't swallow return types.
|
||||
void peerHasVoid (Peer::ptr const& peer)
|
||||
{
|
||||
peerHas (peer);
|
||||
}
|
||||
|
||||
void badPeer (Peer::ptr const&);
|
||||
|
||||
void setTimer ();
|
||||
|
||||
std::size_t takePeerSetFrom (const PeerSet& s);
|
||||
std::size_t getPeerCount () const;
|
||||
virtual bool isDone () const
|
||||
{
|
||||
return mComplete || mFailed;
|
||||
@@ -118,12 +114,20 @@ protected:
|
||||
|
||||
PeerSet (uint256 const& hash, int interval, bool txnData,
|
||||
clock_type& clock, beast::Journal journal);
|
||||
|
||||
virtual ~PeerSet () = 0;
|
||||
|
||||
virtual void newPeer (Peer::ptr const&) = 0;
|
||||
|
||||
virtual void onTimer (bool progress, ScopedLockType&) = 0;
|
||||
|
||||
virtual std::weak_ptr<PeerSet> pmDowncast () = 0;
|
||||
|
||||
bool isProgress ()
|
||||
{
|
||||
return mProgress;
|
||||
}
|
||||
|
||||
void setComplete ()
|
||||
{
|
||||
mComplete = true;
|
||||
@@ -132,11 +136,17 @@ protected:
|
||||
{
|
||||
mFailed = true;
|
||||
}
|
||||
|
||||
void invokeOnTimer ();
|
||||
|
||||
void sendRequest (const protocol::TMGetLedger& message);
|
||||
|
||||
void sendRequest (const protocol::TMGetLedger& message, Peer::ptr const& peer);
|
||||
|
||||
void setTimer ();
|
||||
|
||||
std::size_t getPeerCount () const;
|
||||
|
||||
protected:
|
||||
beast::Journal m_journal;
|
||||
clock_type& m_clock;
|
||||
@@ -153,9 +163,8 @@ protected:
|
||||
clock_type::time_point mLastAction;
|
||||
bool mProgress;
|
||||
|
||||
|
||||
// VFALCO TODO move the responsibility for the timer to a higher level
|
||||
boost::asio::deadline_timer mTimer;
|
||||
boost::asio::deadline_timer mTimer;
|
||||
|
||||
// VFALCO TODO Verify that these are used in the way that the names suggest.
|
||||
typedef Peer::id_t PeerIdentifier;
|
||||
@@ -592,7 +592,7 @@ OverlayImpl::selectPeers (PeerSet& set, std::size_t limit,
|
||||
});
|
||||
std::size_t accepted = 0;
|
||||
for (auto const& e : v)
|
||||
if (set.peerHas(e.second) && ++accepted >= limit)
|
||||
if (set.insert(e.second) && ++accepted >= limit)
|
||||
break;
|
||||
return accepted;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/app/peers/PeerSet.h>
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/overlay/Overlay.h>
|
||||
#include <beast/asio/placeholders.h>
|
||||
@@ -57,7 +57,7 @@ PeerSet::~PeerSet ()
|
||||
{
|
||||
}
|
||||
|
||||
bool PeerSet::peerHas (Peer::ptr const& ptr)
|
||||
bool PeerSet::insert (Peer::ptr const& ptr)
|
||||
{
|
||||
ScopedLockType sl (mLock);
|
||||
|
||||
@@ -68,12 +68,6 @@ bool PeerSet::peerHas (Peer::ptr const& ptr)
|
||||
return true;
|
||||
}
|
||||
|
||||
void PeerSet::badPeer (Peer::ptr const& ptr)
|
||||
{
|
||||
ScopedLockType sl (mLock);
|
||||
mPeers.erase (ptr->id ());
|
||||
}
|
||||
|
||||
void PeerSet::setTimer ()
|
||||
{
|
||||
mTimer.expires_from_now (boost::posix_time::milliseconds (mTimerInterval));
|
||||
@@ -96,7 +90,7 @@ void PeerSet::invokeOnTimer ()
|
||||
}
|
||||
else
|
||||
{
|
||||
clearProgress ();
|
||||
mProgress = false;
|
||||
onTimer (true, sl);
|
||||
}
|
||||
|
||||
@@ -178,20 +172,6 @@ void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL)
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t PeerSet::takePeerSetFrom (const PeerSet& s)
|
||||
{
|
||||
std::size_t ret = 0;
|
||||
mPeers.clear ();
|
||||
|
||||
for (auto const& p : s.mPeers)
|
||||
{
|
||||
mPeers.insert (std::make_pair (p.first, 0));
|
||||
++ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::size_t PeerSet::getPeerCount () const
|
||||
{
|
||||
std::size_t ret (0);
|
||||
@@ -20,6 +20,5 @@
|
||||
#include <BeastConfig.h>
|
||||
|
||||
#include <ripple/app/consensus/LedgerConsensus.cpp>
|
||||
#include <ripple/app/peers/PeerSet.cpp>
|
||||
#include <ripple/app/ledger/LedgerCleaner.cpp>
|
||||
#include <ripple/app/ledger/LedgerMaster.cpp>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <ripple/overlay/impl/Message.cpp>
|
||||
#include <ripple/overlay/impl/OverlayImpl.cpp>
|
||||
#include <ripple/overlay/impl/PeerImp.cpp>
|
||||
#include <ripple/overlay/impl/PeerSet.cpp>
|
||||
#include <ripple/overlay/impl/TMHello.cpp>
|
||||
|
||||
#include <ripple/overlay/tests/short_read.test.cpp>
|
||||
|
||||
Reference in New Issue
Block a user