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
4 changes: 2 additions & 2 deletions include/bitcoin/network/net/socket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class BCT_API socket

protected:
// These are thread safe.
const config::address address_;
std::atomic_bool stopped_{};
asio::strand strand_;
std::atomic_bool stopped_{};

// These are protected by strand (see also handle_accept).
asio::socket socket_;
config::address address_;
config::authority authority_{};

private:
Expand Down
12 changes: 9 additions & 3 deletions src/net/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ socket::socket(const logger& log, asio::io_context& service) NOEXCEPT
// authority_.port() nonzero implies outbound connection.
socket::socket(const logger& log, asio::io_context& service,
const config::address& address) NOEXCEPT
: address_(address),
strand_(service.get_executor()),
: strand_(service.get_executor()),
socket_(strand_),
address_(address),
reporter(log),
tracker<socket>(log)
{
Expand Down Expand Up @@ -228,8 +228,10 @@ void socket::handle_accept(const error::boost_code& ec,
{
// This is running in the acceptor (not socket) execution context.
// socket_ and authority_ are not guarded here, see comments on accept.
// address_ remains defaulted for inbound (accepted) connections.

if (!ec) authority_ = { socket_.remote_endpoint() };
if (!ec)
authority_ = { socket_.remote_endpoint() };

if (error::asio_is_canceled(ec))
{
Expand All @@ -256,6 +258,10 @@ void socket::handle_connect(const error::boost_code& ec,

authority_ = peer;

// Outgoing connection requires address_ for .inbound() resolution.
if (is_zero(address_.port()))
address_ = config::endpoint{ peer }.to_address();

if (error::asio_is_canceled(ec))
{
handler(error::operation_canceled);
Expand Down
41 changes: 40 additions & 1 deletion src/sessions/session_inbound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ void session_inbound::attach_handshake(const channel::ptr& channel,
const auto reject = settings().enable_reject;
const auto address_v2 = settings().enable_address_v2;

// protocol_version_70016 sends and receives send_address_v2 even though
// inbound connections do not accept addresses. There is no message to
// disable address broadcasting, so this is just allowed to upgrade.

// Address v2 can be disabled, independent of version.
if (is_configured(messages::level::bip155) && address_v2)
channel->attach<protocol_version_70016>(self, minimum_services,
Expand Down Expand Up @@ -248,7 +252,42 @@ void session_inbound::handle_channel_start(const code&,
void session_inbound::attach_protocols(
const channel::ptr& channel) NOEXCEPT
{
session::attach_protocols(channel);
BC_ASSERT_MSG(channel->stranded(), "channel strand");
BC_ASSERT_MSG(channel->paused(), "channel not paused for protocol attach");

const auto self = shared_from_this();

// Alert is deprecated, independent of version.
if (channel->is_negotiated(messages::level::alert_message) &&
settings().enable_alert)
channel->attach<protocol_alert_311>(self)->start();

// Reject is deprecated, independent of version.
if (channel->is_negotiated(messages::level::bip61) &&
settings().enable_reject)
channel->attach<protocol_reject_70002>(self)->start();

if (channel->is_negotiated(messages::level::bip31))
channel->attach<protocol_ping_60001>(self)->start();
else if (channel->is_negotiated(messages::level::version_message))
channel->attach<protocol_ping_106>(self)->start();

// Attach is overridden to disable inbound address protocols.

if (settings().enable_address_v2)
{
////// Sending address v2 is enabled in handshake.
////if (channel->send_address_v2())
//// channel->attach<protocol_address_out_70016>(self)->start();
}

if (settings().enable_address)
{
if (channel->is_negotiated(messages::level::getaddr_message))
channel->attach<protocol_address_out_209>(self)->start();
////else if (channel->is_negotiated(messages::level::version_message))
//// channel->attach<protocol_address_out_106>(self)->start();
}
}

void session_inbound::handle_channel_stop(const code& LOG_ONLY(ec),
Expand Down
Loading