2121#include < xrpld/overlay/detail/ConnectAttempt.h>
2222#include < xrpld/overlay/detail/PeerImp.h>
2323#include < xrpld/overlay/detail/ProtocolVersion.h>
24+ #include < xrpld/perflog/PerfLog.h>
2425
2526#include < xrpl/json/json_reader.h>
2627
@@ -52,6 +53,7 @@ ConnectAttempt::ConnectAttempt(
5253 , stream_(*stream_ptr_)
5354 , slot_(slot)
5455{
56+ ++app_.getPerfLog ().getPeerCounters ().connection .totalOutboundAttempts ;
5557 JLOG (journal_.debug ()) << " Connect " << remote_endpoint;
5658}
5759
@@ -72,6 +74,7 @@ ConnectAttempt::stop()
7274 {
7375 JLOG (journal_.debug ()) << " Stop" ;
7476 }
77+ ++app_.getPerfLog ().getPeerCounters ().connection .connectCloseStop ;
7578 close ();
7679}
7780
@@ -150,8 +153,10 @@ ConnectAttempt::onTimer(error_code ec)
150153 {
151154 // This should never happen
152155 JLOG (journal_.error ()) << " onTimer: " << ec.message ();
156+ ++app_.getPerfLog ().getPeerCounters ().connection .connectCloseOnTimer ;
153157 return close ();
154158 }
159+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailTimeouts ;
155160 fail (" Timeout" );
156161}
157162
@@ -165,8 +170,10 @@ ConnectAttempt::onConnect(error_code ec)
165170 endpoint_type local_endpoint;
166171 if (!ec)
167172 local_endpoint = socket_.local_endpoint (ec);
168- if (ec)
173+ if (ec) {
174+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailOnConnectError ;
169175 return fail (" onConnect" , ec);
176+ }
170177 if (!socket_.is_open ())
171178 return ;
172179 JLOG (journal_.trace ()) << " onConnect" ;
@@ -192,17 +199,23 @@ ConnectAttempt::onHandshake(error_code ec)
192199 endpoint_type local_endpoint;
193200 if (!ec)
194201 local_endpoint = socket_.local_endpoint (ec);
195- if (ec)
202+ if (ec) {
203+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailOnHandshakeError ;
196204 return fail (" onHandshake" , ec);
205+ }
197206 JLOG (journal_.trace ()) << " onHandshake" ;
198207
199208 if (!overlay_.peerFinder ().onConnected (
200- slot_, beast::IPAddressConversion::from_asio (local_endpoint)))
209+ slot_, beast::IPAddressConversion::from_asio (local_endpoint))) {
210+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailOnHandshakeDuplicate ;
201211 return fail (" Duplicate connection" );
212+ }
202213
203214 auto const sharedValue = makeSharedValue (*stream_ptr_, journal_);
204- if (!sharedValue)
215+ if (!sharedValue) {
216+ ++app_.getPerfLog ().getPeerCounters ().connection .connectCloseOnHandshake ;
205217 return close (); // makeSharedValue logs
218+ }
206219
207220 req_ = makeRequest (
208221 !overlay_.peerFinder ().config ().peerPrivate ,
@@ -237,8 +250,10 @@ ConnectAttempt::onWrite(error_code ec)
237250 return ;
238251 if (ec == boost::asio::error::operation_aborted)
239252 return ;
240- if (ec)
253+ if (ec) {
254+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailOnWriteError ;
241255 return fail (" onWrite" , ec);
256+ }
242257 boost::beast::http::async_read (
243258 stream_,
244259 read_buf_,
@@ -267,8 +282,10 @@ ConnectAttempt::onRead(error_code ec)
267282 shared_from_this (),
268283 std::placeholders::_1)));
269284 }
270- if (ec)
285+ if (ec) {
286+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailOnReadError ;
271287 return fail (" onRead" , ec);
288+ }
272289 processResponse ();
273290}
274291
@@ -279,10 +296,14 @@ ConnectAttempt::onShutdown(error_code ec)
279296 if (!ec)
280297 {
281298 JLOG (journal_.error ()) << " onShutdown: expected error condition" ;
299+ ++app_.getPerfLog ().getPeerCounters ().connection .connectCloseOnShutdownNoError ;
282300 return close ();
283301 }
284- if (ec != boost::asio::error::eof)
302+ if (ec != boost::asio::error::eof) {
303+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailOnShutdownError ;
285304 return fail (" onShutdown" , ec);
305+ }
306+ ++app_.getPerfLog ().getPeerCounters ().connection .connectCloseOnShutdown ;
286307 close ();
287308}
288309
@@ -332,6 +353,7 @@ ConnectAttempt::processResponse()
332353 JLOG (journal_.info ())
333354 << " Unable to upgrade to peer protocol: " << response_.result ()
334355 << " (" << response_.reason () << " )" ;
356+ ++app_.getPerfLog ().getPeerCounters ().connection .connectCloseUpgrade ;
335357 return close ();
336358 }
337359
@@ -345,14 +367,18 @@ ConnectAttempt::processResponse()
345367 if (pvs.size () == 1 && isProtocolSupported (pvs[0 ]))
346368 negotiatedProtocol = pvs[0 ];
347369
348- if (!negotiatedProtocol)
370+ if (!negotiatedProtocol) {
371+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailProtocol ;
349372 return fail (
350373 " processResponse: Unable to negotiate protocol version" );
374+ }
351375 }
352376
353377 auto const sharedValue = makeSharedValue (*stream_ptr_, journal_);
354- if (!sharedValue)
378+ if (!sharedValue) {
379+ ++app_.getPerfLog ().getPeerCounters ().connection .connectCloseShared ;
355380 return close (); // makeSharedValue logs
381+ }
356382
357383 try
358384 {
@@ -378,8 +404,10 @@ ConnectAttempt::processResponse()
378404
379405 auto const result = overlay_.peerFinder ().activate (
380406 slot_, publicKey, static_cast <bool >(member));
381- if (result != PeerFinder::Result::success)
407+ if (result != PeerFinder::Result::success) {
408+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailSlotsFull ;
382409 return fail (" Outbound slots full" );
410+ }
383411
384412 auto const peer = std::make_shared<PeerImp>(
385413 app_,
@@ -397,6 +425,7 @@ ConnectAttempt::processResponse()
397425 }
398426 catch (std::exception const & e)
399427 {
428+ ++app_.getPerfLog ().getPeerCounters ().connection .connectFailOnHandshakeFailure ;
400429 return fail (std::string (" Handshake failure (" ) + e.what () + " )" );
401430 }
402431}
0 commit comments