mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-29 15:05:50 +00:00
Do not open peer port in standalone mode
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#define RIPPLE_SERVER_SERVERHANDLER_H_INCLUDED
|
#define RIPPLE_SERVER_SERVERHANDLER_H_INCLUDED
|
||||||
|
|
||||||
#include <ripple/basics/BasicConfig.h>
|
#include <ripple/basics/BasicConfig.h>
|
||||||
|
#include <ripple/core/Config.h>
|
||||||
#include <ripple/server/Port.h>
|
#include <ripple/server/Port.h>
|
||||||
#include <ripple/overlay/Overlay.h>
|
#include <ripple/overlay/Overlay.h>
|
||||||
#include <beast/utility/Journal.h>
|
#include <beast/utility/Journal.h>
|
||||||
@@ -96,7 +97,9 @@ public:
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
ServerHandler::Setup
|
ServerHandler::Setup
|
||||||
setup_ServerHandler (BasicConfig const& c, std::ostream& log);
|
setup_ServerHandler (
|
||||||
|
Config const& c,
|
||||||
|
std::ostream& log);
|
||||||
|
|
||||||
} // ripple
|
} // ripple
|
||||||
|
|
||||||
|
|||||||
@@ -674,7 +674,9 @@ to_Port(ParsedPort const& parsed, std::ostream& log)
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<HTTP::Port>
|
std::vector<HTTP::Port>
|
||||||
parse_Ports (BasicConfig const& config, std::ostream& log)
|
parse_Ports (
|
||||||
|
Config const& config,
|
||||||
|
std::ostream& log)
|
||||||
{
|
{
|
||||||
std::vector<HTTP::Port> result;
|
std::vector<HTTP::Port> result;
|
||||||
|
|
||||||
@@ -704,17 +706,40 @@ parse_Ports (BasicConfig const& config, std::ostream& log)
|
|||||||
result.push_back(to_Port(parsed, log));
|
result.push_back(to_Port(parsed, log));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t count = 0;
|
if (config.RUN_STANDALONE)
|
||||||
for (auto const& p : result)
|
|
||||||
if (p.protocol.count("peer") > 0)
|
|
||||||
++count;
|
|
||||||
if (count > 1)
|
|
||||||
{
|
{
|
||||||
log << "Error: More than one peer protocol configured in [server]\n";
|
auto it = result.begin ();
|
||||||
Throw<std::exception> ();
|
|
||||||
|
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<std::exception> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
log << "Warning: No peer protocol configured\n";
|
||||||
}
|
}
|
||||||
if (count == 0)
|
|
||||||
log << "Warning: No peer protocol configured\n";
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -748,10 +773,11 @@ setup_Client (ServerHandler::Setup& setup)
|
|||||||
void
|
void
|
||||||
setup_Overlay (ServerHandler::Setup& setup)
|
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)
|
[](HTTP::Port const& port)
|
||||||
{
|
{
|
||||||
return port.protocol.count("peer") > 0;
|
return port.protocol.count("peer") != 0;
|
||||||
});
|
});
|
||||||
if (iter == setup.ports.cend())
|
if (iter == setup.ports.cend())
|
||||||
{
|
{
|
||||||
@@ -765,7 +791,9 @@ setup_Overlay (ServerHandler::Setup& setup)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerHandler::Setup
|
ServerHandler::Setup
|
||||||
setup_ServerHandler(BasicConfig const& config, std::ostream& log)
|
setup_ServerHandler(
|
||||||
|
Config const& config,
|
||||||
|
std::ostream& log)
|
||||||
{
|
{
|
||||||
ServerHandler::Setup setup;
|
ServerHandler::Setup setup;
|
||||||
setup.ports = detail::parse_Ports(config, log);
|
setup.ports = detail::parse_Ports(config, log);
|
||||||
|
|||||||
Reference in New Issue
Block a user