In commit “[tests] Add p2p connection to TestNode”
Should drop p2p_conn_type
and just take p2p_conn
as an argument.
Here there is two much coupling in the other direction (Tests<->TestNode rather than TestNode<->MiniNode), and the control flow is unnecessarily convoluted. Test calls add_p2p_connection, add_p2p_connection calls back into test using p2p_conn_type callback to construct the test’s custom NodeConnCB object, wires it up, and then passes it back to test.
Would be cleaner and simpler for tests to construct their own NodeConnCB objects and just pass them here to be wired up.
(I see in #11518 you are using this flow to indirectly pass dstport to the P2PConnection constructor up through the p2p_conn_type callback and inherited contructors. But I think a direct approach would be better there, too: instead of connecting in the P2PConnection constructor, you should just add a P2PConnection connect method and have this code call it.)
Tests should be largely unaffected by this change. Instead of saying add_p2p_connection(CustomHandler)
they would say add_p2p_connection(CustomHandler())
which would be better because it will allow them to more easily pass options to their own handlers, and would be more straightforward because it will be obvious just looking at the test code how and when the handler classes that it defines are getting instantiated.