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 .outboundConnectCloseStop ;
7578 close ();
7679}
7780
@@ -150,8 +153,14 @@ ConnectAttempt::onTimer(error_code ec)
150153 {
151154 // This should never happen
152155 JLOG (journal_.error ()) << " onTimer: " << ec.message ();
156+ ++app_.getPerfLog ()
157+ .getPeerCounters ()
158+ .connection .outboundConnectCloseOnTimer ;
153159 return close ();
154160 }
161+ ++app_.getPerfLog ()
162+ .getPeerCounters ()
163+ .connection .outboundConnectFailTimeouts ;
155164 fail (" Timeout" );
156165}
157166
@@ -166,7 +175,12 @@ ConnectAttempt::onConnect(error_code ec)
166175 if (!ec)
167176 local_endpoint = socket_.local_endpoint (ec);
168177 if (ec)
178+ {
179+ ++app_.getPerfLog ()
180+ .getPeerCounters ()
181+ .connection .outboundConnectFailOnConnectError ;
169182 return fail (" onConnect" , ec);
183+ }
170184 if (!socket_.is_open ())
171185 return ;
172186 JLOG (journal_.trace ()) << " onConnect" ;
@@ -193,16 +207,31 @@ ConnectAttempt::onHandshake(error_code ec)
193207 if (!ec)
194208 local_endpoint = socket_.local_endpoint (ec);
195209 if (ec)
210+ {
211+ ++app_.getPerfLog ()
212+ .getPeerCounters ()
213+ .connection .outboundConnectFailOnHandshakeError ;
196214 return fail (" onHandshake" , ec);
215+ }
197216 JLOG (journal_.trace ()) << " onHandshake" ;
198217
199218 if (!overlay_.peerFinder ().onConnected (
200219 slot_, beast::IPAddressConversion::from_asio (local_endpoint)))
220+ {
221+ ++app_.getPerfLog ()
222+ .getPeerCounters ()
223+ .connection .outboundConnectFailOnHandshakeDuplicate ;
201224 return fail (" Duplicate connection" );
225+ }
202226
203227 auto const sharedValue = makeSharedValue (*stream_ptr_, journal_);
204228 if (!sharedValue)
229+ {
230+ ++app_.getPerfLog ()
231+ .getPeerCounters ()
232+ .connection .outboundConnectCloseOnHandshake ;
205233 return close (); // makeSharedValue logs
234+ }
206235
207236 req_ = makeRequest (
208237 !overlay_.peerFinder ().config ().peerPrivate ,
@@ -238,7 +267,12 @@ ConnectAttempt::onWrite(error_code ec)
238267 if (ec == boost::asio::error::operation_aborted)
239268 return ;
240269 if (ec)
270+ {
271+ ++app_.getPerfLog ()
272+ .getPeerCounters ()
273+ .connection .outboundConnectFailOnWriteError ;
241274 return fail (" onWrite" , ec);
275+ }
242276 boost::beast::http::async_read (
243277 stream_,
244278 read_buf_,
@@ -268,7 +302,12 @@ ConnectAttempt::onRead(error_code ec)
268302 std::placeholders::_1)));
269303 }
270304 if (ec)
305+ {
306+ ++app_.getPerfLog ()
307+ .getPeerCounters ()
308+ .connection .outboundConnectFailOnReadError ;
271309 return fail (" onRead" , ec);
310+ }
272311 processResponse ();
273312}
274313
@@ -279,10 +318,21 @@ ConnectAttempt::onShutdown(error_code ec)
279318 if (!ec)
280319 {
281320 JLOG (journal_.error ()) << " onShutdown: expected error condition" ;
321+ ++app_.getPerfLog ()
322+ .getPeerCounters ()
323+ .connection .outboundConnectCloseOnShutdownNoError ;
282324 return close ();
283325 }
284326 if (ec != boost::asio::error::eof)
327+ {
328+ ++app_.getPerfLog ()
329+ .getPeerCounters ()
330+ .connection .outboundConnectFailOnShutdownError ;
285331 return fail (" onShutdown" , ec);
332+ }
333+ ++app_.getPerfLog ()
334+ .getPeerCounters ()
335+ .connection .outboundConnectCloseOnShutdown ;
286336 close ();
287337}
288338
@@ -332,6 +382,9 @@ ConnectAttempt::processResponse()
332382 JLOG (journal_.info ())
333383 << " Unable to upgrade to peer protocol: " << response_.result ()
334384 << " (" << response_.reason () << " )" ;
385+ ++app_.getPerfLog ()
386+ .getPeerCounters ()
387+ .connection .outboundConnectCloseUpgrade ;
335388 return close ();
336389 }
337390
@@ -346,13 +399,23 @@ ConnectAttempt::processResponse()
346399 negotiatedProtocol = pvs[0 ];
347400
348401 if (!negotiatedProtocol)
402+ {
403+ ++app_.getPerfLog ()
404+ .getPeerCounters ()
405+ .connection .outboundConnectFailProtocol ;
349406 return fail (
350407 " processResponse: Unable to negotiate protocol version" );
408+ }
351409 }
352410
353411 auto const sharedValue = makeSharedValue (*stream_ptr_, journal_);
354412 if (!sharedValue)
413+ {
414+ ++app_.getPerfLog ()
415+ .getPeerCounters ()
416+ .connection .outboundConnectCloseShared ;
355417 return close (); // makeSharedValue logs
418+ }
356419
357420 try
358421 {
@@ -379,7 +442,12 @@ ConnectAttempt::processResponse()
379442 auto const result = overlay_.peerFinder ().activate (
380443 slot_, publicKey, static_cast <bool >(member));
381444 if (result != PeerFinder::Result::success)
445+ {
446+ ++app_.getPerfLog ()
447+ .getPeerCounters ()
448+ .connection .outboundConnectFailSlotsFull ;
382449 return fail (" Outbound slots full" );
450+ }
383451
384452 auto const peer = std::make_shared<PeerImp>(
385453 app_,
@@ -397,6 +465,9 @@ ConnectAttempt::processResponse()
397465 }
398466 catch (std::exception const & e)
399467 {
468+ ++app_.getPerfLog ()
469+ .getPeerCounters ()
470+ .connection .outboundConnectFailOnHandshakeFailure ;
400471 return fail (std::string (" Handshake failure (" ) + e.what () + " )" );
401472 }
402473}
0 commit comments