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