Skip to content

Commit 9f98474

Browse files
committed
Outgoing conn requires address_ for .inbound() resolution.
1 parent 37bb8f7 commit 9f98474

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

include/bitcoin/network/net/socket.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ class BCT_API socket
103103

104104
protected:
105105
// These are thread safe.
106-
const config::address address_;
107-
std::atomic_bool stopped_{};
108106
asio::strand strand_;
107+
std::atomic_bool stopped_{};
109108

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

114114
private:

src/net/socket.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ socket::socket(const logger& log, asio::io_context& service) NOEXCEPT
5050
// authority_.port() nonzero implies outbound connection.
5151
socket::socket(const logger& log, asio::io_context& service,
5252
const config::address& address) NOEXCEPT
53-
: address_(address),
54-
strand_(service.get_executor()),
53+
: strand_(service.get_executor()),
5554
socket_(strand_),
55+
address_(address),
5656
reporter(log),
5757
tracker<socket>(log)
5858
{
@@ -228,8 +228,10 @@ void socket::handle_accept(const error::boost_code& ec,
228228
{
229229
// This is running in the acceptor (not socket) execution context.
230230
// socket_ and authority_ are not guarded here, see comments on accept.
231+
// address_ remains defaulted for inbound (accepted) connections.
231232

232-
if (!ec) authority_ = { socket_.remote_endpoint() };
233+
if (!ec)
234+
authority_ = { socket_.remote_endpoint() };
233235

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

257259
authority_ = peer;
258260

261+
// Outgoing connection requires address_ for .inbound() resolution.
262+
if (is_zero(address_.port()))
263+
address_ = config::endpoint{ peer };
264+
259265
if (error::asio_is_canceled(ec))
260266
{
261267
handler(error::operation_canceled);

0 commit comments

Comments
 (0)