Inside Bitcoin
Opening the selected file…
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) 2021-present 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 <interfaces/echo.h> // IWYU pragma: associated6#include <interfaces/handler.h> // IWYU pragma: associated8#include <util/btcsignals.h>10#include <memory>11#include <utility>13namespace common {14namespace {15class CleanupHandler : public interfaces::Handler16{17public:18explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}19~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }20void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }21std::function<void()> m_cleanup;22};24class SignalHandler : public interfaces::Handler25{26public:27explicit SignalHandler(btcsignals::connection connection) : m_connection(std::move(connection)) {}29void disconnect() override { m_connection.disconnect(); }31btcsignals::scoped_connection m_connection;32};34class EchoImpl : public interfaces::Echo35{36public:37std::string echo(const std::string& echo) override { return echo; }38};39} // namespace40} // namespace common42namespace interfaces {43std::unique_ptr<Handler> MakeCleanupHandler(std::function<void()> cleanup)44{45return std::make_unique<common::CleanupHandler>(std::move(cleanup));46}48std::unique_ptr<Handler> MakeSignalHandler(btcsignals::connection connection)49{50return std::make_unique<common::SignalHandler>(std::move(connection));51}53std::unique_ptr<Echo> MakeEcho() { return std::make_unique<common::EchoImpl>(); }54} // namespace interfaces