This is a backport of [[https://github.com/bitcoin/bitcoin/pull/19203 | core#19203]], [[https://github.com/bitcoin/bitcoin/pull/21328 | core#21328]], [[https://github.com/bitcoin/bitcoin/pull/20812 | core#20812]] (for `PickValueInArray((const std::array<T, size> &array)`) and [[https://github.com/bitcoin/bitcoin/pull/21371 | core#21371]]
with changes from:
- https://github.com/bitcoin/bitcoin/pull/21328/commits/6423c8175fad3163c10ffdb49e0df48e4e4931f1 (Socks5 port -> uint16_t)