diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index 7875c6daf1..c2311041c8 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -1654,6 +1654,7 @@ + @@ -1708,7 +1709,6 @@ - diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 497d9fa51b..e6671febf8 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -247,6 +247,9 @@ {28a8ede0-743b-4a9a-bae1-5b2bc03ee44e} + + {d7d4123e-3fb2-4f85-9596-1ae26b6c14fd} + @@ -1715,9 +1718,6 @@ [1] Ripple\ripple_core\functional - - [1] Ripple\ripple_core\functional - [1] Ripple\ripple_app\main @@ -2283,9 +2283,6 @@ [1] Ripple\resource\impl - - [1] Ripple\resource\impl - [1] Ripple\resource\api @@ -2295,9 +2292,6 @@ [1] Ripple\resource\impl - - [1] Ripple\resource\impl - [1] Ripple\resource\api @@ -2307,6 +2301,12 @@ [1] Ripple\resource\api + + [1] Ripple\algorithm + + + [1] Ripple\resource\impl + diff --git a/src/ripple/resource/impl/Logic.h b/src/ripple/resource/impl/Logic.h index 70a03c0f5a..793ec12b19 100644 --- a/src/ripple/resource/impl/Logic.h +++ b/src/ripple/resource/impl/Logic.h @@ -53,12 +53,14 @@ public: typedef SharedData SharedState; SharedState m_state; + DiscreteClock m_clock; Journal m_journal; //-------------------------------------------------------------------------- - Logic (Journal journal) - : m_journal (journal) + Logic (DiscreteClock ::Source& source, Journal journal) + : m_clock (source) + , m_journal (journal) { #if 1 #if BEAST_MSVC @@ -83,11 +85,6 @@ public: state->table.clear(); } - virtual DiscreteTime get_now () - { - return 0; - } - Consumer newInboundEndpoint (IPEndpoint const& address) { if (isWhitelisted (address)) @@ -216,7 +213,7 @@ public: Gossip exportConsumers () { - DiscreteTime const now (get_now()); + DiscreteTime const now (m_clock()); Gossip gossip; SharedState::Access state (m_state); @@ -242,7 +239,7 @@ public: void importConsumers (std::string const& origin, Gossip const& gossip) { - DiscreteTime const now (get_now()); + DiscreteTime const now (m_clock()); { SharedState::Access state (m_state); @@ -311,7 +308,7 @@ public: { SharedState::Access state (m_state); - DiscreteTime const now (get_now()); + DiscreteTime const now (m_clock()); for (List ::iterator iter ( state->inactive.begin()); iter != state->inactive.end();) @@ -390,7 +387,7 @@ public: break; } state->inactive.push_back (entry); - entry.whenExpires = get_now() + secondsUntilExpiration; + entry.whenExpires = m_clock() + secondsUntilExpiration; } } @@ -405,7 +402,7 @@ public: Disposition charge (Entry& entry, Charge const& fee, SharedState::Access& state) { - DiscreteTime const now (get_now()); + DiscreteTime const now (m_clock()); int const balance (entry.add (fee.cost(), now)); m_journal.info << "Charging " << entry.label() << " for " << fee; return disposition (balance); @@ -414,7 +411,7 @@ public: bool warn (Entry& entry, SharedState::Access& state) { bool notify (false); - DiscreteTime const now (get_now()); + DiscreteTime const now (m_clock()); if (entry.balance (now) >= warningThreshold && now != entry.lastWarningTime) { charge (entry, feeWarning, state); @@ -431,7 +428,7 @@ public: bool disconnect (Entry& entry, SharedState::Access& state) { bool drop (false); - DiscreteTime const now (get_now()); + DiscreteTime const now (m_clock()); if (entry.balance (now) >= dropThreshold) { charge (entry, feeDrop, state); @@ -442,7 +439,7 @@ public: int balance (Entry& entry, SharedState::Access& state) { - return entry.balance (get_now()); + return entry.balance (m_clock()); } //-------------------------------------------------------------------------- @@ -511,7 +508,7 @@ public: void onWrite (PropertyStream::Map& map) { - DiscreteTime const now (get_now()); + DiscreteTime const now (m_clock()); SharedState::Access state (m_state); diff --git a/src/ripple/resource/impl/LogicType.h b/src/ripple/resource/impl/LogicType.h index 078c523a3e..e33d9862b4 100644 --- a/src/ripple/resource/impl/LogicType.h +++ b/src/ripple/resource/impl/LogicType.h @@ -23,25 +23,23 @@ namespace ripple { namespace Resource { -/** Provides the Clock required by Logic's get_now(). - This allows the unit tests to provide its own manual clock. -*/ -template -class LogicType : public Logic +template +class LogicType + : private BaseFromMember + , public Logic { public: + typedef typename DiscreteClockSourceType::DiscreteClockType DiscreteClockType; + explicit LogicType (Journal journal) - : Logic (journal) + : Logic (BaseFromMember ::member(), journal) { } - DiscreteTime get_now () + DiscreteClockSourceType& clock() { - return m_clock(); + return BaseFromMember ::member(); } - -private: - Clock m_clock; }; } diff --git a/src/ripple/resource/impl/Manager.cpp b/src/ripple/resource/impl/Manager.cpp index 9b2b4770fe..bd8a6f8548 100644 --- a/src/ripple/resource/impl/Manager.cpp +++ b/src/ripple/resource/impl/Manager.cpp @@ -30,8 +30,7 @@ public: ManagerImp (Journal journal) : Thread ("Resource::Manager") - , - m_journal (journal) + , m_journal (journal) , m_logic (journal) { startThread (); diff --git a/src/ripple/resource/impl/SimpleMonotonicClock.h b/src/ripple/resource/impl/SimpleMonotonicClock.h deleted file mode 100644 index 88a60824d4..0000000000 --- a/src/ripple/resource/impl/SimpleMonotonicClock.h +++ /dev/null @@ -1,40 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_RESOURCE_SIMPLEMONOTONICCLOCK_H_INCLUDED -#define RIPPLE_RESOURCE_SIMPLEMONOTONICCLOCK_H_INCLUDED - -namespace ripple { -namespace Resource { - -/** Monotonically increasing time value. */ -struct SimpleMonotonicClock -{ - typedef int value_type; - - value_type operator() () const - { - return value_type (RelativeTime::fromStartup().inSeconds()); - } -}; - -} -} - -#endif diff --git a/src/ripple/resource/impl/Tests.cpp b/src/ripple/resource/impl/Tests.cpp index f963703bc2..d4bcac90d3 100644 --- a/src/ripple/resource/impl/Tests.cpp +++ b/src/ripple/resource/impl/Tests.cpp @@ -23,22 +23,6 @@ namespace Resource { class Tests : public UnitTest { public: - // A manually operated clock - class TestClock - { - public: - static int& now() - { - static int when (0); - return when; - } - - int operator() () const - { - return now(); - } - }; - void createGossip (Gossip& gossip) { int const v (10 + random().nextInt (10)); @@ -58,8 +42,7 @@ public: { beginTestCase ("Imports"); - ScopedPointer logic ( - new LogicType (journal())); + LogicType logic (journal()); Gossip g[5]; @@ -67,7 +50,7 @@ public: createGossip (g[i]); for (int i = 0; i < 5; ++i) - logic->importConsumers (String::fromNumber (i).toStdString(), g[i]); + logic.importConsumers (String::fromNumber (i).toStdString(), g[i]); pass(); } @@ -76,8 +59,7 @@ public: { beginTestCase ("Import"); - ScopedPointer logic ( - new LogicType (journal())); + LogicType logic (journal()); Gossip g; Gossip::Item item; @@ -85,7 +67,7 @@ public: item.address = IPEndpoint (IPEndpoint::V4 (207, 127, 82, 1)); g.items.push_back (item); - logic->importConsumers ("g", g); + logic.importConsumers ("g", g); pass(); } @@ -93,34 +75,34 @@ public: void testCharges () { beginTestCase ("Charge"); - ScopedPointer logic ( - new LogicType (journal())); + + LogicType logic (journal()); { IPEndpoint address (IPEndpoint::from_string ("207.127.82.1")); - Consumer c (logic->newInboundEndpoint (address)); + Consumer c (logic.newInboundEndpoint (address)); logMessage ("Charging " + c.label() + " 10,000 units"); c.charge (10000); for (int i = 0; i < 128; ++i) { logMessage ( - "Time = " + String::fromNumber (TestClock::now()) + + "Time = " + String::fromNumber (logic.clock().now()) + ", Balance = " + String::fromNumber (c.balance())); - ++TestClock::now(); + ++logic.clock().now(); } } { IPEndpoint address (IPEndpoint::from_string ("207.127.82.2")); - Consumer c (logic->newInboundEndpoint (address)); + Consumer c (logic.newInboundEndpoint (address)); logMessage ("Charging " + c.label() + " 1000 units per second"); for (int i = 0; i < 128; ++i) { c.charge (1000); logMessage ( - "Time = " + String::fromNumber (TestClock::now()) + + "Time = " + String::fromNumber (logic.clock().now()) + ", Balance = " + String::fromNumber (c.balance())); - ++TestClock::now(); + ++logic.clock().now(); } } @@ -129,9 +111,9 @@ public: void runTest () { - //testCharges(); + testCharges(); testImports(); - //testImport(); + testImport(); } Tests () : UnitTest ("ResourceManager", "ripple", runManual) diff --git a/src/ripple/resource/ripple_resource.cpp b/src/ripple/resource/ripple_resource.cpp index 25d8c0d88f..c468bc224a 100644 --- a/src/ripple/resource/ripple_resource.cpp +++ b/src/ripple/resource/ripple_resource.cpp @@ -21,6 +21,8 @@ #include "ripple_resource.h" +#include "../algorithm/api/DiscreteClock.h" + #include "beast/modules/beast_core/system/BeforeBoost.h" #include @@ -31,7 +33,6 @@ # include "impl/Tuning.h" # include "impl/Entry.h" # include "impl/Import.h" -#include "impl/SimpleMonotonicClock.h" #include "impl/Charge.cpp" # include "impl/Logic.h" # include "impl/LogicType.h"