| 
    rippled
    
   | 
 
Manages outbound peer connection attempts with comprehensive timeout handling. More...
#include <ConnectAttempt.h>


Classes | |
| struct | StepTimeouts | 
| Defines timeout values for each connection step.  More... | |
Public Member Functions | |
| ConnectAttempt (Application &app, boost::asio::io_context &io_context, endpoint_type const &remote_endpoint, Resource::Consumer usage, shared_context const &context, Peer::id_t id, std::shared_ptr< PeerFinder::Slot > const &slot, beast::Journal journal, OverlayImpl &overlay) | |
| Construct a new ConnectAttempt object.   | |
| ~ConnectAttempt () | |
| void | stop () override | 
| Stop the connection attempt.   | |
| void | run () | 
| Begin the connection attempt.   | |
| T | shared_from_this (T... args) | 
| T | weak_from_this (T... args) | 
Protected Attributes | |
| OverlayImpl & | overlay_ | 
Private Types | |
| enum class | ConnectionStep {  Init , TcpConnect , TlsHandshake , HttpWrite , HttpRead , Complete , ShutdownStarted }  | 
| Represents the current phase of the connection establishment process.  More... | |
| using | error_code = boost::system::error_code | 
| using | endpoint_type = boost::asio::ip::tcp::endpoint | 
| using | request_type = boost::beast::http::request< boost::beast::http::empty_body > | 
| using | response_type = boost::beast::http::response< boost::beast::http::dynamic_body > | 
| using | socket_type = boost::asio::ip::tcp::socket | 
| using | middle_type = boost::beast::tcp_stream | 
| using | stream_type = boost::beast::ssl_stream< middle_type > | 
| using | shared_context = std::shared_ptr< boost::asio::ssl::context > | 
Private Member Functions | |
| void | setTimer (ConnectionStep step) | 
| Set timers for the specified connection step.   | |
| void | cancelTimer () | 
| Cancel both global and step timers.   | |
| void | onTimer (error_code ec) | 
| Handle timer expiration events.   | |
| void | onConnect (error_code ec) | 
| void | onHandshake (error_code ec) | 
| void | onWrite (error_code ec) | 
| void | onRead (error_code ec) | 
| void | fail (std::string const &reason) | 
| void | fail (std::string const &name, error_code ec) | 
| void | shutdown () | 
| void | tryAsyncShutdown () | 
| void | onShutdown (error_code ec) | 
| void | close () | 
| void | processResponse () | 
| Process the HTTP upgrade response from peer.   | |
Static Private Member Functions | |
| static std::string | stepToString (ConnectionStep step) | 
| template<class = void> | |
| static boost::asio::ip::tcp::endpoint | parse_endpoint (std::string const &s, boost::system::error_code &ec) | 
Private Attributes | |
| Application & | app_ | 
| Peer::id_t const | id_ | 
| beast::WrappedSink | sink_ | 
| beast::Journal const | journal_ | 
| endpoint_type | remote_endpoint_ | 
| Resource::Consumer | usage_ | 
| boost::asio::strand< boost::asio::io_context::executor_type > | strand_ | 
| boost::asio::basic_waitable_timer< std::chrono::steady_clock > | timer_ | 
| boost::asio::basic_waitable_timer< std::chrono::steady_clock > | stepTimer_ | 
| std::unique_ptr< stream_type > | stream_ptr_ | 
| socket_type & | socket_ | 
| stream_type & | stream_ | 
| boost::beast::multi_buffer | read_buf_ | 
| response_type | response_ | 
| std::shared_ptr< PeerFinder::Slot > | slot_ | 
| request_type | req_ | 
| bool | shutdown_ = false | 
| bool | ioPending_ = false | 
| ConnectionStep | currentStep_ = ConnectionStep::Init | 
Static Private Attributes | |
| static constexpr std::chrono::seconds | connectTimeout {25} | 
Manages outbound peer connection attempts with comprehensive timeout handling.
The ConnectAttempt class handles the complete lifecycle of establishing an outbound connection to a peer in the XRPL network. It implements a sophisticated dual-timer system that provides both global timeout protection and per-step timeout diagnostics.
The connection establishment follows these steps:
Uses a hybrid timeout approach:
All operations are serialized using boost::asio::strand to ensure thread safety. The class is designed to be used exclusively within the ASIO event loop.
Definition at line 60 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 64 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 65 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 66 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 68 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 70 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 71 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 72 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 73 of file ConnectAttempt.h.
      
  | 
  strongprivate | 
