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
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ include_bitcoin_node_protocols_HEADERS = \

include_bitcoin_node_sessionsdir = ${includedir}/bitcoin/node/sessions
include_bitcoin_node_sessions_HEADERS = \
include/bitcoin/node/sessions/attach.hpp \
include/bitcoin/node/sessions/session.hpp \
include/bitcoin/node/sessions/session_inbound.hpp \
include/bitcoin/node/sessions/session_manual.hpp \
include/bitcoin/node/sessions/session_outbound.hpp \
include/bitcoin/node/sessions/session_peer.hpp \
include/bitcoin/node/sessions/session_tcp.hpp \
include/bitcoin/node/sessions/sessions.hpp

Expand Down
2 changes: 1 addition & 1 deletion builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_transaction_in_106.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocol_transaction_out_106.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocols.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\attach.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_inbound.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_manual.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_outbound.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_peer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_tcp.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\sessions.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,6 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\protocols\protocols.hpp">
<Filter>include\bitcoin\node\protocols</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\attach.hpp">
<Filter>include\bitcoin\node\sessions</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session.hpp">
<Filter>include\bitcoin\node\sessions</Filter>
</ClInclude>
Expand All @@ -296,6 +293,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_outbound.hpp">
<Filter>include\bitcoin\node\sessions</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_peer.hpp">
<Filter>include\bitcoin\node\sessions</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_tcp.hpp">
<Filter>include\bitcoin\node\sessions</Filter>
</ClInclude>
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
#include <bitcoin/node/protocols/protocol_transaction_in_106.hpp>
#include <bitcoin/node/protocols/protocol_transaction_out_106.hpp>
#include <bitcoin/node/protocols/protocols.hpp>
#include <bitcoin/node/sessions/attach.hpp>
#include <bitcoin/node/sessions/session.hpp>
#include <bitcoin/node/sessions/session_inbound.hpp>
#include <bitcoin/node/sessions/session_manual.hpp>
#include <bitcoin/node/sessions/session_outbound.hpp>
#include <bitcoin/node/sessions/session_peer.hpp>
#include <bitcoin/node/sessions/session_tcp.hpp>
#include <bitcoin/node/sessions/sessions.hpp>

Expand Down
8 changes: 0 additions & 8 deletions include/bitcoin/node/sessions/session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ class BCN_API session
virtual bool is_recent() const NOEXCEPT;

protected:
template <class Sibling, class Shared>
std::shared_ptr<Sibling> shared_from_sibling() NOEXCEPT
{
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
return std::dynamic_pointer_cast<Sibling>(
dynamic_cast<Shared*>(this)->shared_from_this());
BC_POP_WARNING()
}

/// Constructors.
/// -----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/node/sessions/session_inbound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

#include <bitcoin/network.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/sessions/attach.hpp>
#include <bitcoin/node/sessions/session_peer.hpp>

