diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2016-10-26 17:41:44 -0400 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2016-11-03 13:35:54 -0700 |
commit | 7588b85cd2fc0a37c260d014206d5badde4b2c78 (patch) | |
tree | 5039a72ffcf64d9f542cbbdab5475e2ca72cfdf3 /src | |
parent | 440f1d3e4c60c9c3e0a1a74d3321b0a8e37a1e8d (diff) |
net: construct CNodeStates in place
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp index 5f5b1e3b7c..2d02f59d2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -257,7 +257,7 @@ struct CBlockReject { */ struct CNodeState { //! The peer's address - CService address; + const CService address; //! Whether we have a fully established connection. bool fCurrentlyConnected; //! Accumulated misbehaviour score for this peer. @@ -265,7 +265,7 @@ struct CNodeState { //! Whether this peer should be disconnected and banned (unless whitelisted). bool fShouldBan; //! 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. std::vector<CBlockReject> rejects; //! The best known block we know this peer has announced. @@ -309,7 +309,7 @@ struct CNodeState { */ bool fSupportsDesiredCmpctVersion; - CNodeState() { + CNodeState(CAddress addrIn, std::string addrNameIn) : address(addrIn), name(addrNameIn) { fCurrentlyConnected = false; nMisbehavior = 0; fShouldBan = false; @@ -355,10 +355,10 @@ void UpdatePreferredDownload(CNode* node, CNodeState* state) } void InitializeNode(NodeId nodeid, const CNode *pnode) { + CAddress addr = pnode->addr; + std::string addrName = pnode->addrName; LOCK(cs_main); - CNodeState &state = mapNodeState.insert(std::make_pair(nodeid, CNodeState())).first->second; - state.name = pnode->addrName; - state.address = pnode->addr; + mapNodeState.emplace_hint(mapNodeState.end(), std::piecewise_construct, std::forward_as_tuple(nodeid), std::forward_as_tuple(addr, std::move(addrName))); } void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) { |