mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27: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>
|
||||||
<ClInclude Include="..\..\src\ripple\app\peers\ClusterNodeStatus.h">
|
<ClInclude Include="..\..\src\ripple\app\peers\ClusterNodeStatus.h">
|
||||||
</ClInclude>
|
</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">
|
<ClCompile Include="..\..\src\ripple\app\peers\UniqueNodeList.cpp">
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
|
||||||
@@ -2700,6 +2692,10 @@
|
|||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
|
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
|
||||||
</ClInclude>
|
</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 Include="..\..\src\ripple\overlay\impl\ProtocolMessage.h">
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClCompile Include="..\..\src\ripple\overlay\impl\TMHello.cpp">
|
<ClCompile Include="..\..\src\ripple\overlay\impl\TMHello.cpp">
|
||||||
@@ -2720,6 +2716,8 @@
|
|||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
|
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\ripple\overlay\PeerSet.h">
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
|
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<None Include="..\..\src\ripple\overlay\README.md">
|
<None Include="..\..\src\ripple\overlay\README.md">
|
||||||
|
|||||||
@@ -2532,12 +2532,6 @@
|
|||||||
<ClInclude Include="..\..\src\ripple\app\peers\ClusterNodeStatus.h">
|
<ClInclude Include="..\..\src\ripple\app\peers\ClusterNodeStatus.h">
|
||||||
<Filter>ripple\app\peers</Filter>
|
<Filter>ripple\app\peers</Filter>
|
||||||
</ClInclude>
|
</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">
|
<ClCompile Include="..\..\src\ripple\app\peers\UniqueNodeList.cpp">
|
||||||
<Filter>ripple\app\peers</Filter>
|
<Filter>ripple\app\peers</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -3228,6 +3222,9 @@
|
|||||||
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
|
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
|
||||||
<Filter>ripple\overlay\impl</Filter>
|
<Filter>ripple\overlay\impl</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClCompile Include="..\..\src\ripple\overlay\impl\PeerSet.cpp">
|
||||||
|
<Filter>ripple\overlay\impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClInclude Include="..\..\src\ripple\overlay\impl\ProtocolMessage.h">
|
<ClInclude Include="..\..\src\ripple\overlay\impl\ProtocolMessage.h">
|
||||||
<Filter>ripple\overlay\impl</Filter>
|
<Filter>ripple\overlay\impl</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@@ -3255,6 +3252,9 @@
|
|||||||
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
|
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
|
||||||
<Filter>ripple\overlay</Filter>
|
<Filter>ripple\overlay</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\ripple\overlay\PeerSet.h">
|
||||||
|
<Filter>ripple\overlay</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
|
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
|
||||||
<Filter>ripple\overlay</Filter>
|
<Filter>ripple\overlay</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#define RIPPLE_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
|
#define RIPPLE_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
|
||||||
|
|
||||||
#include <ripple/app/ledger/Ledger.h>
|
#include <ripple/app/ledger/Ledger.h>
|
||||||
#include <ripple/app/peers/PeerSet.h>
|
#include <ripple/overlay/PeerSet.h>
|
||||||
#include <ripple/basics/CountedObject.h>
|
#include <ripple/basics/CountedObject.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#ifndef RIPPLE_APP_TX_TRANSACTIONACQUIRE_H_INCLUDED
|
#ifndef RIPPLE_APP_TX_TRANSACTIONACQUIRE_H_INCLUDED
|
||||||
#define 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>
|
#include <ripple/shamap/SHAMap.h>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
|
|||||||
@@ -20,9 +20,9 @@
|
|||||||
#ifndef RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
|
#ifndef RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
|
||||||
#define 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/json/json_value.h>
|
||||||
#include <ripple/overlay/Peer.h>
|
#include <ripple/overlay/Peer.h>
|
||||||
|
#include <ripple/overlay/PeerSet.h>
|
||||||
#include <ripple/server/Handoff.h>
|
#include <ripple/server/Handoff.h>
|
||||||
#include <beast/asio/ssl_bundle.h>
|
#include <beast/asio/ssl_bundle.h>
|
||||||
#include <beast/http/message.h>
|
#include <beast/http/message.h>
|
||||||
|
|||||||
@@ -29,30 +29,45 @@
|
|||||||
|
|
||||||
namespace ripple {
|
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
|
class PeerSet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef beast::abstract_clock <std::chrono::steady_clock> clock_type;
|
typedef beast::abstract_clock <std::chrono::steady_clock> clock_type;
|
||||||
|
|
||||||
|
/** Returns the hash of the data we want. */
|
||||||
uint256 const& getHash () const
|
uint256 const& getHash () const
|
||||||
{
|
{
|
||||||
return mHash;
|
return mHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns true if we got all the data. */
|
||||||
bool isComplete () const
|
bool isComplete () const
|
||||||
{
|
{
|
||||||
return mComplete;
|
return mComplete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns false if we failed to get the data. */
|
||||||
bool isFailed () const
|
bool isFailed () const
|
||||||
{
|
{
|
||||||
return mFailed;
|
return mFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the number of times we timed out. */
|
||||||
int getTimeouts () const
|
int getTimeouts () const
|
||||||
{
|
{
|
||||||
return mTimeouts;
|
return mTimeouts;
|
||||||
@@ -60,22 +75,13 @@ public:
|
|||||||
|
|
||||||
bool isActive ();
|
bool isActive ();
|
||||||
|
|
||||||
|
/** Called to indicate that forward progress has been made. */
|
||||||
void progress ()
|
void progress ()
|
||||||
{
|
{
|
||||||
mProgress = true;
|
mProgress = true;
|
||||||
mAggressive = false;
|
mAggressive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearProgress ()
|
|
||||||
{
|
|
||||||
mProgress = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isProgress ()
|
|
||||||
{
|
|
||||||
return mProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
void touch ()
|
void touch ()
|
||||||
{
|
{
|
||||||
mLastAction = m_clock.now();
|
mLastAction = m_clock.now();
|
||||||
@@ -86,22 +92,12 @@ public:
|
|||||||
return mLastAction;
|
return mLastAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VFALCO TODO Rename this to addPeerToSet
|
/** Insert a peer to the managed set.
|
||||||
//
|
This will call the derived class hook function.
|
||||||
bool peerHas (Peer::ptr const&);
|
@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
|
virtual bool isDone () const
|
||||||
{
|
{
|
||||||
return mComplete || mFailed;
|
return mComplete || mFailed;
|
||||||
@@ -118,12 +114,20 @@ protected:
|
|||||||
|
|
||||||
PeerSet (uint256 const& hash, int interval, bool txnData,
|
PeerSet (uint256 const& hash, int interval, bool txnData,
|
||||||
clock_type& clock, beast::Journal journal);
|
clock_type& clock, beast::Journal journal);
|
||||||
|
|
||||||
virtual ~PeerSet () = 0;
|
virtual ~PeerSet () = 0;
|
||||||
|
|
||||||
virtual void newPeer (Peer::ptr const&) = 0;
|
virtual void newPeer (Peer::ptr const&) = 0;
|
||||||
|
|
||||||
virtual void onTimer (bool progress, ScopedLockType&) = 0;
|
virtual void onTimer (bool progress, ScopedLockType&) = 0;
|
||||||
|
|
||||||
virtual std::weak_ptr<PeerSet> pmDowncast () = 0;
|
virtual std::weak_ptr<PeerSet> pmDowncast () = 0;
|
||||||
|
|
||||||
|
bool isProgress ()
|
||||||
|
{
|
||||||
|
return mProgress;
|
||||||
|
}
|
||||||
|
|
||||||
void setComplete ()
|
void setComplete ()
|
||||||
{
|
{
|
||||||
mComplete = true;
|
mComplete = true;
|
||||||
@@ -132,11 +136,17 @@ protected:
|
|||||||
{
|
{
|
||||||
mFailed = true;
|
mFailed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void invokeOnTimer ();
|
void invokeOnTimer ();
|
||||||
|
|
||||||
void sendRequest (const protocol::TMGetLedger& message);
|
void sendRequest (const protocol::TMGetLedger& message);
|
||||||
|
|
||||||
void sendRequest (const protocol::TMGetLedger& message, Peer::ptr const& peer);
|
void sendRequest (const protocol::TMGetLedger& message, Peer::ptr const& peer);
|
||||||
|
|
||||||
|
void setTimer ();
|
||||||
|
|
||||||
|
std::size_t getPeerCount () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
beast::Journal m_journal;
|
beast::Journal m_journal;
|
||||||
clock_type& m_clock;
|
clock_type& m_clock;
|
||||||
@@ -153,7 +163,6 @@ protected:
|
|||||||
clock_type::time_point mLastAction;
|
clock_type::time_point mLastAction;
|
||||||
bool mProgress;
|
bool mProgress;
|
||||||
|
|
||||||
|
|
||||||
// VFALCO TODO move the responsibility for the timer to a higher level
|
// VFALCO TODO move the responsibility for the timer to a higher level
|
||||||
boost::asio::deadline_timer mTimer;
|
boost::asio::deadline_timer mTimer;
|
||||||
|
|
||||||
@@ -592,7 +592,7 @@ OverlayImpl::selectPeers (PeerSet& set, std::size_t limit,
|
|||||||
});
|
});
|
||||||
std::size_t accepted = 0;
|
std::size_t accepted = 0;
|
||||||
for (auto const& e : v)
|
for (auto const& e : v)
|
||||||
if (set.peerHas(e.second) && ++accepted >= limit)
|
if (set.insert(e.second) && ++accepted >= limit)
|
||||||
break;
|
break;
|
||||||
return accepted;
|
return accepted;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <BeastConfig.h>
|
#include <BeastConfig.h>
|
||||||
#include <ripple/app/main/Application.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/core/JobQueue.h>
|
||||||
#include <ripple/overlay/Overlay.h>
|
#include <ripple/overlay/Overlay.h>
|
||||||
#include <beast/asio/placeholders.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);
|
ScopedLockType sl (mLock);
|
||||||
|
|
||||||
@@ -68,12 +68,6 @@ bool PeerSet::peerHas (Peer::ptr const& ptr)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PeerSet::badPeer (Peer::ptr const& ptr)
|
|
||||||
{
|
|
||||||
ScopedLockType sl (mLock);
|
|
||||||
mPeers.erase (ptr->id ());
|
|
||||||
}
|
|
||||||
|
|
||||||
void PeerSet::setTimer ()
|
void PeerSet::setTimer ()
|
||||||
{
|
{
|
||||||
mTimer.expires_from_now (boost::posix_time::milliseconds (mTimerInterval));
|
mTimer.expires_from_now (boost::posix_time::milliseconds (mTimerInterval));
|
||||||
@@ -96,7 +90,7 @@ void PeerSet::invokeOnTimer ()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clearProgress ();
|
mProgress = false;
|
||||||
onTimer (true, sl);
|
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 PeerSet::getPeerCount () const
|
||||||
{
|
{
|
||||||
std::size_t ret (0);
|
std::size_t ret (0);
|
||||||
@@ -20,6 +20,5 @@
|
|||||||
#include <BeastConfig.h>
|
#include <BeastConfig.h>
|
||||||
|
|
||||||
#include <ripple/app/consensus/LedgerConsensus.cpp>
|
#include <ripple/app/consensus/LedgerConsensus.cpp>
|
||||||
#include <ripple/app/peers/PeerSet.cpp>
|
|
||||||
#include <ripple/app/ledger/LedgerCleaner.cpp>
|
#include <ripple/app/ledger/LedgerCleaner.cpp>
|
||||||
#include <ripple/app/ledger/LedgerMaster.cpp>
|
#include <ripple/app/ledger/LedgerMaster.cpp>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <ripple/overlay/impl/Message.cpp>
|
#include <ripple/overlay/impl/Message.cpp>
|
||||||
#include <ripple/overlay/impl/OverlayImpl.cpp>
|
#include <ripple/overlay/impl/OverlayImpl.cpp>
|
||||||
#include <ripple/overlay/impl/PeerImp.cpp>
|
#include <ripple/overlay/impl/PeerImp.cpp>
|
||||||
|
#include <ripple/overlay/impl/PeerSet.cpp>
|
||||||
#include <ripple/overlay/impl/TMHello.cpp>
|
#include <ripple/overlay/impl/TMHello.cpp>
|
||||||
|
|
||||||
#include <ripple/overlay/tests/short_read.test.cpp>
|
#include <ripple/overlay/tests/short_read.test.cpp>
|
||||||
|
|||||||
Reference in New Issue
Block a user