Skip to content

Commit 92e2e3e

Browse files
committed
Log outbound connection attempts.
Log peer connection when logging autoconnect preparation.
1 parent c36809d commit 92e2e3e

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

src/xrpld/overlay/detail/ConnectAttempt.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ ConnectAttempt::ConnectAttempt(
5151
, stream_(*stream_ptr_)
5252
, slot_(slot)
5353
{
54-
JLOG(journal_.debug()) << "Connect " << remote_endpoint;
54+
log << "CONNECTATTEMPT start " << to_string(std::chrono::system_clock::now())
55+
<< ". remote ip: " << remote_endpoint_ << ". id: " << id_;
56+
JLOG(journal_.debug()) << "connecting " << log.str();
5557
}
5658

5759
ConnectAttempt::~ConnectAttempt()
5860
{
5961
if (slot_ != nullptr)
6062
overlay_.peerFinder().on_closed(slot_);
6163
JLOG(journal_.trace()) << "~ConnectAttempt";
64+
JLOG(journal_.debug()) << log.str() << ". end reason: "
65+
<< (close_reason.str().empty() ? "unknown" : close_reason.str());
6266
}
6367

6468
void
@@ -71,7 +75,7 @@ ConnectAttempt::stop()
7175
{
7276
JLOG(journal_.debug()) << "Stop";
7377
}
74-
close();
78+
close("stop");
7579
}
7680

7781
void
@@ -88,7 +92,7 @@ ConnectAttempt::run()
8892
//------------------------------------------------------------------------------
8993

9094
void
91-
ConnectAttempt::close()
95+
ConnectAttempt::close(const char* reason)
9296
{
9397
XRPL_ASSERT(
9498
strand_.running_in_this_thread(),
@@ -99,21 +103,25 @@ ConnectAttempt::close()
99103
timer_.cancel(ec);
100104
socket_.close(ec);
101105
JLOG(journal_.debug()) << "Closed";
106+
log << "close ";
107+
close_reason << reason;
102108
}
103109
}
104110

105111
void
106112
ConnectAttempt::fail(std::string const& reason)
107113
{
108114
JLOG(journal_.debug()) << reason;
109-
close();
115+
close(reason.c_str());
110116
}
111117

112118
void
113119
ConnectAttempt::fail(std::string const& name, error_code ec)
114120
{
121+
std::stringstream ss;
122+
ss << name << ", error: " << ec.message();
115123
JLOG(journal_.debug()) << name << ": " << ec.message();
116-
close();
124+
close(ss.str().c_str());
117125
}
118126

119127
void
@@ -149,7 +157,9 @@ ConnectAttempt::onTimer(error_code ec)
149157
{
150158
// This should never happen
151159
JLOG(journal_.error()) << "onTimer: " << ec.message();
152-
return close();
160+
std::stringstream ss;
161+
ss << "onTimer, error: " << ec.message();
162+
return close(ss.str().c_str());
153163
}
154164
fail("Timeout");
155165
}
@@ -201,7 +211,7 @@ ConnectAttempt::onHandshake(error_code ec)
201211

202212
auto const sharedValue = makeSharedValue(*stream_ptr_, journal_);
203213
if (!sharedValue)
204-
return close(); // makeSharedValue logs
214+
return close("onHandshake no sharedValue"); // makeSharedValue logs
205215

206216
req_ = makeRequest(
207217
!overlay_.peerFinder().config().peerPrivate,
@@ -278,11 +288,11 @@ ConnectAttempt::onShutdown(error_code ec)
278288
if (!ec)
279289
{
280290
JLOG(journal_.error()) << "onShutdown: expected error condition";
281-
return close();
291+
return close("onShutdown: expected error condition");
282292
}
283293
if (ec != boost::asio::error::eof)
284294
return fail("onShutdown", ec);
285-
close();
295+
close("onShutdown eof");
286296
}
287297

288298
//--------------------------------------------------------------------------
@@ -331,7 +341,10 @@ ConnectAttempt::processResponse()
331341
JLOG(journal_.info())
332342
<< "Unable to upgrade to peer protocol: " << response_.result()
333343
<< " (" << response_.reason() << ")";
334-
return close();
344+
std::stringstream ss;
345+
ss << "unable to upgrade peer protocol: " << response_.result()
346+
<< " (" << response_.reason() << ")";
347+
return close(ss.str().c_str());
335348
}
336349

