Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ src_libbitcoin_network_la_SOURCES = \
src/settings.cpp \
src/async/deadline.cpp \
src/async/logger.cpp \
src/async/reporter.cpp \
src/async/thread.cpp \
src/async/threadpool.cpp \
src/async/time.cpp \
Expand Down Expand Up @@ -217,12 +218,13 @@ include_bitcoin_network_async_HEADERS = \
include/bitcoin/network/async/enable_shared_from_base.hpp \
include/bitcoin/network/async/handlers.hpp \
include/bitcoin/network/async/logger.hpp \
include/bitcoin/network/async/reporter.hpp \
include/bitcoin/network/async/subscriber.hpp \
include/bitcoin/network/async/thread.hpp \
include/bitcoin/network/async/threadpool.hpp \
include/bitcoin/network/async/time.hpp \
include/bitcoin/network/async/timer.hpp \
include/bitcoin/network/async/track.hpp
include/bitcoin/network/async/tracker.hpp

include_bitcoin_network_configdir = ${includedir}/bitcoin/network/config
include_bitcoin_network_config_HEADERS = \
Expand All @@ -234,7 +236,7 @@ include_bitcoin_network_impl_asyncdir = ${includedir}/bitcoin/network/impl/async
include_bitcoin_network_impl_async_HEADERS = \
include/bitcoin/network/impl/async/enable_shared_from_base.ipp \
include/bitcoin/network/impl/async/subscriber.ipp \
include/bitcoin/network/impl/async/track.ipp
include/bitcoin/network/impl/async/tracker.ipp

