Clean up Overlay and PeerFinder sources:

* Tidy up identifiers and declarations
* Merge PeerFinder headers into one file
* Merge handout classes and functions into one file
This commit is contained in:
Vinnie Falco
2014-08-28 14:57:40 -07:00
parent db03ce939c
commit 5f59282ba1
28 changed files with 1837 additions and 1931 deletions

View File

@@ -2832,12 +2832,6 @@
<ClCompile Include="..\..\src\ripple\overlay\tests\peer_info.test.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\Callback.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\Config.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\Endpoint.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Bootcache.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
@@ -2853,11 +2847,6 @@
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Config.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\ConnectHandouts.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\ConnectHandouts.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Counts.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Endpoint.cpp">
@@ -2865,7 +2854,7 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Fixed.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\handout.h">
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Handouts.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\iosformat.h">
</ClInclude>
@@ -2879,18 +2868,8 @@
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Manager.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\RedirectHandouts.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\RedirectHandouts.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Reporting.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\SlotHandouts.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\SlotHandouts.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\SlotImp.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
@@ -2932,8 +2911,6 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\Slot.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\Types.h">
</ClInclude>
<CustomBuild Include="..\..\src\ripple\proto\ripple.proto">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='debug|x64'">protoc --cpp_out=..\..\build\proto --proto_path=%(RelativeDir) %(Identity)</Command>

View File

@@ -3978,15 +3978,6 @@
<ClCompile Include="..\..\src\ripple\overlay\tests\peer_info.test.cpp">
<Filter>ripple\overlay\tests</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\Callback.h">
<Filter>ripple\peerfinder</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\Config.h">
<Filter>ripple\peerfinder</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\Endpoint.h">
<Filter>ripple\peerfinder</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Bootcache.cpp">
<Filter>ripple\peerfinder\impl</Filter>
</ClCompile>
@@ -4005,12 +3996,6 @@
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Config.cpp">
<Filter>ripple\peerfinder\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\ConnectHandouts.cpp">
<Filter>ripple\peerfinder\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\ConnectHandouts.h">
<Filter>ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Counts.h">
<Filter>ripple\peerfinder\impl</Filter>
</ClInclude>
@@ -4020,7 +4005,7 @@
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Fixed.h">
<Filter>ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\handout.h">
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Handouts.h">
<Filter>ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\iosformat.h">
@@ -4038,21 +4023,9 @@
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Manager.cpp">
<Filter>ripple\peerfinder\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\RedirectHandouts.cpp">
<Filter>ripple\peerfinder\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\RedirectHandouts.h">
<Filter>ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Reporting.h">
<Filter>ripple\peerfinder\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\SlotHandouts.cpp">
<Filter>ripple\peerfinder\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\SlotHandouts.h">
<Filter>ripple\peerfinder\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\SlotImp.cpp">
<Filter>ripple\peerfinder\impl</Filter>
</ClCompile>
@@ -4110,9 +4083,6 @@
<ClInclude Include="..\..\src\ripple\peerfinder\Slot.h">
<Filter>ripple\peerfinder</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\Types.h">
<Filter>ripple\peerfinder</Filter>
</ClInclude>
<CustomBuild Include="..\..\src\ripple\proto\ripple.proto">
<Filter>ripple\proto</Filter>
</CustomBuild>

View File

@@ -60,8 +60,11 @@ public:
virtual ShortId getShortId () const = 0;
virtual RippleAddress const& getNodePublic () const = 0;
virtual Json::Value json () = 0;
// VFALCO TODO Replace both with
// boost::optional<std::string> const& cluster_id();
//
virtual bool isInCluster () const = 0;
virtual std::string getClusterNodeName() const = 0;
virtual std::string const& getClusterNodeName() const = 0;
//
// Ledger

View File

