This work creates CConnman. The idea is to begin moving data structures and functionality out of globals in net.h and into an instanced class, in order to avoid side-effects in networking code. Eventually, an (internal) api begins to emerge, and as long as the conditions of that api are met, the inner-workings may be a black box.
For now (for ease), a single global CConnman is created. Down the road, the instance could be passed around instead. Also, CConnman should be moved out of net.h/net.cpp, but that can be done in a separate move-only-ish step.
A few todos remain here:
there areif(g_connman)
’s everywhere. A few places should assume that a connman is running (or it should be passed around). For example, ProcessMessages.GetRelayTx/RelayTransaction are awkward. Where should mapRelay live? Should it be dealt with directly rather than hidden inside of relay functions? (rebased on top of #8082)How to deal with CConnman parameters? Continue adding them to Start(), or have it parse the program options itself? (Created CConnman::Options)RPC needs a new error for dealing with the “p2p not enabled” case.
Todos for a follow-up PR:
- Actually create connman.h/cpp and move the class there.
- Pass CConnman into QT similar to the wallet
Drop StartNode/StopNode and just use CConnman::Stop/Start directly (Need to make sure that MapPort can be moved directly into Init without side-effects)- Pass CChainParams into CConnman and pass it around
Create CConnmanOptions to reduce the verbosity of CConnman::Start()- Deal with fDiscover/fListen/etc in CConnman