fix: Improve logging of the reason to refuse a peer connection (#5664)

Currently, all peer connection rejections are logged with the reason "slots full". This is inaccurate, as the PeerFinder can also reject connections if they are a duplicate. This change updates the logging logic to correctly report the specific reason (full or duplicate) for a rejected peer connection, providing more accurate diagnostic information.
This commit is contained in:
Vito Tumas
2025-08-11 20:52:47 +02:00
committed by GitHub
parent b7ed99426b
commit c9d73b6135
3 changed files with 36 additions and 5 deletions

View File

@@ -379,7 +379,7 @@ ConnectAttempt::processResponse()
auto const result = overlay_.peerFinder().activate(
slot_, publicKey, static_cast<bool>(member));
if (result != PeerFinder::Result::success)
return fail("Outbound slots full");
return fail("Outbound " + std::string(to_string(result)));
auto const peer = std::make_shared<PeerImp>(
app_,

View File

@@ -26,6 +26,7 @@
#include <xrpld/overlay/Cluster.h>
#include <xrpld/overlay/detail/ConnectAttempt.h>
#include <xrpld/overlay/detail/PeerImp.h>
#include <xrpld/overlay/detail/TrafficCount.h>
#include <xrpld/overlay/detail/Tuning.h>
#include <xrpld/overlay/predicates.h>
#include <xrpld/peerfinder/make_Manager.h>
@@ -41,8 +42,6 @@
#include <boost/algorithm/string/predicate.hpp>
#include "xrpld/overlay/detail/TrafficCount.h"
namespace ripple {
namespace CrawlOptions {
@@ -269,8 +268,8 @@ OverlayImpl::onHandoff(
if (result != PeerFinder::Result::success)
{
m_peerFinder->on_closed(slot);
JLOG(journal.debug())
<< "Peer " << remote_endpoint << " redirected, slots full";
JLOG(journal.debug()) << "Peer " << remote_endpoint
<< " redirected, " << to_string(result);
handoff.moved = false;
handoff.response = makeRedirectResponse(
slot, request, remote_endpoint.address());

View File

@@ -28,6 +28,8 @@
#include <boost/asio/ip/tcp.hpp>
#include <string_view>
namespace ripple {
namespace PeerFinder {
@@ -136,6 +138,36 @@ using Endpoints = std::vector<Endpoint>;
/** Possible results from activating a slot. */
enum class Result { duplicate, full, success };
/**
* @brief Converts a `Result` enum value to its string representation.
*
* This function provides a human-readable string for a given `Result` enum,
* which is useful for logging, debugging, or displaying status messages.
*
* @param result The `Result` enum value to convert.
* @return A `std::string_view` representing the enum value. Returns "unknown"
* if the enum value is not explicitly handled.
*
* @note This function returns a `std::string_view` for performance.
* A `std::string` would need to allocate memory on the heap and copy the
* string literal into it every time the function is called.
*/
inline std::string_view
to_string(Result result) noexcept
{
switch (result)
{
case Result::success:
return "success";
case Result::duplicate:
return "duplicate connection";
case Result::full:
return "slots full";
}
return "unknown";
}
/** Maintains a set of IP addresses used for getting into the network. */
class Manager : public beast::PropertyStream::Source
{