337350
// Just because our peer selected a particular protocol version doesn't
@@ -351,7 +364,7 @@ ConnectAttempt::processResponse()
351364

352365
auto const sharedValue = makeSharedValue(*stream_ptr_, journal_);
353366
if (!sharedValue)
354-
return close(); // makeSharedValue logs
367+
return close("processResponse no sharedValue"); // makeSharedValue logs
355368

356369
try
357370
{
@@ -365,14 +378,17 @@ ConnectAttempt::processResponse()
365378

366379
JLOG(journal_.info())
367380
<< "Public Key: " << toBase58(TokenType::NodePublic, publicKey);
381+
log << "public key: " << toBase58(TokenType::NodePublic, publicKey);
368382

369383
JLOG(journal_.debug())
370384
<< "Protocol: " << to_string(*negotiatedProtocol);
385+
log << " protocol: " << to_string(*negotiatedProtocol);
371386

372387
auto const member = app_.cluster().member(publicKey);
373388
if (member)
374389
{
375390
JLOG(journal_.info()) << "Cluster name: " << *member;
391+
log << "cluster name: " << *member;
376392
}
377393

378394
auto const result = overlay_.peerFinder().activate(
@@ -391,14 +407,15 @@ ConnectAttempt::processResponse()
391407
*negotiatedProtocol,
392408
id_,
393409
overlay_);
394-
peer->log << "outbound. ";
410+
peer->log << "outbound ( " << log.str() << "). ";
395411

396412
overlay_.add_active(peer);
397413
}
398414
catch (std::exception const& e)
399415
{
400416
return fail(std::string("Handshake failure (") + e.what() + ")");
401417
}
418+
close_reason << "successful connection";
402419
}
403420

404421
} // namespace ripple

src/xrpld/overlay/detail/ConnectAttempt.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <xrpld/overlay/detail/OverlayImpl.h>
2424
#include <xrpld/overlay/detail/Tuning.h>
25+
#include <sstream>
2526

2627
namespace ripple {
2728

@@ -62,6 +63,9 @@ class ConnectAttempt : public OverlayImpl::Child,
6263
request_type req_;
6364

6465
public:
66+
std::stringstream log;
67+
std::stringstream close_reason;
68+
6569
ConnectAttempt(
6670
Application& app,
6771
boost::asio::io_service& io_service,
@@ -83,7 +87,7 @@ class ConnectAttempt : public OverlayImpl::Child,
8387

8488
private:
8589
void
86-
close();
90+
close(const char* reason);
8791
void
8892
fail(std::string const& reason);
8993
void

src/xrpld/overlay/detail/PeerImp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ PeerImp::PeerImp(
130130
<< txReduceRelayEnabled_ << " on " << remote_address_
131131
<< " " << id_;
132132

133-
log << "ctor2";
133+
log << "ctor2 ";
134134
initLog();
135135
}
136136

src/xrpld/peerfinder/detail/Counts.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,25 @@ class Counts
249249
return ss.str();
250250
}
251251

252+
std::string
253+
stats() const {
254+
std::stringstream ss;
255+
ss << "peer stats, "
256+
<< "outbound attempts: " << m_attempts
257+
<< " active connections: " << m_active
258+
<< " inbound slots: " << m_in_max
259+
<< " active inbound slots: " << m_in_active
260+
<< " outbound slots: " << m_out_max
261+
<< " active outbound slots: " << m_out_active
262+
<< " fixed: " << m_fixed
263+
<< " active fixed: " << m_fixed_active
264+
<< " reserved: " << m_reserved
265+
<< " inbound not active or closing: " << m_acceptCount
266+
<< " closing: " << m_closingCount
267+
<< ". ";
268+
return ss.str();
269+
}
270+
252271
//--------------------------------------------------------------------------
253272
private:
254273
// Adjusts counts based on the specified slot, in the direction indicated.

src/xrpld/peerfinder/detail/Logic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ class Logic
494494
autoconnect()
495495
{
496496
std::stringstream ss;
497-
ss << "AUTOCONNECT ";
497+
ss << "AUTOCONNECT " << counts_.stats();
498498
std::vector<beast::IP::Endpoint> const none;
499499

500500
std::lock_guard _(lock_);

0 commit comments

Comments
 (0)