diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj
index ed63d4175..9f6855b8a 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj
+++ b/Builds/VisualStudio2013/RippleD.vcxproj
@@ -1934,14 +1934,6 @@
-
- True
- True
- ..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)
- ..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)
-
-
-
True
True
@@ -2700,6 +2692,10 @@
+
+ True
+ True
+
@@ -2720,6 +2716,8 @@
+
+
diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters
index 8fffc8862..23dd1516e 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj.filters
+++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters
@@ -2532,12 +2532,6 @@
ripple\app\peers
-
- ripple\app\peers
-
-
- ripple\app\peers
-
ripple\app\peers
@@ -3228,6 +3222,9 @@
ripple\overlay\impl
+
+ ripple\overlay\impl
+
ripple\overlay\impl
@@ -3255,6 +3252,9 @@
ripple\overlay
+
+ ripple\overlay
+
ripple\overlay
diff --git a/src/ripple/app/ledger/InboundLedger.h b/src/ripple/app/ledger/InboundLedger.h
index 49c7f0235..1d72faaa3 100644
--- a/src/ripple/app/ledger/InboundLedger.h
+++ b/src/ripple/app/ledger/InboundLedger.h
@@ -21,7 +21,7 @@
#define RIPPLE_APP_LEDGER_INBOUNDLEDGER_H_INCLUDED
#include
-#include
+#include
#include
#include
diff --git a/src/ripple/app/tx/TransactionAcquire.h b/src/ripple/app/tx/TransactionAcquire.h
index f6f94d119..cb54e6262 100644
--- a/src/ripple/app/tx/TransactionAcquire.h
+++ b/src/ripple/app/tx/TransactionAcquire.h
@@ -20,7 +20,7 @@
#ifndef RIPPLE_APP_TX_TRANSACTIONACQUIRE_H_INCLUDED
#define RIPPLE_APP_TX_TRANSACTIONACQUIRE_H_INCLUDED
-#include
+#include
#include
namespace ripple {
diff --git a/src/ripple/overlay/Overlay.h b/src/ripple/overlay/Overlay.h
index 7b014c30a..21a71ff51 100644
--- a/src/ripple/overlay/Overlay.h
+++ b/src/ripple/overlay/Overlay.h
@@ -20,9 +20,9 @@
#ifndef RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
#define RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
-#include
#include
#include
+#include
#include
#include
#include
diff --git a/src/ripple/app/peers/PeerSet.h b/src/ripple/overlay/PeerSet.h
similarity index 77%
rename from src/ripple/app/peers/PeerSet.h
rename to src/ripple/overlay/PeerSet.h
index a81fb29fc..237dc4ef2 100644
--- a/src/ripple/app/peers/PeerSet.h
+++ b/src/ripple/overlay/PeerSet.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 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&);
-
- // 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;
+ /** 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&);
+
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 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;
diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp
index 032845ec5..fe1950448 100644
--- a/src/ripple/overlay/impl/OverlayImpl.cpp
+++ b/src/ripple/overlay/impl/OverlayImpl.cpp
@@ -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;
}
diff --git a/src/ripple/app/peers/PeerSet.cpp b/src/ripple/overlay/impl/PeerSet.cpp
similarity index 91%
rename from src/ripple/app/peers/PeerSet.cpp
rename to src/ripple/overlay/impl/PeerSet.cpp
index 0b055128f..740999025 100644
--- a/src/ripple/app/peers/PeerSet.cpp
+++ b/src/ripple/overlay/impl/PeerSet.cpp
@@ -19,7 +19,7 @@
#include
#include
-#include
+#include
#include
#include
#include
@@ -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);
diff --git a/src/ripple/unity/app1.cpp b/src/ripple/unity/app1.cpp
index 9a4ade0fb..01cf34bc7 100644
--- a/src/ripple/unity/app1.cpp
+++ b/src/ripple/unity/app1.cpp
@@ -20,6 +20,5 @@
#include
#include
-#include
#include
#include
diff --git a/src/ripple/unity/overlay.cpp b/src/ripple/unity/overlay.cpp
index 242088957..0e94406c7 100644
--- a/src/ripple/unity/overlay.cpp
+++ b/src/ripple/unity/overlay.cpp
@@ -23,6 +23,7 @@
#include
#include
#include
+#include
#include
#include