@@ -56,77 +56,6 @@ static const int MAX_LINE_LENGTH = 100000;
56
56
57
57
/* ***** Low-level TorControlConnection ********/
58
58
59
- /* * Reply from Tor, can be single or multi-line */
60
- class TorControlReply
61
- {
62
- public:
63
- TorControlReply () { Clear (); }
64
-
65
- int code;
66
- std::vector<std::string> lines;
67
-
68
- void Clear ()
69
- {
70
- code = 0 ;
71
- lines.clear ();
72
- }
73
- };
74
-
75
- /* * Low-level handling for Tor control connection.
76
- * Speaks the SMTP-like protocol as defined in torspec/control-spec.txt
77
- */
78
- class TorControlConnection
79
- {
80
- public:
81
- typedef std::function<void (TorControlConnection&)> ConnectionCB;
82
- typedef std::function<void (TorControlConnection &,const TorControlReply &)> ReplyHandlerCB;
83
-
84
- /* * Create a new TorControlConnection.
85
- */
86
- explicit TorControlConnection (struct event_base *base);
87
- ~TorControlConnection ();
88
-
89
- /* *
90
- * Connect to a Tor control port.
91
- * tor_control_center is address of the form host:port.
92
- * connected is the handler that is called when connection is successfully established.
93
- * disconnected is a handler that is called when the connection is broken.
94
- * Return true on success.
95
- */
96
- bool Connect (const std::string& tor_control_center, const ConnectionCB& connected, const ConnectionCB& disconnected);
97
-
98
- /* *
99
- * Disconnect from Tor control port.
100
- */
101
- void Disconnect ();
102
-
103
- /* * Send a command, register a handler for the reply.
104
- * A trailing CRLF is automatically added.
105
- * Return true on success.
106
- */
107
- bool Command (const std::string &cmd, const ReplyHandlerCB& reply_handler);
108
-
109
- /* * Response handlers for async replies */
110
- boost::signals2::signal<void (TorControlConnection &,const TorControlReply &)> async_handler;
111
- private:
112
- /* * Callback when ready for use */
113
- std::function<void (TorControlConnection&)> connected;
114
- /* * Callback when connection lost */
115
- std::function<void (TorControlConnection&)> disconnected;
116
- /* * Libevent event base */
117
- struct event_base *base;
118
- /* * Connection to control socket */
119
- struct bufferevent *b_conn;
120
- /* * Message being received */
121
- TorControlReply message;
122
- /* * Response handlers */
123
- std::deque<ReplyHandlerCB> reply_handlers;
124
-
125
- /* * Libevent handlers: internal */
126
- static void readcb (struct bufferevent *bev, void *ctx);
127
- static void eventcb (struct bufferevent *bev, short what, void *ctx);
128
- };
129
-
130
59
TorControlConnection::TorControlConnection (struct event_base *_base):
131
60
base(_base), b_conn(nullptr )
132
61
{
@@ -363,55 +292,6 @@ std::map<std::string,std::string> ParseTorReplyMapping(const std::string &s)
363
292
return mapping;
364
293
}
365
294
366
- /* ***** Bitcoin specific TorController implementation ********/
367
-
368
- /* * Controller that connects to Tor control socket, authenticate, then create
369
- * and maintain an ephemeral onion service.
370
- */
371
- class TorController
372
- {
373
- public:
374
- TorController (struct event_base * base, const std::string& tor_control_center, const CService& target);
375
- ~TorController ();
376
-
377
- /* * Get name of file to store private key in */
378
- fs::path GetPrivateKeyFile ();
379
-
380
- /* * Reconnect, after getting disconnected */
381
- void Reconnect ();
382
- private:
383
- struct event_base * base;
384
- const std::string m_tor_control_center;
385
- TorControlConnection conn;
386
- std::string private_key;
387
- std::string service_id;
388
- bool reconnect;
389
- struct event *reconnect_ev;
390
- float reconnect_timeout;
391
- CService service;
392
- const CService m_target;
393
- /* * Cookie for SAFECOOKIE auth */
394
- std::vector<uint8_t > cookie;
395
- /* * ClientNonce for SAFECOOKIE auth */
396
- std::vector<uint8_t > clientNonce;
397
-
398
- /* * Callback for ADD_ONION result */
399
- void add_onion_cb (TorControlConnection& conn, const TorControlReply& reply);
400
- /* * Callback for AUTHENTICATE result */
401
- void auth_cb (TorControlConnection& conn, const TorControlReply& reply);
402
- /* * Callback for AUTHCHALLENGE result */
403
- void authchallenge_cb (TorControlConnection& conn, const TorControlReply& reply);
404
- /* * Callback for PROTOCOLINFO result */
405
- void protocolinfo_cb (TorControlConnection& conn, const TorControlReply& reply);
406
- /* * Callback after successful connection */
407
- void connected_cb (TorControlConnection& conn);
408
- /* * Callback after connection lost or failed connection attempt */
409
- void disconnected_cb (TorControlConnection& conn);
410
-
411
- /* * Callback for reconnect timer */
412
- static void reconnect_cb (evutil_socket_t fd, short what, void *arg);
413
- };
414
-
415
295
TorController::TorController (struct event_base * _base, const std::string& tor_control_center, const CService& target):
416
296
base(_base),
417
297
m_tor_control_center(tor_control_center), conn(base), reconnect(true ), reconnect_ev(0 ),
0 commit comments