The motivation of this PR is to extract and encapsulate logic in SendMessages() into smaller and focused methods, also motivated by a brief comment during a review of #21509.
This PR extracts the logic to maybe announce the nodes local address to a peer.
If there is sufficient support for this type of refactoring, then the intention would be that further changes should be made in separate PRs to extract each area of logic from SendMessages().
The idea would be for the changes to eventually look something like this:
bool PeerManagerImpl::SendMessages(CNode* pto) {
...
{
LOCK(cs_main);
...
MaybeAnnounceLocalAddress(...);
SendAddr(...);
SendGetHeadersBlockSync(...);
SendBlockAnnouncements(...);
SendInv(...);
...
}
...
}
The argument for this change would be, that it would be easier to read and understand the high level logic of SendMessages(). There other reason would be to separate and encapsulate each area of logic according to narrow responsibilities.
Since the logic in SendMessages() is important, I am concerned that moving the code around for style and readability may introduce unintended bugs, for example implementing safe and correct method signatures. I was also unable to find tests that specifically target announcing local addresses while in IBD or if the peer is block-relay-only.
Any feedback would greatly appreciated.