diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index f3503ff721..d86bbb6da6 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -3279,29 +3279,6 @@ True - - - - - - - - - - - - - - - - - - - - - - True - @@ -3465,10 +3442,6 @@ - - - - diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index d936ffbabb..a95233105b 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -469,15 +469,6 @@ {55CFEEC5-7FF5-F959-9862-9FAE232054B7} - - {48C2C255-35B5-AA2C-B105-0F34A4D0347D} - - - {3C72B4D4-96EE-300D-795F-8FB6126FAEFD} - - - {B0FE6BBC-BDC6-E3A4-E670-C026AB04DABE} - {29DBD04F-9324-A965-5C79-AA06EC10BA58} @@ -4497,39 +4488,6 @@ ripple\sslutil\impl - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\api - - - ripple\testoverlay\impl - ripple\types @@ -4749,12 +4707,6 @@ ripple\unity - - ripple\unity - - - ripple\unity - ripple\unity diff --git a/SConstruct b/SConstruct index 115fde358e..f3bbb3453f 100644 --- a/SConstruct +++ b/SConstruct @@ -567,7 +567,6 @@ for toolchain in all_toolchains: objects.append(addSource('src/ripple/unity/rpcx.cpp', env, variant_dirs)) objects.append(addSource('src/ripple/unity/sitefiles.cpp', env, variant_dirs)) objects.append(addSource('src/ripple/unity/sslutil.cpp', env, variant_dirs)) - objects.append(addSource('src/ripple/unity/testoverlay.cpp', env, variant_dirs)) objects.append(addSource('src/ripple/unity/types.cpp', env, variant_dirs)) objects.append(addSource('src/ripple/unity/validators.cpp', env, variant_dirs)) objects.append(addSource('src/ripple/unity/websocket.cpp', env, variant_dirs)) diff --git a/src/ripple/testoverlay/README.md b/src/ripple/testoverlay/README.md deleted file mode 100644 index 9b39fcb19f..0000000000 --- a/src/ripple/testoverlay/README.md +++ /dev/null @@ -1,17 +0,0 @@ -# TestOverlay - -This provides a set of template classes for simulating a peer to peer -network. These facilities are provided: - -- Initial construction of the network. -- Message passing between peers -- Network wide state information. -- Per-peer state information. - -## Description - -Through the use of suitable template arguments, the logic and state information -for each peer can be customized. Messages are packets of arbitrary size with -template-parameter defined data. The network is modeled discretely; The time -evolution of the network is defined by successive steps where messages are -always delivered reliably on the next step after which they are sent. diff --git a/src/ripple/testoverlay/TODO.md b/src/ripple/testoverlay/TODO.md deleted file mode 100644 index 91521ba401..0000000000 --- a/src/ripple/testoverlay/TODO.md +++ /dev/null @@ -1,6 +0,0 @@ -# TestOverlay TODO - -- Add documentation - -- Fix the templates to be sane, use derivation and virtual instead of - compile time polymorphism diff --git a/src/ripple/testoverlay/api/ConfigType.h b/src/ripple/testoverlay/api/ConfigType.h deleted file mode 100644 index c2b283d791..0000000000 --- a/src/ripple/testoverlay/api/ConfigType.h +++ /dev/null @@ -1,57 +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_TESTOVERLAY_CONFIGTYPE_H_INCLUDED -#define RIPPLE_TESTOVERLAY_CONFIGTYPE_H_INCLUDED - -/** A simulated peer to peer network for unit tests. */ -namespace TestOverlay -{ - -/** Combines Params with standard Config requirements for test objects. */ -template < - class Params, - template class StateType = StateBase, - template class PeerLogicType = PeerLogicBase -> -class ConfigType -{ -public: - // These defaults can be overridden in - // Params simply by adding declarations to it. - - static std::int64_t const randomSeedValue = 42; - - typedef std::size_t SizeType; - - typedef SimplePayload Payload; - - typedef StateType State; - typedef MessageType Message; - typedef NetworkType Network; - - typedef PeerType Peer; - typedef PeerLogicType PeerLogic; - - typedef NoInitPolicy InitPolicy; -}; - -} - -#endif diff --git a/src/ripple/testoverlay/api/ConnectionType.h b/src/ripple/testoverlay/api/ConnectionType.h deleted file mode 100644 index 3e9beaf3d8..0000000000 --- a/src/ripple/testoverlay/api/ConnectionType.h +++ /dev/null @@ -1,195 +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_TESTOVERLAY_CONNECTIONTYPE_H_INCLUDED -#define RIPPLE_TESTOVERLAY_CONNECTIONTYPE_H_INCLUDED - -// HH Todo: Stop the practice of opening a namespace and #include -} // namespace ripple - -#include - -namespace ripple { - -namespace TestOverlay -{ - -/** A connection between two nodes. */ -template -class ConnectionType : public Config -{ -public: - typedef typename Config::Peer Peer; - typedef typename Config::Message Message; - typedef typename Config::State State; - typedef typename State::UniqueID UniqueID; - - typedef std::vector Messages; - typedef hash_set MessageTable; - - /** Create the 'no connection' object. */ - ConnectionType () - : m_peer (nullptr) - { - } - - ConnectionType (Peer& peer, bool inbound) - : m_peer (&peer) - , m_inbound (inbound) - { - } - - ConnectionType (ConnectionType const& other) - : m_peer (other.m_peer) - , m_inbound (other.m_inbound) - { - } - - ConnectionType& operator= (ConnectionType const& other) - { - m_peer = other.m_peer; - m_inbound = other.m_inbound; - return *this; - } - - /** Returns `true` if there is no connection. */ - bool empty () const - { - return m_peer == nullptr; - } - - /** Returns `true` if this is an inbound connection. - If there is no connection, the return value is undefined. - */ - bool inbound () const - { - return m_inbound; - } - - /** Returns the peer on the other end. - If there is no connection, the return value is undefined. - */ - /** @{ */ - Peer& peer () - { - return *m_peer; - } - - Peer const& peer () const - { - return *m_peer; - } - /** @} */ - - /** Returns a container with the current step's incoming messages. */ - /** @{ */ - Messages& messages () - { - return m_messages; - } - - Messages const& messages () const - { - return m_messages; - } - /** @} */ - - /** Returns a container with the next step's incoming messages. - During each step, peers process the current step's message - list, but post new messages to the pending messages list. - This way, new messages will always process in the next step - and not the current one. - */ - /** @{ */ - Messages& pending () - { - return m_pending; - } - - Messages const& pending () const - { - return m_pending; - } - /** @} */ - - - //-------------------------------------------------------------------------- - - /** A UnaryPredicate that always returns true. */ - class Any - { - public: - bool operator() (ConnectionType const&) const - { - return true; - } - }; - - //-------------------------------------------------------------------------- - - /** A UnaryPredicate that returns `true` if the peer matches. */ - class IsPeer - { - public: - explicit IsPeer (Peer const& peer) - : m_peer (&peer) - { - } - - bool operator() (ConnectionType const& connection) const - { - return &connection.peer () == m_peer; - } - - private: - Peer const* m_peer; - }; - - //-------------------------------------------------------------------------- - - /** A UnaryPredicate that returns `true` if the peer does not match. */ - class IsNotPeer - { - public: - explicit IsNotPeer (Peer const& peer) - : m_peer (&peer) - { - } - - bool operator() (ConnectionType const& connection) const - { - return &connection.peer () != m_peer; - } - - private: - Peer const* m_peer; - }; - - //-------------------------------------------------------------------------- - -private: - Peer* m_peer; - bool m_inbound; - Messages m_messages; - Messages m_pending; -}; - -} - -#endif diff --git a/src/ripple/testoverlay/api/InitPolicy.h b/src/ripple/testoverlay/api/InitPolicy.h deleted file mode 100644 index 8fb6699c57..0000000000 --- a/src/ripple/testoverlay/api/InitPolicy.h +++ /dev/null @@ -1,85 +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_TESTOVERLAY_INITPOLICY_H_INCLUDED -#define RIPPLE_TESTOVERLAY_INITPOLICY_H_INCLUDED - -/** A simulated peer to peer network for unit tests. */ -namespace TestOverlay -{ - -//------------------------------------------------------------------------------ -// -// InitPolicy -// -// This is called during construction to form the network. -// - -/** InitPolicy which does nothing. */ -class NoInitPolicy -{ -public: - template - void operator() (Network& network) - { - } -}; - -//------------------------------------------------------------------------------ - -/** Init policy for a pre-built connected network. */ -template -class PremadeInitPolicy -{ -public: - static int const numberOfPeers = NumberOfPeers; - static int const outgoingConnectionsPerPeer = OutgoingConnectionsPerPeer; - - template - void operator() (Network& network) - { - typedef typename Network::Peer Peer; - typedef typename Network::Peers Peers; - typedef typename Network::Config Config; - typedef typename Config::SizeType SizeType; - - for (SizeType i = 0; i < numberOfPeers; ++i) - network.createPeer (); - - Peers& peers (network.peers ()); - for (SizeType i = 0; i < numberOfPeers; ++i) - { - Peer& peer (*peers [i]); - for (SizeType j = 0; j < outgoingConnectionsPerPeer; ++j) - { - for (;;) - { - SizeType k (network.state ().random ().nextInt (numberOfPeers)); - if (peer.connect_to (*peers [k])) - break; - } - } - } - } -}; - -} - -#endif diff --git a/src/ripple/testoverlay/api/MessageType.h b/src/ripple/testoverlay/api/MessageType.h deleted file mode 100644 index 679b72cbf6..0000000000 --- a/src/ripple/testoverlay/api/MessageType.h +++ /dev/null @@ -1,75 +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_TESTOVERLAY_MESSAGETYPE_H_INCLUDED -#define RIPPLE_TESTOVERLAY_MESSAGETYPE_H_INCLUDED - -namespace TestOverlay -{ - -/** A message sent between peers. */ -template -class MessageType : public Config -{ -public: - typedef typename Config::State::UniqueID UniqueID; - typedef typename Config::Payload Payload; - - MessageType () - : m_id (0) - { - } - - MessageType (UniqueID id, Payload payload) - : m_id (id) - , m_payload (payload) - { - } - - MessageType (MessageType const& other) - : m_id (other.m_id) - , m_payload (other.m_payload) - { - } - - MessageType& operator= (MessageType const& other) - { - m_id = other.m_id; - m_payload = other.m_payload; - return *this; - } - - UniqueID id () const - { - return m_id; - } - - Payload payload () const - { - return m_payload; - } - -private: - UniqueID m_id; - Payload m_payload; -}; - -} - -#endif diff --git a/src/ripple/testoverlay/api/NetworkType.h b/src/ripple/testoverlay/api/NetworkType.h deleted file mode 100644 index f2571ff5e7..0000000000 --- a/src/ripple/testoverlay/api/NetworkType.h +++ /dev/null @@ -1,144 +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_TESTOVERLAY_NETWORKTYPE_H_INCLUDED -#define RIPPLE_TESTOVERLAY_NETWORKTYPE_H_INCLUDED - -namespace TestOverlay { - -template -class NetworkType : public ConfigParam -{ -public: - typedef ConfigParam Config; - - typedef typename Config::Peer Peer; - typedef typename Config::State State; - typedef typename Config::SizeType SizeType; - - typedef std::vector > Peers; - - NetworkType () - : m_steps (0) - { - typename Config::InitPolicy () (*this); - } - - /** Return the number of steps taken in the simulation. */ - SizeType steps () const - { - return m_steps; - } - - /** Return the size of the network measured in peers. */ - SizeType size () const - { - return m_peers.size (); - } - - /** Retrieve the state information associated with the Config. */ - State& state () - { - return m_state; - } - - /** Create new Peer. */ - Peer& createPeer () - { - Peer* peer (new Peer (*this)); - m_peers.push_back (std::unique_ptr (peer)); - return *peer; - } - - /** Retrieve the container holding the set of peers. */ - Peers& peers () - { - return m_peers; - } - - /** Run the network for 1 iteration. */ - Results step () - { - Results results; - for (typename Peers::iterator iter = m_peers.begin (); - iter!= m_peers.end (); ++iter) - (*iter)->pre_step (); - for (typename Peers::iterator iter = m_peers.begin (); - iter!= m_peers.end (); ++iter) - (*iter)->step (); - ++results.steps; - ++m_steps; - for (typename Peers::iterator iter = m_peers.begin (); - iter!= m_peers.end (); ++iter) - { - Peer& peer (**iter); - peer.post_step (); - results = results + peer.results(); - peer.results() = Results(); - } - return results; - } - - /** Run the network until a condition is met. - Requirements: - p (*this) is well-formed and returns bool. - */ - template - Results step_until (Predicate p) - { - Results results; - while (! p (*this)) - results += step (); - return results; - } - - //-------------------------------------------------------------------------- - - /** A UnaryPredicate that returns true after # steps have passed. */ - class Steps - { - public: - explicit Steps (SizeType steps) - : m_steps (steps) - { - } - - bool operator() (NetworkType const&) - { - if (m_steps == 0) - return true; - --m_steps; - return false; - } - - private: - SizeType m_steps; - }; - -private: - State m_state; - SizeType m_steps; - Peers m_peers; -}; - -//------------------------------------------------------------------------------ - -} - -#endif diff --git a/src/ripple/testoverlay/api/PeerLogicBase.h b/src/ripple/testoverlay/api/PeerLogicBase.h deleted file mode 100644 index 7cd697790b..0000000000 --- a/src/ripple/testoverlay/api/PeerLogicBase.h +++ /dev/null @@ -1,82 +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_TESTOVERLAY_PEERLOGICBASE_H_INCLUDED -#define RIPPLE_TESTOVERLAY_PEERLOGICBASE_H_INCLUDED - -namespace TestOverlay -{ - -/** Base class for all PeerLogic implementations. - This provides stubs for all necessary functions, although - they don't actually do anything. -*/ -template -class PeerLogicBase : public Config -{ -public: - typedef typename Config::Peer Peer; - typedef typename Peer::Connection Connection; - typedef typename Connection::Message Message; - - explicit PeerLogicBase (Peer& peer) - : m_peer (peer) - { - } - - /** Return the Peer associated with this logic. */ - /** @{ */ - Peer& peer () - { - return m_peer; - } - - Peer const& peer () const - { - return m_peer; - } - /** @} */ - - // Called to process a message - void receive (Connection const& c, Message const& m) - { - } - - // Called before taking a step - void pre_step () - { - } - - // Called during a step - void step () - { - } - - // Called after a step is taken - void post_step () - { - } - -private: - Peer& m_peer; -}; - -} - -#endif diff --git a/src/ripple/testoverlay/api/PeerType.h b/src/ripple/testoverlay/api/PeerType.h deleted file mode 100644 index c066163c2b..0000000000 --- a/src/ripple/testoverlay/api/PeerType.h +++ /dev/null @@ -1,302 +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_TESTOVERLAY_PEERTYPE_H_INCLUDED -#define RIPPLE_TESTOVERLAY_PEERTYPE_H_INCLUDED - -#include - -namespace TestOverlay -{ - -/** A peer in the overlay network. */ -template -class PeerType - : public Config -{ -public: - typedef typename Config::Peer Peer; - typedef typename Config::Payload Payload; - typedef typename Config::PeerLogic PeerLogic; - typedef typename Config::Message Message; - typedef typename Config::Network Network; - typedef typename Config::State State; - typedef typename State::UniqueID UniqueID; - typedef ConnectionType Connection; - typedef std::vector Connections; - - typedef hash_set MessageTable; - - explicit PeerType (Network& network) - : m_network (network) - , m_id (network.state().nextPeerID()) - , m_logic (*this) - { - } - - PeerType (PeerType const&) = delete; - PeerType& operator= (PeerType const&) = delete; - - /** Return the pending Results data associated with this peer. */ - /** @{ */ - Results& results () - { - return m_results; - } - - Results const& results () const - { - return m_results; - } - /** @} */ - - /** Return the unique ID associated with this peer. */ - UniqueID id () const - { - return m_id; - } - - /** Return the network this peer belongs to. */ - /** @{ */ - Network& network () - { - return m_network; - } - - Network const& network () const - { - return m_network; - } - /** @} */ - - /** Return the container holding active connections. */ - /** @{ */ - Connections& connections () - { - return m_connections; - } - - Connections const& connections () const - { - return m_connections; - } - /** @} */ - - /** Return the container holding the message ids seen by this peer. */ - /** @{ */ - MessageTable& msg_table () - { - return m_msg_table; - } - - MessageTable const& msg_table () const - { - return m_msg_table; - } - /** @} */ - - /** Establish an outgoing connection to peer. - @return `true` if the peer is not us and not connected already. - */ - bool connect_to (Peer& peer) - { - if (&peer == this) - return false; - typename Connections::iterator const iter (std::find_if ( - connections().begin(), connections().end (), - typename Connection::IsPeer (peer))); - if (iter != connections().end()) - return false; - assert (std::find_if (peer.connections().begin(), - peer.connections().end(), - typename Connection::IsPeer (*this)) - == peer.connections().end ()); - connections().push_back (Connection (peer, false)); - peer.connections().push_back (Connection (*this, true)); - return true; - } - - /** Disconnect from a peer. - @return `true` if the peer was found and disconnected. - */ - bool disconnect (Peer& peer) - { - if (&peer == this) - return false; - typename Connections::iterator const iter1 (std::find_if ( - connections().begin(), connections().end (), - typename Connection::IsPeer (peer))); - if (iter1 == connections().end()) - return false; - typename Connections::iterator const iter2 (std::find_if ( - peer.connections().begin(), peer.connections().end (), - typename Connection::IsPeer (*this))); - assert (iter2 != peer.connections().end()); - connections().erase (iter1); - peer.connections().erase (iter2); - return true; - } - - //-------------------------------------------------------------------------- - - /** Send a new message to a specific connection. - A new message with an unused id is created with the given payload. - */ - void send (Peer& peer, Payload const& payload) - { - Message const m (network().state().nextMessageID(), payload); - assert (msg_table().insert (m.id()).second); - assert (send_to (peer, - Message (network().state().nextMessageID(), - payload))); - } - - /** Send a message to a specific connection. - The message already has an id and associated payload. - */ - bool send (Peer& peer, Message const& m) - { - return send_to (peer, m); - } - - /** Send a new message to all connections. - A new message with an unused id is created with the given payload. - */ - void send_all (Payload const& payload) - { - Message const m (network().state().nextMessageID(), payload); - assert (msg_table().insert (m.id()).second); - assert (send_all_if (m, - typename Connection::Any ())); - }; - - /** Send a message to all connections. - The message already has an id and associated payload. - */ - bool send_all (Message const& m) - { - return send_all_if (m, - typename Connection::Any ()); - }; - - /** Create a new message and send it to each connection that passes the predicate. - Predicate is a UnaryPredicate that takes a Connection parameter. - A new message with an unused id is created with the given payload. - */ - template - void send_all_if (Payload const& payload, Predicate p) - { - Message const m (network().state().nextMessageID(), payload); - assert (msg_table().insert (m.id()).second); - assert (send_all_if (m, p)); - } - - /** Send an existing message to all connections that pass the predicate. - @return `true` if at least one message was sent. - */ - template - bool send_all_if (Message const& m, Predicate p) - { - bool sent = false; - for (typename Connections::iterator iter (connections().begin()); - iter != connections().end(); ++iter) - if (p (*iter)) - sent = send_to (iter->peer(), m) || sent; - return sent; - } - -private: - // Low level send function, everything goes through this. - // Returns true if the message was sent. - // - bool send_to (Peer& peer, Message const& m) - { - // already seen it? - if (peer.msg_table().count(m.id()) != 0) - { - ++results().dropped; - return false; - } - typename Connections::iterator const iter (std::find_if ( - peer.connections().begin(), peer.connections().end (), - typename Connection::IsPeer (*this))); - assert (iter != peer.connections().end()); - assert (peer.msg_table().insert(m.id()).second); - iter->pending().push_back (m); - ++results().sent; - return true; - } - -public: - //-------------------------------------------------------------------------- - - /** Called once on each Peer object before every iteration. */ - void pre_step () - { - m_logic.pre_step (); - } - - /** Called once on each Peer object during every iteration. */ - void step () - { - // Call logic with current messages - for (typename Connections::iterator iter (connections().begin()); - iter != connections().end(); ++iter) - { - Connection& c (*iter); - for (typename Connection::Messages::iterator iter ( - c.messages().begin()); iter != c.messages().end(); ++iter) - { - Message const& m (*iter); - assert (msg_table().count (m.id()) == 1); - m_logic.receive (c, m); - ++results().received; - } - } - - m_logic.step (); - } - - /** Called once on each Peer object after every iteration. */ - void post_step () - { - // Move pending messages to current messages - for (typename Connections::iterator iter (connections().begin()); - iter != connections().end(); ++iter) - { - Connection& c (*iter); - c.messages().clear (); - c.messages().swap (c.pending()); - } - - m_logic.post_step (); - } - -private: - Results m_results; - Network& m_network; - UniqueID const m_id; - Connections m_connections; - MessageTable m_msg_table; - PeerLogic m_logic; // must come last -}; - -} - -#endif diff --git a/src/ripple/testoverlay/api/StateBase.h b/src/ripple/testoverlay/api/StateBase.h deleted file mode 100644 index 81610b5beb..0000000000 --- a/src/ripple/testoverlay/api/StateBase.h +++ /dev/null @@ -1,66 +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_TESTOVERLAY_STATEBASE_H_INCLUDED -#define RIPPLE_TESTOVERLAY_STATEBASE_H_INCLUDED - -namespace TestOverlay -{ - -/* Base class for state information used by test objects. */ -template -class StateBase -{ -public: - // Identifies messages and peers. - // Always starts at 1 and increases incrementally. - // - typedef std::uint64_t UniqueID; - - StateBase () - : m_random (Params::randomSeedValue) - , m_peerID (0) - , m_messageID (0) - { - } - - beast::Random& random () - { - return m_random; - } - - UniqueID nextPeerID () - { - return ++m_peerID; - } - - UniqueID nextMessageID () - { - return ++m_messageID; - } - -private: - beast::Random m_random; - UniqueID m_peerID; - UniqueID m_messageID; -}; - -} - -#endif diff --git a/src/ripple/unity/testoverlay.cpp b/src/ripple/unity/testoverlay.cpp deleted file mode 100644 index 69091bcc57..0000000000 --- a/src/ripple/unity/testoverlay.cpp +++ /dev/null @@ -1,24 +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. -*/ -//============================================================================== - -#include - -#include - -#include diff --git a/src/ripple/unity/testoverlay.h b/src/ripple/unity/testoverlay.h deleted file mode 100644 index 3b27cbf74c..0000000000 --- a/src/ripple/unity/testoverlay.h +++ /dev/null @@ -1,53 +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_TESTOVERLAY_H_INCLUDED -#define RIPPLE_TESTOVERLAY_H_INCLUDED - -#include -#include -#include - -/** Provides a template based peer to peer network simulator. - - A TestOverlay::Network simulates an entire peer to peer network. - It provides peer connectivity and message passing services, while - allowing domain specific customization through user provided types. - - This system is designed to allow business logic to be exercised - in unit tests, using a simulated large scale network. -*/ - -namespace ripple -{ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -} - -#endif diff --git a/src/ripple/unity/validators.cpp b/src/ripple/unity/validators.cpp index 3daa1fd027..c748368062 100644 --- a/src/ripple/unity/validators.cpp +++ b/src/ripple/unity/validators.cpp @@ -19,37 +19,6 @@ #include -#if 0 -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include // for unit test - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif - #include #include #include