Bitcoin Core 31.99.0
P2P Digital Currency
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
TorControlConnection Class Reference

Low-level handling for Tor control connection. More...

#include <torcontrol.h>

Collaboration diagram for TorControlConnection:
[legend]

Public Types

typedef std::function< void(TorControlConnection &, const TorControlReply &)> ReplyHandlerCB
 

Public Member Functions

 TorControlConnection (CThreadInterrupt &interrupt)
 Create a new TorControlConnection. More...
 
 ~TorControlConnection ()
 
bool Connect (const std::string &tor_control_center)
 Connect to a Tor control port. More...
 
void Disconnect ()
 Disconnect from Tor control port. More...
 
bool Command (const std::string &cmd, const ReplyHandlerCB &reply_handler)
 Send a command, register a handler for the reply. More...
 
bool IsConnected () const
 Check if the connection is established. More...
 
bool WaitForData (std::chrono::milliseconds timeout)
 Wait for data to be available on the socket. More...
 
bool ReceiveAndProcess ()
 Read available data from socket and process complete replies. More...
 

Private Member Functions

bool ProcessBuffer ()
 Process complete lines from the receive buffer. More...
 

Private Attributes

CThreadInterruptm_interrupt
 Reference to interrupt object for clean shutdown. More...
 
std::unique_ptr< Sockm_sock
 Socket for the connection. More...
 
TorControlReply m_message
 Message being received. More...
 
std::deque< ReplyHandlerCBm_reply_handlers
 Response handlers. More...
 
std::vector< std::byte > m_recv_buffer
 Buffer for incoming data. More...
 

Detailed Description

Low-level handling for Tor control connection.

Speaks the SMTP-like protocol as defined in torspec/control-spec.txt

Definition at line 55 of file torcontrol.h.

Member Typedef Documentation

◆ ReplyHandlerCB

Definition at line 58 of file torcontrol.h.

Constructor & Destructor Documentation

◆ TorControlConnection()

TorControlConnection::TorControlConnection ( CThreadInterrupt interrupt)
explicit

Create a new TorControlConnection.

Definition at line 76 of file torcontrol.cpp.

◆ ~TorControlConnection()

TorControlConnection::~TorControlConnection ( )

Definition at line 81 of file torcontrol.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ Command()

bool TorControlConnection::Command ( const std::string &  cmd,
const ReplyHandlerCB reply_handler 
)

Send a command, register a handler for the reply.

A trailing CRLF is automatically added. Return true on success.

Definition at line 217 of file torcontrol.cpp.

Here is the caller graph for this function:

◆ Connect()

bool TorControlConnection::Connect ( const std::string &  tor_control_center)

Connect to a Tor control port.

tor_control_center is address of the form host:port. Return true on success.

Definition at line 86 of file torcontrol.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Disconnect()

void TorControlConnection::Disconnect ( )

Disconnect from Tor control port.

Definition at line 112 of file torcontrol.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsConnected()

bool TorControlConnection::IsConnected ( ) const

Check if the connection is established.

Definition at line 120 of file torcontrol.cpp.

Here is the caller graph for this function:

◆ ProcessBuffer()

bool TorControlConnection::ProcessBuffer ( )
private

Process complete lines from the receive buffer.

Definition at line 179 of file torcontrol.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReceiveAndProcess()

bool TorControlConnection::ReceiveAndProcess ( )

Read available data from socket and process complete replies.

Dispatches to registered reply handlers.

Returns
true if connection is still open, false if connection was closed

Definition at line 148 of file torcontrol.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitForData()

bool TorControlConnection::WaitForData ( std::chrono::milliseconds  timeout)

Wait for data to be available on the socket.

Parameters
[in]timeoutMaximum time to wait
Returns
true if data is available, false on timeout or error

Definition at line 131 of file torcontrol.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_interrupt

CThreadInterrupt& TorControlConnection::m_interrupt
private

Reference to interrupt object for clean shutdown.

Definition at line 104 of file torcontrol.h.

◆ m_message

TorControlReply TorControlConnection::m_message
private

Message being received.

Definition at line 108 of file torcontrol.h.

◆ m_recv_buffer

std::vector<std::byte> TorControlConnection::m_recv_buffer
private

Buffer for incoming data.

Definition at line 112 of file torcontrol.h.

◆ m_reply_handlers

std::deque<ReplyHandlerCB> TorControlConnection::m_reply_handlers
private

Response handlers.

Definition at line 110 of file torcontrol.h.

◆ m_sock

std::unique_ptr<Sock> TorControlConnection::m_sock
private

Socket for the connection.

Definition at line 106 of file torcontrol.h.


The documentation for this class was generated from the following files: