| 3120 | } |
| 3121 | |
| 3122 | std::optional<Network> CConnman::PrivateBroadcast::PickNetwork(std::optional<Proxy>& proxy) const |
| 3123 | { |
| 3124 | prevector<4, Network> nets; |
| 3125 | std::optional<Proxy> clearnet_proxy; |
| 3126 | proxy.reset(); |
| 3127 | if (g_reachable_nets.Contains(NET_ONION)) { |
| 3128 | nets.push_back(NET_ONION); |
| 3129 | |
| 3130 | clearnet_proxy = ProxyForIPv4or6(); |
| 3131 | if (clearnet_proxy.has_value()) { |
| 3132 | if (g_reachable_nets.Contains(NET_IPV4)) { |
| 3133 | nets.push_back(NET_IPV4); |
| 3134 | } |
| 3135 | if (g_reachable_nets.Contains(NET_IPV6)) { |
| 3136 | nets.push_back(NET_IPV6); |
| 3137 | } |
| 3138 | } |
| 3139 | } |
| 3140 | if (g_reachable_nets.Contains(NET_I2P)) { |
| 3141 | nets.push_back(NET_I2P); |
| 3142 | } |
| 3143 | |
| 3144 | if (nets.empty()) { |
| 3145 | return std::nullopt; |
| 3146 | } |
| 3147 | |
| 3148 | const Network net{nets[FastRandomContext{}.randrange(nets.size())]}; |
| 3149 | if (net == NET_IPV4 || net == NET_IPV6) { |
| 3150 | proxy = clearnet_proxy; |
| 3151 | } |
| 3152 | return net; |
| 3153 | } |
| 3154 | |
| 3155 | size_t CConnman::PrivateBroadcast::NumToOpen() const |
| 3156 | { |