Remove unused testoverlay module

This commit is contained in:
Vinnie Falco
2014-10-01 08:10:02 -07:00
parent dbd993ed2b
commit 6c072f37ef
16 changed files with 0 additions and 1213 deletions

View File

@@ -3279,29 +3279,6 @@
<ClCompile Include="..\..\src\ripple\sslutil\impl\ECDSACanonical.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\testoverlay\api\ConfigType.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\ConnectionType.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\InitPolicy.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\MessageType.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\NetworkType.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\PeerLogicBase.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\PeerType.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\Results.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\SimplePayload.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\StateBase.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\testoverlay\impl\TestOverlay.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\types\AgedHistory.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\Base58.h">
@@ -3465,10 +3442,6 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\unity\sslutil.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\unity\testoverlay.cpp">
</ClCompile>
<ClInclude Include="..\..\src\ripple\unity\testoverlay.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\unity\types.cpp">
</ClCompile>
<ClInclude Include="..\..\src\ripple\unity\types.h">

View File

@@ -469,15 +469,6 @@
<Filter Include="ripple\sslutil\impl">
<UniqueIdentifier>{55CFEEC5-7FF5-F959-9862-9FAE232054B7}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\testoverlay">
<UniqueIdentifier>{48C2C255-35B5-AA2C-B105-0F34A4D0347D}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\testoverlay\api">
<UniqueIdentifier>{3C72B4D4-96EE-300D-795F-8FB6126FAEFD}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\testoverlay\impl">
<UniqueIdentifier>{B0FE6BBC-BDC6-E3A4-E670-C026AB04DABE}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\types">
<UniqueIdentifier>{29DBD04F-9324-A965-5C79-AA06EC10BA58}</UniqueIdentifier>
</Filter>
@@ -4497,39 +4488,6 @@
<ClCompile Include="..\..\src\ripple\sslutil\impl\ECDSACanonical.cpp">
<Filter>ripple\sslutil\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\testoverlay\api\ConfigType.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\ConnectionType.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\InitPolicy.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\MessageType.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\NetworkType.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\PeerLogicBase.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\PeerType.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\Results.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\SimplePayload.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\testoverlay\api\StateBase.h">
<Filter>ripple\testoverlay\api</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\testoverlay\impl\TestOverlay.cpp">
<Filter>ripple\testoverlay\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\types\AgedHistory.h">
<Filter>ripple\types</Filter>
</ClInclude>
@@ -4749,12 +4707,6 @@
<ClInclude Include="..\..\src\ripple\unity\sslutil.h">
<Filter>ripple\unity</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\unity\testoverlay.cpp">
<Filter>ripple\unity</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\unity\testoverlay.h">
<Filter>ripple\unity</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\unity\types.cpp">
<Filter>ripple\unity</Filter>
</ClCompile>

View File

@@ -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))

View File

@@ -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.

View File

@@ -1,6 +0,0 @@
# TestOverlay TODO
- Add documentation
- Fix the templates to be sane, use derivation and virtual instead of
compile time polymorphism

View File

@@ -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> class StateType = StateBase,
template <class> 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 <Params> State;
typedef MessageType <Params> Message;
typedef NetworkType <Params> Network;
typedef PeerType <Params> Peer;
typedef PeerLogicType <Params> PeerLogic;
typedef NoInitPolicy InitPolicy;
};
}
#endif

View File

@@ -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 <ripple/common/UnorderedContainers.h>
namespace ripple {
namespace TestOverlay
{
/** A connection between two nodes. */
template <class Config>
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 <Message> Messages;
typedef hash_set <UniqueID> 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

View File

@@ -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 <class Network>
void operator() (Network& network)
{
}
};
//------------------------------------------------------------------------------
/** Init policy for a pre-built connected network. */
template <int NumberOfPeers,
int OutgoingConnectionsPerPeer>
class PremadeInitPolicy
{
public:
static int const numberOfPeers = NumberOfPeers;
static int const outgoingConnectionsPerPeer = OutgoingConnectionsPerPeer;
template <class Network>
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

View File

@@ -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 Config>
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

View File

@@ -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 ConfigParam>
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 <std::unique_ptr <Peer> > 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> (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 <class Predicate>
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

View File

@@ -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 Config>
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

View File

@@ -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 <cassert>
namespace TestOverlay
{
/** A peer in the overlay network. */
template <class Config>
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 <Config> Connection;
typedef std::vector <Connection> Connections;
typedef hash_set <UniqueID> 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 <class Predicate>
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 <class Predicate>
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

View File

@@ -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 Params>
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

View File

@@ -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 <BeastConfig.h>
#include <ripple/unity/testoverlay.h>
#include <ripple/testoverlay/impl/TestOverlay.cpp>

View File

@@ -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 <memory>
#include <beast/strings/String.h>
#include <beast/module/core/maths/Random.h>
/** 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 <ripple/testoverlay/api/Results.h>
#include <ripple/testoverlay/api/SimplePayload.h>
#include <ripple/testoverlay/api/MessageType.h>
#include <ripple/testoverlay/api/ConnectionType.h>
#include <ripple/testoverlay/api/PeerType.h>
#include <ripple/testoverlay/api/NetworkType.h>
#include <ripple/testoverlay/api/StateBase.h>
#include <ripple/testoverlay/api/PeerLogicBase.h>
#include <ripple/testoverlay/api/InitPolicy.h>
#include <ripple/testoverlay/api/ConfigType.h>
}
#endif

View File

@@ -19,37 +19,6 @@
#include <BeastConfig.h>
#if 0
#include <ripple/unity/validators.h>
#include <boost/regex.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/key_extractors.hpp>
#include <set>
#include <beast/threads/ScopedWrapperContext.h>
#include <beast/module/asio/asio.h>
#include <beast/module/sqdb/sqdb.h>
#include <ripple/unity/testoverlay.h> // for unit test
#include <ripple/validators/impl/Tuning.h>
#include <ripple/validators/impl/ChosenList.h>
#include <ripple/validators/impl/Count.h>
#include <ripple/validators/impl/SourceFile.h>
#include <ripple/validators/impl/SourceStrings.h>
#include <ripple/validators/impl/SourceURL.h>
#include <ripple/validators/impl/SourceDesc.h>
#include <ripple/validators/impl/Store.h>
#include <ripple/validators/impl/StoreSqdb.h>
#include <ripple/validators/impl/Utilities.h>
#include <ripple/validators/impl/Validation.h>
#include <ripple/validators/impl/Validator.h>
#include <ripple/validators/impl/Logic.h>
#endif
#include <ripple/validators/impl/Manager.cpp>
#include <ripple/validators/impl/Source.cpp>
#include <ripple/validators/impl/SourceFile.cpp>