[net processing] Move send ping message logic into function
Summary:
Partial backport of core#20721:
https://github.com/bitcoin/bitcoin/pull/20721/commits/0b43b81f69ff13dbc1e893a80950f186690b4f62
Ref T1696.
Depends on D10875.
Test Plan:
ninja all check-all
Reviewers: #bitcoin_abc, PiRK
Reviewed By: #bitcoin_abc, PiRK
Maniphest Tasks: T1696
Differential Revision: https://reviews.bitcoinabc.org/D10876