Skip to content

Commit c9d73b6

Browse files
authored
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.
1 parent b7ed994 commit c9d73b6

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/xrpld/overlay/detail/ConnectAttempt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ ConnectAttempt::processResponse()
379379
auto const result = overlay_.peerFinder().activate(
380380
slot_, publicKey, static_cast<bool>(member));
381381
if (result != PeerFinder::Result::success)
382-
return fail("Outbound slots full");
382+
return fail("Outbound " + std::string(to_string(result)));
383383

384384
auto const peer = std::make_shared<PeerImp>(
385385
app_,

src/xrpld/overlay/detail/OverlayImpl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <xrpld/overlay/Cluster.h>
2727
#include <xrpld/overlay/detail/ConnectAttempt.h>
2828
#include <xrpld/overlay/detail/PeerImp.h>
29+
#include <xrpld/overlay/detail/TrafficCount.h>
2930
#include <xrpld/overlay/detail/Tuning.h>
3031
#include <xrpld/overlay/predicates.h>
3132
#include <xrpld/peerfinder/make_Manager.h>
@@ -41,8 +42,6 @@
4142

4243
#include <boost/algorithm/string/predicate.hpp>
4344

44-
#include "xrpld/overlay/detail/TrafficCount.h"
45-
4645
namespace ripple {
4746

4847
namespace CrawlOptions {
@@ -269,8 +268,8 @@ OverlayImpl::onHandoff(
269268
if (result != PeerFinder::Result::success)
270269
{
271270
m_peerFinder->on_closed(slot);
272-
JLOG(journal.debug())
273-
<< "Peer " << remote_endpoint << " redirected, slots full";
271+
JLOG(journal.debug()) << "Peer " << remote_endpoint
272+
<< " redirected, " << to_string(result);
274273
handoff.moved = false;
275274
handoff.response = makeRedirectResponse(
276275
slot, request, remote_endpoint.address());

src/xrpld/peerfinder/PeerfinderManager.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
#include <boost/asio/ip/tcp.hpp>
3030

31+
#include <string_view>
32+
3133
namespace ripple {
3234
namespace PeerFinder {
3335

@@ -136,6 +138,36 @@ using Endpoints = std::vector<Endpoint>;
136138
/** Possible results from activating a slot. */
137139
enum class Result { duplicate, full, success };
138140

141+
/**
142+
* @brief Converts a `Result` enum value to its string representation.
143+
*
144+
* This function provides a human-readable string for a given `Result` enum,
145+
* which is useful for logging, debugging, or displaying status messages.
146+
*
147+
* @param result The `Result` enum value to convert.
148+
* @return A `std::string_view` representing the enum value. Returns "unknown"
149+
* if the enum value is not explicitly handled.
150+
*
151+
* @note This function returns a `std::string_view` for performance.
152+
* A `std::string` would need to allocate memory on the heap and copy the
153+
* string literal into it every time the function is called.
154+
*/
155+
inline std::string_view
156+
to_string(Result result) noexcept
157+
{
158+
switch (result)
159+
{
160+
case Result::success:
161+
return "success";
162+
case Result::duplicate:
163+
return "duplicate connection";
164+
case Result::full:
165+
return "slots full";
166+
}
167+
168+
return "unknown";
169+
}
170+
139171
/** Maintains a set of IP addresses used for getting into the network. */
140172
class Manager : public beast::PropertyStream::Source
141173
{

0 commit comments

Comments
 (0)