Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <common/args.h>6#include <compat/compat.h>7#include <i2p.h>8#include <netaddress.h>9#include <netbase.h>10#include <test/fuzz/FuzzedDataProvider.h>11#include <test/fuzz/fuzz.h>12#include <test/fuzz/util.h>13#include <test/fuzz/util/net.h>14#include <test/fuzz/util/threadinterrupt.h>15#include <test/util/setup_common.h>16#include <test/util/time.h>17#include <util/fs_helpers.h>18#include <util/threadinterrupt.h>20void initialize_i2p()21{22static const auto testing_setup = MakeNoLogFileContext<>();23}25FUZZ_TARGET(i2p, .init = initialize_i2p)26{27SeedRandomStateForTest(SeedRand::ZEROS);28FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};30FakeNodeClock clock{ConsumeTime(fuzzed_data_provider)};31FakeSteadyClock steady_clock;33// Mock CreateSock() to create FuzzedSock.34auto CreateSockOrig = CreateSock;35CreateSock = [&fuzzed_data_provider, &steady_clock](int, int, int) {36return std::make_unique<FuzzedSock>(fuzzed_data_provider, steady_clock);37};39const fs::path private_key_path = gArgs.GetDataDirNet() / "fuzzed_i2p_private_key";40const CService addr{in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT), 7656};41const Proxy sam_proxy{addr, /*tor_stream_isolation=*/false};42auto interrupt{ConsumeThreadInterrupt(fuzzed_data_provider)};44i2p::sam::Session session{private_key_path, sam_proxy, interrupt};45i2p::Connection conn;47if (session.Listen(conn)) {48if (session.Accept(conn)) {49try {50(void)conn.sock->RecvUntilTerminator('\n', 10ms, *interrupt, i2p::sam::MAX_MSG_SIZE);51} catch (const std::runtime_error&) {52}53}54}56bool proxy_error;58if (session.Connect(CService{}, conn, proxy_error)) {59try {60conn.sock->SendComplete("verack\n", 10ms, *interrupt);61} catch (const std::runtime_error&) {62}63}65fs::remove(private_key_path);67CreateSock = CreateSockOrig;68}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.