diff --git a/doc/rippled-example.cfg b/doc/rippled-example.cfg index e92d2ffc5..182192b15 100644 --- a/doc/rippled-example.cfg +++ b/doc/rippled-example.cfg @@ -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. +# +# 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: +# +# '=' +# +# Depending on the section and key, different value types are possible: +# +# A signed integer +# An unsigned integer +# A boolean. 1 = true/yes/on, 0 = false/no/off. +# +# Consult the documentation on the key in question to determine the possible +# value types. +# # # #------------------------------------------------------------------------------- @@ -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 diff --git a/src/BeastConfig.h b/src/BeastConfig.h index bf71a0bd1..12d408450 100644 --- a/src/BeastConfig.h +++ b/src/BeastConfig.h @@ -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 diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index 54773b7d9..da48a5c24 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -71,6 +71,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 () @@ -83,6 +94,12 @@ OverlayImpl::~OverlayImpl () return this->m_child_count == 0; }); } +OverlayImpl::Setup const& +OverlayImpl::setup() const +{ + return setup_; +} + void OverlayImpl::accept (socket_type&& socket) { @@ -436,10 +453,10 @@ OverlayImpl::getActivePeers () ret.reserve (m_publicKeyMap.size ()); - for (auto 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; diff --git a/src/ripple/overlay/impl/OverlayImpl.h b/src/ripple/overlay/impl/OverlayImpl.h index 9f40aaf36..c4a0f6657 100644 --- a/src/ripple/overlay/impl/OverlayImpl.h +++ b/src/ripple/overlay/impl/OverlayImpl.h @@ -52,13 +52,29 @@ private: using error_code = boost::system::error_code; using yield_context = boost::asio::yield_context; + enum class Promote + { + automatic, + never, + always + }; + + struct Setup + { + bool use_handshake = false; + bool auto_connect = true; + Promote promote = Promote::automatic; + }; + typedef hash_map > PeersBySlot; + std::weak_ptr > PeersBySlot; typedef hash_map PeerByPublicKey; typedef hash_map PeerByShortId; + Setup setup_; + // VFALCO TODO Change to regular mutex and eliminate re-entrancy std::recursive_mutex m_mutex; @@ -114,6 +130,9 @@ public: OverlayImpl (OverlayImpl const&) = delete; OverlayImpl& operator= (OverlayImpl const&) = delete; + Setup const& + setup() const; + void connect (beast::IP::Endpoint const& remote_endpoint) override;