Skip to content

Commit

Permalink
Merge pull request #665 from evoskuil/master
Browse files Browse the repository at this point in the history
Stub in block_memory.
  • Loading branch information
evoskuil authored Aug 1, 2024
2 parents a40fbfd + 17e2296 commit 3875b74
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 22 deletions.
6 changes: 4 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ lib_LTLIBRARIES = src/libbitcoin-node.la
src_libbitcoin_node_la_CPPFLAGS = -I${srcdir}/include -DSYSCONFDIR=\"${sysconfdir}\" ${bitcoin_database_BUILD_CPPFLAGS} ${bitcoin_network_BUILD_CPPFLAGS}
src_libbitcoin_node_la_LIBADD = ${bitcoin_database_LIBS} ${bitcoin_network_LIBS}
src_libbitcoin_node_la_SOURCES = \
src/block_arena.cpp \
src/block_memory.cpp \
src/configuration.cpp \
src/error.cpp \
src/full_node.cpp \
src/memory.cpp \
src/parser.cpp \
src/settings.cpp \
src/chasers/chaser.cpp \
Expand Down Expand Up @@ -125,13 +126,14 @@ include_bitcoin_HEADERS = \

include_bitcoin_nodedir = ${includedir}/bitcoin/node
include_bitcoin_node_HEADERS = \
include/bitcoin/node/block_arena.hpp \
include/bitcoin/node/block_memory.hpp \
include/bitcoin/node/chase.hpp \
include/bitcoin/node/configuration.hpp \
include/bitcoin/node/define.hpp \
include/bitcoin/node/error.hpp \
include/bitcoin/node/events.hpp \
include/bitcoin/node/full_node.hpp \
include/bitcoin/node/memory.hpp \
include/bitcoin/node/parser.hpp \
include/bitcoin/node/settings.hpp \
include/bitcoin/node/version.hpp
Expand Down
3 changes: 2 additions & 1 deletion builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ add_definitions(
# Define ${CANONICAL_LIB_NAME} project.
#------------------------------------------------------------------------------
add_library( ${CANONICAL_LIB_NAME}
"../../src/block_arena.cpp"
"../../src/block_memory.cpp"
"../../src/configuration.cpp"
"../../src/error.cpp"
"../../src/full_node.cpp"
"../../src/memory.cpp"
"../../src/parser.cpp"
"../../src/settings.cpp"
"../../src/chasers/chaser.cpp"
Expand Down
6 changes: 4 additions & 2 deletions builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
<Import Project="$(ProjectDir)$(ProjectName).props" />
</ImportGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\src\block_arena.cpp" />
<ClCompile Include="..\..\..\..\src\block_memory.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_block.cpp" />
<ClCompile Include="..\..\..\..\src\chasers\chaser_check.cpp" />
Expand All @@ -87,7 +89,6 @@
<ClCompile Include="..\..\..\..\src\configuration.cpp" />
<ClCompile Include="..\..\..\..\src\error.cpp" />
<ClCompile Include="..\..\..\..\src\full_node.cpp" />
<ClCompile Include="..\..\..\..\src\memory.cpp" />
<ClCompile Include="..\..\..\..\src\parser.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol.cpp" />
<ClCompile Include="..\..\..\..\src\protocols\protocol_block_in.cpp" />
Expand All @@ -109,6 +110,8 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\include\bitcoin\node.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\block_arena.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\block_memory.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chase.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\chasers\chaser_block.hpp" />
Expand All @@ -128,7 +131,6 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\error.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\events.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\full_node.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\memory.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\parser.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_block_in.hpp" />
Expand Down
18 changes: 12 additions & 6 deletions builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\src\block_arena.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\block_memory.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\chasers\chaser.cpp">
<Filter>src\chasers</Filter>
</ClCompile>
Expand Down Expand Up @@ -90,9 +96,6 @@
<ClCompile Include="..\..\..\..\src\full_node.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\memory.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\parser.cpp">
<Filter>src</Filter>
</ClCompile>
Expand Down Expand Up @@ -152,6 +155,12 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node.hpp">
<Filter>include\bitcoin</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\block_arena.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\block_memory.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\chase.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
Expand Down Expand Up @@ -209,9 +218,6 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\full_node.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\memory.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\parser.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
Expand Down
3 changes: 2 additions & 1 deletion include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

#include <bitcoin/database.hpp>
#include <bitcoin/network.hpp>
#include <bitcoin/node/block_arena.hpp>
#include <bitcoin/node/block_memory.hpp>
#include <bitcoin/node/chase.hpp>
#include <bitcoin/node/configuration.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/error.hpp>
#include <bitcoin/node/events.hpp>
#include <bitcoin/node/full_node.hpp>
#include <bitcoin/node/memory.hpp>
#include <bitcoin/node/parser.hpp>
#include <bitcoin/node/settings.hpp>
#include <bitcoin/node/version.hpp>
Expand Down
42 changes: 42 additions & 0 deletions include/bitcoin/node/block_arena.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2011-2024 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_BLOCK_ARENA_HPP
#define LIBBITCOIN_NODE_BLOCK_ARENA_HPP

#include <bitcoin/system.hpp>
#include <bitcoin/node/define.hpp>

namespace libbitcoin {
namespace node {

class BCN_API block_arena final
: public arena
{
public:
block_arena() NOEXCEPT;

private:
void* do_allocate(size_t bytes, size_t align) THROWS override;
void do_deallocate(void* ptr, size_t bytes, size_t align) NOEXCEPT override;
bool do_is_equal(const arena& other) const NOEXCEPT override;
};
} // namespace node
} // namespace libbitcoin

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,29 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_MEMORY_HPP
#define LIBBITCOIN_NODE_MEMORY_HPP
#ifndef LIBBITCOIN_NODE_BLOCK_MEMORY_HPP
#define LIBBITCOIN_NODE_BLOCK_MEMORY_HPP

#include <shared_mutex>
#include <bitcoin/network.hpp>
#include <bitcoin/node/block_arena.hpp>
#include <bitcoin/node/define.hpp>

namespace libbitcoin {
namespace node {

class memory
class BCN_API block_memory final
: public network::memory
{
public:
using base = network::memory;
using base::base;
block_memory() NOEXCEPT;

arena* get_arena() NOEXCEPT override;
retainer::ptr get_retainer() NOEXCEPT override;

private:
block_arena arena_{};
std::shared_mutex mutex_{};
};

} // namespace node
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/node/full_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

#include <bitcoin/database.hpp>
#include <bitcoin/network.hpp>
#include <bitcoin/node/block_memory.hpp>
#include <bitcoin/node/chasers/chasers.hpp>
#include <bitcoin/node/configuration.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/memory.hpp>

namespace libbitcoin {
namespace node {
Expand Down Expand Up @@ -166,7 +166,7 @@ class BCN_API full_node

// These are thread safe.
const configuration& config_;
memory memory_;
block_memory memory_;
query& query_;

// These are protected by strand.
Expand Down
51 changes: 51 additions & 0 deletions src/block_arena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) 2011-2024 libbitcoin developers (see AUTHORS)
*
* This file is part of libbitcoin.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bitcoin/node/block_arena.hpp>

#include <bitcoin/system.hpp>

namespace libbitcoin {
namespace node {

block_arena::block_arena() NOEXCEPT
{
}

BC_PUSH_WARNING(NO_NEW_OR_DELETE)

void* block_arena::do_allocate(size_t bytes, size_t) THROWS
{
return ::operator new(bytes);
}

void block_arena::do_deallocate(void* ptr, size_t, size_t) NOEXCEPT
{
::operator delete(ptr);
}

BC_POP_WARNING()

bool block_arena::do_is_equal(const arena& other) const NOEXCEPT
{
// Do not cross the streams.
return &other == this;
}

} // namespace node
} // namespace libbitcoin
18 changes: 16 additions & 2 deletions src/memory.cpp → src/block_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <bitcoin/node/memory.hpp>
#include <bitcoin/node/block_memory.hpp>

#include <bitcoin/network.hpp>
#include <bitcoin/system.hpp>

namespace libbitcoin {
namespace node {

block_memory::block_memory() NOEXCEPT
{
}

arena* block_memory::get_arena() NOEXCEPT
{
return &arena_;
}

retainer::ptr block_memory::get_retainer() NOEXCEPT
{
return {};
}

} // namespace node
} // namespace libbitcoin
1 change: 0 additions & 1 deletion src/full_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <bitcoin/network.hpp>
#include <bitcoin/node/chasers/chasers.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/memory.hpp>
#include <bitcoin/node/sessions/sessions.hpp>

namespace libbitcoin {
Expand Down

0 comments on commit 3875b74

Please sign in to comment.