Bitcoin Core 31.99.0
P2P Digital Currency
torcontrol.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6#include <test/fuzz/fuzz.h>
7#include <test/fuzz/util.h>
9#include <torcontrol.h>
10
11#include <cstdint>
12#include <string>
13#include <vector>
14
16{
17 static const auto testing_setup = MakeNoLogFileContext<>();
18}
19
21{
22 FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
23
24 TorController tor_controller;
25 CThreadInterrupt interrupt;
26 TorControlConnection conn{interrupt};
27
29 TorControlReply tor_control_reply;
32 [&] {
33 tor_control_reply.code = TOR_REPLY_OK;
34 },
35 [&] {
36 tor_control_reply.code = TOR_REPLY_UNRECOGNIZED;
37 },
38 [&] {
39 tor_control_reply.code = TOR_REPLY_SYNTAX_ERROR;
40 },
41 [&] {
42 tor_control_reply.code = fuzzed_data_provider.ConsumeIntegral<int>();
43 });
45
48 [&] {
49 tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/true);
50 },
51 [&] {
52 tor_controller.add_onion_cb(conn, tor_control_reply, /*pow_was_enabled=*/false);
53 },
54 [&] {
55 tor_controller.auth_cb(conn, tor_control_reply);
56 },
57 [&] {
58 tor_controller.authchallenge_cb(conn, tor_control_reply);
59 },
60 [&] {
61 tor_controller.protocolinfo_cb(conn, tor_control_reply);
62 },
63 [&] {
64 tor_controller.get_socks_cb(conn, tor_control_reply);
65 });
66 }
67}
A helper class for interruptible sleeps.
Low-level handling for Tor control connection.
Definition: torcontrol.h:56
Reply from Tor, can be single or multi-line.
Definition: torcontrol.h:38
std::vector< std::string > lines
Definition: torcontrol.h:43
Controller that connects to Tor control socket, authenticate, then create and maintain an ephemeral o...
Definition: torcontrol.h:123
void get_socks_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for GETINFO net/listeners/socks result.
Definition: torcontrol.cpp:427
void add_onion_cb(TorControlConnection &conn, const TorControlReply &reply, bool pow_was_enabled)
Callback for ADD_ONION result.
Definition: torcontrol.cpp:508
void authchallenge_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for AUTHCHALLENGE result.
Definition: torcontrol.cpp:601
void auth_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for AUTHENTICATE result.
Definition: torcontrol.cpp:549
void protocolinfo_cb(TorControlConnection &conn, const TorControlReply &reply)
Callback for PROTOCOLINFO result.
Definition: torcontrol.cpp:640
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition: fuzz.h:22
Definition: basic.cpp:8
void initialize_torcontrol()
Definition: torcontrol.cpp:15
FUZZ_TARGET(torcontrol,.init=initialize_torcontrol)
Definition: torcontrol.cpp:20
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
Definition: util.h:35
std::vector< std::string > ConsumeRandomLengthStringVector(FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16, const size_t max_string_length=16) noexcept
Definition: util.h:73
constexpr int TOR_REPLY_SYNTAX_ERROR
Syntax error in command argument.
Definition: torcontrol.h:32
constexpr int TOR_REPLY_OK
Tor control reply code.
Definition: torcontrol.h:30
constexpr int TOR_REPLY_UNRECOGNIZED
Definition: torcontrol.h:31
FuzzedDataProvider & fuzzed_data_provider
Definition: fees.cpp:39