![]() |
Bitcoin Core 31.99.0
P2P Digital Currency
|
Low-level handling for Tor control connection. More...
#include <torcontrol.h>
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 | |
| CThreadInterrupt & | m_interrupt |
| Reference to interrupt object for clean shutdown. More... | |
| std::unique_ptr< Sock > | m_sock |
| Socket for the connection. More... | |
| TorControlReply | m_message |
| Message being received. More... | |
| std::deque< ReplyHandlerCB > | m_reply_handlers |
| Response handlers. More... | |
| std::vector< std::byte > | m_recv_buffer |
| Buffer for incoming data. More... | |
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.
| typedef std::function<void(TorControlConnection &,const TorControlReply &)> TorControlConnection::ReplyHandlerCB |
Definition at line 58 of file torcontrol.h.
|
explicit |
Create a new TorControlConnection.
Definition at line 76 of file torcontrol.cpp.
| TorControlConnection::~TorControlConnection | ( | ) |
| 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.
| 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.
| void TorControlConnection::Disconnect | ( | ) |
Disconnect from Tor control port.
Definition at line 112 of file torcontrol.cpp.
| bool TorControlConnection::IsConnected | ( | ) | const |
Check if the connection is established.
Definition at line 120 of file torcontrol.cpp.
|
private |
Process complete lines from the receive buffer.
Definition at line 179 of file torcontrol.cpp.
| bool TorControlConnection::ReceiveAndProcess | ( | ) |
Read available data from socket and process complete replies.
Dispatches to registered reply handlers.
Definition at line 148 of file torcontrol.cpp.
| bool TorControlConnection::WaitForData | ( | std::chrono::milliseconds | timeout | ) |
Wait for data to be available on the socket.
| [in] | timeout | Maximum time to wait |
Definition at line 131 of file torcontrol.cpp.
|
private |
Reference to interrupt object for clean shutdown.
Definition at line 104 of file torcontrol.h.
|
private |
Message being received.
Definition at line 108 of file torcontrol.h.
|
private |
Buffer for incoming data.
Definition at line 112 of file torcontrol.h.
|
private |
Response handlers.
Definition at line 110 of file torcontrol.h.
|
private |
Socket for the connection.
Definition at line 106 of file torcontrol.h.