mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
net: mark TransportSerializer/m_serializer as const
The (V1)TransportSerializer instance CNode::m_serializer is used from multiple threads via PushMessage without protection by a mutex. This is only thread safe because the class does not have any mutable state, so document that by marking the methods and the object as "const".
This commit is contained in:
parent
06ebdc886f
commit
bbec32c9ad
2 changed files with 6 additions and 5 deletions
|
@ -797,7 +797,8 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds
|
|||
return msg;
|
||||
}
|
||||
|
||||
void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) {
|
||||
void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) const
|
||||
{
|
||||
// create dbl-sha256 checksum
|
||||
uint256 hash = Hash(msg.data);
|
||||
|
||||
|
|
|
@ -325,13 +325,13 @@ public:
|
|||
class TransportSerializer {
|
||||
public:
|
||||
// prepare message for transport (header construction, error-correction computation, payload encryption, etc.)
|
||||
virtual void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) = 0;
|
||||
virtual void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) const = 0;
|
||||
virtual ~TransportSerializer() {}
|
||||
};
|
||||
|
||||
class V1TransportSerializer : public TransportSerializer {
|
||||
class V1TransportSerializer : public TransportSerializer {
|
||||
public:
|
||||
void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) override;
|
||||
void prepareForTransport(CSerializedNetMsg& msg, std::vector<unsigned char>& header) const override;
|
||||
};
|
||||
|
||||
/** Information about a peer */
|
||||
|
@ -342,7 +342,7 @@ class CNode
|
|||
|
||||
public:
|
||||
std::unique_ptr<TransportDeserializer> m_deserializer;
|
||||
std::unique_ptr<TransportSerializer> m_serializer;
|
||||
std::unique_ptr<const TransportSerializer> m_serializer;
|
||||
|
||||
NetPermissionFlags m_permissionFlags{NetPermissionFlags::None};
|
||||
|
||||
|
|
Loading…
Reference in a new issue