diff --git a/src/net.cpp b/src/net.cpp index a31b2a5efc..8e596cb6b3 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -932,7 +932,8 @@ CNetMessage V1TransportDeserializer::GetMessage(const std::chrono::microseconds return msg; } -void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vector& header) { +void V1TransportSerializer::prepareForTransport(CSerializedNetMsg& msg, std::vector& header) const +{ // create dbl-sha256 checksum uint256 hash = Hash(msg.data); @@ -4126,7 +4127,9 @@ ServiceFlags CConnman::GetLocalServices() const unsigned int CConnman::GetReceiveFloodSize() const { return nReceiveFloodSize; } CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, std::shared_ptr sock, const CAddress& addrIn, uint64_t nKeyedNetGroupIn, uint64_t nLocalHostNonceIn, const CAddress& addrBindIn, const std::string& addrNameIn, ConnectionType conn_type_in, bool inbound_onion, std::unique_ptr&& i2p_sam_session) - : m_sock{sock}, + : m_deserializer{std::make_unique(V1TransportDeserializer(Params(), idIn, SER_NETWORK, INIT_PROTO_VERSION))}, + m_serializer{std::make_unique(V1TransportSerializer())}, + m_sock{sock}, m_connected{GetTime()}, addr{addrIn}, addrBind{addrBindIn}, @@ -4150,9 +4153,6 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, std::shared_ptr s } else { LogPrint(BCLog::NET, "Added connection peer=%d\n", id); } - - m_deserializer = std::make_unique(V1TransportDeserializer(Params(), id, SER_NETWORK, INIT_PROTO_VERSION)); - m_serializer = std::make_unique(V1TransportSerializer()); } bool CConnman::NodeFullyConnected(const CNode* pnode) diff --git a/src/net.h b/src/net.h index e2d258e703..def5098b38 100644 --- a/src/net.h +++ b/src/net.h @@ -427,13 +427,13 @@ public: class TransportSerializer { public: // prepare message for transport (header construction, error-correction computation, payload encryption, etc.) - virtual void prepareForTransport(CSerializedNetMsg& msg, std::vector& header) = 0; + virtual void prepareForTransport(CSerializedNetMsg& msg, std::vector& header) const = 0; virtual ~TransportSerializer() {} }; -class V1TransportSerializer : public TransportSerializer { +class V1TransportSerializer : public TransportSerializer { public: - void prepareForTransport(CSerializedNetMsg& msg, std::vector& header) override; + void prepareForTransport(CSerializedNetMsg& msg, std::vector& header) const override; }; /** Information about a peer */ @@ -443,10 +443,10 @@ class CNode friend struct ConnmanTestMsg; public: - std::unique_ptr m_deserializer; - std::unique_ptr m_serializer; + const std::unique_ptr m_deserializer; // Used only by SocketHandler thread + const std::unique_ptr m_serializer; - NetPermissionFlags m_permissionFlags{ NetPermissionFlags::None }; + NetPermissionFlags m_permissionFlags{NetPermissionFlags::None}; // treated as const outside of fuzz tester std::atomic nServices{NODE_NONE}; /** @@ -472,7 +472,7 @@ public: RecursiveMutex cs_vProcessMsg; std::list vProcessMsg GUARDED_BY(cs_vProcessMsg); - size_t nProcessQueueSize{0}; + size_t nProcessQueueSize GUARDED_BY(cs_vProcessMsg){0}; RecursiveMutex cs_sendProcessing; @@ -501,7 +501,7 @@ public: * from the wire. This cleaned string can safely be logged or displayed. */ std::string cleanSubVer GUARDED_BY(m_subver_mutex){}; - bool m_prefer_evict{false}; // This peer is preferred for eviction. + bool m_prefer_evict{false}; // This peer is preferred for eviction. (treated as const) bool HasPermission(NetPermissionFlags permission) const { return NetPermissions::HasFlag(m_permissionFlags, permission); } diff --git a/src/net_processing.cpp b/src/net_processing.cpp index c7cb7cb82a..77ed5bb9b2 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -519,14 +519,14 @@ private: std::atomic m_best_height{-1}; /** Next time to check for stale tip */ - std::chrono::seconds m_stale_tip_check_time{0s}; + std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s}; /** Whether this node is running in blocks only mode */ const bool m_ignore_incoming_txs; /** Whether we've completed initial sync yet, for determining when to turn * on extra block-relay-only peers. */ - bool m_initial_sync_finished{false}; + bool m_initial_sync_finished GUARDED_BY(cs_main){false}; /** Protects m_peer_map. This mutex must not be locked while holding a lock * on any of the mutexes inside a Peer object. */