-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor, net: End friendship of CNode, CConnman and ConnmanTestMsg #27257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK 0e769e8
0e769e8
to
d02b99b
Compare
@vasild Thanks for the review! Took all of your suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK d02b99b
d02b99b
to
e29ecec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK e29ecec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crACK e29ecec
nice cleanup!
e29ecec
to
6514352
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-review ACK 6514352
6514352
to
60c3f49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 60c3f49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 60c3f49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 60c3f49
Now that all access to the process queue members is handled by methods of `CNode` we can make these members private.
-BEGIN VERIFY SCRIPT- ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); } ren cs_vProcessMsg m_msg_process_queue_mutex ren vProcessMsg m_msg_process_queue ren nProcessQueueSize m_msg_process_queue_size -END VERIFY SCRIPT-
Both `CConnman` and `ConnmanTestMsg` no longer access private members of `CNode`, we can therefore remove the friend relationship.
60c3f49
to
3566aa7
Compare
m_msg_process_queue_size -= msgs.front().m_raw_message_size; | ||
fPauseRecv = m_msg_process_queue_size > recv_flood_size; | ||
|
||
return std::make_pair(std::move(msgs.front()), !m_msg_process_queue.empty()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was making a copy here of the CNetMessage
, fixed now!
Easy to review with git range-diff 60c3f4918190900e5f79341abcc0878214656257...3566aa7d495bb783bbd135726238d9f2a9e9f80e
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 3566aa7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 3566aa7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK 3566aa7
utACK 3566aa7 I didn't verify myself that the new code doesn't result in a copy of All of my review comments are nits/style comments and shouldn't stop this from being merged. |
node.nProcessQueueSize += nSizeAdded; | ||
node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize; | ||
} | ||
node.MarkReceivedMsgsForProcessing(nReceiveFloodSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: feel free to use a single line for single-line if blocks:
if (complete) node.MarkReceivedMsgsForProcessing(nReceiveFloodSize);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a matter of personal taste (since both are allowed), but I just want to mention here why I, personally, avoid that:
- It is not gdb friendly - you can't set a breakpoint on the
if
body (yes, one can set a breakpoint on the function call, but it becomes tedious if that function is called a lot from other places) - Creates bigger diff during changes in the future, comapre:
- if (A) B;
+ if (A) {
+ B;
+ C;
+ }
vs
if (A) {
B;
+ C;
}
The latter is easier to read, especially if A
, B
and C
are complex expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it's personal taste and the project style guide allows either.
It is not gdb friendly - you can't set a breakpoint on the if body (yes, one can set a breakpoint on the function call, but it becomes tedious if that function is called a lot from other places)
Are you familiar with conditional breakpoints? You can set the breakpoint to only stop the program if a boolean condition evaluates to true. Here, I think you could add the breakpoint:
break "net.cpp":68 if complete
and it would only stop if the if block is going to be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alas that does not work if the condition includes function calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alas that does not work if the condition includes function calls.
Why not? From the GDB docs:
Break conditions can have side effects, and may even call functions in your program.
cd0c8ee [net] Pass nRecvFloodSize to CNode (dergoegge) 860402e [net] Remove trivial GetConnectionType() getter (dergoegge) b5a85b3 [net] Delete CNetMessage copy constructor/assignment op (dergoegge) Pull request description: Follow-up PR for #27257 * Deletes the copy constructor/assignment operator of `CNetMessage` * Removes trivial getter for the connection type * Avoids passing `nRecvFloodSize` to CNode methods by passing it to `CNode` on creation ACKs for top commit: jnewbery: utACK cd0c8ee theStack: ACK cd0c8ee Tree-SHA512: 673a758668617f69fba77e61f0eaa1538da27a4849c82c98742436692baa2d7f001129af3e7a66b160e599d12109dac08137a146f10ff9b9ebdc5c2237311d41
cd0c8ee [net] Pass nRecvFloodSize to CNode (dergoegge) 860402e [net] Remove trivial GetConnectionType() getter (dergoegge) b5a85b3 [net] Delete CNetMessage copy constructor/assignment op (dergoegge) Pull request description: Follow-up PR for bitcoin#27257 * Deletes the copy constructor/assignment operator of `CNetMessage` * Removes trivial getter for the connection type * Avoids passing `nRecvFloodSize` to CNode methods by passing it to `CNode` on creation ACKs for top commit: jnewbery: utACK cd0c8ee theStack: ACK cd0c8ee Tree-SHA512: 673a758668617f69fba77e61f0eaa1538da27a4849c82c98742436692baa2d7f001129af3e7a66b160e599d12109dac08137a146f10ff9b9ebdc5c2237311d41
We should define clear interfaces between CNode, CConnman and PeerManager. This PR makes a small step in that direction by ending the friendship of CNode, CConnman and ConnmanTestMsg. CNode's message processing queue is made private in the process and its mutex is turned into a non-recursive mutex.