net: construct CNodeStates in place

This commit is contained in:
Cory Fields 2016-10-26 17:41:44 -04:00 committed by Pieter Wuille
parent 440f1d3e4c
commit 7588b85cd2
1 changed files with 6 additions and 6 deletions

View File

@ -257,7 +257,7 @@ struct CBlockReject {
*/ */
struct CNodeState { struct CNodeState {
//! The peer's address //! The peer's address
CService address; const CService address;
//! Whether we have a fully established connection. //! Whether we have a fully established connection.
bool fCurrentlyConnected; bool fCurrentlyConnected;
//! Accumulated misbehaviour score for this peer. //! Accumulated misbehaviour score for this peer.
@ -265,7 +265,7 @@ struct CNodeState {
//! Whether this peer should be disconnected and banned (unless whitelisted). //! Whether this peer should be disconnected and banned (unless whitelisted).
bool fShouldBan; bool fShouldBan;
//! String name of this peer (debugging/logging purposes). //! String name of this peer (debugging/logging purposes).
std::string name; const std::string name;
//! List of asynchronously-determined block rejections to notify this peer about. //! List of asynchronously-determined block rejections to notify this peer about.
std::vector<CBlockReject> rejects; std::vector<CBlockReject> rejects;
//! The best known block we know this peer has announced. //! The best known block we know this peer has announced.
@ -309,7 +309,7 @@ struct CNodeState {
*/ */
bool fSupportsDesiredCmpctVersion; bool fSupportsDesiredCmpctVersion;
CNodeState() { CNodeState(CAddress addrIn, std::string addrNameIn) : address(addrIn), name(addrNameIn) {
fCurrentlyConnected = false; fCurrentlyConnected = false;
nMisbehavior = 0; nMisbehavior = 0;
fShouldBan = false; fShouldBan = false;
@ -355,10 +355,10 @@ void UpdatePreferredDownload(CNode* node, CNodeState* state)
} }
void InitializeNode(NodeId nodeid, const CNode *pnode) { void InitializeNode(NodeId nodeid, const CNode *pnode) {
CAddress addr = pnode->addr;
std::string addrName = pnode->addrName;
LOCK(cs_main); LOCK(cs_main);
CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second; mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName)));
state.name = pnode->addrName;
state.address = pnode->addr;
} }
void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) { void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) {