From 2a97bd384888b8954fe52740fabca4483446443b Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Sat, 12 Dec 2015 01:44:25 -0800 Subject: [PATCH] Do not open peer port in standalone mode --- src/ripple/server/ServerHandler.h | 5 +- src/ripple/server/impl/ServerHandlerImp.cpp | 54 ++++++++++++++++----- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/ripple/server/ServerHandler.h b/src/ripple/server/ServerHandler.h index 2b92d7991..603d3b6d4 100644 --- a/src/ripple/server/ServerHandler.h +++ b/src/ripple/server/ServerHandler.h @@ -21,6 +21,7 @@ #define RIPPLE_SERVER_SERVERHANDLER_H_INCLUDED #include +#include #include #include #include @@ -96,7 +97,9 @@ public: //------------------------------------------------------------------------------ ServerHandler::Setup -setup_ServerHandler (BasicConfig const& c, std::ostream& log); +setup_ServerHandler ( + Config const& c, + std::ostream& log); } // ripple diff --git a/src/ripple/server/impl/ServerHandlerImp.cpp b/src/ripple/server/impl/ServerHandlerImp.cpp index 819598c49..94a82aecb 100644 --- a/src/ripple/server/impl/ServerHandlerImp.cpp +++ b/src/ripple/server/impl/ServerHandlerImp.cpp @@ -674,7 +674,9 @@ to_Port(ParsedPort const& parsed, std::ostream& log) } std::vector -parse_Ports (BasicConfig const& config, std::ostream& log) +parse_Ports ( + Config const& config, + std::ostream& log) { std::vector result; @@ -704,17 +706,40 @@ parse_Ports (BasicConfig const& config, std::ostream& log) result.push_back(to_Port(parsed, log)); } - std::size_t count = 0; - for (auto const& p : result) - if (p.protocol.count("peer") > 0) - ++count; - if (count > 1) + if (config.RUN_STANDALONE) { - log << "Error: More than one peer protocol configured in [server]\n"; - Throw (); + auto it = result.begin (); + + while (it != result.end()) + { + auto& p = it->protocol; + + // Remove the peer protocol, and if that would + // leave the port empty, remove the port as well + if (p.erase ("peer") && p.empty()) + it = result.erase (it); + else + ++it; + } + } + else + { + auto const count = std::count_if ( + result.cbegin(), result.cend(), + [](HTTP::Port const& p) + { + return p.protocol.count("peer") != 0; + }); + + if (count > 1) + { + log << "Error: More than one peer protocol configured in [server]\n"; + Throw (); + } + + if (count == 0) + log << "Warning: No peer protocol configured\n"; } - if (count == 0) - log << "Warning: No peer protocol configured\n"; return result; } @@ -748,10 +773,11 @@ setup_Client (ServerHandler::Setup& setup) void setup_Overlay (ServerHandler::Setup& setup) { - auto const iter = std::find_if(setup.ports.cbegin(), setup.ports.cend(), + auto const iter = std::find_if( + setup.ports.cbegin(), setup.ports.cend(), [](HTTP::Port const& port) { - return port.protocol.count("peer") > 0; + return port.protocol.count("peer") != 0; }); if (iter == setup.ports.cend()) { @@ -765,7 +791,9 @@ setup_Overlay (ServerHandler::Setup& setup) } ServerHandler::Setup -setup_ServerHandler(BasicConfig const& config, std::ostream& log) +setup_ServerHandler( + Config const& config, + std::ostream& log) { ServerHandler::Setup setup; setup.ports = detail::parse_Ports(config, log);