include_bitcoin_network_messagesdir = ${includedir}/bitcoin/network/messages
include_bitcoin_network_messages_HEADERS = \
Expand Down
1 change: 1 addition & 0 deletions builds/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ add_library( ${CANONICAL_LIB_NAME}
"../../src/settings.cpp"
"../../src/async/deadline.cpp"
"../../src/async/logger.cpp"
"../../src/async/reporter.cpp"
"../../src/async/thread.cpp"
"../../src/async/threadpool.cpp"
"../../src/async/time.cpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<ItemGroup>
<ClCompile Include="..\..\..\..\src\async\deadline.cpp" />
<ClCompile Include="..\..\..\..\src\async\logger.cpp" />
<ClCompile Include="..\..\..\..\src\async\reporter.cpp" />
<ClCompile Include="..\..\..\..\src\async\thread.cpp" />
<ClCompile Include="..\..\..\..\src\async\threadpool.cpp" />
<ClCompile Include="..\..\..\..\src\async\time.cpp" />
Expand Down Expand Up @@ -152,12 +153,13 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\enable_shared_from_base.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\handlers.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\logger.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\reporter.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\subscriber.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\thread.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\threadpool.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\time.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\timer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\track.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\tracker.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\boost.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\config\authority.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\network\config\config.hpp" />
Expand Down Expand Up @@ -238,7 +240,7 @@
<ItemGroup>
<None Include="..\..\..\..\include\bitcoin\network\impl\async\enable_shared_from_base.ipp" />
<None Include="..\..\..\..\include\bitcoin\network\impl\async\subscriber.ipp" />
<None Include="..\..\..\..\include\bitcoin\network\impl\async\track.ipp" />
<None Include="..\..\..\..\include\bitcoin\network\impl\async\tracker.ipp" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<ClCompile Include="..\..\..\..\src\async\logger.cpp">
<Filter>src\async</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\async\reporter.cpp">
<Filter>src\async</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\async\thread.cpp">
<Filter>src\async</Filter>
</ClCompile>
Expand Down Expand Up @@ -302,6 +305,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\logger.hpp">
<Filter>include\bitcoin\network\async</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\reporter.hpp">
<Filter>include\bitcoin\network\async</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\subscriber.hpp">
<Filter>include\bitcoin\network\async</Filter>
</ClInclude>
Expand All @@ -317,7 +323,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\timer.hpp">
<Filter>include\bitcoin\network\async</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\track.hpp">
<ClInclude Include="..\..\..\..\include\bitcoin\network\async\tracker.hpp">
<Filter>include\bitcoin\network\async</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\network\boost.hpp">
Expand Down Expand Up @@ -556,7 +562,7 @@
<None Include="..\..\..\..\include\bitcoin\network\impl\async\subscriber.ipp">
<Filter>include\bitcoin\network\impl\async</Filter>
</None>
<None Include="..\..\..\..\include\bitcoin\network\impl\async\track.ipp">
<None Include="..\..\..\..\include\bitcoin\network\impl\async\tracker.ipp">
<Filter>include\bitcoin\network\impl\async</Filter>
</None>
<None Include="packages.config" />
Expand Down
3 changes: 2 additions & 1 deletion include/bitcoin/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
#include <bitcoin/network/async/enable_shared_from_base.hpp>
#include <bitcoin/network/async/handlers.hpp>
#include <bitcoin/network/async/logger.hpp>
#include <bitcoin/network/async/reporter.hpp>
#include <bitcoin/network/async/subscriber.hpp>
#include <bitcoin/network/async/thread.hpp>
#include <bitcoin/network/async/threadpool.hpp>
#include <bitcoin/network/async/time.hpp>
#include <bitcoin/network/async/timer.hpp>
#include <bitcoin/network/async/track.hpp>
#include <bitcoin/network/async/tracker.hpp>
#include <bitcoin/network/config/authority.hpp>
#include <bitcoin/network/config/config.hpp>
#include <bitcoin/network/config/endpoint.hpp>
Expand Down
3 changes: 2 additions & 1 deletion include/bitcoin/network/async/async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
#include <bitcoin/network/async/enable_shared_from_base.hpp>
#include <bitcoin/network/async/handlers.hpp>
#include <bitcoin/network/async/logger.hpp>
#include <bitcoin/network/async/reporter.hpp>
#include <bitcoin/network/async/subscriber.hpp>
#include <bitcoin/network/async/thread.hpp>
#include <bitcoin/network/async/threadpool.hpp>
#include <bitcoin/network/async/time.hpp>
#include <bitcoin/network/async/timer.hpp>
#include <bitcoin/network/async/track.hpp>
#include <bitcoin/network/async/tracker.hpp>

#endif
4 changes: 2 additions & 2 deletions include/bitcoin/network/async/deadline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <bitcoin/network/async/logger.hpp>
#include <bitcoin/network/async/time.hpp>
#include <bitcoin/network/async/thread.hpp>
#include <bitcoin/network/async/track.hpp>
#include <bitcoin/network/async/tracker.hpp>
#include <bitcoin/network/define.hpp>
#include <bitcoin/network/error.hpp>

Expand All @@ -37,7 +37,7 @@ namespace network {
/// This simplifies invocation, eliminates boost-specific error handling and
/// makes timer firing and cancellation conditions safe for shared objects.
class BCT_API deadline final
: public std::enable_shared_from_this<deadline>, public track<deadline>
: public std::enable_shared_from_this<deadline>, protected tracker<deadline>
{
public:
DELETE_COPY_MOVE(deadline);
Expand Down
44 changes: 44 additions & 0 deletions include/bitcoin/network/async/reporter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2011-2022 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_NETWORK_ASYNC_REPORTER_HPP
#define LIBBITCOIN_NETWORK_ASYNC_REPORTER_HPP

#include <bitcoin/network/async/logger.hpp>
#include <bitcoin/network/define.hpp>

namespace libbitcoin {
namespace network {

class BCT_API reporter
{
protected:
reporter(const logger& log) NOEXCEPT;

public:
const logger& log() const NOEXCEPT;

private:
// This is thread safe.
const logger& log_;
};

} // namespace network
} // namespace libbitcoin

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* 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_NETWORK_ASYNC_TRACK_HPP
#define LIBBITCOIN_NETWORK_ASYNC_TRACK_HPP
#ifndef LIBBITCOIN_NETWORK_ASYNC_TRACKER_HPP
#define LIBBITCOIN_NETWORK_ASYNC_TRACKER_HPP

#include <atomic>
#include <bitcoin/network/async/logger.hpp>
Expand All @@ -26,19 +26,14 @@
namespace libbitcoin {
namespace network {

/// Thread safe, base class.
/// Class to log changes in the reference count of shared objects.
template <class Shared, bool Track = true>
class track
template <class Class>
class tracker
{
protected:
DEFAULT_COPY_MOVE(track);
DEFAULT_COPY_MOVE(tracker);

track(const logger& log) NOEXCEPT;
~track() NOEXCEPT;

public:
const logger& get_log() const NOEXCEPT;
tracker(const logger& log) NOEXCEPT;
~tracker() NOEXCEPT;

private:
// These are thread safe.
Expand All @@ -49,6 +44,6 @@ class track
} // namespace network
} // namespace libbitcoin

#include <bitcoin/network/impl/async/track.ipp>
#include <bitcoin/network/impl/async/tracker.ipp>

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* 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_NETWORK_ASYNC_TRACK_IPP
#define LIBBITCOIN_NETWORK_ASYNC_TRACK_IPP
#ifndef LIBBITCOIN_NETWORK_ASYNC_TRACKER_IPP
#define LIBBITCOIN_NETWORK_ASYNC_TRACKER_IPP

#include <atomic>
#include <typeinfo>
Expand All @@ -28,40 +28,34 @@
namespace libbitcoin {
namespace network {

template <class Shared, bool Track>
std::atomic<size_t> track<Shared, Track>::instances_(0);
template <class Class>
std::atomic<size_t> tracker<Class>::instances_(zero);

template <class Shared, bool Track>
track<Shared, Track>::track(const logger& log) NOEXCEPT
template <class Class>
tracker<Class>::tracker(const logger& log) NOEXCEPT
: log_(log)
{
if constexpr (Track && bc::build_checked)
if constexpr (build_checked)
{
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
log_.write() << typeid(Shared).name()
log_.write() << typeid(Class).name()
<< "(" << ++instances_ << ")" << std::endl;
BC_POP_WARNING()
}
}

template <class Shared, bool Track>
track<Shared, Track>::~track() NOEXCEPT
template <class Class>
tracker<Class>::~tracker() NOEXCEPT
{
if constexpr (Track && bc::build_checked)
if constexpr (build_checked)
{
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
log_.write() << typeid(Shared).name()
log_.write() << typeid(Class).name()
<< "(" << --instances_ << ")~" << std::endl;
BC_POP_WARNING()
}
}

template <class Shared, bool Track>
const logger& track<Shared, Track>::get_log() const NOEXCEPT
{
return log_;
}

} // namespace network
} // namespace libbitcoin

Expand Down
3 changes: 2 additions & 1 deletion include/bitcoin/network/net/acceptor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace network {
/// Create inbound socket connections.
/// Stop is thread safe and idempotent, may be called multiple times.
class BCT_API acceptor
: public std::enable_shared_from_this<acceptor>, public track<acceptor>
: public std::enable_shared_from_this<acceptor>, public reporter,
protected tracker<acceptor>
{
public:
DELETE_COPY_MOVE(acceptor);
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/network/net/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class session;
/// * See proxy for its thread safety constraints.
/// A channel is a proxy with logged timers and state.
class BCT_API channel
: public proxy, public track<channel>
: public proxy, protected tracker<channel>
{
public:
DELETE_COPY_MOVE(channel);
Expand Down
3 changes: 2 additions & 1 deletion include/bitcoin/network/net/connector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ namespace network {
/// Create outbound socket connections.
/// Stop is thread safe and idempotent, may be called multiple times.
class BCT_API connector
: public std::enable_shared_from_this<connector>, public track<connector>
: public std::enable_shared_from_this<connector>, public reporter,
protected tracker<connector>
{
public:
DELETE_COPY_MOVE(connector);
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/network/net/hosts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace network {
/// The file is a line-oriented set of config::authority serializations.
/// Duplicate addresses and those with zero-valued ports are disacarded.
class BCT_API hosts
: public track<hosts>
: public reporter, protected tracker<hosts>
{
public:
DELETE_COPY_MOVE(hosts);
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/network/net/proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace network {
/// notify/send_bytes are protected/virtual for test access only.
/// Handles all channel communication, error handling, and logging.
class BCT_API proxy
: public enable_shared_from_base<proxy>, public track<proxy, false>
: public enable_shared_from_base<proxy>, public reporter
{
public:
DELETE_COPY_MOVE(proxy);
Expand Down
3 changes: 2 additions & 1 deletion include/bitcoin/network/net/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace network {
/// Stop is thread safe and idempotent, may be called multiple times.
/// All handlers (except accept) are posted to the internal strand.
class BCT_API socket
: public std::enable_shared_from_this<socket>, public track<socket>
: public std::enable_shared_from_this<socket>, public reporter,
protected tracker<socket>
{
public:
DELETE_COPY_MOVE(socket);
Expand Down
5 changes: 1 addition & 4 deletions include/bitcoin/network/p2p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace network {
/// * attach must be called from channel strand.
/// * close must not be called concurrently or from any threadpool thread.
class BCT_API p2p
: public enable_shared_from_base<p2p>
: public enable_shared_from_base<p2p>, public reporter, protected tracker<p2p>
{
public:
typedef std::shared_ptr<p2p> ptr;
Expand Down Expand Up @@ -139,9 +139,6 @@ class BCT_API p2p
/// Network configuration settings.
const settings& network_settings() const NOEXCEPT;

/// Return a logging instance.
const logger& log() const NOEXCEPT;

/// Return a reference to the network io_context (thread safe).
asio::io_context& service() NOEXCEPT;

Expand Down
Loading