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