namespace libbitcoin {
namespace node {

class session_inbound
: public attach<network::session_inbound>
: public session_peer<network::session_inbound>
{
public:
typedef std::shared_ptr<session_inbound> ptr;
using base = attach<network::session_inbound>;
using base = session_peer<network::session_inbound>;
using base::base;

protected:
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/node/sessions/session_manual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

#include <bitcoin/network.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/sessions/attach.hpp>
#include <bitcoin/node/sessions/session_peer.hpp>

namespace libbitcoin {
namespace node {

class session_manual
: public attach<network::session_manual>
: public session_peer<network::session_manual>
{
public:
typedef std::shared_ptr<session_manual> ptr;
using base = attach<network::session_manual>;
using base = session_peer<network::session_manual>;
using base::base;
};

Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/node/sessions/session_outbound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@

#include <bitcoin/network.hpp>
#include <bitcoin/node/define.hpp>
#include <bitcoin/node/sessions/attach.hpp>
#include <bitcoin/node/sessions/session_peer.hpp>

namespace libbitcoin {
namespace node {

class session_outbound
: public attach<network::session_outbound>
: public session_peer<network::session_outbound>
{
public:
typedef std::shared_ptr<session_outbound> ptr;
using base = attach<network::session_outbound>;
using base = session_peer<network::session_outbound>;
using base::base;
};

Expand Down
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_NODE_SESSIONS_ATTACH_HPP
#define LIBBITCOIN_NODE_SESSIONS_ATTACH_HPP
#ifndef LIBBITCOIN_NODE_SESSIONS_SESSION_PEER_HPP
#define LIBBITCOIN_NODE_SESSIONS_SESSION_PEER_HPP

#include <memory>
#include <utility>
Expand All @@ -31,17 +31,16 @@ namespace node {

class full_node;

/// Session base class template for network session attachment.
/// CRTP base class template for network session multiple derivation.
/// node::session does not derive from network::session (siblings).
/// This avoids the diamond inheritance problem between network/node.
/// Protocol contructors are templatized on Session, obtaining session.
template <class Session>
class attach
class session_peer
: public Session, public node::session
{
public:
template <typename... Args>
attach(full_node& node, uint64_t identifier, Args&&... args) NOEXCEPT
session_peer(full_node& node, uint64_t identifier, Args&&... args) NOEXCEPT
: Session(node, identifier, std::forward<Args>(args)...),
node::session(node)
{
Expand All @@ -52,8 +51,9 @@ class attach
network::result_handler&& handler) NOEXCEPT override
{
// Set the current top for version protocol, before handshake.
std::dynamic_pointer_cast<network::channel_peer>(channel)->
set_start_height(archive().get_top_confirmed());
const auto top = archive().get_top_confirmed();
const auto peer = std::dynamic_pointer_cast<channel_peer>(channel);
peer->set_start_height(top);

// Attach and execute appropriate version protocol.
Session::attach_handshake(channel, std::move(handler));
Expand All @@ -63,24 +63,26 @@ class attach
const network::channel::ptr& channel) NOEXCEPT override
{
using namespace system;
using namespace network::messages::peer;
using namespace network;
using namespace messages::peer;
using base = session_peer<Session>;

// this-> is required for dependent base access in CRTP.
const auto self = this->template shared_from_base<base>();
const auto relay = this->config().network.enable_relay;
const auto delay = this->config().node.delay_inbound;
const auto headers = this->config().node.headers_first;
const auto node_network = to_bool(bit_and<uint64_t>
(
this->config().network.services_maximum,
network::messages::peer::service::node_network
service::node_network
));
const auto node_client_filters = to_bool(bit_and<uint64_t>
(
this->config().network.services_maximum,
network::messages::peer::service::node_client_filters
service::node_client_filters
));

const auto self = session::shared_from_sibling<attach<Session>,
network::session>();

// Attach appropriate alert, reject, ping, and/or address protocols.
Session::attach_protocols(channel);

Expand All @@ -97,8 +99,7 @@ class attach
// This allows the node to support bip157 without supporting bip152.
///////////////////////////////////////////////////////////////////////

const auto peer = std::dynamic_pointer_cast<network::channel_peer>(
channel);
const auto peer = std::dynamic_pointer_cast<channel_peer>(channel);

// Node must advertise node_client_filters or no out filters.
if (node_client_filters && blocks_out &&
Expand Down Expand Up @@ -165,9 +166,12 @@ class attach
network::channel::ptr create_channel(
const network::socket::ptr& socket) NOEXCEPT override
{
return std::static_pointer_cast<network::channel>(
std::make_shared<node::channel_peer>(this->get_memory(), this->log,
socket, this->config(), this->create_key()));
// this-> is required for dependent base access in CRTP.
const auto channel = std::make_shared<node::channel_peer>(
this->get_memory(), this->log, socket, this->config(),
this->create_key());

return std::static_pointer_cast<network::channel>(channel);
}
};

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/node/sessions/sessions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#ifndef LIBBITCOIN_NODE_SESSIONS_SESSIONS_HPP
#define LIBBITCOIN_NODE_SESSIONS_SESSIONS_HPP

#include <bitcoin/node/sessions/attach.hpp>
#include <bitcoin/node/sessions/session.hpp>
#include <bitcoin/node/sessions/session_inbound.hpp>
#include <bitcoin/node/sessions/session_manual.hpp>
#include <bitcoin/node/sessions/session_outbound.hpp>
#include <bitcoin/node/sessions/session_peer.hpp>
#include <bitcoin/node/sessions/session_tcp.hpp>

#endif
Loading