aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2022-05-20 05:37:54 +1000
committerAnthony Towns <aj@erisian.com.au>2022-08-29 22:50:54 +1000
commitef26f2f421071986a3878a1a94b0149ae8e16fcd (patch)
treea156568bc6c1d947069a12bc743d7054347e9be2 /src/net.cpp
parentbbec32c9ad2fe213314db9d39aa1eacff2e0bc23 (diff)
downloadbitcoin-ef26f2f421071986a3878a1a94b0149ae8e16fcd.tar.xz
net: mark CNode unique_ptr members as const
Dereferencing a unique_ptr is not necessarily thread safe. The reason these are safe is because their values are set at construction and do not change later; so mark them as const and set them via the initializer list to guarantee that.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/net.cpp b/src/net.cpp
index cf0c9aef7b..535a5ce8e2 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -2723,7 +2723,9 @@ CNode::CNode(NodeId idIn,
ConnectionType conn_type_in,
bool inbound_onion,
std::unique_ptr<i2p::sam::Session>&& i2p_sam_session)
- : m_sock{sock},
+ : m_deserializer{std::make_unique<V1TransportDeserializer>(V1TransportDeserializer(Params(), idIn, SER_NETWORK, INIT_PROTO_VERSION))},
+ m_serializer{std::make_unique<V1TransportSerializer>(V1TransportSerializer())},
+ m_sock{sock},
m_connected{GetTime<std::chrono::seconds>()},
addr{addrIn},
addrBind{addrBindIn},
@@ -2746,9 +2748,6 @@ CNode::CNode(NodeId idIn,
} else {
LogPrint(BCLog::NET, "Added connection peer=%d\n", id);
}
-
- m_deserializer = std::make_unique<V1TransportDeserializer>(V1TransportDeserializer(Params(), id, SER_NETWORK, INIT_PROTO_VERSION));
- m_serializer = std::make_unique<V1TransportSerializer>(V1TransportSerializer());
}
bool CConnman::NodeFullyConnected(const CNode* pnode)