@@ -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
5759ConnectAttempt::~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
6468void
@@ -71,7 +75,7 @@ ConnectAttempt::stop()
7175 {
7276 JLOG (journal_.debug ()) << " Stop" ;
7377 }
74- close ();
78+ close (" stop " );
7579}
7680
7781void
@@ -88,7 +92,7 @@ ConnectAttempt::run()
8892// ------------------------------------------------------------------------------
8993
9094void
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
105111void
106112ConnectAttempt::fail (std::string const & reason)
107113{
108114 JLOG (journal_.debug ()) << reason;
109- close ();
115+ close (reason. c_str () );
110116}
111117
112118void
113119ConnectAttempt::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
119127void
@@ -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
0 commit comments