Represents the current phase of the connection establishment process.
Used for tracking progress and providing detailed timeout diagnostics. Each step has its own timeout value defined in StepTimeouts.
| Enumerator | |
|---|---|
| Init | |
| TcpConnect | |
| TlsHandshake | |
| HttpWrite | |
| HttpRead | |
| Complete | |
| ShutdownStarted | |
Definition at line 83 of file ConnectAttempt.h.
| ripple::ConnectAttempt::ConnectAttempt | ( | Application & | app, | 
| boost::asio::io_context & | io_context, | ||
| endpoint_type const & | remote_endpoint, | ||
| Resource::Consumer | usage, | ||
| shared_context const & | context, | ||
| Peer::id_t | id, | ||
| std::shared_ptr< PeerFinder::Slot > const & | slot, | ||
| beast::Journal | journal, | ||
| OverlayImpl & | overlay | ||
| ) | 
Construct a new ConnectAttempt object.
| app | Application context providing configuration and services | 
| io_context | ASIO I/O context for async operations | 
| remote_endpoint | Target peer endpoint to connect to | 
| usage | Resource usage tracker for rate limiting | 
| context | Shared SSL context for encryption | 
| id | Unique peer identifier for this connection attempt | 
| slot | PeerFinder slot representing this connection | 
| journal | Logging interface for diagnostics | 
| overlay | Parent overlay manager | 
Definition at line 31 of file ConnectAttempt.cpp.
| ripple::ConnectAttempt::~ConnectAttempt | ( | ) | 
Definition at line 60 of file ConnectAttempt.cpp.
      
  | 
  overridevirtual | 
Stop the connection attempt.
This method is thread-safe and can be called from any thread.
Implements ripple::OverlayImpl::Child.
Definition at line 69 of file ConnectAttempt.cpp.
| void ripple::ConnectAttempt::run | ( | ) | 
Begin the connection attempt.
This method is thread-safe and posts to the strand if needed.
Definition at line 84 of file ConnectAttempt.cpp.
      
  | 
  private | 
Set timers for the specified connection step.
| step | The connection step to set timers for | 
Sets both the step-specific timer and the global timer (if not already set).
Definition at line 212 of file ConnectAttempt.cpp.
      
  | 
  private | 
Cancel both global and step timers.
Used during cleanup and when connection completes successfully. Exceptions from timer cancellation are safely ignored.
Definition at line 283 of file ConnectAttempt.cpp.
      
  | 
  private | 
Handle timer expiration events.
| ec | Error code from timer operation | 
Determines which timer expired (global vs step) and logs appropriate diagnostic information before terminating the connection.
Definition at line 297 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 337 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 376 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 435 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 467 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 198 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 205 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 110 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 126 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 155 of file ConnectAttempt.cpp.
      
  | 
  private | 
Definition at line 183 of file ConnectAttempt.cpp.
      
  | 
  private | 
Process the HTTP upgrade response from peer.
Validates the peer's response, extracts protocol information, verifies handshake, and either creates a PeerImp or handles redirect responses.
Definition at line 496 of file ConnectAttempt.cpp.
      
  | 
  staticprivate | 
Definition at line 255 of file ConnectAttempt.h.
      
  | 
  staticprivate | 
Definition at line 279 of file ConnectAttempt.h.
      
  | 
  staticconstexprprivate | 
Definition at line 94 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 118 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 119 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 120 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 121 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 122 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 123 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 125 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 126 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 127 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 129 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 130 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 131 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 132 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 134 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 135 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 136 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 138 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 139 of file ConnectAttempt.h.
      
  | 
  private | 
Definition at line 140 of file ConnectAttempt.h.
      
  | 
  protectedinherited | 
Definition at line 68 of file OverlayImpl.h.