@@ -539,7 +539,7 @@ OverlayImpl::getActivePeers ()
ret.reserve (m_publicKeyMap.size ());
BOOST_FOREACH (PeerByPublicKey::value_type const& pair, m_publicKeyMap)
for (auto const& pair : m_publicKeyMap)
{
assert (pair.second);
ret.push_back (pair.second);

View File

@@ -25,7 +25,6 @@
#include <ripple/common/Resolver.h>
#include <ripple/common/seconds_clock.h>
#include <ripple/common/UnorderedContainers.h>
#include <ripple/peerfinder/Callback.h>
#include <ripple/peerfinder/Manager.h>
#include <ripple/resource/api/Manager.h>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,54 +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_PEERFINDER_CALLBACK_H_INCLUDED
#define RIPPLE_PEERFINDER_CALLBACK_H_INCLUDED
#include <ripple/peerfinder/Slot.h>
#include <ripple/peerfinder/Types.h>
namespace ripple {
namespace PeerFinder {
/** The Callback receives PeerFinder notifications.
The notifications are sent on a thread owned by the PeerFinder,
so it is best not to do too much work in here. Just post functor
to another worker thread or job queue and return.
*/
struct Callback
{
/** Initiate outgoing Peer connections to the specified set of endpoints. */
virtual void connect (IPAddresses const& addresses) = 0;
/** Activate the handshaked peer with the specified address. */
virtual void activate (Slot::ptr const& slot) = 0;
/** Sends a set of Endpoint records to the specified peer. */
virtual void send (Slot::ptr const& slot, Endpoints const& endpoints) = 0;
/** Disconnect the handshaked peer with the specified address.
@param graceful `true` to wait for send buffers to drain before closing.
*/
virtual void disconnect (Slot::ptr const& slot, bool graceful) = 0;
};
}
}
#endif

View File

@@ -1,77 +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_PEERFINDER_CONFIG_H_INCLUDED
#define RIPPLE_PEERFINDER_CONFIG_H_INCLUDED
namespace ripple {
namespace PeerFinder {
/** PeerFinder configuration settings. */
struct Config
{
/** The largest number of public peer slots to allow.
This includes both inbound and outbound, but does not include
fixed peers.
*/
int maxPeers;
/** The number of automatic outbound connections to maintain.
Outbound connections are only maintained if autoConnect
is `true`. The value can be fractional; The decision to round up
or down will be made using a per-process pseudorandom number and
a probability proportional to the fractional part.
Example:
If outPeers is 9.3, then 30% of nodes will maintain 9 outbound
connections, while 70% of nodes will maintain 10 outbound
connections.
*/
double outPeers;
/** `true` if we want to accept incoming connections. */
bool wantIncoming;
/** `true` if we want to establish connections automatically */
bool autoConnect;
/** The listening port number. */
std::uint16_t listeningPort;
/** The set of features we advertise. */
std::string features;
//--------------------------------------------------------------------------
/** Create a configuration with default values. */
Config ();
/** Returns a suitable value for outPeers according to the rules. */
double calcOutPeers () const;
/** Adjusts the values so they follow the business rules. */
void applyTuning ();
/** Write the configuration into a property stream */
void onWrite (beast::PropertyStream::Map& map);
};
}
}
#endif

View File

@@ -1,44 +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_PEERFINDER_ENDPOINT_H_INCLUDED
#define RIPPLE_PEERFINDER_ENDPOINT_H_INCLUDED
#include <beast/net/IPEndpoint.h>
namespace ripple {
namespace PeerFinder {
/** Describes a connectible peer address along with some metadata. */
struct Endpoint
{
Endpoint ();
Endpoint (beast::IP::Endpoint const& ep, int hops_);
int hops;
beast::IP::Endpoint address;
};
bool operator< (Endpoint const& lhs, Endpoint const& rhs);
} // namespace PeerFinder
} // namespace ripple
#endif

View File

@@ -20,16 +20,122 @@
#ifndef RIPPLE_PEERFINDER_MANAGER_H_INCLUDED
#define RIPPLE_PEERFINDER_MANAGER_H_INCLUDED
#include <ripple/peerfinder/Callback.h>
#include <ripple/peerfinder/Config.h>
#include <ripple/peerfinder/Slot.h>
#include <ripple/peerfinder/Types.h>
#include <ripple/sitefiles/api/Manager.h>
#include <beast/chrono/abstract_clock.h>
#include <beast/module/core/files/File.h>
namespace ripple {
namespace PeerFinder {
typedef beast::abstract_clock <std::chrono::seconds> clock_type;
/** Represents a set of addresses. */
typedef std::vector <beast::IP::Endpoint> IPAddresses;
//------------------------------------------------------------------------------
/** PeerFinder configuration settings. */
struct Config
{
/** The largest number of public peer slots to allow.
This includes both inbound and outbound, but does not include
fixed peers.
*/
int maxPeers;
/** The number of automatic outbound connections to maintain.
Outbound connections are only maintained if autoConnect
is `true`. The value can be fractional; The decision to round up
or down will be made using a per-process pseudorandom number and
a probability proportional to the fractional part.
Example:
If outPeers is 9.3, then 30% of nodes will maintain 9 outbound
connections, while 70% of nodes will maintain 10 outbound
connections.
*/
double outPeers;
/** `true` if we want to accept incoming connections. */
bool wantIncoming;
/** `true` if we want to establish connections automatically */
bool autoConnect;
/** The listening port number. */
std::uint16_t listeningPort;
/** The set of features we advertise. */
std::string features;
//--------------------------------------------------------------------------
/** Create a configuration with default values. */
Config ();
/** Returns a suitable value for outPeers according to the rules. */
double calcOutPeers () const;
/** Adjusts the values so they follow the business rules. */
void applyTuning ();
/** Write the configuration into a property stream */
void onWrite (beast::PropertyStream::Map& map);
};
//------------------------------------------------------------------------------
/** Describes a connectible peer address along with some metadata. */
struct Endpoint
{
Endpoint ();
Endpoint (beast::IP::Endpoint const& ep, int hops_);
int hops;
beast::IP::Endpoint address;
};
bool operator< (Endpoint const& lhs, Endpoint const& rhs);
/** A set of Endpoint used for connecting. */
typedef std::vector <Endpoint> Endpoints;
//------------------------------------------------------------------------------
/** The Callback receives PeerFinder notifications.
The notifications are sent on a thread owned by the PeerFinder,
so it is best not to do too much work in here. Just post functor
to another worker thread or job queue and return.
*/
// DEPRECATED Callbacks only cause re-entrancy pain
struct Callback
{
/** Initiate outgoing Peer connections to the specified set of endpoints. */
virtual void connect (IPAddresses const& addresses) = 0;
/** Activate the handshaked peer with the specified address. */
virtual void activate (Slot::ptr const& slot) = 0;
/** Sends a set of Endpoint records to the specified peer. */
virtual void send (Slot::ptr const& slot, Endpoints const& endpoints) = 0;
/** Disconnect the handshaked peer with the specified address.
@param graceful `true` to wait for send buffers to drain before closing.
*/
virtual void disconnect (Slot::ptr const& slot, bool graceful) = 0;
};
//------------------------------------------------------------------------------
/** Possible results from activating a slot. */
enum class Result
{
duplicate,
full,
success
};
/** Maintains a set of IP addresses used for getting into the network. */
class Manager
: public beast::Stoppable

View File

@@ -1,41 +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_PEERFINDER_TYPES_H_INCLUDED
#define RIPPLE_PEERFINDER_TYPES_H_INCLUDED
#include <ripple/peerfinder/Endpoint.h>
#include <beast/chrono/abstract_clock.h>
namespace ripple {
namespace PeerFinder {
/** Represents a set of addresses. */
typedef std::vector <beast::IP::Endpoint> IPAddresses;
/** A set of Endpoint used for connecting. */
typedef std::vector <Endpoint> Endpoints;
typedef beast::abstract_clock <std::chrono::seconds> clock_type;
}
}
#endif

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_PEERFINDER_BOOTCACHE_H_INCLUDED
#define RIPPLE_PEERFINDER_BOOTCACHE_H_INCLUDED
#include <ripple/peerfinder/Types.h>
#include <ripple/peerfinder/Manager.h>
#include <ripple/peerfinder/impl/Store.h>
#include <beast/utility/Journal.h>
#include <beast/utility/PropertyStream.h>

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/peerfinder/Config.h>
#include <ripple/peerfinder/Manager.h>
namespace ripple {
namespace PeerFinder {

View File

@@ -1,64 +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 <ripple/peerfinder/impl/ConnectHandouts.h>
namespace ripple {
namespace PeerFinder {
ConnectHandouts::ConnectHandouts (
std::size_t needed, Squelches& squelches)
: m_needed (needed)
, m_squelches (squelches)
{
m_list.reserve (needed);
}
bool
ConnectHandouts::try_insert (beast::IP::Endpoint const& endpoint)
{
if (full ())
return false;
// Make sure the address isn't already in our list
if (std::any_of (m_list.begin(), m_list.end(),
[&endpoint](beast::IP::Endpoint const& other)
{
// Ignore port for security reasons
return other.address() ==
endpoint.address();
}))
{
return false;
}
// Add to squelch list so we don't try it too often.
// If its already there, then make try_insert fail.
auto const result (m_squelches.insert (
endpoint.address()));
if (! result.second)
return false;
m_list.push_back (endpoint);
return true;
}
}
}

View File

@@ -1,79 +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_PEERFINDER_CONNECTHANDOUTS_H_INCLUDED
#define RIPPLE_PEERFINDER_CONNECTHANDOUTS_H_INCLUDED
#include <ripple/peerfinder/impl/Tuning.h>
#include <beast/container/aged_set.h>
namespace ripple {
namespace PeerFinder {
/** Receives handouts for making automatic connections. */
class ConnectHandouts
{
public:
// Keeps track of addresses we have made outgoing connections
// to, for the purposes of not connecting to them too frequently.
typedef beast::aged_set <beast::IP::Address> Squelches;
typedef std::vector <beast::IP::Endpoint> list_type;
private:
std::size_t m_needed;
Squelches& m_squelches;
list_type m_list;
public:
ConnectHandouts (std::size_t needed, Squelches& squelches);
bool empty() const
{
return m_list.empty();
}
bool full() const
{
return m_list.size() >= m_needed;
}
bool try_insert (Endpoint const& endpoint)
{
return try_insert (endpoint.address);
}
list_type& list()
{
return m_list;
}
list_type const& list() const
{
return m_list;
}
bool try_insert (beast::IP::Endpoint const& endpoint);
};
}
}
#endif

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_PEERFINDER_COUNTS_H_INCLUDED
#define RIPPLE_PEERFINDER_COUNTS_H_INCLUDED
#include <ripple/peerfinder/Config.h>
#include <ripple/peerfinder/Manager.h>
#include <ripple/peerfinder/Slot.h>
namespace ripple {

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/peerfinder/Endpoint.h>
#include <ripple/peerfinder/Manager.h>
namespace ripple {
namespace PeerFinder {

View File

@@ -0,0 +1,352 @@
//------------------------------------------------------------------------------
/*
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_PEERFINDER_HANDOUTS_H_INCLUDED
#define RIPPLE_PEERFINDER_HANDOUTS_H_INCLUDED
#include <ripple/peerfinder/impl/SlotImp.h>
#include <ripple/peerfinder/impl/Tuning.h>
#include <beast/container/aged_set.h>
#include <cassert>
#include <iterator>
#include <beast/cxx14/type_traits.h> // <type_traits>
namespace ripple {
namespace PeerFinder {
namespace detail {
/** Try to insert one object in the target.
When an item is handed out it is moved to the end of the container.
@return The number of objects inserted
*/
// VFALCO TODO specialization that handles std::list for SequenceContainer
// using splice for optimization over erase/push_back
//
template <class Target, class HopContainer>
std::size_t
handout_one (Target& t, HopContainer& h)
{
assert (! t.full());
for (auto it = h.begin(); it != h.end(); ++it)
{
auto const& e = *it;
if (t.try_insert (e))
{
h.move_back (it);
return 1;
}
}
return 0;
}
}
/** Distributes objects to targets according to business rules.
A best effort is made to evenly distribute items in the sequence
container list into the target sequence list.
*/
template <class TargetFwdIter, class SeqFwdIter>
void
handout (TargetFwdIter first, TargetFwdIter last,
SeqFwdIter seq_first, SeqFwdIter seq_last)
{
for (;;)
{
std::size_t n (0);
for (auto si = seq_first; si != seq_last; ++si)
{
auto c = *si;
bool all_full (true);
for (auto ti = first; ti != last; ++ti)
{
auto& t = *ti;
if (! t.full())
{
n += detail::handout_one (t, c);
all_full = false;
}
}
if (all_full)
return;
}
if (! n)
break;
}
}
//------------------------------------------------------------------------------
/** Receives handouts for redirecting a connection.
An incoming connection request is redirected when we are full on slots.
*/
class RedirectHandouts
{
public:
template <class = void>
explicit
RedirectHandouts (SlotImp::ptr const& slot);
template <class = void>
bool try_insert (Endpoint const& ep);
bool full () const
{
return list_.size() >= Tuning::redirectEndpointCount;
}
SlotImp::ptr const& slot () const
{
return slot_;
}
std::vector <Endpoint> const& list() const
{
return list_;
}
private:
SlotImp::ptr slot_;
std::vector <Endpoint> list_;
};
template <class>
RedirectHandouts::RedirectHandouts (SlotImp::ptr const& slot)
: slot_ (slot)
{
list_.reserve (Tuning::redirectEndpointCount);
}
template <class>
bool
RedirectHandouts::try_insert (Endpoint const& ep)
{
if (full ())
return false;
// VFALCO NOTE This check can be removed when we provide the
// addresses in a peer HTTP handshake instead of
// the tmENDPOINTS message.
//
if (ep.hops > Tuning::maxHops)
return false;
// Don't send them our address
if (ep.hops == 0)
return false;
// Don't send them their own address
if (slot_->remote_endpoint().address() ==
ep.address.address())
return false;
// Make sure the address isn't already in our list
if (std::any_of (list_.begin(), list_.end(),
[&ep](Endpoint const& other)
{
// Ignore port for security reasons
return other.address.address() == ep.address.address();
}))
{
return false;
}
list_.emplace_back (ep.address, ep.hops);
return true;
}
//------------------------------------------------------------------------------
/** Receives endpoints for a slot during periodic handouts. */
class SlotHandouts
{
public:
template <class = void>
explicit
SlotHandouts (SlotImp::ptr const& slot);
template <class = void>
bool try_insert (Endpoint const& ep);
bool full () const
{
return list_.size() >= Tuning::numberOfEndpoints;
}
void insert (Endpoint const& ep)
{
list_.push_back (ep);
}
SlotImp::ptr const& slot () const
{
return slot_;
}
std::vector <Endpoint> const& list() const
{
return list_;
}
private:
SlotImp::ptr slot_;
std::vector <Endpoint> list_;
};
template <class>
SlotHandouts::SlotHandouts (SlotImp::ptr const& slot)
: slot_ (slot)
{
list_.reserve (Tuning::numberOfEndpoints);
}
template <class>
bool
SlotHandouts::try_insert (Endpoint const& ep)
{
if (full ())
return false;
if (ep.hops > Tuning::maxHops)
return false;
if (slot_->recent.filter (ep.address, ep.hops))
return false;
// Don't send them their own address
if (slot_->remote_endpoint().address() ==
ep.address.address())
return false;
// Make sure the address isn't already in our list
if (std::any_of (list_.begin(), list_.end(),
[&ep](Endpoint const& other)
{
// Ignore port for security reasons
return other.address.address() == ep.address.address();
}))
return false;
list_.emplace_back (ep.address, ep.hops);
// Insert into this slot's recent table. Although the endpoint
// didn't come from the slot, adding it to the slot's table
// prevents us from sending it again until it has expired from
// the other end's cache.
//
slot_->recent.insert (ep.address, ep.hops);
return true;
}
//------------------------------------------------------------------------------
/** Receives handouts for making automatic connections. */
class ConnectHandouts
{
public:
// Keeps track of addresses we have made outgoing connections
// to, for the purposes of not connecting to them too frequently.
typedef beast::aged_set <beast::IP::Address> Squelches;
typedef std::vector <beast::IP::Endpoint> list_type;
private:
std::size_t m_needed;
Squelches& m_squelches;
list_type m_list;
public:
template <class = void>
ConnectHandouts (std::size_t needed, Squelches& squelches);
template <class = void>
bool try_insert (beast::IP::Endpoint const& endpoint);
bool empty() const
{
return m_list.empty();
}
bool full() const
{
return m_list.size() >= m_needed;
}
bool try_insert (Endpoint const& endpoint)
{
return try_insert (endpoint.address);
}
list_type& list()
{
return m_list;
}
list_type const& list() const
{
return m_list;
}
};
template <class>
ConnectHandouts::ConnectHandouts (
std::size_t needed, Squelches& squelches)
: m_needed (needed)
, m_squelches (squelches)
{
m_list.reserve (needed);
}
template <class>
bool
ConnectHandouts::try_insert (beast::IP::Endpoint const& endpoint)
{
if (full ())
return false;
// Make sure the address isn't already in our list
if (std::any_of (m_list.begin(), m_list.end(),
[&endpoint](beast::IP::Endpoint const& other)
{
// Ignore port for security reasons
return other.address() ==
endpoint.address();
}))
{
return false;
}
// Add to squelch list so we don't try it too often.
// If its already there, then make try_insert fail.
auto const result (m_squelches.insert (
endpoint.address()));
if (! result.second)
return false;
m_list.push_back (endpoint);
return true;
}
}
}
#endif

View File

@@ -20,8 +20,7 @@
#ifndef RIPPLE_PEERFINDER_LIVECACHE_H_INCLUDED
#define RIPPLE_PEERFINDER_LIVECACHE_H_INCLUDED
#include <ripple/peerfinder/Endpoint.h>
#include <ripple/peerfinder/Types.h>
#include <ripple/peerfinder/Manager.h>
#include <beast/chrono/chrono_io.h>
#include <beast/container/aged_map.h>
#include <beast/utility/maybe_const.h>

View File

@@ -20,15 +20,12 @@
#ifndef RIPPLE_PEERFINDER_LOGIC_H_INCLUDED
#define RIPPLE_PEERFINDER_LOGIC_H_INCLUDED
#include <ripple/peerfinder/Callback.h>
#include <ripple/peerfinder/impl/ConnectHandouts.h>
#include <ripple/peerfinder/Manager.h>
#include <ripple/peerfinder/impl/Counts.h>
#include <ripple/peerfinder/impl/Fixed.h>
#include <ripple/peerfinder/impl/handout.h>
#include <ripple/peerfinder/impl/iosformat.h>
#include <ripple/peerfinder/impl/RedirectHandouts.h>
#include <ripple/peerfinder/impl/Handouts.h>
#include <ripple/peerfinder/impl/Reporting.h>
#include <ripple/peerfinder/impl/SlotHandouts.h>
#include <ripple/peerfinder/impl/SlotImp.h>
#include <ripple/peerfinder/impl/Source.h>

View File

@@ -1,70 +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 <ripple/peerfinder/impl/RedirectHandouts.h>
namespace ripple {
namespace PeerFinder {
RedirectHandouts::RedirectHandouts (SlotImp::ptr const& slot)
: m_slot (slot)
{
m_list.reserve (Tuning::redirectEndpointCount);
}
bool
RedirectHandouts::try_insert (Endpoint const& ep)
{
if (full ())
return false;
// VFALCO NOTE This check can be removed when we provide the
// addresses in a peer HTTP handshake instead of
// the tmENDPOINTS message.
//
if (ep.hops > Tuning::maxHops)
return false;
// Don't send them our address
if (ep.hops == 0)
return false;
// Don't send them their own address
if (m_slot->remote_endpoint().address() ==
ep.address.address())
return false;
// Make sure the address isn't already in our list
if (std::any_of (m_list.begin(), m_list.end(),
[&ep](Endpoint const& other)
{
// Ignore port for security reasons
return other.address.address() == ep.address.address();
}))
{
return false;
}
m_list.emplace_back (ep.address, ep.hops);
return true;
}
}
}

View File

@@ -1,62 +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_PEERFINDER_REDIRECTHANDOUTS_H_INCLUDED
#define RIPPLE_PEERFINDER_REDIRECTHANDOUTS_H_INCLUDED
#include <ripple/peerfinder/impl/SlotImp.h>
#include <ripple/peerfinder/impl/Tuning.h>
namespace ripple {
namespace PeerFinder {
/** Receives handouts for redirecting a connection.
An incoming connection request is redirected when we are full on slots.
*/
class RedirectHandouts
{
public:
RedirectHandouts (SlotImp::ptr const& slot);
bool full () const
{
return m_list.size() >= Tuning::redirectEndpointCount;
}
SlotImp::ptr const& slot () const
{
return m_slot;
}
std::vector <Endpoint> const& list() const
{
return m_list;
}
bool try_insert (Endpoint const& ep);
private:
SlotImp::ptr m_slot;
std::vector <Endpoint> m_list;
};
}
}
#endif

View File

@@ -1,70 +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 <ripple/peerfinder/impl/SlotHandouts.h>
namespace ripple {
namespace PeerFinder {
SlotHandouts::SlotHandouts (SlotImp::ptr const& slot)
: m_slot (slot)
{
m_list.reserve (Tuning::numberOfEndpoints);
}
bool
SlotHandouts::try_insert (Endpoint const& ep)
{
if (full ())
return false;
if (ep.hops > Tuning::maxHops)
return false;
if (m_slot->recent.filter (ep.address, ep.hops))
return false;
// Don't send them their own address
if (m_slot->remote_endpoint().address() ==
ep.address.address())
return false;
// Make sure the address isn't already in our list
if (std::any_of (m_list.begin(), m_list.end(),
[&ep](Endpoint const& other)
{
// Ignore port for security reasons
return other.address.address() == ep.address.address();
}))
return false;
m_list.emplace_back (ep.address, ep.hops);
// Insert into this slot's recent table. Although the endpoint
// didn't come from the slot, adding it to the slot's table
// prevents us from sending it again until it has expired from
// the other end's cache.
//
m_slot->recent.insert (ep.address, ep.hops);
return true;
}
}
}

View File

@@ -1,65 +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_PEERFINDER_SLOTHANDOUTS_H_INCLUDED
#define RIPPLE_PEERFINDER_SLOTHANDOUTS_H_INCLUDED
#include <ripple/peerfinder/impl/SlotImp.h>
#include <ripple/peerfinder/impl/Tuning.h>
namespace ripple {
namespace PeerFinder {
/** Functor to receive endpoints for a slot during handout. */
class SlotHandouts
{
public:
explicit SlotHandouts (SlotImp::ptr const& slot);
bool full () const
{
return m_list.size() >= Tuning::numberOfEndpoints;
}
void insert (Endpoint const& ep)
{
m_list.push_back (ep);
}
SlotImp::ptr const& slot () const
{
return m_slot;
}
std::vector <Endpoint> const& list() const
{
return m_list;
}
bool try_insert (Endpoint const& ep);
private:
SlotImp::ptr m_slot;
std::vector <Endpoint> m_list;
};
}
}
#endif

View File

@@ -1,88 +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_PEERFINDER_HANDOUT_H_INCLUDED
#define RIPPLE_PEERFINDER_HANDOUT_H_INCLUDED
namespace ripple {
namespace PeerFinder {
namespace detail {
/** Tries to insert one object in the target.
When an item is handed out it is moved to the end of the container.
@return The number of objects handed out
*/
// VFALCO TODO specialization that handles std::list for SequenceContainer
// using splice for optimization over erase/push_back
//
template <class Target, class HopContainer>
std::size_t handout_one (Target& t, HopContainer& h)
{
assert (! t.full());
for (auto hi (h.begin()); hi != h.end(); ++hi)
{
auto const& e (*hi);
if (t.try_insert (e))
{
h.move_back (hi);
return 1;
}
}
return 0;
}
}
/** Distributes objects to targets according to business rules.
A best effort is made to evenly distribute items in the sequence
container list into the target sequence list.
*/
template <class TargetFwdIter, class SeqFwdIter>
void handout (TargetFwdIter first, TargetFwdIter last,
SeqFwdIter seq_first, SeqFwdIter seq_last)
{
for (;;)
{
std::size_t n (0);
for (auto si (seq_first); si != seq_last; ++si)
{
auto c (*si);
bool all_full (true);
for (auto ti (first); ti != last; ++ti)
{
auto& t (*ti);
if (! t.full())
{
n += detail::handout_one (t, c);
all_full = false;
}
}
if (all_full)
return;
}
if (! n)
break;
}
}
}
}
#endif

View File

@@ -32,6 +32,11 @@ enum MessageType
// token, response = give solution to proof of work
// token, result = report result of pow
//------------------------------------------------------------------------------
/* Requests or responds to a proof of work.
Unimplemented and unused currently.
*/
message TMProofWork
{
required string token = 1;
@@ -52,6 +57,8 @@ message TMProofWork
optional PowResult result = 6;
}
//------------------------------------------------------------------------------
// Sent on connect
message TMHello
{

View File

@@ -28,12 +28,9 @@
#include <ripple/peerfinder/impl/Bootcache.cpp>
#include <ripple/peerfinder/impl/Checker.cpp>
#include <ripple/peerfinder/impl/Config.cpp>
#include <ripple/peerfinder/impl/ConnectHandouts.cpp>
#include <ripple/peerfinder/impl/Endpoint.cpp>
#include <ripple/peerfinder/impl/Livecache.cpp>
#include <ripple/peerfinder/impl/Manager.cpp>
#include <ripple/peerfinder/impl/RedirectHandouts.cpp>
#include <ripple/peerfinder/impl/SlotHandouts.cpp>
#include <ripple/peerfinder/impl/SlotImp.cpp>
#include <ripple/peerfinder/impl/SourceStrings.cpp>