Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured Overlay implementation #576

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions doc/rippled-example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@
# or Mac style end of lines. Blank lines and lines beginning with '#' are
# ignored. Undefined sections are reserved. No escapes are currently defined.
#
# Notation
#
# In this document a simple BNF notation is used. Angle brackets denote
# required elements, square brackets denote optional elements, and single
# quotes indicate string literals. A vertical bar separating 1 or more
# elements is a logical "or"; Any one of the elements may be chosen.
# Parenthesis are notational only, and used to group elements, they are not
# part of the syntax unless they appear in quotes. White space may always
# appear between elements, it has no effect on values.
#
# <key> A required identifier
# '=' The equals sign character
# | Logical "or"
# ( ) Used for grouping
#
#
# An identifier is a string of upper or lower case letters, digits, or
# underscores subject to the requirement that the first character of an
# identifier must be a letter. Identifiers are not case sensitive (but
# values may be).
#
# Some configuration sections contain key/value pairs. A line containing
# a key/value pair has this syntax:
#
# <identifier> '=' <value>
#
# Depending on the section and key, different value types are possible:
#
# <integer> A signed integer
# <unsigned> An unsigned integer
# <flag> A boolean. 1 = true/yes/on, 0 = false/no/off.
#
# Consult the documentation on the key in question to determine the possible
# value types.
#
#
#
#-------------------------------------------------------------------------------
Expand All @@ -60,6 +95,38 @@
#
#
#
# [overlay] EXPERIMENTAL
#
# This section is EXPERIMENTAL, and should not be
# present for production configuration settings.
#
# A set of key/value pair parameters to configure the overlay.
#
# auto_connect = 0 | 1
#
# When set, activates the autoconnect feature. This maintains outgoing
# connections using the PeerFinder algorithm.
#
# use_handshake = 0 | 1
#
# Use the new HTTP handshaking interface when making outgoing
# connections. Incoming HTTP connection handshakes are automatically
# detected and switched appropriately.
#
# become_superpeer = 'never' | 'always' | 'auto'
#
# Controls the selection of peer roles:
#
# 'never' Always handshake in the leaf role.
# 'always' Always handshake in the superpeer role.
# 'auto' Start as a leaf, promote to superpeer after
# passing capability check (default).
#
# Note that in the superpeer role, the IP and port will only be
# advertised by other peers if incoming connection tests are succesful.
#
#
#
# [ips]
#
# List of hostnames or ips where the Ripple protocol is served. For a starter
Expand Down
13 changes: 0 additions & 13 deletions src/BeastConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,6 @@
#define RIPPLE_SINGLE_IO_SERVICE_THREAD 0
#endif

/** Config: RIPPLE_STRUCTURED_OVERLAY_CLIENT
RIPPLE_STRUCTURED_OVERLAY_SERVER
Enables Structured Overlay support for the client or server roles.
This feature is currently in development:
https://ripplelabs.atlassian.net/browse/RIPD-157
*/
#ifndef RIPPLE_STRUCTURED_OVERLAY_CLIENT
#define RIPPLE_STRUCTURED_OVERLAY_CLIENT 0
#endif
#ifndef RIPPLE_STRUCTURED_OVERLAY_SERVER
#define RIPPLE_STRUCTURED_OVERLAY_SERVER 1
#endif

/** Config: RIPPLE_ASYNC_RPC_HANDLER
*/
#ifndef RIPPLE_ASYNC_RPC_HANDLER
Expand Down
35 changes: 35 additions & 0 deletions src/beast/beast/http/rfc2616.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#define BEAST_HTTP_RFC2616_H_INCLUDED

#include <algorithm>
#include <cctype>
#include <iterator>
#include <limits>
#include <string>
#include <utility>

Expand Down Expand Up @@ -230,6 +233,38 @@ for_each_element (FwdIter first, FwdIter last, Function func)
}
}

template <class UInt, class FwdIt>
std::pair <bool, UInt>
parse_uint (FwdIt first, FwdIt last)
{
static_assert(std::is_unsigned<UInt>::value,
"UInt must be unsigned");
std::pair <bool, UInt> result (false, 0);
if (first == last)
return result;
UInt const limit = std::numeric_limits <UInt>::max();
while (first != last)
{
typename std::iterator_traits <
FwdIt>::value_type const c = *first++;
if (c < '0' || c > '9')
return result;
unsigned const n = c - '0';
if (n > (limit - (10u * result.second)))
return result;
result.second = 10u * result.second + n;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks remarkably similar to something I saw recently in beast::detail::parseUnsigned.

}
result.first = true;
return result;
}

template <class UInt>
std::pair <bool, UInt>
parse_uint (std::string const& s)
{
return parse_uint <UInt> (s.begin(), s.end());
}

} // rfc2616

} // http
Expand Down
5 changes: 4 additions & 1 deletion src/ripple/overlay/Peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ class Peer
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
Expand Down
23 changes: 20 additions & 3 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ OverlayImpl::OverlayImpl (Stoppable& parent,
, m_resolver (resolver)
, m_nextShortId (0)
{
auto const& section = getConfig()["overlay"];
set (setup_.use_handshake, "use_handshake", section);
set (setup_.auto_connect, "auto_connect", section);
std::string promote;
set (promote, "become_superpeer", section);
if (promote == "never")
setup_.promote = Promote::never;
else if (promote == "always")
setup_.promote = Promote::always;
else
setup_.promote = Promote::automatic;
}

OverlayImpl::~OverlayImpl ()
Expand All @@ -87,6 +98,12 @@ OverlayImpl::~OverlayImpl ()
return this->m_child_count == 0; });
}

OverlayImpl::Setup const&
OverlayImpl::setup() const
{
return setup_;
}

void
OverlayImpl::accept (bool proxyHandshake, socket_type&& socket)
{
Expand Down Expand Up @@ -535,10 +552,10 @@ OverlayImpl::getActivePeers ()

ret.reserve (m_publicKeyMap.size ());

BOOST_FOREACH (PeerByPublicKey::value_type const& pair, m_publicKeyMap)
for (auto const& e : m_publicKeyMap)
{
assert (pair.second);
ret.push_back (pair.second);
assert (e.second);
ret.push_back (e.second);
}

return ret;
Expand Down
21 changes: 20 additions & 1 deletion src/ripple/overlay/impl/OverlayImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,31 @@ class OverlayImpl
, public PeerFinder::Callback
{
private:
enum class Promote
{
automatic,
never,
always
};

struct Setup
{
bool use_handshake = false;
bool auto_connect = true;
Promote promote = Promote::automatic;
};

typedef boost::asio::ip::tcp::socket socket_type;

typedef hash_map <PeerFinder::Slot::ptr,
std::weak_ptr <PeerImp>> PeersBySlot;
std::weak_ptr <PeerImp>> PeersBySlot;

typedef hash_map <RippleAddress, Peer::ptr> PeerByPublicKey;

typedef hash_map <Peer::ShortId, Peer::ptr> PeerByShortId;

Setup setup_;

std::recursive_mutex m_mutex;

// Blocks us until dependent objects have been destroyed
Expand Down Expand Up @@ -111,6 +127,9 @@ class OverlayImpl
OverlayImpl (OverlayImpl const&) = delete;
OverlayImpl& operator= (OverlayImpl const&) = delete;

Setup const&
setup() const;

void
connect (beast::IP::Endpoint const& remote_endpoint) override;

Expand Down
Loading