mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
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.
This commit is contained in:
parent
bbec32c9ad
commit
ef26f2f421
2 changed files with 5 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -341,8 +341,8 @@ class CNode
|
|||
friend struct ConnmanTestMsg;
|
||||
|
||||
public:
|
||||
std::unique_ptr<TransportDeserializer> m_deserializer;
|
||||
std::unique_ptr<const TransportSerializer> m_serializer;
|
||||
const std::unique_ptr<TransportDeserializer> m_deserializer; // Used only by SocketHandler thread
|
||||
const std::unique_ptr<const TransportSerializer> m_serializer;
|
||||
|
||||
NetPermissionFlags m_permissionFlags{NetPermissionFlags::None};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue