diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj
index cb3e963e44..bc104f0bad 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj
+++ b/Builds/VisualStudio2013/RippleD.vcxproj
@@ -3908,7 +3908,9 @@
True
True
-
+
+ True
+ True
@@ -3918,36 +3920,37 @@
..\..\src\websocketpp;%(AdditionalIncludeDirectories)
..\..\src\websocketpp;%(AdditionalIncludeDirectories)
-
+
-
- True
+
+ True
+ True
-
+
-
- True
+
+ True
+ True
-
+
-
+
-
- True
+
+ True
+ True
-
+
-
+
-
- True
+
+ True
+ True
-
+
-
- True
-
-
+
diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters
index 7d252272f2..ecd220f76d 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj.filters
+++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters
@@ -436,14 +436,11 @@
{5DB3CD0B-B361-B301-9562-697CA8A52B68}
-
- {B23DCD4C-1622-2C31-4562-87F2F95D3884}
+
+ {843C622F-AA52-E6C5-D3EB-D4B6D564B395}
-
- {3D1F0CBE-9B69-D29E-EAAE-E5A1204068BC}
-
-
- {663AE0EE-6781-C2F4-8D04-0D5D30AC0773}
+
+ {416459B4-BDA4-31D6-834A-88932E767F37}
{44780F86-42D3-2F2B-0846-5AEE2CA6D7FE}
@@ -4563,7 +4560,7 @@
ripple\unity
-
+
ripple\unity
@@ -4572,44 +4569,41 @@
ripple\unity
-
- ripple\validators
+
+ ripple\unl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators\impl
+
+ ripple\unl\impl
-
- ripple\validators
+
+ ripple\unl
-
- ripple\validators\tests
-
-
- ripple\validators
+
+ ripple\unl
ripple\websocket
diff --git a/SConstruct b/SConstruct
index c2bce4f74c..1eedf758ac 100644
--- a/SConstruct
+++ b/SConstruct
@@ -679,7 +679,8 @@ def get_classic_sources(toolchain):
append_sources(result, *list_sources('src/ripple/rpc', '.cpp'))
append_sources(result, *list_sources('src/ripple/shamap', '.cpp'))
append_sources(result, *list_sources('src/ripple/test', '.cpp'))
-
+ append_sources(result, *list_sources('src/ripple/unl', '.cpp'))
+
append_sources(
result,
*list_sources('src/ripple/nodestore', '.cpp'),
@@ -716,6 +717,7 @@ def get_unity_sources(toolchain):
'src/ripple/unity/rpcx.cpp',
'src/ripple/unity/shamap.cpp',
'src/ripple/unity/test.cpp',
+ 'src/ripple/unity/unl.cpp',
)
append_sources(
@@ -843,7 +845,6 @@ for tu_style in ['classic', 'unity']:
'src/ripple/unity/ripple.proto.cpp',
'src/ripple/unity/resource.cpp',
'src/ripple/unity/server.cpp',
- 'src/ripple/unity/validators.cpp',
'src/ripple/unity/websocket02.cpp'
)
diff --git a/src/ripple/app/ledger/impl/LedgerMaster.cpp b/src/ripple/app/ledger/impl/LedgerMaster.cpp
index d0f86b1e35..1934225d16 100644
--- a/src/ripple/app/ledger/impl/LedgerMaster.cpp
+++ b/src/ripple/app/ledger/impl/LedgerMaster.cpp
@@ -45,7 +45,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include //
diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp
index 035d1e5fc4..556f8355df 100644
--- a/src/ripple/app/main/Application.cpp
+++ b/src/ripple/app/main/Application.cpp
@@ -64,7 +64,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -291,7 +291,7 @@ public:
std::unique_ptr m_networkOPs;
std::unique_ptr m_deprecatedUNL;
std::unique_ptr serverHandler_;
- std::unique_ptr m_validators;
+ std::unique_ptr m_validators;
std::unique_ptr m_amendmentTable;
std::unique_ptr mFeeTrack;
std::unique_ptr mHashRouter;
@@ -407,8 +407,8 @@ public:
, serverHandler_ (make_ServerHandler (*m_networkOPs, get_io_service (),
*m_jobQueue, *m_networkOPs, *m_resourceManager, *m_collectorManager))
- , m_validators (Validators::make_Manager(*this, get_io_service(),
- m_logs.journal("UVL"), getConfig ()))
+ , m_validators (unl::make_Manager(*this, get_io_service(),
+ m_logs.journal("UNL"), getConfig ()))
, m_amendmentTable (make_AmendmentTable
(weeks(2), MAJORITY_FRACTION,
@@ -570,7 +570,7 @@ public:
return cachedSLEs_;
}
- Validators::Manager& getValidators ()
+ unl::Manager& getValidators ()
{
return *m_validators;
}
diff --git a/src/ripple/app/main/Application.h b/src/ripple/app/main/Application.h
index 9dc4a86f11..c169867a7b 100644
--- a/src/ripple/app/main/Application.h
+++ b/src/ripple/app/main/Application.h
@@ -31,7 +31,7 @@ namespace boost { namespace asio { class io_service; } }
namespace ripple {
-namespace Validators { class Manager; }
+namespace unl { class Manager; }
namespace Resource { class Manager; }
namespace NodeStore { class Database; }
@@ -98,7 +98,7 @@ public:
virtual JobQueue& getJobQueue () = 0;
virtual NodeCache& getTempNodeCache () = 0;
virtual CachedSLEs& cachedSLEs() = 0;
- virtual Validators::Manager& getValidators () = 0;
+ virtual unl::Manager& getValidators () = 0;
virtual AmendmentTable& getAmendmentTable() = 0;
virtual IHashRouter& getHashRouter () = 0;
virtual LoadFeeTrack& getFeeTrack () = 0;
diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp
index 9b00fe2e03..b6a914b1c5 100644
--- a/src/ripple/overlay/impl/OverlayImpl.cpp
+++ b/src/ripple/overlay/impl/OverlayImpl.cpp
@@ -111,6 +111,18 @@ OverlayImpl::Timer::on_timer (error_code ec)
overlay_.sendEndpoints();
overlay_.autoConnect();
+ {
+ std::lock_guard<
+ std::recursive_mutex> lock (overlay_.mutex_);
+ for (auto const& e : overlay_.m_publicKeyMap)
+ {
+ auto const sp = e.second.lock();
+ if (sp)
+ if (sp->unlHorizon_->shouldDrop())
+ sp->fail("Poor UNL horizon");
+ }
+ }
+
if ((++overlay_.timer_count_ % Tuning::checkSeconds) == 0)
overlay_.check();
diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp
index 67e7119ca9..609c649e8a 100644
--- a/src/ripple/overlay/impl/PeerImp.cpp
+++ b/src/ripple/overlay/impl/PeerImp.cpp
@@ -81,7 +81,8 @@ PeerImp::PeerImp (id_t id, endpoint_type remote_endpoint,
, fee_ (Resource::feeLightPeer)
, slot_ (slot)
, http_message_(std::move(request))
- , validatorsConnection_(getApp().getValidators().newConnection(id))
+ , unlHorizon_(getApp().getValidators().insert(id,
+ slotToHorizonKind(*slot_)))
{
}
@@ -425,7 +426,10 @@ PeerImp::close()
void
PeerImp::fail(std::string const& reason)
{
- assert(strand_.running_in_this_thread());
+ if(! strand_.running_in_this_thread())
+ return strand_.post(std::bind (
+ (void(Peer::*)(std::string const&))&PeerImp::fail,
+ shared_from_this(), reason));
if (socket_.is_open())
if (journal_.debug) journal_.debug <<
reason;
@@ -1803,7 +1807,8 @@ PeerImp::checkValidation (Job&, STValidation::pointer val,
}
#if RIPPLE_HOOK_VALIDATORS
- validatorsConnection_->onValidation(*val);
+ getApp().getValidators().onMessage(
+ unlHorizon_, *packet, *val);
#endif
if (getApp().getOPs ().recvValidation(
diff --git a/src/ripple/overlay/impl/PeerImp.h b/src/ripple/overlay/impl/PeerImp.h
index 2f06506c4a..27f9cad2c3 100644
--- a/src/ripple/overlay/impl/PeerImp.h
+++ b/src/ripple/overlay/impl/PeerImp.h
@@ -33,7 +33,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -160,10 +160,10 @@ private:
int large_sendq_ = 0;
int no_ping_ = 0;
std::unique_ptr load_event_;
- std::unique_ptr validatorsConnection_;
+ std::unique_ptr unlHorizon_;
bool hopsAware_ = false;
- //--------------------------------------------------------------------------
+ friend class OverlayImpl;
public:
PeerImp (PeerImp const&) = delete;
@@ -325,13 +325,13 @@ public:
bool
isHighLatency() const override;
+ void
+ fail(std::string const& reason);
+
private:
void
close();
- void
- fail(std::string const& reason);
-
void
fail(std::string const& name, error_code ec);
@@ -436,6 +436,16 @@ private:
state_ = new_state;
}
+ unl::Horizon::Kind
+ slotToHorizonKind (PeerFinder::Slot const& slot)
+ {
+ if(slot.fixed())
+ return unl::Horizon::kindTrusted;
+ if(slot.inbound())
+ return unl::Horizon::kindUntrusted;
+ return unl::Horizon::kindManaged;
+ }
+
//--------------------------------------------------------------------------
void
@@ -511,7 +521,8 @@ PeerImp::PeerImp (std::unique_ptr&& ssl_bundle,
, fee_ (Resource::feeLightPeer)
, slot_ (std::move(slot))
, http_message_(std::move(response))
- , validatorsConnection_(getApp().getValidators().newConnection(id))
+ , unlHorizon_(getApp().getValidators().insert(id,
+ slotToHorizonKind(*slot_)))
{
read_buffer_.commit (boost::asio::buffer_copy(read_buffer_.prepare(
boost::asio::buffer_size(buffers)), buffers));
diff --git a/src/ripple/unity/validators.cpp b/src/ripple/unity/unl.cpp
similarity index 80%
rename from src/ripple/unity/validators.cpp
rename to src/ripple/unity/unl.cpp
index a85b1a2a2c..aa473b1c85 100644
--- a/src/ripple/unity/validators.cpp
+++ b/src/ripple/unity/unl.cpp
@@ -18,8 +18,8 @@
//==============================================================================
#include
-#include
-#include
-#include
-#include
-#include
+
+#include
+#include
+#include
+#include
diff --git a/src/ripple/validators/Connection.h b/src/ripple/unl/Horizon.h
similarity index 68%
rename from src/ripple/validators/Connection.h
rename to src/ripple/unl/Horizon.h
index 3632448bb5..7e9b4fe119 100644
--- a/src/ripple/validators/Connection.h
+++ b/src/ripple/unl/Horizon.h
@@ -17,22 +17,35 @@
*/
//==============================================================================
-#ifndef RIPPLE_VALIDATORS_CONNECTION_H_INCLUDED
-#define RIPPLE_VALIDATORS_CONNECTION_H_INCLUDED
-
-#include
+#ifndef RIPPLE_UNL_HORIZON_H_INCLUDED
+#define RIPPLE_UNL_HORIZON_H_INCLUDED
namespace ripple {
-namespace Validators {
+namespace unl {
-/** Represents validator concerns on a protocol connection. */
-class Connection
+/** Maintains validator horizon statistics on a connection. */
+class Horizon
{
public:
- virtual ~Connection() = default;
+ enum Kind
+ {
+ /* Outbound made by autoconnect.
+ Can be dropped.
+ */
+ kindManaged,
- /** Called when a signed validation is received on the connection. */
- virtual void onValidation (STValidation const& v) = 0;
+ /* Inbound. */
+ kindUntrusted,
+
+ /* Fixed or cluster peer.
+ Can't be dropped.
+ */
+ kindTrusted
+ };
+
+ virtual ~Horizon() = default;
+
+ virtual bool shouldDrop() = 0;
};
}
diff --git a/src/ripple/validators/README.md b/src/ripple/unl/README.md
similarity index 100%
rename from src/ripple/validators/README.md
rename to src/ripple/unl/README.md
diff --git a/src/ripple/unl/UNLManager.h b/src/ripple/unl/UNLManager.h
new file mode 100644
index 0000000000..2dd9acd647
--- /dev/null
+++ b/src/ripple/unl/UNLManager.h
@@ -0,0 +1,83 @@
+//------------------------------------------------------------------------------
+/*
+ This file is part of rippled: https://github.com/ripple/rippled
+ Copyright (c) 2012, 2013 Ripple Labs Inc.
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+//==============================================================================
+
+#ifndef RIPPLE_UNL_MANAGER_H_INCLUDED
+#define RIPPLE_UNL_MANAGER_H_INCLUDED
+
+#include "ripple.pb.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace ripple {
+namespace unl {
+
+/** Maintains the list of chosen validators.
+ The algorithm for acquiring, building, and calculating metadata on
+ the list of chosen validators is critical to the health of the network.
+ All operations are performed asynchronously on an internal thread.
+*/
+class Manager : public beast::PropertyStream::Source
+{
+protected:
+ Manager();
+
+public:
+ /** Destroy the object.
+ Any pending source fetch operations are aborted. This will block
+ until any pending database I/O has completed and the thread has
+ stopped.
+ */
+ virtual ~Manager() = default;
+
+ virtual
+ std::unique_ptr
+ insert (int id, Horizon::Kind kind) = 0;
+
+ virtual
+ void
+ erase (std::unique_ptr c) = 0;
+
+ /** Called when a signed validation is received
+ Preconditions:
+ Signature check passed
+ Effects:
+ */
+ virtual
+ void
+ onMessage (std::unique_ptr const& h,
+ protocol::TMValidation const& m,
+ STValidation const& v) = 0;
+
+ /** Called when a ledger is built. */
+ virtual
+ void
+ onLedgerClosed (LedgerIndex index,
+ LedgerHash const& hash, LedgerHash const& parent) = 0;
+};
+
+}
+}
+
+#endif
diff --git a/src/ripple/validators/impl/ConnectionImp.cpp b/src/ripple/unl/impl/BasicHorizon.cpp
similarity index 93%
rename from src/ripple/validators/impl/ConnectionImp.cpp
rename to src/ripple/unl/impl/BasicHorizon.cpp
index b8902a844d..da958c71bb 100644
--- a/src/ripple/validators/impl/ConnectionImp.cpp
+++ b/src/ripple/unl/impl/BasicHorizon.cpp
@@ -18,10 +18,10 @@
//==============================================================================
#include
-#include
+#include
namespace ripple {
-namespace Validators {
+namespace unl {
}
}
diff --git a/src/ripple/validators/impl/ConnectionImp.h b/src/ripple/unl/impl/BasicHorizon.h
similarity index 74%
rename from src/ripple/validators/impl/ConnectionImp.h
rename to src/ripple/unl/impl/BasicHorizon.h
index f2cb58484a..5e4cead2f3 100644
--- a/src/ripple/validators/impl/ConnectionImp.h
+++ b/src/ripple/unl/impl/BasicHorizon.h
@@ -17,18 +17,23 @@
*/
//==============================================================================
-#ifndef RIPPLE_VALIDATORS_CONNECTIONIMP_H_INCLUDED
-#define RIPPLE_VALIDATORS_CONNECTIONIMP_H_INCLUDED
+#ifndef RIPPLE_UNL_BASICHORIZON_H_INCLUDED
+#define RIPPLE_UNL_BASICHORIZON_H_INCLUDED
+#include "ripple.pb.h"
#include
+#include
+#include
#include
-#include
-#include
+#include
+#include
+#include
#include
#include
#include
#include
#include
+#include
#include
#include
#include
@@ -36,12 +41,15 @@
#include