Bitcoin Core  22.0.0
P2P Digital Currency
bitcoin-node.cpp
Go to the documentation of this file.
1 // Copyright (c) 2021 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 
5 #include <interfaces/echo.h>
6 #include <interfaces/init.h>
7 #include <interfaces/ipc.h>
8 #include <node/context.h>
9 #include <util/system.h>
10 
11 #include <memory>
12 
13 namespace init {
14 namespace {
15 const char* EXE_NAME = "bitcoin-node";
16 
17 class BitcoinNodeInit : public interfaces::Init
18 {
19 public:
20  BitcoinNodeInit(NodeContext& node, const char* arg0)
21  : m_node(node),
22  m_ipc(interfaces::MakeIpc(EXE_NAME, arg0, *this))
23  {
24  m_node.args = &gArgs;
25  m_node.init = this;
26  }
27  std::unique_ptr<interfaces::Echo> makeEcho() override { return interfaces::MakeEcho(); }
28  interfaces::Ipc* ipc() override { return m_ipc.get(); }
30  std::unique_ptr<interfaces::Ipc> m_ipc;
31 };
32 } // namespace
33 } // namespace init
34 
35 namespace interfaces {
36 std::unique_ptr<Init> MakeNodeInit(NodeContext& node, int argc, char* argv[], int& exit_status)
37 {
38  auto init = std::make_unique<init::BitcoinNodeInit>(node, argc > 0 ? argv[0] : "");
39  // Check if bitcoin-node is being invoked as an IPC server. If so, then
40  // bypass normal execution and just respond to requests over the IPC
41  // channel and return null.
42  if (init->m_ipc->startSpawnedProcess(argc, argv, exit_status)) {
43  return nullptr;
44  }
45  return init;
46 }
47 } // namespace interfaces
std::unique_ptr< Echo > MakeEcho()
Return implementation of Echo interface.
Definition: echo.cpp:17
interfaces::Init * init
Init interface for initializing current process and connecting to other processes.
Definition: context.h:41
NodeContext & m_node
NodeContext struct containing references to chain state and connection state.
Definition: context.h:39
std::unique_ptr< Init > MakeNodeInit(NodeContext &node, int argc, char *argv[], int &exit_status)
Return implementation of Init interface for the node process.
std::unique_ptr< Ipc > MakeIpc(const char *exe_name, const char *process_argv0, Init &init)
Return implementation of Ipc interface.
Definition: interfaces.cpp:73
Definition: protocol.cpp:27
ArgsManager * args
Definition: context.h:49
std::unique_ptr< interfaces::Ipc > m_ipc
ArgsManager gArgs
Definition: system.cpp:84
Initial interface created when a process is first started, and used to give and get access to other i...
Definition: init.h:26
Interface providing access to interprocess-communication (IPC) functionality.
Definition: ipc.h:40