Skip to content

Commit

Permalink
Append default port (2459) in [ips] and [ips_fixed] when no port is s…
Browse files Browse the repository at this point in the history
…pecified

FIXES: XRPLF#2861
  • Loading branch information
gregtatcam committed Apr 27, 2020
1 parent 023f570 commit 6d9f656
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,9 @@ OverlayImpl::onPrepare()
for (auto const& addr : addresses)
{
if (addr.port() == 0)
{
Throw<std::runtime_error>(
"Port not specified for "
"address:" +
addr.to_string());
}

ips.push_back(to_string(addr));
ips.push_back(to_string(addr.at_port(DEFAULT_PEER_PORT)));
else
ips.push_back(to_string(addr));
}

std::string const base("config: ");
Expand All @@ -600,8 +595,19 @@ OverlayImpl::onPrepare()
[this](
std::string const& name,
std::vector<beast::IP::Endpoint> const& addresses) {
if (!addresses.empty())
m_peerFinder->addFixedPeer(name, addresses);
std::vector<beast::IP::Endpoint> ips;
ips.reserve(addresses.size());

for (auto& addr : addresses)
{
if (addr.port() == 0)
ips.emplace_back(addr.address(), DEFAULT_PEER_PORT);
else
ips.emplace_back(addr);
}

if (!ips.empty())
m_peerFinder->addFixedPeer(name, ips);
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/protocol/SystemParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ static std::uint32_t constexpr XRP_LEDGER_EARLIEST_SEQ{32570};

} // namespace ripple

/** Default peer port (IANA registered) */
inline std::uint16_t constexpr DEFAULT_PEER_PORT{2459};

#endif
3 changes: 2 additions & 1 deletion src/ripple/rpc/handlers/Connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ripple/net/RPCErr.h>
#include <ripple/overlay/Overlay.h>
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/SystemParameters.h>
#include <ripple/protocol/jss.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/impl/Handler.h>
Expand Down Expand Up @@ -53,7 +54,7 @@ doConnect(RPC::JsonContext& context)
if (context.params.isMember(jss::port))
iPort = context.params[jss::port].asInt();
else
iPort = 6561;
iPort = DEFAULT_PEER_PORT;

auto ip =
beast::IP::Endpoint::from_string(context.params[jss::ip].asString());
Expand Down

0 comments on commit 6d9f656

Please sign in to comment.