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

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

#include <torcontrol.h>

Inheritance diagram for TorControlConnection:
[legend]
Collaboration diagram for TorControlConnection:
[legend]

Public Types

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

Public Member Functions

 TorControlConnection (struct event_base *base)
 Create a new TorControlConnection. More...
 
 ~TorControlConnection ()
 
bool Connect (const std::string &tor_control_center, const ConnectionCB &connected, const ConnectionCB &disconnected)
 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...
 

Static Private Member Functions

static void readcb (struct bufferevent *bev, void *ctx)
 Libevent handlers: internal. More...
 
static void eventcb (struct bufferevent *bev, short what, void *ctx)
 

Private Attributes

std::function< void(TorControlConnection &)> connected
 Callback when ready for use. More...
 
std::function< void(TorControlConnection &)> disconnected
 Callback when connection lost. More...
 
struct event_base * base
 Libevent event base. More...
 
struct bufferevent * b_conn {nullptr}
 Connection to control socket. More...
 
TorControlReply message
 Message being received. More...
 
std::deque< ReplyHandlerCBreply_handlers
 Response handlers. 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 51 of file torcontrol.h.

Member Typedef Documentation

◆ ConnectionCB

Definition at line 54 of file torcontrol.h.

◆ ReplyHandlerCB

Definition at line 55 of file torcontrol.h.

Constructor & Destructor Documentation

◆ TorControlConnection()

TorControlConnection::TorControlConnection ( struct event_base *  base)
explicit

Create a new TorControlConnection.

Definition at line 68 of file torcontrol.cpp.

◆ ~TorControlConnection()

TorControlConnection::~TorControlConnection ( )

Definition at line 73 of file torcontrol.cpp.

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 185 of file torcontrol.cpp.

Here is the caller graph for this function:

◆ Connect()

bool TorControlConnection::Connect ( const std::string &  tor_control_center,
const ConnectionCB connected,
const ConnectionCB disconnected 
)

Connect to a Tor control port.

tor_control_center is address of the form host:port. connected is the handler that is called when connection is successfully established. disconnected is a handler that is called when the connection is broken. Return true on success.

Definition at line 141 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 178 of file torcontrol.cpp.

Here is the caller graph for this function:

◆ eventcb()

void TorControlConnection::eventcb ( struct bufferevent *  bev,
short  what,
void *  ctx 
)
staticprivate

Definition at line 124 of file torcontrol.cpp.

Here is the caller graph for this function:

◆ readcb()

void TorControlConnection::readcb ( struct bufferevent *  bev,
void *  ctx 
)
staticprivate

Libevent handlers: internal.

Definition at line 79 of file torcontrol.cpp.

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

Member Data Documentation

◆ b_conn

struct bufferevent* TorControlConnection::b_conn {nullptr}
private

Connection to control socket.

Definition at line 90 of file torcontrol.h.

◆ base

struct event_base* TorControlConnection::base
private

Libevent event base.

Definition at line 88 of file torcontrol.h.

◆ connected

std::function<void(TorControlConnection&)> TorControlConnection::connected
private

Callback when ready for use.

Definition at line 84 of file torcontrol.h.

◆ disconnected

std::function<void(TorControlConnection&)> TorControlConnection::disconnected
private

Callback when connection lost.

Definition at line 86 of file torcontrol.h.

◆ message

TorControlReply TorControlConnection::message
private

Message being received.

Definition at line 92 of file torcontrol.h.

◆ reply_handlers

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

Response handlers.

Definition at line 94 of file torcontrol.h.


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